예제 #1
0
 def setUp(self):
     testNS = {
         'med'   : 'http://ts.tno.nl/mediator/1.0/',
         't'     : 'http://ts.tno.nl/mediator/test#',
         'dc'    : 'http://purl.org/dc/elements/1.1/',
         'ne'    : 'http://ts.tno.nl/mediator/1.0/examples/NonExistent/',
         'oa'    : 'http://tutorial.topbraid.com/ontoA/',
         'edoal' : 'http://ns.inria.org/edoal/1.0/#'
     }
     self.base = 'http://knowledgeweb.semanticweb.org/heterogeneity/alignment#'
     self.nsMgr = NSManager(testNS, self.base)
     self.c = PT.Correspondence(nsMgr=self.nsMgr)
     self.operands = []
     self.testCases = {}
     
     '''
     The Transform tests will validate:
     * testTransformation: the creation of a transformation specification
     * testMakeTransform:  the transition from the name of an operation to a callable function
     * testTransform:      the transition from the specification of the operands to the inclusion of the correct values in the operation
     '''
     
     alignFile = "resources/alignPassTransformation1.xml"
     self.align = EDOALparser.Alignment(alignFile, self.nsMgr)
     if self.align == None: raise TestException("Cannot find an alignment in file '{}'".format(alignFile))
     self.corrs = self.align._align.findall(str(self.nsMgr.asClarks(':map')) + '/' + str(self.nsMgr.asClarks(':Cell')))
     if self.corrs == None or self.corrs == []: raise TestException("Cannot find <map><Cell> elements in file '{}'".format(alignFile))
     self.Transformations = []
     
     for corr in self.corrs:
         TransformationElmnts = corr.findall(str(self.nsMgr.asClarks('edoal:transformation')) + '/' + str(self.nsMgr.asClarks('edoal:Transformation')))
         if TransformationElmnts == None or TransformationElmnts == []: raise TestException("Cannot find <transformation><Transformation> elements in file '{}'".format(alignFile))
         self.Transformations += TransformationElmnts
         
     print('Testcase: {}'.format(self.__class__.__name__))
예제 #2
0
 def setUp(self):
     testNS = {
         'med': 'http://ds.tno.nl/mediator/1.0/',
         'dc': 'http://purl.org/dc/elements/1.1/',
         'edoal': 'http://ns.inria.org/edoal/1.0/#',
         'test': 'http://ds.tno.nl/mediator/1.0'
     }
     self.base = 'http://knowledgeweb.semanticweb.org/heterogeneity/alignment#'
     self.nsMgr = NSManager(nsDict=testNS, base=self.base)
예제 #3
0
 def setUp(self):
     testNS = {
         'med'   : 'http://ds.tno.nl/mediator/1.0/',
         'dc'    : 'http://purl.org/dc/elements/1.1/',
         'edoal' : 'http://ns.inria.org/edoal/1.0/#'
     }
     self.base = 'http://knowledgeweb.semanticweb.org/heterogeneity/alignment#'
     self.nsMgr = NSManager(testNS, self.base)
     self.c = PT.Correspondence(nsMgr=self.nsMgr)
     print('Testcase: {}'.format(self.__class__.__name__))
예제 #4
0
 def setUp(self):
     testNS = {
         'med'   : 'http://ts.tno.nl/mediator/1.0/',
         'dc'    : 'http://purl.org/dc/elements/1.1/',
         'edoal' : 'http://ns.inria.org/edoal/1.0/#'
     }
     self.base = 'http://knowledgeweb.semanticweb.org/heterogeneity/alignment#'
     self.nsMgr = NSManager(testNS, self.base)
     self.path = PT.Path()
     self.property = PT.EProperty(entity_iri='med:testProperty', nsMgr=self.nsMgr)
     self.relations = [PT.ERelation(entity_iri='med:testRel1', nsMgr=self.nsMgr), PT.ERelation(entity_iri='med:testRel2', nsMgr=self.nsMgr), PT.ERelation(entity_iri='med:testRel3', nsMgr=self.nsMgr)]
     print('Testcase: {}'.format(self.__class__.__name__))
예제 #5
0
 def addEntityExpr(self, ent_expr=None):
     assert isinstance(
         ent_expr, EntityExpression
     ) and ent_expr != "", "Entity expression expected, got {}".format(
         type(ent_expr))
     assert len(
         self.getEntities()
     ) < 2, "Entity constructions containing more than 2 entity expressions are not allowed (although it would remove recursion)"
     assert NSManager.isIRI(
         ent_expr.getIriRef()
     ), "Cannot add invalid iri as ent_expr to ent_expr construction, got {}".format(
         ent_expr.getIriRef())
     self._entities.append(ent_expr)
예제 #6
0
class transformTest(unittest.TestCase):

    def setUp(self):
        testNS = {
            'med'   : 'http://ts.tno.nl/mediator/1.0/',
            't'     : 'http://ts.tno.nl/mediator/test#',
            'dc'    : 'http://purl.org/dc/elements/1.1/',
            'ne'    : 'http://ts.tno.nl/mediator/1.0/examples/NonExistent/',
            'oa'    : 'http://tutorial.topbraid.com/ontoA/',
            'edoal' : 'http://ns.inria.org/edoal/1.0/#'
        }
        self.base = 'http://knowledgeweb.semanticweb.org/heterogeneity/alignment#'
        self.nsMgr = NSManager(testNS, self.base)
        self.c = PT.Correspondence(nsMgr=self.nsMgr)
        self.operands = []
        self.testCases = {}
        
        '''
        The Transform tests will validate:
        * testTransformation: the creation of a transformation specification
        * testMakeTransform:  the transition from the name of an operation to a callable function
        * testTransform:      the transition from the specification of the operands to the inclusion of the correct values in the operation
        '''
        
        alignFile = "resources/alignPassTransformation1.xml"
        self.align = EDOALparser.Alignment(alignFile, self.nsMgr)
        if self.align == None: raise TestException("Cannot find an alignment in file '{}'".format(alignFile))
        self.corrs = self.align._align.findall(str(self.nsMgr.asClarks(':map')) + '/' + str(self.nsMgr.asClarks(':Cell')))
        if self.corrs == None or self.corrs == []: raise TestException("Cannot find <map><Cell> elements in file '{}'".format(alignFile))
        self.Transformations = []
        
        for corr in self.corrs:
            TransformationElmnts = corr.findall(str(self.nsMgr.asClarks('edoal:transformation')) + '/' + str(self.nsMgr.asClarks('edoal:Transformation')))
            if TransformationElmnts == None or TransformationElmnts == []: raise TestException("Cannot find <transformation><Transformation> elements in file '{}'".format(alignFile))
            self.Transformations += TransformationElmnts
            
        print('Testcase: {}'.format(self.__class__.__name__))

    def tearDown(self):
        pass

    def testTransformation(self):
        # Test the connection to, and correct execution of, a predefined python method
        print('\tTesting {} '.format(inspect.currentframe().f_code.co_name), end="")
        from transformations import unitconversion
        # setup specifics
        oneOperands = []
        t = self.Transformations[0]
        operandEl = t.find(str(self.nsMgr.asClarks('edoal:entity1')))
        if operandEl == None: raise TestException("Cannot find <edoal:entity1> element in <edoal:Transformation> ")
        oneOperands.append(self.align.Value(el=operandEl, parse_alignment=self.align))
        
        twoOperands = []
        operandEl = t.find(str(self.nsMgr.asClarks('edoal:entity2')) + '/' + str(self.nsMgr.asClarks('edoal:Apply')) + '/' + str(self.nsMgr.asClarks('edoal:arguments')))
        if operandEl == None: raise TestException("Cannot find <edoal:entity2><edoal:Apply><edoal:arguments> element in <edoal:Transformation> ")
        for value_el in operandEl.iter():
            if value_el.tag == self.nsMgr.asClarks('edoal:Literal'):
                twoOperands.append(self.align.Value(el=value_el, parse_alignment=self.align))

        # PASS tests
        # First test: init a complete transformation
        assert 'FtoC' in dir(unitconversion)
        t = PT.Transformation(python_module='unitconversion', method_name='FtoC', operands=oneOperands)
        assert t != None, "Failed to make a Transformation"
        print(".", end="")
        assert t.getLocalMethod()[1] == 'FtoC', "Expected {}, got {}".format('FtoC', t.getLocalMethod()[1])
        print(".", end="")
        assert t.getLocalMethod()[0].__name__ == 'transformations.unitconversion', "Expected {}, got {}".format('transformations.unitconversion', t.getLocalMethod()[0].__name__)
        print(".", end="")
        assert t._operands == oneOperands, "Failed to register operands: expected {}, got {}".format(oneOperands, t._operands)
        print(".", end="")
        args = '32'
        assert t.getOperationResult(args) == decimal.Decimal('0'), "Expected {} as transformation result, got {}".format(decimal.Decimal('0'), t.getOperationResult(value=args))
        print(".", end="")
        
        # Second test: init an empty transformation, and add the elements
        assert 'CtoF' in dir(unitconversion)
        t = PT.Transformation()
        assert t != None, "Failed to make an empty Transformation"
        print(".", end="")
        t.registerLocalMethod(python_module='unitconversion', method_name='CtoF')
        assert t.getLocalMethod()[1] == 'CtoF', "Failed to register local method: Expected {}, got {}".format('CtoF', t.getLocalMethod()[1])
        print(".", end="")
        assert t.getLocalMethod()[0].__name__ == 'transformations.unitconversion', "Failed to register local method: Expected {}, got {}".format('transformations.unitconversion', t.getLocalMethod()[0].__name__)
        print(".", end="")
        t.registerOperands(operands=oneOperands)
        assert t._operands == oneOperands, "Failed to register operands: expected {}, got {}".format(oneOperands, t._operands)
        print(".", end="")
        assert t.getOperationResult('0') == decimal.Decimal('32'), "Expected {} as transformation result, got {}".format(decimal.Decimal('32'), t.getOperationResult(value='0'))
        print(".", end="")
        
        # Third test: init a partially empty transformation, and add two operands
        assert 'TempConvertor' in dir(unitconversion)
        t = PT.Transformation(python_module='unitconversion', method_name='TempConvertor')
        assert t != None, "Failed to make an partly empty Transformation"
        print(".", end="")
        assert t.getLocalMethod()[1] == 'TempConvertor', "Failed to register local method: Expected {}, got {}".format('CtoF', t.getLocalMethod()[1])
        print(".", end="")
        assert t.getLocalMethod()[0].__name__ == 'transformations.unitconversion', "Failed to register local method: Expected {}, got {}".format('transformations.unitconversion', t.getLocalMethod()[0].__name__)
        print(".", end="")
        t.registerOperands(operands=twoOperands)
        assert t._operands == twoOperands, "Failed to register operands: expected {}, got {}".format(twoOperands, t._operands)
        print(".", end="")
        assert t.getOperationResult(temp_value='0', src_unit='c', tgt_unit='f') == decimal.Decimal('32'), "Expected {} as transformation result, got {}".format(decimal.Decimal('32'), t.getOperationResult(temp_value='0', src_unit='f', tgt_unit='c'))
        print(".", end="")
        
        # Fail scenarios
        with self.assertRaises(AssertionError):
            PT.Transformation(python_module='unitconversion', method_name='CtoF', operands=['InvalidOperand'])
        print(".", end="")
        with self.assertRaises(AssertionError):
            PT.Transformation(python_module='unitconversion', method_name='appelepap', operands=oneOperands)
        print(".", end="")
        with self.assertRaises(AssertionError):
            PT.Transformation(python_module='appelepap', method_name='FtoC', operands=oneOperands)
        print(". done")

    def testMakeTransform(self):
        # Success scenarios
        # Test the creation of a callable transformation
        print('\tTesting {} '.format(inspect.currentframe().f_code.co_name), end="")
        t = PT.Transformation(python_module='unitconversion', method_name='FtoC', operands=self.operands)
        t.makeTransform(resultIRI='newIRI')
        assert callable(t.transform), "Expected callable function, but {} is not callable".format(t.transform)
        print(".", end="")
        assert t.getOperationResult('32') == decimal.Decimal('0'), "Expected {} as transformation result, got {}".format(decimal.Decimal('0'), t.getOperationResult('32'))
        print(".", end="")

        # Fail scenarios
        t = PT.Transformation(operands=self.operands)
        with self.assertRaises(AssertionError): 
            t.makeTransform(resultIRI='newIRI')
        print(".", end="")
        t = PT.Transformation(python_module='unitconversion', operands=self.operands)
        with self.assertRaises(AssertionError): 
            _ = t.makeTransform(resultIRI='newIRI')
        print(".", end="")
        t = PT.Transformation(method_name='FtoC', operands=self.operands)
        with self.assertRaises(AssertionError): 
            _ = t.makeTransform(resultIRI='newIRI')
        print(". done")
예제 #7
0
class correspondenceTest(unittest.TestCase):

    def setUp(self):
        testNS = {
            'med'   : 'http://ds.tno.nl/mediator/1.0/',
            'dc'    : 'http://purl.org/dc/elements/1.1/',
            'edoal' : 'http://ns.inria.org/edoal/1.0/#'
        }
        self.base = 'http://knowledgeweb.semanticweb.org/heterogeneity/alignment#'
        self.nsMgr = NSManager(testNS, self.base)
        self.c = PT.Correspondence(nsMgr=self.nsMgr)
        print('Testcase: {}'.format(self.__class__.__name__))

    def tearDown(self):
        pass

    def testSetName(self):
        print('\tTesting {} '.format(inspect.currentframe().f_code.co_name), end="")
        # Success scenarios
        self.c.setName(name="appelepap") 
        assert self.c.getName() == "appelepap", "Assertion error, got {}".format(self.c.getName())
        self.c.setName(name="unknownPF:appelepap") 
        assert self.c.getName() == "unknownPF:appelepap", "Assertion error, got {}".format(self.c.getName())
        print(".", end="")
        # Failure scenarios
        with self.assertRaises(AssertionError): 
            self.c.setName(name="")
        with self.assertRaises(AssertionError): 
            self.c.setName(name=12)
        with self.assertRaises(AssertionError): 
            self.c.setName(name=True)
        with self.assertRaises(AssertionError): 
            self.c.setName(name=False)
        with self.assertRaises(AssertionError): 
            self.c.setName(name=None)
        print(". done")
            
    def testEntity(self):
        print('\tTesting {} '.format(inspect.currentframe().f_code.co_name), end="")
        count = 0
        N = 4 + 4
        # Success scenarios
        for e_type in [PT.Alignment.EDOAL['CLASS'], PT.Alignment.EDOAL['RELN'], PT.Alignment.EDOAL['PROP'], PT.Alignment.EDOAL['INST']]:
            count += 1
            # Success scenarios, QName with prefix
            testEnt = PT._Entity(entity_iri="med:appelepap", entity_type=e_type, nsMgr=self.nsMgr)
            exp_iri = "<http://ds.tno.nl/mediator/1.0/appelepap>"
            assert testEnt.getIriRef() == exp_iri, "Testfault: got '{}', expected '{}'.".format(testEnt.getIriRef(), exp_iri)
            assert testEnt.getType() == e_type, "Testfault: got '{}', expected '{}'.".format(testEnt.getType(), e_type)
            # Success scenarios, QName without prefix
            testEnt = PT._Entity(entity_iri=":appelepap", entity_type=e_type, nsMgr=self.nsMgr)
            exp_iri = "<" + self.base + "appelepap>"
            assert testEnt.getIriRef() == exp_iri and testEnt.getType() == e_type
            # Success scenarios, with correct IRI
            testEnt = PT._Entity(entity_iri="http://www.w3.org/TR/2003/CR-owl-guide-20030818/wine#VintageYear", entity_type=e_type, nsMgr=self.nsMgr)
            exp_iri = "<http://www.w3.org/TR/2003/CR-owl-guide-20030818/wine#VintageYear>"
            assert testEnt.getIriRef() == exp_iri, "Testfault: got '{}', expected '{}'.".format(testEnt.getIriRef(), exp_iri)
            assert testEnt.getType() == e_type, "Testfault: got '{}', expected '{}'.".format(testEnt.getType(), e_type)
            # Success scenarios, with correct <IRI>
            testEnt = PT._Entity(entity_iri="<http://www.w3.org/TR/2003/CR-owl-guide-20030818/wine#VintageYear>", entity_type=e_type, nsMgr=self.nsMgr)
            exp_iri = "<http://www.w3.org/TR/2003/CR-owl-guide-20030818/wine#VintageYear>"
            assert testEnt.getIriRef() == exp_iri, "Testfault: got '{}', expected '{}'.".format(testEnt.getIriRef(), exp_iri)
            assert testEnt.getType() == e_type, "Testfault: got '{}', expected '{}'.".format(testEnt.getType(), e_type)
            # Success scenarios, with correct Clark's notation
            testEnt = PT._Entity(entity_iri="{http://www.w3.org/TR/2003/CR-owl-guide-20030818/wine#}VintageYear", entity_type=e_type, nsMgr=self.nsMgr)
            exp_iri = "<http://www.w3.org/TR/2003/CR-owl-guide-20030818/wine#VintageYear>"
            assert testEnt.getIriRef() == exp_iri, "Testfault: got '{}', expected '{}'.".format(testEnt.getIriRef(), exp_iri)
            assert testEnt.getType() == e_type, "Testfault: expected '{}', got '{}'.".format(testEnt.getType(), e_type)
            print(".", end="")
        # Failure scenarios
        for e_type in [PT.Alignment.EDOAL['CLASS'], PT.Alignment.EDOAL['RELN'], PT.Alignment.EDOAL['PROP'], PT.Alignment.EDOAL['INST']]:
            count += 1
            with self.assertRaises(RuntimeError): 
                testEnt = PT._Entity(entity_iri=":^_invalidIriChar", entity_type=e_type, nsMgr=self.nsMgr)
            with self.assertRaises(RuntimeError): 
                testEnt = PT._Entity(entity_iri=":!_invalidIriChar", entity_type=e_type, nsMgr=self.nsMgr)
            with self.assertRaises(RuntimeError): 
                testEnt = PT._Entity(entity_iri="^_invalidIriChar", entity_type=e_type, nsMgr=self.nsMgr)
            with self.assertRaises(AssertionError): 
                testEnt = PT._Entity(entity_iri="", entity_type=e_type, nsMgr=self.nsMgr)
            with self.assertRaises(RuntimeError): 
                testEnt = PT._Entity(entity_iri="unknownPF:appelepap", entity_type=e_type, nsMgr=self.nsMgr)
            with self.assertRaises(RuntimeError): 
                testEnt = PT._Entity(entity_iri="noPFOrAnythingWhatsoever", entity_type=e_type, nsMgr=self.nsMgr)
            with self.assertRaises(AssertionError): 
                testEnt = PT._Entity(entity_iri=12, entity_type=e_type, nsMgr=self.nsMgr)
            with self.assertRaises(AssertionError): 
                testEnt = PT._Entity(entity_iri=12.3, entity_type=e_type, nsMgr=self.nsMgr)
            with self.assertRaises(AssertionError): 
                testEnt = PT._Entity(entity_iri=True, entity_type=e_type, nsMgr=self.nsMgr)
            with self.assertRaises(AssertionError): 
                testEnt = PT._Entity(entity_iri=False, entity_type=e_type, nsMgr=self.nsMgr)
            with self.assertRaises(AssertionError): 
                testEnt = PT._Entity(entity_iri=None, entity_type=e_type, nsMgr=self.nsMgr)
            print(".", end="")
        assert count == N, "Didn't test everything, expected {} tests, done only {}".format(N, count)
        print(". done")

    def testConstruction(self):
        print('\tTesting {} '.format(inspect.currentframe().f_code.co_name), end="")
        count = 0
        N = 3 + 3 * 3 + 4 + 4
        # Mixed success and failure scenarios
        for e_type1 in [PT.Alignment.EDOAL['CLASS'], PT.Alignment.EDOAL['RELN'], PT.Alignment.EDOAL['PROP']]:
            count += 1
            testEnt1 = PT._Entity(entity_iri="med:appelepap", entity_type=e_type1, nsMgr=self.nsMgr)
            # Success scenario - unary operation
            constr = PT.Neg(testEnt1)
            assert constr.getCType() == PT._EntityConstruction.NOTSYMBOL, "Testfault: expected '{}', got '{}'.".format(PT._EntityConstruction.NOTSYMBOL, constr.getCType())
            print(".", end="")
            # Binary operation scenarios
            for e_type2 in [PT.Alignment.EDOAL['CLASS'], PT.Alignment.EDOAL['RELN'], PT.Alignment.EDOAL['PROP']]:
                testEnt2 = PT._Entity(entity_iri="med:appelepap", entity_type=e_type2, nsMgr=self.nsMgr)
                if e_type1 == e_type2:
                    # Success scenario - binary operations
                    count += 1
                    constr = PT.Union(testEnt1, testEnt2)
                    assert constr.getCType() == PT._EntityConstruction.SQRUNION, "Testfault: expected '{}', got '{}'.".format(PT._EntityConstruction.SQRUNION, constr.getCType())
                    constr = PT.Intersection(testEnt1, testEnt2)
                    assert constr.getCType() == PT._EntityConstruction.SQRINTSCT, "Testfault: expected '{}', got '{}'.".format(PT._EntityConstruction.SQRINTSCT, constr.getCType())
                    print(".", end="")
                else: 
                    # Failure scenario - binary operations
                    count += 1
                    with self.assertRaises(AssertionError): 
                        constr = PT.Union(testEnt1, testEnt2)
                    print(".", end="")
        # Failure scenarios
        testEnt1 = PT._Entity(entity_iri="med:appelepap", entity_type=PT.Alignment.EDOAL['INST'], nsMgr=self.nsMgr)
        for e_type in [PT.Alignment.EDOAL['CLASS'], PT.Alignment.EDOAL['RELN'], PT.Alignment.EDOAL['PROP'], PT.Alignment.EDOAL['INST']]:
            count += 1
            testEnt2 = PT._Entity(entity_iri="med:appelepap", entity_type=e_type, nsMgr=self.nsMgr)
            with self.assertRaises(AssertionError): 
                constr = PT.Union(testEnt1, testEnt2)
            print(".", end="")
        testEnt2 = PT._Entity(entity_iri="med:appelepap", entity_type=PT.Alignment.EDOAL['INST'], nsMgr=self.nsMgr)
        for e_type in [PT.Alignment.EDOAL['CLASS'], PT.Alignment.EDOAL['RELN'], PT.Alignment.EDOAL['PROP'], PT.Alignment.EDOAL['INST']]:
            count += 1
            testEnt1 = PT._Entity(entity_iri="med:appelepap", entity_type=e_type, nsMgr=self.nsMgr)
            with self.assertRaises(AssertionError): 
                constr = PT.Union(testEnt1, testEnt2)
            print(".", end="")
        assert count == N, "Didn't test everything, expected {} tests, done only {}".format(N, count)
        print(". done")

    def testSetSrcEE(self):
        print('\tTesting {} '.format(inspect.currentframe().f_code.co_name), end="")
        count = 0
        N = 4 * 4 + 3 * 4 + 4
        # Success scenarios; entity_expr of type _Entity
        for e_type in [PT.Alignment.EDOAL['CLASS'], PT.Alignment.EDOAL['RELN'], PT.Alignment.EDOAL['PROP'], PT.Alignment.EDOAL['INST']]:
            for test_iri in ["med:appelepap", ":appelepap", "http://www.w3.org/TR/2003/CR-owl-guide-20030818/wine#VintageYear", "{http://www.w3.org/TR/2003/CR-owl-guide-20030818/wine#}VintageYear"]:
                count += 1
                testEnt = PT._Entity(entity_iri=test_iri, entity_type=e_type, nsMgr=self.nsMgr)
                self.c.setEE1(entity_expr=testEnt)
                assert self.c.getEE1().getIriRef() == self.nsMgr.asIRI(test_iri), "Testfault: got '{}', expected '{}'.".format(self.c.getEE1().getIriRef(), self.nsMgr.asIRI(test_iri))
                assert self.c.getEE1().getType() == e_type, "Testfault: got '{}', expected '{}'.".format(self.c.getEE1().getType(), e_type)
                print(".", end="")
                if e_type != PT.Alignment.EDOAL['INST']:
                    count += 1
                    # Success scenarios; entity_expr of type _EntityConstruction
                    testEnt2 = PT._Entity(entity_iri="med:perenmoes", entity_type=e_type, nsMgr=self.nsMgr)
                    constr = PT.Union(testEnt, testEnt2)
                    self.c.setEE1(entity_expr=constr)
                    assert self.c.getEE1().getCType() == PT._EntityConstruction.SQRUNION, "Testfault: got '{}', expected '{}'.".format(self.c.getEE1().getCType(), PT._EntityConstruction.SQRUNION)
                    assert self.c.getEE1().getEntType() == e_type, "Testfault: got '{}', expected '{}'.".format(self.c.getEE1().getEntType(), e_type)
                    assert self.c.getEE1().getEntities()[0] == testEnt, "Testfault: got '{}', expected '{}'.".format(self.c.getEE1().getEntities()[0], testEnt)
                    assert self.c.getEE1().getEntities()[1] == testEnt2, "Testfault: got '{}', expected '{}'.".format(self.c.getEE1().getEntities()[1], testEnt2)
                    constr = PT.Intersection(testEnt, testEnt2)
                    self.c.setEE1(entity_expr=constr)
                    assert self.c.getEE1().getCType() == PT._EntityConstruction.SQRINTSCT, "Testfault: got '{}', expected '{}'.".format(self.c.getEE1().getCType(), PT._EntityConstruction.SQRINTSCT)
                    assert self.c.getEE1().getEntType() == e_type, "Testfault: got '{}', expected '{}'.".format(self.c.getEE1().getEntType(), e_type)
                    assert self.c.getEE1().getEntities()[0] == testEnt, "Testfault: got '{}', expected '{}'.".format(self.c.getEE1().getEntities()[0], testEnt)
                    assert self.c.getEE1().getEntities()[1] == testEnt2, "Testfault: got '{}', expected '{}'.".format(self.c.getEE1().getEntities()[1], testEnt2)
                    print(".", end="")
        # Failure scenarios
        for e_type in [PT.Alignment.EDOAL['CLASS'], PT.Alignment.EDOAL['RELN'], PT.Alignment.EDOAL['PROP'], PT.Alignment.EDOAL['INST']]:
            count += 1
            with self.assertRaises(AssertionError): 
                self.c.setEE1(entity_expr="wrong type")
            with self.assertRaises(AssertionError): 
                self.c.setEE1(entity_expr=12)
            with self.assertRaises(AssertionError): 
                self.c.setEE1(entity_expr=12.3)
            with self.assertRaises(AssertionError): 
                self.c.setEE1(entity_expr=True)
            with self.assertRaises(AssertionError): 
                self.c.setEE1(entity_expr=None)
            print(".", end="")
        assert count == N, "Didn't test everything, expected {} tests, done only {}".format(N, count)
        print(". done")

    def testSetTgtEE(self):
        print('\tTesting {} '.format(inspect.currentframe().f_code.co_name), end="")
        count = 0
        N = 4 * 4 + 3 * 4 + 4
        # Success scenarios; entity_expr of type _Entity
        for e_type in [PT.Alignment.EDOAL['CLASS'], PT.Alignment.EDOAL['RELN'], PT.Alignment.EDOAL['PROP'], PT.Alignment.EDOAL['INST']]:
            for test_iri in ["med:appelepap", ":appelepap", "http://www.w3.org/TR/2003/CR-owl-guide-20030818/wine#VintageYear", "{http://www.w3.org/TR/2003/CR-owl-guide-20030818/wine#}VintageYear"]:
                count += 1
                testEnt = PT._Entity(entity_iri=test_iri, entity_type=e_type, nsMgr=self.nsMgr)
                self.c.setEE2(entity_expr=testEnt)
                assert self.c.getEE2().getIriRef() == self.nsMgr.asIRI(test_iri), "Testfault: got '{}', expected '{}'.".format(self.c.getEE2().getIriRef(), self.nsMgr.asIRI(test_iri))
                assert self.c.getEE2().getType() == e_type, "Testfault: got '{}', expected '{}'.".format(self.c.getEE2().getType(), e_type)
                print(".", end="")
                if e_type != PT.Alignment.EDOAL['INST']:
                    # Success scenarios; entity_expr of type _EntityConstruction
                    count += 1
                    testEnt2 = PT._Entity(entity_iri="med:perenmoes", entity_type=e_type, nsMgr=self.nsMgr)
                    constr = PT.Union(testEnt, testEnt2)
                    self.c.setEE2(entity_expr=constr)
                    assert self.c.getEE2().getCType() == PT._EntityConstruction.SQRUNION, "Testfault: got '{}', expected '{}'.".format(self.c.getEE2().getCType(), PT._EntityConstruction.SQRUNION)
                    assert self.c.getEE2().getEntType() == e_type, "Testfault: got '{}', expected '{}'.".format(self.c.getEE2().getEntType(), e_type)
                    assert self.c.getEE2().getEntities()[0] == testEnt, "Testfault: got '{}', expected '{}'.".format(self.c.getEE2().getEntities()[0], testEnt)
                    assert self.c.getEE2().getEntities()[1] == testEnt2, "Testfault: got '{}', expected '{}'.".format(self.c.getEE2().getEntities()[1], testEnt2)
                    constr = PT.Intersection(testEnt, testEnt2)
                    self.c.setEE2(entity_expr=constr)
                    assert self.c.getEE2().getCType() == PT._EntityConstruction.SQRINTSCT, "Testfault: got '{}', expected '{}'.".format(self.c.getEE2().getCType(), PT._EntityConstruction.SQRINTSCT)
                    assert self.c.getEE2().getEntType() == e_type, "Testfault: got '{}', expected '{}'.".format(self.c.getEE2().getEntType(), e_type)
                    assert self.c.getEE2().getEntities()[0] == testEnt, "Testfault: got '{}', expected '{}'.".format(self.c.getEE2().getEntities()[0], testEnt)
                    assert self.c.getEE2().getEntities()[1] == testEnt2, "Testfault: got '{}', expected '{}'.".format(self.c.getEE2().getEntities()[1], testEnt2)
                    print(".", end="")
        # Failure scenarios
        for e_type in [PT.Alignment.EDOAL['CLASS'], PT.Alignment.EDOAL['RELN'], PT.Alignment.EDOAL['PROP'], PT.Alignment.EDOAL['INST']]:
            count += 1
            with self.assertRaises(AssertionError): 
                self.c.setEE2(entity_expr="wrong type")
            with self.assertRaises(AssertionError): 
                self.c.setEE2(entity_expr=12)
            with self.assertRaises(AssertionError): 
                self.c.setEE2(entity_expr=12.3)
            with self.assertRaises(AssertionError): 
                self.c.setEE2(entity_expr=True)
            with self.assertRaises(AssertionError): 
                self.c.setEE2(entity_expr=None)
            print(".", end="")
        assert count == N, "Didn't test everything, expected {} tests, done only {}".format(N, count)
        print(". done")

    def testSetCorrRelation(self):
        print('\tTesting {} '.format(inspect.currentframe().f_code.co_name), end="")
        count = 0
        N = 5 
        # Success scenarios
        for rel in [PT.MEDRELEQ, PT.MEDRELSUB, PT.MEDRELSUP, PT.MEDRELIN, PT.MEDRELNI]:
            count += 1
            self.c.setCorrRelation(relation=rel)
            assert self.c.getCorrRelation() == rel
            print(".", end="")
        # Failure scenarios
        with self.assertRaises(AssertionError): 
            self.c.setCorrRelation(relation=None)
        with self.assertRaises(AssertionError): 
            self.c.setCorrRelation(relation=12)
        with self.assertRaises(AssertionError): 
            self.c.setCorrRelation(relation="appelepap")
        with self.assertRaises(AssertionError): 
            self.c.setCorrRelation(relation=True)
        with self.assertRaises(AssertionError): 
            self.c.setCorrRelation(relation=False)
        assert count == N, "Didn't test everything, expected {} tests, done only {}".format(N, count)
        print(". done")

    def testSetCorrMeasure(self):
        print('\tTesting {} '.format(inspect.currentframe().f_code.co_name), end="")
        count = 0
        N = 6 + 8
        # Success scenarios
        for val, tpe in [(0.01, self.nsMgr.asIRI('xsd:float')), ('medium', self.nsMgr.asIRI('xsd:string')), (0.0, self.nsMgr.asIRI('xsd:double')), (1.0, self.nsMgr.asIRI('xsd:float')), (0, self.nsMgr.asIRI('xsd:decimal')), (1, self.nsMgr.asIRI('xsd:integer'))]:
            count += 1
            self.c.setCorrMeasure(measure=val, measure_type=tpe)
            assert (val, tpe) == self.c.getCorrMeasure()
            print(".", end="")
        # Failure scenarios - no check exist yet for incoherence between measure and measure_type, e.g., (0.42, xsd:integer), or ('appelepap', xsd:float)
        for val, tpe in [(0.01, ''), (None, self.nsMgr.asIRI('xsd:float')), (None, None), ('', None), (None, ''), ('', ''), (-0.1, self.nsMgr.asIRI('xsd:float')), (12, self.nsMgr.asIRI('xsd:integer'))]:
            count += 1
            with self.assertRaises(AssertionError): 
                self.c.setCorrMeasure(measure=val, measure_type=tpe)
            print(".", end="")
        assert count == N, "Didn't test everything, expected {} tests, done only {}".format(N, count)
        print(". done")
예제 #8
0
    def setUp(self):
#         from mediator.EDOALparser import Alignment
        ns = {'rdf'  : "http://www.w3.org/1999/02/22-rdf-syntax-ns#",
              'xsd'  : "http://www.w3.org/2001/XMLSchema#",
              'align':"http://knowledgeweb.semanticweb.org/heterogeneity/alignment#",
              'dc'   : 'http://purl.org/dc/elements/1.1/',
              'edoal':'http://ns.inria.org/edoal/1.0/#',
              'alext': 'http://exmo.inrialpes.fr/align/ext/1.0/',
              'medtfn': 'http://ts.tno.nl/mediator/1.0/transformations#',
              't'    : 'http://ts.tno.nl/mediator/test#'
              }
        self.nsMgr = NSManager(ns, "http://knowledgeweb.semanticweb.org/heterogeneity/alignment#")
        print(str(self.nsMgr))
        self.testCases = {}
        # Edoal parsing tests
        '''
        The admin tests will check the edoal Alignment element (refer to http://alignapi.gforge.inria.fr/format.html), however, restricted to:
        * <xml>: (value: "yes"/"no") indicates if the alignment can be read as an XML file compliant with the DTD;
        * <level>: (values: "0", "1", "2EDOAL") the level of alignment, characterising its type;
        * <type>: (values: "11"/"1?"/"1+"/"1*"/"?1"/"??"/"?+"/"?*"/"+1"/"+?"/"++"/"+*"/"*1"/"*?"/"?+"/"**"; default "11") 
            This represents the arity of alignment. Usual notations are 1:1, 1:m, n:1 or n:m. We prefer to note if the mapping is injective, 
            surjective and total, or partial on both sides. We then end up with more alignment arities:
            . 1 for injective and total, 
            . ? for injective, 
            . + for total and 
            . * for none
            and each sign concerning one mapping and its converse;
        * <onto1> and <onto2>: (value: Ontology) the source and target ontologies that are being aligned;
        '''
        
        self.testCases['ADMIN'] = []
        self.testCases['ADMIN'].append(
            { 
            'pass': {'resources/alignPassSimple0.xml':  # Simple Class-EQ-Class, Prop-EQ-Prop, Reln-EQ-Reln
                      {'about': 'http://ds.tno.nl/ontoA-ontoB/CPR-EQ-CPR',
                       'admin': ['yes', 'PaulBrandt', '2015/08/25', 'manual', 'TEST DATA (simple alignments)', '2EDOAL', '?*'],
                       'ontoS': ["<http://tutorial.topbraid.com/ontoA#>", None, "<http://www.w3.org/2002/07/owl#>", "OWL1.0"],
                       'ontoT': ["<http://tutorial.topbraid.com/ontoB#>", "resources/nl/test1/ontoB.xml", "<http://www.w3.org/2002/07/owl#>", "OWL1.0"]
                       },
                     'resources/wine_align.xml':  # Simple Class-EQ-Class, Prop-EQ-Prop, Reln-LT-Reln,
                      {'about': 'http://oms.omwg.org/wine-vin/',  #   & one SmplSrcCls-EQ-CmplxTgtCls, one CmpxlSrcCls-LT-CmplxTgtCls
                       'admin': ['yes', 'http://www.scharffe.fr/foaf.rdf', '2006/06/07', 'manual', 'TESTcase: hugely adapted from original wine-vin example', '2EDOAL', '**'],
                       'ontoS': ["<http://www.w3.org/TR/2003/CR-owl-guide-20030818/wine#>", None, "<http://www.w3.org/TR/owl-guide/>", "owl"],
                       'ontoT': ["<http://ontology.deri.org/vin#>", "http://www.scharffe.fr/ontologies/OntologieDuVin.wsml", "<http://www.wsmo.org/wsml/wsml-syntax/wsml-dl>", "wsml"]
                    }
                },
            'fail': 
                [
                    ['resources/alignFail0A.xml', RuntimeError],  # Missing <Alignment> element
                    ['resources/alignFail0B.xml', ValueError],  # Missing 'alignET:about="somename"' in <Alignment > element
                    ['resources/alignFail1A.xml', NotImplementedError],  # Incorrect value for <Level> element: 2EDOAL expected
                    ['resources/alignFail1B.xml', RuntimeError],  # Missing <Level> element 
                    ['resources/alignFail2A.xml', RuntimeError],  # Missing <type> element 
                    ['resources/alignFail2B.xml', ValueError],  # Illegal value for <Level> element 
                    ['', AssertionError],  # Missing file name 
                    ['resources/missingAlignFile.xml', AssertionError],  # Illegal file name 
                ]
            }
        )
        
        '''
        The Correspondence tests will check the edoal set of correspondences (the <Cell> elements; refer to http://alignapi.gforge.inria.fr/edoal.html), however, restricted to:
        * <Cell {rdf:about=" URI "} /> 
        *     <entity1> entity </entity1> 
        *     <entity2> entity </entity2> 
        *     <relation> STRING </relation> 
        *     <measure> STRING </measure>
        These are all required elements
        '''
        
        self.testCases['CORR'] = []
        self.testCases['CORR'].append(
            { 
            'pass': {
                'resources/alignPassSimple0.xml': {  # Simple Class-EQ-Class, Prop-EQ-Prop, Reln-EQ-Reln
                    'corrs': [
                        {
                            'name' : "MappingRule_0",
                            'ent1' : {'et': Alignment.EDOAL['CLASS'], 'eir' : "<http://tutorial.topbraid.com/ontoA#unEquivanox>"},
                            'ent2' : {'et': Alignment.EDOAL['CLASS'], 'eir' : "<http://tutorial.topbraid.com/ontoB#OneEq>"},
                            'msre' : 1.0,
                            'reln' : 'EQ'
                        }, {
                            'name' : "MappingRule_1",
                            'ent1' : {'et': Alignment.EDOAL['PROP'], 'eir' : "<http://tutorial.topbraid.com/ontoA#unEquivanox>"},
                            'ent2' : {'et': Alignment.EDOAL['PROP'], 'eir' : "<http://tutorial.topbraid.com/ontoB#OneEq>"},
                            'msre' : 1.0,
                            'reln' : 'EQ'
                         }, {
                            'name' : "MappingRule_2",
                            'ent1' : {'et': Alignment.EDOAL['RELN'], 'eir' : "<http://tutorial.topbraid.com/ontoA#unEquivanox>"},
                            'ent2' : {'et': Alignment.EDOAL['RELN'], 'eir' : "<http://tutorial.topbraid.com/ontoB#OneEq>"},
                            'msre' : 1.0,
                            'reln' : 'EQ'
                        }, {
                            'name' : "MappingRule_3",
                            'ent1' : {'et': Alignment.EDOAL['INST'], 'eir' : "<http://tutorial.topbraid.com/ontoA#unEquivanox>"},
                            'ent2' : {'et': Alignment.EDOAL['INST'], 'eir' : "<http://tutorial.topbraid.com/ontoB#OneEq>"},
                            'msre' : 1.0,
                            'reln' : 'EQ'
                        }
                    ]
                },
                'resources/wine_align.xml': {  # Simple Class-EQ-Class, Prop-EQ-Prop, Reln-LT-Reln,
                    'corrs': [
                        {
                            'name' : "MappingRule_0",
                            'ent1' : {'et': Alignment.EDOAL['CLASS'], 'eir' : "<http://www.w3.org/TR/2003/CR-owl-guide-20030818/wine#VintageYear>"},
                            'ent2' : {'et': Alignment.EDOAL['CLASS'], 'eir' : "<http://ontology.deri.org/vin#Millesime>"},
                            'msre' : 1.0,
                            'reln' : 'EQ'
                        }, {
                            'name' : "MappingRule_1",
                            'ent1' : {'et': Alignment.EDOAL['PROP'], 'eir' : "<http://www.w3.org/TR/2003/CR-owl-guide-20030818/wine#VintageYear>"},
                            'ent2' : {'et': Alignment.EDOAL['PROP'], 'eir' : "<http://ontology.deri.org/vin#Millesime>"},
                            'msre' : 1.0,
                            'reln' : 'EQ'
                        }, {
                            'name' : "MappingRule_2",
                            'ent1' : {'et': Alignment.EDOAL['RELN'], 'eir' : "<http://www.w3.org/TR/2003/CR-owl-guide-20030818/wine#VintageYear>"},
                            'ent2' : {'et': Alignment.EDOAL['RELN'], 'eir' : "<http://ontology.deri.org/vin#Millesime>"},
                            'msre' : 1.0,
                            'reln' : 'EQ'
                        }
                    ]
                }
            },
            'fail': {  # TODO: zet geen testdata in de edoal data, maar maak aparte 'fail'labels: 'AssertionErrors'
                    'resources/alignFail3A.xml': {
                        "MissingMap": RuntimeError},  # Missing <map><Cell>...</Cell></map> element 
                    'resources/alignFail3B.xml': {
                        "MissingCell": RuntimeError},  # Missing <Cell> element 
                    'resources/alignFail3C.xml': {
                        "MappingRule_0": AssertionError,  # Empty <Cell> element
                        "MappingRule_1": AssertionError,  # Missing <entity1> element
                        "MappingRule_11": AssertionError,  # Multiple <entity1> element 
                        "MappingRule_12": AssertionError,  # Non-empty simple <class> element 
                        "MappingRule_13": AssertionError,  # Non-empty simple <property> element 
                        "MappingRule_14": AssertionError,  # Non-empty simple <relation> element 
                        "MappingRule_15": AssertionError,  # Non-empty simple <class> element 
                        "MappingRule_16": AssertionError,  # Non-empty simple <property> element
                        "MappingRule_17": AssertionError,  # Non-empty simple <relation> element
                        "MappingRule_2": AssertionError,  # Missing <entity2> element
                        "MappingRule_21": AssertionError,  # Multiple <entity2> element 
                        "MappingRule_3": RuntimeError,  # Missing <relation> element 
                        "MappingRule_31": RuntimeError,  # Multiple <relation> element 
                        "MappingRule_32": RuntimeError,  # Illegal <relation> element 
                        "MappingRule_4": RuntimeError,  # Missing <measure> element 
                        "MappingRule_41": RuntimeError,  # Multiple <measure> element
                        "MappingRule_42": RuntimeError,  # Missing About attribute in <measure> element 
                        "MappingRule_5": AssertionError,  # Missing About attribute in empty EDOAL element 
                        "MappingRule_6": AssertionError,  # Empty <entity> element 
                        "MappingRule_7": AssertionError,  # Unknown entity element in entity 
                        "MappingRule_8": AssertionError  # Unknown cell element in entity 
                    }
                }
            }
        )
        
        '''
        A Value expression is a rather central element in the EDAOL alginment. Therefore we designed a separate test for it.
        BNF definition is (refer to http://alignapi.gforge.inria.fr/edoal.html):
        <value> value </value>
        value ::= <Literal {edoal:type=" URI "} edoal:string=" STRING " />
                | instexpr 
                | attrexpr 
                | <Apply edoal:operator=" URI "> <arguments rdf:parseType="Collection">value*</arguments> </Apply> 
                | <Aggregate edoal:operator=" URI "> <arguments rdf:parseType="Collection">value*</arguments> </Aggregate>
        
        instexpr ::= <Instance rdf:about=" URI "/>
        attexpr ::= propexpr | relexpr
        '''
        self.testCases['VALUE'] = []
        self.testCases['VALUE'].append(
            {
            'pass': {
                # The LiteralPass1 tests are all <Literal>'s, but not all possible literal values/xsd:valuetype's have been specified and hence, tested
                'resources/valueSimplePass1.xml': {
                    'valueLiteralePass1A': {
                        'valueType': 'edoal:Literal',
                        'value': 'appelepap',
                        'type': '<http://www.w3.org/2001/XMLSchema#string>'
                        },
                    'valueLiteralePass1B': {
                        'valueType': 'edoal:Literal',
                        'value': '123',
                        'type': '<http://www.w3.org/2001/XMLSchema#integer>'
                        },
                    'valueLiteralePass1C': {
                        'valueType': 'edoal:Literal',
                        'value': '1.23',
                        'type': '<http://www.w3.org/2001/XMLSchema#float>'
                        },
                    'valueInstancePass1': {
                        'valueType': 'edoal:Instance',
                        'value': '<http://ts.tno.nl/mediator/1.0/appelepap>'
                        },
                    'valuePropertyPass1A': {
                        'valueType': 'edoal:Property',
                        'value': '<http://ts.tno.nl/mediator/1.0/appelepap>',
                        'lang': None
                        },
                    'valuePropertyPass1B': {
                        'valueType': 'edoal:Property',
                        'value': '<http://ts.tno.nl/mediator/1.0/appelepap>',
                        'lang': 'NL'
                        },
                    'valueRelationPass1': {
                        'valueType': 'edoal:Relation',
                        'value': '<http://ts.tno.nl/mediator/1.0/appelepap>'
                        }
                    },
                'resources/valueSimplePass2.xml': {
                    'valueLiteralePass2A': {
                        'valueType': 'edoal:Apply',
                        'value': 'transformations.unitconversion/CtoF',
                        'type': '<http://ns.inria.org/edoal/1.0/#apply>'
                        },
                    'valueLiteralePass2B': {
                        'valueType': 'edoal:Apply',
                        'value': 'transformations.unitconversion/TempConvertor',
                        'type': '<http://ns.inria.org/edoal/1.0/#apply>'
                        }
                    },
                'resources/valuePathPass1.xml': {
                    'valuePathPass1A': {
                        'valueType': 'edoal:compose',
                        'value': ['<http://ts.tno.nl/mediator/1.0/example#hasProperty> ({http://ns.inria.org/edoal/1.0/#}property)'],
                        'type': Alignment.EDOAL['PROP']
                        },
                    'valuePathPass1B': {
                        'valueType': 'edoal:compose',
                        'value': ['<http://ts.tno.nl/mediator/1.0/example#hasRelation> ({http://ns.inria.org/edoal/1.0/#}relation)', '<http://ts.tno.nl/mediator/1.0/example#hasProperty> ({http://ns.inria.org/edoal/1.0/#}property)'],
                        'type': Alignment.EDOAL['PROP']
                        },
                    'valuePathPass1C': {
                        'valueType': 'edoal:compose',
                        'value': ['<http://ts.tno.nl/mediator/1.0/example#hasRelation> ({http://ns.inria.org/edoal/1.0/#}relation)'],
                        'type': Alignment.EDOAL['RELN']
                        },
                    'valuePathPass1D': {
                        'valueType': 'edoal:compose',
                        'value': [],
                        'type': Alignment.EDOAL['PROP']
                        },
                    'valuePathPass1E': {
                        'valueType': 'edoal:compose',
                        'value': [],
                        'type': Alignment.EDOAL['RELN']
                        },
                    'valuePathPass1F': {
                        'valueType': 'edoal:compose',
                        'value': ['<http://ts.tno.nl/mediator/1.0/example#hasRelation1> ({http://ns.inria.org/edoal/1.0/#}relation)', '<http://ts.tno.nl/mediator/1.0/example#hasRelation2> ({http://ns.inria.org/edoal/1.0/#}relation)', '<http://ts.tno.nl/mediator/1.0/example#hasProperty> ({http://ns.inria.org/edoal/1.0/#}property)'],
                        'type': Alignment.EDOAL['PROP']
                        }
                    }
                },
            'fail': {
                # The LiteralFail1 tests are all <Literal>'s, but not all possible literal values/xsd:valuetype's tested
                'resources/valueSimpleFail1.xml': { 
                    'FailEmpty1'   : AssertionError,  # Empty <entity> element
                    'FailLiteral1' : AssertionError,  # Missing edoal:string attribute in <edoal:Literal\>
                    'FailLiteral2' : AssertionError,  # Literal is always a single, empty element with its value in the attributes 
                    'FailInstance1': AssertionError,  # Missing rdf:about attribute in <edoal:Instance\>
                    'FailInstance2': AssertionError,  # Empty rdf:about attribute in element
                    'FailInstance3': AssertionError,  # Incorrect attribute in element
                    'FailInstance4': AssertionError,  # Not an empty element
                    'FailProperty1': AssertionError,  # Empty about attribute, empty Lang attribute
                    'FailProperty2': AssertionError,  # Missing about attribute, empty Lang attribute
                    'FailProperty3': AssertionError,  # Empty about attribute, missing Lang attribute 
                    'FailProperty4': AssertionError,  # Missing about attribute, missing Lang attribute
                    'FailProperty5': AssertionError,  # Empty about attribute, valid Lang attribute
                    'FailProperty6': AssertionError,  # Missing about attribute, valid Lang attribute
                    'FailRelation1': AssertionError,  # Empty about attribute
                    'FailRelation2': AssertionError,  # Missing about attribute 
                    'FailRelation3': AssertionError  # Valid attribute, invalid element (element is not empty) 
                    },
                'resources/valuePathFail1.xml': { 
                    'FailPathOfNonAttrExpr1'  : AssertionError,  # Instance path is illegal
                    'FailPathOfNonAttrExpr2'  : AssertionError,  # Literal path is illegal
                    'FailPathOfNonAttrExpr3'  : AssertionError,  # Class path is illegal 
                    'FailPathWithNonAttrExpr1': AssertionError,  # Property Path containing Instance is illegal
                    'FailPathWithNonAttrExpr2': AssertionError,  # Relation Path containing Literal is illegal
                    'FailPathWithNonAttrExpr3': AssertionError,  # Relation Path containing Class is illegal
                    'FailComplexPathNotImpl'  : NotImplementedError  # Correct path, but too complex to be implemented yet
                    }
                }
            } 
        )
예제 #9
0
class TestEDOALParser(unittest.TestCase):

    def setUp(self):
#         from mediator.EDOALparser import Alignment
        ns = {'rdf'  : "http://www.w3.org/1999/02/22-rdf-syntax-ns#",
              'xsd'  : "http://www.w3.org/2001/XMLSchema#",
              'align':"http://knowledgeweb.semanticweb.org/heterogeneity/alignment#",
              'dc'   : 'http://purl.org/dc/elements/1.1/',
              'edoal':'http://ns.inria.org/edoal/1.0/#',
              'alext': 'http://exmo.inrialpes.fr/align/ext/1.0/',
              'medtfn': 'http://ts.tno.nl/mediator/1.0/transformations#',
              't'    : 'http://ts.tno.nl/mediator/test#'
              }
        self.nsMgr = NSManager(ns, "http://knowledgeweb.semanticweb.org/heterogeneity/alignment#")
        print(str(self.nsMgr))
        self.testCases = {}
        # Edoal parsing tests
        '''
        The admin tests will check the edoal Alignment element (refer to http://alignapi.gforge.inria.fr/format.html), however, restricted to:
        * <xml>: (value: "yes"/"no") indicates if the alignment can be read as an XML file compliant with the DTD;
        * <level>: (values: "0", "1", "2EDOAL") the level of alignment, characterising its type;
        * <type>: (values: "11"/"1?"/"1+"/"1*"/"?1"/"??"/"?+"/"?*"/"+1"/"+?"/"++"/"+*"/"*1"/"*?"/"?+"/"**"; default "11") 
            This represents the arity of alignment. Usual notations are 1:1, 1:m, n:1 or n:m. We prefer to note if the mapping is injective, 
            surjective and total, or partial on both sides. We then end up with more alignment arities:
            . 1 for injective and total, 
            . ? for injective, 
            . + for total and 
            . * for none
            and each sign concerning one mapping and its converse;
        * <onto1> and <onto2>: (value: Ontology) the source and target ontologies that are being aligned;
        '''
        
        self.testCases['ADMIN'] = []
        self.testCases['ADMIN'].append(
            { 
            'pass': {'resources/alignPassSimple0.xml':  # Simple Class-EQ-Class, Prop-EQ-Prop, Reln-EQ-Reln
                      {'about': 'http://ds.tno.nl/ontoA-ontoB/CPR-EQ-CPR',
                       'admin': ['yes', 'PaulBrandt', '2015/08/25', 'manual', 'TEST DATA (simple alignments)', '2EDOAL', '?*'],
                       'ontoS': ["<http://tutorial.topbraid.com/ontoA#>", None, "<http://www.w3.org/2002/07/owl#>", "OWL1.0"],
                       'ontoT': ["<http://tutorial.topbraid.com/ontoB#>", "resources/nl/test1/ontoB.xml", "<http://www.w3.org/2002/07/owl#>", "OWL1.0"]
                       },
                     'resources/wine_align.xml':  # Simple Class-EQ-Class, Prop-EQ-Prop, Reln-LT-Reln,
                      {'about': 'http://oms.omwg.org/wine-vin/',  #   & one SmplSrcCls-EQ-CmplxTgtCls, one CmpxlSrcCls-LT-CmplxTgtCls
                       'admin': ['yes', 'http://www.scharffe.fr/foaf.rdf', '2006/06/07', 'manual', 'TESTcase: hugely adapted from original wine-vin example', '2EDOAL', '**'],
                       'ontoS': ["<http://www.w3.org/TR/2003/CR-owl-guide-20030818/wine#>", None, "<http://www.w3.org/TR/owl-guide/>", "owl"],
                       'ontoT': ["<http://ontology.deri.org/vin#>", "http://www.scharffe.fr/ontologies/OntologieDuVin.wsml", "<http://www.wsmo.org/wsml/wsml-syntax/wsml-dl>", "wsml"]
                    }
                },
            'fail': 
                [
                    ['resources/alignFail0A.xml', RuntimeError],  # Missing <Alignment> element
                    ['resources/alignFail0B.xml', ValueError],  # Missing 'alignET:about="somename"' in <Alignment > element
                    ['resources/alignFail1A.xml', NotImplementedError],  # Incorrect value for <Level> element: 2EDOAL expected
                    ['resources/alignFail1B.xml', RuntimeError],  # Missing <Level> element 
                    ['resources/alignFail2A.xml', RuntimeError],  # Missing <type> element 
                    ['resources/alignFail2B.xml', ValueError],  # Illegal value for <Level> element 
                    ['', AssertionError],  # Missing file name 
                    ['resources/missingAlignFile.xml', AssertionError],  # Illegal file name 
                ]
            }
        )
        
        '''
        The Correspondence tests will check the edoal set of correspondences (the <Cell> elements; refer to http://alignapi.gforge.inria.fr/edoal.html), however, restricted to:
        * <Cell {rdf:about=" URI "} /> 
        *     <entity1> entity </entity1> 
        *     <entity2> entity </entity2> 
        *     <relation> STRING </relation> 
        *     <measure> STRING </measure>
        These are all required elements
        '''
        
        self.testCases['CORR'] = []
        self.testCases['CORR'].append(
            { 
            'pass': {
                'resources/alignPassSimple0.xml': {  # Simple Class-EQ-Class, Prop-EQ-Prop, Reln-EQ-Reln
                    'corrs': [
                        {
                            'name' : "MappingRule_0",
                            'ent1' : {'et': Alignment.EDOAL['CLASS'], 'eir' : "<http://tutorial.topbraid.com/ontoA#unEquivanox>"},
                            'ent2' : {'et': Alignment.EDOAL['CLASS'], 'eir' : "<http://tutorial.topbraid.com/ontoB#OneEq>"},
                            'msre' : 1.0,
                            'reln' : 'EQ'
                        }, {
                            'name' : "MappingRule_1",
                            'ent1' : {'et': Alignment.EDOAL['PROP'], 'eir' : "<http://tutorial.topbraid.com/ontoA#unEquivanox>"},
                            'ent2' : {'et': Alignment.EDOAL['PROP'], 'eir' : "<http://tutorial.topbraid.com/ontoB#OneEq>"},
                            'msre' : 1.0,
                            'reln' : 'EQ'
                         }, {
                            'name' : "MappingRule_2",
                            'ent1' : {'et': Alignment.EDOAL['RELN'], 'eir' : "<http://tutorial.topbraid.com/ontoA#unEquivanox>"},
                            'ent2' : {'et': Alignment.EDOAL['RELN'], 'eir' : "<http://tutorial.topbraid.com/ontoB#OneEq>"},
                            'msre' : 1.0,
                            'reln' : 'EQ'
                        }, {
                            'name' : "MappingRule_3",
                            'ent1' : {'et': Alignment.EDOAL['INST'], 'eir' : "<http://tutorial.topbraid.com/ontoA#unEquivanox>"},
                            'ent2' : {'et': Alignment.EDOAL['INST'], 'eir' : "<http://tutorial.topbraid.com/ontoB#OneEq>"},
                            'msre' : 1.0,
                            'reln' : 'EQ'
                        }
                    ]
                },
                'resources/wine_align.xml': {  # Simple Class-EQ-Class, Prop-EQ-Prop, Reln-LT-Reln,
                    'corrs': [
                        {
                            'name' : "MappingRule_0",
                            'ent1' : {'et': Alignment.EDOAL['CLASS'], 'eir' : "<http://www.w3.org/TR/2003/CR-owl-guide-20030818/wine#VintageYear>"},
                            'ent2' : {'et': Alignment.EDOAL['CLASS'], 'eir' : "<http://ontology.deri.org/vin#Millesime>"},
                            'msre' : 1.0,
                            'reln' : 'EQ'
                        }, {
                            'name' : "MappingRule_1",
                            'ent1' : {'et': Alignment.EDOAL['PROP'], 'eir' : "<http://www.w3.org/TR/2003/CR-owl-guide-20030818/wine#VintageYear>"},
                            'ent2' : {'et': Alignment.EDOAL['PROP'], 'eir' : "<http://ontology.deri.org/vin#Millesime>"},
                            'msre' : 1.0,
                            'reln' : 'EQ'
                        }, {
                            'name' : "MappingRule_2",
                            'ent1' : {'et': Alignment.EDOAL['RELN'], 'eir' : "<http://www.w3.org/TR/2003/CR-owl-guide-20030818/wine#VintageYear>"},
                            'ent2' : {'et': Alignment.EDOAL['RELN'], 'eir' : "<http://ontology.deri.org/vin#Millesime>"},
                            'msre' : 1.0,
                            'reln' : 'EQ'
                        }
                    ]
                }
            },
            'fail': {  # TODO: zet geen testdata in de edoal data, maar maak aparte 'fail'labels: 'AssertionErrors'
                    'resources/alignFail3A.xml': {
                        "MissingMap": RuntimeError},  # Missing <map><Cell>...</Cell></map> element 
                    'resources/alignFail3B.xml': {
                        "MissingCell": RuntimeError},  # Missing <Cell> element 
                    'resources/alignFail3C.xml': {
                        "MappingRule_0": AssertionError,  # Empty <Cell> element
                        "MappingRule_1": AssertionError,  # Missing <entity1> element
                        "MappingRule_11": AssertionError,  # Multiple <entity1> element 
                        "MappingRule_12": AssertionError,  # Non-empty simple <class> element 
                        "MappingRule_13": AssertionError,  # Non-empty simple <property> element 
                        "MappingRule_14": AssertionError,  # Non-empty simple <relation> element 
                        "MappingRule_15": AssertionError,  # Non-empty simple <class> element 
                        "MappingRule_16": AssertionError,  # Non-empty simple <property> element
                        "MappingRule_17": AssertionError,  # Non-empty simple <relation> element
                        "MappingRule_2": AssertionError,  # Missing <entity2> element
                        "MappingRule_21": AssertionError,  # Multiple <entity2> element 
                        "MappingRule_3": RuntimeError,  # Missing <relation> element 
                        "MappingRule_31": RuntimeError,  # Multiple <relation> element 
                        "MappingRule_32": RuntimeError,  # Illegal <relation> element 
                        "MappingRule_4": RuntimeError,  # Missing <measure> element 
                        "MappingRule_41": RuntimeError,  # Multiple <measure> element
                        "MappingRule_42": RuntimeError,  # Missing About attribute in <measure> element 
                        "MappingRule_5": AssertionError,  # Missing About attribute in empty EDOAL element 
                        "MappingRule_6": AssertionError,  # Empty <entity> element 
                        "MappingRule_7": AssertionError,  # Unknown entity element in entity 
                        "MappingRule_8": AssertionError  # Unknown cell element in entity 
                    }
                }
            }
        )
        
        '''
        A Value expression is a rather central element in the EDAOL alginment. Therefore we designed a separate test for it.
        BNF definition is (refer to http://alignapi.gforge.inria.fr/edoal.html):
        <value> value </value>
        value ::= <Literal {edoal:type=" URI "} edoal:string=" STRING " />
                | instexpr 
                | attrexpr 
                | <Apply edoal:operator=" URI "> <arguments rdf:parseType="Collection">value*</arguments> </Apply> 
                | <Aggregate edoal:operator=" URI "> <arguments rdf:parseType="Collection">value*</arguments> </Aggregate>
        
        instexpr ::= <Instance rdf:about=" URI "/>
        attexpr ::= propexpr | relexpr
        '''
        self.testCases['VALUE'] = []
        self.testCases['VALUE'].append(
            {
            'pass': {
                # The LiteralPass1 tests are all <Literal>'s, but not all possible literal values/xsd:valuetype's have been specified and hence, tested
                'resources/valueSimplePass1.xml': {
                    'valueLiteralePass1A': {
                        'valueType': 'edoal:Literal',
                        'value': 'appelepap',
                        'type': '<http://www.w3.org/2001/XMLSchema#string>'
                        },
                    'valueLiteralePass1B': {
                        'valueType': 'edoal:Literal',
                        'value': '123',
                        'type': '<http://www.w3.org/2001/XMLSchema#integer>'
                        },
                    'valueLiteralePass1C': {
                        'valueType': 'edoal:Literal',
                        'value': '1.23',
                        'type': '<http://www.w3.org/2001/XMLSchema#float>'
                        },
                    'valueInstancePass1': {
                        'valueType': 'edoal:Instance',
                        'value': '<http://ts.tno.nl/mediator/1.0/appelepap>'
                        },
                    'valuePropertyPass1A': {
                        'valueType': 'edoal:Property',
                        'value': '<http://ts.tno.nl/mediator/1.0/appelepap>',
                        'lang': None
                        },
                    'valuePropertyPass1B': {
                        'valueType': 'edoal:Property',
                        'value': '<http://ts.tno.nl/mediator/1.0/appelepap>',
                        'lang': 'NL'
                        },
                    'valueRelationPass1': {
                        'valueType': 'edoal:Relation',
                        'value': '<http://ts.tno.nl/mediator/1.0/appelepap>'
                        }
                    },
                'resources/valueSimplePass2.xml': {
                    'valueLiteralePass2A': {
                        'valueType': 'edoal:Apply',
                        'value': 'transformations.unitconversion/CtoF',
                        'type': '<http://ns.inria.org/edoal/1.0/#apply>'
                        },
                    'valueLiteralePass2B': {
                        'valueType': 'edoal:Apply',
                        'value': 'transformations.unitconversion/TempConvertor',
                        'type': '<http://ns.inria.org/edoal/1.0/#apply>'
                        }
                    },
                'resources/valuePathPass1.xml': {
                    'valuePathPass1A': {
                        'valueType': 'edoal:compose',
                        'value': ['<http://ts.tno.nl/mediator/1.0/example#hasProperty> ({http://ns.inria.org/edoal/1.0/#}property)'],
                        'type': Alignment.EDOAL['PROP']
                        },
                    'valuePathPass1B': {
                        'valueType': 'edoal:compose',
                        'value': ['<http://ts.tno.nl/mediator/1.0/example#hasRelation> ({http://ns.inria.org/edoal/1.0/#}relation)', '<http://ts.tno.nl/mediator/1.0/example#hasProperty> ({http://ns.inria.org/edoal/1.0/#}property)'],
                        'type': Alignment.EDOAL['PROP']
                        },
                    'valuePathPass1C': {
                        'valueType': 'edoal:compose',
                        'value': ['<http://ts.tno.nl/mediator/1.0/example#hasRelation> ({http://ns.inria.org/edoal/1.0/#}relation)'],
                        'type': Alignment.EDOAL['RELN']
                        },
                    'valuePathPass1D': {
                        'valueType': 'edoal:compose',
                        'value': [],
                        'type': Alignment.EDOAL['PROP']
                        },
                    'valuePathPass1E': {
                        'valueType': 'edoal:compose',
                        'value': [],
                        'type': Alignment.EDOAL['RELN']
                        },
                    'valuePathPass1F': {
                        'valueType': 'edoal:compose',
                        'value': ['<http://ts.tno.nl/mediator/1.0/example#hasRelation1> ({http://ns.inria.org/edoal/1.0/#}relation)', '<http://ts.tno.nl/mediator/1.0/example#hasRelation2> ({http://ns.inria.org/edoal/1.0/#}relation)', '<http://ts.tno.nl/mediator/1.0/example#hasProperty> ({http://ns.inria.org/edoal/1.0/#}property)'],
                        'type': Alignment.EDOAL['PROP']
                        }
                    }
                },
            'fail': {
                # The LiteralFail1 tests are all <Literal>'s, but not all possible literal values/xsd:valuetype's tested
                'resources/valueSimpleFail1.xml': { 
                    'FailEmpty1'   : AssertionError,  # Empty <entity> element
                    'FailLiteral1' : AssertionError,  # Missing edoal:string attribute in <edoal:Literal\>
                    'FailLiteral2' : AssertionError,  # Literal is always a single, empty element with its value in the attributes 
                    'FailInstance1': AssertionError,  # Missing rdf:about attribute in <edoal:Instance\>
                    'FailInstance2': AssertionError,  # Empty rdf:about attribute in element
                    'FailInstance3': AssertionError,  # Incorrect attribute in element
                    'FailInstance4': AssertionError,  # Not an empty element
                    'FailProperty1': AssertionError,  # Empty about attribute, empty Lang attribute
                    'FailProperty2': AssertionError,  # Missing about attribute, empty Lang attribute
                    'FailProperty3': AssertionError,  # Empty about attribute, missing Lang attribute 
                    'FailProperty4': AssertionError,  # Missing about attribute, missing Lang attribute
                    'FailProperty5': AssertionError,  # Empty about attribute, valid Lang attribute
                    'FailProperty6': AssertionError,  # Missing about attribute, valid Lang attribute
                    'FailRelation1': AssertionError,  # Empty about attribute
                    'FailRelation2': AssertionError,  # Missing about attribute 
                    'FailRelation3': AssertionError  # Valid attribute, invalid element (element is not empty) 
                    },
                'resources/valuePathFail1.xml': { 
                    'FailPathOfNonAttrExpr1'  : AssertionError,  # Instance path is illegal
                    'FailPathOfNonAttrExpr2'  : AssertionError,  # Literal path is illegal
                    'FailPathOfNonAttrExpr3'  : AssertionError,  # Class path is illegal 
                    'FailPathWithNonAttrExpr1': AssertionError,  # Property Path containing Instance is illegal
                    'FailPathWithNonAttrExpr2': AssertionError,  # Relation Path containing Literal is illegal
                    'FailPathWithNonAttrExpr3': AssertionError,  # Relation Path containing Class is illegal
                    'FailComplexPathNotImpl'  : NotImplementedError  # Correct path, but too complex to be implemented yet
                    }
                }
            } 
        )

    def tearDown(self):
        pass

    def testParseEdoalAdmin(self):
        '''parsing admin block of edoal should instantiate Alignment Object with valid admin getters, 
        and raise exception on faulty or missing XML elements'''
#         from mediator.EDOALparser import Alignment
        info = True
        debug = 3
        rule = 'ADMIN'
        if info or debug >= 1:
            print()
            print('=-' * 7)
            print('EDOAL parser tests, {} part'.format(rule))
            print('=-' * 7)
        for t in self.testCases[rule]:
            if info:
                print('\ntesting', rule, 'with', len(t['pass']), 'pass case(s) and', len(t['fail']), 'fail case(s)')
            if debug >= 3:
                print('> pass cases:', t['pass'])
                print('> fail cases:', t['fail'])
                print()

            # PASS: Execute the test for each defined correspondence file that is expected to pass
            for p, crit in t['pass'].items():
                # Read and parse XML Alignment file 
                if debug >= 1:
                    print('testing pass case:', p)
                    if debug >= 3:
                        for k, v in crit.items():
                            print('\t{}: {}'.format(k, v))
                pa = Alignment(fn=p, nsMgr=self.nsMgr)
                # Validate the Administration part, i.e., the first elements in the Alignment.
                assert pa.getAbout() == crit['about'], 'Alignment attribute "{}" conflicts with expected value {}'.format(pa.about, crit['about'])
                assert pa.getCreator() == crit['admin'][1], 'Alignment attribute "{}" conflicts with expected value {}'.format(pa.getCreator(), crit['admin'][1])
                assert pa.getDate() == crit['admin'][2], 'Alignment attribute "{}" conflicts with expected value {}'.format(pa.getDate(), crit['admin'][2])
                assert pa.getMethod() == crit['admin'][3], 'Alignment attribute "{}" conflicts with expected value {}'.format(pa.getMethod(), crit['admin'][3])
                assert pa.getPurpose() == crit['admin'][4], 'Alignment attribute "{}" conflicts with expected value {}'.format(pa.getPurpose(), crit['admin'][4])
                assert pa.getLevel() == crit['admin'][5], 'Alignment attribute "{}" conflicts with expected value {}'.format(pa.getLevel(), crit['admin'][5])
                assert pa.getType() == crit['admin'][6], 'Alignment attribute "{}" conflicts with expected value {}'.format(pa.getType(), crit['admin'][6])
                # Validate the ontology references that are mentioned in the Alignment
                onto = pa.getSrcOnto()
                assert onto.name == crit['ontoS'][0], 'Alignment attribute "{}" conflicts with expected value {}'.format(onto.name, crit['ontoS'][0])
                assert onto.location == crit['ontoS'][1], 'Alignment attribute "{}" conflicts with expected value {}'.format(onto.location, crit['ontoS'][1])
                assert onto.formalism_uri == crit['ontoS'][2], 'Alignment attribute "{}" conflicts with expected value {}'.format(onto.formalism_uri, crit['ontoS'][2])
                assert onto.formalism_name == crit['ontoS'][3], 'Alignment attribute "{}" conflicts with expected value {}'.format(onto.formalism_name, crit['ontoS'][3])
                onto = pa.getTgtOnto()
                assert onto.name == crit['ontoT'][0], 'Alignment attribute "{}" conflicts with expected value {}'.format(onto.name, crit['ontoT'][0])
                assert onto.location == crit['ontoT'][1], 'Alignment attribute "{}" conflicts with expected value {}'.format(onto.location, crit['ontoT'][1])
                assert onto.formalism_uri == crit['ontoT'][2], 'Alignment attribute "{}" conflicts with expected value {}'.format(onto.formalism_uri, crit['ontoT'][2])
                assert onto.formalism_name == crit['ontoT'][3], 'Alignment attribute "{}" conflicts with expected value {}'.format(onto.formalism_name, crit['ontoT'][3])
                  
            # FAIL: Execute the test for each correspondence that is expected to fail on this query
            f = []                        
            for f in t['fail']:
                # Read and parse XML Alignment file 
                if info or debug >= 1:
                    print('testing fail case:', f)
                # Test that an incorrect EDOAL Alignment raises the correct exceptions
                try:
                    # For every fail case, one of the below calls will result in an error
                    pa = Alignment(f[0], nsMgr=self.nsMgr)
                    _ = pa.getAbout()
                    _ = pa.getCreator()
                    _ = pa.getDate()
                    _ = pa.getMethod()
                    _ = pa.getPurpose()
                    _ = pa.getLevel()
                    _ = pa.getType()
                    _ = pa.getSrcOnto()
                    _ = pa.getTgtOnto()
                    raise TestException('TestNSManager {} should have raised exception {}'.format(f[0], f[1]))
                except Exception as e: assert type(e) == f[1], 'TestNSManager {} should have raised exception {}; got {}'.format(f[0], f[1], type(e))
            # Test the need for a proper nsMgr
            properfile = list(t['pass'].keys())[0]
            self.assertRaises(AssertionError, Alignment, properfile, None)
#             with self.assertRaises(AssertionError):
#                 _ = Alignment(properfile, nsMgr=None)
            # Test adding the same alignment twice    
            pa = Alignment(properfile, nsMgr=self.nsMgr)
            with self.assertRaises(AssertionError):
                pa._addAlignment(fn=properfile, nsMgr=self.nsMgr)
            if info:
                print('=' * 20)

    def testParseEdoalCorrespondence(self):
#         from mediator.EDOALparser import Alignment
        info = True
        debug = 3
        rule = 'CORR'
        if info or debug >= 1:
            print()
            print('=-' * 7)
            print('EDOAL parser tests, {} part'.format(rule))
            print('=-' * 7)
        for t in self.testCases[rule]:
            if info:
                print('\ntesting', rule, 'with', len(t['pass']), 'pass case(s) and', len(t['fail']), 'fail case(s)')
            if debug >= 3:
                print('> pass cases:', t['pass'])
                print('> fail cases:', t['fail'])
                print()

            # PASS: Execute the test for each defined correspondence file that is expected to pass
            for p, crit in t['pass'].items():
                # Read and parse XML Alignment file 
                if debug >= 1:
                    print('testing pass case:', p)

                pa = Alignment(fn=p, nsMgr=self.nsMgr)
                
                # Get each correspondence cell 
                cell_elements = pa._align.findall(pa.nsMgr.asClarks('align:map') + '/' + pa.nsMgr.asClarks('align:Cell'))
                assert len(cell_elements) > 0, "Pass tests need to have at least one <align:map> element"
                
                # Iterate over all <Cell>...</Cell> parts
                for cell in cell_elements:
                    # Determine whether the CELL element is a pass or fail cell, based on its name
                    name = cell.get(pa.nsMgr.CLARKS_LABELS['RDFABOUT'])
                    for c in crit['corrs']:
                        if name == c['name']:
                            if debug >= 3: print('\t testing {} ..'.format(name), end="")
                            # Since this cell is part of a pass test, continue test
                            corr = pa._parseCorrespondence(cell)
                            assert corr.getName() == c['name']
                            entExpr = corr.getEE1()
                            assert entExpr.getIriRef() == c['ent1']['eir'], "Expected '{}', got '{}'".format(c['ent1']['eir'], entExpr.getIriRef())
                            assert entExpr.getType() == c['ent1']['et'], "Expected '{}', got '{}'".format(c['ent1']['et'], entExpr.getType())
                            if debug >= 3: print(". done")
                            break
                    if corr.getName() != c['name']:
                        # TODO: TestNSManager completeness - maak teller ipv afhankelijk te zijn van about name
                        raise TestException("Incomplete test setup, or invalid parsing: Testcase for {} expected but not found".format(corr.getName()))

            # FAIL: Execute the test for each correspondence that is expected to fail on this query
            f = []
            for f in t['fail']:
                if info or debug >= 1:
                    print('testing fail case:', f)     
                
                pa = Alignment(fn=f, nsMgr=self.nsMgr)
                mappings = t['fail'][f]
                assert pa != None and pa != [], "The fail tests, too, require an Edoal alignment. None found in testcase {}".format(f)
                # Get each correspondence cell 
                map_elements = []
                map_elements = pa._align.findall(pa.nsMgr.asClarks('align:map'))
                if map_elements == []:
                    # Found absent <map> element, which should raise an exception
                    try:
                        if debug >= 3: print("\ttesting {} ..".format('MissingMap'), end="")
                        _ = pa.getCorrespondences()
                        raise TestException('Testcase {}: test {} should have raised exception {}'.format(f, 'MissingMap', mappings['MissingMap']))
                    except Exception as e: 
                        assert type(e) == mappings['MissingMap'], 'TestNSManager should have raised exception {}; got {}'.format(mappings['MissingMap'], type(e))
                        if debug >= 3: print(". done")
                else:
                    for map_element in map_elements:
                        cell_elements = map_element.findall(pa.nsMgr.asClarks('align:Cell'))
                        if cell_elements == []:
                            if debug >= 3: print("\ttesting {} ..".format('MissingCell'), end="")
                            # Found empty <map> element, which should raise an exception
                            try:
                                _ = pa.getCorrespondences()
                                raise TestException('Testcase {}: test {} should have raised exception {}'.format(f, 'MissingCell', mappings['MissingCell']))
                            except Exception as e: 
                                assert type(e) == mappings['MissingCell'], 'TestNSManager should have raised exception {}; got {}'.format(mappings['MissingCell'], type(e))
                                if debug >= 3: print(". done")
                        else:
                            # iterate over all <Cell> elements and validate the failure of each cell
                            for cell in cell_elements:
                                name = cell.get(NSManager.CLARKS_LABELS['RDFABOUT'])
                                assert isinstance(name, str) and name != '', "An edoal {} element requires an {} attribute. None found in this cell in {}".format(cell.tag, pa.nsMrg.CLARKS_LABELS['RDFABOUT'], f)
                                if debug >= 3: print("\ttesting {} ..".format(name), end="")
                                try:
                                    corr = pa._parseCorrespondence(cell)
                                    raise TestException('Testcase {}: test {} should have raised exception {}'.format(f, name, mappings[name]))
                                except Exception as e: 
                                    assert type(e) == mappings[name], 'TestNSManager {} should have raised exception {}; got {}'.format(name, mappings[name], type(e))
                                    if debug >= 3: print(". done")
        
        w = 'resources/alignWarningPass1.xml'
        print('testing warning case:', w)
        pa = Alignment(fn=w, nsMgr=self.nsMgr)
        assert pa != None and pa != [], "Test failure: The test requires an Edoal alignment. None found in testcase {}".format(w)
        assert pa.getAbout() == "http://ds.tno.nl/ontoA-ontoB/DuplicateCells", "Test failure: other alignment read, got '{}'".format(pa.getAbout())
        # Get each correspondence cell 
        cell_elements = pa._align.findall(pa.nsMgr.asClarks('align:map') + '/' + pa.nsMgr.asClarks('align:Cell'))
        assert len(cell_elements) == 3, "Test failure: test needs to have 3 <align:map> elements, got {}".format(len(cell_elements))
        print('\ttesting DuplicateCells ', end="")
        # Iterate over all <Cell>...</Cell> parts
        nameMgr = []
        pa._corrs = []
        for cell in cell_elements:
            # There are three correct <Cell>'s, but the second is a duplicate. 
            # Assert that a duplicate warning is raised, and that the other two correspondences have been created.
            print('.', end="")
            name = cell.get(NSManager.CLARKS_LABELS['RDFABOUT'])
            if name in nameMgr:
                with self.assertWarns(UserWarning):
                    corr = pa._parseCorrespondence(cell)
            else:
                nameMgr.append(name)
                corr = pa._parseCorrespondence(cell)
                pa.appendCorrespondence(corr)
                assert corr.getName() == name
        assert len(pa.getCorrespondences()) == 2, "Got {}".format(len(pa.getCorrespondences()))
        print(' done')
                    
    def testParseEdoalValue(self):
#         from mediator.EDOALparser import Alignment

        info = True
        debug = 3
        rule = 'VALUE'
        if info or debug >= 1:
            print()
            print('=-' * 7)
            print('EDOAL parser tests, {} part'.format(rule))
            print('=-' * 7)
        for t in self.testCases[rule]:
            if info:
                print('\ntesting', rule, 'with', len(t['pass']), 'pass case(s) and', len(t['fail']), 'fail case(s)')
            if debug >= 3:
                print('> pass cases:', t['pass'])
                print('> fail cases:', t['fail'])
                print()

            testCriteria = []
            
            # PASS: Execute the test for each defined correspondence file that is expected to pass
            for testCase, testCriteria in t['pass'].items():
                if debug >= 1:
                    print('PASS case {} has specified {} tests'.format(testCase, len(testCriteria)))
                # Do the test
                # Create a Alignment object only to have a valid Alignment object and create a valid nsMgr;
                #    the test data is incorrect edoal, and this code below takes that into consideration
                pa = Alignment(fn=testCase, nsMgr=self.nsMgr)
                testsEl = pa._align.findall(self.nsMgr.asClarks('t:tests'))
                if testsEl == None or len(testsEl) == 0: raise TestException("No tests found, cannot perform tests")
                tests = testsEl[0].findall(self.nsMgr.asClarks('t:test'))
                if len(testCriteria) != len(tests): raise TestException('Test setup specifies {} tests, but {} tests found in test data ({})'.format(len(testCriteria), len(tests), testCase))
                if debug >= 3: print('Found {} tests in test data'.format(len(tests)))
                for test in tests:
                    tname = test.get(NSManager.CLARKS_LABELS['RDFABOUT'])
                    # Check the test data
                    if tname == None or tname == '': raise TestException('Testcase {}: Use of {} attribute in <test> element required to discern the various testCriteria'.format(testCase, NSManager.nsmap['RDFABOUT']))
                    edoal_entity = test.find(self.nsMgr.asClarks('edoal:entity1'))
                    if edoal_entity == None: raise TestException('Testcase {}: Test ({}) is required to contain an <entity1> element'.format(testCase, tname))
                    if debug >= 3: print('Testing test: {} ..'.format(tname), end="")
                    edoalValue = pa.Value(el=edoal_entity, parse_alignment=pa)
                    if edoalValue == None: raise TestException('Testcase {}: Test ({}) is required to contain a <value> element'.format(testCase, tname))
                    # Check the value type that is under test, perform the test and verify the outcome is as expected
                    if testCriteria[tname]['valueType'] == 'edoal:Literal':
                        assert (testCriteria[tname]['value'], testCriteria[tname]['type']) == edoalValue.getLiteral(), \
                            'Testcase {}, test {}: expected {} but found {}'.format(testCase, tname, (testCriteria[tname]['value'], testCriteria[tname]['type']), edoalValue.getLiteral())
                    elif testCriteria[tname]['valueType'] == 'edoal:Instance':
                        assert testCriteria[tname]['value'] == edoalValue.getIndividual(), 'Testcase {}, test {}: expected {} but found {}'.format(testCase, tname, testCriteria[tname]['value'], edoalValue.getIndividual())
                    elif testCriteria[tname]['valueType'] in ['edoal:Property', 'edoal:Relation']:
                        assert testCriteria[tname]['value'] == edoalValue.getAttrExpression(), 'Testcase {}, test {}: expected {} but found {}'.format(testCase, tname, testCriteria[tname]['value'], edoalValue.getAttrExpression())
                    elif testCriteria[tname]['valueType'] in ['edoal:Apply', 'edoal:Aggregate']:
                        assert testCriteria[tname]['value'] == edoalValue.getOperator().getName(), 'Testcase {}, test {}: expected {} but found {}'.format(testCase, tname, testCriteria[tname]['value'], edoalValue.getOperator().getName())
                    elif testCriteria[tname]['valueType'] == 'edoal:compose':
                        assert testCriteria[tname]['type'] == edoalValue.getEntityType(), 'Testcase {}, test {}: expected {} but found {}'.format(testCase, tname, testCriteria[tname]['type'], edoalValue.getEntityType())
                        if edoalValue.hasPath():
                            for criterion, attrExpr in zip(testCriteria[tname]['value'], edoalValue.getPath()):
                                assert criterion == str(attrExpr), 'Testcase {}, test {}: expected {} but found {}'.format(testCase, tname, criterion, attrExpr)
                        else: raise AssertionError('Testcase {}, test {}: missing path expression'.format(testCase, tname))
                    else: raise TestException('No test code implemented for value type {}, please specify and add test code'.format(testCriteria[tname]['valueType']))
                    if debug >= 3: print('. done')

            # FAIL: Execute the testCriteria, which are expected to fail
            for testCase, testCriteria in t['fail'].items():
                if debug >= 1:
                    print('\nFAIL case {} has specified {} tests'.format(testCase, len(testCriteria)))

                # Create a Alignment object only to have a valid Alignment object and create a valid nsMgr;
                #    the test data is incorrect edoal, and this code below takes that into consideration
                pa = Alignment(fn=testCase, nsMgr=self.nsMgr)
                testsEl = pa._align.findall(self.nsMgr.asClarks('t:tests'))
                if testsEl == None or len(testsEl) == 0: raise TestException("No tests found, cannot perform tests")
                tests = testsEl[0].findall(self.nsMgr.asClarks('t:test'))
                if len(testCriteria) != len(tests): raise TestException('TestNSManager setup specifies {} tests, but {} tests found in test data ({})'.format(len(testCriteria), len(tests), testCase))
                if debug >= 3: print('Found {} tests in test data'.format(len(tests)))
                # Illegal use of the Alignment element
                for test in tests:
                    tname = test.get(NSManager.CLARKS_LABELS['RDFABOUT'])
                    # Check the test data
                    if tname == None or tname == '': raise TestException('Testcase {}: Use of {} attribute in <test> element required to discern the various testCriteria'.format(testCase, NSManager.nsmap['RDFABOUT']))
                    edoal_entity = test.find(self.nsMgr.asClarks('edoal:entity1'))
                    if edoal_entity == None: raise TestException('Testcase {}: TestCase ({}) is required to contain an <entity1> element'.format(testCase, tname))
                    # Perform the test, check for the occurrence of an exception and verify that the fault condition raises the correct exception
                    try:
                        if debug >= 3: print('testing {} ...'.format(tname), end="")
                        _ = pa.Value(el=edoal_entity, parse_alignment=pa)
                        # This should be dead code, because an exception should have been raised
                        raise TestException('Testcase {}: Test {} failed, expected exception ({}) did not occur!'.format(testCase, tname, testCriteria[tname]))
                    except Exception as e: assert type(e) == testCriteria[tname], 'Testcase {}, test {}: expected {}, got {}'.format(testCase, tname, testCriteria[tname], type(e))
                    if debug >= 3: print('. done')

    def test_parseOperation(self):
        assert False, "Make test for method '_parseOperation()'"

    def test_parseTransform(self):
        assert False, "Make test for method '_parseTransform()'"
        
    def testAlignment(self):
        # Pass testcases
        a = Alignment(fn='resources/valueSimplePass1.xml', nsMgr=self.nsMgr)
        assert a.about == "http://ds.tno.nl/ontoA-ontoB/CPR-EQ-CPR"
        
        # Fail testcases
        with self.assertRaises(AssertionError):
            _ = Alignment(fn='', nsMgr=self.nsMgr)
        with self.assertRaises(AssertionError):
            _ = Alignment(fn='resources/valueSimplePass1.xml', nsMgr=None)
예제 #10
0
class TestNSManager(unittest.TestCase):
    def setUp(self):
        testNS = {
            'med': 'http://ds.tno.nl/mediator/1.0/',
            'dc': 'http://purl.org/dc/elements/1.1/',
            'edoal': 'http://ns.inria.org/edoal/1.0/#',
            'test': 'http://ds.tno.nl/mediator/1.0'
        }
        self.base = 'http://knowledgeweb.semanticweb.org/heterogeneity/alignment#'
        self.nsMgr = NSManager(nsDict=testNS, base=self.base)

    def tearDown(self):
        pass

    def testNsConcat(self):
        print('Testcase {}\n\ttesting {} ..'.format(
            self.__class__.__name__,
            inspect.currentframe().f_code.co_name),
              end="",
              flush=True)
        assert self.nsMgr.nsConcat(
            'http://www.w3.org/2001/XMLSchema#', 'appel'
        ) == '<http://www.w3.org/2001/XMLSchema#appel>', "got {}".format(
            self.nsMgr.nsConcat('http://www.w3.org/2001/XMLSchema#', 'appel'))
        assert self.nsMgr.nsConcat(
            '<http://www.w3.org/2001/XMLSchema#>', 'appel'
        ) == '<http://www.w3.org/2001/XMLSchema#appel>', "got {}".format(
            self.nsMgr.nsConcat('<http://www.w3.org/2001/XMLSchema#>',
                                'appel'))
        assert self.nsMgr.nsConcat(
            'http://www.w3.org/2001/XMLSchema/', 'appel'
        ) == '<http://www.w3.org/2001/XMLSchema/appel>', "got {}".format(
            self.nsMgr.nsConcat('http://www.w3.org/2001/XMLSchema/', 'appel'))
        assert self.nsMgr.nsConcat(
            '<http://www.w3.org/2001/XMLSchema/>', 'appel'
        ) == '<http://www.w3.org/2001/XMLSchema/appel>', "got {}".format(
            self.nsMgr.nsConcat('<http://www.w3.org/2001/XMLSchema/>',
                                'appel'))
        assert self.nsMgr.nsConcat(
            'http://www.w3.org/2001/XMLSchema', 'appel'
        ) == '<http://www.w3.org/2001/XMLSchema/appel>', "got {}".format(
            self.nsMgr.nsConcat('http://www.w3.org/2001/XMLSchema', 'appel'))
        assert self.nsMgr.nsConcat(
            '<http://www.w3.org/2001/XMLSchema>', 'appel'
        ) == '<http://www.w3.org/2001/XMLSchema/appel>', "got {}".format(
            self.nsMgr.nsConcat('<http://www.w3.org/2001/XMLSchema>', 'appel'))
        print(". done")

    def testCONSTANTS(self):
        print('Testcase {}\n\ttesting {} ..'.format(
            self.__class__.__name__,
            inspect.currentframe().f_code.co_name),
              end="",
              flush=True)
        assert self.nsMgr.CLARKS_LABELS[
            'XSDSTRING'] == '{http://www.w3.org/2001/XMLSchema#}string'
        assert self.nsMgr.CLARKS_LABELS[
            'RDFABOUT'] == '{http://www.w3.org/1999/02/22-rdf-syntax-ns#}about'
        assert self.nsMgr.CLARKS_LABELS[
            'RDFDATATP'] == '{http://www.w3.org/1999/02/22-rdf-syntax-ns#}datatype'
        assert self.nsMgr.CLARKS_LABELS[
            'RDFPARSTP'] == '{http://www.w3.org/1999/02/22-rdf-syntax-ns#}parseType'
        assert self.nsMgr.CLARKS_LABELS[
            'RDFDATATP'] == '{http://www.w3.org/1999/02/22-rdf-syntax-ns#}datatype'
        assert self.nsMgr.CLARKS_LABELS[
            'ALIGNMENT'] == '{http://knowledgeweb.semanticweb.org/heterogeneity/alignment#}Alignment'
        print(". done")

    def testSplitIRI(self):
        print('Testcase {}\n\ttesting {} ..'.format(
            self.__class__.__name__,
            inspect.currentframe().f_code.co_name),
              end="",
              flush=True)
        assert ('align', "Alignment") == self.nsMgr._splitIRI(
            "<http://knowledgeweb.semanticweb.org/heterogeneity/alignment#Alignment>"
        ), "Unexpectedly got '{}'".format(
            self.nsMgr._splitIRI(
                "<http://knowledgeweb.semanticweb.org/heterogeneity/alignment#Alignment>"
            ))
        assert ('med', "Alignment") == self.nsMgr._splitIRI(
            "<http://ds.tno.nl/mediator/1.0/Alignment>")
        with self.assertRaises(AssertionError):
            self.nsMgr._splitIRI("http:Alignment")
        with self.assertRaises(AssertionError):
            self.nsMgr._splitIRI("<http:Alignment>")
        with self.assertRaises(AssertionError):
            self.nsMgr._splitIRI("Alignment")
        with self.assertRaises(AssertionError):
            self.nsMgr._splitIRI("<Alignment>")
        with self.assertRaises(AssertionError):
            self.nsMgr._splitIRI("{http://purl.org/dc/elements/1.1/}creator")
        print(". done")

    def testAsClarks(self):
        print('Testcase {}\n\ttesting {} ..'.format(
            self.__class__.__name__,
            inspect.currentframe().f_code.co_name),
              end="",
              flush=True)
        assert isinstance(self.nsMgr.asClarks('dc:creator'), str)
        assert self.nsMgr.asClarks(
            'dc:creator'
        ) == '{http://purl.org/dc/elements/1.1/}creator', 'Expected "{http://purl.org/dc/elements/1.1/}creator", got {}'.format(
            self.nsMgr.asClarks('dc:creator'))
        assert self.nsMgr.asClarks(
            "<http://purl.org/dc/elements/1.1/creator>"
        ) == '{http://purl.org/dc/elements/1.1/}creator', 'Expected "{http://purl.org/dc/elements/1.1/}creator", got {}'.format(
            self.nsMgr.asClarks("<http://purl.org/dc/elements/1.1/creator>"))
        assert self.nsMgr.asClarks(
            ':align'
        ) == '{' + self.base + '}align', 'Expected: {}, got: {}'.format(
            '{' + self.base + '}align', str(self.nsMgr.asClarks(':align')))
        with self.assertRaises(Exception):
            self.nsMgr.asClarks('none:creator')
        with self.assertRaises(Exception):
            self.nsMgr.asClarks('dc:creator:invalidQname')
        print(". done")

    def testAsIri(self):
        print('Testcase {}\n\ttesting {} ..'.format(
            self.__class__.__name__,
            inspect.currentframe().f_code.co_name),
              end="",
              flush=True)
        print(str(self.nsMgr))
        # Success scenarios
        inpstr = 'dc:creator'
        expstr = '<http://purl.org/dc/elements/1.1/creator>'
        assert str(self.nsMgr.asIRI(
            inpstr)) == expstr, 'Expected: {}, got: {}'.format(
                expstr, str(self.nsMgr.asIRI(inpstr)))
        inpstr = 'test:creator'
        expstr = '<http://ds.tno.nl/mediator/1.0/creator>'
        assert str(self.nsMgr.asIRI(
            inpstr)) == expstr, 'Expected: {}, got: {}'.format(
                expstr, str(self.nsMgr.asIRI(inpstr)))
        inpstr = ':align'
        expstr = '<' + self.base + 'align>'
        assert str(self.nsMgr.asIRI(
            inpstr)) == expstr, 'Expected: {}, got: {}'.format(
                expstr, str(self.nsMgr.asIRI(inpstr)))
        inpstr = '{}align'
        expstr = '<' + self.base + 'align>'
        assert str(self.nsMgr.asIRI(
            inpstr)) == expstr, 'Expected: {}, got: {}'.format(
                expstr, str(self.nsMgr.asIRI(inpstr)))
        inpstr = '<http://purl.org/dc/elements/1.1/creator>'
        expstr = '<http://purl.org/dc/elements/1.1/creator>'
        assert str(self.nsMgr.asIRI(
            inpstr)) == expstr, 'Expected: {}, got: {}'.format(
                expstr, str(self.nsMgr.asIRI(inpstr)))
        inpstr = '{http://purl.org/dc/elements/1.1/}creator'
        expstr = '<http://purl.org/dc/elements/1.1/creator>'
        assert str(self.nsMgr.asIRI(
            inpstr)) == expstr, 'Expected: {}, got: {}'.format(
                expstr, str(self.nsMgr.asIRI(inpstr)))
        # Fail scenarios
        with self.assertRaises(Exception):
            self.nsMgr.asIri('')
        with self.assertRaises(Exception):
            self.nsMgr.asIri('<>')
        with self.assertRaises(Exception):
            self.nsMgr.asIri(':')
        with self.assertRaises(Exception):
            self.nsMgr.asIri('<:>')
        with self.assertRaises(Exception):
            self.nsMgr.asIri('{}')
        with self.assertRaises(Exception):
            self.nsMgr.asIri('<{}>')
        with self.assertRaises(Exception):
            self.nsMgr.asIri('{<>}')
        with self.assertRaises(Exception):
            self.nsMgr.asIri('{}creator{}')
        with self.assertRaises(Exception):
            self.nsMgr.asIri('{}{}creator')
        with self.assertRaises(Exception):
            self.nsMgr.asIri('<none:creator>')
        with self.assertRaises(Exception):
            self.nsMgr.asIri('<dc:creator:invalidQname>')
        print(". done")

    def testPrefix(self):
        print('Testcase {}\n\ttesting {} ..'.format(
            self.__class__.__name__,
            inspect.currentframe().f_code.co_name),
              end="",
              flush=True)
        pf = self.nsMgr.getPrefix('http://ds.tno.nl/mediator/1.0/')
        assert pf == 'med', "Expected {}, got {}".format('med', pf)
        # TestNSManager creation of new prefix
        pf = self.nsMgr.getPrefix('http://ds.tno.nl/non-existent/1.0/')
        cntr = self.nsMgr._prefixCntr
        expectedPF = self.nsMgr.newPrefix()[:-1] + str(cntr)
        assert pf == expectedPF, "Expected {}, got {}".format(expectedPF, pf)
        # TestNSManager new prefix has been registered, i.e., no new prefix has been created again
        pf = self.nsMgr.getPrefix('http://ds.tno.nl/non-existent/1.0/')
        assert pf == expectedPF, "Expected {}, got {}".format(expectedPF, pf)
        print(". done")

    def testIsQName(self):
        print('Testcase {}\n\ttesting {} ..'.format(
            self.__class__.__name__,
            inspect.currentframe().f_code.co_name),
              end="",
              flush=True)
        assert self.nsMgr.isQName('appel:ei')
        assert self.nsMgr.isQName(':ei')
        assert not self.nsMgr.isQName('')
        assert not self.nsMgr.isQName(':')
        assert not self.nsMgr.isQName('appel:')
        assert not self.nsMgr.isQName(':appel:ei')
        assert not self.nsMgr.isQName('koe:appel:ei')
        assert not self.nsMgr.isQName(
            'http://knowledgeweb.semanticweb.org/heterogeneity/alignment#egg')
        print(". done")

    def testIsClarks(self):
        print('Testcase {}\n\ttesting {} ..'.format(
            self.__class__.__name__,
            inspect.currentframe().f_code.co_name),
              end="",
              flush=True)
        assert self.nsMgr.isClarks('{appel}ei')
        assert self.nsMgr.isClarks('{}ei')
        assert not self.nsMgr.isClarks('')
        assert not self.nsMgr.isClarks('{}')
        assert not self.nsMgr.isClarks('{appel}')
        assert not self.nsMgr.isClarks('appel{}')
        assert not self.nsMgr.isClarks('appel{ei}')
        assert not self.nsMgr.isClarks('{}{appel}ei')
        assert not self.nsMgr.isClarks('{koe}{appel}ei')
        assert not self.nsMgr.isClarks('}appel}ei')
        assert not self.nsMgr.isClarks('{appel{ei')
        assert not self.nsMgr.isClarks('{appel}{ei')
        assert not self.nsMgr.isClarks('{appel{}ei')
        print(". done")

    def testIsIRI(self):
        print('Testcase {}\n\ttesting {} ..'.format(
            self.__class__.__name__,
            inspect.currentframe().f_code.co_name),
              end="",
              flush=True)
        assert self.nsMgr.isIRI(
            '<preamb://authority.name/iri_expans/iri_path>')
        assert self.nsMgr.isIRI(
            '<preamb://authority.org/iri_expans/iri_expans/iri_path>')
        assert self.nsMgr.isIRI('<preamb://authority.org/iri_expans#iri_path>')
        assert self.nsMgr.isIRI(
            '<preamb://authority.org/iri_expans/iri_expans#iri_path>')
        assert self.nsMgr.isIRI(
            '<http://knowledgeweb.semanticweb.org/heterogeneity/alignment#Alignment>'
        )
        assert self.nsMgr.isIRI('<http://ds.tno.nl/mediator/1.0/Alignment>')
        assert self.nsMgr.isIRI(
            '<preamb://authority.org/iri_expans/iri_expans#subpath/path>')

        assert not self.nsMgr.isIRI(
            'preamb://authority.fives/iri_expans/iri_path')
        assert not self.nsMgr.isIRI(
            'preamb://authority.name/iri_expans/iri_path>')
        assert not self.nsMgr.isIRI(
            '<preamb://authority.name/iri_expans/iri_path')
        assert not self.nsMgr.isIRI(
            '<preamb://authority.l/iri_expans/iri_path>')
        assert not self.nsMgr.isIRI(
            '<preamb://authority./iri_expans/iri_path>')
        assert not self.nsMgr.isIRI('<preamb://authority/iri_expans/iri_path>')
        assert not self.nsMgr.isIRI(
            '<://authority.something/iri_expans/iri_path>')
        assert not self.nsMgr.isIRI(
            '<preamb:authority.something/iri_expans/iri_path>')
        assert not self.nsMgr.isIRI('<preamb:authority>')
        assert not self.nsMgr.isIRI(
            '<{preamb://authority.org/iri_expans/iri_expans#}iri_path>')
        assert not self.nsMgr.isIRI(
            '<{preamb://authority.org/iri_expans/iri_expans/}iri_path>')
        assert not self.nsMgr.isIRI(
            '<preamb://authority.org/iri_expans/iri_expan/iri_path#>')
        assert not self.nsMgr.isIRI(
            '<preamb://authority.org/iri_expans/iri_expans#iri_path/>')
        assert not self.nsMgr.isIRI(
            '<preamb://authority.org/iri_expans/iri_expans/iri_path/>')
        print(". done")

    def testSplit(self):
        print('Testcase {}\n\ttesting {} ..'.format(
            self.__class__.__name__,
            inspect.currentframe().f_code.co_name),
              end="",
              flush=True)
        # Success scenarios
        pf, prefix_expansion, iri_path = self.nsMgr.splitIri('dc:path')
        assert pf == 'dc' and prefix_expansion == 'http://purl.org/dc/elements/1.1/' and iri_path == 'path', "Got pf:{}, expansion:{}, path:{}".format(
            pf, prefix_expansion, iri_path)
        pf, prefix_expansion, iri_path = self.nsMgr.splitIri(':path')
        assert pf == '' and prefix_expansion == 'http://knowledgeweb.semanticweb.org/heterogeneity/alignment#' and iri_path == 'path', "Got pf:{}, expansion:{}, path:{}".format(
            pf, prefix_expansion, iri_path)
        pf, prefix_expansion, iri_path = self.nsMgr.splitIri(
            '{http://purl.org/dc/elements/1.1/}path')
        assert pf == 'dc' and prefix_expansion == 'http://purl.org/dc/elements/1.1/' and iri_path == 'path', "Got pf:{}, expansion:{}, path:{}".format(
            pf, prefix_expansion, iri_path)
        pf, prefix_expansion, iri_path = self.nsMgr.splitIri('{}path')
        assert pf == '' and prefix_expansion == 'http://knowledgeweb.semanticweb.org/heterogeneity/alignment#' and iri_path == 'path', "Got pf:{}, expansion:{}, path:{}".format(
            pf, prefix_expansion, iri_path)
        # Fail scenarios
        with self.assertRaises(NotImplementedError):
            pf, prefix_expansion, iri_path = self.nsMgr.splitIri('path:')
        with self.assertRaises(NotImplementedError):
            pf, prefix_expansion, iri_path = self.nsMgr.splitIri('a*a')
        with self.assertRaises(NotImplementedError):
            pf, prefix_expansion, iri_path = self.nsMgr.splitIri('a!a')
        with self.assertRaises(NotImplementedError):
            pf, prefix_expansion, iri_path = self.nsMgr.splitIri('a@a')
        with self.assertRaises(NotImplementedError):
            pf, prefix_expansion, iri_path = self.nsMgr.splitIri('a$a')
        with self.assertRaises(NotImplementedError):
            pf, prefix_expansion, iri_path = self.nsMgr.splitIri('a%a')
        with self.assertRaises(NotImplementedError):
            pf, prefix_expansion, iri_path = self.nsMgr.splitIri('a^a')
        with self.assertRaises(NotImplementedError):
            pf, prefix_expansion, iri_path = self.nsMgr.splitIri('a&a')
        with self.assertRaises(NotImplementedError):
            pf, prefix_expansion, iri_path = self.nsMgr.splitIri('a(a')
        with self.assertRaises(NotImplementedError):
            pf, prefix_expansion, iri_path = self.nsMgr.splitIri('a)a')
        with self.assertRaises(NotImplementedError):
            pf, prefix_expansion, iri_path = self.nsMgr.splitIri('a_a')
        with self.assertRaises(NotImplementedError):
            pf, prefix_expansion, iri_path = self.nsMgr.splitIri('a-a')
        with self.assertRaises(NotImplementedError):
            pf, prefix_expansion, iri_path = self.nsMgr.splitIri('a+a')
        with self.assertRaises(NotImplementedError):
            pf, prefix_expansion, iri_path = self.nsMgr.splitIri('a=a')
        with self.assertRaises(NotImplementedError):
            pf, prefix_expansion, iri_path = self.nsMgr.splitIri('a[a')
        with self.assertRaises(NotImplementedError):
            pf, prefix_expansion, iri_path = self.nsMgr.splitIri('a]a')
        with self.assertRaises(NotImplementedError):
            pf, prefix_expansion, iri_path = self.nsMgr.splitIri('a|a')
        with self.assertRaises(NotImplementedError):
            pf, prefix_expansion, iri_path = self.nsMgr.splitIri('a;a')
        with self.assertRaises(NotImplementedError):
            pf, prefix_expansion, iri_path = self.nsMgr.splitIri('a"a')
        with self.assertRaises(NotImplementedError):
            pf, prefix_expansion, iri_path = self.nsMgr.splitIri("a'a")
        with self.assertRaises(NotImplementedError):
            pf, prefix_expansion, iri_path = self.nsMgr.splitIri('a~a')
        with self.assertRaises(NotImplementedError):
            pf, prefix_expansion, iri_path = self.nsMgr.splitIri('a`a')
        with self.assertRaises(NotImplementedError):
            pf, prefix_expansion, iri_path = self.nsMgr.splitIri('a,a')
        with self.assertRaises(NotImplementedError):
            pf, prefix_expansion, iri_path = self.nsMgr.splitIri('a<a')
        with self.assertRaises(NotImplementedError):
            pf, prefix_expansion, iri_path = self.nsMgr.splitIri('a>a')
        with self.assertRaises(NotImplementedError):
            pf, prefix_expansion, iri_path = self.nsMgr.splitIri('a?a')
        print(". done")