Pregunta

I have trained an OpenNLP Name Entity Recognizer. When I use it over some data it gives an output like:

[0..1) location

I rather want to output the original name that occurred in the data.

¿Fue útil?

Solución

this is a Span objects toString() output. Each call to find(String[]) can return multiple Spans, hence the find() method returns Span[]. Use this code to get the actual named entities

    //"tokens" here is the String[] of words in your sentence
    Span[] find = nf.find(tokens);
    //use the Span's static method to get the String[] of names
    String[] namedEntities = Span.spansToStrings(find, tokens);

A span is simply a start and end index to your String[] tokens.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top