TRIAD Supplier Part Catalogue Model - Add Data Model

In [1]:
import os.path
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

Load Data Model from Hyper-NetworkX JSON File

In [2]:
# Path relative to the starting folder of Jupyter
path = os.path.join(os.path.realpath('..'), 'Data/Models')
In [3]:
# Get JSON filename from a tk pop-up GUI
fullpathname=triad.get(what='Filenames', fullpath=path, window_title='Select Data Model', extension='json')

# Load Data Model and create the Hyper-NetworkX in Memory
triad.load(what='Data Model', frm='HyperNetworkX File', jsonfile=fullpathname)

# Notice1:
# Links of NetworkX read from JSON file are unidirectional, we define one pair of edges, from HE nodes to HN nodes ONLY and 'net_links'='unidirectional'
# But when we pass NetworkX to the framework, the TRIADB database framework automatically turns unidirectional edges to bidirectional
# And when we save NetworkX back to JSON file both pair of edges are written. It is the 'net_links' attribute that is set to 'bidirectional'

# Notice2:
# The "vtype" attribute of each node must be any of the following data types that are currently supported in TRIADB FRAMEWORK
# Text        : TXT  (Short passages of text in any language)
# Word        : WRD  (Words or small phrases up to 128 characters long)
# Real        : REA  (Number)
# Integer     : INT  (Number)
# TimeStamp   : TS   (Date and Time)
# Code        : COD  (Any non-readable string up to 128 characters long)
# URL, PATH   : LNK  (URL address, or PATH up to 2048 characters long)
# Binary      : RAW  (Binary sequence up 1048487 bytes in size)
# Categorical : ENUM (Enumerated string up to 128 characters long)
Out[3]:
HGNetworkx(DATA_MODEL, Supplier-Part-Catalogue, SPC, /data/Code/PythonCode/CachePython/Data/Models)

Draw NetworkX Hypergraph with pydot

In [4]:
triad.hnetx.draw(graph_layout='pydot',
                 graph_axis='on', graph_title='Hypergraph Network with graphviz-dot', graph_width=28, graph_height=14,
                nattribute='nam', hnode_size=3000, hedge_size=3000, elabels_size=11, eattribute='link_nam')
In [5]:
triad.hnetx.draw(graph_layout='graphviz',
                 graph_axis='on', graph_title='Hypergraph Network with graphviz-dot', graph_width=36, graph_height=16,
                nattribute='nam', hnode_size=4000, hedge_size=4000, elabels_size=14, eattribute='link_nam')

Add Data Model to TRIAD Framework Database

In [6]:
triad.add(what='Data Model', frm='HyperNetworkX')
Out[6]:
[('44||1111||20||1', '55||1032||40||0'),
 ('44||1111||20||2', '55||1032||50||0'),
 ('44||1111||20||3', '55||1032||60||0'),
 ('44||1111||20||4', '55||1032||70||0'),
 ('44||1111||20||5', '55||1032||80||0'),
 ('44||1111||20||6', '55||1032||90||0'),
 ('44||1111||20||7', '55||1032||100||0'),
 ('44||1111||20||8', '55||1032||110||0'),
 ('44||1111||20||9', '55||1032||120||0'),
 ('44||1111||20||10', '55||1032||130||0'),
 ('44||1111||20||11', '55||1032||140||0'),
 ('44||1111||20||12', '55||1032||150||0'),
 ('44||1111||20||13', '55||1032||160||0'),
 ('44||1111||20||14', '55||1032||170||0'),
 ('44||1111||20||15', '55||1032||180||0'),
 ('44||1111||10||1', '55||1032||10||0'),
 ('44||1111||10||2', '55||1032||20||0'),
 ('44||1111||10||3', '55||1032||30||0')]

Get Model

In [7]:
triad.get(what='DME')
Out[7]:
KEY CNT NAM ABBR MKEY MNAM MOFMKEY MOFMNAM TYPE DICTYPE PATH
0 44||0||0||0 1 DATA MODELS ENVIRONMENT DME None None None None DICT ENV None
1 44||1111||0||0 0 Supplier-Part-Catalogue Data Model SPC_DM None None None None DICT SYS /data/Code/PythonCode/CachePython/Data/Models
2 44||1111||10||0 3 ENTITY ENT None None None None DICT STYPE None
3 44||1111||10||1 0 Supplier SUP 55||1032||10||0 INT None None DICT TYPE None
4 44||1111||10||2 0 Part PRT 55||1032||20||0 INT None None DICT TYPE None
5 44||1111||10||3 0 Catalog CAT 55||1032||30||0 INT None None DICT TYPE None
6 44||1111||20||0 15 ATTRIBUTE ATR None None None None DICT STYPE None
7 44||1111||20||1 0 supID id 55||1032||40||0 INT None None DICT TYPE None
8 44||1111||20||2 0 supName nameEN 55||1032||50||0 WRD None None DICT TYPE None
9 44||1111||20||3 0 supAddress address 55||1032||60||0 TXT None None DICT TYPE None
10 44||1111||20||4 0 supCity city 55||1032||70||0 WRD None None DICT TYPE None
11 44||1111||20||5 0 supCountry country 55||1032||80||0 WRD None None DICT TYPE None
12 44||1111||20||6 0 supStatus status 55||1032||90||0 INT None None DICT TYPE None
13 44||1111||20||7 0 prtID id 55||1032||100||0 INT None None DICT TYPE None
14 44||1111||20||8 0 prtName nameEN 55||1032||110||0 WRD None None DICT TYPE None
15 44||1111||20||9 0 prtColor color 55||1032||120||0 WRD None None DICT TYPE None
16 44||1111||20||10 0 prtWeight weight 55||1032||130||0 REA None None DICT TYPE None
17 44||1111||20||11 0 prtUnit unit 55||1032||140||0 ENUM None None DICT TYPE None
18 44||1111||20||12 0 catPrice price 55||1032||150||0 REA None None DICT TYPE None
19 44||1111||20||13 0 catTotal total 55||1032||160||0 INT None None DICT TYPE None
20 44||1111||20||14 0 catDate date 55||1032||170||0 TS None None DICT TYPE None
21 44||1111||20||15 0 catCheck check 55||1032||180||0 ENUM None None DICT TYPE None

Get Model Entitites as HyperEdges

In [8]:
hedf = triad.get(what='DME', sys=1111, con=10).iloc[1:]
hedf
Out[8]:
KEY CNT NAM ABBR MKEY MNAM MOFMKEY MOFMNAM TYPE DICTYPE PATH
1 44||1111||10||1 0 Supplier SUP 55||1032||10||0 INT None None DICT TYPE None
2 44||1111||10||2 0 Part PRT 55||1032||20||0 INT None None DICT TYPE None
3 44||1111||10||3 0 Catalog CAT 55||1032||30||0 INT None None DICT TYPE None

Get Model Attributes as HyperNodes

In [9]:
hndf = triad.get(what='DME', sys=1111, con=20).iloc[1:]
hndf
Out[9]:
KEY CNT NAM ABBR MKEY MNAM MOFMKEY MOFMNAM TYPE DICTYPE PATH
1 44||1111||20||1 0 supID id 55||1032||40||0 INT None None DICT TYPE None
2 44||1111||20||2 0 supName nameEN 55||1032||50||0 WRD None None DICT TYPE None
3 44||1111||20||3 0 supAddress address 55||1032||60||0 TXT None None DICT TYPE None
4 44||1111||20||4 0 supCity city 55||1032||70||0 WRD None None DICT TYPE None
5 44||1111||20||5 0 supCountry country 55||1032||80||0 WRD None None DICT TYPE None
6 44||1111||20||6 0 supStatus status 55||1032||90||0 INT None None DICT TYPE None
7 44||1111||20||7 0 prtID id 55||1032||100||0 INT None None DICT TYPE None
8 44||1111||20||8 0 prtName nameEN 55||1032||110||0 WRD None None DICT TYPE None
9 44||1111||20||9 0 prtColor color 55||1032||120||0 WRD None None DICT TYPE None
10 44||1111||20||10 0 prtWeight weight 55||1032||130||0 REA None None DICT TYPE None
11 44||1111||20||11 0 prtUnit unit 55||1032||140||0 ENUM None None DICT TYPE None
12 44||1111||20||12 0 catPrice price 55||1032||150||0 REA None None DICT TYPE None
13 44||1111||20||13 0 catTotal total 55||1032||160||0 INT None None DICT TYPE None
14 44||1111||20||14 0 catDate date 55||1032||170||0 TS None None DICT TYPE None
15 44||1111||20||15 0 catCheck check 55||1032||180||0 ENUM None None DICT TYPE None
In [10]:
hldfout=triad.get(what='HL', direction='out', from_sys=1111, labelA=3, labelB=4)
hldfout
Out[10]:
fromKEY fromABR fromNAM frmVAL VIAKey VIATYPE labelA labelB toKEY toABR toNAM toVAL
0 44||1111||10||1 SUP Supplier None 11||6000||60||1 Entity-Attribute is_Entity_of isE 44||1111||20||1 id supID None
1 44||1111||10||1 SUP Supplier None 11||6000||60||2 Entity-Attribute is_Entity_of isE 44||1111||20||2 nameEN supName None
2 44||1111||10||1 SUP Supplier None 11||6000||60||3 Entity-Attribute is_Entity_of isE 44||1111||20||3 address supAddress None
3 44||1111||10||1 SUP Supplier None 11||6000||60||4 Entity-Attribute is_Entity_of isE 44||1111||20||4 city supCity None
4 44||1111||10||1 SUP Supplier None 11||6000||60||5 Entity-Attribute is_Entity_of isE 44||1111||20||5 country supCountry None
5 44||1111||10||1 SUP Supplier None 11||6000||60||6 Entity-Attribute is_Entity_of isE 44||1111||20||6 status supStatus None
6 44||1111||10||2 PRT Part None 11||6000||60||7 Entity-Attribute is_Entity_of isE 44||1111||20||7 id prtID None
7 44||1111||10||2 PRT Part None 11||6000||60||8 Entity-Attribute is_Entity_of isE 44||1111||20||8 nameEN prtName None
8 44||1111||10||2 PRT Part None 11||6000||60||9 Entity-Attribute is_Entity_of isE 44||1111||20||9 color prtColor None
9 44||1111||10||2 PRT Part None 11||6000||60||10 Entity-Attribute is_Entity_of isE 44||1111||20||10 weight prtWeight None
10 44||1111||10||2 PRT Part None 11||6000||60||11 Entity-Attribute is_Entity_of isE 44||1111||20||11 unit prtUnit None
11 44||1111||10||3 CAT Catalog None 11||6000||60||12 Entity-Attribute is_Entity_of isE 44||1111||20||1 id supID None
12 44||1111||10||3 CAT Catalog None 11||6000||60||13 Entity-Attribute is_Entity_of isE 44||1111||20||7 id prtID None
13 44||1111||10||3 CAT Catalog None 11||6000||60||14 Entity-Attribute is_Entity_of isE 44||1111||20||12 price catPrice None
14 44||1111||10||3 CAT Catalog None 11||6000||60||15 Entity-Attribute is_Entity_of isE 44||1111||20||13 total catTotal None
15 44||1111||10||3 CAT Catalog None 11||6000||60||16 Entity-Attribute is_Entity_of isE 44||1111||20||14 date catDate None
16 44||1111||10||3 CAT Catalog None 11||6000||60||17 Entity-Attribute is_Entity_of isE 44||1111||20||15 check catCheck None
In [11]:
hldfin=triad.get(what='HL', direction='in', from_sys=1111, labelA=3, labelB=4)
hldfin
Out[11]:
toKEY toABR toNAM toVAL VIAKey VIAType labelA labelB fromKEY fromABR fromNAM frmVAL
0 44||1111||20||1 id supID None 11||6000||60||1 Entity-Attribute has_Entity hasE 44||1111||10||1 SUP Supplier None
1 44||1111||20||2 nameEN supName None 11||6000||60||2 Entity-Attribute has_Entity hasE 44||1111||10||1 SUP Supplier None
2 44||1111||20||3 address supAddress None 11||6000||60||3 Entity-Attribute has_Entity hasE 44||1111||10||1 SUP Supplier None
3 44||1111||20||4 city supCity None 11||6000||60||4 Entity-Attribute has_Entity hasE 44||1111||10||1 SUP Supplier None
4 44||1111||20||5 country supCountry None 11||6000||60||5 Entity-Attribute has_Entity hasE 44||1111||10||1 SUP Supplier None
5 44||1111||20||6 status supStatus None 11||6000||60||6 Entity-Attribute has_Entity hasE 44||1111||10||1 SUP Supplier None
6 44||1111||20||7 id prtID None 11||6000||60||7 Entity-Attribute has_Entity hasE 44||1111||10||2 PRT Part None
7 44||1111||20||8 nameEN prtName None 11||6000||60||8 Entity-Attribute has_Entity hasE 44||1111||10||2 PRT Part None
8 44||1111||20||9 color prtColor None 11||6000||60||9 Entity-Attribute has_Entity hasE 44||1111||10||2 PRT Part None
9 44||1111||20||10 weight prtWeight None 11||6000||60||10 Entity-Attribute has_Entity hasE 44||1111||10||2 PRT Part None
10 44||1111||20||11 unit prtUnit None 11||6000||60||11 Entity-Attribute has_Entity hasE 44||1111||10||2 PRT Part None
11 44||1111||20||1 id supID None 11||6000||60||12 Entity-Attribute has_Entity hasE 44||1111||10||3 CAT Catalog None
12 44||1111||20||7 id prtID None 11||6000||60||13 Entity-Attribute has_Entity hasE 44||1111||10||3 CAT Catalog None
13 44||1111||20||12 price catPrice None 11||6000||60||14 Entity-Attribute has_Entity hasE 44||1111||10||3 CAT Catalog None
14 44||1111||20||13 total catTotal None 11||6000||60||15 Entity-Attribute has_Entity hasE 44||1111||10||3 CAT Catalog None
15 44||1111||20||14 date catDate None 11||6000||60||16 Entity-Attribute has_Entity hasE 44||1111||10||3 CAT Catalog None
16 44||1111||20||15 check catCheck None 11||6000||60||17 Entity-Attribute has_Entity hasE 44||1111||10||3 CAT Catalog None
In [12]:
triad.add(what='Hyper-NetworkX', 
          net_type='Data Model Hypergraph', net_name='Supplier-Part-Catalogue', net_short='SPC', net_path=path, net_links='bidirectional',
          hedges_df   =hedf,    hedges_type='HE',          
          hnodes_df   =hndf,    hnodes_type='HN',
          hlinks_dfout=hldfout, hlinks_dfin=hldfin)
Out[12]:
HGNetworkx(Data Model Hypergraph, Supplier-Part-Catalogue, SPC, /home/athan/Work/TRIADemo/Data/Models)

Re-Draw NetworkX Hypergraph with Graphviz Engine (neato)

| ewidth=2,             |eweight=1,               |ecolor='blue', |edisplay='direct', |ekey='link_abbr',  |nkey=None, |nxkey=None,

| glayout='neato',      |goverlap='scalexy',      |gsep='+20',    |gnodesep=1,        |gsplines='curved',                        
| hncolor='brown1',     |hnshape='oval',          |hnwidth=0.5,   |hnheight=0.5,      |hnfontsize=14,
| hecolor='lightgreen', |heshape='doubleoctagon', |hewidth=0.5,   |heheight=0.5,      |hefontsize=14
In [13]:
triad.add_hgraphviz(edisplay='both', glayout='neato', nkey='nam', nxkey='abbr')
Out[13]:
<TRIAD.NetworkxHypergraph.HGPyDot at 0x7ff235e97630>
In [14]:
triad.hgraphviz.draw()
Out[14]:
G 44||1111||20||1 supID id 44||1111||10||1 Supplier SUP 44||1111||20||1->44||1111||10||1 hasE 44||1111||10||3 Catalog CAT 44||1111||20||1->44||1111||10||3 hasE 44||1111||20||2 supName nameEN 44||1111||20||2->44||1111||10||1 hasE 44||1111||20||3 supAddress address 44||1111||20||3->44||1111||10||1 hasE 44||1111||20||4 supCity city 44||1111||20||4->44||1111||10||1 hasE 44||1111||20||5 supCountry country 44||1111||20||5->44||1111||10||1 hasE 44||1111||20||6 supStatus status 44||1111||20||6->44||1111||10||1 hasE 44||1111||20||7 prtID id 44||1111||10||2 Part PRT 44||1111||20||7->44||1111||10||2 hasE 44||1111||20||7->44||1111||10||3 hasE 44||1111||20||8 prtName nameEN 44||1111||20||8->44||1111||10||2 hasE 44||1111||20||9 prtColor color 44||1111||20||9->44||1111||10||2 hasE 44||1111||20||10 prtWeight weight 44||1111||20||10->44||1111||10||2 hasE 44||1111||20||11 prtUnit unit 44||1111||20||11->44||1111||10||2 hasE 44||1111||20||12 catPrice price 44||1111||20||12->44||1111||10||3 hasE 44||1111||20||13 catTotal total 44||1111||20||13->44||1111||10||3 hasE 44||1111||20||14 catDate date 44||1111||20||14->44||1111||10||3 hasE 44||1111||20||15 catCheck check 44||1111||20||15->44||1111||10||3 hasE 44||1111||10||1->44||1111||20||1 isE 44||1111||10||1->44||1111||20||2 isE 44||1111||10||1->44||1111||20||3 isE 44||1111||10||1->44||1111||20||4 isE 44||1111||10||1->44||1111||20||5 isE 44||1111||10||1->44||1111||20||6 isE 44||1111||10||2->44||1111||20||7 isE 44||1111||10||2->44||1111||20||8 isE 44||1111||10||2->44||1111||20||9 isE 44||1111||10||2->44||1111||20||10 isE 44||1111||10||2->44||1111||20||11 isE 44||1111||10||3->44||1111||20||1 isE 44||1111||10||3->44||1111||20||7 isE 44||1111||10||3->44||1111||20||12 isE 44||1111||10||3->44||1111||20||13 isE 44||1111||10||3->44||1111||20||14 isE 44||1111||10||3->44||1111||20||15 isE