(deffacts MAIN::requirements "Expert Commitee" (softgoalElement (sgId gen104) (sgQualityAttribute "quality") (sgSujectObject "review") (sgGoalId gen98) (sgActorName "reviewer") (sgBhId gen2)) (softgoalElement (sgId gen107) (sgQualityAttribute "quality") (sgSujectObject "review") (sgGoalId gen96) (sgActorName "chair") (sgBhId gen20)) (softgoalElement (sgId gen109) (sgQualityAttribute "quality") (sgSujectObject "review") (sgGoalId gen97) (sgActorName "committe") (sgBhId gen26)) (softgoalElement (sgId gen110) (sgQualityAttribute "quality") (sgSujectObject "review") (sgGoalId gen98) (sgActorName "reviewer") (sgBhId gen34)) (softgoalElement (sgId gen113) (sgQualityAttribute "quality") (sgSujectObject "article") (sgGoalId gen96) (sgActorName "chair") (sgBhId gen50)))
以下是提取的数据副本:
(gen113)quality [article]
(gen111)honest [review]
(gen110)quality[review]
(gen109)quality [review]
(gen108)acknowledge [committee]
(gen107)quality [review]
(gen105)punctuality [plubication]
(gen104)quality [review]
我使用的是这个规则:
(defrule Deleting::ruleDeleteSoftgoal "This rule deletes duplicate softagoal found in the facts base."
(declare (salience 58))
?fact <- (softgoalElement
(sgId ?sgId1)
(sgSujectObject ?SubjectObjectSg1)
(sgQualityAttribute ?QualityAttributeSg1)
(sgGoalId ?GoalIdSg1 )
(sgActorName ?ActorNameSg1 )
)
?fact2 <- (softgoalElement
(sgId ?sgId2)
(sgSujectObject ?SubjectObjectSg2)
(sgQualityAttribute ?QualityAttributeSg2)
(sgGoalId ?GoalIdSg2 )
(sgActorName ?ActorNameSg2 )
)
(test (and (neq ?sgId1 ?sgId2)(eq ?SubjectObjectSg2 ?SubjectObjectSg1)(eq ?QualityAttributeSg2 ?QualityAttributeSg1)
(neq ?GoalIdSg2 ?GoalIdSg1 )(neq ?ActorNameSg2 ?ActorNameSg1 )))
=>
(retract ?fact2) )
但是,存在于相同的数据库(sgActorName)上,并且我无法删除,最后只留下一条记录:我必须这样:
(gen113)quality [article]
(gen111)honest [review]
(gen110)quality [review]
(gen108)acknowledge [committee]
(gen105)punctuality [plubication]
我能帮上忙吗?
加里,
我一直在尝试消除重复,在这个基础上,规则正在删除一些重复的组合,而其他的没有,我检查了规则,没有发现任何阻止排除的东西。你能再帮我一次吗?
数据:
(deftemplate synonymoustype "Gets the Type of softgoal"
(slot type (type STRING) )
(slot syntype (type STRING) )
)
(deftemplate synonymoustopic "Gets the topic of softgoal"
(slot topic (type STRING) )
(slot syntopic (type STRING) )
)
排除规则:
(defrule ruleDeleteSoftgoal ""
(declare (salience 50))
(synSoftgoal
(ttId ?ttId1)
(synTopic ?syntopic1)
(synType ?syntype1))
?fact2 <- (synSoftgoal
(ttId ?ttId2)
(synTopic ?syntopic2)
(synType ?syntype2))
(test (and (neq ?ttId1 ?ttId2)
(eq ?syntopic2 ?syntopic1)
(eq ?syntype2 ?syntype1)))
=>
(retract ?fact2))
基础:
(deffacts synonymtype
(synonymoustype (type "correct") (syntype "equitable ") )
(synonymoustype (type "correct") (syntype "legitimate ") )
(synonymoustype (type "correct") (syntype "proper ") )
(synonymoustype (type "correct") (syntype "true ") )
(synonymoustype (type "fair") (syntype "equitable") )
(synonymoustype (type "fair") (syntype "legitimate") )
(synonymoustype (type "fair") (syntype "sincere") )
(synonymoustype (type "fair") (syntype "straightforward ") )
(synonymoustype (type "fair") (syntype "trustworthy") )
(synonymoustype (type "honest") (syntype "sincere") )
(synonymoustype (type "honest") (syntype "straightforward") )
(synonymoustype (type "honest") (syntype "true") )
(synonymoustype (type "honest") (syntype "trustworthy") )
(synonymoustype (type "acknowledge") (syntype "accept") ))
(deffacts synonymtopic
(synonymoustopic (topic "evaluation") (syntopic "appraisal") )
(synonymoustopic (topic "review") (syntopic "analysis") )
(synonymoustopic (topic "review") (syntopic "audit") ) )
结果:
(gen42)accept [appraisal]
(gen41)trustworthy [appraisal] - DEVERIA TER UMA SÓ
(gen40)true [appraisal] - DEVERIA TER UMA SÓ
(gen39)straightforward [appraisal] - DEVERIA TER UMA SÓ
(gen38)sincere [appraisal] - DEVERIA TER UMA SÓ
(gen37)trustworthy [appraisal]
(gen36)straightforward [appraisal]
(gen35)sincere [appraisal]
(gen34)legitimate [appraisal] - DEVERIA TER UMA SÓ
(gen33)equitable [appraisal] -DEVERIA TER UMA SÓ
(gen32)true [appraisal]
(gen31)proper [appraisal]
(gen30)legitimate [appraisal]
(gen29)equitable [appraisal]
(gen28)accept [analysis]
(gen27)trustworthy [analysis
再次感谢。
发布于 2014-06-05 01:19:31
您删除重复项的标准不明确。一种可能的解决方案是检查sgGoalId、sgActorName或sgBhId是否不同:
(defrule ruleDeleteSoftgoal
(softgoalElement
(sgId ?sgId1)
(sgSujectObject ?SubjectObjectSg1)
(sgQualityAttribute ?QualityAttributeSg1)
(sgGoalId ?GoalIdSg1)
(sgActorName ?ActorNameSg1)
(sgBhId ?sgBhId1))
?fact2 <- (softgoalElement
(sgId ?sgId2)
(sgSujectObject ?SubjectObjectSg2)
(sgQualityAttribute ?QualityAttributeSg2)
(sgGoalId ?GoalIdSg2)
(sgActorName ?ActorNameSg2)
(sgBhId ?sgBhId2))
(test (and (neq ?sgId1 ?sgId2)
(eq ?SubjectObjectSg2 ?SubjectObjectSg1)
(eq ?QualityAttributeSg2 ?QualityAttributeSg1)
(or (neq ?GoalIdSg2 ?GoalIdSg1 )
(neq ?ActorNameSg2 ?ActorNameSg1)
(neq ?sgBhId2 ?sgBhId1))))
=>
(retract ?fact2))
另一种是取消对sgGoalId和sgActorName的检查。
(defrule ruleDeleteSoftgoal
(softgoalElement
(sgId ?sgId1)
(sgSujectObject ?SubjectObjectSg1)
(sgQualityAttribute ?QualityAttributeSg1))
?fact2 <- (softgoalElement
(sgId ?sgId2)
(sgSujectObject ?SubjectObjectSg2)
(sgQualityAttribute ?QualityAttributeSg2))
(test (and (neq ?sgId1 ?sgId2)
(eq ?SubjectObjectSg2 ?SubjectObjectSg1)
(eq ?QualityAttributeSg2 ?QualityAttributeSg1)))
=>
(retract ?fact2))
两者都会产生您想要的最终输出。
加里,这是执行完毕的顺序:
(deftemplate synonymoustype "Gets the Type of softgoal"
(slot type (type STRING) )
(slot syntype (type STRING) )
)
(deftemplate synonymoustopic "Gets the topic of softgoal"
(slot topic (type STRING) )
(slot syntopic (type STRING) )
)
(deftemplate synSoftgoal "synsoftgoal receives synonyms for softgoals extracted from the base facts of (Cunha, 2014)"
(slot ttId (type SYMBOL) )
(slot synTopic (type STRING) )
(slot synType (type STRING) )
)
抬起底座:
(deffacts synonymtype
(synonymoustype (type "correct") (syntype "equitable ") )
(synonymoustype (type "correct") (syntype "legitimate ") )
(synonymoustype (type "correct") (syntype "proper ") )
(synonymoustype (type "correct") (syntype "true ") )
(synonymoustype (type "fair") (syntype "equitable") )
(synonymoustype (type "fair") (syntype "legitimate") )
(synonymoustype (type "fair") (syntype "sincere") )
(synonymoustype (type "fair") (syntype "straightforward ") )
(synonymoustype (type "fair") (syntype "trustworthy") )
(synonymoustype (type "honest") (syntype "sincere") )
(synonymoustype (type "honest") (syntype "straightforward") )
(synonymoustype (type "honest") (syntype "true") )
(synonymoustype (type "honest") (syntype "trustworthy") )
(synonymoustype (type "acknowledge") (syntype "accept") ))
(deffacts synonymtopic
(synonymoustopic (topic "evaluation") (syntopic "appraisal") )
(synonymoustopic (topic "review") (syntopic "analysis") )
(synonymoustopic (topic "review") (syntopic "audit") ) )
运行以下树规则:
(defrule ruleAssertSynsoftgoal "extracts the data from the base and inserts in synSoftgoal"
(synonymoustype
(type ?type )
(syntype ?syntype ))
(synonymoustopic
(topic ?topic )
(syntopic ?syntopic))
=>
(assert (synSoftgoal (ttId(gensym)) (synType ?syntype)(synTopic ?syntopic) ))
)
(defrule ruleDeleteSoftgoal "delete duplicate"
(synSoftgoal
(ttId ?ttId1)
(synTopic ?syntopic1)
(synType ?syntype1))
?fact2 <- (synSoftgoal
(ttId ?ttId2)
(synTopic ?syntopic2)
(synType ?syntype2))
(test (and (neq ?ttId1 ?ttId2)
(eq ?syntopic2 ?syntopic1)
(eq ?syntype2 ?syntype1)))
=>
(retract ?fact2))
(defrule rulePrintsTypeTopic "prints the base synSoftgoal"
(declare (salience 65))
(synSoftgoal
(ttId ?tId )
(synType ?Type)
(synTopic ?Topic)
)
=>
(printout t "Id:(" ?tId ") SynSoftgoal: "?Type" [" ?Topic "]" crlf)
)
结果:
(gen42)accept [appraisal]
(gen41)trustworthy [appraisal] - DEVERIA TER UMA SÓ
(gen40)true [appraisal] - DEVERIA TER UMA SÓ
(gen39)straightforward [appraisal] - DEVERIA TER UMA SÓ
(gen38)sincere [appraisal] - DEVERIA TER UMA SÓ
(gen37)trustworthy [appraisal]
(gen36)straightforward [appraisal]
(gen35)sincere [appraisal]
(gen34)legitimate [appraisal] - DEVERIA TER UMA SÓ
(gen33)equitable [appraisal] -DEVERIA TER UMA SÓ
(gen32)true [appraisal]
(gen31)proper [appraisal]
(gen30)legitimate [appraisal]
(gen29)equitable [appraisal]
(gen28)accept [analysis]
(gen27)trustworthy [analysis
https://stackoverflow.com/questions/24038636
复制相似问题