use of com.graphaware.nlp.ml.word2vec.Word2VecProcessor in project neo4j-nlp by graphaware.
the class Word2VecProcedure method attachConcepts.
@Procedure(name = "ga.nlp.ml.word2vec.attach", mode = Mode.WRITE)
@Description("For each tag attach the related word2vec value")
public Stream<SingleResult> attachConcepts(@Name("input") Map<String, Object> word2VecRequest) {
Word2VecRequest request = Word2VecRequest.fromMap(word2VecRequest);
Word2VecProcessor word2VecProcessor = (Word2VecProcessor) getNLPManager().getExtension(Word2VecProcessor.class);
int processed = word2VecProcessor.attach(request);
return Stream.of(new SingleResult(processed));
}
use of com.graphaware.nlp.ml.word2vec.Word2VecProcessor in project neo4j-nlp by graphaware.
the class Word2VecProcedure method listModels.
@Procedure(name = "ga.nlp.ml.word2vec.listModels", mode = Mode.WRITE)
public Stream<Word2VecModelResult> listModels() {
Word2VecProcessor word2VecProcessor = (Word2VecProcessor) getNLPManager().getExtension(Word2VecProcessor.class);
Map<String, Word2VecIndexLookup> models = word2VecProcessor.getWord2VecModel().getModels();
List<Word2VecModelResult> results = new ArrayList<>();
models.keySet().forEach(s -> {
try {
results.add(new Word2VecModelResult(s, models.get(s).getStorePath(), models.get(s).countIndex()));
} catch (IOException e) {
//
}
});
return results.stream();
}
use of com.graphaware.nlp.ml.word2vec.Word2VecProcessor in project neo4j-nlp by graphaware.
the class Word2VecProcedure method addModel.
@Procedure(name = "ga.nlp.ml.word2vec.addModel", mode = Mode.WRITE)
public Stream<SingleResult> addModel(@Name("sourePath") String sourcePath, @Name("destinationPath") String destinationPath, @Name("modelName") String modelName, @Name(defaultValue = "en", value = "language") String language) {
Word2VecProcessor word2VecProcessor = (Word2VecProcessor) getNLPManager().getExtension(Word2VecProcessor.class);
word2VecProcessor.getWord2VecModel().createModelFromPaths(sourcePath, destinationPath, modelName, language);
return Stream.of(SingleResult.success());
}
use of com.graphaware.nlp.ml.word2vec.Word2VecProcessor in project neo4j-nlp by graphaware.
the class Word2VecProcedure method retrieveVector.
@UserFunction(name = "ga.nlp.ml.word2vec.vector")
@Description("Retrieve the embedding vector for the given Tag node")
public List<Double> retrieveVector(@Name("tag") Node tag, @Name(value = "modelName", defaultValue = "") String modelName) {
Word2VecProcessor word2VecProcessor = (Word2VecProcessor) getNLPManager().getExtension(Word2VecProcessor.class);
Double[] doubleArray = ArrayUtils.toObject(word2VecProcessor.getWord2Vec(tag.getProperty("value").toString(), modelName));
return Arrays.asList(doubleArray);
}
use of com.graphaware.nlp.ml.word2vec.Word2VecProcessor in project neo4j-nlp by graphaware.
the class Word2VecProcedure method retrieveVectorForWord.
@UserFunction(name = "ga.nlp.ml.word2vec.wordVector")
@Description("Retrieve the embedding vector for the given word ")
public List<Double> retrieveVectorForWord(@Name("word") String word, @Name(value = "modelName", defaultValue = "") String modelName) {
Word2VecProcessor word2VecProcessor = (Word2VecProcessor) getNLPManager().getExtension(Word2VecProcessor.class);
double[] vector = word2VecProcessor.getWord2Vec(word, modelName);
if (vector == null) {
return null;
}
Double[] doubleArray = ArrayUtils.toObject(vector);
return Arrays.asList(doubleArray);
}
Aggregations