def test_assemble_instance_json_with_an_object_which_does_not_have_label(self, mlogger, mdebug, msettings):
     bindings = [
         {
             u'predicate': {u'type': u'uri', u'value': u'http://brmedia.com/related_to'},
             u'object': {u'type': u'uri', u'value': u'http://dbpedia.org/ontology/Cricket'},
         }
     ]
     class_schema = mock_schema({
         u'http://www.w3.org/2000/01/rdf-schema#label': "string",
         u'http://www.w3.org/1999/02/22-rdf-syntax-ns#type': "string",
         u'http://brmedia.com/related_to': "string_uri"
     }, "http://dbpedia.org/ontology/News")
     get_instance.build_items_dict(bindings, "http://dbpedia.org/ontology/News", 1, class_schema)
     expected_msg = "The predicate http://brmedia.com/related_to refers to an object http://dbpedia.org/ontology/Cricket which doesn't have a label. Set expand_object_properties=0 if you don't care about this ontological inconsistency."
     self.assertTrue(mdebug.called)
     self.assertEqual(mdebug.call_args[0][0], expected_msg)
 def test_assemble_instance_json_with_object_labels(self):
     bindings = [
         {
             u'predicate': {u'type': u'uri', u'value': u'http://www.w3.org/2000/01/rdf-schema#label'},
             u'object': {u'type': u'literal', u'value': u'Cricket becomes the most popular sport of Brazil'}
         },
         {
             u'predicate': {u'type': u'uri', u'value': u'http://www.w3.org/1999/02/22-rdf-syntax-ns#type'},
             u'object': {u'type': u'uri', u'value': u'http://dbpedia.org/ontology/News'},
             u'object_label': {u'type': u'literal', u'value': u'News'}
         },
         {
             u'predicate': {u'type': u'uri', u'value': u'http://brmedia.com/related_to'},
             u'object': {u'type': u'uri', u'value': u'http://dbpedia.org/ontology/Cricket'},
             u'object_label': {u'type': u'literal', u'value': u'Cricket'}
         }
     ]
     class_schema = mock_schema({
         u'http://www.w3.org/2000/01/rdf-schema#label': "string",
         u'http://www.w3.org/1999/02/22-rdf-syntax-ns#type': "string",
         u'http://brmedia.com/related_to': "string_uri"
     }, "http://dbpedia.org/ontology/News")
     computed = get_instance.build_items_dict(bindings, "http://dbpedia.org/ontology/News", 1, class_schema)
     expected = {
         u'http://www.w3.org/2000/01/rdf-schema#label': u'Cricket becomes the most popular sport of Brazil',
         u'http://www.w3.org/1999/02/22-rdf-syntax-ns#type': 'http://dbpedia.org/ontology/News',
         u'http://brmedia.com/related_to': {"@id": "http://dbpedia.org/ontology/Cricket", "title": u"Cricket"}
     }
     self.assertEqual(computed, expected)
 def test_build_items_dict_with_blank_nodes(self):
     bindings = [
         {"predicate": {"value": "key1"}, "object": {"value": 1}, "label": {"value": "label1"}, "is_object_blank": {"value": "1"}},
         {"predicate": {"value": "key1"}, "object": {"value": 2}, "label": {"value": "label1"}},
         {"predicate": {"value": "key2"}, "object": {"value": "value2"}, "label": {"value": "label1"}}
     ]
     class_schema = {
         "properties": {
             "key1": {
                 "type": "array",
                 "items": {
                     "type": "integer"
                 },
                 "datatype": "http://www.w3.org/2001/XMLSchema#integer"
             },
             "key2": {
                 "type": "string",
                 "datatype": "http://www.w3.org/2001/XMLSchema#string"
             },
             "rdf:type": {
                 "type": "string",
                 "datatype": "http://www.w3.org/2001/XMLSchema#string"
             }
         }
     }
     expected = {
         "key1": [2],
         "key2": "value2",
         u'http://www.w3.org/1999/02/22-rdf-syntax-ns#type': "some:Class"}
     response = get_instance.build_items_dict(bindings, "some:Class", True, class_schema)
     self.assertEqual(response, expected)
 def test_build_items_dict(self):
     bindings = [{
         "predicate": {
             "value": "key1"
         },
         "object": {
             "value": 1
         },
         "label": {
             "value": "label1"
         }
     }, {
         "predicate": {
             "value": "key1"
         },
         "object": {
             "value": 2
         },
         "label": {
             "value": "label1"
         }
     }, {
         "predicate": {
             "value": "key2"
         },
         "object": {
             "value": "value2"
         },
         "label": {
             "value": "label1"
         }
     }]
     class_schema = {
         "properties": {
             "key1": {
                 "type": "array",
                 "items": {
                     "type": "integer"
                 },
                 "datatype": u'http://www.w3.org/2001/XMLSchema#integer'
             },
             "key2": {
                 "type": "string",
                 "datatype": u'http://www.w3.org/2001/XMLSchema#string'
             },
             "rdf:type": {
                 "type": "string",
                 "datatype": u'http://www.w3.org/2001/XMLSchema#string'
             }
         }
     }
     expected = {
         "key1": [1, 2],
         "key2": "value2",
         u'http://www.w3.org/1999/02/22-rdf-syntax-ns#type': "some:Class"
     }
     response = get_instance.build_items_dict(bindings, "some:Class", True,
                                              class_schema)
     self.assertEqual(response, expected)
 def test_assemble_instance_json_with_object_labels(self):
     bindings = [{
         u'predicate': {
             u'type': u'uri',
             u'value': u'http://www.w3.org/2000/01/rdf-schema#label'
         },
         u'object': {
             u'type': u'literal',
             u'value': u'Cricket becomes the most popular sport of Brazil'
         }
     }, {
         u'predicate': {
             u'type': u'uri',
             u'value': u'http://www.w3.org/1999/02/22-rdf-syntax-ns#type'
         },
         u'object': {
             u'type': u'uri',
             u'value': u'http://dbpedia.org/ontology/News'
         },
         u'object_label': {
             u'type': u'literal',
             u'value': u'News'
         }
     }, {
         u'predicate': {
             u'type': u'uri',
             u'value': u'http://brmedia.com/related_to'
         },
         u'object': {
             u'type': u'uri',
             u'value': u'http://dbpedia.org/ontology/Cricket'
         },
         u'object_label': {
             u'type': u'literal',
             u'value': u'Cricket'
         }
     }]
     class_schema = mock_schema(
         {
             u'http://www.w3.org/2000/01/rdf-schema#label': "string",
             u'http://www.w3.org/1999/02/22-rdf-syntax-ns#type': "string",
             u'http://brmedia.com/related_to': "string_uri"
         }, "http://dbpedia.org/ontology/News")
     computed = get_instance.build_items_dict(
         bindings, "http://dbpedia.org/ontology/News", 1, class_schema)
     expected = {
         u'http://www.w3.org/2000/01/rdf-schema#label':
         u'Cricket becomes the most popular sport of Brazil',
         u'http://www.w3.org/1999/02/22-rdf-syntax-ns#type':
         'http://dbpedia.org/ontology/News',
         u'http://brmedia.com/related_to': {
             "@id": "http://dbpedia.org/ontology/Cricket",
             "title": u"Cricket"
         }
     }
     self.assertEqual(computed, expected)
    def test_build_items_dict_with_super_property_and_same_value(self):
        bindings = self.prepare_input_and_expected_output(object_value="Rio de Janeiro")
        class_schema = mock_schema({
            u'birthPlace': "string",
            u'birthCity': "string",
        }, "http://class.uri")

        expected = {
            "birthCity": "Rio de Janeiro",
            'http://www.w3.org/1999/02/22-rdf-syntax-ns#type': 'http://class.uri'
        }
        response = get_instance.build_items_dict(bindings, "http://class.uri", False, class_schema)

        self.assertEqual(response, expected)
 def test_assemble_instance_json_with_an_object_which_does_not_have_label(
         self, mlogger, mdebug, msettings):
     bindings = [{
         u'predicate': {
             u'type': u'uri',
             u'value': u'http://brmedia.com/related_to'
         },
         u'object': {
             u'type': u'uri',
             u'value': u'http://dbpedia.org/ontology/Cricket'
         },
     }]
     class_schema = mock_schema(
         {
             u'http://www.w3.org/2000/01/rdf-schema#label': "string",
             u'http://www.w3.org/1999/02/22-rdf-syntax-ns#type': "string",
             u'http://brmedia.com/related_to': "string_uri"
         }, "http://dbpedia.org/ontology/News")
     get_instance.build_items_dict(bindings,
                                   "http://dbpedia.org/ontology/News", 1,
                                   class_schema)
     expected_msg = "The predicate http://brmedia.com/related_to refers to an object http://dbpedia.org/ontology/Cricket which doesn't have a label. Set expand_object_properties=0 if you don't care about this ontological inconsistency."
     self.assertTrue(mdebug.called)
     self.assertEqual(mdebug.call_args[0][0], expected_msg)
    def test_build_items_dict_with_super_property_and_same_value(self):
        bindings = self.prepare_input_and_expected_output(
            object_value="Rio de Janeiro")
        class_schema = mock_schema(
            {
                u'birthPlace': "string",
                u'birthCity': "string",
            }, "http://class.uri")

        expected = {
            "birthCity": "Rio de Janeiro",
            'http://www.w3.org/1999/02/22-rdf-syntax-ns#type':
            'http://class.uri'
        }
        response = get_instance.build_items_dict(bindings, "http://class.uri",
                                                 False, class_schema)

        self.assertEqual(response, expected)