Как использовать или в равенстве в клипах?

Мне приходится работать с этой базой и удалять дубликаты.

(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

Спасибо еще раз.


person user3174846    schedule 04.06.2014    source источник


Ответы (1)


Ваши критерии удаления дубликатов не ясны. Одно из возможных решений — проверить, отличаются ли 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
person Gary Riley    schedule 04.06.2014
comment
Трудно понять, как исправить вашу программу, когда вы просто включаете фрагменты кода, а не полный пример, который можно запустить для воспроизведения результатов, которые вы видите. - person Gary Riley; 27.06.2014
comment
Все еще невоспроизводимый с последними правками. Формат результатов, которые вы указали, даже не соответствует операторам распечатки из вашего кода, которые выглядят так: Id: (gen4) SynSoftgoal: правильный [аудит] - person Gary Riley; 29.06.2014
comment
Гэри, это то, что в сочетании она сочетает каждый тип со всеми темами, и как ответ был бы очень большим, просто поместите часть результатов. Она делает все виды в сочетании с каждой темой, получив в конце процесса synsoftgoal 42 и среди них цитируемых вами. Если вы можете отправить электронное письмо, отправив все для вас. Спасибо - person user3174846; 30.06.2014