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 your research and applications.
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://xmlns.com/foaf/0.1/')
Explore terms, autocompletion works!
onto.terms.foaf.Person
/home/docs/checkouts/readthedocs.org/user_builds/tools4rdf/checkouts/fix_dc/tools4rdf/network/parser.py:289: UserWarning: foaf:isPrimaryTopicOf is a superproperty of foaf:homepage, but not found in attribute.
warnings.warn(
/home/docs/checkouts/readthedocs.org/user_builds/tools4rdf/checkouts/fix_dc/tools4rdf/network/parser.py:289: UserWarning: foaf:isPrimaryTopicOf is a superproperty of foaf:openid, but not found in attribute.
warnings.warn(
/home/docs/checkouts/readthedocs.org/user_builds/tools4rdf/checkouts/fix_dc/tools4rdf/network/parser.py:289: UserWarning: rdfs:label is a superproperty of foaf:name, but not found in attribute.
warnings.warn(
foaf:Person
onto.terms.foaf.Person.uri, onto.terms.foaf.Person.description
('http://xmlns.com/foaf/0.1/Person', rdflib.term.Literal('A person.'))
Another term
onto.terms.foaf.familyName
foaf:familyName
Find domain and range of the term
onto.terms.foaf.familyName.domain, onto.terms.foaf.familyName.range
(['foaf:Person'], ['Literal'])
Build SPARQL queries automatically, and execute them on endpoints
df = onto.query(
'https://dbpedia.org/sparql',
onto.terms.foaf.Person,
onto.terms.foaf.familyName,
limit=10,
)
df
| Person | familyNamevalue | |
|---|---|---|
| 0 | http://dbpedia.org/resource/Sami_Kelopuro | Kelopuro |
| 1 | http://dbpedia.org/resource/Ben_Lamb_(poker_pl... | Lamb |
| 2 | http://dbpedia.org/resource/Juha_Helppi | Helppi |
| 3 | http://dbpedia.org/resource/Patrik_Antonius | Antonius |
| 4 | http://dbpedia.org/resource/Peter_Jetten | Jetten |
| 5 | http://dbpedia.org/resource/Viacheslav_Zhukov | Zhukov |
| 6 | http://dbpedia.org/resource/Chris_Moorman | Moorman |
| 7 | http://dbpedia.org/resource/Mitch_Schock | Schock |
| 8 | http://dbpedia.org/resource/Tommy_Angelo | Angelo |
| 9 | http://dbpedia.org/resource/Eric_Haber | Haber |
We can take a look at the SPARQL query that was executed:
q = onto.create_query(
onto.terms.foaf.Person,
onto.terms.foaf.familyName,
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 ?familyNamevalue
WHERE {
?Person foaf:familyName ?familyNamevalue .
{ ?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](add link)