semantic-network


Namesemantic-network JSON
Version 0.2.0 PyPI version JSON
download
home_pageNone
SummarySemantic network implementation
upload_time2025-10-22 21:14:10
maintainerNone
docs_urlNone
authorNone
requires_python>=3.7
licenseMIT
keywords rdf semantic network graph
VCS
bugtrack_url
requirements networkx pytest
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # 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
    ----------------------------------------


#### 2. Graph Search
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)

            

Raw data

            {
    "_id": null,
    "home_page": null,
    "name": "semantic-network",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.7",
    "maintainer_email": null,
    "keywords": "rdf, semantic, network, graph",
    "author": null,
    "author_email": "Alexander Abramov <extremal.ru@gmail.com>",
    "download_url": "https://files.pythonhosted.org/packages/6f/6f/894f03c462feeb1b7d94d5e56a4f1d548448f47bc119a100c45595ac2e7f/semantic_network-0.2.0.tar.gz",
    "platform": null,
    "description": "# semantic_network Package\n## SemanticNetwork\n\nThe class is designed for encoding graph structures using universal triplets:\n\n    entity_1 relation entity_2\n    entity_2 relation entity_3\n\n- Triplet parts are separated by spaces\n- First and third parts are objects\n- Second part is a directed relationship between objects\n\n\n#### 1. Creating and Extending the Graph:\n\n    from semantic_network import SemanticNetwork\n\n    script = \"\"\"\n        Circle hasPart Circle.radius\n        Circle hasPart Circle.center\n    \"\"\"\n\n    sn = SemanticNetwork.from_script(script)\n\n    script_2 = \"\"\"\n        c1 fromProto Circle\n        c1 hasPart c1.radius\n        c2 fromProto Circle\n        c2 hasPart c2.radius\n        c2 hasPart c2.center\n        c2.radius fromProto Circle.radius\n    \"\"\"\n\n    sn.append_script(script_2)\n\nThis creates a graph with objects and relationships:\n\n    print(sn)\n    ----------------------------------------\n    |- c1\n    |- Circle\n    |- c1 fromProto Circle\n    |- c1.radius\n    |- c1 hasPart c1.radius\n    |- c2\n    |- c2 fromProto Circle\n    |- c2.radius\n    |- c2 hasPart c2.radius\n    |- c2.center\n    |- c2 hasPart c2.center\n    |- Circle.radius\n    |- c2.radius fromProto Circle.radius\n    ----------------------------------------\n\n\n#### 2. Graph Search\nSearch queries are specified using a special query format.\nElements starting with * are treated as variables, while other elements are treated as constants.\n\n    q = \"\"\"\n        *o1 hasPart *o2\n        *o1 fromProto Circle\n    \"\"\"\n\n    for objs, rels in sn.query(q):\n        print(objs, rels)\n\nReturns dictionaries with found graph fragments:\n\n    {'o1': 'c2', 'Circle': 'Circle', 'o2': 'c2.radius'} {'fromProto': 'fromProto', 'hasPart': 'hasPart'}\n    {'o1': 'c2', 'Circle': 'Circle', 'o2': 'c2.center'} {'fromProto': 'fromProto', 'hasPart': 'hasPart'}\n    {'o1': 'c1', 'Circle': 'Circle', 'o2': 'c1.radius'} {'fromProto': 'fromProto', 'hasPart': 'hasPart'}\n\nDuring search, the system also verifies that the query graph is connected and acyclic.\n\n\n#### 3. Utility Methods\n\n    # Extend the graph\n    sn.append_script(new_script)\n\n    # Print graph description (number of unique objects and relationships)\n    sn.describe()\n    \n    # Create a copy\n    sn.copy()\n\n    # Serialization to dictionary and creation from dictionary\n    sn.to_dict()\n    sn = SemanticNetwork.from_dict(dict_data)\n\n    # Write to file with additional custom variables dictionary, and read from file\n    sm.dump(path, variables)\n    sn = SemanticNetwork.load(path)\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "Semantic network implementation",
    "version": "0.2.0",
    "project_urls": {
        "Homepage": "https://github.com/avabr/semantic-network",
        "Issues": "https://github.com/avabr/semantic-network/issues",
        "Repository": "https://github.com/avabr/semantic-network"
    },
    "split_keywords": [
        "rdf",
        " semantic",
        " network",
        " graph"
    ],
    "urls": [
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "1d3206125ef5cc2e75945debf5a86d127ca25d9308583b4241b430dcd8159eae",
                "md5": "3815ed95b904c868150ad9e503d3a14f",
                "sha256": "5aa68cbc4f7e4dccf1932e9d9c2696de30d5a2ce16c6b291154761a0c19a4f7d"
            },
            "downloads": -1,
            "filename": "semantic_network-0.2.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "3815ed95b904c868150ad9e503d3a14f",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.7",
            "size": 10877,
            "upload_time": "2025-10-22T21:14:09",
            "upload_time_iso_8601": "2025-10-22T21:14:09.193274Z",
            "url": "https://files.pythonhosted.org/packages/1d/32/06125ef5cc2e75945debf5a86d127ca25d9308583b4241b430dcd8159eae/semantic_network-0.2.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "6f6f894f03c462feeb1b7d94d5e56a4f1d548448f47bc119a100c45595ac2e7f",
                "md5": "42a1cc67928d804af5fecb41f471d9fe",
                "sha256": "e95428bdd0f6b7a0d7bbc530e9f699796a2e7b75fc8df958b7b9b08b9218abfa"
            },
            "downloads": -1,
            "filename": "semantic_network-0.2.0.tar.gz",
            "has_sig": false,
            "md5_digest": "42a1cc67928d804af5fecb41f471d9fe",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.7",
            "size": 12570,
            "upload_time": "2025-10-22T21:14:10",
            "upload_time_iso_8601": "2025-10-22T21:14:10.433319Z",
            "url": "https://files.pythonhosted.org/packages/6f/6f/894f03c462feeb1b7d94d5e56a4f1d548448f47bc119a100c45595ac2e7f/semantic_network-0.2.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2025-10-22 21:14:10",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "avabr",
    "github_project": "semantic-network",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "requirements": [
        {
            "name": "networkx",
            "specs": [
                [
                    "==",
                    "3.4.2"
                ]
            ]
        },
        {
            "name": "pytest",
            "specs": []
        }
    ],
    "lcname": "semantic-network"
}
        
Elapsed time: 0.49704s