Search in sources :

Example 1 with Word2VecProcessor

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));
}
Also used : SingleResult(com.graphaware.nlp.dsl.result.SingleResult) Word2VecRequest(com.graphaware.nlp.dsl.request.Word2VecRequest) Word2VecProcessor(com.graphaware.nlp.ml.word2vec.Word2VecProcessor)

Example 2 with Word2VecProcessor

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();
}
Also used : ArrayList(java.util.ArrayList) Word2VecModelResult(com.graphaware.nlp.dsl.result.Word2VecModelResult) IOException(java.io.IOException) Word2VecIndexLookup(com.graphaware.nlp.ml.word2vec.Word2VecIndexLookup) Word2VecProcessor(com.graphaware.nlp.ml.word2vec.Word2VecProcessor)

Example 3 with Word2VecProcessor

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());
}
Also used : Word2VecProcessor(com.graphaware.nlp.ml.word2vec.Word2VecProcessor)

Example 4 with Word2VecProcessor

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);
}
Also used : Word2VecProcessor(com.graphaware.nlp.ml.word2vec.Word2VecProcessor)

Example 5 with Word2VecProcessor

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);
}
Also used : Word2VecProcessor(com.graphaware.nlp.ml.word2vec.Word2VecProcessor)

Aggregations

Word2VecProcessor (com.graphaware.nlp.ml.word2vec.Word2VecProcessor)5 Word2VecRequest (com.graphaware.nlp.dsl.request.Word2VecRequest)1 SingleResult (com.graphaware.nlp.dsl.result.SingleResult)1 Word2VecModelResult (com.graphaware.nlp.dsl.result.Word2VecModelResult)1 Word2VecIndexLookup (com.graphaware.nlp.ml.word2vec.Word2VecIndexLookup)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1