Last active
October 24, 2015 22:47
-
-
Save TomDemeranville/abe83b359ddef7232255 to your computer and use it in GitHub Desktop.
Modeling the claims store using Neo4j
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
= Modeling the claims store using Neo4j | |
First, let's add some items to the store. One of the DOIs has two ORCIDs in its metadata. | |
//setup | |
[source,cypher] | |
---- | |
CREATE (doi1:output {name:'10.123/abcd'}) | |
CREATE (orcid1:person {name:'0000-1111-1111-1111'}) | |
CREATE (doi2:output {name:'10.123/efgh'}) | |
CREATE (doi1)-[:CreatedBy]->(orcid1) | |
CREATE (doi2)-[:CreatedBy]->(orcid1) | |
RETURN * | |
---- | |
//graph | |
Now, we're going to import an ORCID record. It contains one of the DOIs. | |
Note how the source of the information can be modeled using the direction of the relationship. | |
//setup | |
[source,cypher] | |
---- | |
MATCH (doi:output{name:"10.123/abcd"}) | |
CREATE (orcid2:person {name:'0000-2222-2222-2222'})-[:Created]->(doi) | |
RETURN * | |
---- | |
//graph | |
We can now do things like find out all person-doi relationships, no matter who asserted them. | |
//setup | |
[source,cypher] | |
---- | |
MATCH (works:output) -[]- (people:person) | |
RETURN works.name,people.name | |
---- | |
//table | |
We can also model things like isPartOF, contains, or both! Things with biderectional relationships are confirmed by Both parties. | |
//setup | |
[source,cypher] | |
---- | |
MATCH (doi:output{name:"10.123/abcd"}) | |
MATCH (doi2:output{name:"10.123/efgh"}) | |
CREATE (doi)-[:contains]->(doi2) | |
CREATE (doi2)-[:isPartOf]->(doi) | |
RETURN * | |
---- | |
//graph | |
We can add organisations, and model the relationships to suit ORCID or DOIs, as funders or creators or affiliations | |
//setup | |
[source,cypher] | |
---- | |
MATCH (doi:output{name:"10.123/abcd"}) | |
MATCH (orcid:person{name:"0000-2222-2222-2222"}) | |
CREATE (o:org {name:'orgID'})-[:Created]->(doi) | |
CREATE (o)-[:Manages]->(g:grant{name:"grantID"})-[:Funded]->(doi) | |
CREATE (orcid)-[:Afiliated]->(o) | |
CREATE (g)-[:funded]->(orcid) | |
RETURN * | |
---- | |
//graph | |
We can even find paths from works to funding | |
//setup | |
[source,cypher] | |
---- | |
MATCH (g:grant{name:'grantID'}), (o:output{name:'10.123/efgh'}), | |
path = shortestPath( (g)<-[*..5]->(o) ) | |
RETURN path | |
---- | |
//table |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment