<jupyter_start><jupyter_text>Output Network to JSON<jupyter_code>import qualreas as qr
import os
import json
import networkx as nx
path = os.path.join(os.getenv('PYPROJ'), 'qualreas')
print(path)
apath = path + "/Algebras/"

rcc8 = path + "/Networks/rcc8_example.json"
rcc8_missing = path + "/Networks/rcc8_example_MISSING.json"  # Missing specifications (force defaults)

book = path + "/Networks/BookExample.json"
bookx = path + "/Networks/BookExampleExtended.json"

nssdf = path + "/Networks/nssdfExample2.json"<jupyter_output><empty_output><jupyter_text>NSSDF 2009 Example 2  Read Network from JSON File<jupyter_code>!cat {nssdf}
nssdf_net = qr.Network(algebra_path=apath, json_file_name=nssdf)
nssdf_net.summary()
nssdf_net.propagate()
nssdf_net.summary()<jupyter_output>NSSDF 2009 Example 2: 8 nodes, 64 edges
  Algebra: Extended_Linear_Interval_Algebra
  Yesterday:['ProperInterval']
    => Yesterday: E
    => Today: M
    => Yesterday_Morning: SI
    => Yesterday_Evening: FI
    => Time_of_Obs: DI
    => Time_of_Arrest: DI
    => Time_of_Release: B
    => Period_of_Detention: O
  Today:['ProperInterval']
    => Today: E
    => Yesterday: MI
    => Time_of_Release: DI
    => Yesterday_Morning: BI
    => Yesterday_Evening: MI
    => Time_of_Obs: BI
    => Time_of_Arrest: BI
    => Period_of_Detention: OI
  Yesterday_Morning:['ProperInterval']
    => Yesterday_Morning: E
    => Yesterday: S
    => Yesterday_Evening: B
    => Time_of_Arrest: DI
    => Today: B
    => Time_of_Obs: B
    => Time_of_Release: B
    => Period_of_Detention: O
  Yesterday_Evening:['ProperInterval']
    => Yesterday_Evening: E
    => Yesterday: F
    => Yesterday_Morning: BI
    => Time_of_Obs: DI
    => Today: M
    => Time_of_Arrest: BI
    => Time_of_Release: B
    => Period_[...]<jupyter_text>Convert Network to Dict<jupyter_code>nssdf_dict = nssdf_net.to_dict()
nssdf_dict<jupyter_output><empty_output><jupyter_text>Convert Dict to Network<jupyter_code>nssdf_net_from_dict = qr.Network(algebra_path=apath, network_dict=nssdf_dict)
nssdf_net_from_dict.summary()<jupyter_output>NSSDF 2009 Example 2: 8 nodes, 26 edges
  Algebra: Extended_Linear_Interval_Algebra
  Yesterday:
    => Yesterday: E
    => Today: M
    => Yesterday_Morning: SI
    => Yesterday_Evening: FI
  Today:
    => Today: E
    => Yesterday: MI
    => Time_of_Release: DI
  Yesterday_Morning:
    => Yesterday_Morning: E
    => Yesterday: S
    => Yesterday_Evening: B
    => Time_of_Arrest: DI
  Yesterday_Evening:
    => Yesterday_Evening: E
    => Yesterday: F
    => Yesterday_Morning: BI
    => Time_of_Obs: DI
  Time_of_Release:
    => Time_of_Release: PE
    => Today: D
    => Period_of_Detention: PF
  Time_of_Arrest:
    => Time_of_Arrest: PE
    => Yesterday_Morning: D
    => Period_of_Detention: PS
  Time_of_Obs:
    => Time_of_Obs: PE
    => Yesterday_Evening: D
  Period_of_Detention:
    => Period_of_Detention: E|PE
    => Time_of_Arrest: PSI
    => Time_of_Release: PFI<jupyter_text>Pretty Print Network Dict<jupyter_code>import pprint
pprint.pprint(nssdf_dict)
print(json.dumps(nssdf_dict))<jupyter_output>{"name": "NSSDF 2009 Example 2", "algebra": "Extended_Linear_Interval_Algebra", "description": "Using Semantic Web Technology to Exploit Soft Information", "nodes": [["Yesterday", ["ProperInterval"]], ["Today", ["ProperInterval"]], ["Yesterday_Morning", ["ProperInterval"]], ["Yesterday_Evening", ["ProperInterval"]], ["Time_of_Obs", ["Point"]], ["Time_of_Arrest", ["Point"]], ["Time_of_Release", ["Point"]], ["Period_of_Detention", ["ProperInterval", "Point"]]], "edges": [["Yesterday", "Today", "M"], ["Yesterday", "Yesterday_Morning", "SI"], ["Yesterday", "Yesterday_Evening", "FI"], ["Today", "Time_of_Release", "DI"], ["Yesterday_Morning", "Yesterday_Evening", "B"], ["Yesterday_Morning", "Time_of_Arrest", "DI"], ["Yesterday_Evening", "Time_of_Obs", "DI"], ["Time_of_Arrest", "Period_of_Detention", "PS"], ["Time_of_Release", "Period_of_Detention", "PF"]]}<jupyter_text>The following was reformated from the json.dumps operation, above:<jupyter_code>{
    "name": "NSSDF 2009 Example 2",
    "algebra": "Extended_Linear_Interval_Algebra",
    "description": "Using Semantic Web Technology to Exploit Soft Information",
    "nodes": [
        ["Yesterday", ["ProperInterval"]],
        ["Today", ["ProperInterval"]],
        ["Yesterday_Morning", ["ProperInterval"]],
        ["Yesterday_Evening", ["ProperInterval"]],
        ["Time_of_Obs", ["Point"]],
        ["Time_of_Arrest", ["Point"]],
        ["Time_of_Release", ["Point"]],
        ["Period_of_Detention",
         ["ProperInterval", "Point"]]],
    "edges": [
        ["Yesterday", "Today", "M"],
        ["Yesterday", "Yesterday_Morning", "SI"],
        ["Yesterday", "Yesterday_Evening", "FI"],
        ["Today", "Time_of_Release", "DI"],
        ["Yesterday_Morning", "Yesterday_Evening", "B"],
        ["Yesterday_Morning", "Time_of_Arrest", "DI"],
        ["Yesterday_Evening", "Time_of_Obs", "DI"],
        ["Time_of_Arrest", "Period_of_Detention", "PS"],
        ["Time_of_Release", "Period_of_Detention", "PF"]
    ]
}<jupyter_output><empty_output><jupyter_text>dict_of_dict = nx.convert.to_dict_of_dicts(nssdf_net)pprint.pprint(dict_of_dict)<jupyter_code>{TemporalEntity(['ProperInterval'] 'Yesterday_Morning'):
 {TemporalEntity(['ProperInterval'] 'Yesterday_Morning'): {'constraint': relset(['E'])},                                                       
  TemporalEntity(['ProperInterval'] 'Yesterday_Evening'): {'constraint': relset(['B'])},                                                      
  TemporalEntity(['Point'] 'Time_of_Arrest'): {'constraint': relset(['DI'])},
  TemporalEntity(['ProperInterval'] 'Yesterday'): {'constraint': relset(['S'])}},
 TemporalEntity(['ProperInterval'] 'Yesterday_Evening'): 
 {TemporalEntity(['ProperInterval'] 'Yesterday_Morning'): 
  {'constraint': relset(['BI'])},
  TemporalEntity(['ProperInterval'] 'Yesterday_Evening'): {'constraint': relset(['E'])},
                                                          TemporalEntity(['ProperInterval'] 'Yesterday'): {'constraint': relset(['F'])},
                                                          TemporalEntity(['Point'] 'Time_of_Obs'): {'constraint': relset(['DI'])}},
 TemporalEntity(['Point'] 'Time_of_Arrest'): {TemporalEntity(['ProperInterval'] 'Yesterday_Morning'): {'constraint': relset(['D'])},
                                              TemporalEntity(['Point'] 'Time_of_Arrest'): {'constraint': relset(['PE'])},
                                              TemporalEntity(['ProperInterval', 'Point'] 'Period_of_Detention'): {'constraint': relset(['PS'])}},
 TemporalEntity(['ProperInterval'] 'Today'): {TemporalEntity(['ProperInterval'] 'Today'): {'constraint': relset(['E'])},
                                              TemporalEntity(['ProperInterval'] 'Yesterday'): {'constraint': relset(['MI'])},
                                              TemporalEntity(['Point'] 'Time_of_Release'): {'constraint': relset(['DI'])}},
 TemporalEntity(['ProperInterval'] 'Yesterday'): {TemporalEntity(['ProperInterval'] 'Yesterday_Morning'): {'constraint': relset(['SI'])},
                                                  TemporalEntity(['ProperInterval'] 'Yesterday_Evening'): {'constraint': relset(['FI'])},
                                                  TemporalEntity(['ProperInterval'] 'Today'): {'constraint': relset(['M'])},
                                                  TemporalEntity(['ProperInterval'] 'Yesterday'): {'constraint': relset(['E'])}},
 TemporalEntity(['Point'] 'Time_of_Obs'): {TemporalEntity(['ProperInterval'] 'Yesterday_Evening'): {'constraint': relset(['D'])},
                                           TemporalEntity(['Point'] 'Time_of_Obs'): {'constraint': relset(['PE'])}},
 TemporalEntity(['Point'] 'Time_of_Release'): {TemporalEntity(['ProperInterval'] 'Today'): {'constraint': relset(['D'])},
                                               TemporalEntity(['Point'] 'Time_of_Release'): {'constraint': relset(['PE'])},
                                               TemporalEntity(['ProperInterval', 'Point'] 'Period_of_Detention'): {'constraint': relset(['PF'])}},
 TemporalEntity(['ProperInterval', 'Point'] 'Period_of_Detention'): {TemporalEntity(['Point'] 'Time_of_Arrest'): {'constraint': relset(['PSI'])},
                                                                     TemporalEntity(['Point'] 'Time_of_Release'): {'constraint': relset(['PFI'])},
                                                                     TemporalEntity(['ProperInterval', 'Point'] 'Period_of_Detention'): {'constraint': relset(['E', 'PE'])}}}
net_from_dict_of_dicts = nx.convert.from_dict_of_dicts(dict_of_dict)
net_from_dict_of_dicts.summary()
nssdf_net.summary()
nssdf_net.propagate()
nssdf_net.summary()
nssdf_net.to_json()<jupyter_output><empty_output><jupyter_text>Interval Algebra<jupyter_code>!cat {book}
book_net = qr.Network(algebra_path=apath, json_file_name=book)
book_net.summary()
book_net.propagate()
book_net.summary()<jupyter_output><empty_output><jupyter_text>Extended Interval Algebra  Example from Book (What book was this?  I've forgotten.)<jupyter_code>!cat {bookx}
bookx_net = qr.Network(algebra_path=apath, json_file_name=bookx)
bookx_net.summary()
bookx_net.propagate()
bookx_net.summary()<jupyter_output><empty_output><jupyter_text>Region Connection Calculus 8<jupyter_code>!cat {rcc8}
rcc8_net = qr.Network(algebra_path=apath, json_file_name=rcc8)
rcc8_net.summary()
rcc8_net.propagate()
rcc8_net.summary()<jupyter_output><empty_output><jupyter_text>RCC8 no name & no constraint<jupyter_code>!cat {rcc8_missing}
rcc8_net_missing = qr.Network(algebra_path=apath, json_file_name=rcc8_missing)
rcc8_net_missing.summary()
rcc8_net_missing.propagate()
rcc8_net_missing.summary()<jupyter_output><empty_output><jupyter_text>Network Examination This examination uses the NetworkX API.<jupyter_code>rcc8_net
list(rcc8_net.nodes)
for n in rcc8_net.nodes:
    print(n.name)
for e in rcc8_net.edges:
    print(e)
h1 = rcc8_net.get_entity("House1")
h2 = rcc8_net.get_entity("House2")
print(h1)
print(h2)
print(rcc8_net.edges[h1, h2]['constraint'])
h1 = rcc8_net.get_entity("House1")
h2 = rcc8_net.get_entity("House2")
rcc8_net.get_edge_data(h1, h2)
rcc8_net.get_edge("House1", "House2")<jupyter_output><empty_output><jupyter_text>Output Network to JSON Format<jupyter_code>!cat {nssdf}
nssdf_net.to_json()<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.15946049359096998, 'fraction_numerical': 0.007365601683566099, 'mean_word_length': 4.150246305418719, 'pattern_counts': {'":': 10, '<': 50, '<?xml version=': 0, '>': 108, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 34, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '13', 'dir': 'jupyter-structured-clean-dedup', 'id': '450149', 'license': 'MIT', 'n_tokens_mistral': 3592, 'n_tokens_neox': 3376, 'n_words': 569, 'path': 'Notebooks/Obsolete_Maybe/output_network_to_json.ipynb', 'repo_name': 'alreich/qualreas', 'size': '10454'}