Core Concepts/Components

Knowledge Graph

Understanding the KnowledgeGraph object as a container for graph components.

See the documentation for the Knowledge Graph model.

The Knowledge Graph in General

In knowledge representation and reasoning, a knowledge graph is a knowledge base that uses a graph-structured data model to represent and operate on data. It stores interlinked descriptions of entities—objects, events, situations, or abstract concepts—and encodes the relationships underlying these entities.

At its core, a knowledge graph is a digital structure that represents knowledge as concepts and the relationships between them (facts). This information is typically stored in a graph database and visualized as a graph structure.

The KnowledgeGraph Object in the Perseus Client

In the Perseus Client, the KnowledgeGraph is the main object that encapsulates all the components of a knowledge graph. It acts as a container for the Entity, Relation, and LiteralValue objects that are parsed from the API's TTL output.

A KnowledgeGraph object holds the complete structure of the graph—all the nodes, edges, and their properties—as well as relevant metadata.

Knowledge Graph Components

A KnowledgeGraph object has several key attributes:

  • entities: A list of Entity objects that represent the nodes in the graph.
  • relations: A list of Relation objects that represent the edges connecting the entities.
  • namespaces: A dictionary mapping namespace prefixes to their full URIs. Namespaces are used to shorten long URIs, making the data more readable and manageable. For example, the prefix rdf is commonly used as a shorthand for http://www.w3.org/1999/02/22-rdf-syntax-ns#.

Example of a KnowledgeGraph Object

Here is an example of what a comprehensive KnowledgeGraph object might look like in the Perseus Client.

KnowledgeGraph(
    namespaces={
        'rdf': 'http://www.w3.org/1999/02/22-rdf-syntax-ns#',
        'rdfs': 'http://www.w3.org/2000/01/rdf-schema#',
        'owl': 'http://www.w3.org/2002/07/owl#',
        'prop': 'https://example.org/ontology/property/',
        'rel': 'https://example.org/ontology/relations/',
        'person': 'https://example.org/ontology/person/',
        'data': 'http://example.org/data/'
    },
    entities=[
        Entity(
            uri="data:MarieCurie",
            types=["person:Person"],
            properties={
                "rdfs:label": LiteralValue(value="Marie Curie")
            },
        ),
        Entity(
            uri="data:NobelPrizeInPhysics",
            types=["prop:Award"],
            properties={
                "rdfs:label": LiteralValue(value="Nobel Prize in Physics")
            },
        )
    ],
    relations=[
        Relation(
            source_uri="data:MarieCurie",
            target_uri="data:NobelPrizeInPhysics",
            predicate="rel:wonAward",
            properties={
                "prop:year": LiteralValue(value=1903)
            },
        )
    ]
)