rdflib

How can I insert variable into SPARQL query?

How can I insert variable into SPARQL query? Question: I use the rdflib library. I need to insert a variable into a SPARQL query. I do this: q = prepareUpdate("""INSERT DATA { <r> a <owl:Ontology> }""") g.update(q, initBindings={‘r’: uri}) uri = ‘http://www.example.org/ontologies/example/example.owl’ g – object class Graph() Output result: <r:> a <owl:Ontology> . Required result: …

Total answers: 1

Fetching triples using SPARQL query from turtle file

Fetching triples using SPARQL query from turtle file Question: I am new to SPARQL and currently struglling to fetch triples from a turtle file. ### https://ontology/1001 <https://ontology/1001> rdf:type owl:Class ; rdfs:subClassOf <https://ontology/748>; <http://www.geneontology.org/formats/oboInOwl#hasExactSynonym> "Injury, neuronal" , "Neurotrauma" ; rdfs:label "Nervous system injury" . ### https://ontology/10021 <https://ontology/10021> rdf:type owl:Class ; rdfs:subClassOf <https://ontology/2034> ; rdfs:label "C3 glomerulopathy" …

Total answers: 1

Python rdflib – string to URIRef or Literal – inverse of .n3() method

Python rdflib – string to URIRef or Literal – inverse of .n3() method Question: I’m using rdflib to work with semantic data, and want to serialise a triple to some minimal string value. Given a triple (s,p,o), I can use rdflib’s .n3() method to return the string values representing the contents of s,p,o and join …

Total answers: 1

How to filter by language tag using g.triples in python rdflib?

How to filter by language tag using g.triples in python rdflib? Question: I would like to create a dictionary where the keys are the subjects of the triples, and the values are the objects. I am querying a graph (in this example is g) where I have multiples labels, an dI would like to filter …

Total answers: 1

How to convert Pandas DataFrame to RDF (Resource Description Framework)?

How to convert Pandas DataFrame to RDF (Resource Description Framework)? Question: I’m looking for a recipe for converting Pandas DataFrames to RDF data in Python. I’m aware of the following Python modules (I know how to Google!), but they do not work for me: rdfpandas pandasrdf Neither seems mature. I have problems with both. In …

Total answers: 1

How to get graph's namespaces in rdflib

How to get graph's namespaces in rdflib Question: I’ve loaded an RDF file in Python, using rdflib: g = rdflib.Graph() g.parse ( “foaf_ex.rdf” ) the *.rdf defines a number of prefix/namespace pairs (e.g., foaf:) and I know they come into g because they’re still there when I print g.serialize(). My question is, is there an …

Total answers: 2

Visualize an RDFLIB Graph in Python

Visualize an RDFLIB Graph in Python Question: 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 …

Total answers: 2