pyLodStorage 0.3.0__tar.gz → 0.3.1__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.0/pylodstorage.egg-info → pylodstorage-0.3.1}/PKG-INFO +1 -1
- {pylodstorage-0.3.0 → pylodstorage-0.3.1}/lodstorage/trulytabular.py +63 -35
- {pylodstorage-0.3.0 → pylodstorage-0.3.1}/lodstorage/version.py +1 -1
- {pylodstorage-0.3.0 → pylodstorage-0.3.1/pylodstorage.egg-info}/PKG-INFO +1 -1
- {pylodstorage-0.3.0 → pylodstorage-0.3.1}/sampledata/trulytabular.yaml +6 -1
- {pylodstorage-0.3.0 → pylodstorage-0.3.1}/LICENSE +0 -0
- {pylodstorage-0.3.0 → pylodstorage-0.3.1}/README.md +0 -0
- {pylodstorage-0.3.0 → pylodstorage-0.3.1}/lodstorage/__init__.py +0 -0
- {pylodstorage-0.3.0 → pylodstorage-0.3.1}/lodstorage/csv.py +0 -0
- {pylodstorage-0.3.0 → pylodstorage-0.3.1}/lodstorage/entity.py +0 -0
- {pylodstorage-0.3.0 → pylodstorage-0.3.1}/lodstorage/jsonable.py +0 -0
- {pylodstorage-0.3.0 → pylodstorage-0.3.1}/lodstorage/jsonpicklemixin.py +0 -0
- {pylodstorage-0.3.0 → pylodstorage-0.3.1}/lodstorage/lod.py +0 -0
- {pylodstorage-0.3.0 → pylodstorage-0.3.1}/lodstorage/mwTable.py +0 -0
- {pylodstorage-0.3.0 → pylodstorage-0.3.1}/lodstorage/plot.py +0 -0
- {pylodstorage-0.3.0 → pylodstorage-0.3.1}/lodstorage/query.py +0 -0
- {pylodstorage-0.3.0 → pylodstorage-0.3.1}/lodstorage/querymain.py +0 -0
- {pylodstorage-0.3.0 → pylodstorage-0.3.1}/lodstorage/sample.py +0 -0
- {pylodstorage-0.3.0 → pylodstorage-0.3.1}/lodstorage/schema.py +0 -0
- {pylodstorage-0.3.0 → pylodstorage-0.3.1}/lodstorage/sparql.py +0 -0
- {pylodstorage-0.3.0 → pylodstorage-0.3.1}/lodstorage/sql.py +0 -0
- {pylodstorage-0.3.0 → pylodstorage-0.3.1}/lodstorage/storageconfig.py +0 -0
- {pylodstorage-0.3.0 → pylodstorage-0.3.1}/lodstorage/tabulateCounter.py +0 -0
- {pylodstorage-0.3.0 → pylodstorage-0.3.1}/lodstorage/uml.py +0 -0
- {pylodstorage-0.3.0 → pylodstorage-0.3.1}/lodstorage/xml.py +0 -0
- {pylodstorage-0.3.0 → pylodstorage-0.3.1}/lodstorage/yamlablemixin.py +0 -0
- {pylodstorage-0.3.0 → pylodstorage-0.3.1}/pylodstorage.egg-info/SOURCES.txt +0 -0
- {pylodstorage-0.3.0 → pylodstorage-0.3.1}/pylodstorage.egg-info/dependency_links.txt +0 -0
- {pylodstorage-0.3.0 → pylodstorage-0.3.1}/pylodstorage.egg-info/entry_points.txt +0 -0
- {pylodstorage-0.3.0 → pylodstorage-0.3.1}/pylodstorage.egg-info/requires.txt +0 -0
- {pylodstorage-0.3.0 → pylodstorage-0.3.1}/pylodstorage.egg-info/top_level.txt +0 -0
- {pylodstorage-0.3.0 → pylodstorage-0.3.1}/sampledata/__init__.py +0 -0
- {pylodstorage-0.3.0 → pylodstorage-0.3.1}/sampledata/endpoints.yaml +0 -0
- {pylodstorage-0.3.0 → pylodstorage-0.3.1}/sampledata/formats.yaml +0 -0
- {pylodstorage-0.3.0 → pylodstorage-0.3.1}/sampledata/queries.yaml +0 -0
- {pylodstorage-0.3.0 → pylodstorage-0.3.1}/sampledata/scholia.yaml +0 -0
- {pylodstorage-0.3.0 → pylodstorage-0.3.1}/sampledata/wf.yaml +0 -0
- {pylodstorage-0.3.0 → pylodstorage-0.3.1}/sampledata/wikidata.yaml +0 -0
- {pylodstorage-0.3.0 → pylodstorage-0.3.1}/setup.cfg +0 -0
- {pylodstorage-0.3.0 → pylodstorage-0.3.1}/setup.py +0 -0
|
@@ -194,7 +194,16 @@ class WikidataItem:
|
|
|
194
194
|
return text
|
|
195
195
|
|
|
196
196
|
@classmethod
|
|
197
|
-
def
|
|
197
|
+
def getPrefixes(cls):
|
|
198
|
+
prefixes="""PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
|
|
199
|
+
PREFIX schema: <http://schema.org/>
|
|
200
|
+
PREFIX wd: <http://www.wikidata.org/entity/>
|
|
201
|
+
PREFIX wdt: <http://www.wikidata.org/prop/direct/>
|
|
202
|
+
PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>"""
|
|
203
|
+
return prefixes
|
|
204
|
+
|
|
205
|
+
@classmethod
|
|
206
|
+
def getLabelAndDescription(cls,sparql:SPARQL, itemId:str,lang:str="en"):
|
|
198
207
|
'''
|
|
199
208
|
get the label for the given item and language
|
|
200
209
|
|
|
@@ -205,23 +214,19 @@ class WikidataItem:
|
|
|
205
214
|
Returns:
|
|
206
215
|
(str,str): the label and description as a tuple
|
|
207
216
|
'''
|
|
208
|
-
query="""
|
|
209
|
-
|
|
210
|
-
PREFIX wd: <http://www.wikidata.org/entity/>
|
|
211
|
-
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
|
|
212
|
-
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
|
|
213
|
-
PREFIX schema: <http://schema.org/>
|
|
217
|
+
query=f"""# get the label for the given item
|
|
218
|
+
{cls.getPrefixes()}
|
|
214
219
|
SELECT ?itemLabel ?itemDescription
|
|
215
220
|
WHERE
|
|
216
|
-
{
|
|
217
|
-
VALUES ?item {
|
|
218
|
-
wd
|
|
219
|
-
}
|
|
221
|
+
{{
|
|
222
|
+
VALUES ?item {{
|
|
223
|
+
wd:{itemId}
|
|
224
|
+
}}
|
|
220
225
|
?item rdfs:label ?itemLabel.
|
|
221
|
-
|
|
226
|
+
FILTER (lang(?itemLabel) = "{lang}").
|
|
222
227
|
?item schema:description ?itemDescription.
|
|
223
|
-
FILTER((LANG(?itemDescription)) = "
|
|
224
|
-
}"""
|
|
228
|
+
FILTER((LANG(?itemDescription)) = "{lang}")
|
|
229
|
+
}}"""
|
|
225
230
|
return sparql.getValues(query, ["itemLabel","itemDescription"])
|
|
226
231
|
|
|
227
232
|
@classmethod
|
|
@@ -238,23 +243,20 @@ WHERE
|
|
|
238
243
|
a list of potential items
|
|
239
244
|
'''
|
|
240
245
|
valuesClause=f' "{itemLabel}"@{lang}\n'
|
|
241
|
-
query="""# get the items that have the given label in the given language
|
|
246
|
+
query=f"""# get the items that have the given label in the given language
|
|
242
247
|
# e.g. we'll find human=Q5 as the oldest type for the label "human" first
|
|
243
248
|
# and then the newer ones such as "race in Warcraft"
|
|
244
|
-
|
|
245
|
-
PREFIX schema: <http://schema.org/>
|
|
246
|
-
PREFIX wd: <http://www.wikidata.org/entity/>
|
|
247
|
-
PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
|
|
249
|
+
{cls.getPrefixes()}
|
|
248
250
|
SELECT ?itemId ?item ?itemLabel ?itemDescription
|
|
249
|
-
WHERE {
|
|
250
|
-
VALUES ?itemLabel {
|
|
251
|
-
|
|
252
|
-
}
|
|
251
|
+
WHERE {{
|
|
252
|
+
VALUES ?itemLabel {{
|
|
253
|
+
{valuesClause}
|
|
254
|
+
}}
|
|
253
255
|
BIND (xsd:integer(SUBSTR(STR(?item),33)) AS ?itemId)
|
|
254
256
|
?item rdfs:label ?itemLabel.
|
|
255
257
|
?item schema:description ?itemDescription
|
|
256
|
-
FILTER(LANG(?itemDescription)="
|
|
257
|
-
} ORDER BY ?itemId"""
|
|
258
|
+
FILTER(LANG(?itemDescription)="{lang}")
|
|
259
|
+
}} ORDER BY ?itemId"""
|
|
258
260
|
|
|
259
261
|
qLod=sparql.queryAsListOfDicts(query)
|
|
260
262
|
items=[]
|
|
@@ -318,8 +320,7 @@ class TrulyTabular(object):
|
|
|
318
320
|
itemText=self.getItemText()
|
|
319
321
|
query=f"""# Count all items with the given type
|
|
320
322
|
# {itemText}
|
|
321
|
-
|
|
322
|
-
PREFIX wdt: <http://www.wikidata.org/prop/direct/>
|
|
323
|
+
{WikidataItem.getPrefixes()}
|
|
323
324
|
SELECT (COUNT (DISTINCT ?item) AS ?count)
|
|
324
325
|
WHERE
|
|
325
326
|
{{
|
|
@@ -350,7 +351,7 @@ WHERE
|
|
|
350
351
|
def getItemText(self):
|
|
351
352
|
# leads to 405 Method not allowed in SPARQLWrapper under certain circumstances
|
|
352
353
|
# itemText=self.asText(long=True)
|
|
353
|
-
itemText=self.itemQid
|
|
354
|
+
itemText=f"{self.itemQid}:{self.item.qlabel}"
|
|
354
355
|
return itemText
|
|
355
356
|
|
|
356
357
|
@classmethod
|
|
@@ -395,9 +396,7 @@ WHERE
|
|
|
395
396
|
sparqlQuery=f"""# truly tabular {naiveText} query for
|
|
396
397
|
# {item.qid}:{item.qlabel}
|
|
397
398
|
# generated by {script} version {Version.version} on {self.isodate}
|
|
398
|
-
|
|
399
|
-
PREFIX wdt: <http://www.wikidata.org/prop/direct/>
|
|
400
|
-
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
|
|
399
|
+
{WikidataItem.getPrefixes()}
|
|
401
400
|
SELECT ?{item.varname} ?{item.varname}Label"""
|
|
402
401
|
# loop over all properties
|
|
403
402
|
for wdProp in self.properties.values():
|
|
@@ -408,13 +407,17 @@ SELECT ?{item.varname} ?{item.varname}Label"""
|
|
|
408
407
|
genList=genMap[wdProp.pid]
|
|
409
408
|
for aggregate in genList:
|
|
410
409
|
if not aggregate in ["ignore","label"]:
|
|
410
|
+
distinct=""
|
|
411
411
|
if aggregate=="list":
|
|
412
412
|
aggregateFunc="GROUP_CONCAT"
|
|
413
413
|
aggregateParam=f';SEPARATOR="{listSeparator}"'
|
|
414
|
+
distinct="DISTINCT "
|
|
414
415
|
else:
|
|
416
|
+
if aggregate=="count":
|
|
417
|
+
distinct="DISTINCT "
|
|
415
418
|
aggregateFunc=aggregate.upper()
|
|
416
419
|
aggregateParam=""
|
|
417
|
-
sparqlQuery+=f"\n ({aggregateFunc} (?{wdProp.varname}{aggregateParam}) AS ?{wdProp.varname}_{aggregate})"
|
|
420
|
+
sparqlQuery+=f"\n ({aggregateFunc} ({distinct}?{wdProp.varname}{aggregateParam}) AS ?{wdProp.varname}_{aggregate})"
|
|
418
421
|
elif aggregate=="label":
|
|
419
422
|
sparqlQuery+=f"\n ?{wdProp.varname}Label"
|
|
420
423
|
sparqlQuery+=f"""
|
|
@@ -454,14 +457,39 @@ WHERE {{
|
|
|
454
457
|
Args:
|
|
455
458
|
whereClause(str): an extra WhereClause to use
|
|
456
459
|
'''
|
|
457
|
-
query=self.queryManager.queriesByName["mostFrequentProperties"]
|
|
458
460
|
if whereClause is None:
|
|
459
461
|
whereClause=f"?item wdt:P31 wd:{self.itemQid};";
|
|
460
462
|
else:
|
|
461
463
|
whereClause+=";"
|
|
462
464
|
itemText=self.getItemText()
|
|
463
|
-
|
|
464
|
-
|
|
465
|
+
if self.endpoint=="https://query.wikidata.org/sparql":
|
|
466
|
+
optimizerHint=' hint:Query hint:optimizer "None".\n'
|
|
467
|
+
else:
|
|
468
|
+
optimizerHint=''
|
|
469
|
+
sparqlQuery=f"""# get the most frequently used properties for
|
|
470
|
+
# {itemText}
|
|
471
|
+
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
|
|
472
|
+
PREFIX schema: <http://schema.org/>
|
|
473
|
+
PREFIX wd: <http://www.wikidata.org/entity/>
|
|
474
|
+
PREFIX wdt: <http://www.wikidata.org/prop/direct/>
|
|
475
|
+
PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
|
|
476
|
+
SELECT ?prop ?propLabel ?count WHERE {{
|
|
477
|
+
{{
|
|
478
|
+
SELECT ?prop (COUNT(DISTINCT ?item) AS ?count) WHERE {{
|
|
479
|
+
{optimizerHint}
|
|
480
|
+
{whereClause}
|
|
481
|
+
?p ?id.
|
|
482
|
+
?prop wikibase:directClaim ?p.
|
|
483
|
+
}}
|
|
484
|
+
GROUP BY ?prop ?propLabel
|
|
485
|
+
}}
|
|
486
|
+
?prop rdfs:label ?propLabel
|
|
487
|
+
FILTER(LANG(?propLabel) = "{self.lang}")
|
|
488
|
+
}}
|
|
489
|
+
ORDER BY DESC (?count)
|
|
490
|
+
"""
|
|
491
|
+
title=f"most frequently used properties for {self.item.asText(long=True)}"
|
|
492
|
+
query=Query(name=f"mostFrequentProperties for {itemText}",query=sparqlQuery,title=title)
|
|
465
493
|
return query
|
|
466
494
|
|
|
467
495
|
def noneTabularQuery(self,wdProperty:WikidataProperty,asFrequency:bool=True):
|
|
@@ -6,10 +6,15 @@
|
|
|
6
6
|
sparql: |
|
|
7
7
|
# get the most frequently used properties for
|
|
8
8
|
# %s
|
|
9
|
+
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
|
|
10
|
+
PREFIX schema: <http://schema.org/>
|
|
11
|
+
PREFIX wd: <http://www.wikidata.org/entity/>
|
|
12
|
+
PREFIX wdt: <http://www.wikidata.org/prop/direct/>
|
|
13
|
+
PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
|
|
9
14
|
SELECT ?prop ?propLabel ?count WHERE {
|
|
10
15
|
{
|
|
11
16
|
SELECT ?prop (COUNT(DISTINCT ?item) AS ?count) WHERE {
|
|
12
|
-
hint:Query hint:optimizer "None".
|
|
17
|
+
#hint:Query hint:optimizer "None".
|
|
13
18
|
%s
|
|
14
19
|
?p ?id.
|
|
15
20
|
?prop wikibase:directClaim ?p.
|
|
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
|
|
File without changes
|