This provides a way of querying either in-memory RDF graphs or remote SPARQL endpoints using a LinkML specified datamodel.
As an example, a small schema for a portion of DBpedia:
id: http://dbpedia.org/ontology/
imports:
- linkml:types
prefixes:
dbont: http://dbpedia.org/ontology/
dbproperty: http://dbpedia.org/property/
dbr: http://dbpedia.org/resource/
linkml: https://w3id.org/linkml/
geo: http://www.w3.org/2003/01/geo/wgs84_pos#
wd: http://www.wikidata.org/entity/
rdf: http://www.w3.org/1999/02/22-rdf-syntax-ns#
rdfs: http://www.w3.org/2000/01/rdf-schema#
default_prefix: dbont
classes:
Thing:
slots:
- id
- label
- comment
- type
Food:
is_a: Thing
exact_mappings:
- wd:Q2095
slots:
- servingTemperature
- servingSize
- alias
- cuisine
- ingredientName
- origin
- region
- distributor
- approximateCalories
- carbohydrate
- fat
- protein
pipenv run gen-python dbont.yaml > dbont.py
from dbont import Food
from linkml_sparql import QueryEngine, SparqlEndpoint
schema = YAMLGenerator(SCHEMA).schema
qe = QueryEngine(schema=schema,
endpoint=SparqlEndpoint(url='http://dbpedia.org/sparql/'),
lang='en')
objs = qe.query(type=Food.class_class_curie,
origin='dbr:Scotland',
target_class=Food)
for obj in objs:
print(f'{obj.id} {obj.label} distributed by {obj.distributor}')
More documentation coming soon. For now, consult the tests.
Functionality is very incomplete
- remote querying via DESCRIBE can be inefficient
- ...lots more