コード例 #1
0
 def test_count_query_without_extras(self):
     params = self.default_params
     query = Query(params)
     computed = query.to_string(count=True)
     expected = """
     SELECT count(DISTINCT ?subject) as ?total
     WHERE {
         GRAPH <http://some.graph/> { ?subject a <http://some.graph/SomeClass> OPTION(inference "http://semantica.globo.com/ruleset");
                  <http://www.w3.org/2000/01/rdf-schema#label> ?label .
                  }
     }
     """
     self.assertEqual(strip(computed), strip(expected))
コード例 #2
0
 def test_query_with_predicate_as_rdfs_label(self):
     params = self.default_params.copy()
     params["p"] = "rdfs:label"
     query = Query(params)
     computed = query.to_string()
     expected = """
     SELECT DISTINCT ?label, ?subject
     WHERE {
         GRAPH <http://some.graph/> { ?subject a <http://some.graph/SomeClass> OPTION(inference "http://semantica.globo.com/ruleset");
                  <http://www.w3.org/2000/01/rdf-schema#label> ?label .
                  }
     }
     LIMIT 10
     OFFSET 0
     """
     self.assertEqual(strip(computed), strip(expected))
コード例 #3
0
 def test_query_with_sort_by(self):
     params = self.default_params.copy()
     params["sort_by"] = "dbpedia:predicate"
     params["sort_order"] = "asc"
     query = Query(params)
     computed = query.to_string()
     expected = """
     SELECT DISTINCT ?label, ?sort_object, ?subject
     WHERE {
         GRAPH <http://some.graph/> { ?subject a <http://some.graph/SomeClass> OPTION(inference "http://semantica.globo.com/ruleset");
                  <http://www.w3.org/2000/01/rdf-schema#label> ?label .
         OPTIONAL {?subject <http://dbpedia.org/ontology/predicate> ?sort_object} }
     }
     ORDER BY ASC(?sort_object)
     LIMIT 10
     OFFSET 0
     """
     self.assertEqual(strip(computed), strip(expected))
コード例 #4
0
 def test_query_with_predicate_and_object_as_literal(self):
     params = self.default_params.copy()
     params["p"] = "schema:Creature"
     params["o"] = "Xubiru"
     query = Query(params)
     computed = query.to_string()
     expected = """
     SELECT DISTINCT ?label, ?subject
     WHERE {
         GRAPH <http://some.graph/> { ?subject a <http://some.graph/SomeClass> OPTION(inference "http://semantica.globo.com/ruleset");
                  <http://www.w3.org/2000/01/rdf-schema#label> ?label ;
                  <http://schema.org/Creature> ?literal1 .
                  }
         FILTER(str(?literal1) = "Xubiru") .
     }
     LIMIT 10
     OFFSET 0
     """
     self.assertEqual(strip(computed), strip(expected))
コード例 #5
0
 def test_query_with_sort_by_object_of_predicate(self):
     params = self.default_params.copy()
     params["p"] = "schema:another_predicate"
     params["sort_by"] = "schema:another_predicate"
     params["sort_order"] = "desc"
     query = Query(params)
     computed = query.to_string()
     expected = """
     SELECT DISTINCT ?label, ?object, ?subject
     WHERE {
         GRAPH <http://some.graph/> { ?subject a <http://some.graph/SomeClass> OPTION(inference "http://semantica.globo.com/ruleset");
                  <http://www.w3.org/2000/01/rdf-schema#label> ?label ;
                  <http://schema.org/another_predicate> ?object .
                  }
     }
     ORDER BY DESC(?object)
     LIMIT 10
     OFFSET 0
     """
     self.assertEqual(strip(computed), strip(expected))
コード例 #6
0
    def test_query_with_p1_o1_p2_o2(self):
        params = self.default_params.copy()
        params["p1"] = "some:predicate"
        params["o1"] = "some:object"
        params["p2"] = "another:predicate"
        params["o2"] = "?another_object"
        query = Query(params)
        computed = query.to_string()
        expected = """
        SELECT DISTINCT ?another_object, ?label, ?subject
        WHERE {
            GRAPH <http://some.graph/> { ?subject a <http://some.graph/SomeClass> OPTION(inference "http://semantica.globo.com/ruleset");
                     <http://www.w3.org/2000/01/rdf-schema#label> ?label ;
                     another:predicate ?another_object ;
                     some:predicate some:object .
                     }
        }

        LIMIT 10
        OFFSET 0
        """
        self.assertEqual(strip(computed), strip(expected))