我很难找到一个明确,明智的rdflib使用上下文的例子.ConjunctiveGraph不接受上下文,并且不推荐使用Graph.我应该如何在同一个全局ConjunctiveGraph中的不同上下文中创建和操作?
我正在尝试在SPARQL的python实现(现在在rdfextras中)使用IN和NOT IN语句(如果我理解正确,在SPARQL 1.1中引入),但似乎语法无法识别.
我们考虑两组(A和B).我想输出Set A中的内容,删除Set B中的内容.
SELECT ?title WHERE {
some logic defining ?item and ?SetB
FILTER (?item NOT IN ?SetB)
}
Run Code Online (Sandbox Code Playgroud)
也许这个特殊的东西是在SPARQL 1.1中添加的并且不受支持rdfextra,在这种情况下我希望有一个解决方法(或者如何在不使用NOT IN关键字的情况下执行此操作)
我要检查两个单词之间的上位/下位词关系(由用户给定的),这意味着它们中的任何可以是其他上位词或它也可以是不存在的two.Can之间没有上位词关系我使用path_similarity的情况下我正试图这样做.如果你可以建议任何更好的方法.我也想知道从sparql查询检查相同是否更好
first=wn.synset('automobile.n.01')
second=wn.synset('car.n.01')
first.path_similarity(second)
Run Code Online (Sandbox Code Playgroud) 我需要使用 rdflib 将 csv 文件转换为 rdf,我已经有了读取 csv 的代码,但我不知道如何将其转换为 rdf。
我有以下代码:
import csv
from rdflib.graph import Graph
# Open the input file
with open('data.csv', 'rb') as fcsv:
g = Graph()
csvreader = csv.reader(fcsv)
y = True
for row in csvreader:
if y:
names = row
y = False
else:
for i in range(len(row)):
continue
print(g.serialize(format='xml'))
fcsv.close()
Run Code Online (Sandbox Code Playgroud)
有人可以解释一下并举个例子吗?
在以下最小测试用例中:
from rdflib import Graph, Namespace, Literal, RDF
base = "http://test.com/ns"
foobar = Namespace("http://test.com/ns#")
g = Graph(base=base)
g.bind('foobar', foobar)
g.add((foobar.something, RDF.type, Literal('Blah')))
g.add((foobar.something, foobar.contains, Literal('a property')))
g.add((foobar.anotherthing, RDF.type, Literal('Blubb')))
g.add((foobar.anotherthing, foobar.contains, Literal('another property')))
print(g.serialize(format='turtle').decode("utf-8"))
Run Code Online (Sandbox Code Playgroud)
我明白了
@base <http://test.com/ns> .
@prefix foobar: <http://test.com/ns#> .
<#anotherthing> a "Blubb" ;
ns1:contains "another property" .
ns1:something a "Blah" ;
ns1:contains "a property" .
Run Code Online (Sandbox Code Playgroud)
我期望的更像是
@base <http://test.com/ns> .
@prefix foobar: <http://test.com/ns#> .
<#anotherthing> a "Blubb" ;
foobar:contains "another property" .
<#something> a "Blah" ;
foobar:contains "a …Run Code Online (Sandbox Code Playgroud) 访问rdf列表成员的最佳方法是什么?我正在使用rdflib(python),但在普通的SPARQL中给出的答案也可以(这种类型的答案可以通过rdfextras,一个rdflib帮助程序库使用).
我正在尝试访问由Zotero生成的rdf中的特定期刊文章的作者(为简洁起见,已删除了一些字段):
<rdf:RDF
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:z="http://www.zotero.org/namespaces/export#"
xmlns:dcterms="http://purl.org/dc/terms/"
xmlns:bib="http://purl.org/net/biblio#"
xmlns:foaf="http://xmlns.com/foaf/0.1/"
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:prism="http://prismstandard.org/namespaces/1.2/basic/"
xmlns:link="http://purl.org/rss/1.0/modules/link/">
<bib:Article rdf:about="http://www.ncbi.nlm.nih.gov/pubmed/18273724">
<z:itemType>journalArticle</z:itemType>
<dcterms:isPartOf rdf:resource="urn:issn:0954-6634"/>
<bib:authors>
<rdf:Seq>
<rdf:li>
<foaf:Person>
<foaf:surname>Lee</foaf:surname>
<foaf:givenname>Hyoun Seung</foaf:givenname>
</foaf:Person>
</rdf:li>
<rdf:li>
<foaf:Person>
<foaf:surname>Lee</foaf:surname>
<foaf:givenname>Jong Hee</foaf:givenname>
</foaf:Person>
</rdf:li>
<rdf:li>
<foaf:Person>
<foaf:surname>Ahn</foaf:surname>
<foaf:givenname>Gun Young</foaf:givenname>
</foaf:Person>
</rdf:li>
<rdf:li>
<foaf:Person>
<foaf:surname>Lee</foaf:surname>
<foaf:givenname>Dong Hun</foaf:givenname>
</foaf:Person>
</rdf:li>
<rdf:li>
<foaf:Person>
<foaf:surname>Shin</foaf:surname>
<foaf:givenname>Jung Won</foaf:givenname>
</foaf:Person>
</rdf:li>
<rdf:li>
<foaf:Person>
<foaf:surname>Kim</foaf:surname>
<foaf:givenname>Dong Hyun</foaf:givenname>
</foaf:Person>
</rdf:li>
<rdf:li>
<foaf:Person>
<foaf:surname>Chung</foaf:surname>
<foaf:givenname>Jin Ho</foaf:givenname>
</foaf:Person>
</rdf:li>
</rdf:Seq>
</bib:authors>
<dc:title>Fractional photothermolysis for the treatment of acne scars: a report of …Run Code Online (Sandbox Code Playgroud) 是否可以使用RDFLIB绘制Sesame RDF数据库的图形?这是我试过的:
endpoint = "http://127.0.0.1:8080/openrdf-workbench/repositories/movies/explore?resource=%3Cfile%3A%2F%2Fmovies_export.rdf%3E"
from rdflib import Graph
g = Graph()
g.parse(endpoint)
Run Code Online (Sandbox Code Playgroud)
这是错误:
Traceback (most recent call last):
File "C:\Software\rdflib\movieGraph.py", line 10, in <module>
g.parse(endpoint)
File "c:\python26_32bit\lib\site-packages\rdflib\graph.py", line 756, in parse
parser = plugin.get(format, Parser)()
File "c:\python26_32bit\lib\site-packages\rdflib\plugin.py", line 89, in get
raise PluginException("No plugin registered for (%s, %s)" % (name, kind))
rdflib.plugin.PluginException: No plugin registered for (application/xml, <class
'rdflib.parser.Parser'>)
Run Code Online (Sandbox Code Playgroud)
我认为唯一的技巧是指定一个正确的URL来使Sesame返回.rdf xml布局.
问题的作者:转发到http://answers.semanticweb.com/questions/9414/python-using-rdflib-to-graph-a-sesame-database(见那里的答案)
我正在尝试使用 RDFlib Python 中的以下查询针对用户的名字文字获取 uri。
plugin.register(
'sparql', rdflib.query.Processor,
'rdfextras.sparql.processor', 'Processor')
plugin.register(
'sparql', rdflib.query.Result,
'rdfextras.sparql.query', 'SPARQLQueryResult')
f1Str="Thomas"
ecsuri= GraphS.query("""
PREFIX akt: <http://www.aktors.org/ontology/portal#>
SELECT ?akturi WHERE{
?akturi akt:family-name ?fname.
FILTER (?fname = """+f1Str+""")
}""")
Run Code Online (Sandbox Code Playgroud)
它给出了以下错误,似乎是由于f1Str,我们如何使用存储在某个变量中的值过滤 SPARQL 中的数据。请帮忙。
*Exception Type: ParseException
Exception Value: Expected "}" (at char 481), (line:10, col:29)*
Run Code Online (Sandbox Code Playgroud) 我开始使用该rdflib库在 Python 中处理 rdf 数据。目前,我想创建一个.n3rdf 图的文件,如下所示:
@prefix ns1: <http://some.namespace/with/name#> .
@prefix ns2: <http://second.namespace/some/name#>
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
@prefix xml: <http://www.w3.org/XML/1998/namespace> .
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
<my_example> ns1:annotated_with [ ns1:annotation
ns2: annotation_value> ] ;
ns1:name "myname" .
Run Code Online (Sandbox Code Playgroud)
也就是说,该图中有一个名为 的示例my_example,其名称为“myname”。此示例使用注释值为 的对象进行注释annotation value。我想用 Python 构建这个示例,如下所示:
import rdflib
gg=rdflib.graph.Graph()
ns1 = rdflib.Namespace('http://some.namespace/with/name#')
ns2 = rdflib.Namespace('http://second.namespace/some/name#')
u = rdflib.term.URIRef('my_example')
gg.add((u, ns1.name, rdflib.Literal('myname')))
blank = rdflib.BNode()
gg.add((u, ns1.annotated_with, blank))
gg.add((blank, ns1.annotation, ns2.annotation_value))
print gg.serialize(format='n3') …Run Code Online (Sandbox Code Playgroud) 我正在使用 rdflib 将 RDF 图加载到 Python 脚本中 我想使用定义的前缀打印主题列表 我没有找到任何应用前缀的方法。我的代码
import rdflib
filepath = "... my file path ..."
gs = rdflib.Graph()
gs.bind('qs', "http://qs.org/")
gs.bind('foaf',"http://xmlns.com/foaf/0.1/")
gs.parse(filepath,format="nt")
mdstr = ""
for subject in gs.subjects():
mdstr += str(subject) +"\n"
print(mdstr)
Run Code Online (Sandbox Code Playgroud)
例如,我得到 http://qs.org/s12095 代替 qs:s12095