use of org.neo4j.procedure.Description in project neo4j-nlp by graphaware.
the class SimilarityProcedure method similarity.
// @Procedure(name = "ga.nlp.ml.similarity.cosine", mode = Mode.WRITE)
// @Description("Compute similarity between Annotated Text")
// public Stream<SingleResult> similarityOld(@Name("input") List<Node> input,
// @Name("depth") Long depth,
// @Name("query") String query,
// @Name("relationshipType") String relationshipType) {
// SimilarityProcessor similarityProcessor = (SimilarityProcessor) getNLPManager().getExtension(SimilarityProcessor.class);
// int processed = similarityProcessor.compute(input, query, relationshipType, depth);
// return Stream.of(new SingleResult(processed));
// }
@Procedure(name = "ga.nlp.ml.similarity.cosine", mode = Mode.WRITE)
@Description("Compute similarity between Annotated Text")
public Stream<SingleResult> similarity(@Name("similarityRequest") Map<String, Object> similarityRequest) {
try {
SimilarityRequest request = SimilarityRequest.fromMap(similarityRequest);
SimilarityProcessor similarityProcessor = (SimilarityProcessor) getNLPManager().getExtension(SimilarityProcessor.class);
int processed = similarityProcessor.compute(request);
return Stream.of(new SingleResult(processed));
} catch (Exception ex) {
LOG.error("Error while computing similarity", ex);
throw new RuntimeException(ex);
}
}
use of org.neo4j.procedure.Description in project neo4j-nlp by graphaware.
the class TextProcessorsProcedure method setDefaultPipeline.
@Procedure(value = "ga.nlp.processor.pipeline.default", mode = Mode.WRITE)
@Description("Specify the pipeline to be used by default")
public Stream<SingleResult> setDefaultPipeline(@Name("name") String name) {
PipelineSpecification pipelineSpecification = getConfiguration().loadPipeline(name);
if (null == pipelineSpecification) {
throw new RuntimeException("Pipeline " + name + " does not exist");
}
getConfiguration().updateInternalSetting(SettingsConstants.DEFAULT_PIPELINE, name);
return Stream.of(SingleResult.success());
}
use of org.neo4j.procedure.Description in project neo4j-nlp by graphaware.
the class TextProcessorsProcedure method train.
@Procedure(name = "ga.nlp.processor.train", mode = Mode.WRITE)
@Description("Procedure for training custom models.")
public Stream<SingleResult> train(@Name("customModelsRequest") Map<String, Object> customModelsRequest) {
try {
CustomModelsRequest request = CustomModelsRequest.fromMap(customModelsRequest);
Object result = getNLPManager().train(request);
return Stream.of(new SingleResult(result));
} catch (Exception e) {
throw new RuntimeException(e);
}
}
use of org.neo4j.procedure.Description 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) {
PipelineSpecification pipelineSpecification = PipelineSpecification.fromMap(specificationInput);
String pipeline = getNLPManager().getPipeline(pipelineSpecification.getName());
PipelineSpecification spec = getConfiguration().loadPipeline(pipeline);
TextProcessor processor = getNLPManager().getTextProcessorsManager().getTextProcessor(spec.getTextProcessor());
AnnotatedText annotatedText = processor.annotateText(text, "en", pipelineSpecification);
ObjectMapper mapper = new ObjectMapper();
mapper.configure(SerializationConfig.Feature.FAIL_ON_EMPTY_BEANS, false);
return mapper.convertValue(annotatedText, Map.class);
}
use of org.neo4j.procedure.Description in project neo4j-nlp by graphaware.
the class SentenceFunctions method nextTags.
@UserFunction("ga.nlp.sentence.nextTags")
@Description("Returns a list of Tag nodes that appear just after the given Tag in a sentence along with the frequency")
public List<Map<String, Object>> nextTags(@Name("from") Node from) {
Map<Long, Integer> freqMap = new HashMap<>();
Map<Long, Node> references = new HashMap<>();
for (Relationship rel : from.getRelationships(Relationships.TAG_OCCURRENCE_TAG, Direction.INCOMING)) {
Node tagOccurence = rel.getStartNode();
int minPosition = (int) tagOccurence.getProperty(Properties.END_POSITION);
Node sentence = tagOccurence.getSingleRelationship(Relationships.SENTENCE_TAG_OCCURRENCE, Direction.INCOMING).getStartNode();
for (Relationship rel2 : sentence.getRelationships(Relationships.SENTENCE_TAG_OCCURRENCE, Direction.OUTGOING)) {
Node occurence = rel2.getEndNode();
int occPosition = (int) occurence.getProperty(Properties.START_POSITION);
if (occPosition == (minPosition + 1)) {
Node tag = occurence.getSingleRelationship(Relationships.TAG_OCCURRENCE_TAG, Direction.OUTGOING).getEndNode();
Integer freq = freqMap.containsKey(tag.getId()) ? freqMap.get(tag.getId()) + 1 : 1;
freqMap.put(tag.getId(), freq);
}
}
}
List<Map<String, Object>> response = new ArrayList<>();
for (Long l : references.keySet()) {
Map<String, Object> m = new HashMap<>();
m.put("node", references.get(l));
m.put("frequency", freqMap.get(l));
response.add(m);
}
return response;
}
Aggregations