Jena高階(二)本體推理規則(Rules)的介紹

2021-06-16 15:17:40 字數 4166 閱讀 3623

本體的推理規則庫是有一條條規則組成的。每條規則由主體(body)和頭(head)組成,一條規則可以有乙個主體和乙個頭,例如規則:[rule1:(?a fa:hashusband ?b)(?a fa:ismotherof ?c)->(?b fa:isfatherof ?c)],其中規則的主體為:?a @hashusband ?b,?a @ismotherof ?c,頭為:?b @isfatherof ?c,也就是說有所有的主體可以推出頭。?a @hashusband ?b,?a @ismotherof ?c,?b @isfatherof ?c三者有乙個稱謂:clauseentry。例如方法rule類中getbody()方法返回是乙個clauseentry集合。他有2個元素?a @hashusband ?b,?a @ismotherof ?c。下面有個規則庫:

[c-sharp]view plain

copy

@prefix fa: >.@include .@include .

[rule1: (?a fa:hashusband ?b)(?a fa:ismotherof ?c)->(?b fa:isfatherof ?c)]  

[rule2: (?a fa:hashusband ?b)(?a fa:hasdaughter ?c)->(?b fa:isfartherof ?c)]  

[rule3: (?a fa:hashusband ?b)(?a fa:hasdaughter ?c)->(?b fa:hasdaughter ?c)]  

[rule4: (?a fa:hashusband ?b)(?a fa:hasdaughter ?c)->(?c fa:hasfather ?b)]  

[rule5: (?a fa:hashusband ?b)(?a fa:hasdaughter ?c)->(?c fa:isdaughterof ?b)]  

[rule6: (?a fa:hashusband ?b)(?a fa:hasson ?c)->(?b fa:isfatherof ?c)]  

[rule7: (?a fa:hashusband ?b)(?a fa:hasson ?c)->(?b fa:hasson ?c)]  

[rule8: (?a fa:hashusband ?b)(?a fa:hasson ?c)->(?c fa:hasfather ?b)]  

[rule9: (?a fa:hashusband ?b)(?a fa:hasson ?c)->(?c fa:issonof ?b)]  

[rule10:(?a fa:haswife ?b)(?a fa:isfatherof ?c)->(?b fa:ismotherof ?c)]  

[rule11:(?a fa:haswife ?b)(?a fa:hadaughter ?c)->(?b fa:ismotherof ?c)]  

[rule12:(?a fa:haswife ?b)(?a fa:hadaughter ?c)->(?b fa:hasdaugher ?c)]  

[rule13:(?a fa:haswife ?b)(?a fa:hadaughter ?c)->(?c fa:hasmother ?b)]  

[rule14:(?a fa:haswife ?b)(?a fa:hadaughter ?c)->(?c fa:isdaughterof ?b)]  

[rule15:(?a fa:haswife ?b)(?a fa:hasson ?c)->(?b fa:ismotherof ?c)]  

[rule16:(?a fa:haswife ?b)(?a fa:hasson ?c)->(?b fa:hasson ?c)]  

[rule17:(?a fa:haswife ?b)(?a fa:hasson ?c)->(?c fa:hasmother ?b)]  

[rule18:(?a fa:haswife ?b)(?a fa:hasson ?c)->(?c fa:issonof ?b)]  

[rule19:(?a fa:haswife ?b)->(?a fa:ishusbandof ?b)]  

[rule20:(?a fa:hashusband ?b)->(?a fa:iswifeof ?b)]  

[rule21:(?a fa:ishusbandof ?b)->(?a fa:haswife ?b)]  

[rule22:(?a fa:iswifeof ?b)->(?a fa:hashusband ?b)]  

[rule23:(?a fa:hasfather ?b) (?c fa:hasfather ?d) (?b fa:hasbrother ?d) notequal(?b,?d)->(?a fa:hascousin ?b)]  

[rule24:(?a fa:hasfather ?b)(?c fa:hasfather ?d)(?b fa:hasfather ?e)(?d fa:hasfather ?e) notequal(?b,?d)->(?a fa:hascousin ?c)]  

[rule25:(?a fa:hasson ?b)(?b fa:hasson ?c)->(?a fa:hasgrandson ?c)]  

[rule26:(?a fa:hasson ?b)(?b fa:hasdaughter ?c)->(?a fa:hasgranddaughter ?c)]  

[rule27:(?a fa:hasfather ?b)(?b fa:hasbrother ?c)->(?a fa:hasuncle ?c)]  

[rule28:(?a fa:hasfather ?b)(?b fa:hassister ?c)->(?a fa:hasaunt ?c)]  

[rule29:(?a fa:hasgrandson ?b)->(?b fa:isgrandsonof ?a)]  

[rule30:(?a fa:hasaunt ?b)->(?b fa:isauntof ?a)]  

[rule31:(?a fa:hasfather ?b)->(?b fa:isfatherof ?a)]  

[rule32:(?a fa:hasmother ?b)->(?b fa:ismotherof ?a)]  

[rule33:(?a fa:hasbrother ?b)->(?b fa:isbrotherof ?a)]  

[rule34:(?a fa:hassister ?b)->(?b fa:issisterof ?b)]  

[rule35:(?a fa:hascousin ?b)->(?b fa:iscousinof ?a)]  

[rule36:(?a fa:hasson ?b)->(?b fa:issonof ?a)]  

[rule37:(?a fa:hasdaughter ?b)->(?b fa:isdaughterof ?a)]  

[rule38:(?a fa:hasgranddaughter ?b)->(?b fa:isgranddaughterof ?a)]  

[rule39:(?a fa:haswife ?b)->(?b fa:iswifeof ?a)]  

[rule40:(?a fa:hashusband ?b)->(?b fa:ishusbandof ?a)]  

[rule41:(?a fa:hasuncle ?b)->(?b fa:isuncleof ?a)]  

下面**是根據這個規則庫查個規則的例子

[c-sharp]view plain

copy

public

static

void

main(string args)   

system.out

.println(

"/n-------------------/n"

);  

clauseentry head=rules.get

(0).gethead();  

intk=rules.

get(0).headlength();  

for(

inti=0;i

system.out

.print(head[i]+

",");  

}  system.out

.println(

"/n-------------------/n"

);  

system.out

.println(rules.

get(0).getname());  

}    

一本好書 C 高階高階教程

c 高階高階教程 checklist by 66 66一第1章 c 基礎知識 1.1 關於c 標準 1.2 文字常量和常變數 1.3 const的用法 1.4 const cast的用法 1.5 mutable的用法 1.6 求餘運算子 1.7 sizeo f的用法 1.8 引用與指標常量 1.9 ...

Redis高階高階(二)

一 訊息通知 在一些 上,經常會有一些發布 訂閱或者郵件訂閱的功能,尤其一些部落格上。其實這種問題很常見,當頁面需要進行如傳送郵件 複雜的計算時會阻塞頁面的渲染。為了避免使用者等待太久,應該使用其他程序單獨完成此類操作,這裡郵件訂閱可以用任務佇列來實現,具體來說,當需要傳送郵件時,將其存入佇列中,另...

高階查詢二

in 語句 只執行一次 確定給定的值是否與子查詢或列表中的值相匹配。in在查詢的時候,首先查詢子查詢的表,然後將內錶和外表做乙個笛卡爾積,然後按照條件進行篩選。所以相對內錶比較小的時候,in的速度較快。exists語句 執行student.length次 指定乙個子查詢,檢測行的存在。遍歷迴圈外表,...