1
votes

I want to build a social network graph from Facebook data in neo4j (java). I'm trying to search for relevant examples to understand these concepts but still unable to get any of those specific kinds. Please help me to know how can I achieve it and ,if possible, provide appropriate links where i can get related help.

I want to have node and relationship (edge) properties as follows:

Node properties:
   String id, name, town;
   int numOfFriends;
   Double age;
   Date dateOfJoining
   HashSet<String> postIdSet;

Relationship Properties:
   boolean Knows;
   int numOfLikes, numOfComments;
   float wtLikes, wtComments;
   String relationship;

How can I create a graphDB having nodes and edges with above properties?

I have a sample code structure for creating graphDB and adding nodes and relationships as follows:

GraphDatabaseService graphDB = new GraphDatabaseFactory().newEmbeddedDatabase(DB_PATH);
registerShutdownHook(graphDB);

Transaction tx = graphDB.beginTx();
try {
    /* define relationshipType*/
    RelationshipType rel = DynamicRelationshipType.withName(??);

    /* create new node with given properties*/
    Node node1 = graphDB.createNode();

    /* set node1 properties e.g. node1.id="1234" */

    /* create another new node with given properties */
    Node node2 = graphDB.createNode();

    /* set node2 properties e.g. node1.id="5678" */

    /* search for node with id "1234" */
    Node n1 = getNodeById(graphDB,"1234");

    /* search for node with id "5678" */
    Node n2 = getNodeById(graphDB,"5678");

    /* create relationship between n1 and n2 with above mentioned properties and set their values */
    Relationship relationship = n1.createRelationshipTo(n2, rel);
    relationship.setProperty(??);
    tx.success();
} finally {
    tx.finish();
}

How can I add those different properties to a node or to an edge (relationship)?

How can I search for a node with given String "id" property and updates it's other properties like e.g. numOfFriends?

It'd would be most useful if somebody try to fill up/provide the sample solution code to all/any of queries: (1)adding given set of node properties, (2)adding given set of edge properties, (3)searching for node and anything additional.. This can serve as a quick reference to anybody visiting this question.. Thanks.

2
It'd would be most useful if somebody try to fill up/provide the sample solution code to all/any of queries: (1)adding given set of node properties, (2)adding given set of edge properties, (3)searching for node and anything additional.. This can serve as a quick reference to anybody visiting this question.. Thanks. - N D Thokare
you mean edit inline in your question? - Michael Hunger
That's why there's a manual- to serve as a reference...the code is in it if you read through the chapter. - Luanne
@MichaelHunger not inline with question, but just a relevant patch of code for any of 3 queries, however possible... - N D Thokare
@Luanne I know there is manual for such information.. but for newbies like me, it would help for quick learning if we get sample code and then go through manual/documentation instead of directly going through manual (which can takes a lot of time even to understand simple concepts) - N D Thokare

2 Answers

6
votes

Just set the properties using node.setProperty or relationship.setProperty

Searching: you can use Cypher to execute a query to fetch back the node, properties and relations or you an use the index to look up the node and then do a node.getProperty.

All in the manual: http://docs.neo4j.org/chunked/stable/tutorials-java-embedded.html (assuming you use embedded based on your code)

BTW: tx.success() needs to be called after you've finished your node/rel operations.

0
votes

Here's a bunch of gists I've been looking at: http://gist.neo4j.org/

Might give you an idea how to move forward with your project.