コード例 #1
0
 def __init__(self, T):
     self.comps = Rec({'base_type': T})
     self.witness_cache = []
     self.supertype_cache = []
     self.witness_conditions = [
         lambda l: isinstance(l, list) and forall(l, lambda x: T.query(x))
     ]
コード例 #2
0
 def __init__(self, T, a):
     self.comps = Rec({'base_type': T, 'obj': a})
     self.witness_cache = []
     self.supertype_cache = []
     self.witness_conditions = [lambda x: x == a and T.query(x),\
                                lambda x: isinstance(a,LazyObj)\
                                          and show(x) == show(a.eval()) and T.query(x)]
コード例 #3
0
 def __init__(self, name='', cs={}):
     self.name = name
     if self.name == '': self.name = gensym('T')
     self.comps = Rec(cs)
     self.witness_cache = []
     self.supertype_cache = []
     self.witness_conditions = []
コード例 #4
0
ファイル: ttrtypes.py プロジェクト: liesenf/pyttr
 def __init__(self, pred, args):
     self.comps = Rec({'pred': pred, 'args': args})
     self.witness_cache = []
     self.supertype_cache = []
     self.witness_conditions = []
     self.witness_types = []
     self.poss = ''
コード例 #5
0
 def __init__(self, T1, T2):
     self.comps = Rec({'domain': T1, 'range': T2})
     self.witness_cache = []
     self.supertype_cache = []
     self.witness_conditions = [lambda f: isinstance(f,Fun) \
                                     and f.domain_type == self.comps.domain \
                                     and self.comps.range.query(f.app(self.comps.domain.create_hypobj()))]
コード例 #6
0
ファイル: ttrtypes.py プロジェクト: liesenf/pyttr
 def __init__(self, T1, T2):
     self.comps = Rec({'left': T1, 'right': T2})
     self.witness_cache = []
     self.supertype_cache = []
     self.witness_conditions = [lambda a: self.comps.left.in_poss(self.poss).query(a), \
                                    lambda a: self.comps.right.in_poss(self.poss).query(a)]
     self.witness_types = []
     self.poss = ''
コード例 #7
0
ファイル: ttrtypes.py プロジェクト: liesenf/pyttr
 def __init__(self, name=gensym('BT')):
     self.name = name
     self.comps = Rec({})
     self.witness_cache = []
     self.supertype_cache = []
     self.witness_conditions = []
     self.witness_types = []
     self.poss = ''
コード例 #8
0
ファイル: ttrtypes.py プロジェクト: arildm/pyttr
 def create_hypobj(self):
     res = Rec()
     depfields = RecType()
     for l in self.comps.__dict__:
         T = self.comps.__getattribute__(l)
         if isinstance(T,Type):
             res.addfield(l,T.create_hypobj())
         else: depfields.addfield(l,T)
     return ProcessDepFields(depfields,res,self,'hyp')
コード例 #9
0
ファイル: ttrtypes.py プロジェクト: GU-CLASP/pyttr
 def create(self):
     res = Rec()
     depfields = RecType()
     for l in self.comps.__dict__:
         T = self.comps.__getattribute__(l)
         if isinstance(T, TypeClass):
             res.addfield(l, T.in_poss(self.poss).create())
         else:
             depfields.addfield(l, T)
     return ProcessDepFields(depfields, res, self)
コード例 #10
0
 def __init__(self, list):
     self.comps = Rec({'types': list})
     self.witness_cache = []
     self.supertype_cache = []
     self.witness_conditions = \
       [lambda s: isinstance(s,TTRString) \
        and len(s.items) == len(self.comps.types) \
        and forall([x for x in range(len(self.comps.types))], \
                   lambda i: self.comps.types[i].in_poss(self.poss).query(s.items[i]))]
     self.poss = ''
コード例 #11
0
 def __init__(self, T):
     self.comps = Rec({'base_type': T})
     self.witness_cache = []
     self.supertype_cache = []
     self.witness_conditions = \
       [lambda s: isinstance(s,TTRString) \
        and len(s.items)>0 \
        and forall(s.items,
                   lambda a: self.comps.base_type.in_poss(self.poss).query(a))]
     self.poss = ''
コード例 #12
0
ファイル: ttrtypes.py プロジェクト: GU-CLASP/pyttr
 def __init__(self, strT):
     self.comps = Rec({'base_type': strT})
     self.witness_cache = []
     self.supertype_cache = []
     self.witness_conditions = \
       [lambda s: isinstance(s,TTRString) and s.startswith_recursive(self.comps.base_type)]
     # and len(s.items)>0 \
     # and forall(s.items,
     #            lambda a: self.comps.base_type.in_poss(self.poss).query(a))]
     self.witness_types = []
     self.poss = _M
コード例 #13
0
 def __init__(self, d={}):
     self.comps = Rec()
     for item in d.items():
         if isinstance(item[1], dict):
             self.addfield(item[0], RecType(item[1]))
         else:
             self.addfield(item[0], item[1])
     self.witness_cache = []
     self.supertype_cache = []
     self.witness_conditions = [ \
         lambda r: isinstance(r, Rec) and RecOfRecType(r,self,self.poss)]
     self.poss = ''
コード例 #14
0
ファイル: probttrtypes.py プロジェクト: GU-CLASP/pyttr
 def sample(self, n=config.sample_size):
     chart = {}
     count = -1
     nondepfields = RecType()
     for l in self.comps.__dict__:
         T = self.comps.__getattribute__(l)
         if isinstance(T, RecType):
             count = count + 1
             chart[count] = []
             vals = T.in_poss(self.poss).sample(n)
             #print(show(T.in_poss(self.poss)))
             #print(vals)
             if count == 0:
                 for r in vals:
                     chart[count].append(Rec({l: r}))
                 #print(chart)
             else:
                 for r in vals:
                     for rec in chart[count - 1]:
                         combrec = rec.addrec(Rec({l: r}))
                         if combrec:
                             chart[count].append(combrec)
                         else:
                             pass
         elif isinstance(T, TypeClass):
             nondepfields.addfield(l, T)
         else:
             count = count + 1
             chart[count] = []
             matches = T[0].matches(self.poss, n)
             #print('matches: ', show(matches))
             for m in matches:
                 for s in m[0].in_poss(self.poss).sample(n):
                     r = Rec({l: s})
                     #print('r: ',show(r))
                     #print('T[1]',show(T[1]))
                     for p in T[1]:
                         newrec = Rec({})
                         newrec.addpath(p, m[1][T[1].index(p)])
                         #print('newrec:',show(newrec))
                         r = r.addrec(newrec)
                         #print('r after addrec: ',show(r))
                     if count == 0:
                         chart[count].append(r)
                     else:
                         for rec in chart[count - 1]:
                             combrec = rec.addrec(r)
                             if combrec:
                                 chart[count].append(combrec)
     count = count + 1
     chart[count] = []
     #print(show(nondepfields))
     if count == 0:
         newrecs = []
         for l in nondepfields.comps.__dict__:
             matches = nondepfields.comps.__getattribute__(l).in_poss(
                 self.poss).sample(n)
             if newrecs == []:
                 for i in range(2 * n):
                     m = np.random.choice(matches)
                     newrecs.append(Rec({l: m}))
             else:
                 for i in range(len(newrecs)):
                     m = np.random.choice(matches)
                     newrecs[i] = newrecs[i].addrec(Rec({l: m}))
         for r in newrecs:
             chart[count].append(r)
     else:
         for rec in chart[count - 1]:
             #print([l for l in rec.__dict__],[l for l in nondepfields.comps.__dict__])
             if set([l for l in nondepfields.comps.__dict__
                     ]).issubset(set([l for l in rec.__dict__])):
                 chart[count].append(rec)
             else:
                 newrecs = []
                 for l in [
                         l for l in nondepfields.comps.__dict__
                         if not l in rec.__dict__
                 ]:
                     matches = nondepfields.comps.__getattribute__(
                         l).in_poss(self.poss).sample(n)
                     if newrecs == []:
                         for i in range(2 * n):
                             m = np.random.choice(matches)
                             newrecs.append(Rec({l: m}))
                         # for m in matches:
                         #     newrecs.append(Rec({l:m}))
                     else:
                         for i in range(len(newrecs)):
                             m = np.random.choice(matches)
                             newrecs[i] = newrecs[i].addrec(Rec({l: m}))
                         # for r in newrecs:
                         #     m = np.random.choice(matches)
                         #     r.addrec(Rec({l:m}))
                 for r in newrecs:
                     chart[count].append(rec.addrec(r))
     #print(show(chart))
     res = []
     for r in chart[count]:
         if not any(map(lambda x: equal(x, r), res)):
             res.append(r)
     if len(res) <= n:
         return res
     else:
         return list(np.random.choice(res, n, False))
コード例 #15
0
ファイル: probttrtypes.py プロジェクト: GU-CLASP/pyttr
 def __init__(self, T):
     self.comps = Rec({'base_type': T})
     self.witness_conditions = [
         lambda a, c, oracle: PNeg(self.comps.base_type.query(a, c, oracle))
     ]
コード例 #16
0
 def __init__(self, T1, T2):
     self.comps = Rec({'left': T1, 'right': T2})
     self.witness_cache = []
     self.supertype_cache = []
     self.witness_conditions = [lambda a: self.comps.left.query(a) \
                                    and self.comps.right.query(a)]
コード例 #17
0
print(show(Fun('x', Ind, PType(man, ['x'])).app('j')))

print(show(manj))

print(manj.query_nonspec())

M = Possibility('M')
manj.in_poss(M)
print(Fun('x', Ind, PType(man, ['x'])).app('j').in_poss(M).query_nonspec())

print(show(M))

print(Ty.query(RecType({'x': Ind})))

print(RecType({'x': Ind}).query(Rec({'x': 'j'})))

print(RecType({'x': Ind}).query(Rec({'x': 'j', 'y': 'k', 'z': 'e1'})))

print(RecType({'x': Ind, 'y': Ind}).query(Rec({'x': 'j'})))  #False

print(
    RecTy.query(
        RecType({
            'x': Ind,
            'c': (Fun('v', Ind, PType(man, ['v'])), ['x'])
        })))

T_man = RecType({'x': Ind, 'c': (Fun('v', Ind, PType(man, ['v'])), ['x'])})

print(T_man.query(Rec({'x': 'j', 'c': '_e1'})))
コード例 #18
0
ファイル: example-records.py プロジェクト: zarzouram/pyttr
"""
Created on Tue Mar  3 15:05:58 2015

@author: cooper
"""

from records import Rec
from utils import show
r = Rec({
    'f': {
        'f': {
            'ff': 'a',
            'gg': 'b'
        },
        'g': 'c'
    },
    'g': {
        'h': {
            'g': 'a',
            'h': 'd'
        }
    }
})

print(show(r))
print(show(r.f))
print(show(r.g.h))
print(show(r.f.f.ff))

print(show(r.subst('a', 'z')))