Skip to main content

No project description provided

Project description

<img src="lodkit.png" width=50% height=50%>

LODKit

License: GPL v3 PyPI version

LODKit is a collection of Linked Open Data related Python functionalities.

LODkit (includes|will include)

  • a custom rdflib.Graph subclass that is capable of
    • RDFS and OWL-RL inferencing
    • Bnode-safe graph merging [todo]
  • a custom importer for loading RDF files as if they where Python modules
  • LOD-specific type definitions
  • [...]

Examples

lodkit.Graph

lodkit.Graph is an rdflib.Graph subclass that is cabable of RFDS and OWL-RL inferencing.

The default plugin for inferencing is the owlrl native Python inferencing engine. The deductive closure type used for lodkit.Graph is RDFS_OWLRL_Semantics which allows for RDFS and OWL-RL reasoning.

from lodkit.graph import Graph

from rdflib import Namespace
from rdflib.namespace import OWL

ex = Namespace("http://example.org/")

graph = Graph()
graph.add((ex.subj, ex.pred, ex.obj))
graph.add((ex.inverse, OWL.inverseOf, ex.pred))


len(graph)                              # 2
(ex.obj, ex.inverse, ex.subj) in graph  # False

graph.inference(reasoner="owlrl")

len(graph)                              # 359
(ex.obj, ex.inverse, ex.subj) in graph  # True

The reasoner parameter of lodkit.Graph.inference (so far) also takes

Also the reasoner parameter takes Reasoner objects directly, see reasoners.py.

lodkit.importer

lodkit.importer is a custom importer for importing RDF files as if they where regular Python modules. RDF files are parsed into rdflib.Graph instances and made available in the module namespace.

E.g. in a directory structure

├── dir/
│   ├── main.py
│   ├── some_rdf.ttl
│   ├── subdir/
│       └── some_more_rdf.xml

the following creates rdflib.Graph instances in the current module namespace:

# main.py
import lodkit.importer

import some_rdf
from subdir import some_more_rdf

print(type(some_rdf))       # <class 'rdflib.graph.Graph'>
print(type(some_more_rdf))  # <class 'rdflib.graph.Graph'>

I find this really convenient for bulk-parsing graphs (example).

lodkit.utils

lodkit.utils (is|will be) a general collection of LOD related utilities.

plist

plist is a simple shorthand for referencing a triple subject by multiple predicates i.e. basically a Python representation of what is expressed in ttl with ';' and what the Turtle docs call "predicate lists".).

E.g. the following creates a list of 3 triples relating to a single subject:

from lodkit.utils import plist

from rdflib import Literal, Namespace, URIRef
from rdflib.namespace import RDF, FOAF


REL = Namespace("http://www.perceive.net/schemas/relationship/")

triples = plist(
    URIRef("http://example.org/#green-goblin"),
    (REL.enemyOF, URIRef("http://example.org/#spiderman")),
    (RDF.type, FOAF.Person),
    (FOAF.name, Literal("Green Goblin"))
)

graph = triples.to_graph()
print(graph.serialize())

Output:

@prefix foaf: <http://xmlns.com/foaf/0.1/> .
@prefix ns1: <http://www.perceive.net/schemas/relationship/> .

<http://example.org/#green-goblin> a foaf:Person ;
    ns1:enemyOF <http://example.org/#spiderman> ;
    foaf:name "Green Goblin" .

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

lodkit-0.1.6.tar.gz (20.2 kB view hashes)

Uploaded Source

Built Distribution

lodkit-0.1.6-py3-none-any.whl (20.9 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page