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.

Resources

Please do not confuse the RDFLib Python library with the rdflib.js Javascript library.

439 questions
1
vote
1 answer

How to set up the ID of a json element in rdflib

Context I am loading a rdf file in rdflib, and am trying to export it in json-ld. The original rdf looks like: A substation The exported…
Guillaume
  • 2,325
  • 2
  • 22
  • 40
1
vote
1 answer

How to update RDF graph by instantiating the variables existing in triples with values?

I have a knowledge base that looks as follows: @prefix ex: . @prefix rdfs: . ex:a a ex:C . ex:C rdfs:subClassOf ex:D . ex:D rdfs:subClassOf ex:E . And I have the following rule: s…
izolveidon
  • 59
  • 1
  • 1
  • 10
1
vote
1 answer

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 file called output.txt in Turtle format. import…
rdrg109
  • 265
  • 1
  • 8
1
vote
0 answers

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 run the same code a few months ago and it always worked, so…
1
vote
0 answers

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 how to turn a regular JSON in a JSON-LD correctly.…
Derk
  • 11
  • 2
1
vote
0 answers

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 =…
Helge
  • 111
  • 1
  • 2
1
vote
0 answers

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 which Concepts C are connected with named predicates…
Sinbud
  • 40
  • 5
1
vote
1 answer

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 content before it reaches the persistence layer. I've…
Thomas Kimber
  • 10,601
  • 3
  • 25
  • 42
1
vote
0 answers

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 libraries. I had tried constructing the instances…
Thomas Kimber
  • 10,601
  • 3
  • 25
  • 42
1
vote
0 answers

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 local Apache server using Php and EasyRdf. My…
JakeTheDog
  • 11
  • 3
1
vote
1 answer

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, column 0" I've tested my code with a dbpedia…
scuffster
  • 51
  • 1
1
vote
2 answers

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") knows_query = """ SELECT ?min ?max WHERE { ?s rdfs:label """+x+"""; mydb:min…
grizzli11
  • 45
  • 1
  • 5
1
vote
0 answers

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 SPARQLUpdateStore FUSEKI_QUERY =…
Roman
  • 91
  • 5
1
vote
1 answer

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 there any way to change the datatype of my date…
1
vote
0 answers

Get union entities from knowledge graphs

Some entities/classes present in knowledge-graphs have operations performed on them like 'Union', 'Intersection' etc. Below is one ontology file which has has lots of union operations on various of its classes. ontology -> Link Problem : I wanted to…
Zenmate
  • 41
  • 4