Name Entity recognition using java

73 Views Asked by At

I want to implement a small and simple code to be able to extract a named entity from a small text. example: the user enters this sentence: Mr. Smith visited the hospital in New York for his asthma treatment and his cancer appointement.

the result I'm looking for is "asthma" and "cancer".

looking around i was able to find cTakes and apache opennlp. i wasn't able to make it work what I did is like this

public void extractNamedEntities(String inputText) {
    try {
        // Create a new JCas for processing
        JCas jCas = JCasFactory.createJCas();

        // Set the input text
        jCas.setDocumentText(inputText);


        // Process the text using cTakes pipeline
        SimplePipeline.runPipeline(jCas,
                SentenceDetector.createAnnotatorDescription()); // Change MyAnnotator to your annotator class

        // Retrieve named entity annotations after processing
        //Collection<DocumentID> documentIDAnnotations = DocumentIDAnnotationUtil.getDocumentID(jCas);
        System.out.println(DocumentIDAnnotationUtil.getDocumentID(jCas));
        //return documentIDAnnotations;
    } catch (Exception e) {
        e.printStackTrace();
        //return null;
    }
}

My biggest concern is the annotator in this line

SimplePipeline.runPipeline(jCas,
            SentenceDetector.createAnnotatorDescription());

is there predefined annotator to use, or am i completely in the wrong direction.

My context of work is Medical.

and I welcome any other suggestion different than my approach.

or if there is free api that i can use to fulfill this task (as my primary goal for my small app is not extracting the named entity)

0

There are 0 best solutions below