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
4
votes
1 answer

SPARQL parameterized queries

Good day! I apply rdflib for python. I have a question. How can I put variable into SPARQL's query ? Instead of 'OSPF' in course:OSPF! qres = g.query( """SELECT ?x ?z ?y WHERE { course:OSPF course:termName ?x. …
zhalnin
  • 43
  • 4
4
votes
2 answers

How to perform arithmetic operations in Sparql with python?

I am writting a public domain calculator, whose code is available at: https://github.com/okfn/pdcalc/blob/master/pd/map.rdf The code is currently unable to properly determine the public domain status of a work because of an issue that has been…
okhaos
  • 41
  • 1
4
votes
2 answers

python 3.9 and rdflib keep changing slashes in a url

I am completely new in Python . I am using 3.9.2 and rdflib . I try to execute the first example, from rdflib import Graph g = Graph() g.parse('http://dbpedia.org/resource/Semantic_Web') for s, p, o in g: print(s, p, o) I create a py file ,…
codebot
  • 517
  • 8
  • 29
  • 55
4
votes
1 answer

RDFlib 'on disk' store

After 2 days of research I (a newby) still can't figure out what 'on disk' stores are available in RDFFlib 3.1.0. If you have a working example, that would be nice to see... For my app I prefer SQLite. I need no access to online RDF stores, I want…
ArtDijk
  • 1,957
  • 6
  • 23
  • 31
4
votes
0 answers

Can NetworkX library read RDF data in Ntriple format and build a Graph object along with attributes or node features

Can NetworkX library read RDF data in Ntriple format and build a Graph object along with attributes or node features. I tried the below code to convert the RDF data(.nt file) in to Graph using the rdflib, from rdflib.extras.external_graph_libs…
Mahek
  • 71
  • 3
4
votes
1 answer

how to add comment or label to the graph in RDFLib?

I'm trying to add names of datasets to the graph object and later retrieve them, pretty sure there must be easy way to accomplish it, but could not find anything so far ... thanks
user52028778
  • 27,164
  • 3
  • 36
  • 42
4
votes
1 answer

Using prefixes to display entities from an rdflib graph

I'm using rdflib to load an RDF graph into a Python scrpit I would like to print a list of subjects using the defined prefixes I doesn't find any method to apply the prefixes. My code import rdflib filepath = "... my file path ..." gs =…
Moissinac
  • 63
  • 5
4
votes
1 answer

how to look-up rdf object knowing subject or other way around?

I'm using RDFLIB to build graphs among 3 data-sets (A, B, C) with ntriples. Goal: graphs contain links among those data-set A->B, B->C and C->A, I want to check consistency of those links by making sure that links outgoing from A refer back to the…
user52028778
  • 27,164
  • 3
  • 36
  • 42
4
votes
1 answer

RDFlib: Add triples to graph in bulk

I am parsing triple files and adding the triples into my local triplestore. Code Snippet: graph = ConjunctiveGraph('Sleepycat') graph.open("mytriplestore", create=False) g = Graph() g.parse("filename.ttl", format="ttl") for t in g: …
RDangol
  • 179
  • 9
4
votes
1 answer

Custom SPARQL functions in rdflib

What is a good way to hook a custom SPARQL function into rdflib? I have been looking around in rdflib for an entry point for custom function. I found no dedicated entry point but found that rdflib.plugins.sparql.CUSTOM_EVALS might be a place to add…
Finn Årup Nielsen
  • 6,130
  • 1
  • 33
  • 43
4
votes
1 answer

How can I speed up SPARQL query from Python RDFLib?

I have loaded a large RDF dataset (Geonames dataset: 18GB) in PostgreSQL tables using rdflib_sqlalchemy.SQLAlchemy. I have run following simple query from Python script with RDFLib support. It has taken more than two hours to give me the result. Is…
Beautiful Mind
  • 5,828
  • 4
  • 23
  • 42
4
votes
1 answer

Bulk edit subject of triples in rdflib

I create an rdflib graph by parsing records from a database using rdflib-jsonld. However, the subject of triples has a missing / from the url. To add it, I use the following code: for s,p,o in graph1: print 'parsing to graph2. next step…
kurious
  • 1,024
  • 10
  • 29
4
votes
3 answers

RDFLib parser does not recognize json-ld format

My code in Python 3.4: from rdflib import Graph, plugin import json, rdflib_jsonld from rdflib.plugin import register, Serializer register('json-ld', Serializer, 'rdflib_jsonld.serializer', 'JsonLDSerializer') context = { "@context": { …
Brainlock
  • 243
  • 4
  • 11
4
votes
2 answers

Rdflib, Python: Are there any object framing methods to get nested dict/list structure from a graph a-la JSON-LD?

Rdflib CONSTRUCT query returns a list of tuples representing a graph. However, template languages usually are most convenient with a tree-like structures of nested mixed dicts and lists (because the structure matches well with tree-like structure of…
Roman Susi
  • 4,135
  • 2
  • 32
  • 47
4
votes
2 answers

rdflib "repeat node-elements" parse error with OWL/XML file

I have an OWL file prepared in Protege by someone else. I'm trying to parse it with the following Python code, but keep getting a parse error. import rdflib g=rdflib.Graph() result = g.parse(r'myfile.owl') rdflib.exceptions.ParserError:…
Melanie
  • 1,349
  • 2
  • 17
  • 27
1 2
3
29 30