DIV CSS 佈局教程網

 DIV+CSS佈局教程網 >> 網頁腳本 >> XML學習教程 >> XML詳解 >> XML 編程思想:定義 RDF 和 DAML+OIL 圖示
XML 編程思想:定義 RDF 和 DAML+OIL 圖示
編輯:XML詳解     

Uche Ogbuji 繼續定義問題跟蹤應用程序的 RDF 與 DAML+OIL 圖示,繼續同以前一樣討論建模。

  在本專欄的上一篇文章中,我討論了諸如 RDF 這樣的 XML 知識管理系統是如何另辟蹊徑解決數據設計與建模這些老問題的。我的目的是要准確說明問題跟蹤程序包的模式,我曾使用問題跟蹤程序包來演示將 RDF 同 XML 應用程序一起使用。現在,我將以 RDFS 和 DAML+OIL 形式完成問題跟蹤程序模式的定義。

  這裡,同樣需要熟悉 RDF、RDFS 和 DAML+OIL。寫完上一篇文章之後,我已與同事 Roxane Ouellet 一起發表了 DAML+OIL 簡介(請參閱 參考資料),因此,您再也不用埋頭翻閱厚厚的規范來掌握它了。

  請繼續

  言歸正傳,下面給出的清單 1 是問題跟蹤程序的完整 RDFS。

  清單 1. 問題跟蹤程序的 RDFS 模式

  <?XML version="1.0" encoding="UTF-8"?>
<!DOCTYPE rdf:RDF [
<!ENTITY rdf "http://www.w3.org/1999/02/22-rdf-syntax-ns#">
<!ENTITY rdfs "http://www.w3.org/2000/01/rdf-schema#">
<!ENTITY it "http://rdfinference.org/schemata/issue-tracker/">
<!ENTITY dc "http://purl.org/dc/elements/1.1/">
]>
<rdf:RDF
XMLns:rdf="&rdf;"
XMLns:rdfs="&rdfs;"
XMLns:it="&it;"
>
<rdfs:Class rdf:about="&it;Catalog">
<rdfs:label>Issue catalog</rdfs:label>
<rdfs:comment>
An optional collection of resources for which issues have or can
be defined. Use dc:relation to associate the catalog with its
resources.
</rdfs:comment>
</rdfs:Class>
<rdfs:Class rdf:about="&it;Issue">
<rdfs:label>Issue</rdfs:label>
<rdfs:comment>
A problem, suggestion or other matter for action or discussion
relevant to a resource. Use Dublin Core propertIEs for base
description.
</rdfs:comment>
</rdfs:Class>
<rdfs:Property rdf:about="&it;issue">
<rdfs:label>issue</rdfs:label>
<rdfs:comment>Associate an issue to its resources</rdfs:comment>
<rdfs:range rdf:resource="&it;Issue"/>
</rdfs:Property>
<rdfs:Property rdf:about="&it;action">
<rdfs:label>action</rdfs:label>
<rdfs:comment>Associate an action with an issue</rdfs:comment>
<rdfs:domain rdf:resource="&it;Issue"/>
<rdfs:range rdf:resource="&it;Action"/>
</rdfs:Property>
<rdfs:Class rdf:about="&it;Action">
<rdfs:label>Action</rdfs:label>
<rdfs:comment>
An action to be taken with regard to an issue
</rdfs:comment>
</rdfs:Class>
<rdfs:Class rdf:about="&it;it:assignee">
<rdfs:label>Assign to</rdfs:label>
<rdfs:comment>
Specify the party to whom the action is assigned
</rdfs:comment>
<rdfs:domain rdf:resource="&it;Action"/>
</rdfs:Class>
<rdfs:Class rdf:about="&it;status">
<rdfs:label>status</rdfs:label>
<rdfs:comment>For instance, "not done" or "done"</rdfs:comment>
<rdfs:domain rdf:resource="&it;Action"/>
</rdfs:Class>
<rdfs:Class rdf:about="&it;comment">
<rdfs:label>comment</rdfs:label>
<rdfs:comment>Associate a comment with an issue</rdfs:comment>
<rdfs:domain rdf:resource="&it;Issue"/>
<rdfs:range rdf:resource="&it;Comment"/>
</rdfs:Class>
<rdfs:Class rdf:about="&it;Comment">
<rdfs:label>Comment</rdfs:label>
<rdfs:comment>A comment made with regard to an issue</rdfs:comment>
</rdfs:Class>
</rdf:RDF>


 

 您會注意到發生了一些變化,包括使用的名稱空間也發生了變化。遺憾的是,我們不會象解釋我們以前的 RDF 示例沒有使用任何定義的類那樣詳盡地解釋這些變化。這一模式表示了 RDFInference.org 的問題跟蹤程序當前正在使用什麼,包括由於各種原因所做的變化。我將稍後提供實例 RDF 的相應更新。

  我也采用了一些詞法約定:首先,我將所有的名稱空間 URI 定義為 DTD 內部子集中的實體(這一約定是我從 Ouellet 女士那裡學來的),這一約定減少了錯誤並改善了可讀性。於是,我只使用 rdf:about ,而不再使用 rdf:ID ,在艱辛地經歷了與對包含文檔的假設 URI 解析 ID 有關的所有缺陷之後,最近,我采用了這一約定。請注意,只有在能確保有一個顯式的 xml:base 聲明,以及需要互操作性的所有 RDF 處理程序都支持 XML 基礎時,我才使用 rdf:ID 。

  Catalog 類提供了一種方法,來聚合所有擁有問題或允許用戶為其創建問題的資源。這主要為應用程序提供便利。請想象一下跟蹤程序的一個基於 Web 的表單。它可能有一個感興趣資源的下拉選擇框。一種填充該列表的方法是從給定的目錄檢查所有 dc:relation 語句的對象。而我將要提供的 DAML+OIL 模式則演示了另外一種方法。

  還有其它幾個小小的變化,例如為了詞類更一致的使用,將“assigned-to”重命名為“assignee”。除此之外,在這一模式中沒有什麼值得奇怪的,好了,讓我們繼續了解 DAML+OIL 版本。

  DAML 的特點

  DAML+OIL 是一個模式系統,它提供了對 RDFS 的關鍵改進,其中包括一個內置的數據類型確定系統、枚舉支持、特性專門化以及通過推論進行分類與確定類型。它也超出了純粹的示意圖,它允許我們定義存在(ontology),我們對概念的理解大概就是這樣的,但是目前我們主要還是使用基本的示意功能。清單 2 是類似於清單 1 的問題跟蹤程序的 DAML+OIL 模式。

 清單 2. 問題跟蹤程序的 DAML+OIL 模式

  <?XML version="1.0" encoding="UTF-8"?>
<!DOCTYPE rdf:RDF [
<!ENTITY rdf "http://www.w3.org/1999/02/22-rdf-syntax-ns#">
<!ENTITY xsd "http://www.w3.org/2000/10/XMLSchema#">
<!ENTITY rdfs "http://www.w3.org/2000/01/rdf-schema#">
<!ENTITY daml "http://www.daml.org/2001/03/daml+oil#">
<!ENTITY dc "http://purl.org/dc/elements/1.1/">
<!ENTITY it "http://rdfinference.org/schemata/issue-tracker/">
]>
<rdf:RDF
XMLns:rdf="&rdf;"
XMLns:rdfs="&rdfs;"
XMLns:daml="&daml;"
XMLns:xsd="&xsd;"
XMLns:it="&it;"
>
<daml:Ontology rdf:about="">
<daml:versionInfo>
<!-- Note: requires expansion by RCS, CVS or the like
$Revision$
</daml:versionInfo>
<rdfs:comment>
Ontology for an issue tracking system for arbitrary resources
</rdfs:comment>
<daml:imports rdf:resource="http://www.w3.org/2001/10/daml+oil"/>
</daml:Ontology>
<daml:Class rdf:about="&it;RelevantResource">
<rdfs:label>Relevant resource</rdfs:label>
<rdfs:comment>
An implIEd classification of resources that have related issues
</rdfs:comment>
<rdfs:subClassOf>
<daml:onProperty rdf:resource="&it;issue"/>
<daml:toClass rdf:resource="&it;Issue"/>
</rdfs:subClassOf>
</daml:Class>
<daml:Class rdf:about="&it;Issue">
<rdfs:label>Issue</rdfs:label>
<rdfs:comment>
A problem, suggestion or other matter for action or discussion
relevant to a resource. Use Dublin Core propertIEs for base
description.
</rdfs:comment>
</daml:Class>
<daml:ObjectProperty rdf:about="&it;issue">
<rdfs:label>issue</rdfs:label>
<rdfs:comment>Associate an issue to its resources</rdfs:comment>
<rdfs:range rdf:resource="&it;Issue"/>
</daml:ObjectProperty>
<daml:ObjectProperty rdf:about="&it;action">
<rdfs:label>action</rdfs:label>
<rdfs:comment>Associate an action with an issue</rdfs:comment>
<rdfs:domain rdf:resource="&it;Issue"/>
<rdfs:range rdf:resource="&it;Action"/>
</daml:ObjectProperty>
<daml:Class rdf:about="&it;Action">
<rdfs:label>Action</rdfs:label>
<rdfs:comment>An action to be taken with regard to an
issue</rdfs:comment>
</daml:Class>
<daml:ObjectProperty rdf:about="&it;it:assignee">
<rdfs:label>Assign to</rdfs:label>
<rdfs:comment>
Specify the party to whom the action is assigned
</rdfs:comment>
<rdfs:domain rdf:resource="&it;Action"/>
</daml:ObjectProperty>
<daml:ObjectProperty rdf:about="&it;status">
<rdfs:label>status</rdfs:label>
<rdfs:comment>For instance, "not done" or "done"</rdfs:comment>
<rdfs:domain rdf:resource="&it;Action"/>
</daml:ObjectProperty>
<daml:ObjectProperty rdf:about="&it;comment">
<rdfs:label>comment</rdfs:label>
<rdfs:comment>Associate a comment with an issue</rdfs:comment>
<rdfs:domain rdf:resource="&it;Issue"/>
<rdfs:range rdf:resource="&it;Comment"/>
</daml:ObjectProperty>
<daml:Class rdf:about="&it;Comment">
<rdfs:label>Comment</rdfs:label>
<rdfs:comment>A comment made with regard to an issue</rdfs:comment>
</daml:Class>
</rdf:RDF>


 

 存在標題出現在任何定義之前。這是一個 DAML 約定,它描述文檔、確定模式(因此使用空的 rdf:about ,它將文檔本身設置為主題)。它的一個特征是有一條修訂語句,我是使用由修訂控制系統擴展的關鍵字來定義該語句的。其另外一個特征是一個導入,它是由 DAML+OIL 添加的一個顯式機制,目的在於將來自其它文件的定義合並到當前文件(在 DAML 出現之前,您要麼必須將多個源定義合並成一個模型,要麼使用諸如 XInclude 的較低級別的機制)。作為標准實踐,我導入核心 DAML+OIL 模式,為特定於 DAML+OIL 的資源添加定義。

  接下來是一個特殊的類 RelevantResource ,它沒有顯式地聲明其實例,而是由對實例特性的推論定義實例。更進一步地研究 RelevantResource 類可以搞清楚這一點。它被定義為匿名內聯資源的子類,而匿名內聯資源類型又是 daml:Restriction 的類型。這是一個特殊的 DAML+OIL 機制,它允許您根據實例具有的特性以及這些特性的值來定義規則。在這個例子裡,約束條件選擇所有具有 issue 特性並且該特性的值屬於類 Issue 的資源。通過從這一約束條件劃分子類, RelevantResource 類成為一種包含一個所有滿足該約束條件資源集合的虛擬類。如果在任何時候資源獲得具有適當類值的適當特性,那麼無需顯式聲明,它會自動成為這一虛擬類的成員。

  在您可能還沒有控制正在操作的所有信息空間時,這是一項非常重要的功能,這也是為什麼要推出 DAML+OIL 的緣故,DAML+OIL 的推出在鞏固 Semantic Web 的這類技術方面向前跨了一大步。在更恰當的例子中,這一功能允許我們無須為問題跟蹤顯式地注冊所有資源,如同我們以模式的 RDFS 形式(使用 Catalog 類)所做的那樣。

  我使用 daml:Class 定義所有的類,它是 rdfs:Class 的子類,而 rdfs:Class 提供 DAML 所引入的所有附加功能。類似地,我使用 daml:ObjectProperty 定義特性。問題跟蹤程序模式不使用具體的數據類型(字符串、整數等等)來定義任何特性的值,但是需要說明的是,這些特性在 DAML+OIL 中是作為 daml:DatatypeProperty 的子類定義的。

 DAML+OIL 模式實際上就是在 RDFInference.org 應用程序中所使用的那種模式,而且我們也將它用作本專欄繼續下去的基礎。

  更新實例

  由於那些我所提到過的變化,我回顧並更新了到目前為止在本專欄中我們一直在研究的問題的樣本實例,請參閱清單 3。

  清單 3. 更新的實例數據

  <?XML version='1.0'?>
<!DOCTYPE rdf:RDF [
<!ENTITY rdf "http://www.w3.org/1999/02/22-rdf-syntax-ns#">
<!ENTITY rdfs "http://www.w3.org/2000/01/rdf-schema#">
<!ENTITY daml "http://www.daml.org/2001/03/daml+oil#">
<!ENTITY dc "http://purl.org/dc/elements/1.1/">
<!ENTITY foaf "http://XMLns.com/foaf/0.1/">
<!ENTITY it "http://rdfinference.org/schemata/issue-tracker/">
<!ENTITY rit "http://rdfinference.org/ril/issue-tracker/">
]>
<rdf:RDF
XMLns:rdf="&rdf;"
XMLns:rdfs="&rdfs;"
XMLns:daml="&daml;"
XMLns:rit="&rit;"
XMLns:it="&it;"
XMLns:dc="&dc;"
XMLns:foaf="&foaf;"
XMLns="&it;"
>
<rdf:Description rdf:about='http://rdfinference.org/ril/ril-20010502'>
<issue rdf:resource='&rit;i2001030423'/>
<issue rdf:resource='&rit;i2001042003'/>
</rdf:Description>
<Issue rdf:about='&rit;i2001030423'>
<dc:title>Unnecessary abbreviation</dc:title>
<dc:creator rdf:resource='mailto:[email protected]'/>
<dc:description>
Is the abbreviation of rdf:type predicates in querIEs necessary?
</dc:description>
<dc:date>2001-03-04</dc:date>
<comment rdf:parseType="Resource">
<dc:creator rdf:resource='mailto:[email protected]'/>
<dc:description>
The abbreviation in listing 8 doesn't seem necessary to Nico
Chauvat or me.
</dc:description>
</comment>
<action rdf:parseType="Resource">
<dc:description>Organize a vote on this topic</dc:description>
<it:assignee rdf:resource='mailto:[email protected]'/>
</action>
</Issue>
<Issue rdf:about='&rit;i2001042003'>
<dc:title>Inconsistent versioning</dc:title>
<dc:creator rdf:resource='mailto:[email protected]'/>
<dc:description>
The RIL versioning is not clear (there's a mix of 0.1, 0/1, 0.2
and 0/2)
</dc:description>
<dc:date>2001-04-20</dc:date>
<action rdf:parseType="Resource">
<dc:description>
Correct all to use the "0/1" form in the next draft.
</dc:description>
<it:assignee rdf:resource='mailto:[email protected]'/>
</action>
</Issue>
<rdf:Description rdf:about='mailto:[email protected]'>
<foaf:name>Alexandre Fayolle</foaf:name>
</rdf:Description>
<rdf:Description rdf:about='mailto:[email protected]'>
<foaf:name>Uche Ogbuji</foaf:name>
</rdf:Description>
<rdf:Description rdf:about='mailto:[email protected]'>
<foaf:name>Nicolas Chauvat</foaf:name>
</rdf:Description>
</rdf:RDF>

  我們定義一個針對其提出樣本問題的資源。按照 DAML+OIL 模式, http://rdfinference.org/ril/ril-20010502 自動成為 RelevantResource 類的成員。另外一個重要的變化是我們通過 mailto URL 來和某個人聯系,該 URL 然後使用“朋友的朋友”(FOAF)鏈接到他們正常的姓名,“朋友的朋友”是一種有名的確定個人聯系信息的 DAML+OIL 模式,它適合於描述誰屬於某個電子郵箱。請注意,在 RDF 中有另一個有名的選擇可用於建模聯系信息,它基於普通的 vCard 格式,將聯系信息作為電子郵件的附件嵌入。vCard RDF 模式比 FOAF 模式覆蓋面更廣,但是我們不需要其額外的特性。如果我們需要的話,還有一個基於 FOAF 的選項:FOAFCorp,它將同公司結構有關的元素添加到 FOAF 中的核心個人概要信息。

  生成這個表單而不是原來的表單的 XSLT 的變化很小 ― 主要是文字結果元素名稱和名稱空間 URI 的變化。

  結束語

  通常,即使您希望以松散的方式應用在本專欄上一篇文章中討論過的約束,您也應該有某種模式供文檔使用(如果不用於其它東西的話)。RDFS 仍然是最簡單、最普遍的選擇,但是 DAML+OIL 有許多好的方面,還是值得推薦:不僅是額外的功能,而且還包括更清晰的核心語義。既然問題跟蹤程序有了一個模式,我們將繼續下去,改進我們構造查詢的方式:我們將研究 Versa,它是一種用於 RDF 的開放查詢語言,它將使我們提供的所有查詢代碼更簡單和更快。



 

XML學習教程| jQuery入門知識| AJAX入門| Dreamweaver教程| Fireworks入門知識| SEO技巧| SEO優化集錦|
Copyright © DIV+CSS佈局教程網 All Rights Reserved