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

20 statements  

« prev     ^ index     » next       coverage.py v7.15.2, created at 2026-09-14 10:55 +0000

1from apis_core.utils.rdf import Attribute, Filter 

2 

3 

4class E53_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 E53_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 E53_PlaceFromWikidata: 

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

41 

42 label = Attribute( 

43 [ 

44 """ 

45 SELECT ?label 

46 WHERE { 

47 ?subject wdt:P625 ?coordinates . 

48 ?subject rdfs:label ?label . 

49 FILTER(lang(?label) = "de") 

50 } """, 

51 """ 

52 SELECT ?label 

53 WHERE { 

54 ?subject wdt:P625 ?coordinates . 

55 ?subject rdfs:label ?label . 

56 FILTER(lang(?label) = "en") 

57 } """, 

58 """ 

59 SELECT ?label 

60 WHERE { 

61 ?subject wdt:P625 ?coordinates . 

62 ?subject wdt:P1448/rdfs:label ?label 

63 } """, 

64 """ 

65 SELECT ?label 

66 WHERE { 

67 ?subject wdt:P625 ?coordinates . 

68 ?subject rdfs:label ?label . 

69 }""", 

70 ] 

71 ) 

72 longitude = Attribute(""" 

73 SELECT ?longitude 

74 WHERE { 

75 ?subject wdt:P625 ?geo1 . 

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

77 } 

78 """) 

79 latitude = Attribute(""" 

80 SELECT ?latitude 

81 WHERE { 

82 ?subject wdt:P625 ?geo1 . 

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

84 } 

85 """) 

86 same_as = Attribute( 

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

88 )