Questions tagged [rdflib]
RDFLib is a Python library for working with RDF. It supports parsers and serializers for different syntaxes (RDF/XML, N3, N-Triples, Turtle, TriX and RDFa) as well of remote and local SPARQL queries. Please do not use this tag for rdflib.js.
427
questions
0
votes
1
answer
25
views
How can I insert variable into SPARQL query?
I use the rdflib library. I need to insert a variable into a SPARQL query.
I do this:
q = prepareUpdate("""INSERT DATA { <r> a <owl:Ontology> }""")
g.update(q,...
0
votes
0
answers
31
views
How can I add an annotation for a property between two individuals using rdflib
I'm using rdflib in python to build a graph, and how can i use it to add an annotation for a property between two individuals.
For example, graph namespace is <http//:example.com/test#>, two ...
3
votes
0
answers
37
views
Changing the join order in a custom RDFLib store
In a project we override the store triples method to generate virtual triples given a subject/predicate or predicate/object pair. And the logic depends on either the subject or object being bound to a ...
0
votes
0
answers
13
views
how to sort RDFLIB output based on the lines of code written and not alphabetically?
when I save my RDFLIB code, the output TTL is alphabetically ordered. However, I want parts of a group to be together, or at least the output follows the lines of g.add(()) command. Is there away to ...
0
votes
1
answer
26
views
Parsing an ontology in Python using rdflib and Google Collab
I have an ontology in an 'owl' file (quran_data_full.owl) and I saved it in a folder in my google drive (Quran Corpus). I want now to perform some queries in this ontology and this is my first time ...
0
votes
1
answer
25
views
Customize output of `serialize` from the rdflib Python library
Table of contents
The context
What I want to do
Why I want to do this?
The context
I know how to generate a Turtle file using Python and rdflib. See minimal working example below. It generates a ...
1
vote
0
answers
56
views
Why does Python return 'ModuleNotFoundError: No module named ...' if the module is properly installed?
I'm trying to import "rdflib" (from rdflib import Graph) for my Python code. For some reason, when I launch the code, the console returns me ModuleNotFoundError: No module named 'rdflib'. I ...
1
vote
0
answers
46
views
Converting JSON data to JSON-LD and creating an RDF graph using pyld and rdflib - issues with defining the context
I have a problem with handling JSON data from different sources. So, my plan was to use JSON-LD, and store the data from a source in RDF so that I can do some analysis work on them. But I don't know ...
2
votes
1
answer
39
views
Fetching triples using SPARQL query from turtle file
I am new to SPARQL and currently struglling to fetch triples from a turtle file.
### https://ontology/1001
<https://ontology/1001> rdf:type owl:Class ;
...
1
vote
0
answers
27
views
Rdflib and activitystreams
so I'm investigating rdflib to use with ActivityStreams. My current main goal is to input an Object and get the same one back!
My current try looks like this
import rdflib
G = rdflib.Graph()
G.parse('...
1
vote
0
answers
52
views
Restrict SPARQL property path predicates based on blank node attached meta / reified data
I want to traverse graph starting from any "root" concept and getting down to its leaf concepts moving by reified predicates of certain type (e.g. hasChild only).
I have a large graph in ...
0
votes
1
answer
56
views
Getting the query string out of an rdflib prepared query
How do I recover the original string from an rdflib preparedQuery.
In other words,
query_string = "select ?s {?s ?p ?o.}"
q = prepareQuery(query_string)
I would like to run some function ...
1
vote
0
answers
27
views
Fuseki returns no results when called from Python vs curl or online
I'm setting up Fuseki/Jena to host a persistent collection of rdf and I'd like to control uploads through a python interface using rdflib graph objects as a means of pre-filtering/mastering the ...
0
votes
0
answers
24
views
Mirror/setup of a Python rdflib graph from a remote SPARQL endpoint
How do I setup a Python rdflib graph from a remote SPARQL endpoint?
I have done a SELECT ?s ?p ?o WHERE { ?s ?p ?o } SPARQL query to the remote endpoint to get all triples and I have downloaded the ...
0
votes
0
answers
28
views
rdflib - fastest method for cloning rdflib.Graph
I've a task where I'm attempting to load data into a graph, but the upload process is sensitive to the contents of the graph since I'm performing some data mastery at load-time.
I don't want to update ...
0
votes
0
answers
28
views
Collecting duplicate entries into single object in python
I am working with RDFLib and using graph. This graph contains subject, predicate and object. Below is the sample filtered content of the graph (entries are randomly ordered):
Subject : 3....
0
votes
1
answer
24
views
Python rdflib - string to URIRef or Literal - inverse of .n3() method
I'm using rdflib to work with semantic data, and want to serialise a triple to some minimal string value.
Given a triple (s,p,o), I can use rdflib's .n3() method to return the string values ...
0
votes
0
answers
20
views
Getting a union graph using rdflib and anzograph
I have a number of graphs in an anzograph. Using rdflib, I want to access them as a union graph.
Without the store and parsing the graphs into memory, it works fine as a ConjunctiveGraph. However, ...
0
votes
1
answer
47
views
Using rdflib with anzograph
I am using the community edition of anzograph. I have no problem using the sparql http protocol, however when I try to use the graph store protocol via rdflib I get a result I don't understand. I am ...
1
vote
1
answer
89
views
python rdflib doesn't export @context and @graph when serializing with json-ld
I have created a Graph() in rdflib 6.2.0 and attempting to export it as JSON-LD. My expectation was that I would end up with a @context containing all the namespace prefixes and a @graph containing ...
1
vote
0
answers
108
views
Owlready2: importing in-memory rdflib graph
I have an ontology that defines a subject area, and have used that to help construct an rdflib graph of object instances, and their interrelating properties.
I'm using python, owlready2 and rdflib ...
0
votes
1
answer
54
views
How to make rdflib serialize to XML without creating nested objects
I have a simple model of nodes with interelationships and the RDF file that defines it is a flat list of XML objects, one for each Node. But when I use rdflib to parse the file, operate on it and ...
0
votes
1
answer
51
views
Extract specific triples from turtle file using SPARQL
I am in a learning phase of SPARQL. I am using rdflib to extract some triples from a graph. I have loaded the triple file and stored it is a graph object. The turtle file looks like below.
https://...
0
votes
0
answers
40
views
"KeyError: rdflib.term.BNode" Error appeared when executing SPARQL query
I'm trying to retrieve all intersection members for a specific class from a .owl ontology using SPARQL. I executed the following SPARQL query :
PREFIX rdfs:<http://www.w3.org/2000/01/rdf-...
0
votes
0
answers
82
views
Extracting the TBox Axioms from an Ontology using Python
I am currently working on an algorithm for Descriptive Logics. I wanted to do try this project in Python, even though I am familiar with the strengths of OWL API in Java.
Currently I am stuck on ...
0
votes
0
answers
122
views
Merging Ontology by using rdflib
I have two files one ttl and owl. And I need to merge both of them together and create an equivalences as triples. I am using the pizza ontology.
One file is cw_onto.owl and other pizza.ttl
1
vote
0
answers
40
views
Equivalence of load() and dump() functions from Php 'EasyRdf' in Python 'rdflib'
I recently started working with Knowledge Graphs and RDFs, and I was fortunate enough that someone provided me with an introductory excercise, which helped me implement some basic functionalities on a ...
0
votes
1
answer
83
views
How to filter by language tag using g.triples in python rdflib?
I would like to create a dictionary where the keys are the subjects of the triples, and the values are the objects. I am querying a graph (in this example is g) where I have multiples labels, an dI ...
0
votes
0
answers
77
views
Run SPARQL query from Jupyter (python) for JanusGraph via Gremlin
I have JanusGraph and Gremlin running on a remote machine. From Jupyter notebook, I can connect to JanusGraph and create graph from RDF using rdf2gremlin.
CONNECTION_STRING = "ws://<ip>:<...
0
votes
0
answers
63
views
RDFLib: Accessing default graph of `rdflib.Dataset`
I don't seem to have any way of accessing only the default graph inside of a rdflib.Dataset.
from rdflib import Dataset
ds = Dataset()
trig_string = (
'<dg:s> <dg:p> <dg:o>. '
...
0
votes
0
answers
239
views
How to open and parse large n-triple file with Python?
I want to create a large list of person names and for this reason I downloaded a n-triple file from the KB Yago4. I used the Python library RDFLib and this code:
from rdflib.graph import Graph
g = ...
0
votes
0
answers
29
views
SPARQL-query (RDFlib 6.1.1) with NOT EXIST or BIND produce ParseException
Neither (NOT) EXIST nor BIND works with RDFlib 6.1.1 and Python 3.10.
BIND - Example:
SELECT ?Column ?PK1
WHERE {
?Column rdf:type dimd:PrimaryKey ;
dimd:isPrimaryKey ?PK1 .
BIND( ?PK1 AS ...
1
vote
1
answer
62
views
problem using Uniprot SPARQL endpoint and CONSTRUCT
From SPARQLwrapper I can successfully query and return results using SPARQL select. When I try to use the CONSTRUCT example from the website I get and error "ExpatError: no element found: line 1, ...
0
votes
1
answer
88
views
Forcing libraries that use requests library to use my proxy explicitly defined in get request
I'm trying to parse an RDF file using RDFLib. However, I have to use a proxy when making requests and I don't know how to get RDFLib to use my proxy.
import rdflib
g = rdflib.Graph()
g.parse(url)
...
0
votes
1
answer
60
views
A DBpedia SPARQL query misses small number of triples when asking for large number of relations
I'm running the following SPARQL query on DBpedia (in fact I'm running a similar CONSTRUCT query via rdflib, see blow in the edited section):
SELECT *
WHERE {
{ ?influencer dbo:influenced ?...
0
votes
1
answer
35
views
Execute N3 rules on top of a Turtle file using Python
I have a turtle RDF file that contains all information related to an ontology and some instances and an N3 file that has different rules.
My goal is to execute the N3 rules on top of the Turtle file. ...
1
vote
2
answers
213
views
Parametrized SPARQL Queries with python RDFLib
I am trying to query a very simple database about Alloys with a parametrized SPARQL query using RDFLib:
x = "Inconel_625"
g = Graph()
g.parse ("Desktop/materials.ttl")
...
0
votes
2
answers
102
views
Serializing `rdflib.Dataset` into the default graph?
I am looking to parse data into the default graph of a rdflib.Dataset by using ds.add(...) or ds.parse(...). When I try to serialize to application/trig or application/n-quads, I can see that the ...
1
vote
0
answers
199
views
Creating named graph with rdflib in Virtuoso
The following code works for me when using Apache Jena Fuseki 4.3.2 (docker image secoresearch/fuseki:4.3.2) with rdflib 6.1.1:
from rdflib import Graph
from rdflib.plugins.stores.sparqlstore import ...
1
vote
1
answer
89
views
How to change literals of type xsd:date to xsd:dateTime using Python?
I have a graph which uses Literals of datatype xsd:date to save dates. However I want to use an .owl version of that graph in a reasoner, and the reasoner only accepts the xsd:dateTime format. Is ...
0
votes
1
answer
61
views
SPARQL queries and user defined vocabulary
I am trying to play with rdflib and a (my) user defined vocabulary (name: ODE).
To do that I have generated a class namespace/_ODE.py derived from DefinedNamespace:
1 from rdflib.term import URIRef
...
0
votes
1
answer
91
views
rdflib's parseQuery decode the query string which cause invalid URI
I have the following ttl file:
@prefix : <https://www.example.co/reserved/language#> .
<https://www.example.co/reserved/root> :_id "01G39WKRH76BGY5D3SKDHJP2SX" ;
:transcript%...
0
votes
1
answer
57
views
RDFLIB : SPARQL count query gives an inappropriate output
I am new to python and SPARQL. I am trying to get the count of the metadata where the subject is "social sciences" from a list of .ttl files. I am using the below code. However, the output ...
0
votes
1
answer
84
views
HTTPS connection with RDFLib
I am using Python and the RDFLib library and I want to perform an HTTPS connection to a SPARQL endpoint such as Amazon Nepute (HTTPS is mandatory) and perform authentication. However, I cannot find in ...
0
votes
0
answers
131
views
Know the ObjectProperty of two subclasses using owlready
I built an ontology for units as follows:
Class: Unit -> Class: Temperature -> Classes: K, deg C, etc
Class: UnitTerms -> Classes: heat dissipation, storage temperature,...etc
-> means ...
0
votes
0
answers
46
views
How to run SPARQL queries in R (WBG Topical Taxonomy) without parallelization
I am an R user and I am interested to use the World Bank Group (WBG) Topical Taxonomy through SPARQL queries.
This can be done directly on the API https://vocabulary.worldbank.org/PoolParty/sparql/...
2
votes
1
answer
439
views
Creating Owlready2 properties dynamically
I am in need of creating an ontology dynamically.
for classes I am creating them using below method.
with onto:
NewClass = types.new_class(class_name, tuple(SuperClasses))
But for creating ...
0
votes
0
answers
67
views
How can rdflib parse an arithmetic expression in RDF
To say an arithmetic expression like x=m/n^2, I express it in RDF as follows:
@prefix : <http://ex.org/> .
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
@prefix math: <...
0
votes
2
answers
262
views
How to add an Ontology IRI with the Python rdflib library?
My problem is described here but the (maybe old) proposed solution does not work for me!
https://github.com/RDFLib/rdflib/issues/817
I would like to use rdflib to fill with Python the Ontology IRI ...
0
votes
1
answer
357
views
How to get all items of a blank node in rdflib
I'm new to RDflib, I want to implement a feature like this:
To say, Person hasProperty Weight(kg) , Height(m),
and BMI (Body Mass Index)=Weight/Height^2, so if Bob's Weight=70, Height=1.75, How to ...