def test_to_graph_should_return_link_to_spatial_coverage_with_location_triple( ) -> None: """It returns a spatial coverage graph isomorphic to spec.""" dataset = Dataset() dataset.identifier = "http://example.com/datasets/1" # Create location: location = Location() location.identifier = "http://example.com/locations/1" location.centroid = "POINT(4.88412 52.37509)" # Add location to dataset: dataset.spatial_coverage = location src = """ @prefix dct: <http://purl.org/dc/terms/> . @prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> . @prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> . @prefix dcat: <http://www.w3.org/ns/dcat#> . @prefix geosparql: <http://www.opengis.net/ont/geosparql#> . <http://example.com/datasets/1> a dcat:Dataset ; dct:spatial <http://example.com/locations/1> ; . <http://example.com/locations/1> a dct:Location ; dcat:centroid "POINT(4.88412 52.37509)"^^geosparql:asWKT ; . """ g1 = Graph().parse(data=dataset.to_rdf(), format="turtle") g2 = Graph().parse(data=src, format="turtle") _isomorphic = isomorphic(g1, g2) if not _isomorphic: _dump_diff(g1, g2) pass assert _isomorphic
def test_to_graph_should_return_identifier_set_at_constructor() -> None: """It returns a centroid graph isomorphic to spec.""" location = Location("http://example.com/locations/1") location.centroid = "POINT(4.88412 52.37509)" src = """ @prefix dct: <http://purl.org/dc/terms/> . @prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> . @prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> . @prefix dcat: <http://www.w3.org/ns/dcat#> . @prefix locn: <http://www.w3.org/ns/locn#> . @prefix geosparql: <http://www.opengis.net/ont/geosparql#> . <http://example.com/locations/1> a dct:Location ; dcat:centroid "POINT(4.88412 52.37509)"^^geosparql:asWKT ; . """ g1 = Graph().parse(data=location.to_rdf(), format="turtle") g2 = Graph().parse(data=src, format="turtle") _isomorphic = isomorphic(g1, g2) if not _isomorphic: _dump_diff(g1, g2) pass assert _isomorphic
def test_to_graph_should_return_bounding_box_as_graph() -> None: """It returns a bounding box graph isomorphic to spec.""" location = Location() location.identifier = "http://example.com/locations/1" location.bounding_box = """POLYGON (( 3.053 47.975 , 7.24 47.975 , 7.24 53.504 , 3.053 53.504 , 3.053 47.975 ))""" src = """ @prefix dct: <http://purl.org/dc/terms/> . @prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> . @prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> . @prefix dcat: <http://www.w3.org/ns/dcat#> . @prefix locn: <http://www.w3.org/ns/locn#> . @prefix geosparql: <http://www.opengis.net/ont/geosparql#> . <http://example.com/locations/1> a dct:Location ; dcat:bbox \"\"\"POLYGON (( 3.053 47.975 , 7.24 47.975 , 7.24 53.504 , 3.053 53.504 , 3.053 47.975 ))\"\"\"^^geosparql:asWKT ; . """ g1 = Graph().parse(data=location.to_rdf(), format="turtle") g2 = Graph().parse(data=src, format="turtle") _isomorphic = isomorphic(g1, g2) if not _isomorphic: _dump_diff(g1, g2) pass assert _isomorphic
def test_create_location(self): expected_location = Location() expected_location.identifier = URI("http://sws.geonames.org/3144096/") countries = ["Norge", "Norway"] for country in countries: location = create_location(country) self.assertEqual(expected_location.identifier, location.identifier)
def test_to_graph_should_return_location_skolemized( mocker: MockFixture) -> None: """It returns a title graph isomorphic to spec.""" location = Location() location.geometry = """POLYGON (( 4.8842353 52.375108 , 4.884276 52.375153 , 4.8842567 52.375159 , 4.883981 52.375254 , 4.8838502 52.375109 , 4.883819 52.375075 , 4.8841037 52.374979 , 4.884143 52.374965 , 4.8842069 52.375035 , 4.884263 52.375016 , 4.8843200 52.374996 , 4.884255 52.374926 , 4.8843289 52.374901 , 4.884451 52.375034 , 4.8842353 52.375108 ))""" src = """ @prefix dct: <http://purl.org/dc/terms/> . @prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> . @prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> . @prefix dcat: <http://www.w3.org/ns/dcat#> . @prefix locn: <http://www.w3.org/ns/locn#> . @prefix geosparql: <http://www.opengis.net/ont/geosparql#> . <http://wwww.digdir.no/.well-known/skolem/284db4d2-80c2-11eb-82c3-83e80baa2f94> a dct:Location ; locn:geometry \"\"\"POLYGON (( 4.8842353 52.375108 , 4.884276 52.375153 , 4.8842567 52.375159 , 4.883981 52.375254 , 4.8838502 52.375109 , 4.883819 52.375075 , 4.8841037 52.374979 , 4.884143 52.374965 , 4.8842069 52.375035 , 4.884263 52.375016 , 4.8843200 52.374996 , 4.884255 52.374926 , 4.8843289 52.374901 , 4.884451 52.375034 , 4.8842353 52.375108 ))\"\"\"^^geosparql:asWKT ; . """ mocker.patch( "skolemizer.Skolemizer.add_skolemization", return_value=skolemization, ) g1 = Graph().parse(data=location.to_rdf(), format="turtle") g2 = Graph().parse(data=src, format="turtle") _isomorphic = isomorphic(g1, g2) if not _isomorphic: _dump_diff(g1, g2) pass assert _isomorphic
def test_to_graph_should_return_geometry_as_graph() -> None: """It returns a title graph isomorphic to spec.""" location = Location() location.identifier = "http://example.com/locations/1" location.geometry = """POLYGON (( 4.8842353 52.375108 , 4.884276 52.375153 , 4.8842567 52.375159 , 4.883981 52.375254 , 4.8838502 52.375109 , 4.883819 52.375075 , 4.8841037 52.374979 , 4.884143 52.374965 , 4.8842069 52.375035 , 4.884263 52.375016 , 4.8843200 52.374996 , 4.884255 52.374926 , 4.8843289 52.374901 , 4.884451 52.375034 , 4.8842353 52.375108 ))""" src = """ @prefix dct: <http://purl.org/dc/terms/> . @prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> . @prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> . @prefix dcat: <http://www.w3.org/ns/dcat#> . @prefix locn: <http://www.w3.org/ns/locn#> . @prefix geosparql: <http://www.opengis.net/ont/geosparql#> . <http://example.com/locations/1> a dct:Location ; locn:geometry \"\"\"POLYGON (( 4.8842353 52.375108 , 4.884276 52.375153 , 4.8842567 52.375159 , 4.883981 52.375254 , 4.8838502 52.375109 , 4.883819 52.375075 , 4.8841037 52.374979 , 4.884143 52.374965 , 4.8842069 52.375035 , 4.884263 52.375016 , 4.8843200 52.374996 , 4.884255 52.374926 , 4.8843289 52.374901 , 4.884451 52.375034 , 4.8842353 52.375108 ))\"\"\"^^geosparql:asWKT ; . """ g1 = Graph().parse(data=location.to_rdf(), format="turtle") g2 = Graph().parse(data=src, format="turtle") _isomorphic = isomorphic(g1, g2) if not _isomorphic: _dump_diff(g1, g2) pass assert _isomorphic
def create_location(spatial: str) -> Location: location = Location() location.identifier = URI("http://sws.geonames.org/3144096/") return location