rdflib

Python RDFLib plugin printed unread json

橙三吉。 提交于 2019-12-25 04:16:03
问题 I am trying to reproduce the example code from https://github.com/RDFLib/rdflib-jsonld as below: from rdflib import Graph, plugin from rdflib.serializer import Serializer testrdf = ''' @prefix dc: <http://purl.org/dc/terms/> . <http://example.org/about> dc:title "Someone's Homepage"@en . ''' g = Graph().parse(data=testrdf, format='n3') print(g.serialize(format='json-ld', indent=4)) However, it seems my python output was not printed as same as the expected result. The result should be: { "@id"

Querying the shared nodes in a RDF graph

断了今生、忘了曾经 提交于 2019-12-25 03:22:53
问题 I have a graph of RDF data, that is the result of a SPARQL query in rdflib , but this question is valid just on any endpoint too. The graph looks like the picture below. I want to find a way to query the nodes that are shared between two clusters. Those are basically the nodes that are: Subject to two objects Object to two subjects Object to a subject, and, then subject to another object I tried with Graph.subjects() and Graph.objects() on rdflib it seems to me that they are only iterable and

RDFLib Blank Node Printing

早过忘川 提交于 2019-12-24 09:39:37
问题 I have an RDF dataset where triples are stored in N-Triples format like follows: <http://ebola.ndssl.bi.vt.edu/country/1> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://ebola.ndssl.bi.vt.edu/vocab/country> . _:AmapX3aXcountryX5fXcountryX5fXnameX5fXclassMapX40XX40X1 <http://ebola.ndssl.bi.vt.edu/vocab/hasValue> "Guinea" . I want to do some processing with the blank nodes. I am writing a program to reading this file in Python. I am using Python RDFLib library. After reading the file,

constructing graph using rdflib for the outputs from sparql 'SELECT' query with sparqlWrapper

廉价感情. 提交于 2019-12-24 05:59:46
问题 I am trying to construct a graph out of the results from SPARQL query. For the purpose of the query construction, I'm using SparqlWrapper and DBpedia as the knowledge base. from SPARQLWrapper import SPARQLWrapper, JSON from rdflib import Namespace, Graph, URIRef from rdflib.namespace import RDF, FOAF g = Graph() name = "Asturias" #labelName = URIRef("<http://dbpedia.org/resource/" + name +">") sparql = SPARQLWrapper("http://dbpedia.org/sparql") sparql.setQuery(""" PREFIX rdfs: <http://www.w3

constructing graph using rdflib for the outputs from sparql 'SELECT' query with sparqlWrapper

↘锁芯ラ 提交于 2019-12-24 05:59:21
问题 I am trying to construct a graph out of the results from SPARQL query. For the purpose of the query construction, I'm using SparqlWrapper and DBpedia as the knowledge base. from SPARQLWrapper import SPARQLWrapper, JSON from rdflib import Namespace, Graph, URIRef from rdflib.namespace import RDF, FOAF g = Graph() name = "Asturias" #labelName = URIRef("<http://dbpedia.org/resource/" + name +">") sparql = SPARQLWrapper("http://dbpedia.org/sparql") sparql.setQuery(""" PREFIX rdfs: <http://www.w3

SPARQL: unable to use FactForge endpoint

情到浓时终转凉″ 提交于 2019-12-24 02:22:58
问题 I am using python to run some sparql queries. I want to extract information from http://factforge.net/sparql sparql = SPARQLWrapper("http://factforge.net/sparql") query = """ # F02: Big Cities in Eastern Europe PREFIX onto: <http://www.ontotext.com/> PREFIX gn: <http://www.geonames.org/ontology#> PREFIX dbo: <http://dbpedia.org/ontology/> PREFIX dbr: <http://dbpedia.org/resource/> PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> PREFIX skos: <http://www.w3.org/2004/02/skos/core#> SELECT *

Using owl:Class prefix with rdflib and xml serialization

穿精又带淫゛_ 提交于 2019-12-23 18:15:43
问题 I would like to use the owl: prefix in the XML serialization of my RDF ontology (using rdflib version 4.1.1); unfortunately I'm still getting the serialization as rdf:Description tags. I have looked at the answer about binding the namespace to the graph at RDFLib: Namespace prefixes in XML serialization but this seems to only work when serializing using the ns format rather than xml format. Let's be more concrete. I'm attempting to get the following ontology (as taken from Introducing RDFS

Reading a Turtle/N3 RDF File with Python

假装没事ソ 提交于 2019-12-22 04:17:29
问题 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

Excluding Blank Nodes from SPARQL query results

安稳与你 提交于 2019-12-21 02:35:13
问题 I am using RDFLib to query on the Semantic Dicom Ontology. I am querying for owl:Class in the graph constructed from the above ontology. RDFLib returns results which contain blank nodes and I wish to exclude such queries. My query - from rdflib import Graph g = Graph() g.parse('dicom.owl') q = """SELECT ?c WHERE {?c rdf:type owl:Class}""" qres = g.query(q) dicom.owl is the Semantic Dicom Ontology downloaded in my machine. Some of the results that I receive - How can I modify my query to

retrieving the class name of a specific subclass in owl

此生再无相见时 提交于 2019-12-18 09:32:47
问题 I am an rdflib beginner, i have an ontology with classes and sub-classes and I need to look for a specific word in a subclass and, if it is found, return its class name. I have the following code: import rdflib from rdflib import plugin from rdflib.graph import Graph g = Graph() g.parse("test.owl") from rdflib.namespace import Namespace plugin.register( 'sparql', rdflib.query.Processor, 'rdfextras.sparql.processor', 'Processor') plugin.register( 'sparql', rdflib.query.Result, 'rdfextras