Exemplo n.º 1
0
 def setUp(self):
     self.ZRO = RavensObject('Z')
     attr1 = RavensAttribute('shape', 'circle')
     attr2 = RavensAttribute('size', 'large')
     self.ZRO.attributes = [attr1, attr2]
     self.YRO = RavensObject('Y')
     attr1 = RavensAttribute('shape', 'square')
     attr2 = RavensAttribute('size', 'small')
     self.YRO.attributes = [attr1, attr2]
     self.otf = ObjectTransformation((self.ZRO, self.YRO))
Exemplo n.º 2
0
 def testEquals(self):
     ARO = RavensObject('A')
     attr1 = RavensAttribute('shape', 'circle')
     attr2 = RavensAttribute('size', 'large')
     ARO.attributes = [attr2, attr1]
     BRO = RavensObject('B')
     attr1 = RavensAttribute('shape', 'square')
     attr2 = RavensAttribute('size', 'small')
     BRO.attributes = [attr1, attr2]
     test_otf = ObjectTransformation((ARO, BRO))
     assert (self.otf == test_otf)
     test_otf = ObjectTransformation((BRO, ARO))
     assert (self.otf != test_otf)
Exemplo n.º 3
0
 def get_transformation(self, f1, o1, f2, o2):
     brf1 = BetterRavensFigure(self.figures[f1])
     brf2 = BetterRavensFigure(self.figures[f2])
     if o1 not in brf1 or o2 not in brf2:
         print "Incorrect object names"
         return -1
     transformation = ObjectTransformation([brf1[o1].RO, brf2[o2].RO])
     return transformation
Exemplo n.º 4
0
class ObjectTransformationTest(unittest.TestCase):
    def setUp(self):
        self.ZRO = RavensObject('Z')
        attr1 = RavensAttribute('shape', 'circle')
        attr2 = RavensAttribute('size', 'large')
        self.ZRO.attributes = [attr1, attr2]
        self.YRO = RavensObject('Y')
        attr1 = RavensAttribute('shape', 'square')
        attr2 = RavensAttribute('size', 'small')
        self.YRO.attributes = [attr1, attr2]
        self.otf = ObjectTransformation((self.ZRO, self.YRO))

    def testBasic(self):
        assert (self.otf.getObject(0))
        assert (self.otf.getObject(1))
        self.assertRaises(IndexError, self.otf.getObject, 2)

    def testGetTransformations(self):
        transformations = self.otf.getTransformations()
        assert ('shape' in transformations)
        assert (transformations['shape'].initial_value == 'circle')
        assert (transformations['shape'].final_value == 'square')
        assert ('size' in transformations)
        assert (transformations['size'].initial_value == 'large')
        assert (transformations['size'].final_value == 'small')

    def testEquals(self):
        ARO = RavensObject('A')
        attr1 = RavensAttribute('shape', 'circle')
        attr2 = RavensAttribute('size', 'large')
        ARO.attributes = [attr2, attr1]
        BRO = RavensObject('B')
        attr1 = RavensAttribute('shape', 'square')
        attr2 = RavensAttribute('size', 'small')
        BRO.attributes = [attr1, attr2]
        test_otf = ObjectTransformation((ARO, BRO))
        assert (self.otf == test_otf)
        test_otf = ObjectTransformation((BRO, ARO))
        assert (self.otf != test_otf)
Exemplo n.º 5
0
 def testSingleObjectComparison(self):
     ARO = RavensObject('A')
     attr1 = RavensAttribute('shape', 'circle')
     attr2 = RavensAttribute('size', 'large')
     ARO.attributes = [attr1, attr2]
     BRO = RavensObject('B')
     attr1 = RavensAttribute('shape', 'circle')
     attr2 = RavensAttribute('size', 'small')
     BRO.attributes = [attr2, attr1]
     test_otf = ObjectTransformation((ARO, BRO))
     test_ftf = FigureTransformation()
     test_ftf.add('A', test_otf)
     assert (self.ftf == test_ftf)
Exemplo n.º 6
0
def mappings(x, y, getTransformations=True, repeats=False):
    tempy = y
    if len(y) < len(x):
        tempy.extend([None] * (len(x) - len(y)))
    mappings = util.pairs(x, tempy)
    if len(x) < len(y):
        mappings = util.extended_pairs(x, y)
        # Mappings defined as follows: Given x=[1], y=[1,2], we want
    queue = PriorityQueue()
    for mapping in mappings:
        ftf = FigureTransformation()
        for objectMap in mapping:
            name = objectMap[0].getName()
            otf = ObjectTransformation(objectMap,
                                       ftf,
                                       transform=getTransformations,
                                       try_repeats=repeats)
            ftf.add(name, otf)
        yield ftf