Search in sources :

Example 1 with VectorContainer

use of com.graphaware.nlp.domain.VectorContainer in project neo4j-nlp by graphaware.

the class NLPManager method computeVectorAndPersist.

public Node computeVectorAndPersist(ComputeVectorRequest request) {
    try {
        VectorComputation vectorComputation = vectorComputationProcesses.get(request.getType());
        if (vectorComputation == null) {
            throw new RuntimeException("Cannot find the VectorComputation instance with type: " + request.getType());
        }
        VectorHandler vector = vectorComputation.computeSparseVector(request.getInput().getId(), request.getParameters());
        if (vector != null) {
            VectorContainer vectorNode = new VectorContainer(request.getInput().getId(), request.getPropertyName(), vector);
            getPersister(vectorNode.getClass()).persist(vectorNode, request.getLabel(), null);
        }
        return request.getInput();
    } catch (Exception ex) {
        LOG.error("Error in computeVectorAndPersist", ex);
        throw ex;
    }
}
Also used : VectorComputation(com.graphaware.nlp.vector.VectorComputation) NotSupportedException(javax.ws.rs.NotSupportedException) MethodNotSupportedException(org.apache.http.MethodNotSupportedException) VectorHandler(com.graphaware.nlp.vector.VectorHandler) VectorContainer(com.graphaware.nlp.domain.VectorContainer)

Example 2 with VectorContainer

use of com.graphaware.nlp.domain.VectorContainer in project neo4j-nlp by graphaware.

the class VectorPersister method fromNode.

@Override
public VectorContainer fromNode(Node node, Object... properties) {
    String basePropertyname = (String) properties[0];
    String type = (String) node.getProperty(getTypePropertyName(basePropertyname));
    float[] vector = (float[]) node.getProperty(getArrayPropertyName(basePropertyname));
    VectorHandler createVector = VectorFactory.createVector(type, vector);
    return new VectorContainer(node.getId(), basePropertyname, createVector);
}
Also used : VectorHandler(com.graphaware.nlp.vector.VectorHandler) VectorContainer(com.graphaware.nlp.domain.VectorContainer)

Aggregations

VectorContainer (com.graphaware.nlp.domain.VectorContainer)2 VectorHandler (com.graphaware.nlp.vector.VectorHandler)2 VectorComputation (com.graphaware.nlp.vector.VectorComputation)1 NotSupportedException (javax.ws.rs.NotSupportedException)1 MethodNotSupportedException (org.apache.http.MethodNotSupportedException)1