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;
}
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;
}
Aggregations