예제 #1
0
    def test8_mondialeurope_rdf_auto(self):

        query = """prefix : <http://www.semwebtech.org/mondial/10/meta#>
                SELECT ?N1 ?N2
                WHERE {
                ?X1 a :Country; :capital ?Y1 .
                ?Y1 :name ?N1; :latitude ?lat1; :longitude ?long1 .
                ?X2 a :Country; :capital ?Y2 .
                ?Y2 :name ?N2; :latitude ?lat2; :longitude ?long2 .
                FILTER (?N1 < ?N2)
                Filter (?N1 = "Vaduz")
                }"""

        path = "test/data/sparql_helper/mondial-europe.rdf"

        SparqlPlayground = LocalEndpoint(path)

        SparqlPlayground.initialize()

        result = SparqlPlayground.query(query).sort_values(
            by=["N2"]).reset_index(drop=True)

        expected_result_df = pd.DataFrame({
            "N1": ["Vaduz", "Vaduz", "Vaduz", "Vaduz", "Vaduz", "Vaduz"],
            "N2": [
                "Vatican City", "Vilnius", "Zagreb", "Wien", "Warszawa",
                "Valletta"
            ]
        }).sort_values(by=["N2"]).reset_index(drop=True)

        pd.testing.assert_frame_equal(result, expected_result_df)
예제 #2
0
    def test6_wikidata_n3_auto(self):

        query = "SELECT ?p ?o WHERE {<https://en.wikiquote.org/wiki/Douglas_Adams> ?p ?o .}"

        path = "test/data/sparql_helper/Q42.n3"

        SparqlPlayground = LocalEndpoint(path)

        SparqlPlayground.initialize()

        result = SparqlPlayground.query(query).sort_values(
            by=["p"]).reset_index(drop=True)

        expected_result_df = pd.DataFrame({
            "p": [
                "http://schema.org/inLanguage", "http://schema.org/isPartOf",
                "http://www.w3.org/1999/02/22-rdf-syntax-ns#type",
                "http://schema.org/name", "http://schema.org/about"
            ],
            "o": [
                "en", "https://en.wikiquote.org/", "http://schema.org/Article",
                "Douglas Adams", "http://www.wikidata.org/entity/Q42"
            ]
        }).sort_values(by=["p"]).reset_index(drop=True)

        pd.testing.assert_frame_equal(result, expected_result_df)
예제 #3
0
    def test4_sparqlplayground_ttl_auto(self):

        query = "select ?person ?pet where {?person rdf:type dbo:Person . ?person tto:pet ?pet .}"

        path = "test/data/sparql_helper/sparqlplayground.ttl"

        SparqlPlayground = LocalEndpoint(path)

        SparqlPlayground.initialize()

        result = SparqlPlayground.query(query).sort_values(
            by=["person"]).reset_index(drop=True)

        expected_result_df = pd.DataFrame({
            "person": [
                "http://example.org/tuto/resource#William",
                "http://example.org/tuto/resource#John",
                "http://example.org/tuto/resource#John"
            ],
            "pet": [
                "http://example.org/tuto/resource#RexDog",
                "http://example.org/tuto/resource#LunaCat",
                "http://example.org/tuto/resource#TomCat"
            ]
        }).sort_values(by=["person"]).reset_index(drop=True)

        pd.testing.assert_frame_equal(result, expected_result_df)
예제 #4
0
    def test11_wrongfile(self):

        with pytest.raises(xml.sax.SAXParseException):
            path = "test/data/sparql_helper/file.random"

            SparqlPlayground = LocalEndpoint(path)

            SparqlPlayground.initialize()
예제 #5
0
    def test9_wrongpath(self):

        with pytest.raises(FileNotFoundError):
            path = "test/data/sparql_helper/sparqlplaygroundWRONG.ttl"

            SparqlPlayground = LocalEndpoint(path)

            SparqlPlayground.initialize()
예제 #6
0
    def test1_nobleprize_nt(self):

        query = "PREFIX nobel: <http://data.nobelprize.org/terms/> PREFIX foaf: <http://xmlns.com/foaf/0.1/> PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> SELECT DISTINCT ?label WHERE { ?laur rdf:type nobel:Laureate . ?laur rdfs:label ?label . ?laur foaf:gender \"female\" . ?laur nobel:laureateAward ?award . ?award nobel:category <http://data.nobelprize.org/resource/category/Physics> . }"

        path = "test/data/sparql_helper/nobelprize_dump.nt"

        NoblePrize = LocalEndpoint(path, "nt")

        NoblePrize.initialize()

        result = NoblePrize.query(query).sort_values(by=["label"]).reset_index(
            drop=True)

        expected_result_df = pd.DataFrame({
            "label": [
                "Marie Curie, née Sklodowska", "Donna Strickland",
                "Maria Goeppert Mayer"
            ],
        }).sort_values(by=["label"]).reset_index(drop=True)

        pd.testing.assert_frame_equal(result, expected_result_df)
예제 #7
0
    def test10_brokenquery(self):

        with pytest.raises(pyparsing.ParseException):
            path = "test/data/sparql_helper/sparqlplayground.ttl"

            SparqlPlayground = LocalEndpoint(path)

            SparqlPlayground.initialize()

            SparqlPlayground.query("SELECT *")