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

Can an rdflib program use user defined ontology

Not sure if it is a dumb question, but I am looking for an example program using rdflib which works with local ontology. I am seeing lots of examples using standard ontolgies like FOAF, but I want to write a python program that works with a user…
Laeeq Khan
  • 167
  • 10
1
vote
0 answers

How to parse multiple ttl files into rdf graph from colab directory

I have a couple of files out of which I have to make an RDF graph. Instead of parsing each file again and again by having to write the name of the files, I tried to use the following code: from rdflib import Graph g = Graph() import os directory =…
K C
  • 413
  • 4
  • 15
1
vote
0 answers

How to print a part of results from rdf graph and make a subcluster of it

For a rdf-graph based project I have to do the following: parse an rdf graph from rdf and ttl files make subclusters on them and undergo network analysis comment upon how to improvise clustering techniques to improvise the semantic web…
K C
  • 413
  • 4
  • 15
1
vote
1 answer

RDFLib + JSON-LD + Named Graphs: how to override graph name when using @graph?

Disposition Full illustrative code is available at this Gist. Imagine we're describing a blog article in a JSON-LD document. In addition to a few properties of the article itself (its type and label), we want to add some semantic data for the…
Anatoly Scherbakov
  • 1,672
  • 1
  • 13
  • 20
1
vote
0 answers

Use Literal or String as SPARQL Predicate

I am constructing a small knowledge graph from triples of strings using rdflib. A typical triple would look like: "Bob" "went" "home", and I am adding them to my graph as shown below (I know I should be using standard objects and namespaces, but…
Joel Oduro-Afriyie
  • 1,563
  • 14
  • 13
1
vote
2 answers

RDFlib Blank node update query

I am trying to update the object of a triple with a blank node as its subject using RDFlib. I firstly select the blank node in the first function and insert this blank node into the update query in the second function, however, this doesn't provide…
Alex
  • 21
  • 5
1
vote
0 answers

Renaming a namespace's prefix

I have a TTL file like so: @prefix owl: . @prefix : . :Custom_Object a owl:Class . Ideally using rdflib or similar, I would like to load this file and change the prefix for http://example.com…
jarthur
  • 393
  • 1
  • 2
  • 18
1
vote
1 answer

Validating .ttl elements with rdflib

Is there a way using rdflib or a similar package to validate a set of elements? e.g. from rdflib import Graph, Namespace, Literal from rdflib.namespace import DCTERMS n = Namespace("http://example.org/books/") n.book g = Graph() g.bind("dc",…
jarthur
  • 393
  • 1
  • 2
  • 18
1
vote
0 answers

Extra RDF:Description added when encoding RDF triples (serialized to XML)

I'm trying to generate the following XML using rdflib:
Carlos Vega
  • 1,341
  • 2
  • 13
  • 35
1
vote
1 answer

How to get only value AAA in sparql result (rdflib.term.Literal('AAA'),)

Here is my problem: I'm trying using sparql to get the value and show only result for web user the problem is i only know how to get result include rdflib.term.Literal('AAA') Is there any way to get only the value AAA without rdflib.term.Literal…
ngocvy
  • 11
  • 3
1
vote
2 answers

#rdflib (python): how to get a URIRef from a string such as 'ns:xxx'?

I have a RDFlib graph g, whose NameSpaceManager is aware of some namespaces. How do I get a URIRef from a string such as 'ns:xxx', where ns is the prefix associated to a namespace known by g.namespace_manager? Basically, I'm looking for a method…
fps
  • 33
  • 7
1
vote
1 answer

RDFlib adding blank nodes in triples

I'm using the RDFlib to automate the process of creating the DSD. I want to get a format as follows: _:refPeriodStep1 a qb4o:HierarchyStep; etc... but using this: graph.add((BNode('refPeriodStep1'), RDF.type, URIRef(qb4o + 'HierarchyStep'))) the…
1
vote
1 answer

Nested triples with units on value in rdflib - > turtle file

I'm currently making a turtle file. I have to relate values/units based on qudt.org Based on example data shown below: data = { "objectid_l1": "Bridge_1", "defid_l1": "Bridge", "objectid_l2": "Deck_1", …
Revnixcad
  • 61
  • 6
1
vote
1 answer

Is it possible to automatically merge ontologies so that exact matches are consolidated under one preferred term?

My goal is to merge together YSO, JUPO and JUHO ontologies (from Finto-ontology family:https://finto.fi/en/). Using Python's RDFlib library I have been able to merge different turtle-files and get an union of the ontologies, using the graph merging…
1
vote
1 answer

Extracting labels from owl ontologies when the label isn't in the ontology but can be found at the URI

Please bear with me as I am new to semantic technologies. I am trying to use the package rdflib to extract labels from classes in ontologies. However some ontologies don't contain the labels themselves but have the URIs of classes from other…
Lorcán
  • 555
  • 3
  • 15