In [1]:
from symbolic import Symbolic, Reason

In [2]:
s1 = Symbolic('a')
print (s1)
s1.add_symbolic('a', 'foo')
print (s1)
print (len(s1), type(s1))


['a']
[('a', ['foo'])]
1 <class 'symbolic.Symbolic'>

In [3]:
s1 = Symbolic('0 1 1')
s2 = Symbolic('1 0 1')
s1.mask(s2)


Out[3]:
[['0'], ['0', '1'], ['1'], ['1'], [('1', ['_2'])]]

In [4]:
s1 = Symbolic('a b c')
s2 = Symbolic('x y c')
s3 = Symbolic('c o i')
print (s1.mask(s2))
print (s2.mask(s3))


[[('c', ['_2'])]]
[['c']]

In [5]:
r = Reason()
s1 = Symbolic('0 1 0')
r.add_pattern(pattern=s1, attribute='middle', relation='is')
s2 = Symbolic('0 1 1')
r.add_pattern(pattern=s2, attribute='middle', relation='is')
s3 = Symbolic('1 1 1')
r.add_pattern(pattern=s3, attribute='middle', relation='is')
r.add_pattern(pattern=Symbolic('0 0 1'), attribute='middle', relation='is not')
r.add_pattern(pattern=Symbolic('1 0 0'), attribute='middle', relation='is not')

r.get_patterns('middle')['patterns']


Out[5]:
[[('0', ['_0']), ('1', ['_1']), ('0', ['_2'])],
 [('1', ['_0']), ('1', ['_1']), ('1', ['_2'])],
 [('0', ['_0']), ('1', ['_1']), ('1', ['_2'])]]

In [6]:
r.distinguishing('middle')


Out[6]:
[['1'], [('1', ['_1'])]]

In [7]:
s0 = Symbolic('1 1 0')
print (r.determine(s0, 'middle'))

s0 = Symbolic('1 0 0')
print (r.determine(s0, 'middle'))

s0 = Symbolic('0 0 0')
print (r.determine(s0, 'middle'))


(True, 'has distinguishing features')
(False, 'exact match with attribute anti-patterns')
(False, 'has higher similarity with attribute anti-patterns than its patterns')

In [8]:
s0 = Symbolic('x y z')
r.determine(s0, 'middle')


Out[8]:
(None, "I don't know")

In [16]:
r = Reason()
s1 = Symbolic('a b c o u t z')
r.add_pattern(pattern=s1, attribute='abc', relation='is')
s2 = Symbolic('v a b c h v l')
r.add_pattern(pattern=s2, attribute='abc', relation='is')
s3 = Symbolic('x y k a b n')
r.add_pattern(pattern=s3, attribute='abc', relation='is not')
s4 = Symbolic('o n o x y g')
r.add_pattern(pattern=s4, attribute='abc', relation='is not')

print (r.distinguishing('abc'))
print (r.distinguishing('abc', relation='is not'))


[['a'], ['a', 'b'], ['a', 'b', 'c'], ['b'], ['b', 'c'], ['c']]
[['x'], ['x', 'y'], ['y'], ['n']]

In [17]:
s0 = Symbolic('c b a c a n x')
r.determine(s0, 'abc', debug=False)


Out[17]:
(True, 'has higher similarity with attribute patterns than its anti-patterns')

In [18]:
s0 = Symbolic('c b a c b a n x')
r.add_pattern(pattern=s0, attribute='abc', relation='is not')
print (r.distinguishing('abc', relation='is not'))


[['x'], ['n']]

In [19]:
s0 = Symbolic('o g h j n x')
r.determine(s0, 'abc')


Out[19]:
(True, 'has distinguishing features for anti-relation')

In [20]:
s1 = Symbolic('terrier trout crow')
s1.add_symbolic('terrier', 'dog')
s1.add_symbolic('trout', 'fish')
s1.add_symbolic('crow', 'bird')

s2 = Symbolic('robin')
s2.add_symbolic('robin', 'bird')

s1.mask(s2)


Out[20]:
[[('*', ['bird'])]]