2
I am doing the "Tokenization" of a TXT file.
I need the code to hold all the tokens in an Arraylist, but can’t get any token duplicate.
I would like to know how to remove tokens duplicates, or checks whether the token already exists and in this case do not add it.
My current code:
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(expandirAcronimos(token.getLexeme()) + "_" + token.getPOSTag() + "_" + token.getFeatures());// imprime a palavra com o tag
    gravarArq.println(token.getLexeme() + "_" + token.getPOSTag() + "_" + token.getFeatures());// grava no arquivo txt cada palavra tokenizada
    gravarArquivo.println(token.getPOSTag() + "_" + token.getFeatures());// grava no arquivo "Tokens.txt" cada token
    listaTokens.add(token.getPOSTag()); //ADICIONA as tags para dentro de uma lista 
    for(int s=0;s<listaTokens.size();s++){  //PERCORRE A LISTA
        if (!listaTokens.equals(token.getPOSTag())) {
        }
    }
}
mightduck, for your own sanity and to facilitate who will help you, it is essential to make a logical indentation of the code. A good IDE helps in this. . . . Maybe the mgibson answer already solves, but it lacks the closure of the first
for...– brasofilo