Beispiel #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, {})
Beispiel #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)
Beispiel #3
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)
Beispiel #4
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")
Beispiel #5
0
    def test_get_predicates_and_cardinalities(self):

        # Mocks
        fake_response_predicates = {"results": {"bindings": [
            {
                "predicate": {"type": "uri", "value": "http://test/person/root_gender"},
                "predicate_graph": {"type": "uri", "value": "http://test/person/"},
                "type": {"type": "uri", "value": "http://www.w3.org/2002/07/owl#ObjectProperty"},
                "range": {"type": "uri", "value": "http://test/person/Gender"},
                "title": {"type": "literal", "xml:lang": "pt", "value": "Root (to be removed from answer)"},
                "range_graph": {"type": "uri", "value": "http://test/person/"},
                "domain_class": {"type": "uri", "value": "http://test/person/Gender"},

            },
            {
                "predicate": {"type": "uri", "value": "http://test/person/gender"},
                "super_property": {"type": "uri", "value": "http://test/person/root_gender"},
                "predicate_graph": {"type": "uri", "value": "http://test/person/"},
                "predicate_comment": {"type": "literal", "xml:lang": "pt", "value": u"G\u00EAnero."},
                "type": {"type": "uri", "value": "http://www.w3.org/2002/07/owl#ObjectProperty"},
                "range": {"type": "uri", "value": "http://test/person/Gender"},
                "title": {"type": "literal", "xml:lang": "pt", "value": "Sexo"},
                "range_label": {"type": "literal", "xml:lang": "pt", "value": u"G\u00EAnero da Pessoa"},
                "range_graph": {"type": "uri", "value": "http://test/person/"},
                "domain_class": {"type": "uri", "value": "http://test/person/Gender"},
            }
        ]}}

        fake_response_cardinalities = {"results": {
            "bindings": [
                {"max": {"datatype": "http://www.w3.org/2001/XMLSchema#integer", "type": "typed-literal", "value": "1"},
                 "predicate": {"type": "uri", "value": "http://test/person/gender"},
                 "range": {"type": "uri", "value": "http://test/person/Gender"}
                 },
                {"min": {"datatype": "http://www.w3.org/2001/XMLSchema#integer", "type": "typed-literal", "value": "1"},
                 "predicate": {"type": "uri", "value": "http://test/person/gender"},
                 "range": {"type": "uri", "value": "http://test/person/Gender"}
                 },
                {"predicate": {"type": "uri", "value": "http://test/person/gender"},
                 "range": {"type": "bnode", "value": "nodeID://b72146"}
                 },
                {"predicate": {"type": "uri", "value": "http://test/person/gender"},
                 "range": {"type": "bnode", "value": "nodeID://b72146"}
                 }
            ]}
        }

        schema.query_cardinalities = lambda query: fake_response_cardinalities
        schema.query_predicates = lambda query, superclass: fake_response_predicates

        context = prefixes.MemorizeContext(normalize_uri=SHORTEN)
        handler = MockHandler()
        params = ParamDict(handler, class_uri="http://test/person/gender")

        response_predicates_and_cardinalities = schema.get_predicates_and_cardinalities(
            context, params, superclasses=["http://test/person/Gender"])
        expected_predicates_and_cardinalities = {
            'http://test/person/gender': {
                'description': u'G\xeanero.',
                'title': 'Sexo',
                'graph': 'http://test/person/',
                'format': 'uri',
                'required': True,
                'type': 'string',
                'class': 'http://test/person/Gender',
                'range': {'graph': 'http://test/person/',
                          '@id': 'http://test/person/Gender',
                          'title': u'G\xeanero da Pessoa',
                          'format': 'uri',
                          'type': 'string'
                          }
            }
        }
        self.assertEqual(response_predicates_and_cardinalities, expected_predicates_and_cardinalities)
        self.stop()