rdflib

performing sparql query on the rdf data stored in relational database

我是研究僧i 提交于 2019-12-13 04:33:34
问题 I have stored large amount of RDF data into a relational database with the help of rdflib_sqlalchemy.SQLAlchemy.Now I want to execute Sparql query over the same.I can not find any thing to know how to implement sparql query here. Can anyone help. 回答1: Including sample code would make it easier to know what you are after but see the documentation on querying an RDFLib graph with SPARQL. Using the example from the rdflib-sqlalchemy README where graph is the name of the open graph. rq = "select

SPARQL query performance with rdflib-sqlalchemy

≯℡__Kan透↙ 提交于 2019-12-12 17:15:06
问题 I have 7200 or so SKOS.Concept objects created by rdflib-sqlalchemy from parsing a turtle file stored in a Postgres DB. The following SPARQL query takes over 30 seconds to respond with data: SELECT ?subject ?prefLabel WHERE { ?subject rdf:type <http://www.w3.org/2004/02/skos/core#Concept> . ?subject skos:prefLabel ?prefLabel . FILTER (lang(?prefLabel) = 'en') } order by ?prefLabel LIMIT 20 OFFSET 0 I am using the limit and offset to paginate through results. I pass in the language parameter

Same sparql not returning same results

纵饮孤独 提交于 2019-12-12 06:56:05
问题 I'm using the same sparql statement using two different clients but both are not returning the same results. The owl file is in rdf syntax and can be accessed here. This is the sparql statement: PREFIX wo:<http://purl.org/ontology/wo/> PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> select ?individual where { ?individual rdf:type wo:Class } I'm using it using top braid and the following python program: >>> import rdflib >>> import rdfextras >>> rdfextras.registerplugins() >>> g

How to prevent triples from getting mixed up while uploading to Dydra programmatically?

筅森魡賤 提交于 2019-12-12 06:34:23
问题 I am trying to upload some data to Dydra from a Sesame triplestore I have on my computer. While the download from Sesame works fine, the triples get mixed up (the s-p-o relationships change as the object of one becomes object of another). Can someone please explain why this is happening and how it can be resolved? The code is below: #Querying the triplestore to retrieve all results sesameSparqlEndpoint = 'http://my.ip.ad.here:8080/openrdf-sesame/repositories/rep_name' sparql = SPARQLWrapper

SPARQL - Unknown namespace prefix error

痞子三分冷 提交于 2019-12-11 14:24:09
问题 I have a python file with imported rdflib and some SPARQL query implemented from rdflib import Graph import html5lib if __name__ == '__main__': g = Graph() g.parse('http://localhost:8085/weather-2.html', format='rdfa') res1 = g.parse('http://localhost:8085/weather-2.html', format='rdfa') print(res1.serialize(format='pretty-xml').decode("utf-8")) print() res2 = g.query("""SELECT ?obj WHERE { <http://localhost:8085/weather-2.html> weather:region ?obj . } """) for row in res2: print(row) res1

different output from rdflib SPARQL query when using initBindings

余生颓废 提交于 2019-12-11 11:07:09
问题 I've been trying to run a query on rdflib graph (loaded with schema.rdfa from schema.org ) to find the ancestors. E.g. As per Schema for Corporation the ancestors are Thing > Organization > Corporation This code works perfectly, giving me the output I desire, except that it does not use initBindings and I have to format the query string. import rdflib subject = rdflib.term.URIRef('http://schema.org/Corporation') inplace_query = ''' SELECT ?class where { <%(subject_uri)s> rdfs:subClassOf* ?mid

Querying letter mu in Sparql

左心房为你撑大大i 提交于 2019-12-11 05:04:10
问题 I am using python library RDFLIB to query on semantic dicom owl file. I need to query for a label containing letter mu. I am not able to figure out how to query for labels containing this letter. The code is given below - q = """SELECT ?ur WHERE{?ur rdfs:label "Exposure in uAs".}""" qres = g.query(q) for row in qres: print(row) I am not getting any results for the above query. The semantic dicom owl files contain the following triples - Image of what I am trying to search contents of sedi

SPARQL parameterized queries

随声附和 提交于 2019-12-07 09:48:31
问题 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. course:OSPF ?s ?t. ?s ?d ?z. ?t course:termName ?y. FILTER (regex(?z,"[^a-z]","i") && isLiteral(?z) ) }""" ,initNs=dict(course=Namespace..... @ msalvadores I want enter my Variable by console. --->python parse.py OSPF A value of variable(OSPF) may be another one. How can I initialize it

Reading a Turtle/N3 RDF File with Python

我的未来我决定 提交于 2019-12-05 03:32:09
I'm trying to encode some botanical data in Turtle format, and read this data from Python using RDFLib . However, I'm having trouble, and I'm not sure if it's because my Turtle is malformed or I'm misusing RDFLib. My test data is: @PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> . @PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> . @PREFIX p: <http://www.myplantdomain.com/plant/description> . p:description a rdfs:Property . p:name a rdfs:Property . p:language a rdfs:Property . p:value a rdfs:Property . p:gender a rdfs:Property . p:inforescence a rdfs:Property . p:color a rdfs

INSERT/DELETE/UPDATE query using SPARQLWrapper

↘锁芯ラ 提交于 2019-12-04 04:02:16
问题 Although I have gone through lot of examples on the web explaining the use of python SPARQLWrapper using SELECT statements for fetching data from sesame triple store, but not sure how can we INSERT/DELETE/UPDATE statements in sesame using it. Can any of you please guide in this regard. Thanks 回答1: The SPARQL queries are send as GET request, but the UPDATE (like INSERT, DELETE, etc.) requires the query be send as a POST request. Just add the following line before sparql.query() sparql.method =