Java Code Examples for org.neo4j.graphdb.Node#setProperty()

The following examples show how to use org.neo4j.graphdb.Node#setProperty() . 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: AnswerInfo.java    From SnowGraph with Apache License 2.0 6 votes vote down vote up
public AnswerInfo(Node node, int id, int parentId, String creationDate, int score, String body, int ownerUserId) {
    this.node = node;
    this.answerId = id;
    this.parentQuestionId = parentId;
    this.ownerUserId = ownerUserId;

    node.addLabel(Label.label(StackOverflowExtractor.ANSWER));

    node.setProperty(StackOverflowExtractor.ANSWER_ID, id);
    node.setProperty(StackOverflowExtractor.ANSWER_PARENT_QUESTION_ID, parentId);
    node.setProperty(StackOverflowExtractor.ANSWER_CREATION_DATE, creationDate);
    node.setProperty(StackOverflowExtractor.ANSWER_SCORE, score);
    node.setProperty(StackOverflowExtractor.ANSWER_BODY, body);
    node.setProperty(StackOverflowExtractor.ANSWER_OWNER_USER_ID, ownerUserId);
    node.setProperty(StackOverflowExtractor.ANSWER_ACCEPTED, false);

}
 
Example 2
Source File: MailListExtractor.java    From SnowGraph with Apache License 2.0 6 votes vote down vote up
public void run(GraphDatabaseService db) {
    this.db = db;
    MboxHandler myHandler = new MboxHandler();
    myHandler.setDb(db);
    MimeConfig config=new MimeConfig();
    config.setMaxLineLen(-1);
    parser = new MimeStreamParser(config);
    parser.setContentHandler(myHandler);
    parse(new File(mboxPath));
    try (Transaction tx = db.beginTx()) {
        for (String address : myHandler.getMailUserNameMap().keySet()) {
            Node node = myHandler.getMailUserMap().get(address);
            node.setProperty(MAILUSER_NAMES, String.join(", ", myHandler.getMailUserNameMap().get(address)));
        }
        tx.success();
    }
    try (Transaction tx = db.beginTx()) {
        for (String mailId : myHandler.getMailReplyMap().keySet()) {
            Node mailNode = myHandler.getMailMap().get(mailId);
            Node replyNode = myHandler.getMailMap().get(myHandler.getMailReplyMap().get(mailId));
            if (mailNode != null & replyNode != null)
                mailNode.createRelationshipTo(replyNode, RelationshipType.withName(MailListExtractor.MAIL_IN_REPLY_TO));
        }
        tx.success();
    }
}
 
Example 3
Source File: JavaCodeUtils.java    From SnowGraph with Apache License 2.0 6 votes vote down vote up
public static void createMethodNode(MethodInfo methodInfo, Node node) {
    node.addLabel(Label.label(JavaCodeExtractor.METHOD));
    node.setProperty(JavaCodeExtractor.METHOD_NAME, methodInfo.name);
    node.setProperty(JavaCodeExtractor.METHOD_RETURN, methodInfo.returnString);
    node.setProperty(JavaCodeExtractor.METHOD_ACCESS, methodInfo.visibility);
    node.setProperty(JavaCodeExtractor.METHOD_IS_CONSTRUCTOR, methodInfo.isConstruct);
    node.setProperty(JavaCodeExtractor.METHOD_IS_ABSTRACT, methodInfo.isAbstract);
    node.setProperty(JavaCodeExtractor.METHOD_IS_FINAL, methodInfo.isFinal);
    node.setProperty(JavaCodeExtractor.METHOD_IS_STATIC, methodInfo.isStatic);
    node.setProperty(JavaCodeExtractor.METHOD_IS_SYNCHRONIZED, methodInfo.isSynchronized);
    node.setProperty(JavaCodeExtractor.METHOD_CONTENT, methodInfo.content);
    node.setProperty(JavaCodeExtractor.METHOD_COMMENT, methodInfo.comment);
    node.setProperty(JavaCodeExtractor.METHOD_BELONGTO, methodInfo.belongTo);
    node.setProperty(JavaCodeExtractor.METHOD_PARAMS, methodInfo.paramString);
    node.setProperty(JavaCodeExtractor.METHOD_THROWS, String.join(", ", methodInfo.throwSet));
    node.setProperty(JavaCodeExtractor.SIGNATURE, methodInfo.belongTo+"."+methodInfo.name+"("+methodInfo.paramString+")");
}
 
Example 4
Source File: ReadOptimizedGraphity.java    From metalcon with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void createStatusUpdate(final long timestamp, final Node user,
		final StatusUpdate content) {
	// get last recent status update
	final Node lastUpdate = NeoUtils.getNextSingleNode(user,
			SocialGraphRelationshipType.UPDATE);

	// create new status update node
	final Node crrUpdate = NeoUtils.createStatusUpdateNode(content.getId());

	// prepare status update for JSON parsing
	content.setTimestamp(timestamp);
	content.setCreator(new User(user));

	// fill status update node
	crrUpdate.setProperty(Properties.StatusUpdate.TIMESTAMP, timestamp);
	crrUpdate.setProperty(Properties.StatusUpdate.CONTENT_TYPE,
			content.getType());
	crrUpdate.setProperty(Properties.StatusUpdate.CONTENT, content
			.toJSONObject().toJSONString());

	// update references to previous status update (if existing)
	if (lastUpdate != null) {
		user.getSingleRelationship(SocialGraphRelationshipType.UPDATE,
				Direction.OUTGOING).delete();
		crrUpdate.createRelationshipTo(lastUpdate,
				SocialGraphRelationshipType.UPDATE);
	}

	// add reference from user to current update node
	user.createRelationshipTo(crrUpdate, SocialGraphRelationshipType.UPDATE);
	user.setProperty(Properties.User.LAST_UPDATE, timestamp);

	// update ego network for this user
	this.updateEgoNetwork(user);
}
 
Example 5
Source File: EdgeLabelerTest.java    From SciGraph with Apache License 2.0 5 votes vote down vote up
@Before
public void setup() {
  n1 = createNode("http://x.org/a");
  n2 = createNode("http://x.org/b");
  Node rel = createNode(relationshipType1);
  rel.setProperty(NodeProperties.LABEL, relationshipType1Label);
  createNode(relationshipType2);

  n1.createRelationshipTo(n2, RelationshipType.withName(relationshipType1));
  n1.createRelationshipTo(n2, RelationshipType.withName(relationshipType2));
  n1.createRelationshipTo(n2, RelationshipType.withName(relationshipType3));

  edgeLabeler = new EdgeLabeler(graphDb);
  edgeLabeler.run();
}
 
Example 6
Source File: Neo4jApiTransformationRepairPosLength.java    From trainbenchmark with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public void activate(final Collection<Neo4jPosLengthMatch> matches) {
	for (final Neo4jPosLengthMatch match : matches) {
		final Node segment = match.getSegment();
		try {
			final Number lengthNumber = (Number) segment.getProperty(ModelConstants.LENGTH);
			final int length = Neo4jHelper.numberToInt(lengthNumber);

			segment.setProperty(ModelConstants.LENGTH, -length + 1);
		} catch (final NotFoundException e) {
			// do nothing (node has been removed)
		}
	}
}
 
Example 7
Source File: PatternRecognitionResource.java    From graphify with Apache License 2.0 5 votes vote down vote up
/**
 * Gets a Neo4j node entity that contains the root pattern for performing hierarchical pattern recognition from.
 * @param db The Neo4j graph database service.
 * @return Returns a Neo4j node entity that contains the root pattern for performing hierarchical pattern recognition from.
 */
private static Node getRootPatternNode(GraphDatabaseService db) {
    Node patternNode;
    patternNode = new NodeManager().getOrCreateNode(GRAPH_MANAGER, GraphManager.ROOT_TEMPLATE, db);
    try(Transaction tx = db.beginTx()) {
        if (!patternNode.hasProperty("matches")) {
            patternNode.setProperty("matches", 0);
            patternNode.setProperty("threshold", GraphManager.MIN_THRESHOLD);
            patternNode.setProperty("root", 1);
            patternNode.setProperty("phrase", "{0} {1}");
        }
        tx.success();
    }
    return patternNode;
}
 
Example 8
Source File: Neo4jApiTransformationRepairSwitchMonitored.java    From trainbenchmark with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public void activate(final Collection<Neo4jSwitchMonitoredMatch> matches) {
	for (final Neo4jSwitchMonitoredMatch match : matches) {
		final Node sw = match.getSw();
		final Node sensor = driver.getGraphDb().createNode(Neo4jConstants.labelSensor);
		sensor.setProperty(ModelConstants.ID, driver.generateNewVertexId());
		sw.createRelationshipTo(sensor, Neo4jConstants.relationshipTypeMonitoredBy);
	}
}
 
Example 9
Source File: GraphNodeUtil.java    From SnowGraph with Apache License 2.0 5 votes vote down vote up
public static void createPlainTextNode(PlainTextInfo plainText, Node node) {
    node.addLabel(Label.label(WordKnowledgeExtractor.DOCX_PLAIN_TEXT));
    if(plainText.getText() != null)
        node.setProperty(WordKnowledgeExtractor.PLAIN_TEXT_CONTENT, plainText.toHtml(false));
    /*
    if(plainText.getEnglishText() != null)
        node.setProperty(WordKnowledgeExtractor.PLAIN_TEXT_ENGLISH_CONTENT, plainText.toHtml(true));
        */
    else node.setProperty(WordKnowledgeExtractor.PLAIN_TEXT_CONTENT, "");
}
 
Example 10
Source File: NeoUtils.java    From metalcon with GNU General Public License v3.0 5 votes vote down vote up
/**
 * create a user node in the active database
 * 
 * @param userId
 *            user identifier
 * @return user node having its identifier stored
 * @throws IllegalArgumentException
 *             if the identifier is already in use
 */
public static Node createUserNode(final String userId) {
	if (INDEX_USERS.get(IDENTIFIER, userId).getSingle() == null) {
		final Node user = DATABASE.createNode();
		user.setProperty(Properties.User.IDENTIFIER, userId);
		INDEX_USERS.add(user, IDENTIFIER, userId);
		return user;
	}

	throw new IllegalArgumentException("user node with identifier \""
			+ userId + "\" already existing!");
}
 
Example 11
Source File: Neo4jApiTransformationInjectSwitchSet.java    From trainbenchmark with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public void activate(final Collection<Neo4jSwitchSetInjectMatch> matches) {
	for (final Neo4jSwitchSetInjectMatch match : matches) {
		final Node sw = match.getSw();
		final String currentPositionString = (String) sw.getProperty(ModelConstants.CURRENTPOSITION);
		final Position currentPosition = Position.valueOf(currentPositionString);
		final Position newCurrentPosition = Position.values()[(currentPosition.ordinal() + 1) % Position.values().length];
		sw.setProperty(ModelConstants.CURRENTPOSITION, newCurrentPosition.toString());
	}
}
 
Example 12
Source File: Neo4jGraphDatabase.java    From graphdb-benchmarks with Apache License 2.0 5 votes vote down vote up
@Override
public int reInitializeCommunities()
{
    Map<Integer, Integer> initCommunities = new HashMap<Integer, Integer>();
    int communityCounter = 0;

    try (final Transaction tx = beginUnforcedTransaction())
    {
        try
        {
            for (Node n : GlobalGraphOperations.at(neo4jGraph).getAllNodes())
            {
                Integer communityId = (Integer) (n.getProperty(COMMUNITY));
                if (!initCommunities.containsKey(communityId))
                {
                    initCommunities.put(communityId, communityCounter);
                    communityCounter++;
                }
                int newCommunityId = initCommunities.get(communityId);
                n.setProperty(COMMUNITY, newCommunityId);
                n.setProperty(NODE_COMMUNITY, newCommunityId);
            }
            tx.success();
        }
        catch (Exception e)
        {
            tx.failure();
            throw new BenchmarkingException("unable to reinitialize communities", e);
        }
    }

    return communityCounter;
}
 
Example 13
Source File: GitCommit.java    From SnowGraph with Apache License 2.0 5 votes vote down vote up
public Node createNode(GraphDatabaseService db){
    Node node=db.createNode();
    node.addLabel(Label.label(GitExtractor.COMMIT));
    node.setProperty(GitExtractor.COMMIT_ID,commitId);
    node.setProperty(GitExtractor.COMMIT_DATE,createDate);
    node.setProperty(GitExtractor.COMMIT_LOGMESSAGE,logMessage);
    node.setProperty(GitExtractor.COMMIT_CONTENT,content);
    return node;
}
 
Example 14
Source File: JiraUtils.java    From SnowGraph with Apache License 2.0 5 votes vote down vote up
public static void createIssueUserNode(IssueUserInfo issueUserInfo, Node node) {
    node.addLabel(Label.label(JiraExtractor.ISSUEUSER));
    node.setProperty(JiraExtractor.ISSUEUSER_NAME, issueUserInfo.getName());
    node.setProperty(JiraExtractor.ISSUEUSER_EMAIL_ADDRESS, issueUserInfo.getName());
    node.setProperty(JiraExtractor.ISSUEUSER_DISPLAY_NAME, issueUserInfo.getName());
    node.setProperty(JiraExtractor.ISSUEUSER_ACTIVE, issueUserInfo.getName());
}
 
Example 15
Source File: PageRank.java    From Neo4jSNA with Apache License 2.0 5 votes vote down vote up
@Override
public void apply(Node node) {
	double secondMember = 0.0;
	for( Relationship rin : node.getRelationships() ) {
		Node neigh = rin.getOtherNode(node);
		
		double neighRank = (double) neigh.getProperty(attName);
		secondMember += neighRank / neigh.getDegree();
	}
	
	secondMember *= this.dampingFactor;
	node.setProperty(attName, firstMember + secondMember);
}
 
Example 16
Source File: JiraUtils.java    From SnowGraph with Apache License 2.0 5 votes vote down vote up
public static void createPatchNode(PatchInfo patchInfo, Node node) {
    node.addLabel(Label.label(JiraExtractor.PATCH));
    node.setProperty(JiraExtractor.PATCH_ISSUE_ID, patchInfo.getIssueId());
    node.setProperty(JiraExtractor.PATCH_ID, patchInfo.getPatchId());
    node.setProperty(JiraExtractor.PATCH_NAME, patchInfo.getPatchName());
    node.setProperty(JiraExtractor.PATCH_CONTENT, patchInfo.getContent());
    node.setProperty(JiraExtractor.PATCH_CREATOR_NAME, patchInfo.getCreatorName());
    node.setProperty(JiraExtractor.PATCH_CREATED_DATE, patchInfo.getCreatedDate());
}
 
Example 17
Source File: DL4JMLModel.java    From neo4j-ml-procedures with Apache License 2.0 5 votes vote down vote up
@Override
    List<Node> show() {
        if ( state != State.ready ) throw new IllegalStateException("Model not trained yet");
        List<Node> result = new ArrayList<>();
        int layerCount = model.getnLayers();
        for (Layer layer : model.getLayers()) {
            Node node = node("Layer",
                    "type", layer.type().name(), "index", layer.getIndex(),
                    "pretrainLayer", layer.isPretrainLayer(), "miniBatchSize", layer.getInputMiniBatchSize(),
                    "numParams", layer.numParams());
            if (layer instanceof DenseLayer) {
                DenseLayer dl = (DenseLayer) layer;
                node.addLabel(Label.label("DenseLayer"));
                node.setProperty("activation",dl.getActivationFn().toString()); // todo parameters
                node.setProperty("biasInit",dl.getBiasInit());
                node.setProperty("biasLearningRate",dl.getBiasLearningRate());
                node.setProperty("l1",dl.getL1());
                node.setProperty("l1Bias",dl.getL1Bias());
                node.setProperty("l2",dl.getL2());
                node.setProperty("l2Bias",dl.getL2Bias());
                node.setProperty("distribution",dl.getDist().toString());
                node.setProperty("in",dl.getNIn());
                node.setProperty("out",dl.getNOut());
            }
            result.add(node);
//            layer.preOutput(allOne, Layer.TrainingMode.TEST);
//            layer.p(allOne, Layer.TrainingMode.TEST);
//            layer.activate(allOne, Layer.TrainingMode.TEST);
        }
        return result;
    }
 
Example 18
Source File: ConnectedComponents.java    From Neo4jSNA with Apache License 2.0 4 votes vote down vote up
@Override
public void apply(Node node) {
	long newComponent = this.getLowestComponent(node);
	node.setProperty(attName, newComponent);
}
 
Example 19
Source File: LabelPropagation.java    From Neo4jSNA with Apache License 2.0 4 votes vote down vote up
@Override
public void init(Node node) {
	node.setProperty(attName, node.getId());
}
 
Example 20
Source File: SocialGraph.java    From metalcon with GNU General Public License v3.0 3 votes vote down vote up
/**
 * create a new user
 * 
 * @param userId
 *            user identifier
 * @param displayName
 *            user display name
 * @param profilePicturePath
 *            path to the profile picture of the user
 */
public void createUser(final String userId, final String displayName,
		final String profilePicturePath) {
	final Node user = NeoUtils.createUserNode(userId);
	user.setProperty(Properties.User.DISPLAY_NAME, displayName);
	user.setProperty(Properties.User.PROFILE_PICTURE_PATH,
			profilePicturePath);
}