thepeergroup / aspen

Aspen is a markup language for turning text into graph data (via Cypher for Neo4j).
https://aspen-lang.org
MIT License
60 stars 7 forks source link

Add evaluation-unique nicknames #12

Closed beechnut closed 2 years ago

beechnut commented 4 years ago

In a custom grammar, I want to write a few lines of Cypher which let me reference a nickname within the scope of this set of statements.

For example, I want this Aspen

default:
  attributes:
    Event: title

grammar:
  -
    match:
      - (Person a) and (Person b) met through Graphs4Good.
      - (Person a) met (Person b) at Graphs4Good.
    template: |
      {{{a}}}<-[:INCLUDES]-({{{intro:uniq}}}):Introduction)-[:INCLUDES]->{{{b}}}
      ({{{intro:uniq}}})-[:OCCURRED_AT]->(Event { title: "Graphs4Good Kickoff" })
      {{{a}}}-[:KNOWS]-{{{b}}}
----
(Karin) [organized] (Event, Graphs4Good Kickoff)

Matt and Alyssa met through Graphs4Good.
Alyssa met Joel at Graphs4Good.

to include this Cypher:

MERGE (person_matt)<-[:INCLUDES]-(intro_1:Introduction)-[:INCLUDES]->(person_alyssa)
MERGE (intro_1)-[:OCCURRED_AT]->(:Event { title: "Graphs4Good Kickoff" })
MERGE (person_matt)-[:KNOWS]-(person_alyssa)

MERGE (person_alyssa)<-[:INCLUDES]-(intro_2:Introduction)-[:INCLUDES]->(person_joel)
MERGE (intro_2)-[:OCCURRED_AT]->(Event { title: "Graphs4Good Kickoff" })
MERGE (person_alyssa)-[:KNOWS]-(person_joel)

As you can see, the nickname identifier is unique to each evaluation of the template. We can reference the nickname as a string value anywhere in the template, taking care to wrap it in parens when we reference it as a node: ({{{intro:uniq}}})-[:AND_SO_FORTH]->

The convention could be an slug (here, intro), followed by :uniq to indicate it should autoincrement the nickname to preserve uniqueness.

beechnut commented 3 years ago

This is ready on the adapters branch.