2011-07-13 1 views
3

Allegrographを使用すると、Prologのファンクタはかなり素晴らしいですが、1つの欠点があります。Allegrograph - RDFオブジェクトのプロパティのようなFunctor?

のは、あなたがに等しい例parentOfのために、2つのエンティティをリンクファンクタを定義するとしましょう(自分のオントロジーで定義された両方のRDFオブジェクトのプロパティがありません「をN:fatherOf:motherOf OR n個を!」ファンクタ)。

トリプレット「A !n:fatherOf B」を定義しましょう。 "parentOf"はファンクタであり、rdfオブジェクトのプロパティではないので、AとBをリンクするすべてのプロパティを要求すると、 "A !n:fatherOf B" B ")。

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

私の質問は、「ファクトで生成されたファクト+インファーストファクトで構成されたRDFトリプレットを取得する」という結果を簡単に取得する方法は何ですか?

答えて

2

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

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

は、Prologプログラムが暗黙の知識を持っているため、グランドトリプルと同じ形式で利用できます。

これを行うには、次のように記述する必要があります。推定された知識を派生させ、それをストアに追加する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")) 
+0

回答ありがとうございました。はい、私はすでに、すべてのファンクタを実行し、データベースにトリプレットとして結果を挿入するcronタスクを作成することを考えました。これは、前方連鎖推論のようなものですが、リアルタイムではありません。 :(だからベストアイデア? – Aymeric

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のいずれかを含むトリプルを返します。

関連する問題