Skip to main content

semantic_network Package

SemanticNetwork

The class is designed for encoding graph structures using universal triplets:

entity_1 relation entity_2
entity_2 relation entity_3
  • Triplet parts are separated by spaces
  • First and third parts are objects
  • Second part is a directed relationship between objects

1. Creating and Extending the Graph:

from semantic_network import SemanticNetwork

script = """
    Circle hasPart Circle.radius
    Circle hasPart Circle.center
"""

sn = SemanticNetwork.from_script(script)

script_2 = """
    c1 fromProto Circle
    c1 hasPart c1.radius
    c2 fromProto Circle
    c2 hasPart c2.radius
    c2 hasPart c2.center
    c2.radius fromProto Circle.radius
"""

sn.append_script(script_2)

This creates a graph with objects and relationships:

print(sn)
----------------------------------------
|- c1
|- Circle
|- c1 fromProto Circle
|- c1.radius
|- c1 hasPart c1.radius
|- c2
|- c2 fromProto Circle
|- c2.radius
|- c2 hasPart c2.radius
|- c2.center
|- c2 hasPart c2.center
|- Circle.radius
|- c2.radius fromProto Circle.radius
----------------------------------------

Search queries are specified using a special query format. Elements starting with * are treated as variables, while other elements are treated as constants.

q = """
    *o1 hasPart *o2
    *o1 fromProto Circle
"""

for objs, rels in sn.query(q):
    print(objs, rels)

Returns dictionaries with found graph fragments:

{'o1': 'c2', 'Circle': 'Circle', 'o2': 'c2.radius'} {'fromProto': 'fromProto', 'hasPart': 'hasPart'}
{'o1': 'c2', 'Circle': 'Circle', 'o2': 'c2.center'} {'fromProto': 'fromProto', 'hasPart': 'hasPart'}
{'o1': 'c1', 'Circle': 'Circle', 'o2': 'c1.radius'} {'fromProto': 'fromProto', 'hasPart': 'hasPart'}

During search, the system also verifies that the query graph is connected and acyclic.

3. Utility Methods

# Extend the graph
sn.append_script(new_script)

# Print graph description (number of unique objects and relationships)
sn.describe()

# Create a copy
sn.copy()

# Serialization to dictionary and creation from dictionary
sn.to_dict()
sn = SemanticNetwork.from_dict(dict_data)

# Write to file with additional custom variables dictionary, and read from file
sm.dump(path, variables)
sn = SemanticNetwork.load(path)

Metadata

Release files for semantic-network 0.2.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for semantic-network 0.2.0
File Size Uploaded Provenance Actions
semantic_network-0.2.0.tar.gz 12.6 kB Without provenance Details for semantic_network-0.2.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for semantic-network 0.2.0
File Interpreter ABI Platform Actions
semantic_network-0.2.0-py3-none-any.whl Python 3 none any Details for semantic_network-0.2.0-py3-none-any.whl

Total release size: 23.4 kB

Release files / semantic_network-0.2.0.tar.gz

Download URL semantic_network-0.2.0.tar.gz
Size 12.6 kB
Tags Source
SHA-256 checksum
How to use checksums
e95428bdd0f6b7a0d7bbc530e9f699796a2e7b75fc8df958b7b9b08b9218abfa
BLAKE2b-256 checksum
How to use checksums
6f6f894f03c462feeb1b7d94d5e56a4f1d548448f47bc119a100c45595ac2e7f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.12.11

Release files / semantic_network-0.2.0-py3-none-any.whl

Download URL semantic_network-0.2.0-py3-none-any.whl
Size 10.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
5aa68cbc4f7e4dccf1932e9d9c2696de30d5a2ce16c6b291154761a0c19a4f7d
BLAKE2b-256 checksum
How to use checksums
1d3206125ef5cc2e75945debf5a86d127ca25d9308583b4241b430dcd8159eae
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.12.11

Security for semantic-network 0.2.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page