Python bindings for Sage.
Sage is an open-source Knowledge Graph which uses https://schema.org and JSON-LD serialization inspired by Google's Knowledge Graph.
Sage basically reads your .jsonld
file & builds a Knowledge Graph using https://schema.org standards. It can also
load in Knowledge triples from WikiData, or any FOAF
ontology.
The sage.core
package is written in Cython - meaning it has to be built before usage. To
build it simply run the Cython build script in the project root:
sh ./scripts/cython.sh
The Sage API has a relatively simple API. The code snippet below builds a simple Knowledge Graph.
from config.consts import FS
from sage.core.utils import Log, File
from sage.core.graph import KnowledgeGraph
# !- Loading Graph data from File.
path = File.join(FS.CACHE_DIR, 'graph/examples/avatar.jsonld')
# !- Loading KnowledgeGraph from file.
kg = KnowledgeGraph.fromfile(path)
# INFO | New Vertex: label: Avatar, schema=Movie
# INFO | New Vertex: label: James Cameron, schema=Person
Log.debug(kg.graph.vertices)
# DEBUG | [<Vertex(label='Avatar', schema='Movie')>, <Vertex(label='James Cameron', schema='Person')>]
# !- Retrieve Vertices in the Graph.
avatar = kg.graph['Avatar', 'Movie']
Log.debug(f'avatar = {avatar}')
# DEBUG | avatar = <Vertex(label='Avatar', schema='Movie')>
Log.debug(f'avatar.payload = {avatar.payload}')
# DEBUG | avatar.payload = {'name': 'Avatar', 'genre': 'Science Fiction', 'trailer': 'https://example.com/trailer
Log.debug(f'avatar.edges = {avatar.edges}')
# DEBUG | avatar.edges = [<Edge(e147c670075ef62b, director)>]
# !- Close Knowledge Graph connection.
kg.close()
You are very welcome to modify and use them in your own projects.
Please keep a link to the original repository. If you have made a fork with substantial modifications that you feel may be useful, then please open a new issue on GitHub with a link and short description.
This project is opened under the Apache License 2.0 which allows very broad use for both private and commercial purposes.
A few of the images used for demonstration purposes may be under copyright. These images are included under the "fair usage" laws.