2010-05-18 69 views
1

我有一個本體,我與Jena一起閱讀,幫助我從網站上刮取一些RDFa三元組。我目前沒有將這些三元組存儲在耶拿模型中,但那是相當直接的做法,它在我的下一個列表中。用Jena閱讀Ontology,用RDF三元組提供它,並生成正確的RDF字符串輸出

儘管如此,我正在努力的領域是讓Jena爲我所擁有的本體輸出正確的RDF。本體使用Owl和RDFS定義,但是當我將一些示例三元組傳遞給模型時,它們顯示不正確。就好像它對本體論一無所知。但是,輸出仍然是有效的RDF,只是它不是以我期望的形式出現的。

我正確地認爲,耶拿應該能夠根據本體論對我所收集的三元組產生寫得很好的RDF(不僅僅是有效的)嗎?或者這樣做能夠展示它的能力嗎?

非常感謝您的任何意見。

更新1

例子:

這是我們目前有:

<rdf:Description rdf:about='http://theinternet.com/%3fq=Club/325'> 
     <j.0:hasName>Manchester United</j.0:hasName> 
     <j.0:hasPlayer> 
      <rdf:Description rdf:about='http://theinternet.com/%3fq=player/291/'> 
      </rdf:Description> 
     </j.0:hasPlayer> 
     <j.0:hasEmblem>http://theinternet.com/images/manutd.jpg</j.0:hasEmblem> 
     <j.0:hasWebsite>http://www.manutd.com/</j.0:hasWebsite> 
</rdf:Description> 

</rdf:RDF> 

這是我們最好要:

<?xml version="1.0"?> 
<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" 
    xmlns:dc="http://purl.org/dc/elements/1.1/" 
xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#" 
     xmlns:owl="http://www.w3.org/2002/07/owl#" 
     xmlns:xsd="http://www.w3.org/2001/XMLSchema#" 
     xmlns:ontology="http://theinternet.com/ontology.rdf#"> 

<rdf:Description rdf:about='http://theinternet.com/%3fq=Club/325'> 
<rdf:type rdf:resource='ontology:Club' /> 
     <ontology:hasName>Manchester United</ontology:hasName> 
     <ontology:hasPlayer> 
      <rdf:Description rdf:about='http://theinternet.com/%3fq=player/291/'> 
       <rdf:type rdf:resource='ontology:Player' /> 
      </rdf:Description> 
     </ontology:hasPlayer> 
     <ontology:hasEmblem>http://theinternet.com/images/manutd.jpg</ontology:hasEmblem> 
     <ontology:hasWebsite>http://www.manutd.com/</ontology:hasWebsite> 
</rdf:Description> 

</rdf:RDF> 

對我來說,看起來耶拿只是缺少與本體相關的事情,比如資源類型等。我有這種感覺我錯誤地使用了耶拿。

回答

5

如果你想寫得好 rdf(xml我假設)使用RDF/XML-ABBREV作家。默認值通常很好,但是您會發現tuning instructions here

沒有問題輸出的例子,很難知道你的問題是什麼。你看到像<j.0:SomeClass>這樣的東西嗎?這是一個前綴問題。如果它們是在原始RDFa文檔中定義的,那麼你已經以某種方式丟失了它們,但它應該很容易修復。否則,您可以使用PrefixMapping中的方法(其中Model擴展)在模型上手動設置它們。

更新答案

感謝您的例子。前綴是這裏的主要問題。

model.setNsPrefix("ontology", "http://theinternet.com/ontology.rdf#"); 
model.setNsPrefix("dc", DC_11.NS); 
model.setNsPrefix("owl", OWL.NS); 
model.setNsPrefix("rdfs", RDFS.NS); 
model.setNsPrefix("xsd", XSD.NS); 

DC_11.NS在所述jena vocabulary package定義)

注意rdf:resource(如rdf:about)取一個完整的URI,所以

<rdf:type rdf:resource='ontology:Club' /> 

不起作用。使用showDoctypeDeclarationoption將縮寫爲使用XML實體。

順便說一下,您使用了哪種RDFa解析器?前綴定義應該通過。

+0

嗯,是的,我應該發佈一個例子。我現在要做。 – JonB 2010-05-19 07:54:55

1

您錯過了rdf:type屬性,因爲您尚未加載任何包含所需rdfs:domain或rdfs:range語句的本體,我不認爲您已使用任何推理器來進行這些推理。

您可以加載域或範圍語句以及其餘數據,或者jena擁有一個工具,用於在發現owl:imports語句時自動加載本體。我建議前者保持簡單。

這裏記錄的jena RdfsInferencer http://jena.sourceforge.net/inference/會做你想要的推理。

順便說一句,我發現芝麻是一個很容易使用和比jena更大的大規模的東西,雖然刮幾個三倍要麼罰款。

bbtw,Turtle(N3的子集)是很多比RDF/XML更容易閱讀和編輯。這非常值得學習。過去3年來我一直在使用rdf,現在在處理任何原始數據之前將所有的RDF/XML轉換爲Turtle(儘管我確實有一個很好的工具,可以按照有用的順序寫入所有內容,並自動插入反向引用註釋等。 )

好運