3

Allegrographを使用すると、Prolog ファンクターは非常に優れていますが、欠点が 1 つあります。

2 つのエンティティをリンクするファンクターを定義するとします。たとえば、「!n:motherOf OR !n:fatherOf に等しい parentOf は、オントロジーで定義された両方の rdf オブジェクト プロパティです (ファンクターではありません)。

トリプレット「A !n:fatherOf B」を定義しましょう。「parentOf」はファンクターでありrdfオブジェクトのプロパティではないため、AとBをリンクするすべてのプロパティを要求すると、トリプレット「A !n:fatherOf B」のみが取得されます(ただし、「A 親B」は取得されません)。

A が B の親であるかどうかを知る唯一の方法は、ブール質問を直接行うことです。

だから私の質問は、「ファンクターによって生成されたFACTS + INFERRED FACTSで構成されるRDFトリプレットを取得する」の結果を簡単に取得する方法は何ですか?

4

2 に答える 2

2

Prolog ファンクタは Prolog プログラムの一部です。Prolog を使用して AllegroGraph ストアに対するクエリを作成する場合、実際には、プログラムで表現された制約に対する一連の回答を導出する Prolog プログラムを作成していることになります。

parentOfはストアの一部ではなく、プログラムの一部です。

あなたがしようとしているのは、Prolog プログラムによって暗示された知識を具体化して、グランド トリプルと同じ形式で利用できるようにすることです。

そのためには、推論された知識を導き出し、それをストアに追加するプロローグ プログラムを作成する必要があります。

ここに役立つコードがあります。これは Lisp でのセットアップと例ですが、Prolog ファンクターは明らかなはずです。

;; Assume the prefix is set up. These are for the Lisp environment.
(register-namespace "ex" "http://example.com/")
(enable-!-reader)

;; Define functors for basic relationships.
(<-- (parent ?x ?y)  
     (father ?x ?y))  

(<- (parent ?x ?y)  
    (mother ?x ?y))  

(<-- (male ?x)  
     (q- ?x !ex:sex !ex:male))  

(<-- (female ?x)  
     (q- ?x !ex:sex !ex:female))  

(<-- (father ?x ?y)  
     (male ?x)  
     (q- ?x !ex:has-child ?y))  

(<-- (mother ?x ?y)  
     (female ?x)  
     (q- ?x !ex:has-child ?y)) 

;; Functors for adding triples.
(<-- (a- ?s ?p ?o)
 ;; Fails unless all parts ground.
 (lisp (add-triple ?s ?p ?o)))

(<-- (a- ?s ?p ?o ?g)
 ;; Fails unless all parts ground.
 (lisp (add-triple ?s ?p ?o ?g)))

(<-- (a-- ?s ?p ?o)
 ;; Fails unless all parts ground.
 (lispp (not (get-triple :s ?s :p ?p :o ?o)))
 (lisp (add-triple ?s ?p ?o)))

(<-- (a-- ?s ?p ?o ?g)
 ;; Fails unless all parts ground.
 (lispp (not (get-triple :s ?s :p ?p :o ?o :g ?g)))
 (lisp (add-triple ?s ?p ?o ?g)))

;; Add some sample data.
(create-triple-store "/tmp/foo")
(add-triple !ex:john !ex:sex !ex:male)
(add-triple !ex:dave !ex:sex !ex:male)
(add-triple !ex:alice !ex:sex !ex:female)
(add-triple !ex:alice !ex:has-child !ex:dave)
(add-triple !ex:john !ex:has-child !ex:dave)

;; Now who is a parent of whom?
(select (?parent ?child)
  (parent ?parent ?child))

;; Returns:
;; (("http://example.com/john" "http://example.com/dave")
;;  ("http://example.com/alice" "http://example.com/dave"))

;; Add the triples.
(select (?parent ?child)    ; never succeeds
  (parent ?parent ?child)
  (a-- ?parent !ex:parentOf ?child)
  (fail))

;; Now see what's in the store using the materialized triples.
(select (?parent ?child)
  (q- ?parent !ex:parentOf ?child))

;; Returns:
;; (("http://example.com/john" "http://example.com/dave")
;;  ("http://example.com/alice" "http://example.com/dave"))
于 2011-07-14T19:31:31.983 に答える
0

このようなものが欲しいですか?

(<-- (parentOf ?a ?b)
    (or
        (q ?a !n:fatherOf ?b)
        (q ?a !n:motherOf ?b)))

(select (?a ?b)
    (parentOf ?a ?b))

select ステートメントは、n:fatherOf または n:motherOf のいずれかを含むトリプルを返します。

于 2012-06-05T17:47:37.377 に答える