-
Notifications
You must be signed in to change notification settings - Fork 252
Expand file tree
/
Copy pathgraph_edges.py
More file actions
executable file
·52 lines (46 loc) · 1.5 KB
/
graph_edges.py
File metadata and controls
executable file
·52 lines (46 loc) · 1.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#! /usr/bin/env python3
#
# graph_edges.py
#
"""
Representing graph edges in basic Atomese. This demo constructs a
single graph edge, using the canonical (i.e. "recommended") Atomese
style for this. It is not the only way; there are no particularly
strong rules for how Atomese "must" be used, and thus graph edges,
and most things can be represented in a variety of ways. As they say,
"limited by your imagination". However, the canonical form is obvious,
which is why it is recommended.
"""
# Import all Atom types.
from opencog.atomspace import *
# Create a labelled directed graph edge. In ASCII graphics:
#
# "some edge label"
# "from vertex" ------------------------> "to vertex"
#
# which in (scheme-style) Atomese, becomes
#
# (Edge (Predicate "some edge label")
# (List (Item "from vertex") (Item "to vertex")))
#
# In Python, the parens get re-arranged and commas are inserted:
#
# Edge (Predicate ("some edge label"),
# List (Item ("from vertex"), Item ("to vertex")))
#
e = EdgeLink(
# Any UTF-8 string can be used as an edge label.
PredicateNode("My URL collection"),
ListLink(
ItemNode("file:///Home Computer/folders/My photo album"),
ItemNode("Fantastic Sunset on Sunday.jpg")))
print("Here's your data:\n", e)
# The "Link" and "Node" suffixes are optional.
f = Edge(
Predicate("My URL collection"),
List(
Item("file:///usr/bin/"),
Item("bash")))
print("Here's a tool:\n", f)
# THE END. That's All, Folks!
# -------------------------------------------