tools4rdf#
tools4RDF is a Python toolkit designed to simplify working with RDF data, ontologies, and knowledge graphs. It provides user-friendly utilities for creating, manipulating, querying, and visualizing RDF data, making it easier to integrate semantic web technologies into research and applications, particularly for domain scientists and developers without deep RDF expertise.
It is built on top of rdflib, and a primary function is the automated creation of SPARQL queries through an autocompleted programmatic interface.
Explore the examples below to get started with tools4rdf and see how it can accelerate your semantic data workflows!
A small example#
from tools4rdf import OntologyNetwork
Read in the FOAF ontology
onto = OntologyNetwork('http://purl.org/spar/foaf')
Explore terms, autocompletion works!
onto.terms.foaf.Person
foaf:Person
onto.terms.foaf.Person.uri, onto.terms.foaf.Person.description
('http://xmlns.com/foaf/0.1/Person',
rdflib.term.Literal('A person.', datatype=rdflib.term.URIRef('http://www.w3.org/2001/XMLSchema#string')))
Another term
onto.terms.foaf.name
foaf:name
Find domain and range of the term
onto.terms.foaf.name.domain, onto.terms.foaf.name.range
(['foaf:Agent',
'foaf:Project',
'foaf:Document',
'foaf:Person',
'foaf:Group',
'foaf:Organization',
'foaf:Image',
'foaf:PersonalProfileDocument'],
[])
Build SPARQL queries automatically, and execute them on endpoints
df = onto.query(
'https://dbpedia.org/sparql',
onto.terms.foaf.Person,
onto.terms.foaf.name,
limit=10,
)
df
| Person | namevalue | |
|---|---|---|
| 0 | http://dbpedia.org/resource/Esteban_Mujica | Esteban Andres Mujica Peralta |
| 1 | http://dbpedia.org/resource/Joan_Cererols | Joan Cererols |
| 2 | http://dbpedia.org/resource/Menahem_ben_Saruq | Menachem ben Saruq |
| 3 | http://dbpedia.org/resource/Rafe_de_Crespigny | Richard Rafe Champion de Crespigny |
| 4 | http://dbpedia.org/resource/0%25Mercury | 0%Mercury |
| 5 | http://dbpedia.org/resource/1472_F.C.__Abah_So... | Abah Solomon Joseph |
| 6 | http://dbpedia.org/resource/1472_F.C.__Adeka_A... | Adeka Andrew Inalegegwu |
| 7 | http://dbpedia.org/resource/1472_F.C.__Adenodi... | Adenodi Micheal Oluwasegunfunmi |
| 8 | http://dbpedia.org/resource/1472_F.C.__Afere_O... | Afere Oluwaayemi Emmanuel |
| 9 | http://dbpedia.org/resource/1472_F.C.__Akinyem... | Akinyemi Kayode John |
We can take a look at the SPARQL query that was executed:
q = onto.create_query(
onto.terms.foaf.Person,
onto.terms.foaf.name,
limit=10,
)
print(q)
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX foaf: <http://xmlns.com/foaf/0.1/>
SELECT DISTINCT ?Person ?namevalue
WHERE {
?Person foaf:name ?namevalue .
?Person rdf:type foaf:Person .
}
LIMIT 10
Other features include:
Automated SPARQL query of both local knowledge graphs and remote endpoints
Read and parse ontologies
Combine ontologies programatically and connect them
For more examples, please check here
Supported SPARQL keywords#
The queries automatically generated by tools4RDF incorporates the following SPARQL features:
PREFIXdeclarations: Automatically generated from the ontologies and namespaces in useSELECT DISTINCT: All queries use SELECT DISTINCT to retrieve unique resultsWHEREclause: Triple patterns are constructed based on the paths between source and destination termsLIMIT: The number of results can be restricted using thelimitparameterType assertions: Automatic generation of
rdf:typestatements for classesSubclass support: When subclasses are included,
UNIONclauses are generated to match any subclassComparison operators:
<,>,<=,>=,==,!=Logical operators:
&&,||for combining conditionsXSD datatype support: Filters are generated with appropriate XSD datatypes
Remote endpoints: Pass a SPARQL endpoint to the query