TRIAD - Traversal and Hypergraph Neighbourhood Visualization

Create a Triad Framework object

In [1]:
from TRIAD.CacheTriad import TriadFramework

triad=TriadFramework('_SYSTEM', 'SYS', 1)

flatten = lambda l: [item for sublist in l for item in sublist]
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

Get HyperAtoms

In [2]:
triad.get(what='HyperNodes', env=55, str='Acme%')
Out[2]:
KEY TYPE NAM ABR REF VAL
0 55||1032||50||1 REF None None 11||1000||70||1 Acme Widget Suppliers
1 55||1032||110||3 REF None None 11||1000||70||16 Acme Widget Washer

Get Part HyperBonds

In [3]:
part_hbs=triad.head(objectID='55||1032||110||3').get_hyperedges()
part_hbs
Out[3]:
['55||1032||20||3', '55||1032||20||4']

Get Part HyperAtom Sets (Tuples with Values)

In [4]:
[triad.tail(objectID=hb).get_hypernodes(True) for hb in part_hbs]
Out[4]:
[[993, 'Acme Widget Washer', 'Red', 142.88, 'kg'],
 [994, 'Acme Widget Washer', 'Silver', 142.88, 'kb']]

Get Part HyperAtom Sets (Tuples with References)

In [5]:
[triad.tail(objectID=hb).get_hypernodes(False) for hb in part_hbs]
Out[5]:
[['55||1032||100||3',
  '55||1032||110||3',
  '55||1032||120||1',
  '55||1032||130||3',
  '55||1032||140||2'],
 ['55||1032||100||4',
  '55||1032||110||3',
  '55||1032||120||3',
  '55||1032||130||3',
  '55||1032||140||3']]

Get Part Shared HyperAtoms

In [6]:
part_shared_has=[triad.tail(objectID=hb).get_hypernodes(False)[0] for hb in part_hbs]
part_shared_has
Out[6]:
['55||1032||100||3', '55||1032||100||4']

Get Catalogue HyperBonds

In [7]:
cat_hbs=[triad.head(objectID=ha).get_hyperedges(False) for ha in part_shared_has]
cat_hbs = [flatten(cat_hbs)[pos] for pos in [1,3,4]]
cat_hbs
Out[7]:
['55||1032||30||3', '55||1032||30||4', '55||1032||30||15']

Get Catalogue HyperAtom Sets (Tuples with Values)

In [8]:
[triad.tail(objectID=hb).get_hypernodes(True) for hb in cat_hbs]
Out[8]:
[[1081, 993, 15.3, 200, 'False'],
 [1081, 994, 20.5, 100, 'False'],
 [1084, 994, 57.3, 100, 'True']]

Get Catalogue HyperAtom Sets (Tuples with References)

In [9]:
flatten([triad.tail(objectID=hb).get_hypernodes(False) for hb in cat_hbs])
Out[9]:
['55||1032||40||1',
 '55||1032||100||3',
 '55||1032||150||3',
 '55||1032||160||3',
 '55||1032||180||2',
 '55||1032||40||1',
 '55||1032||100||4',
 '55||1032||150||4',
 '55||1032||160||4',
 '55||1032||180||2',
 '55||1032||40||4',
 '55||1032||100||4',
 '55||1032||150||13',
 '55||1032||160||4',
 '55||1032||180||1']

Get Catalogue Shared HyperAtoms

In [10]:
cat_shared_has=[triad.tail(objectID=hb).get_hypernodes(False)[0] for hb in cat_hbs]
cat_shared_has
Out[10]:
['55||1032||40||1', '55||1032||40||1', '55||1032||40||4']

Get Supplier HyperBonds

In [11]:
sup_hbs=[triad.head(objectID=ha).get_hyperedges(False) for ha in cat_shared_has]
sup_hbs=[flatten(sup_hbs)[pos] for pos in [0,20]]
sup_hbs
Out[11]:
['55||1032||10||1', '55||1032||10||4']

Get Supplier HyperAtom Sets (Tuples)

In [12]:
[triad.tail(objectID=hb).get_hypernodes(True) for hb in sup_hbs]
Out[12]:
[[1081,
  'Acme Widget Suppliers',
  '1 Grub St., Potemkin Village, IL 61801',
  'ILLINOIS',
  'USA',
  10],
 [1084,
  'Alien Aircaft Inc.',
  '2 Groom Lake, Rachel, NV 51902',
  'NOTTINGHAM',
  'UK',
  10]]

Visualize Hypergraph of Parts Neighbourhood

Get HyperBonds

In [13]:
sqlstr = "select ID as KEY, nodeReference->nodeValue as NAM, nodeAbbr as ABBR from TRIADB.NodeTail where ID IN "
filterstr = "('55||1032||20||3', '55||1032||20||4')"

hbonds = triad.sqlview.query_display(sqlstr+filterstr)
hbonds
Execution reached the end of the result set
Out[13]:
KEY NAM ABBR
0 55||1032||20||3 3 None
1 55||1032||20||4 4 None

Get HyperAtoms

In [14]:
sqlstr = "select ID as KEY, nodeReference->nodeValue as NAM, nodeAbbr as ABBR from TRIADB.NodeHead where ID IN "
filterstr = "('55||1032||100||3', '55||1032||110||3', '55||1032||120||1', '55||1032||130||3', '55||1032||140||2', '55||1032||100||4', '55||1032||120||3', '55||1032||140||3')"

hatoms = triad.sqlview.query_display(sqlstr+filterstr)
hatoms
Execution reached the end of the result set
Out[14]:
KEY NAM ABBR
0 55||1032||100||3 993 None
1 55||1032||100||4 994 None
2 55||1032||110||3 Acme Widget Washer None
3 55||1032||120||1 Red None
4 55||1032||120||3 Silver None
5 55||1032||130||3 142.88 None
6 55||1032||140||2 kg None
7 55||1032||140||3 kb None
In [15]:
hlinks1 = triad.get(what='HyperLinks', from_id='55||1032||20||3', labelA=3, labelB=4, direction='out')
hlinks2 = triad.get(what='HyperLinks', from_id='55||1032||20||4', labelA=3, labelB=4, direction='out')

import pandas as pd
hlinksout = pd.concat([hlinks1, hlinks2])
hlinksout
Out[15]:
fromKEY fromABR fromNAM frmVAL VIAKey VIATYPE labelA labelB toKEY toABR toNAM toVAL
0 55||1032||20||3 None None 3 11||6000||40||35 Hyperbond-Hyperatom has_HyperAtom hasHA 55||1032||100||3 None None 993
1 55||1032||20||3 None None 3 11||6000||40||36 Hyperbond-Hyperatom has_HyperAtom hasHA 55||1032||110||3 None None Acme Widget Washer
2 55||1032||20||3 None None 3 11||6000||40||37 Hyperbond-Hyperatom has_HyperAtom hasHA 55||1032||120||1 None None Red
3 55||1032||20||3 None None 3 11||6000||40||38 Hyperbond-Hyperatom has_HyperAtom hasHA 55||1032||130||3 None None 142.88
4 55||1032||20||3 None None 3 11||6000||40||39 Hyperbond-Hyperatom has_HyperAtom hasHA 55||1032||140||2 None None kg
0 55||1032||20||4 None None 4 11||6000||40||40 Hyperbond-Hyperatom has_HyperAtom hasHA 55||1032||100||4 None None 994
1 55||1032||20||4 None None 4 11||6000||40||41 Hyperbond-Hyperatom has_HyperAtom hasHA 55||1032||110||3 None None Acme Widget Washer
2 55||1032||20||4 None None 4 11||6000||40||42 Hyperbond-Hyperatom has_HyperAtom hasHA 55||1032||120||3 None None Silver
3 55||1032||20||4 None None 4 11||6000||40||43 Hyperbond-Hyperatom has_HyperAtom hasHA 55||1032||130||3 None None 142.88
4 55||1032||20||4 None None 4 11||6000||40||44 Hyperbond-Hyperatom has_HyperAtom hasHA 55||1032||140||3 None None kb
In [16]:
hlinks1 = triad.get(what='HyperLinks', from_id='55||1032||20||3', labelA=3, labelB=4, direction='in')
hlinks2 = triad.get(what='HyperLinks', from_id='55||1032||20||4', labelA=3, labelB=4, direction='in')
import pandas as pd
hlinksin = pd.concat([hlinks1, hlinks2])
hlinksin
Out[16]:
toKEY toABR toNAM toVAL VIAKey VIAType labelA labelB fromKEY fromABR fromNAM frmVAL
0 55||1032||100||3 None None 993 11||6000||40||35 Hyperbond-Hyperatom is_HyperAtom_of isHA 55||1032||20||3 None None 3
1 55||1032||110||3 None None Acme Widget Washer 11||6000||40||36 Hyperbond-Hyperatom is_HyperAtom_of isHA 55||1032||20||3 None None 3
2 55||1032||120||1 None None Red 11||6000||40||37 Hyperbond-Hyperatom is_HyperAtom_of isHA 55||1032||20||3 None None 3
3 55||1032||130||3 None None 142.88 11||6000||40||38 Hyperbond-Hyperatom is_HyperAtom_of isHA 55||1032||20||3 None None 3
4 55||1032||140||2 None None kg 11||6000||40||39 Hyperbond-Hyperatom is_HyperAtom_of isHA 55||1032||20||3 None None 3
0 55||1032||100||4 None None 994 11||6000||40||40 Hyperbond-Hyperatom is_HyperAtom_of isHA 55||1032||20||4 None None 4
1 55||1032||110||3 None None Acme Widget Washer 11||6000||40||41 Hyperbond-Hyperatom is_HyperAtom_of isHA 55||1032||20||4 None None 4
2 55||1032||120||3 None None Silver 11||6000||40||42 Hyperbond-Hyperatom is_HyperAtom_of isHA 55||1032||20||4 None None 4
3 55||1032||130||3 None None 142.88 11||6000||40||43 Hyperbond-Hyperatom is_HyperAtom_of isHA 55||1032||20||4 None None 4
4 55||1032||140||3 None None kb 11||6000||40||44 Hyperbond-Hyperatom is_HyperAtom_of isHA 55||1032||20||4 None None 4
In [17]:
triad.add(what='Hyper-NetworkX', 
          net_type='HyperBond-HyperAtom HyperGraph', net_name='Acme Widget Washer', net_short='AWW', net_path="", net_links='bidirectional',
          hedges_df=hbonds, hedges_type='HE',          
          hnodes_df=hatoms, hnodes_type='HN',
          hlinks_dfout=hlinksout, hlinks_dfin=hlinksin)
Out[17]:
HGNetworkx(HyperBond-HyperAtom HyperGraph, Acme Widget Washer, AWW, )
In [18]:
triad.add(what='Hyper-Graphviz', ekey='link_nam', nkey='nam', glayout='neato', edisplay='direct').draw()
Out[18]:
G 55||1032||100||3 993 55||1032||100||4 994 55||1032||110||3 Acme Widget Washer 55||1032||120||1 Red 55||1032||120||3 Silver 55||1032||130||3 142.88 55||1032||140||2 kg 55||1032||140||3 kb 55||1032||20||3 3 55||1032||20||3->55||1032||100||3 has_HyperAtom 55||1032||20||3->55||1032||110||3 has_HyperAtom 55||1032||20||3->55||1032||120||1 has_HyperAtom 55||1032||20||3->55||1032||130||3 has_HyperAtom 55||1032||20||3->55||1032||140||2 has_HyperAtom 55||1032||20||4 4 55||1032||20||4->55||1032||100||4 has_HyperAtom 55||1032||20||4->55||1032||110||3 has_HyperAtom 55||1032||20||4->55||1032||120||3 has_HyperAtom 55||1032||20||4->55||1032||130||3 has_HyperAtom 55||1032||20||4->55||1032||140||3 has_HyperAtom
In [19]:
triad.add(what='Hyper-Graphviz', ekey='link_abbr', nkey='nam', glayout='neato', edisplay='both').draw()
Out[19]:
G 55||1032||100||3 993 55||1032||20||3 3 55||1032||100||3->55||1032||20||3 isHA 55||1032||100||4 994 55||1032||20||4 4 55||1032||100||4->55||1032||20||4 isHA 55||1032||110||3 Acme Widget Washer 55||1032||110||3->55||1032||20||3 isHA 55||1032||110||3->55||1032||20||4 isHA 55||1032||120||1 Red 55||1032||120||1->55||1032||20||3 isHA 55||1032||120||3 Silver 55||1032||120||3->55||1032||20||4 isHA 55||1032||130||3 142.88 55||1032||130||3->55||1032||20||3 isHA 55||1032||130||3->55||1032||20||4 isHA 55||1032||140||2 kg 55||1032||140||2->55||1032||20||3 isHA 55||1032||140||3 kb 55||1032||140||3->55||1032||20||4 isHA 55||1032||20||3->55||1032||100||3 hasHA 55||1032||20||3->55||1032||110||3 hasHA 55||1032||20||3->55||1032||120||1 hasHA 55||1032||20||3->55||1032||130||3 hasHA 55||1032||20||3->55||1032||140||2 hasHA 55||1032||20||4->55||1032||100||4 hasHA 55||1032||20||4->55||1032||110||3 hasHA 55||1032||20||4->55||1032||120||3 hasHA 55||1032||20||4->55||1032||130||3 hasHA 55||1032||20||4->55||1032||140||3 hasHA