簡體   English   中英

如何使用SWI-Prolog從OWL RDF / XML查詢個人的對象屬性?

[英]How to query an individual for its object property from an OWL RDF/XML using SWI-Prolog?

我在Protege中指定了“ isPartOf”對象屬性,並且斷言

“ Room_1 isPartOf Apartment_1”。

“ Room_1”和“ Apartment_1”都是個人。 OWL文件中的相關代碼如下所示:

<rdf:RDF xmlns="http://www.xxx.come/example#"
 xml:base="http://www.xxx.come/example"
 xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
 xmlns:owl="http://www.w3.org/2002/07/owl#"
 xmlns:xml="http://www.w3.org/XML/1998/namespace"
 xmlns:xsd="http://www.w3.org/2001/XMLSchema#"
 xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#">


<!-- http://www.xxx.come/example#isPartOf -->

<owl:ObjectProperty rdf:about="http://www.xxx.come/example#isTemporalPartOf">
    <rdf:type rdf:resource="http://www.w3.org/2002/07/owl#AsymmetricProperty"/>
    <rdf:type rdf:resource="http://www.w3.org/2002/07/owl#TransitiveProperty"/>
    <rdf:type rdf:resource="http://www.w3.org/2002/07/owl#ReflexiveProperty"/>
    <rdfs:domain rdf:resource="http://www.xxx.come/example#Room"/>
    <rdfs:range rdf:resource="http://www.xxx.come/example#Apartment"/>
</owl:ObjectProperty>


<!-- http://www.xxx.come/example#Room_1 -->

<owl:NamedIndividual rdf:about="http://www.xxx.come/example#Room_1">
    <rdf:type rdf:resource="http://www.xxx.come/example#Room"/>
    <isPartOf rdf:resource="http://http://www.xxx.come/example#Apartment_1"/>
    <hasSize rdf:datatype="http://www.w3.org/2001/XMLSchema#double">99.6</hasSize>
    <hasSize rdf:datatype="http://www.w3.org/2001/XMLSchema#double">145.5</hasSize>
</owl:NamedIndividual>
</rdf:RDF>

您將如何使用Prolog查詢這樣的三元組? 我以為會是這樣的:

is_part_of(Ind1, Ind2):- 
    rdf(Ind1, 
        "http://www.w3.org/1999/02/22-rdf-syntax-ns#isPartOf, 
        Ind2).

這顯然是行不通的。

我還從rdf庫中看到了rdf_has(S,P,O,RealP)看起來有點可用,但規范含糊不清。

緊接着這個問題,如果兩個人都是階級怎么辦? 如果對象屬性是數據類型屬性怎么辦?

我認為我一直在解決一個簡單的問題,但是我已經花了很長時間搜索示例或類似問題,但沒有找到任何東西。

提前致謝!

可能的問題是semweb/rdf_db 文檔中沒有快速semweb/rdf_db示例。 這是一個示例會話。

?- use_module(library(semweb/rdf_db)).
true.

?- rdf_load('example.owl', [format(xml)]).
% Parsed "example.owl" in 0.01 sec; 11 triples
true.

?- rdf(Ind1, 'http://www.xxx.come/example#isPartOf',  Ind2).
Ind1 = 'http://www.xxx.come/example#Room_1',
Ind2 = 'http://http://www.xxx.come/example#Apartment_1'.

?- rdf(Ind1, 'http://www.xxx.come/example#hasSize',  Ind2).
Ind1 = 'http://www.xxx.come/example#Room_1',
Ind2 = literal(type('http://www.w3.org/2001/XMLSchema#double', '99.6')) .

?- % is_part_of(Ind1, Ind2):- rdf(Ind1, 'http://www.xxx.come/example#isPartOf', Ind2).
|    ['rules.pl'].
true.

?- is_part_of(Ind1, Ind2).
Ind1 = 'http://www.xxx.come/example#Room_1',
Ind2 = 'http://http://www.xxx.come/example#Apartment_1'.

?- rdf_register_prefix(ex, 'http://www.xxx.come/example#').
true.

?- rdf(Ind1, ex:isPartOf,  Ind2).
Ind1 = 'http://www.xxx.come/example#Room_1',
Ind2 = 'http://http://www.xxx.come/example#Apartment_1'.

您的代碼中的錯誤:

  1. Prolog中的原子應該用單引號引起來。
    至於雙引號-參見例如這個問題 我的SWI-Prolog說:

    Type error: `atom' expected, found `"http://www.xxx.come/example#isPartOf"' (a string)

    無論如何,雙引號也應該被關閉。

  2. 您應該使用正確的完整URI: http://www.xxx.come/example#isPartOf而不是http://www.w3.org/1999/02/22-rdf-syntax-ns#isPartOf

  3. 此格式不正確的URI( http://http://www.xxx.come/example#Apartment_1 )可能會導致其他問題。

如果已經定義了RDFS或OWL模式,則可以使用rdfs2pl將其轉換為序言規則。

結果與斯坦尼斯拉夫提供的示例大致相同。 查看提供的顯式代碼以了解正在發生的事情很有用,但是如果您有大量的謂詞,那么為它們編寫顯式規則可能很乏味且容易出錯。

生成的代碼與提供的示例之間的區別是rdfs2pl在其生成的規則中使用rdf_has / 3 您問這個謂詞。 它在RDF圖上提供了有限的推論 例如,如果您有:

ex:isPartOf owl:inverseOf ex:hasPart .
ex:apartment1 ex:hasPart ex:room1.

然后查詢rdf_has(X,myont:isPartOf,Y)將返回一個結果和X=ex:room1Y=ex:apartment1 ,即使它沒有明確說明,它是由OWL的語義,並通過您的inverseOf entailed宣言。 相反, rdf/3將僅查詢斷言的模型。

何時選擇rdf/3rdf_has/3取決於您的用例。 進行查詢時能夠使用推理可能非常有用。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM