Example #1
0
def raise_contradiction(csubj, cpred, ctime, ctruth):
    """
    """
    fact = get_fact(csubj, cpred, ctime, ctruth)
    e = Contradiction(fact)
    logger.error(str(e))
    raise e
Example #2
0
def get_instances(*sentences):
    q, templs = get_instancesn(*sentences)
    logger.info(q)
    try:
        return clips.Eval(q), templs
    except:
        logger.error(clips.ErrorStream.Read())
        raise
Example #3
0
def extend():
    '''
    Run the CLIPS machine;
    build or extend the rete network.
    To be used whenever new sentences
    or rules are added to clips,
    and we want to query the system.
    '''
    acts = clips.Run()
    logger.error(clips.ErrorStream.Read())
    return acts
Example #4
0
def tell(*args):
    '''
    Take any number of sentences and rules and
    add them to clips.
    '''
    for sentence in args:
        s = sentence.put_action()
        logger.info(s)
        if isinstance(sentence, Rule):
            try:
                clips.Build(s)
            except:
                logger.error(clips.ErrorStream.Read())
                raise
        else:
            try:
                clips.Eval(s)
            except:
                logger.error(clips.ErrorStream.Read())
                raise
        sen = sentence.sen_tonl()
        if sen:
            utils.to_history(sen + '.')
Example #5
0
          then 
               (bind ?children (send ?dur get-children))
               (send ?dur put-children (create$ ?new-child $?children))
               (bind ?parents ?self:parents)
               (bind ?self:parents (create$ ?dur $?parents))
               (bind ?familiar TRUE)
          ))
    (if (eq ?familiar TRUE) then (bind ?self:families (create$ ?family)))
    (bind ?self:end ?end)
)
'''
logger.info(_commend_clp)
try:
  clips.Build(_commend_clp)
except:
    logger.error(clips.ErrorStream.Read())
    raise

_makedur_clp = '''
(deffunction make-duration (?duration)
    (bind ?family (gensym*))
    (bind ?newdur (duplicate-instance ?duration))
    (send ?newdur put-children (create$))
    (bind ?newchild (make-instance of ChildDuration (child ?newdur) (family ?family)))
    (bind ?children (send ?duration get-children))
    (send ?duration put-children (create$ ?newchild $?children))
    (modify-instance ?newdur (parents (create$ ?duration))
                              (families (create$ ?family)))
    (return ?newdur)
)
'''