pyLodStorage 0.3.3__tar.gz → 0.3.5__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {pylodstorage-0.3.3/pylodstorage.egg-info → pylodstorage-0.3.5}/PKG-INFO +1 -1
- {pylodstorage-0.3.3 → pylodstorage-0.3.5}/lodstorage/query.py +8 -0
- {pylodstorage-0.3.3 → pylodstorage-0.3.5}/lodstorage/trulytabular.py +82 -69
- {pylodstorage-0.3.3 → pylodstorage-0.3.5}/lodstorage/version.py +1 -1
- {pylodstorage-0.3.3 → pylodstorage-0.3.5/pylodstorage.egg-info}/PKG-INFO +1 -1
- {pylodstorage-0.3.3 → pylodstorage-0.3.5}/sampledata/endpoints.yaml +8 -2
- {pylodstorage-0.3.3 → pylodstorage-0.3.5}/LICENSE +0 -0
- {pylodstorage-0.3.3 → pylodstorage-0.3.5}/README.md +0 -0
- {pylodstorage-0.3.3 → pylodstorage-0.3.5}/lodstorage/__init__.py +0 -0
- {pylodstorage-0.3.3 → pylodstorage-0.3.5}/lodstorage/csv.py +0 -0
- {pylodstorage-0.3.3 → pylodstorage-0.3.5}/lodstorage/entity.py +0 -0
- {pylodstorage-0.3.3 → pylodstorage-0.3.5}/lodstorage/jsonable.py +0 -0
- {pylodstorage-0.3.3 → pylodstorage-0.3.5}/lodstorage/jsonpicklemixin.py +0 -0
- {pylodstorage-0.3.3 → pylodstorage-0.3.5}/lodstorage/lod.py +0 -0
- {pylodstorage-0.3.3 → pylodstorage-0.3.5}/lodstorage/mwTable.py +0 -0
- {pylodstorage-0.3.3 → pylodstorage-0.3.5}/lodstorage/plot.py +0 -0
- {pylodstorage-0.3.3 → pylodstorage-0.3.5}/lodstorage/querymain.py +0 -0
- {pylodstorage-0.3.3 → pylodstorage-0.3.5}/lodstorage/sample.py +0 -0
- {pylodstorage-0.3.3 → pylodstorage-0.3.5}/lodstorage/schema.py +0 -0
- {pylodstorage-0.3.3 → pylodstorage-0.3.5}/lodstorage/sparql.py +0 -0
- {pylodstorage-0.3.3 → pylodstorage-0.3.5}/lodstorage/sql.py +0 -0
- {pylodstorage-0.3.3 → pylodstorage-0.3.5}/lodstorage/storageconfig.py +0 -0
- {pylodstorage-0.3.3 → pylodstorage-0.3.5}/lodstorage/tabulateCounter.py +0 -0
- {pylodstorage-0.3.3 → pylodstorage-0.3.5}/lodstorage/uml.py +0 -0
- {pylodstorage-0.3.3 → pylodstorage-0.3.5}/lodstorage/xml.py +0 -0
- {pylodstorage-0.3.3 → pylodstorage-0.3.5}/lodstorage/yamlablemixin.py +0 -0
- {pylodstorage-0.3.3 → pylodstorage-0.3.5}/pylodstorage.egg-info/SOURCES.txt +0 -0
- {pylodstorage-0.3.3 → pylodstorage-0.3.5}/pylodstorage.egg-info/dependency_links.txt +0 -0
- {pylodstorage-0.3.3 → pylodstorage-0.3.5}/pylodstorage.egg-info/entry_points.txt +0 -0
- {pylodstorage-0.3.3 → pylodstorage-0.3.5}/pylodstorage.egg-info/requires.txt +0 -0
- {pylodstorage-0.3.3 → pylodstorage-0.3.5}/pylodstorage.egg-info/top_level.txt +0 -0
- {pylodstorage-0.3.3 → pylodstorage-0.3.5}/sampledata/__init__.py +0 -0
- {pylodstorage-0.3.3 → pylodstorage-0.3.5}/sampledata/formats.yaml +0 -0
- {pylodstorage-0.3.3 → pylodstorage-0.3.5}/sampledata/queries.yaml +0 -0
- {pylodstorage-0.3.3 → pylodstorage-0.3.5}/sampledata/scholia.yaml +0 -0
- {pylodstorage-0.3.3 → pylodstorage-0.3.5}/sampledata/trulytabular.yaml +0 -0
- {pylodstorage-0.3.3 → pylodstorage-0.3.5}/sampledata/wf.yaml +0 -0
- {pylodstorage-0.3.3 → pylodstorage-0.3.5}/sampledata/wikidata.yaml +0 -0
- {pylodstorage-0.3.3 → pylodstorage-0.3.5}/setup.cfg +0 -0
- {pylodstorage-0.3.3 → pylodstorage-0.3.5}/setup.py +0 -0
|
@@ -579,12 +579,20 @@ class Endpoint(JSONAble):
|
|
|
579
579
|
"name": "wikidata",
|
|
580
580
|
"lang": "sparql",
|
|
581
581
|
"endpoint": "https://query.wikidata.org/sparql",
|
|
582
|
+
"website": "https://query.wikidata.org/",
|
|
583
|
+
"database": "blazegraph",
|
|
582
584
|
"method": "POST",
|
|
583
585
|
"prefixes": "PREFIX bd: <http://www.bigdata.com/rdf#>\nPREFIX cc: <http://creativecommons.org/ns#>"
|
|
584
586
|
}
|
|
585
587
|
]
|
|
586
588
|
return samples
|
|
587
589
|
|
|
590
|
+
@classmethod
|
|
591
|
+
def getDefault(cls):
|
|
592
|
+
endpointConf=Endpoint()
|
|
593
|
+
endpointConf.fromDict(Endpoint.getSamples()[0])
|
|
594
|
+
return endpointConf
|
|
595
|
+
|
|
588
596
|
def __init__(self):
|
|
589
597
|
'''
|
|
590
598
|
constructor for setting defaults
|
|
@@ -5,7 +5,7 @@ Created on 2022-04-14
|
|
|
5
5
|
'''
|
|
6
6
|
import datetime
|
|
7
7
|
from lodstorage.sparql import SPARQL
|
|
8
|
-
from lodstorage.query import Query,QueryManager,YamlPath
|
|
8
|
+
from lodstorage.query import Query,QueryManager,YamlPath,Endpoint
|
|
9
9
|
from lodstorage.version import Version
|
|
10
10
|
from pathlib import Path
|
|
11
11
|
import os
|
|
@@ -74,23 +74,20 @@ class WikidataProperty():
|
|
|
74
74
|
'''
|
|
75
75
|
# the result dict
|
|
76
76
|
wdProperties={}
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
# get the
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
FILTER((LANG(?propertyLabel)) = "%s")
|
|
92
|
-
}""" % (valuesClause,lang)
|
|
93
|
-
cls.addPropertiesForQuery(wdProperties,sparql,query)
|
|
77
|
+
if len(propertyLabels)>0:
|
|
78
|
+
valuesClause=""
|
|
79
|
+
for propertyLabel in propertyLabels:
|
|
80
|
+
valuesClause+=f' "{propertyLabel}"@{lang}\n'
|
|
81
|
+
query=f"""# get the properties for the given labels
|
|
82
|
+
{WikidataItem.getPrefixes()}
|
|
83
|
+
SELECT ?property ?propertyLabel WHERE {{
|
|
84
|
+
VALUES ?propertyLabel {{
|
|
85
|
+
{valuesClause}
|
|
86
|
+
}}
|
|
87
|
+
?property rdf:type wikibase:Property;rdfs:label ?propertyLabel.
|
|
88
|
+
FILTER(LANG(?propertyLabel) = "{lang}")
|
|
89
|
+
}}"""
|
|
90
|
+
cls.addPropertiesForQuery(wdProperties,sparql,query)
|
|
94
91
|
return wdProperties
|
|
95
92
|
|
|
96
93
|
@classmethod
|
|
@@ -105,23 +102,21 @@ SELECT ?property ?propertyLabel WHERE {
|
|
|
105
102
|
'''
|
|
106
103
|
# the result dict
|
|
107
104
|
wdProperties={}
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
105
|
+
if len(propertyIds)>0:
|
|
106
|
+
valuesClause=""
|
|
107
|
+
for propertyId in propertyIds:
|
|
108
|
+
valuesClause+=f' wd:{propertyId}\n'
|
|
109
|
+
query=f"""
|
|
112
110
|
# get the property for the given property Ids
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
FILTER((LANG(?propertyLabel)) = "%s")
|
|
123
|
-
}""" % (valuesClause,lang)
|
|
124
|
-
cls.addPropertiesForQuery(wdProperties,sparql,query)
|
|
111
|
+
{WikidataItem.getPrefixes()}
|
|
112
|
+
SELECT ?property ?propertyLabel WHERE {{
|
|
113
|
+
VALUES ?property {{
|
|
114
|
+
{valuesClause}
|
|
115
|
+
}}
|
|
116
|
+
?property rdf:type wikibase:Property;rdfs:label ?propertyLabel.
|
|
117
|
+
FILTER(LANG(?propertyLabel) = "{lang}")
|
|
118
|
+
}}"""
|
|
119
|
+
cls.addPropertiesForQuery(wdProperties,sparql,query)
|
|
125
120
|
return wdProperties
|
|
126
121
|
|
|
127
122
|
@classmethod
|
|
@@ -160,6 +155,8 @@ class WikidataItem:
|
|
|
160
155
|
sparql(SPARQL): the sparql access to use
|
|
161
156
|
'''
|
|
162
157
|
self.qid=qid
|
|
158
|
+
# numeric qid
|
|
159
|
+
self.qnumber=int(qid[1:])
|
|
163
160
|
self.url=f"https://www.wikidata.org/wiki/{self.qid}"
|
|
164
161
|
self.lang=lang
|
|
165
162
|
self.sparql=sparql
|
|
@@ -195,13 +192,16 @@ class WikidataItem:
|
|
|
195
192
|
|
|
196
193
|
@classmethod
|
|
197
194
|
def getPrefixes(cls):
|
|
198
|
-
|
|
195
|
+
# see also https://www.wikidata.org/wiki/EntitySchema:E49
|
|
196
|
+
prefixes="""PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
|
|
197
|
+
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
|
|
199
198
|
PREFIX schema: <http://schema.org/>
|
|
200
199
|
PREFIX wd: <http://www.wikidata.org/entity/>
|
|
201
200
|
PREFIX wdt: <http://www.wikidata.org/prop/direct/>
|
|
201
|
+
PREFIX wikibase: <http://wikiba.se/ontology#>
|
|
202
202
|
PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>"""
|
|
203
203
|
return prefixes
|
|
204
|
-
|
|
204
|
+
|
|
205
205
|
@classmethod
|
|
206
206
|
def getLabelAndDescription(cls,sparql:SPARQL, itemId:str,lang:str="en"):
|
|
207
207
|
'''
|
|
@@ -223,9 +223,9 @@ WHERE
|
|
|
223
223
|
wd:{itemId}
|
|
224
224
|
}}
|
|
225
225
|
?item rdfs:label ?itemLabel.
|
|
226
|
-
FILTER (
|
|
226
|
+
FILTER (LANG(?itemLabel) = "{lang}").
|
|
227
227
|
?item schema:description ?itemDescription.
|
|
228
|
-
FILTER(
|
|
228
|
+
FILTER(LANG(?itemDescription) = "{lang}")
|
|
229
229
|
}}"""
|
|
230
230
|
return sparql.getValues(query, ["itemLabel","itemDescription"])
|
|
231
231
|
|
|
@@ -247,17 +247,21 @@ WHERE
|
|
|
247
247
|
# e.g. we'll find human=Q5 as the oldest type for the label "human" first
|
|
248
248
|
# and then the newer ones such as "race in Warcraft"
|
|
249
249
|
{cls.getPrefixes()}
|
|
250
|
-
SELECT
|
|
250
|
+
SELECT
|
|
251
|
+
#?itemId
|
|
252
|
+
?item
|
|
253
|
+
?itemLabel
|
|
254
|
+
?itemDescription
|
|
251
255
|
WHERE {{
|
|
252
256
|
VALUES ?itemLabel {{
|
|
253
257
|
{valuesClause}
|
|
254
258
|
}}
|
|
255
|
-
BIND (xsd:integer(SUBSTR(STR(?item),33)) AS ?itemId)
|
|
259
|
+
#BIND (xsd:integer(SUBSTR(STR(?item),33)) AS ?itemId)
|
|
256
260
|
?item rdfs:label ?itemLabel.
|
|
257
|
-
?item schema:description ?itemDescription
|
|
261
|
+
?item schema:description ?itemDescription.
|
|
258
262
|
FILTER(LANG(?itemDescription)="{lang}")
|
|
259
|
-
}}
|
|
260
|
-
|
|
263
|
+
}}
|
|
264
|
+
#ORDER BY ?itemId"""
|
|
261
265
|
qLod=sparql.queryAsListOfDicts(query)
|
|
262
266
|
items=[]
|
|
263
267
|
for record in qLod:
|
|
@@ -269,7 +273,8 @@ WHERE {{
|
|
|
269
273
|
item.varname=Variable.validVarName(item.qlabel)
|
|
270
274
|
item.description=record["itemDescription"]
|
|
271
275
|
items.append(item)
|
|
272
|
-
|
|
276
|
+
sortedItems=sorted(items,key=lambda item: item.qnumber)
|
|
277
|
+
return sortedItems
|
|
273
278
|
|
|
274
279
|
class TrulyTabular(object):
|
|
275
280
|
'''
|
|
@@ -277,9 +282,8 @@ class TrulyTabular(object):
|
|
|
277
282
|
|
|
278
283
|
checks "how tabular" a query based on a list of properties of an itemclass is
|
|
279
284
|
'''
|
|
280
|
-
endpoint="https://query.wikidata.org/sparql"
|
|
281
285
|
|
|
282
|
-
def __init__(self, itemQid, propertyLabels:list=[],propertyIds:list=[],where:str=None,
|
|
286
|
+
def __init__(self, itemQid, propertyLabels:list=[],propertyIds:list=[],where:str=None,endpointConf=None,lang="en",debug=False):
|
|
283
287
|
'''
|
|
284
288
|
Constructor
|
|
285
289
|
|
|
@@ -292,10 +296,10 @@ class TrulyTabular(object):
|
|
|
292
296
|
'''
|
|
293
297
|
self.itemQid=itemQid
|
|
294
298
|
self.debug=debug
|
|
295
|
-
if
|
|
296
|
-
|
|
297
|
-
self.
|
|
298
|
-
self.sparql=SPARQL(endpoint,method=method)
|
|
299
|
+
if endpointConf is None:
|
|
300
|
+
endpointConf=Endpoint.getDefault()
|
|
301
|
+
self.endpointConf=endpointConf
|
|
302
|
+
self.sparql=SPARQL(endpointConf.endpoint,method=self.endpointConf.method)
|
|
299
303
|
self.sparql.debug=self.debug
|
|
300
304
|
self.where=f"\n {where}" if where is not None else ""
|
|
301
305
|
self.lang=lang
|
|
@@ -475,32 +479,41 @@ WHERE {{
|
|
|
475
479
|
whereClause(str): an extra WhereClause to use
|
|
476
480
|
'''
|
|
477
481
|
if whereClause is None:
|
|
478
|
-
whereClause=f"?item wdt:P31 wd:{self.itemQid}
|
|
479
|
-
|
|
480
|
-
|
|
482
|
+
whereClause=f"?item wdt:P31 wd:{self.itemQid}";
|
|
483
|
+
if self.endpointConf.database!="qlever":
|
|
484
|
+
whereClause+=";?p ?id"
|
|
485
|
+
whereClause+="."
|
|
481
486
|
itemText=self.getItemText()
|
|
482
|
-
if self.endpoint=="https://query.wikidata.org/sparql":
|
|
483
|
-
optimizerHint=' hint:Query hint:optimizer "None".\n'
|
|
484
|
-
else:
|
|
485
|
-
optimizerHint=''
|
|
486
487
|
sparqlQuery=f"""# get the most frequently used properties for
|
|
487
488
|
# {itemText}
|
|
488
|
-
|
|
489
|
-
PREFIX schema: <http://schema.org/>
|
|
490
|
-
PREFIX wd: <http://www.wikidata.org/entity/>
|
|
491
|
-
PREFIX wdt: <http://www.wikidata.org/prop/direct/>
|
|
492
|
-
PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
|
|
489
|
+
{WikidataItem.getPrefixes()}
|
|
493
490
|
SELECT ?prop ?propLabel ?count WHERE {{
|
|
494
|
-
{{
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
491
|
+
{{"""
|
|
492
|
+
if self.endpointConf.database=="qlever":
|
|
493
|
+
sparqlQuery+=f"""
|
|
494
|
+
SELECT ?p (COUNT(DISTINCT ?item) AS ?count) WHERE {{"""
|
|
495
|
+
else:
|
|
496
|
+
sparqlQuery+=f"""
|
|
497
|
+
SELECT ?prop (COUNT(DISTINCT ?item) AS ?count) WHERE {{"""
|
|
498
|
+
if self.endpointConf.database=="blazegraph":
|
|
499
|
+
sparqlQuery+=f"""
|
|
500
|
+
hint:Query hint:optimizer "None"."""
|
|
501
|
+
sparqlQuery+=f"""
|
|
502
|
+
{whereClause}"""
|
|
503
|
+
if self.endpointConf.database=="qlever":
|
|
504
|
+
sparqlQuery+=f"""
|
|
505
|
+
?item ql:has-predicate ?p
|
|
506
|
+
}} GROUP BY ?p
|
|
507
|
+
}}
|
|
508
|
+
?prop wikibase:directClaim ?p."""
|
|
509
|
+
else:
|
|
510
|
+
sparqlQuery+=f"""
|
|
499
511
|
?prop wikibase:directClaim ?p.
|
|
500
512
|
}}
|
|
501
513
|
GROUP BY ?prop ?propLabel
|
|
502
|
-
}}
|
|
503
|
-
|
|
514
|
+
}}"""
|
|
515
|
+
sparqlQuery+=f"""
|
|
516
|
+
?prop rdfs:label ?propLabel.
|
|
504
517
|
FILTER(LANG(?propLabel) = "{self.lang}")
|
|
505
518
|
}}
|
|
506
519
|
ORDER BY DESC (?count)
|
|
@@ -3,6 +3,8 @@
|
|
|
3
3
|
'wikidata':
|
|
4
4
|
lang: sparql
|
|
5
5
|
endpoint: https://query.wikidata.org/sparql
|
|
6
|
+
website: https://query.wikidata.org/
|
|
7
|
+
database: blazegraph
|
|
6
8
|
method: POST
|
|
7
9
|
prefixes: |
|
|
8
10
|
PREFIX bd: <http://www.bigdata.com/rdf#>
|
|
@@ -36,11 +38,12 @@
|
|
|
36
38
|
PREFIX wdv: <http://www.wikidata.org/value/>
|
|
37
39
|
PREFIX wikibase: <http://wikiba.se/ontology#>
|
|
38
40
|
PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
|
|
39
|
-
|
|
40
41
|
'qlever-wikidata':
|
|
41
42
|
lang: sparql
|
|
42
43
|
method: GET
|
|
44
|
+
database: qlever
|
|
43
45
|
endpoint: https://qlever.cs.uni-freiburg.de/api/wikidata
|
|
46
|
+
website: https://qlever.cs.uni-freiburg.de/wikidata
|
|
44
47
|
prefixes: |
|
|
45
48
|
PREFIX bd: <http://www.bigdata.com/rdf#>
|
|
46
49
|
PREFIX cc: <http://creativecommons.org/ns#>
|
|
@@ -73,11 +76,12 @@
|
|
|
73
76
|
PREFIX wdv: <http://www.wikidata.org/value/>
|
|
74
77
|
PREFIX wikibase: <http://wikiba.se/ontology#>
|
|
75
78
|
PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
|
|
76
|
-
|
|
77
79
|
'qlever-wikidata-proxy':
|
|
78
80
|
lang: sparql
|
|
79
81
|
method: GET
|
|
82
|
+
database: qlever
|
|
80
83
|
endpoint: https://qlever.cs.uni-freiburg.de/api/wikidata-proxy
|
|
84
|
+
website: https://qlever.cs.uni-freiburg.de/wikidata
|
|
81
85
|
prefixes: |
|
|
82
86
|
PREFIX bd: <http://www.bigdata.com/rdf#>
|
|
83
87
|
PREFIX cc: <http://creativecommons.org/ns#>
|
|
@@ -113,6 +117,8 @@
|
|
|
113
117
|
'wikidata-openlinksw':
|
|
114
118
|
lang: sparql
|
|
115
119
|
endpoint: https://wikidata.demo.openlinksw.com/sparql
|
|
120
|
+
website: https://wikidata.demo.openlinksw.com/sparql
|
|
121
|
+
database: virtuoso
|
|
116
122
|
prefixes: |
|
|
117
123
|
PREFIX bd: <http://www.bigdata.com/rdf#>
|
|
118
124
|
PREFIX cc: <http://creativecommons.org/ns#>
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|