如何加载对齐格式蟒蛇? [英] how to load Alignment format in python?

查看:211
本文介绍了如何加载对齐格式蟒蛇?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有一种方法来加载校准文件蟒蛇。如果我的文件是这样的:

Is there a way to load alignment file to python. If I have file like this:

<?xml version='1.0' encoding='utf-8' standalone='no'?>
<rdf:RDF xmlns='http://knowledgeweb.semanticweb.org/heterogeneity/alignment#'
xmlns:rdf='http://www.w3.org/1999/02/22-rdf-syntax-ns#'
xmlns:xsd='http://www.w3.org/2001/XMLSchema#'
xmlns:align='http://knowledgeweb.semanticweb.org/heterogeneity/alignment#'>
<Alignment>
<map>
      <Cell>
          <entity1 rdf:resource="http://linkeddata.uriburner.com/about/id/entity//www.last.fm/music/Catie+Curtis"></entity1>
          <entity2 rdf:resource="http://discogs.dataincubator.org/artist/catie-curtis"></entity2>
        <relation>=</relation>
        <measure rdf:datatype="http://www.w3.org/2001/XMLSchema#float">1.0</measure>
      </Cell>
    </map>
<map>
      <Cell>
          <entity1 rdf:resource="http://linkeddata.uriburner.com/about/id/entity//www.last.fm/music/Bigelf"></entity1>
          <entity2 rdf:resource="http://discogs.dataincubator.org/artist/bigelf"></entity2>
        <relation>=</relation>
        <measure rdf:datatype="http://www.w3.org/2001/XMLSchema#float">0.8</measure>
      </Cell>
    </map>
<map>
      <Cell>
          <entity1 rdf:resource="http://linkeddata.uriburner.com/about/id/entity//www.last.fm/music/%C3%81kos"></entity1>
          <entity2 rdf:resource="http://discogs.dataincubator.org/artist/%C3%81kos"></entity2>
        <relation>=</relation>
        <measure rdf:datatype="http://www.w3.org/2001/XMLSchema#float">0.9</measure>
      </Cell>
    </map>
</Alignment>
</rdf:RDF>

我要保持信心值以及三: 主题:HTTP://linkeddata.uriburner.com/about/id/entity//www.last.fm/music/Catie+Curtis predicate:猫头鹰:sameAs的 对象:HTTP://discogs.dataincubator.org/artist/catie-curtis 信心:1.0

I want to keep confidence value as well as triple: Subject:http://linkeddata.uriburner.com/about/id/entity//www.last.fm/music/Catie+Curtis Predicate:owl:SameAs Object:http://discogs.dataincubator.org/artist/catie-curtis Confidence:1.0

我试图用RDFlib做到这一点,但并没有设法。 任何建议将帮助,谢谢!

I was trying to do it with RDFlib, but did not managed to. Any suggestions will help, thanks!

推荐答案

试着用雷德兰库: http://librdf.org/docs/python.html

import RDF
parser = RDF.Parser(name="rdfxml")
model = RDF.Model()
parser.parse_into_model(model, "file:./align.rdf", None)

然后查询模式变量。例如,为了检索所有比对和返回它们的措施,该查询是:

And then query the model variable. For example, in order to retrieve all the alignments and return their measure, the query is the following:

for statement in RDF.Query("SELECT ?a ?m WHERE {?a a <http://knowledgeweb.semanticweb.org/heterogeneity/alignment#Cell> ; <http://knowledgeweb.semanticweb.org/heterogeneity/alignment#measure> ?m. }",query_language="sparql").execute(model):
print "cell: %s measure:%s"%(statement['a'],statement['m'])

结果将包含字典对象的迭代器(变量名,结果),它会被打印出来,如下所示:

The result will contain an iterator of dictionary objects (variable name , result) and it will be printed out as follows:

cell: (r1301329275r1126r2) measure:1.0^^<http://www.w3.org/2001/XMLSchema#float>
cell: (r1301329275r1126r3) measure:0.8^^<http://www.w3.org/2001/XMLSchema#float>
cell: (r1301329275r1126r4) measure:0.9^^<http://www.w3.org/2001/XMLSchema#float>

在Python API来获取节点的内容可以在这里检索: http://librdf.org/docs/ python.html    对于SPARQL查询语言,你可以阅读这个概述: HTTP://www.w3 .ORG / TR / RDF,SPARQL查询/

APIs in python for retrieving Nodes content can be retrieved here: http://librdf.org/docs/python.html For an overview of the SPARQL query language you can read this: http://www.w3.org/TR/rdf-sparql-query/

这篇关于如何加载对齐格式蟒蛇?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆