Search in sources :

Example 31 with AnnotatedText

use of com.graphaware.nlp.domain.AnnotatedText in project neo4j-nlp by graphaware.

the class TextProcessorsManager method annotate.

public AnnotatedText annotate(String text, PipelineSpecification pipelineSpecification) {
    if (null == pipelineSpecification) {
        throw new RuntimeException("No pipeline " + pipelineSpecification.name + " found.");
    }
    if (text.trim().equalsIgnoreCase("")) {
        throw new InvalidTextException();
    }
    TextProcessor processor = getTextProcessor(pipelineSpecification.getTextProcessor());
    long startTime = -System.currentTimeMillis();
    AnnotatedText annotatedText;
    try {
        annotatedText = processor.annotateText(text, pipelineSpecification);
    } catch (Exception e) {
        throw new TextAnalysisException(e.getMessage(), e);
    }
    LOG.info("Time to annotate " + (System.currentTimeMillis() + startTime));
    return annotatedText;
}
Also used : NLPTextProcessor(com.graphaware.nlp.annotation.NLPTextProcessor) AnnotatedText(com.graphaware.nlp.domain.AnnotatedText) InvalidTextException(com.graphaware.nlp.exception.InvalidTextException) TextAnalysisException(com.graphaware.nlp.exception.TextAnalysisException) InvalidPipelineException(com.graphaware.nlp.exception.InvalidPipelineException) InvalidTextProcessorException(com.graphaware.nlp.exception.InvalidTextProcessorException) InvalidTextException(com.graphaware.nlp.exception.InvalidTextException) TextAnalysisException(com.graphaware.nlp.exception.TextAnalysisException)

Example 32 with AnnotatedText

use of com.graphaware.nlp.domain.AnnotatedText in project neo4j-nlp by graphaware.

the class AnnotateFunction method getAnnotation.

@UserFunction("ga.nlp.processor.annotate")
@Description("Perform the annotation on the given text, returns the produced annotation domain")
public Map<String, Object> getAnnotation(@Name("text") String text, @Name("pipelineSpecification") Map<String, Object> specificationInput) {
    if (!specificationInput.containsKey("name")) {
        throw new RuntimeException("You mast specify the name of the pipeline");
    }
    PipelineSpecification spec = getNLPManager().getTextProcessorsManager().getPipelineSpecification((String) specificationInput.get("name"));
    TextProcessor processor = getNLPManager().getTextProcessorsManager().getTextProcessor(spec.getTextProcessor());
    AnnotatedText annotatedText = processor.annotateText(text, spec);
    ObjectMapper mapper = new ObjectMapper();
    mapper.configure(SerializationConfig.Feature.FAIL_ON_EMPTY_BEANS, false);
    Map map = mapper.convertValue(annotatedText, Map.class);
    return map;
}
Also used : PipelineSpecification(com.graphaware.nlp.dsl.request.PipelineSpecification) TextProcessor(com.graphaware.nlp.processor.TextProcessor) AnnotatedText(com.graphaware.nlp.domain.AnnotatedText) Map(java.util.Map) ObjectMapper(org.codehaus.jackson.map.ObjectMapper) Description(org.neo4j.procedure.Description) UserFunction(org.neo4j.procedure.UserFunction)

Aggregations

AnnotatedText (com.graphaware.nlp.domain.AnnotatedText)32 Test (org.junit.Test)18 Sentence (com.graphaware.nlp.domain.Sentence)17 Tag (com.graphaware.nlp.domain.Tag)11 TextProcessor (com.graphaware.nlp.processor.TextProcessor)9 TestAnnotatedText (com.graphaware.nlp.util.TestAnnotatedText)8 NLPIntegrationTest (com.graphaware.nlp.NLPIntegrationTest)5 TagUtils.newTag (com.graphaware.nlp.util.TagUtils.newTag)5 TestNLPGraph (com.graphaware.nlp.util.TestNLPGraph)5 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)5 Transaction (org.neo4j.graphdb.Transaction)5 StanfordTextProcessor (com.graphaware.nlp.processor.stanford.StanfordTextProcessor)3 StubTextProcessor (com.graphaware.nlp.stub.StubTextProcessor)3 StanfordCoreNLP (edu.stanford.nlp.pipeline.StanfordCoreNLP)3 Arrays (java.util.Arrays)3 Collections (java.util.Collections)3 Assert (org.junit.Assert)3 Before (org.junit.Before)3 Node (org.neo4j.graphdb.Node)3 PipelineSpecification (com.graphaware.nlp.dsl.request.PipelineSpecification)2