silky / graql-haskell

A library for building and executing Graql queries on a Grakn knowledge graph using Haskell

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

A simple library for building and executing Graql queries.

Import the modules:

module Example where

import Graql
import Graql.Shell

import Data.Function ((&))

Define the type names:

person = name "person"
husband = name "husband"
wife = name "wife"
marriage = name "marriage"

Define the variables:

x = var "x"
y = var "y"

We can translate the following query into Haskell:

match $x isa person, (husband: $x, wife: $y) isa marriage; select $y;
query = match
    [ x `isa` person
    , rel [husband .: x, wife .: y] `isa` marriage
    ] & select [y]

We can also use infix functions like (-:) instead of isa:

otherQuery = match
    [ x -: person
    , rel [husband .: x, wife .: y] -: marriage
    ] & select [y]

To execute and print the results of our query:

main = do
    result <- runMatch query
    print result

About

A library for building and executing Graql queries on a Grakn knowledge graph using Haskell

License:Apache License 2.0


Languages

Language:Haskell 100.0%