Exemplo n.º 1
0
    def test_convert_bindings_dict_raise_exception(self):
        class ContextMock(prefixes.MemorizeContext):
            object_properties = {}
            context = {'g1': 'http://semantica.globo.com/G1/'}

        context = ContextMock(normalize_uri=SHORTEN)
        cardinalities = {}
        bindings = [
            {
                u'predicate': {u'type': u'uri', u'value': u'http://semantica.globo.com/G1/cita_a_entidade'},
                u'predicate_graph': {u'type': u'uri', u'value': u'http://semantica.globo.com/G1/'},
                u'range_graph': {u'type': u'uri', u'value': u'http://semantica.globo.com/'},
                u'range': {u'type': u'uri', u'value': u'http://semantica.globo.com/base/Criatura'},
                u'title': {u'type': u'literal', u'value': u'Entidades'},
                u'type': {u'type': u'uri', u'value': u'http://www.w3.org/2002/07/owl#ObjectProperty'},
                u'domain_class': {u'type': u'uri', u'value': u'http://test/person/AnyClass'},
            },
            {
                u'predicate': {u'type': u'uri', u'value': u'http://semantica.globo.com/G1/cita_a_entidade'},
                u'predicate_graph': {u'type': u'uri', u'value': u'http://semantica.globo.com/G1/'},
                u'range_graph': {u'type': u'uri', u'value': u'http://semantica.globo.com/'},
                u'range': {u'type': u'uri', u'value': u'http://semantica.globo.com/base/Criatura'},
                u'title': {u'type': u'literal', u'value': u'Entidades'},
                u'type': {u'type': u'uri', u'value': u'http://www.w3.org/2002/07/owl#ObjectProperty'},
                u'domain_class': {u'type': u'uri', u'value': u'http://test/person/AnyClass'},
            }
        ]
        hierarchy = [u'http://test/person/AnyClass']

        with self.assertRaises(schema.InstanceError) as error:
            convert_bindings_dict(context, bindings, cardinalities, hierarchy)
            self.assertEqual(error.exception, "InstanceError: The property g1:cita_a_entidade seems to be duplicated in class http://test/person/AnyClass")
Exemplo n.º 2
0
    def test_convert_bindings_dict_two_predicates_single_range(self):
        class ContextMock(prefixes.MemorizeContext):
            object_properties = {}
            context = {'g1': 'http://semantica.globo.com/G1/'}

        context = ContextMock(normalize_uri=SHORTEN)
        cardinalities = {}
        bindings = [
            {
                u'predicate': {u'type': u'uri', u'value': u'http://semantica.globo.com/G1/cita_a_entidade'},
                u'predicate_graph': {u'type': u'uri', u'value': u'http://semantica.globo.com/G1/'},
                u'range_graph': {u'type': u'uri', u'value': u'http://semantica.globo.com/'},
                u'range': {u'type': u'uri', u'value': u'http://semantica.globo.com/base/Criatura'},
                u'title': {u'type': u'literal', u'value': u'Entidades'},
                u'type': {u'type': u'uri', u'value': u'http://www.w3.org/2002/07/owl#ObjectProperty'},
                u'domain_class': {u'type': u'uri', u'value': u'http://test/person/AnyClass'},
            },
            {
                u'predicate': {u'type': u'uri', u'value': u'http://semantica.globo.com/G1/trata_do_assunto'},
                u'predicate_graph': {u'type': u'uri', u'value': u'http://semantica.globo.com/G1/'},
                u'range': {u'type': u'uri', u'value': u'http://semantica.globo.com/G1/AssuntoCarro'},
                u'range_graph': {u'type': u'uri', u'value': u'http://semantica.globo.com/'},
                u'title': {u'type': u'literal', u'value': u'Assuntos'},
                u'type': {u'type': u'uri', u'value': u'http://www.w3.org/2002/07/owl#ObjectProperty'},
                u'domain_class': {u'type': u'uri', u'value': u'http://test/person/AnyClass'},
            },
        ]
        hierarchy = [u'http://test/person/AnyClass']
        computed = convert_bindings_dict(context, bindings, cardinalities, hierarchy)
        expected = {
            'http://semantica.globo.com/G1/cita_a_entidade': {
                'graph': u'http://semantica.globo.com/G1/',
                'class': u'http://test/person/AnyClass',
                'range': {
                    'graph': u'http://semantica.globo.com/',
                    '@id': u'http://semantica.globo.com/base/Criatura',
                    'title': '',
                    'type': 'string',
                    'format': 'uri'},
                'title': u'Entidades',
                'type': 'array',
                'items': {'type': 'string', 'format': 'uri'}

            },
            'http://semantica.globo.com/G1/trata_do_assunto': {
                'graph': u'http://semantica.globo.com/G1/',
                'class': u'http://test/person/AnyClass',
                'range': {
                    'graph': u'http://semantica.globo.com/',
                    '@id': u'http://semantica.globo.com/G1/AssuntoCarro',
                    'title': '',
                    'type': 'string',
                    'format': 'uri'},
                'title': u'Assuntos',
                'type': 'array',
                'items': {'type': 'string', 'format': 'uri'}
            }
        }

        self.assertEqual(computed, expected)
Exemplo n.º 3
0
    def test_convert_bindings_dict_single_datatypeproperty(self):

        class ContextMock(prefixes.MemorizeContext):
            object_properties = {}
            context = {'test': 'http://test.graph/'}

        context = ContextMock(normalize_uri=SHORTEN)
        cardinalities = {}
        bindings = [
            {
                u'predicate': {u'type': u'uri', u'value': u'http://test.graph/creation_date'},
                u'predicate_graph': {u'type': u'uri', u'value': u'http://test.graph/'},
                u'range': {u'type': u'uri', u'value': u'http://www.w3.org/2001/XMLSchema#dateTime'},
                u'title': {u'type': u'literal', u'value': u'Creation Date'},
                u'type': {u'type': u'uri', u'value': u'http://www.w3.org/2002/07/owl#DatatypeProperty'},
                u'domain_class': {u'type': u'uri', u'value': u'http://test/person/AnyClass'},
                u'unique_value': {u'type': u'typed-literal', u'datatype': u'http://www.w3.org/2001/XMLSchema#integer', u'value': u'1'}
            }
        ]
        hierarchy = [u'http://test/person/AnyClass']
        computed = convert_bindings_dict(context, bindings, cardinalities, hierarchy)
        expected = {
            'http://test.graph/creation_date': {
                'graph': 'http://test.graph/',
                'title': u'Creation Date',
                'class': u'http://test/person/AnyClass',
                'type': 'string',
                'format': 'date',
                'datatype': u'http://www.w3.org/2001/XMLSchema#dateTime',
                'unique_value': True
            }
        }

        self.assertEqual(computed, expected)
Exemplo n.º 4
0
    def _test_convert_bindings_dict_single_predicate_multiple_ranges_of_same_type(self):

        class ContextMock(prefixes.MemorizeContext):
            object_properties = {}
            context = {'test': 'http://test.graph/'}

        context = ContextMock(normalize_uri=SHORTEN)
        cardinalities = {}
        bindings = [
            {
                u'predicate': {u'type': u'uri', u'value': u'http://test.graph/predicate'},
                u'predicate_graph': {u'type': u'uri', u'value': u'http://test.graph/'},
                u'range': {u'type': u'uri', u'value': u'http://test.graph/RangeOne'},
                u'title': {u'type': u'literal', u'value': u'test'},
                u'type': {u'type': u'uri', u'value': u'http://www.w3.org/2002/07/owl#ObjectProperty'},
                u'domain_class': {u'type': u'uri', u'value': u'http://test/person/AnyClass'},
            },
            {
                u'predicate': {u'type': u'uri', u'value': u'http://test.graph/predicate'},
                u'predicate_graph': {u'type': u'uri', u'value': u'http://test.graph/'},
                u'range': {u'type': u'uri', u'value': u'http://test.graph/RangeTwo'},
                u'title': {u'type': u'literal', u'value': u'test'},
                u'type': {u'type': u'uri', u'value': u'http://www.w3.org/2002/07/owl#ObjectProperty'},
                u'domain_class': {u'type': u'uri', u'value': u'http://test/person/AnyClass'},
            }
        ]
        hierarchy = [u'http://test/person/AnyClass']
        computed = convert_bindings_dict(context, bindings, cardinalities, hierarchy)
        expected = {
            'http://test.graph/predicate': {
                'graph': 'http://test.graph/',
                'range': [
                    {
                        'graph': '',
                        '@id': 'http://test.graph/RangeOne',
                        'title': '',
                        'type': 'string',
                        'format': 'uri'
                    },
                    {
                        'graph': '',
                        '@id': 'http://test.graph/RangeTwo',
                        'title': '',
                        'type': 'string',
                        'format': 'uri'
                    }
                ],
                'title': u'test',
                'type': 'string',
                'format': 'uri'
            }
        }
        self.assertItemsEqual(computed, expected)
Exemplo n.º 5
0
    def test_convert_bindings_dict_single_predicate_single_range(self):

        class ContextMock(prefixes.MemorizeContext):
            object_properties = {}
            context = {'test': 'http://test.graph/'}

        context = ContextMock(normalize_uri=SHORTEN)
        cardinalities = {}
        bindings = [
            {
                u'predicate': {u'type': u'uri', u'value': u'http://test.graph/hasParent'},
                u'predicate_graph': {u'type': u'uri', u'value': u'http://test.graph/'},
                u'range': {u'type': u'uri', u'value': u'http://test.graph/Person'},
                u'title': {u'type': u'literal', u'value': u'Has parent'},
                u'type': {u'type': u'uri', u'value': u'http://www.w3.org/2002/07/owl#ObjectProperty'},
                u'domain_class': {u'type': u'uri', u'value': u'http://test/person/AnyClass'},
            }
        ]

        hierarchy = [u'http://test/person/AnyClass']
        computed = convert_bindings_dict(context, bindings, cardinalities, hierarchy)
        expected = {
            'http://test.graph/hasParent': {
                'graph': 'http://test.graph/',
                'class': u'http://test/person/AnyClass',
                'range': {
                    'graph': '',
                    '@id': 'http://test.graph/Person',
                    'title': '',
                    'format': 'uri',
                    'type': 'string'},
                'title': u'Has parent',
                'type': 'array',
                'items': {'type': 'string', 'format': 'uri'}

            }
        }

        self.assertEqual(computed, expected)