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