Reputation: 585
I am designing a web application that visually shows data from Neo4J. Here is my current annotation:
CREATE (diseasedataset:Dataset { title: 'Disease Dataset', description: 'Dataset about diseases and mapping to cytogenetic location', creator: 'Zach'})
CREATE (diseasedata:Table { title: 'Disease', represents: 'mesh:Disease'})
CREATE (diseasedata)-[:BELONGS_TO]->(diseasedataset)
CREATE (diseaseid:Column { title: 'ID', columntype: 'Property', semanticrelation: 'dct:identifier'})
CREATE (diseaseid)-[:BELONGS_TO]->(diseasedata)
CREATE (diseasename:Column { title: 'Name', columntype: 'Property', semanticrelation: 'skos:preferredLabel'})
CREATE (diseasename)-[:BELONGS_TO]->(diseasedata)
CREATE (diseasedesc:Column { title: 'Descriptions', columntype: 'Property', semanticrelation: 'dct:description'})
CREATE (diseasedesc)-[:BELONGS_TO]->(diseasedata)
CREATE (diseasesymp:Column { title: 'Symptoms', columntype: 'Class', represents: 'mesh:Symptom', semanticrelation: 'syo:Symptom'})
CREATE (diseasedesc)-[:BELONGS_TO]->(diseasedata)
How do I create a table (using a cypher query) that for each row has a [Column] and the collection of attributes for each Column. This is particularly tricky because not every column has the same attributes. For example:
Row | Column | Attributes
1 | dieseaseId | title, columnType, semanticRelation
2 | diseasesymp | title, columnType, represents, semanticRelation
3 (etc.)...
Is their an intuitive way to do this? I'm relatively new to Neo4j and Cypher, and haven't been able to find anything like this online or through the documentation. Thanks for your time and any advice!
Upvotes: 1
Views: 117
Reputation: 10856
I'm not sure that you can do this with one cypher query. You might need to first return the keys and then generate a query which gets those keys. To get the keys, you could return all the data, or in Neo4j 2.2.0 (still a release candidate, but hopefully out soon), you can do this:
MATCH n UNWIND keys(n) AS key RETURN DISTINCT key
That will return you a list on unique keys which are on the nodes which you specify (here I'm doing MATCH n
which matches all nodes. Then you can generate a query which does something like:
MATCH n RETURN n.key1, n.key2, n.key3, ....
Upvotes: 1