rdflib

How can I use the RDFLIB module in Python to retrieve a value from an OWL file using SparQL?

放肆的年华 提交于 2021-02-10 19:39:06
问题 I am currently trying to write a script in Python that uses the RDFLIB module in order to retrieve a specific value from an OWL file by using SPARQL. The problem I'm facing is that the current version of my script returns no data. I tried to print each row in order for myself to analayse the output, but the output simply reads "Process finished with exit code 0". My final goal is to retrieve a value (in the example, this value will be '96') from the OWL file. The object to which this value is

RDFlib 'on disk' store

南笙酒味 提交于 2021-01-27 07:45:26
问题 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 to store info about relations inside the organisation in RDF. Thanks 回答1: Here you have an example to make it work with MySQL. I don't think rdflib 3 works with SQLite. import rdflib from rdflib.Graph import ConjunctiveGraph as Graph from rdflib

Visualize an RDFLIB Graph in Python

落爺英雄遲暮 提交于 2020-05-26 09:16:39
问题 I am new to RDFLIB in python. I found this example of creating a graph on here. What is the simplest way to visualize graph created by this code? import rdflib # Now we create a graph, a representaiton of the ontology g = rdflib.Graph() # Now define the key words that we will use (the edge weights of the graph) has_border_with = rdflib.URIRef('http://www.example.org/has_border_with') located_in = rdflib.URIRef('http://www.example.org/located_in') # define the things - base level objects that

Search by name in rdf/n3 file

五迷三道 提交于 2020-01-15 10:54:29
问题 I have to perform some filtering in a turtle/n3 file, returning another file of the same kind. The basic data element (location) i work on is this: :pt0001 vcard:category "Poste e Telegrafi" ; vcard:fn "Ufficio Bologna 1" ; vcard:extended-address "Via Cairoli 9, Bologna BO, Italy" ; vcard:latitude "44.504192" ; vcard:longitude "11.338661" ; vcard:tel "051 243425" ; vcard:fax "051 244459" ; cs:opening "Mon, Tue, Wed, Thu, Fri: 0800-1330. Sat: 0800-1230." ; cs:closing "01-01, 01-06, P, LA, 04

RDFLib: get all URIs under a namespace

主宰稳场 提交于 2020-01-14 04:31:09
问题 How to get the list of URIs under a Namespace in RDFlib? For example, we can do: from rdflib.namespace import FOAF But how do we find out what URIs are available in FOAF? In fact, there are several namespaces (RDF, RDFS, FOAF, ...), and I find it difficult to explore which URIs are within each of them, and which one to use. Say, if I want to express a belonging relationship, should I use RDFS.member or something else? Is there a standard for linked data or it's still ad-hoc? I'm new to RDFs

How to iterate over CONSTRUCT output from rdflib?

独自空忆成欢 提交于 2020-01-07 03:05:28
问题 This is a follow-up question from How to prevent triples from getting mixed up while uploading to Dydra programmatically? I've created a new graph using SPARQL CONSTRUCT query. I now want to iterate over it so that I can add the statements to an RDFlib graph and then insert the data into another triplestore. I have the following questions: If SPARQL CONSTRUCT returns a graph, do I still need to iterate over the statements and add them to an RDFlib graph? I probably need to do so to be able to

How to INSERT all triples from an RDFlib graph into another repository without iterating through every triple?

橙三吉。 提交于 2020-01-06 21:58:54
问题 This question is related to What URI to use for a Sesame repository while executing a SPARQL ADD query. I'm trying to INSERT all triples from a Sesame repository into another (Dydra). There are a couple of ways to do it, such as using SERVICE clause or Dydra's GUI. However, Dydra restricts the use of SERVICE and I want an efficient way to insert the data programmatically. This is the code I have right now: queryStringUpload = 'INSERT {?s ?p ?o} WHERE GRAPH %s {?s ?p ?o}' % dataGraph sparql =

How to perform arithmetic operations in Sparql with python?

一笑奈何 提交于 2020-01-03 18:53:34
问题 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 encountered with sparql 1.0: it does not appear to be possible to perform arithmetic operation on dates, which means that the calculator cannot determine e.g. whether or not the work has been published 70 years after the death of the author.

rdflib SPARQL queries (involving subclasses) not behaving as expected

怎甘沉沦 提交于 2020-01-02 19:29:14
问题 I have just started to self-learn RDF and the Python rdflib library. But I have hit an issue with the following code. I expected the queries to return mark and nat as Persons and only natalie as a Professor. I can't see where I've gone wrong. (BTW, I know Professor should be a title rather than a kind of Person, but I'm just tinkering ATM.) Any help appreciated. Thanks. rdflib 4, Python 2.7 >>> from rdflib import Graph, BNode, URIRef, Literal INFO:rdflib:RDFLib Version: 4.2. >>> from rdflib

Using Python rdflib: how to include literals in sparql queries?

僤鯓⒐⒋嵵緔 提交于 2020-01-01 03:37:08
问题 I can include URIs and variables in my queries, but I can't include literals in my queries. Here, I have some code which successfully reads an RDF file, finds all the RDF triples with skos:prefLabels, counts them, and then identifies a couple of specific ones from a set of keywords: import rdflib.plugins.sparql as sparql import rdflib import rdflib.graph as g graph = g.Graph() # Read the RDF file graph.parse( 'h:\......SKOSTaxonomy.rdf', format='xml') # Build and execute the query q = sparql