Skip to content

MetadataConsulting/letter-annotator

Repository files navigation

Letter Annotator

Get the lastest version from JCenter or Maven Central org.modelcatalogue:letter-annotator-lucene:{version}

Annotates text with terms provided.

String letterText = "This is some document about somatic problems. They can be caused by somatic mosaicism. " +
                "Glad there were no neoplasm because initially thy were suspecting a neoplasm";

String expected = "This is some document about <a href=\"https://en.wikipedia.org/wiki/Somatic\" " +
        "title=\"Somatic\">somatic</a> problems. They can be caused by <span title=\"Somatic Mosaicism\" " +
        "class=\"visited\">somatic mosaicism</span>. Glad there were no <span title=\"Neoplasm\">" +
        "neoplasm</span> because initially thy were suspecting a <span title=\"Neoplasm\">neoplasm</span>";

LetterAnnotator annotator = new LuceneLetterAnnotator();

annotator.addCandidate(CandidateTerm.create("Neoplasm"));
annotator.addCandidate(CandidateTerm.create("Somatic").url("https://en.wikipedia.org/wiki/Somatic"));
annotator.addCandidate(CandidateTerm.create("Mutation"));
annotator.addCandidate(CandidateTerm.create("Somatic Mutation"));
annotator.addCandidate(CandidateTerm.create("Somatic Mosaicism").extensions("class", "visited"));

AnnotatedLetter letter = annotator.annotate(letterText, Highlighter.HTML);

if (!letter.getText().equals(expected)) {
    throw new RuntimeException("Text does not match!");
}
System.out.println("Expected output matched!");
System.out.println("========================");
System.out.println(letter.getText());
System.out.println("========================");