How to pick words and save in a string?

Asked

Viewed 401 times

0

How do I save words I get in a string new?

gravarArq.println(token.getLexeme() + "_" + token.getPOSTag() + "_" + token.getFeatures());

How to take what comes from token.getPOSTag() and save all the words that come from it in a string new?

for (org.cogroo.text.Token token : sentence.getTokens()) { // lista de tokens
    token.getStart(); token.getEnd(); // caracteres onde o token comeca e termina
    token.getLexeme(); // o texto do token (palavra que ele separa e pega exp: "clinico"
    token.getLemmas(); // um array com os possiveis lemas para o par lexeme+postag
    token.getPOSTag(); // classe morfologica de acordo com o contexto("coloca "prp, adj,n(noun))
    token.getFeatures(); // genero, numero, tempo etc
    contadorTokens++;
    System.out.println(token.getLexeme() + "_" + token.getPOSTag() + "_" + token.getFeatures());// imprime a palavra com o tag
      gravarArq.println(token.getLexeme() + "_" + token.getPOSTag() + "_" + token.getFeatures());
    //System.out.println(token.getLexeme());
}
  • Welcome to [en.so]. Could you clarify what your question is? What part of the code exactly are you having problems with? From what I understand is just take what comes from token.getPOSTag() and play in a new variable, right? Enjoy and make a [tour] through the site and check out the guide to [Ask].

1 answer

1

If I understand, I think that’s it.

// instantiation

String val = new String(token.getPOSTag());

// declaration and instantiation (more practical)

String val = token.getPOSTag();

But if your token.getPOSTag() attribute has more than 1 value after that for scan, you will need a list.

ArrayList<String> listaTokens = new ArrayList<String>();

for (org.cogroo.text.Token token : sentence.getTokens()) { // lista de tokens
    token.getStart(); token.getEnd(); // caracteres onde o token comeca e termina
    token.getLexeme(); // o texto do token (palavra que ele separa e pega exp: "clinico"
    token.getLemmas(); // um array com os possiveis lemas para o par lexeme+postag
    listaTokens.add(token.getPOSTag()); // classe morfologica de acordo com o contexto("coloca "prp, adj,n(noun))
    token.getFeatures(); // genero, numero, tempo etc
    contadorTokens++;
    System.out.println(token.getLexeme() + "_" + token.getPOSTag() + "_" + token.getFeatures());// imprime a palavra com o tag
      gravarArq.println(token.getLexeme() + "_" + token.getPOSTag() + "_" + token.getFeatures());
    //System.out.println(token.getLexeme());
}

Browser other questions tagged

You are not signed in. Login or sign up in order to post.