org.neo4j.procedure.Procedure Java Examples

The following examples show how to use org.neo4j.procedure.Procedure. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: Get.java    From neo4j-versioner-core with Apache License 2.0 6 votes vote down vote up
@Procedure(value = "graph.versioner.get.all", mode = DEFAULT)
@Description("graph.versioner.get.all(entity) - Get all the State nodes for the given Entity.")
public Stream<PathOutput> getAllState(
        @Name("entity") Node entity) {

    PathImpl.Builder builder = new PathImpl.Builder(entity)
            .push(entity.getSingleRelationship(RelationshipType.withName(Utility.CURRENT_TYPE), Direction.OUTGOING));
    builder = StreamSupport.stream(entity.getRelationships(RelationshipType.withName(Utility.HAS_STATE_TYPE), Direction.OUTGOING).spliterator(), false)
            //.sorted((a, b) -> -1 * Long.compare((long)a.getProperty(START_DATE_PROP), (long)b.getProperty(START_DATE_PROP)))
            .reduce(
                    builder,
                    (build, rel) -> Optional.ofNullable(rel.getEndNode().getSingleRelationship(RelationshipType.withName(Utility.PREVIOUS_TYPE), Direction.OUTGOING))
                                        .map(build::push)
                                        .orElse(build),
                    (a, b) -> a);
    return Stream.of(new PathOutput(builder.build()));
}
 
Example #2
Source File: Init.java    From neo4j-versioner-core with Apache License 2.0 6 votes vote down vote up
@Procedure(value = "graph.versioner.init", mode = Mode.WRITE)
@Description("graph.versioner.init(entityLabel, {key:value,...}, {key:value,...}, additionalLabel, date) - Create an Entity node with an optional initial State.")
public Stream<NodeOutput> init(
        @Name("entityLabel") String entityLabel,
        @Name(value = "entityProps", defaultValue = "{}") Map<String, Object> entityProps,
        @Name(value = "stateProps", defaultValue = "{}") Map<String, Object> stateProps,
        @Name(value = "additionalLabel", defaultValue = "") String additionalLabel,
        @Name(value = "date", defaultValue = "null") LocalDateTime date) {

    Node entity = createNode(entityProps, singletonList(entityLabel));

    Node state = createNode(stateProps, getStateLabels(additionalLabel));

    connectWithCurrentRelationship(entity, state, date);

    log.info(LOGGER_TAG + "Created a new Entity with label {} and id {}", entityLabel, entity.getId());

    createRNodeAndAssociateTo(entity);

    return streamOfNodes(entity);
}
 
Example #3
Source File: RelationshipProcedure.java    From neo4j-versioner-core with Apache License 2.0 6 votes vote down vote up
@Procedure(value = "graph.versioner.relationship.create", mode = Mode.WRITE)
@Description("graph.versioner.relationship.create(entityA, entityB, type, relProps, date) - Create a relationship from entitySource to entityDestination with the given type and/or properties for the specified date.")
public Stream<RelationshipOutput> relationshipCreate(
        @Name("entitySource") Node entitySource,
        @Name("entityDestination") Node entityDestination,
        @Name(value = "type") String type,
        @Name(value = "relProps", defaultValue = "{}") Map<String, Object> relProps,
        @Name(value = "date", defaultValue = "null") LocalDateTime date) {

    isEntityOrThrowException(entitySource);
    isEntityOrThrowException(entityDestination);

    Optional<Node> sourceCurrentState = createNewSourceState(entitySource, defaultToNow(date));
    Optional<Node> destinationRNode = getRNode(entityDestination);

    if (sourceCurrentState.isPresent() && destinationRNode.isPresent()) {
        return streamOfRelationships(createRelationship(sourceCurrentState.get(), destinationRNode.get(), type, relProps));
    } else {
        return Stream.empty();
    }
}
 
Example #4
Source File: Rollback.java    From neo4j-versioner-core with Apache License 2.0 5 votes vote down vote up
@Procedure(value = "graph.versioner.rollback.nth", mode = WRITE)
@Description("graph.versioner.rollback.nth(entity, nth-state, date) - Rollback the given Entity to the nth previous State")
public Stream<NodeOutput> rollbackNth(
        @Name("entity") Node entity,
        @Name("state") long nthState,
        @Name(value = "date", defaultValue = "null") LocalDateTime date) {

    LocalDateTime instantDate = defaultToNow(date);

    return new GetBuilder().build()
            .flatMap(get -> get.getNthState(entity, nthState).findFirst())
            .map(state -> rollbackTo(entity, state.node, instantDate))
            .orElse(Stream.empty());
}
 
Example #5
Source File: Get.java    From neo4j-versioner-core with Apache License 2.0 5 votes vote down vote up
@Procedure(value = "graph.versioner.get.nth.state", mode = DEFAULT)
@Description("graph.versioner.get.nth.state(entity, nth) - Get the nth State node for the given Entity.")
public Stream<NodeOutput> getNthState(
		@Name("entity") Node entity,
		@Name("nth") long nth) {

   	return getCurrentState(entity)
			.findFirst()
			.flatMap(currentState -> getNthStateFrom(currentState.node, nth))
			.map(Utility::streamOfNodes)
			.orElse(Stream.empty());
}
 
Example #6
Source File: Get.java    From neo4j-versioner-core with Apache License 2.0 5 votes vote down vote up
@Procedure(value = "graph.versioner.get.by.date", mode = DEFAULT)
@Description("graph.versioner.get.by.date(entity, date) - Get State node by the given Entity node, created at the given date")
public Stream<NodeOutput> getStateByDate(
        @Name("entity") Node entity,
        @Name("date") LocalDateTime date) {

    return StreamSupport.stream(entity.getRelationships(RelationshipType.withName(Utility.HAS_STATE_TYPE), Direction.OUTGOING).spliterator(), false)
            .filter(relationship -> relationship.getProperty(Utility.START_DATE_PROP).equals(date))
            .map(Relationship::getEndNode)
            .map(NodeOutput::new);
}
 
Example #7
Source File: Get.java    From neo4j-versioner-core with Apache License 2.0 5 votes vote down vote up
@Procedure(value = "graph.versioner.get.by.label", mode = DEFAULT)
@Description("graph.versioner.get.by.label(entity, label) - Get State nodes with the given label, by the given Entity node")
public Stream<NodeOutput> getAllStateByLabel(
        @Name("entity") Node entity,
        @Name("label") String label) {

    return StreamSupport.stream(entity.getRelationships(RelationshipType.withName(Utility.HAS_STATE_TYPE), Direction.OUTGOING).spliterator(), false)
            .map(Relationship::getEndNode)
            .filter(node -> node.hasLabel(Label.label(label)))
            .map(NodeOutput::new);
}
 
Example #8
Source File: Get.java    From neo4j-versioner-core with Apache License 2.0 5 votes vote down vote up
@Procedure(value = "graph.versioner.get.current.state", mode = DEFAULT)
@Description("graph.versioner.get.current.state(entity) - Get the current State node for the given Entity.")
public Stream<NodeOutput> getCurrentState(
        @Name("entity") Node entity) {

    return Stream.of(Optional.ofNullable(entity.getSingleRelationship(RelationshipType.withName(Utility.CURRENT_TYPE), Direction.OUTGOING))
            .map(Relationship::getEndNode).map(NodeOutput::new).orElse(null));
}
 
Example #9
Source File: Get.java    From neo4j-versioner-core with Apache License 2.0 5 votes vote down vote up
@Procedure(value = "graph.versioner.get.current.path", mode = DEFAULT)
@Description("graph.versioner.get.current.path(entity) - Get the current Path (Entity, State and rels) for the given Entity.")
public Stream<PathOutput> getCurrentPath(
        @Name("entity") Node entity) {

    PathImpl.Builder builder = new PathImpl.Builder(entity);

    builder = Optional.ofNullable(entity.getSingleRelationship(RelationshipType.withName(Utility.CURRENT_TYPE), Direction.OUTGOING))
            .map(builder::push)
            .orElse(new PathImpl.Builder(entity));

    return Stream.of(builder.build()).map(PathOutput::new);
}
 
Example #10
Source File: Diff.java    From neo4j-versioner-core with Apache License 2.0 5 votes vote down vote up
@Procedure(value = "graph.versioner.diff.from.current", mode = DEFAULT)
@Description("graph.versioner.diff.from.current(state) - Get a list of differences that must be applied to the given state in order to become the current entity state")
public Stream<DiffOutput> diffFromCurrent(
		@Name("state") Node state) {

	return Optional.ofNullable(state.getSingleRelationship(RelationshipType.withName(Utility.HAS_STATE_TYPE), Direction.INCOMING))
			.map(Relationship::getStartNode)
			.map(entity -> entity.getSingleRelationship(RelationshipType.withName(Utility.CURRENT_TYPE), Direction.OUTGOING))
			.map(Relationship::getEndNode)
			.filter(current -> !current.equals(state))
			.map(current -> diffBetweenStates(state, current))
			.orElse(Stream.empty());
}
 
Example #11
Source File: Diff.java    From neo4j-versioner-core with Apache License 2.0 5 votes vote down vote up
@Procedure(value = "graph.versioner.diff.from.previous", mode = DEFAULT)
  @Description("graph.versioner.diff.from.previous(state) - Get a list of differences that must be applied to the previous statusof the given one in order to become the given state")
  public Stream<DiffOutput> diffFromPrevious(
          @Name("state") Node state) {

return Optional.ofNullable(state.getSingleRelationship(RelationshipType.withName(Utility.PREVIOUS_TYPE), Direction.OUTGOING))
		.map(Relationship::getEndNode)
		.map(sFrom -> diffBetweenStates(sFrom, state))
		.orElse(Stream.empty());
  }
 
Example #12
Source File: Diff.java    From neo4j-versioner-core with Apache License 2.0 5 votes vote down vote up
@Procedure(value = "graph.versioner.diff", mode = DEFAULT)
@Description("graph.versioner.diff(stateFrom, stateTo) - Get a list of differences that must be applied to stateFrom in order to convert it into stateTo")
public Stream<DiffOutput> diff(
        @Name("stateFrom") Node stateFrom,
        @Name("stateTo") Node stateTo) {
    return diffBetweenStates(stateFrom, stateTo);
}
 
Example #13
Source File: Update.java    From neo4j-versioner-core with Apache License 2.0 5 votes vote down vote up
@Procedure(value = "graph.versioner.patch.from", mode = Mode.WRITE)
@Description("graph.versioner.patch.from(entity, state, useCurrentRel, date) - Add a new State to the given Entity, starting from the given one. It will update all the properties, not asLabels. If useCurrentRel is false, it will replace the current rels to Rs with the state ones.")
public Stream<NodeOutput> patchFrom(
        @Name("entity") Node entity,
        @Name("state") Node state,
        @Name(value = "useCurrentRel", defaultValue = "true") Boolean useCurrentRel,
        @Name(value = "date", defaultValue = "null") LocalDateTime date) {

    LocalDateTime instantDate = defaultToNow(date);
    List<String> labels = streamOfIterable(state.getLabels()).map(Label::name).collect(Collectors.toList());

    checkRelationship(entity, state);

    Optional<Relationship> currentRelationshipOpt = getCurrentRelationship(entity);

    Node newState = currentRelationshipOpt
            .map(currentRelationship -> createPatchedState(state.getAllProperties(), labels, instantDate, currentRelationship))
            .orElseThrow(() -> new VersionerCoreException("Can't find any current State node for the given entity."));

    //Copy all the relationships
    if (useCurrentRel) {
        currentRelationshipOpt.ifPresent(rel -> connectStateToRs(rel.getEndNode()   , newState));
    } else {
        connectStateToRs(state, newState);
    }

    log.info(LOGGER_TAG + "Patched Entity with id {}, adding a State with id {}", entity.getId(), newState.getId());

    return Stream.of(new NodeOutput(newState));
}
 
Example #14
Source File: Update.java    From neo4j-versioner-core with Apache License 2.0 5 votes vote down vote up
@Procedure(value = "graph.versioner.patch", mode = Mode.WRITE)
@Description("graph.versioner.patch(entity, {key:value,...}, additionalLabel, date) - Add a new State to the given Entity, starting from the previous one. It will update all the properties, not asLabels.")
public Stream<NodeOutput> patch(
        @Name("entity") Node entity,
        @Name(value = "stateProps", defaultValue = "{}") Map<String, Object> stateProps,
        @Name(value = "additionalLabel", defaultValue = "") String additionalLabel,
        @Name(value = "date", defaultValue = "null") LocalDateTime date) {

    List<String> labelNames = getStateLabels(additionalLabel);
    LocalDateTime instantDate = defaultToNow(date);
    Optional<Relationship> currentRelationshipOpt = getCurrentRelationship(entity);

    // Creating the new current state
    Node newState = currentRelationshipOpt
            .map(currentRelationship -> createPatchedState(stateProps, labelNames, instantDate, currentRelationship))
            .orElseGet(() -> {
                Node result = setProperties(db.createNode(asLabels(labelNames)), stateProps);
                addCurrentState(result, entity, instantDate);
                return result;
            });

    //Copy all the relationships
    currentRelationshipOpt.ifPresent(rel -> connectStateToRs(rel.getEndNode(), newState));

    log.info(LOGGER_TAG + "Patched Entity with id {}, adding a State with id {}", entity.getId(), newState.getId());

    return Stream.of(new NodeOutput(newState));
}
 
Example #15
Source File: RelationshipProcedure.java    From neo4j-versioner-core with Apache License 2.0 5 votes vote down vote up
@Procedure(value = "graph.versioner.relationship.delete", mode = Mode.WRITE)
@Description("graph.versioner.relationship.delete(entityA, entityB, type, date) - Delete a custom type relationship from entitySource's current State to entityDestination for the specified date.")
public Stream<BooleanOutput> relationshipDelete(
        @Name("entitySource") Node entitySource,
        @Name("entityDestination") Node entityDestination,
        @Name(value = "type") String type,
        @Name(value = "date", defaultValue = "null") LocalDateTime date) {

    isEntityOrThrowException(entitySource);
    isEntityOrThrowException(entityDestination);
    if (isSystemType(type)) {
        throw new VersionerCoreException("It's not possible to delete a System Relationship like " + type + ".");
    }

    Optional<Node> sourceCurrentState = createNewSourceState(entitySource, defaultToNow(date));
    Optional<Node> destinationRNode = getRNode(entityDestination);

    Update updateProcedure = new UpdateBuilder().withLog(log).withDb(db).build().orElseThrow(() -> new VersionerCoreException("Unable to initialize update procedure"));

    if (sourceCurrentState.isPresent() && destinationRNode.isPresent()) {
        updateProcedure.update(entitySource, sourceCurrentState.get().getAllProperties(), "", null);
        getCurrentRelationship(entitySource).ifPresent(rel -> rel.getEndNode().getRelationships(RelationshipType.withName(type), Direction.OUTGOING).forEach(Relationship::delete));
        return Stream.of(new BooleanOutput(Boolean.TRUE));
    } else {
        return Stream.of(new BooleanOutput(Boolean.FALSE));
    }
}
 
Example #16
Source File: Schema.java    From decision_trees_with_rules with MIT License 5 votes vote down vote up
@Procedure(name = "com.maxdemarzi.schema.generate", mode = Mode.SCHEMA)
@Description("CALL com.maxdemarzi.schema.generate() - generate schema")

public Stream<StringResult> generate() throws IOException {
    org.neo4j.graphdb.schema.Schema schema = db.schema();
    if (!schema.getIndexes(Labels.Tree).iterator().hasNext()) {
        schema.constraintFor(Labels.Tree)
                .assertPropertyIsUnique("id")
                .create();
    }
    return Stream.of(new StringResult("Schema Generated"));
}
 
Example #17
Source File: ML.java    From neo4j-ml-procedures with Apache License 2.0 5 votes vote down vote up
@Procedure
public Stream<PredictionResult> predict(@Name("model") String model, @Name("inputs") Map<String,Object> inputs) {
    MLModel mlModel = MLModel.from(model);
    Object value = mlModel.predict(inputs);
    double confidence = 0.0d;
    return Stream.of(new PredictionResult(value, confidence));
}
 
Example #18
Source File: DeepGLProc.java    From ml-models with Apache License 2.0 5 votes vote down vote up
@Procedure(value = "embedding.deepgl.stream")
public Stream<DeepGL.Result> deepGLStream(
        @Name(value = "label", defaultValue = "") String label,
        @Name(value = "relationship", defaultValue = "") String relationship,
        @Name(value = "config", defaultValue = "{}") Map<String, Object> config) {

    final ProcedureConfiguration configuration = ProcedureConfiguration.create(config);

    int iterations = configuration.getInt("iterations", 10);
    int diffusions = configuration.getInt("diffusions", 10);
    double pruningLambda = configuration.get("pruningLambda", 0.1);

    final HeavyGraph graph = (HeavyGraph) new GraphLoader(api, Pools.DEFAULT)
            .init(log, label, relationship, configuration)
            .withoutNodeProperties()
            .withDirection(configuration.getDirection(Direction.BOTH))
            .withOptionalNodeProperties(extractNodeFeatures(config))
            .load(configuration.getGraphImpl());

    if (graph.nodeCount() == 0) {
        return Stream.empty();
    }

    DeepGL algo = new DeepGL(graph,
            Pools.DEFAULT,
            configuration.getConcurrency(),
            iterations,
            pruningLambda,
            diffusions);
    algo.withProgressLogger(ProgressLogger.wrap(log, "DeepGL"));

    algo.compute();
    graph.release();

    return algo.resultStream();
}
 
Example #19
Source File: CustomerProcedures.java    From ongdb-lab-apoc with Apache License 2.0 5 votes vote down vote up
@Procedure(value = "zdr.index.search", mode = Mode.WRITE)
@Description("CALL zdr.index.search(String indexName, String query, long limit) YIELD node,执行LUCENE全文检索,返回前{limit个结果}")
public Stream<ChineseHit> search(@Name("indexName") String indexName, @Name("query") String query, @Name("limit") long limit) {
    if (!db.index().existsForNodes(indexName)) {
        log.debug("如果索引不存在则跳过本次查询:`%s`", indexName);
        return Stream.empty();
    }
    return db.index()
            .forNodes(indexName)
            .query(new QueryContext(query).sortByScore().top((int) limit))
            .stream()
            .map(ChineseHit::new);
}
 
Example #20
Source File: Rollback.java    From neo4j-versioner-core with Apache License 2.0 4 votes vote down vote up
@Procedure(value = "graph.versioner.rollback.to", mode = WRITE)
@Description("graph.versioner.rollback.to(entity, state, date) - Rollback the given Entity to the given State")
public Stream<NodeOutput> rollbackTo(
        @Name("entity") Node entity,
        @Name("state") Node state,
        @Name(value = "date", defaultValue = "null") LocalDateTime date) {

    LocalDateTime instantDate = defaultToNow(date);
    Optional<Node> newState = Optional.empty();

    Utility.checkRelationship(entity, state);

    // If the given State is the CURRENT one, null must be returned
    Spliterator<Relationship> currentRelIterator = state.getRelationships(RelationshipType.withName(Utility.CURRENT_TYPE), Direction.INCOMING).spliterator();
    Optional<Relationship> currentRelationshipOptional = StreamSupport.stream(currentRelIterator, false).filter(Objects::nonNull).findFirst();
    if (!currentRelationshipOptional.isPresent()) {
        // If the given State already has a ROLLBACK relationship, null must be returned
        Spliterator<Relationship> rollbackRelIterator = state.getRelationships(RelationshipType.withName(Utility.ROLLBACK_TYPE), Direction.OUTGOING).spliterator();
        Optional<Relationship> rollbackRelationshipOptional = StreamSupport.stream(rollbackRelIterator, false).filter(Objects::nonNull).findFirst();
        if (!rollbackRelationshipOptional.isPresent()) {
            // Otherwise, the node can be rolled back
            currentRelIterator = entity.getRelationships(RelationshipType.withName(Utility.CURRENT_TYPE), Direction.OUTGOING).spliterator();
            currentRelationshipOptional = StreamSupport.stream(currentRelIterator, false).filter(Objects::nonNull).findFirst();

            newState = currentRelationshipOptional.map(currentRelationship -> {
                Node currentState = currentRelationship.getEndNode();
                LocalDateTime currentDate = (LocalDateTime) currentRelationship.getProperty("date");

                // Creating the rollback state, from the previous one
                Node result = Utility.cloneNode(db, state);

                //Creating ROLLBACK_TYPE relationship
                result.createRelationshipTo(state, RelationshipType.withName(Utility.ROLLBACK_TYPE));

                // Updating CURRENT state
                result = Utility.currentStateUpdate(entity, instantDate, currentRelationship, currentState, currentDate, result);

                //Copy all the relationships
                connectStateToRs(state, result);

                log.info(Utility.LOGGER_TAG + "Rollback executed for Entity with id {}, adding a State with id {}", entity.getId(), result.getId());

                return Optional.of(result);
            }).orElseGet(() -> {
                log.info(Utility.LOGGER_TAG + "Failed rollback for Entity with id {}, there is no CURRENT State available", entity.getId());
                return Optional.empty();
            });
        }
    }

    return newState.map(Utility::streamOfNodes).orElse(Stream.empty());
}
 
Example #21
Source File: Rollback.java    From neo4j-versioner-core with Apache License 2.0 4 votes vote down vote up
@Procedure(value = "graph.versioner.rollback", mode = WRITE)
@Description("graph.versioner.rollback(entity, date) - Rollback the given Entity to its previous State")
public Stream<NodeOutput> rollback(
        @Name("entity") Node entity,
        @Name(value = "date", defaultValue = "null") LocalDateTime date) {

    LocalDateTime instantDate = defaultToNow(date);

    // Getting the CURRENT rel if it exists
    Spliterator<Relationship> currentRelIterator = entity.getRelationships(RelationshipType.withName(Utility.CURRENT_TYPE), Direction.OUTGOING).spliterator();
    Optional<Relationship> currentRelationshipOptional = StreamSupport.stream(currentRelIterator, false).filter(Objects::nonNull).findFirst();

    Optional<Node> newState = currentRelationshipOptional.map(currentRelationship -> {

        Node currentState = currentRelationship.getEndNode();

        return getFirstAvailableRollbackNode(currentState).map(rollbackState -> {
            LocalDateTime currentDate = (LocalDateTime) currentRelationship.getProperty("date");

            // Creating the rollback state, from the previous one
            Node result = Utility.cloneNode(db, rollbackState);

            //Creating ROLLBACK_TYPE relationship
            result.createRelationshipTo(rollbackState, RelationshipType.withName(Utility.ROLLBACK_TYPE));

            // Updating CURRENT state
            result = Utility.currentStateUpdate(entity, instantDate, currentRelationship, currentState, currentDate, result);

            //Copy all the relationships
            connectStateToRs(rollbackState, result);

            log.info(Utility.LOGGER_TAG + "Rollback executed for Entity with id {}, adding a State with id {}", entity.getId(), result.getId());
            return Optional.of(result);
        }).orElseGet(() -> {
            log.info(Utility.LOGGER_TAG + "Failed rollback for Entity with id {}, only one CURRENT State available", entity.getId());
            return Optional.empty();
        });
    }).orElseGet(() -> {
        log.info(Utility.LOGGER_TAG + "Failed rollback for Entity with id {}, there is no CURRENT State available", entity.getId());
        return Optional.empty();
    });

    return newState.map(Utility::streamOfNodes).orElse(Stream.empty());
}
 
Example #22
Source File: Update.java    From neo4j-versioner-core with Apache License 2.0 4 votes vote down vote up
@Procedure(value = "graph.versioner.update", mode = Mode.WRITE)
@Description("graph.versioner.update(entity, {key:value,...}, additionalLabel, date) - Add a new State to the given Entity.")
public Stream<NodeOutput> update(
        @Name("entity") Node entity,
        @Name(value = "stateProps", defaultValue = "{}") Map<String, Object> stateProps,
        @Name(value = "additionalLabel", defaultValue = "") String additionalLabel,
        @Name(value = "date", defaultValue = "null") LocalDateTime date) {

    // Creating the new State
    List<String> labelNames = new ArrayList<>(Collections.singletonList(STATE_LABEL));
    if (!additionalLabel.isEmpty()) {
        labelNames.add(additionalLabel);
    }
    Node result = setProperties(db.createNode(asLabels(labelNames)), stateProps);

    LocalDateTime instantDate = defaultToNow(date);

    // Getting the CURRENT rel if it exist
    Spliterator<Relationship> currentRelIterator = entity.getRelationships(RelationshipType.withName(CURRENT_TYPE), Direction.OUTGOING).spliterator();
    StreamSupport.stream(currentRelIterator, false).forEach(currentRel -> {
        Node currentState = currentRel.getEndNode();

        LocalDateTime currentDate = (LocalDateTime) currentRel.getProperty("date");

        // Creating PREVIOUS relationship between the current and the new State
        result.createRelationshipTo(currentState, RelationshipType.withName(PREVIOUS_TYPE)).setProperty(DATE_PROP, currentDate);

        // Updating the HAS_STATE rel for the current node, adding endDate
        currentState.getRelationships(RelationshipType.withName(HAS_STATE_TYPE), Direction.INCOMING)
                .forEach(hasStatusRel -> hasStatusRel.setProperty(END_DATE_PROP, instantDate));

        // Refactoring current relationship and adding the new ones
        currentRel.delete();

        // Connecting the new current state to Rs
        connectStateToRs(currentState, result);
    });

    // Connecting the new current state to the Entity
    addCurrentState(result, entity, instantDate);

    log.info(LOGGER_TAG + "Updated Entity with id {}, adding a State with id {}", entity.getId(), result.getId());

    return Stream.of(new NodeOutput(result));
}
 
Example #23
Source File: ML.java    From neo4j-ml-procedures with Apache License 2.0 4 votes vote down vote up
@Procedure
public Stream<ModelResult> train(@Name("model") String model) {
    MLModel mlModel = MLModel.from(model);
    mlModel.train();
    return Stream.of(mlModel.asResult());
}
 
Example #24
Source File: ML.java    From neo4j-ml-procedures with Apache License 2.0 4 votes vote down vote up
@Procedure
public Stream<ModelResult> add(@Name("model") String model, @Name("inputs") Map<String,Object> inputs, @Name("outputs") Object output) {
    MLModel mlModel = MLModel.from(model);
    mlModel.add(inputs,output);
    return Stream.of(mlModel.asResult());
}
 
Example #25
Source File: ML.java    From neo4j-ml-procedures with Apache License 2.0 4 votes vote down vote up
@Procedure
public Stream<ModelResult> remove(@Name("model") String model) {
    return Stream.of(MLModel.remove(model));
}
 
Example #26
Source File: ML.java    From neo4j-ml-procedures with Apache License 2.0 4 votes vote down vote up
@Procedure
public Stream<ModelResult> info(@Name("model") String model) {
    return Stream.of(MLModel.from(model).asResult());
}
 
Example #27
Source File: ML.java    From neo4j-ml-procedures with Apache License 2.0 4 votes vote down vote up
@Procedure
public Stream<ModelResult> create(@Name("model") String model, @Name("types") Map<String,String> types, @Name(value="output") String output, @Name(value="params",defaultValue="{}") Map<String, Object> config) {
    return Stream.of(MLModel.create(model,types,output,config).asResult());
}
 
Example #28
Source File: Logistic.java    From ml-models with Apache License 2.0 4 votes vote down vote up
@Procedure(value="regression.logistic.delete")
public void delete(@Name("model") String model) {
    LogisticModel.remove(model);
}
 
Example #29
Source File: Logistic.java    From ml-models with Apache License 2.0 4 votes vote down vote up
@Procedure(value="regression.logistic.add")
public void add(@Name("model") String model, @Name("category") String category, @Name("features") Map<String, Object> features) {
    LogisticModel lModel = LogisticModel.from(model);
    lModel.add(category, features);
}
 
Example #30
Source File: Logistic.java    From ml-models with Apache License 2.0 4 votes vote down vote up
@Procedure(value="regression.logistic.create")
public void create(@Name("name") String model, @Name("catagories") List<String> categories, @Name("featureTypes") Map<String, String> types,
                   @Name(value="config", defaultValue="{}") Map<String, Object> config) {
    new LogisticModel(model, categories, types, config);
}