Skip to content

Instantly share code, notes, and snippets.

@Chappie74
Last active May 15, 2021 20:40
Show Gist options
  • Save Chappie74/f3c85f37460387368edc2985bf0ac13e to your computer and use it in GitHub Desktop.
Save Chappie74/f3c85f37460387368edc2985bf0ac13e to your computer and use it in GitHub Desktop.

Keywords

node - defines a node/vertex in your graph.

edge - defines the relationship between nodes.

walker - creates a robot that traverses the graph performing various user defined actions.

spawn - used to create/instantiate a node.

has - used to define properties of nodes and walkers.

can - actions a node can perform.

anchor - keyword used to annotate a single property of a node that can be used as the return value of said node.

with entry - block of actions to be taken when a walker is initialised and before it begins traversal

take - Queues up edge traversal that is executed in a sequential order.

here - context of the current node the walker is on.


Examples

Definig a node

Here, person is the type given to this node.

node person {
    
}

Definig a node with properties

node person{
    has firstName, lastName, dob
}

Defining a node with properties and actions

Actions can be thought of as functions, and needs to be defined before hand. Jac has a few built in actions that can be found at jaseci>core>actions

node person{
    has firstName, lastName, dob;
    can actions.sing_song, action.make_friends, actions.dance
}

Defining an edge

Edges can be thought of as the relationship between two nodes. A person node can have a friend relationship with another person node. From my understanding, edges don't yet support properties. This is in the works though.

edge friend; 
edge sibling;

Defining a walker

walker find_friends{

}

Spanwing nodes in a walker

In Jac, you are able to spawn typed or generic nodes. node1 is an example of a generic node and node2 is a node of the person type.

walker init{
    node1 = spawn  node;
    node2 = spawn node::person;
}


Spanwing nodes with edges

Imgur

walker init{
    node1 = spawn node::person;
    node2 = spawn node::person;
    node3 = spawn node::person;

    node1 <-> node2
    node2 --> node3
    node2 --> here
    here --> node1
}

Spawning nodes with typed edges

walker init{
    node1 = spawn node::person;
    node2 = spawn node::person;
    node3 = spawn node::person;

    node1 <-[friend]-> node2
    node2 -[family]-> node3
    node2 --> here
    here --> node1
}

Defining specific set of code a walker should perform when at a specific node

Assume we have defined two types of nodes person and pet. Any code in block cointaining ...1 will always be executed for that walker, no matter which node it is on. Any code in ...2 will only be executed if the walker is on a node of person type and so forth.

walker family_ties{
    ...1
    ...1
    ...1

    person{
        ...2
        ...2
    }

    pet{
        ...3
        ...3
    }

}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment