Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/linkml/linkml-sparql
Maps LinkML queries to SPARQL and back (ALPHA)
https://github.com/linkml/linkml-sparql
linked-data linkml ontology orm queries rdf rdflib semantic-web sparql
Last synced: 26 days ago
JSON representation
Maps LinkML queries to SPARQL and back (ALPHA)
- Host: GitHub
- URL: https://github.com/linkml/linkml-sparql
- Owner: linkml
- Created: 2021-07-20T02:30:58.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2021-07-20T02:31:10.000Z (over 3 years ago)
- Last Synced: 2024-11-10T10:13:57.097Z (3 months ago)
- Topics: linked-data, linkml, ontology, orm, queries, rdf, rdflib, semantic-web, sparql
- Language: Python
- Homepage:
- Size: 10.7 KB
- Stars: 3
- Watchers: 4
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# linkml-sparql: ORM for SPARQL endpoints
This provides a way of querying either in-memory RDF graphs or remote SPARQL endpoints using a LinkML specified datamodel.
## Step 1: Define your datamodel and RDF bindings
As an example, a small schema for a portion of DBpedia:
```yaml
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: dbontclasses:
Thing:
slots:
- id
- label
- comment
- typeFood:
is_a: Thing
exact_mappings:
- wd:Q2095
slots:
- servingTemperature
- servingSize
- alias
- cuisine
- ingredientName
- origin
- region
- distributor
- approximateCalories
- carbohydrate
- fat
- protein
```## Step 2: Create Python dataclasses
```bash
pipenv run gen-python dbont.yaml > dbont.py
```## Step 3: Code
```python
from dbont import Food
from linkml_sparql import QueryEngine, SparqlEndpointschema = 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
More documentation coming soon. For now, consult the tests.
## TODOs
Functionality is very incomplete
- remote querying via DESCRIBE can be inefficient
- ...lots more