Как загрузить формат выравнивания в Python? - PullRequest
2 голосов
/ 25 марта 2011

Есть ли способ загрузить файл выравнивания в python.Если у меня есть файл, подобный этому:

<?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 Предикат: сова: SameAs Объект: http://discogs.dataincubator.org/artist/catie-curtis Доверие: 1,0

Я пытался сделать это с помощью RDFlib, но не смог.Любые предложения помогут, спасибо!

1 Ответ

3 голосов
/ 25 марта 2011

Попробуйте с библиотеками Redland: 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)

А затем запросите переменную модель .Например, чтобы получить все выравнивания и вернуть их меру, запрос имеет следующий вид:

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'])

Результат будет содержать итератор объектов словаря (имя переменной, результат) и будет напечатанвыглядит следующим образом:

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>

API в Python для извлечения содержимого Nodes можно получить здесь: http://librdf.org/docs/python.html Для обзора языка запросов SPARQL вы можете прочитать это: http://www.w3.org/TR/rdf-sparql-query/

...