Example #1
0
def get_fact(csubj, cpred, ctime, ctruth):
    try:
        subj = Namable.from_clips(csubj)
    except clips.ClipsError:
        subj = Word.from_clips(csubj)
    pred = Namable.from_clips(cpred)
    t = Time.from_clips(ctime)
    truth = int(str(ctruth))
    fact = Fact(subj, pred, t, truth=truth)
    return fact
Example #2
0
def factback(csubj, cpred, ctime, ctruth):
    """
    """
    try:
        subj = Namable.from_clips(csubj)
    except clips.ClipsError:
        subj = Word.from_clips(csubj)
    pred = Namable.from_clips(cpred)
    t = Time.from_clips(ctime)
    truth = int(str(ctruth))
    fact = Fact(subj, pred, t, truth=truth)
    pred.in_fact(fact)
    for plugin in utils.plugins:
        plugin(fact)
Example #3
0
def ask(*sentences):
    '''
    Retrieve objects from clips.
    sentences is a list of facts or things,
    and they can contain variables,
    whose scope is the set of sentences asked.
    return a list of dicts with the names of the variables
    used in the sentences asked as keys
    and the matched objects as values.
    If there are no variables in the
    question, but the asked sentences match,
    return True.
    if there is no match, return False
    '''
    clps, templs = get_instances(*sentences)
    resp = []
    if clps:
        names = [Namable.from_clips(ins) for ins in clps]
        while names:
            first = names[:len(templs)]
            names = names[len(templs):]
            rsp = {}
            for templ in templs:
                if utils.varpat.match(templ[0]) and not templ[0].startswith('Y'):
                    rsp[templ[0]] = str(first[templs.index(templ)])
            if rsp:
                resp.append(rsp)
        if not resp:
            resp = True
    else:
        resp = False
    return resp
Example #4
0
 def from_clips(cls, instance):
     if not isinstance(instance, clips._clips_wrap.Instance):
         instance = clips.FindInstance(instance)
     s = instance.GetSlot('subject')
     if isinstance(instance, clips._clips_wrap.Class):
         s = Word.from_clips(s)
     else:
         s = Namable.from_clips(s)
     p = Exists.from_clips(instance.GetSlot('predicate'))
     t = Time.from_clips(instance.GetSlot('time'))
     truth = instance.GetSlot('truth')
     return Fact(s, p, t, truth=truth)
Example #5
0
def ask_obj(sentence):
    '''
    retrieve sentences in clips
    matching the given sentence.
    Can use variables.
    '''
    clps, templs = get_instances(sentence)
    sens = []
    if clps:
        if isinstance(sentence, Thing):
            for ins in clps:
                sens.append(Namable.from_clips(ins))
        elif isinstance(sentence, Fact):
            for ins in clps:
                i = clips.FindInstance(ins)
                if issubclass(utils.get_class(str(i.Class.Name)), Fact):
                    sens.append(Fact.from_clips(ins))
    return sens