Search in sources :

Example 11 with PipelineSpecification

use of com.graphaware.nlp.dsl.request.PipelineSpecification in project neo4j-nlp by graphaware.

the class TextProcessorsManager method removePipeline.

public void removePipeline(String pipeline, String processor) {
    PipelineSpecification pipelineSpecification = configuration.loadPipeline(pipeline);
    String language = pipelineSpecification.getLanguage();
    configuration.removePipeline(pipeline, processor);
    getTextProcessor(processor).removePipeline(pipeline);
    if (getPipelineSpecifications().stream().noneMatch(item -> item.getLanguage().equals(language))) {
        removeSupportedLanguage(language);
    } else {
        PipelineSpecification defaultForLanguage = defaultPipelineByLanguage.get(language);
        if (defaultForLanguage != null && defaultForLanguage.getName().equalsIgnoreCase(pipeline)) {
            PipelineSpecification newDefault = getPipelineSpecifications().stream().filter(item -> item.getLanguage().equals(language)).collect(Collectors.toList()).get(0);
            defaultPipelineByLanguage.put(language, newDefault);
        }
    }
}
Also used : PipelineSpecification(com.graphaware.nlp.dsl.request.PipelineSpecification)

Example 12 with PipelineSpecification

use of com.graphaware.nlp.dsl.request.PipelineSpecification in project neo4j-nlp by graphaware.

the class DynamicConfiguration method loadPipeline.

public PipelineSpecification loadPipeline(String name) {
    Map<String, Object> config = getAllConfigValuesFromStore();
    AtomicReference<PipelineSpecification> result = new AtomicReference<>();
    config.keySet().forEach(k -> {
        if (k.startsWith(PIPELINE_KEY_PREFIX)) {
            try {
                String s = config.get(k).toString();
                PipelineSpecification pipelineSpecification = mapper.readValue(config.get(k).toString(), PipelineSpecification.class);
                if (pipelineSpecification.getName().equals(name)) {
                    result.set(pipelineSpecification);
                }
            } catch (Exception e) {
                throw new RuntimeException(e.getMessage());
            }
        }
    });
    return result.get();
}
Also used : PipelineSpecification(com.graphaware.nlp.dsl.request.PipelineSpecification) AtomicReference(java.util.concurrent.atomic.AtomicReference) IOException(java.io.IOException)

Example 13 with PipelineSpecification

use of com.graphaware.nlp.dsl.request.PipelineSpecification in project neo4j-nlp by graphaware.

the class TextProcessorsProcedure method addPipeline.

@Procedure(name = "ga.nlp.processor.addPipeline", mode = Mode.WRITE)
@Description("Add custom pipeline to a Text Processor")
public Stream<SingleResult> addPipeline(@Name("addPipelineRequest") Map<String, Object> addPipelineRequest) {
    try {
        addPipelineRequest.put("createdAt", DATE_FORMAT.format(new Date()));
        PipelineSpecification pipelineSpecification = mapper.convertValue(addPipelineRequest, PipelineSpecification.class);
        getNLPManager().getTextProcessorsManager().addPipeline(pipelineSpecification);
        return Stream.of(SingleResult.success());
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}
Also used : PipelineSpecification(com.graphaware.nlp.dsl.request.PipelineSpecification) Date(java.util.Date) Description(org.neo4j.procedure.Description) Procedure(org.neo4j.procedure.Procedure)

Example 14 with PipelineSpecification

use of com.graphaware.nlp.dsl.request.PipelineSpecification in project neo4j-nlp by graphaware.

the class DynamicConfiguration method loadCustomPipelines.

public List<PipelineSpecification> loadCustomPipelines() {
    List<PipelineSpecification> list = new ArrayList<>();
    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);
                list.add(pipelineSpecification);
            } catch (Exception e) {
                throw new RuntimeException(e);
            }
        }
    });
    return list;
}
Also used : PipelineSpecification(com.graphaware.nlp.dsl.request.PipelineSpecification) ArrayList(java.util.ArrayList) IOException(java.io.IOException)

Example 15 with PipelineSpecification

use of com.graphaware.nlp.dsl.request.PipelineSpecification in project neo4j-nlp by graphaware.

the class ConfigurationMigrationTest method testPipelinesCanBeMigrated.

@Test
public void testPipelinesCanBeMigrated() throws Exception {
    PipelineSpecification specification = new PipelineSpecification("custom", StubTextProcessor.class.getName());
    specification.setStopWords("hello,hihi");
    ObjectMapper mapper = new ObjectMapper();
    String spec = mapper.writeValueAsString(specification);
    try (Transaction tx = getDatabase().beginTx()) {
        keyValueStore.set(DynamicConfiguration.STORE_KEY + "PIPELINE_" + specification.getName(), spec);
        assertFalse(spec.contains("\"@class\""));
        tx.success();
    }
    GraphAwareRuntime runtime = GraphAwareRuntimeFactory.createRuntime(getDatabase());
    runtime.registerModule(new NLPModule("NLP", NLPConfiguration.defaultConfiguration(), getDatabase()));
    runtime.start();
    runtime.waitUntilStarted();
    try (Transaction tx = getDatabase().beginTx()) {
        String s = keyValueStore.get(DynamicConfiguration.STORE_KEY + "PIPELINE_" + specification.getName()).toString();
        assertTrue(s.contains("\"@class\""));
        tx.success();
    }
}
Also used : PipelineSpecification(com.graphaware.nlp.dsl.request.PipelineSpecification) Transaction(org.neo4j.graphdb.Transaction) GraphAwareRuntime(com.graphaware.runtime.GraphAwareRuntime) NLPModule(com.graphaware.nlp.module.NLPModule) StubTextProcessor(com.graphaware.nlp.stub.StubTextProcessor) ObjectMapper(org.codehaus.jackson.map.ObjectMapper) AbstractEmbeddedTest(com.graphaware.nlp.AbstractEmbeddedTest) Test(org.junit.Test)

Aggregations

PipelineSpecification (com.graphaware.nlp.dsl.request.PipelineSpecification)49 Test (org.junit.Test)22 StubTextProcessor (com.graphaware.nlp.stub.StubTextProcessor)13 StanfordTextProcessor (com.graphaware.nlp.processor.stanford.StanfordTextProcessor)11 NLPIntegrationTest (com.graphaware.nlp.NLPIntegrationTest)8 TestAnnotatedText (com.graphaware.nlp.util.TestAnnotatedText)8 Transaction (org.neo4j.graphdb.Transaction)8 AbstractEmbeddedTest (com.graphaware.nlp.AbstractEmbeddedTest)5 NLPTextProcessor (com.graphaware.nlp.annotation.NLPTextProcessor)4 TextProcessor (com.graphaware.nlp.processor.TextProcessor)3 CoreAnnotations (edu.stanford.nlp.ling.CoreAnnotations)3 Annotation (edu.stanford.nlp.pipeline.Annotation)3 StanfordCoreNLP (edu.stanford.nlp.pipeline.StanfordCoreNLP)3 SemanticGraph (edu.stanford.nlp.semgraph.SemanticGraph)3 SemanticGraphCoreAnnotations (edu.stanford.nlp.semgraph.SemanticGraphCoreAnnotations)3 SemanticGraphEdge (edu.stanford.nlp.semgraph.SemanticGraphEdge)3 CoreMap (edu.stanford.nlp.util.CoreMap)3 Description (org.neo4j.procedure.Description)3 LoggerFactory (com.graphaware.common.log.LoggerFactory)2 NLPManager (com.graphaware.nlp.NLPManager)2