
ConjunctiveGraph不接受上下文,并且不推荐使用Graph.我应该如何在同一个全局ConjunctiveGraph中的不同上下文中创建和 *** 作?解决方法 是.这是代码
import rdflibfrom rdflib.Graph import Graphconj=rdflib.ConjunctiveGraph()NS=rdflib.namespace("http://example.com/#")NS_CTX=rdflib.namespace("http://example.com/context/#")alice=NS.alicebob=NS.bobcharlIE=NS.charlIEpizza=NS.pizzameat=NS.meatchocolate=NS.chocolateloves=NS.loveshates=NS.hateslikes=NS.likesdislikes=NS.dislikeslove_ctx=Graph(conj.store,NS_CTX.love)food_ctx=Graph(conj.store,NS_CTX.food)love_ctx.add( (alice,loves,bob) )love_ctx.add( (alice,charlIE) )love_ctx.add( (bob,hates,charlIE) )love_ctx.add( (charlIE,bob) )food_ctx.add( (alice,likes,chocolate) )food_ctx.add( (alice,meat) )food_ctx.add( (alice,dislikes,pizza) )print "Full context"for t in conj: print tprint ""print "Contexts"for c in conj.contexts(): print cprint "love context"for t in love_ctx: print tprint "food context"for t in food_ctx: print t 这是输出
Full context(rdflib.URIRef('http://example.com/#bob'),rdflib.URIRef('http://example.com/#hates'),rdflib.URIRef('http://example.com/#charlIE'))(rdflib.URIRef('http://example.com/#alice'),rdflib.URIRef('http://example.com/#likes'),rdflib.URIRef('http://example.com/#chocolate'))(rdflib.URIRef('http://example.com/#alice'),rdflib.URIRef('http://example.com/#meat'))(rdflib.URIRef('http://example.com/#alice'),rdflib.URIRef('http://example.com/#dislikes'),rdflib.URIRef('http://example.com/#pizza'))(rdflib.URIRef('http://example.com/#alice'),rdflib.URIRef('http://example.com/#loves'),rdflib.URIRef('http://example.com/#bob'))(rdflib.URIRef('http://example.com/#alice'),rdflib.URIRef('http://example.com/#charlIE'))(rdflib.URIRef('http://example.com/#charlIE'),rdflib.URIRef('http://example.com/#bob'))Contexts<http://example.com/context/#food> a rdfg:Graph;rdflib:storage [a rdflib:Store;rdfs:label 'IOMemory'].<http://example.com/context/#love> a rdfg:Graph;rdflib:storage [a rdflib:Store;rdfs:label 'IOMemory'].love context(rdflib.URIRef('http://example.com/#bob'),rdflib.URIRef('http://example.com/#bob'))food context(rdflib.URIRef('http://example.com/#alice'),rdflib.URIRef('http://example.com/#pizza')) 总结 以上是内存溢出为你收集整理的python – 在rdflib中使用上下文全部内容,希望文章能够帮你解决python – 在rdflib中使用上下文所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)