Coverage for apis_core/apis_entities/rdfconfigs/place.py: 100%

20 statements  

« prev     ^ index     » next       coverage.py v7.5.3, created at 2026-02-19 10:33 +0000

1from apis_core.utils.rdf import Attribute, Filter 

2 

3 

4class PlaceFromDNB: 

5 filter_type_is_naturalgeographicunit = Filter( 

6 [("rdf:type", "gndo:NaturalGeographicUnit")] 

7 ) 

8 filter_type_is_tcb_or_adu = Filter( 

9 [("rdf:type", "gndo:TerritorialCorporateBodyOrAdministrativeUnit")] 

10 ) 

11 

12 label = Attribute("gndo:preferredNameForThePlaceOrGeographicName") 

13 longitude = Attribute(""" 

14 SELECT ?longitude 

15 WHERE { 

16 ?subject geo:hasGeometry/geo:asWKT ?point . 

17 BIND(REPLACE(str(?point), "Point \\( \\+?(-?\\d+.\\d+).*", "$1") as ?longitude) 

18 } 

19 """) 

20 latitude = Attribute(""" 

21 SELECT ?latitude 

22 WHERE { 

23 ?subject geo:hasGeometry/geo:asWKT ?point . 

24 BIND(REPLACE(str(?point), "^Point\\s*\\(\\s*[+-]?\\d+\\.\\d+\\s+([+-]?\\d+\\.\\d+)\\s*\\)$", "$1") as ?latitude) 

25 } 

26 """) 

27 same_as = Attribute("owl:sameAs") 

28 

29 

30class PlaceFromGeonames: 

31 filter_type_is_feature = Filter([("rdf:type", "gn:Feature")]) 

32 

33 label = Attribute(["gn:name", "gn:officialName", "gn:alternateName"]) 

34 latitude = Attribute("wgs84_pos:lat") 

35 longitude = Attribute("wgs84_pos:long") 

36 same_as = Attribute(["rdfs:seeAlso", "gn:wikipediaArticle"]) 

37 

38 

39class PlaceFromWikidata: 

40 filter_p625_must_exist = Filter([("wdt:P625", True)]) 

41 

42 label = Attribute( 

43 [ 

44 "rdfs:label,de", 

45 "rdfs:label,en", 

46 "wdt:P1448/rdfs:label", 

47 "rdfs:label", 

48 ] 

49 ) 

50 longitude = Attribute(""" 

51 SELECT ?longitude 

52 WHERE { 

53 ?subject wdt:P625 ?geo1 . 

54 BIND(REPLACE(str(?geo1), "Point\\(([-+]?\\d+\\.?\\d+).*$", "$1") as ?longitude) 

55 } 

56 """) 

57 latitude = Attribute(""" 

58 SELECT ?latitude 

59 WHERE { 

60 ?subject wdt:P625 ?geo1 . 

61 BIND(REPLACE(str(?geo1), "Point\\(([-+]?\\d+\\.?\\d+) ([-+]?\\d+\\.?\\d+).*$", "$2") as ?latitude) 

62 } 

63 """) 

64 same_as = Attribute( 

65 ["owl:sameAs", "wdtn:P227", "wdtn:P1566", "wdtn:P214", "wdtn:P244"] 

66 )