Exemplo n.º 1
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
Exemplo n.º 2
0
def reset():
    logger.info('\n\n\n---------RESET-----------\n\n\n')
    nl.clps.clips.Reset()
    nl.clps.clips.Clear()
    reload(nl.clps.clips)
    reload(nl.clps)
    reload(nl.metanl)
    reload(nl.nltime)
    reload(nl.thing)
    reload(nl.state)
    reload(nl.prop)
    reload(nl.rule)
    reload(nl.kb)
    reload(nl)
Exemplo n.º 3
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 + '.')
Exemplo n.º 4
0
def run_npl(fname):
    # open file, read lines
    # tell asserions
    # compare return of questions with provided output
    with open(fname) as f:
        prep = Preprocessor().parse(f.read())
        resp, buff = None, ''
        for sen in prep.split('\n'):
            logger.info(sen)
            sen = sen.strip('\n ')
            if resp is not None:
                sen = sen.strip('.')
                logger.info('%s match %s' % (sen, resp))
                assert re.compile(sen).match(resp)
                resp = None
            elif sen and not sen.startswith('#'):
                buff += ' ' + sen
                if buff.endswith('.'):
                    logger.info(nl.yacc.parse(buff))
                    buff = ''
                elif buff.endswith('?'):
                    resp = nl.yacc.parse(buff)
                    buff = ''
Exemplo n.º 5
0
#and no longer has status initial.

try:
  kb.tell(Rule([
    Fact(Workflow('W1'), HasTransition(start=Status('S1'), end=Status('S2'), by=Verb('V1', WfAction)), Duration('T4')),
    Fact(Workflow('W1'), Assigned(to=Noun('N1', Content), where=Context('X1')), Duration('T2')),
    Fact(Noun('N1', Content)('C1'), Located(where=Context('X1')), Duration('T1')),
    Fact(Person('P1'), Verb('V1', WfAction)(what=Noun('N1', Content)('C1')), Instant('I1')),
    Fact(Noun('N1', Content)('C1'), Has(what=Status('S1')), Duration('T3')),
    During('I1', 'T1','T2', 'T3', 'T4')
],[
    Fact(Noun('N1')('C1'), Has(what=Status('S2')), Duration(start=Instant('I1'), end=MaxComEnd('T1', 'T2'))),
    Finish('T3', 'I1')]))
except:
   import clips
   logger.info(clips.ErrorStream.Read())



def r_transition(action, workflow, initial, final):
    """

    """
    kb.tell( Fact(workflow, HasTransition(start=initial, end=final, by=action), Duration(start='now', end='now')) )



#def r_transition(action, workflow, content_type, initial, final):
#    """
#    If a person performs a workflow action on a content object,
#    and that object has the intitial status up till that moment,
Exemplo n.º 6
0
 def __init__(cls, classname, bases, newdict, clp=''):
     super(Word, cls).__init__(classname, bases, newdict)
     if clp:
         logger.info(clp)
         clips.Build(clp)
     utils.register(classname, cls)
Exemplo n.º 7
0
import clips
from nl.log import logger
from nl import conf


# CLIPS SNIPPETS
################

class_constraint = '?%(val)s&:(or (eq (class ?%(val)s) %(cls)s) (subclassp (class ?%(val)s) %(cls)s))'


# CLIPS DEFINITIONS
###################

_name_def = '(defclass Namable (is-a USER))'
logger.info(_name_def)
clips.Build(_name_def)

_reduce_class = '''
(deffunction reduce-class (?instance ?class)
    (if (eq (length$
                (find-all-instances ((?a ?class))(eq (instance-name ?a) ?instance)))
             0)
    then (make-instance ?instance of ?class)
    else (return TRUE)))'''
logger.info(_reduce_class)
clips.Build(_reduce_class)


_duration_clps = '(defclass Duration (is-a Namable) (slot start (type NUMBER) (pattern-match reactive)) (slot end (type NUMBER) (pattern-match reactive)))'
logger.info(_duration_clps)
Exemplo n.º 8
0

if conf.start_time:
    utils.now()

# CLIPS SNIPPETS
################

class_constraint = '?%(val)s&:(or (eq (class ?%(val)s) %(cls)s) (subclassp (class ?%(val)s) %(cls)s))'


# CLIPS DEFINITIONS
###################

_set_tal = '(set-sequence-operator-recognition TRUE)'
logger.info(_set_tal)
clips.Eval(_set_tal)


_name_def = '(defclass Namable (is-a USER))'
logger.info(_name_def)
clips.Build(_name_def)

_logger_def = '''
(deffunction logger (?tolog)
  (open "fromclips" file "a")
  (printout file ?tolog)
  (printout file crlf)
  (close file)
)
'''