Esempio n. 1
0
 def test_assemble_predicate_with_datatype_property(self):
     expected_predicate_dict = {'description': u'Nome completo da pessoa',
                                'graph': u'http://test/person/',
                                'title': u'Nome',
                                'type': 'string',
                                'class': u'http://test/person/AnyClass',
                                'datatype': u'http://www.w3.org/2001/XMLSchema#string'}
     name = u'http://test/person/gender'
     predicate = {u'predicate': {u'type': u'uri', u'value': u'http://test/person/name'},
                  u'domain_class': {u'type': u'uri', u'value': u'http://test/person/AnyClass'},
                  u'range': {u'type': u'uri', u'value': u'http://www.w3.org/2001/XMLSchema#string'},
                  u'title': {u'xml:lang': u'pt', u'type': u'literal', u'value': u'Nome'},
                  u'range_graph': {u'type': u'uri', u'value': u'http://test/person/'},
                  u'range_label': {u'xml:lang': u'pt', u'type': u'literal', u'value': u'Nome da Pessoa'},
                  u'predicate_graph': {u'type': u'uri', u'value': u'http://test/person/'},
                  u'predicate_comment': {u'xml:lang': u'pt', u'type': u'literal', u'value': u'Nome completo da pessoa'},
                  u'type': {u'type': u'uri', u'value': u'http://www.w3.org/2002/07/owl#DatatypeProperty'}}
     cardinalities = {}
     context = prefixes.MemorizeContext(normalize_uri=SHORTEN)
     context.prefix_to_slug('http://test/person')
     # test call
     effective_predicate_dict = assemble_predicate(name, predicate, cardinalities, context)
     self.assertEqual(len(context.object_properties), 0)
     self.assertEqual(expected_predicate_dict, effective_predicate_dict)
     self.assertEqual(context.context, {})
Esempio n. 2
0
    def test_assemble_predicate_with_object_property(self):
        expected_predicate_dict = {'description': u'G\xeanero.',
                                   'range': {'graph': u'http://test/person/',
                                             '@id': u'http://test/person/Gender',
                                             'title': u'G\xeanero da Pessoa',
                                             'type': 'string',
                                             'format': 'uri'},
                                   'graph': u'http://test/person/',
                                   'class': u'http://test/person/AnyClass',
                                   'format': 'uri',
                                   'title': u'Sexo',
                                   'type': 'string'}
        name = u'http://test/person/gender'
        predicate = {u'predicate': {u'type': u'uri', u'value': u'http://test/person/gender'},
                     u'domain_class': {u'type': u'uri', u'value': u'http://test/person/AnyClass'},
                     u'range': {u'type': u'uri', u'value': u'http://test/person/Gender'},
                     u'range_graph': {u'type': u'uri', u'value': u'http://test/person/'},
                     u'range_label': {u'xml:lang': u'pt', u'type': u'literal', u'value': u'G\xeanero da Pessoa'},
                     u'title': {u'xml:lang': u'pt', u'type': u'literal', u'value': u'Sexo'},
                     u'predicate_graph': {u'typce': u'uri', u'value': u'http://test/person/'},
                     u'predicate_comment': {u'xml:lang': u'pt', u'type': u'literal', u'value': u'G\xeanero.'},
                     u'type': {u'type': u'uri', u'value': u'http://www.w3.org/2002/07/owl#ObjectProperty'}}
        cardinalities = {u'http://test/person/gender': {u'http://test/person/Gender': {'minItems': 1, 'maxItems': 1}}}
        context = prefixes.MemorizeContext(normalize_uri=SHORTEN)
        context.prefix_to_slug('http://test/person')
        # test call

        effective_predicate_dict = assemble_predicate(name, predicate, cardinalities, context)
        self.assertEqual(context.object_properties, {'test:gender': 'test:Gender'})
        self.assertEqual(context.context, {})
        self.assertEqual(expected_predicate_dict, effective_predicate_dict)
Esempio n. 3
0
 def test_ignore_annotation_properties(self):
     name = u'http://test/person/gender'
     predicate = {u'predicate': {u'type': u'uri', u'value': u'http://test/person/gender'},
                  u'domain_class': {u'type': u'uri', u'value': u'http://test/person/AnyClass'},
                  u'range': {u'type': u'uri', u'value': u'http://test/person/Gender'},
                  u'range_graph': {u'type': u'uri', u'value': u'http://test/person/'},
                  u'range_label': {u'xml:lang': u'pt', u'type': u'literal', u'value': u'G\xeanero da Pessoa'},
                  u'title': {u'xml:lang': u'pt', u'type': u'literal', u'value': u'Sexo'},
                  u'predicate_graph': {u'typce': u'uri', u'value': u'http://test/person/'},
                  u'predicate_comment': {u'xml:lang': u'pt', u'type': u'literal', u'value': u'G\xeanero.'},
                  u'type': {u'type': u'uri', u'value': u'http://www.w3.org/2002/07/owl#AnnotationProperty'}}
     cardinalities = {u'http://test/person/gender': {u'http://test/person/Gender': {'minItems': 1, 'maxItems': 1}}}
     context = prefixes.MemorizeContext(normalize_uri=SHORTEN)
     context.prefix_to_slug('http://test/person')
     with self.assertRaises(schema.InstanceError) as error:
         assemble_predicate(name, predicate, cardinalities, context)
         self.assertEqual(error.exception, "InstanceError: Predicates of type http://www.w3.org/2002/07/owl#AnnotationProperty are not supported yet")
Esempio n. 4
0
 def test_assemble_predicate_cardinality_influences_type(self):
     predicate_uri = "http://example.onto/hasChild"
     binding_row = {
         u'domain_class': {u'type': u'uri', u'value': u'http://example.onto/Human'},
         u'predicate': {u'type': u'uri', u'value': u'http://example.onto/hasChild'},
         u'predicate_graph': {u'type': u'uri', u'value': u'http://test.com/'},
         u'range': {u'type': u'uri', u'value': u'http://example.onto/Human'},
         u'range_graph': {u'type': u'uri', u'value': u'http://test.com/'},
         u'range_label': {u'type': u'literal', u'value': u'Humano', u'xml:lang': u'pt'},
         u'title': {u'type': u'literal', u'value': u'Has child (son or daughter)'},
         u'type': {u'type': u'uri', u'value': u'http://www.w3.org/2002/07/owl#ObjectProperty'}
     }
     cardinalities = {
         u'http://example.onto/furColour': {
             u'http://example.onto/FurColour': {'minItems': 1, 'required': True}
         },
         u'http://example.onto/gender': {
             u'http://example.onto/Gender': {'maxItems': 1, 'minItems': 1, 'required': True}
         },
         u'http://example.onto/hasChild': {
             u'http://example.onto/Human': {'maxItems': 888}
         },
         u'http://example.onto/hasParent': {
             u'http://example.onto/Human': {'maxItems': 2}
         }
     }
     context = prefixes.MemorizeContext(normalize_uri=SHORTEN)
     context.prefix_to_slug('http://test/person')
     computed = assemble_predicate(predicate_uri, binding_row, cardinalities, context)
     expected = {
         'class': u'http://example.onto/Human',
         'graph': u'http://test.com/',
         'items': {
             'format': 'uri',
             'type': 'string'
         },
         'maxItems': 888,
         'range': {
             '@id': u'http://example.onto/Human',
             'format': 'uri',
             'graph': u'http://test.com/',
             'title': u'Humano',
             'type': 'string'
         },
         'title': u'Has child (son or daughter)',
         'type': 'array'
     }
     self.assertEqual(computed, expected)