fractl-io / fractl

Generative AI-powered Programming Language
Apache License 2.0
110 stars 4 forks source link

Proposal - syntactic support to access nodes and attributes in a graph #1061

Open vijayfractl opened 9 months ago

vijayfractl commented 9 months ago

E.g:

(entity :Company ...)
(entity :Employee ...)
(entity :Location ...)
(relationship :WorksFor
 {:meta {:contains [:Company :Employee]}})
(relationship :ReportsTo
 {:meta {:between [:Employee :Employee :as [:A :B]]}})
(relationship :SiteAllocation
 {:meta {:between [:Employee :Location]}})

(dataflow :E1
 {:Employee {:Email? :E1.Email} :as :E}
 {:Result
  {:Company :E.WorksFor.Company.Name} ; return the name of the company related to the employee.

A new check should be added to the compiler - if :Employee contains an attribute called :WorksFor - the relationship cannot be established.

There's the question of supporting the path in reverse - :Company.WorksFor.Employee.Email - this can resolve to a list of emails - how to destructure it?

Similar patterns should work for :between relationships:

(dataflow :E2
 {:Employee {:Email? :E2.Email} :as :E}
 {:Result
  {:Location :E.SiteAllocation.Location.Id}})

The syntax for the :ReportsTo relationship can be:

(dataflow :E3
 {:Employee {:Email? :E3.Email} :as :E}
 {:Result
  {:OtherEmployee :E.ReportsTo.B.Email}}) ; :E points to the :A node of the relationship

between paths can always return multiple results - so some de-structuring syntax maybe needed here,

fractlrao commented 9 months ago

In case of multiple cardinality, would it make sense to reference an individual instance with one or more of the below forms:

  1. :Company.WorksFor.Employee["<uuid>"].Email
  2. :Company.WorksFor.Employee{:Name? "John Doe"}[0].Email
  3. :Company.WorksFor.Employee{:where [:and [:= :Name "John Doe"] [:> :Age 20]]}[0].Email