TRIAD - GET CACHE Node Objects of the Framework

In [1]:
from TRIAD.CacheTriad import TriadFramework

triad=TriadFramework('_SYSTEM', 'SYS', 1)
NetworkX Hypergraph Interface : 
Enhanced drawing and processing routines for NetworkX graph package
(C) 2017 HEALIS.EU - Athanassios I. Hatzis, All Rights Reserved

CachePython Inteface : 
Enhanced OOP Cache-Python interface based on Intersystems Cache python binding modules
(C) 2017 HEALIS.EU - Athanassios I. Hatzis, All Rights Reserved

CacheHypergraph Interface : 
Python Binding of Intersystems Cache Associative Semiotic Hypegraph engine
(C) 2017 HEALIS.EU - Athanassios I. Hatzis, All Rights Reserved

CacheTriad Interface : 
A Python client for Triad Associative Semiotic Hypergraph framework based on previous modules
(C) 2017 HEALIS.EU - Athanassios I. Hatzis, All Rights Reserved
In [2]:
print(triad.binding_classes())
CacheQuery(host='localhost', port=1972, username='_SYSTEM', password='SYS', namespace='HGRAPH', cachepackage='TRIADB', cacheclass='SQLView') 

CacheClass(host='localhost', port=1972, username='_SYSTEM', password='SYS', namespace='HGRAPH', cacheclass='HGRAPH.TRIADB.API', 'No Object Set') 

CacheClass(host='localhost', port=1972, username='_SYSTEM', password='SYS', namespace='HGRAPH', cacheclass='HGRAPH.TRIADB.NodeDict', 'No Object Set') 

None

Use SQL Query to fetch the Node

In [3]:
triad.get(what='Query Node', frm='NodeDict', key='33||1024||0||0')
Out[3]:
KEY CNT NAM ABBR MKEY MNAM MOFMKEY MOFMNAM TYPE DICTYPE PATH
0 33||1024||0||0 0 SUPPLIER PART CATALOGUE Data Resource SPC_DR None None None None DICT SYS /home/athan/Work/TRIADemo/Data/SupplierPartCat...

NodeDict Class

without any object set

In [4]:
print(triad.dic)
CacheClass(host='localhost', port=1972, username='_SYSTEM', password='SYS', namespace='HGRAPH', cacheclass='HGRAPH.TRIADB.NodeDict', 'No Object Set')

a NodeDict instance set with an opened CACHE object Node

In [5]:
triad.get(what='Object Node', frm='NodeDict', key='33||1024||0||0')
Out[5]:
HGRAPH.TRIADB.NodeDict(33, 1024, 0, 0):DICT:SYS = SUPPLIER PART CATALOGUE Data Resource, SPC_DR, 0, 115
In [6]:
print(triad.dic)
Cache_Class = HGRAPH.TRIADB.NodeDict
(Key, Name, Short)          = 33||1024||0||0, SUPPLIER PART CATALOGUE Data Resource, SPC_DR
Type : DictionaryType       = DICT : SYS
Number of nodes in a set    = 0
Serial No                   = 115

same operation using triad.dic instance attribute

In [7]:
print(triad.dic.get_node('44||1111||0||0'))
Cache_Class = HGRAPH.TRIADB.NodeDict
(Key, Name, Short)          = 44||1111||0||0, Supplier-Part-Catalogue Data Model, SPC_DM
Type : DictionaryType       = DICT : SYS
Number of nodes in a set    = 0
Serial No                   = 58

get CACHE Node properties

In [8]:
[triad.dic.path, triad.dic.name, triad.dic.abbr, triad.dic.type, triad.dic.typedic, triad.dic.count]
Out[8]:
['/data/Code/PythonCode/CachePython/Data/Models',
 'Supplier-Part-Catalogue Data Model',
 'SPC_DM',
 'DICT',
 'SYS',
 0]

NodeVia Class

NodeVia instance set with an opened CACHE object Node

In [9]:
# This creates a new connection to CACHE database
triad.get(what='Object Node', frm='NodeVia', key='11||6000||40||9')
Out[9]:
HGRAPH.TRIADB.NodeVia(11, 6000, 40, 9):VIA

Same operation using the instance property triad.via

In [10]:
# This creates a new connection to CACHE database
link=triad.via(objectID='11||6000||40||9')
link
Out[10]:
HGRAPH.TRIADB.NodeVia(11, 6000, 40, 9):VIA

NodeVia instance open a CACHE object Node

In [11]:
# This is using the existing CACHE connection to open another CACHE object NodeVia Node object
link.get_node('11||6000||40||10')
Out[11]:
HGRAPH.TRIADB.NodeVia(11, 6000, 40, 10):VIA
In [12]:
print(link)
Link name, abbreviation           = Hyperbond-Hyperatom, HB-HA

Labels (direct, reverse)          = is_HyperBond_of, has_HyperBond

from.id  ==== via.id ====> to.id  = (55||1032||10||2) ==== (11||6000||40||10) ====> (55||1032||70||2)

from.val ==== label =====> to.val = 2 ==== is_HyperBond_of ====> OREGON

from.val ==== label =====> to.val = 2 <==== has_HyperBond ==== OREGON
In [13]:
[link.get_labels(2), link.get_labels(3), link.get_labels(4)]
Out[13]:
[['isHB', 'hasHB'], ['has_HyperAtom', 'is_HyperAtom_of'], ['hasHA', 'isHA']]

NodeTail Class (HyperEdges)

Get HyperEdges from Query

In [14]:
hedges=triad.get(what='HyperEdges', sys=1032)
hedges
Out[14]:
KEY TYPE NAM ABR REF VAL
0 55||1032||10||1 REF None None 11||1000||30||1 1
1 55||1032||10||2 REF None None 11||1000||30||4 2
2 55||1032||10||3 REF None None 11||1000||30||7 3
3 55||1032||10||4 REF None None 11||1000||30||10 4
4 55||1032||20||1 REF None None 11||1000||30||1 1
5 55||1032||20||2 REF None None 11||1000||30||4 2
6 55||1032||20||3 REF None None 11||1000||30||7 3
7 55||1032||20||4 REF None None 11||1000||30||10 4
8 55||1032||20||5 REF None None 11||1000||30||16 5
9 55||1032||20||6 REF None None 11||1000||30||18 6
10 55||1032||20||7 REF None None 11||1000||30||20 7
11 55||1032||20||8 REF None None 11||1000||30||22 8
12 55||1032||20||9 REF None None 11||1000||30||24 9
13 55||1032||30||1 REF None None 11||1000||30||1 1
14 55||1032||30||2 REF None None 11||1000||30||4 2
15 55||1032||30||3 REF None None 11||1000||30||7 3
16 55||1032||30||4 REF None None 11||1000||30||10 4
17 55||1032||30||5 REF None None 11||1000||30||16 5
18 55||1032||30||6 REF None None 11||1000||30||18 6
19 55||1032||30||7 REF None None 11||1000||30||20 7
20 55||1032||30||8 REF None None 11||1000||30||22 8
21 55||1032||30||9 REF None None 11||1000||30||24 9
22 55||1032||30||10 REF None None 11||1000||30||3 10
23 55||1032||30||11 REF None None 11||1000||30||30 11
24 55||1032||30||12 REF None None 11||1000||30||31 12
25 55||1032||30||13 REF None None 11||1000||30||32 13
26 55||1032||30||14 REF None None 11||1000||30||33 14
27 55||1032||30||15 REF None None 11||1000||30||34 15
28 55||1032||30||16 REF None None 11||1000||30||35 16
29 55||1032||30||17 REF None None 11||1000||30||36 17

NodeTail Instance created without setting it to CACHE object

In [15]:
hedge = triad.tail()
hedge
Out[15]:
CacheClass(localhost, 1972, _SYSTEM, SYS, HGRAPH, 'HGRAPH.TRIADB.NodeTail', 'No Object Set')

Expand Supplier HyperEdges

In [16]:
for k in list(triad.get(what='HyperEdges', sys=1032, con=10).KEY):
    print(hedge.get_node(k).get_hypernodes(True))
[1081, 'Acme Widget Suppliers', '1 Grub St., Potemkin Village, IL 61801', 'ILLINOIS', 'USA', 10]
[1082, 'Big Red Tool and Die', '4 My Way, Bermuda Shorts, OR 90305', 'OREGON', 'USA', 20]
[1083, 'Perfunctory Parts', '99 Short Pier, Terra Del Fuego, TX 41299', 'MADRID', 'SPAIN', 30]
[1084, 'Alien Aircaft Inc.', '2 Groom Lake, Rachel, NV 51902', 'NOTTINGHAM', 'UK', 10]

Expand Part HyperEdges

In [17]:
for k in list(triad.get(what='HyperEdges', sys=1032, con=20).KEY):
    print(hedge.get_node(k).get_hypernodes(True))
[991, 'Left Handed Bacon Stretcher Cover', 'Red', 15.5, 'lb']
[992, 'Smoke Shifter End', 'Black', 3.75, 'lb']
[993, 'Acme Widget Washer', 'Red', 142.88, 'kg']
[994, 'Acme Widget Washer', 'Silver', 142.88, 'kb']
[995, 'I Brake for Crop Circles Sticker']
[996, 'Anti-Gravity Turbine Generator', 'Cyan']
[997, 'Anti-Gravity Turbine Generator', 'Magenta']
[998, 'Fire Hydrant Cap', 'Red', 7.2, 'lb']
[999, '7 Segment Display', 'Green', 2.1, 'gr']

Expand Catalogue HyperEdges

In [18]:
for k in list(triad.get(what='HyperEdges', sys=1032, con=30).KEY):
    print(hedge.get_node(k).get_hypernodes(True))
[1081, 991, 36.1, 300, 'True']
[1081, 992, 42.3, 400, 'True']
[1081, 993, 15.3, 200, 'False']
[1081, 994, 20.5, 100, 'False']
[1081, 995, 20.5, 'False']
[1081, 996, 124.23, 'False']
[1081, 997, 124.23, 'False']
[1081, 998, 11.7, 400, 'True']
[1081, 999, 75.2, 'False']
[1082, 991, 16.5, 200, 'True']
[1082, 997, 0.55, 100, 'True']
[1082, 998, 7.95, 200, 'False']
[1083, 998, 12.5, 'False']
[1083, 999, 1.0, 'False']
[1084, 994, 57.3, 100, 'True']
[1084, 995, 22.2, 'False']
[1084, 998, 48.6, 200, 'True']