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.
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