use of com.graphaware.nlp.dsl.request.PipelineSpecification 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;
}
use of com.graphaware.nlp.dsl.request.PipelineSpecification in project neo4j-nlp by graphaware.
the class TextProcessorsProcedure method refreshPipeline.
@Procedure(value = "ga.nlp.refreshPipeline", mode = Mode.WRITE)
@Description("Refresh pipeline for the given name")
public Stream<PipelineSpecification> refreshPipeline(@Name(value = "pipeline") String pipeline) {
try {
PipelineSpecification pipelineSpecification = getNLPManager().getConfiguration().loadPipeline(pipeline);
getNLPManager().getTextProcessorsManager().removePipeline(pipelineSpecification.getName(), pipelineSpecification.getTextProcessor());
PipelineSpecification newPipeline = new PipelineSpecification(pipelineSpecification.getName(), pipelineSpecification.getLanguage(), pipelineSpecification.getTextProcessor(), pipelineSpecification.getProcessingStepsAsStrings(), pipelineSpecification.getStopWords(), pipelineSpecification.getThreadNumber(), pipelineSpecification.getExcludedNER(), pipelineSpecification.getExcludedPOS());
getNLPManager().getTextProcessorsManager().addPipeline(newPipeline);
return Stream.of(newPipeline);
} catch (Exception e) {
throw new RuntimeException(e);
}
}
use of com.graphaware.nlp.dsl.request.PipelineSpecification in project neo4j-nlp by graphaware.
the class MigrationHandler method doMigrate.
private void doMigrate(String k) throws Exception {
String specStr = graphKeyValueStore.get(k).toString();
if (!specStr.contains("\"@class\"")) {
PipelineSpecification pipelineSpecification = mapper.readValue(specStr, PipelineSpecification.class);
graphKeyValueStore.remove(k);
configuration.storeCustomPipeline(pipelineSpecification);
}
}
use of com.graphaware.nlp.dsl.request.PipelineSpecification in project neo4j-nlp by graphaware.
the class DynamicConfiguration method removePipeline.
public void removePipeline(String name, String textProcessor) {
Map<String, Object> config = getAllConfigValuesFromStore();
config.keySet().forEach(k -> {
if (k.startsWith(PIPELINE_KEY_PREFIX)) {
try {
PipelineSpecification pipelineSpecification = mapper.readValue(config.get(k).toString(), PipelineSpecification.class);
if (pipelineSpecification.getName().equals(name) && pipelineSpecification.getTextProcessor().equals(textProcessor)) {
removeKey(STORE_KEY + k);
}
} catch (Exception e) {
throw new RuntimeException(e.getMessage());
}
}
});
}
Aggregations