Esempio n. 1
0
def plotPh22():
    import Gnuplot
    resp1 = kb.ask_obj(Fact(c1, Has_position(x='X1', y='X2'), 'X3'))
    resp2 = kb.ask_obj(Fact(c2, Has_position(x='X1', y='X2'), 'X3'))

    #resp1 = kb.ask_obj(Fact(c1, Is_forced(newton='X1'), 'X2'))
    #resp2 = kb.ask_obj(Fact(c2, Is_forced(newton='X1'), 'X2'))


    line1 = [(float(p.predicate.x.value), float(p.predicate.y.value)) for p in resp1]
    line2 = [(float(p.predicate.x.value), float(p.predicate.y.value)) for p in resp2]


    gp = Gnuplot.Gnuplot(persist = 1)

    gp('set data style lines')

    plot1 = Gnuplot.PlotItems.Data(line1, with="dots lw 2 lc rgb 'red'",
          title='c1 con %s kgs, desde (%s, %s) a (%s, %s)' % (p1.predicate.kgs.value,
                                                         p3.predicate.x.value,
                                                         p3.predicate.y.value,
                                                         p5.predicate.x.value,
                                                         p5.predicate.y.value))
    plot2 = Gnuplot.PlotItems.Data(line2, with="points pt 6 lw 1 lc rgb 'blue'",
          title='c2 con %s kgs, desde (%s, %s) a (%s, %s)' % (p2.predicate.kgs.value,
                                                         p4.predicate.x.value,
                                                         p4.predicate.y.value,
                                                         p6.predicate.x.value,
                                                         p6.predicate.y.value))

    gp.plot(plot1, plot2)
Esempio n. 2
0
 def __init__(self, subj, pred, t='now', truth=1):
     self.truth = truth
     if isinstance(pred, str):
         self.predicate = Exists(pred)
     else:
         if not isinstance(pred, Exists) and \
            not isinstance(pred, ClassVarVar):
             raise ValueError('The predicate of a fact has to be a verb')
         self.predicate = pred
     if isinstance(subj, str):
         if utils.varpat.match(subj):
             self.subject = self.pred.subject(subj)
         else:
             from nl import kb
             try:
                 self.subject = kb.ask_obj(Thing(subj))[0]
             except IndexError:
                 self.subject = utils.get_class(subj)
             if not self.subject:
                 raise ValueError('If Fact receives a string as subject'
                                  'It has to be a variable or a thing'
                                  'already defined in the knowledge base')
     else:
         if not isinstance(subj, Thing) and \
            not isinstance(subj, Word) and \
            not isinstance(subj, ClassVar) and \
            not isinstance(subj, ClassVarVar):
             raise ValueError('Not a proper subject for fact')
         self.subject = subj
     subj = self.subject
     if not isinstance(subj, ClassVar) and \
        not isinstance(subj, ClassVarVar) and \
            (not isinstance(self.predicate, ClassVar) and
             not isinstance(self.predicate, ClassVarVar) and
             not isinstance(subj, self.predicate.subject)):
         raise ValueError('Not a proper subject for %s' %
                           self.predicate.__class__.__name__)
     if isinstance(t, Namable):
         self.time = t
     else:
         self.time = Instant(t)