1

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!

Community
  • 1
  • 1
Justin
  • 545
  • 3
  • 7
  • 17
  • I think you intended the last line of your create to be ` CREATE (diseasesymp)-[:BELONGS_TO]->(diseasedata)`? – Dave Bennett Mar 06 '15 at 04:03
  • @DaveBennett, you are correct. Thank you for bringing that to my attention! – Justin Mar 06 '15 at 04:07
  • I see the last column is a variable length collection. Are the number of possible properties on the "Column" nodes at least somewhat finite even though they are variable? – Dave Bennett Mar 06 '15 at 12:08
  • @DaveBennett yes that is correct. The range of properties are sizes of 2-5. (2 being a minimum of 2 properties for a node, and 5 being the max) – Justin Mar 06 '15 at 17:10

1 Answers1

1

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, ....
Brian Underwood
  • 10,746
  • 1
  • 22
  • 34