Skip to content

Commit 11be8cd

Browse files
authored
feat(reasoner): support necessary rule expression (#531)
1 parent b449fa9 commit 11be8cd

4 files changed

Lines changed: 18 additions & 2 deletions

File tree

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,4 +84,5 @@ If you use this software, please cite it as below:
8484
[Apache License 2.0](LICENSE)
8585

8686
# OpenSPG Core Team
87+
8788
Lei Liang, Mengshu Sun, Zhengke Gui, Zhongshu Zhu, Zhouyu Jiang, Ling Zhong, Peilong Zhao, Zhongpu Bo, Jin Yang, Huaidong Xiong, Lin Yuan, Jun Xu, Zaoyang Wang, Zhiqiang Zhang, Wen Zhang, Huajun Chen, Wenguang Chen, Jun Zhou, Haofen Wang

README_cn.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,5 +83,6 @@ OpenSPG核心能力模型包括:
8383
[Apache License 2.0](LICENSE)
8484

8585
# OpenSPG 核心团队
86+
8687
梁磊,孙梦姝,桂正科,朱仲书,江洲钰,钟玲,赵培龙,伯仲璞,阳进,熊怀东,袁琳,徐军,汪兆洋,张志强,张文,陈华钧,陈文光,周俊,王昊奋
8788

reasoner/kgdsl-parser/src/main/antlr4/com/antgroup/openspg/reasoner/KGDSL.g4

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -543,6 +543,7 @@ REPEAT : 'repeat' ;
543543
WHERE : ('W' | 'w')('H' | 'h')('E' | 'e')('R' | 'r')('E' | 'e') ;
544544
MATCH : ('M' | 'm')('A' | 'a')('T' | 't')('C' | 'c')('H' | 'h') ;
545545
RETURN : ('R' | 'r')('E' | 'e')('T' | 't')('U' | 'u')('R' | 'r')('N' | 'n') ;
546+
PRIORITY : ('P' | 'p')('R' | 'r')('I' | 'i')('O' | 'o')('R' | 'r')('I' | 'i')('T' | 't')('Y' | 'y');
546547
DEFINE_PRIORITY : 'DefinePriority' ;
547548
DESCRIPTION : 'Description';
548549
// rule 表达式
@@ -718,6 +719,7 @@ double_solidus : '//' ;
718719
underscore : '_' ;
719720
vertical_bar : '|' ;
720721
labmda_body_array : '=>' ;
722+
necessary_symbol : '<=' ;
721723

722724
separator : ( comment|whitespace )+ ;
723725
whitespace : WHITESPACE ;
@@ -967,6 +969,7 @@ thinker_script: (
967969
| define_rule_on_relation_to_concept
968970
| define_proiority_rule_on_concept
969971
| logical_deduce
972+
| necessary_logical_deduce
970973
)*;
971974
972975
/*
@@ -983,12 +986,14 @@ Define (Med.drug)-[基本用药方案]->(药品/`ACEI+噻嗪类利尿剂`) {
983986
*/
984987
define_rule_on_relation_to_concept : define_rule_on_relation_to_concept_structure (description)?;
985988
986-
logical_deduce : deduce_premise labmda_body_array deduce_conclusion description?;
989+
logical_deduce : deduce_premise labmda_body_array deduce_conclusion priority_assignment_statement? description?;
987990
988991
deduce_premise : logical_statement;
989992
990993
deduce_conclusion : logical_statement;
991994
995+
necessary_logical_deduce : deduce_premise necessary_symbol deduce_conclusion priority_assignment_statement? description?;
996+
992997
/*
993998
DefinePriority(危险水平分层) {
994999
超高危=100
@@ -1037,4 +1042,6 @@ assiginment_structure : left_brace muliti_assignment_statement right_brace;
10371042
10381043
muliti_assignment_statement : assignment_statement*;
10391044
1040-
assignment_statement : identifier assignment_operator logical_statement;
1045+
assignment_statement : identifier assignment_operator logical_statement;
1046+
1047+
priority_assignment_statement : left_bracket PRIORITY assignment_operator oC_IntegerLiteral right_bracket;

reasoner/runner/runner-common/src/main/scala/com/antgroup/openspg/reasoner/util/Convert2ScalaUtil.scala

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,4 +33,11 @@ object Convert2ScalaUtil {
3333
jSet.asScala.toSet
3434
}
3535

36+
def toJavaList[T](scalaList: List[T]): java.util.List[T] = {
37+
if (scalaList == null || scalaList.isEmpty) {
38+
return new java.util.ArrayList()
39+
}
40+
scalaList.asJava
41+
}
42+
3643
}

0 commit comments

Comments
 (0)