我必须使用此基础并删除重复项。
(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
再次感谢。
答案 0 :(得分:0)
您删除重复项的标准尚不清楚。一种可能的解决方案是检查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))
两者都产生你想要的最终输出。
Gary,这是执行完成的顺序:
(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