pyLodStorage 0.2.14__tar.gz → 0.3.0__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.2.14/pylodstorage.egg-info → pylodstorage-0.3.0}/PKG-INFO +1 -1
- {pylodstorage-0.2.14 → pylodstorage-0.3.0}/lodstorage/trulytabular.py +48 -8
- {pylodstorage-0.2.14 → pylodstorage-0.3.0}/lodstorage/version.py +2 -2
- {pylodstorage-0.2.14 → pylodstorage-0.3.0/pylodstorage.egg-info}/PKG-INFO +1 -1
- {pylodstorage-0.2.14 → pylodstorage-0.3.0}/LICENSE +0 -0
- {pylodstorage-0.2.14 → pylodstorage-0.3.0}/README.md +0 -0
- {pylodstorage-0.2.14 → pylodstorage-0.3.0}/lodstorage/__init__.py +0 -0
- {pylodstorage-0.2.14 → pylodstorage-0.3.0}/lodstorage/csv.py +0 -0
- {pylodstorage-0.2.14 → pylodstorage-0.3.0}/lodstorage/entity.py +0 -0
- {pylodstorage-0.2.14 → pylodstorage-0.3.0}/lodstorage/jsonable.py +0 -0
- {pylodstorage-0.2.14 → pylodstorage-0.3.0}/lodstorage/jsonpicklemixin.py +0 -0
- {pylodstorage-0.2.14 → pylodstorage-0.3.0}/lodstorage/lod.py +0 -0
- {pylodstorage-0.2.14 → pylodstorage-0.3.0}/lodstorage/mwTable.py +0 -0
- {pylodstorage-0.2.14 → pylodstorage-0.3.0}/lodstorage/plot.py +0 -0
- {pylodstorage-0.2.14 → pylodstorage-0.3.0}/lodstorage/query.py +0 -0
- {pylodstorage-0.2.14 → pylodstorage-0.3.0}/lodstorage/querymain.py +0 -0
- {pylodstorage-0.2.14 → pylodstorage-0.3.0}/lodstorage/sample.py +0 -0
- {pylodstorage-0.2.14 → pylodstorage-0.3.0}/lodstorage/schema.py +0 -0
- {pylodstorage-0.2.14 → pylodstorage-0.3.0}/lodstorage/sparql.py +0 -0
- {pylodstorage-0.2.14 → pylodstorage-0.3.0}/lodstorage/sql.py +0 -0
- {pylodstorage-0.2.14 → pylodstorage-0.3.0}/lodstorage/storageconfig.py +0 -0
- {pylodstorage-0.2.14 → pylodstorage-0.3.0}/lodstorage/tabulateCounter.py +0 -0
- {pylodstorage-0.2.14 → pylodstorage-0.3.0}/lodstorage/uml.py +0 -0
- {pylodstorage-0.2.14 → pylodstorage-0.3.0}/lodstorage/xml.py +0 -0
- {pylodstorage-0.2.14 → pylodstorage-0.3.0}/lodstorage/yamlablemixin.py +0 -0
- {pylodstorage-0.2.14 → pylodstorage-0.3.0}/pylodstorage.egg-info/SOURCES.txt +0 -0
- {pylodstorage-0.2.14 → pylodstorage-0.3.0}/pylodstorage.egg-info/dependency_links.txt +0 -0
- {pylodstorage-0.2.14 → pylodstorage-0.3.0}/pylodstorage.egg-info/entry_points.txt +0 -0
- {pylodstorage-0.2.14 → pylodstorage-0.3.0}/pylodstorage.egg-info/requires.txt +0 -0
- {pylodstorage-0.2.14 → pylodstorage-0.3.0}/pylodstorage.egg-info/top_level.txt +0 -0
- {pylodstorage-0.2.14 → pylodstorage-0.3.0}/sampledata/__init__.py +0 -0
- {pylodstorage-0.2.14 → pylodstorage-0.3.0}/sampledata/endpoints.yaml +0 -0
- {pylodstorage-0.2.14 → pylodstorage-0.3.0}/sampledata/formats.yaml +0 -0
- {pylodstorage-0.2.14 → pylodstorage-0.3.0}/sampledata/queries.yaml +0 -0
- {pylodstorage-0.2.14 → pylodstorage-0.3.0}/sampledata/scholia.yaml +0 -0
- {pylodstorage-0.2.14 → pylodstorage-0.3.0}/sampledata/trulytabular.yaml +0 -0
- {pylodstorage-0.2.14 → pylodstorage-0.3.0}/sampledata/wf.yaml +0 -0
- {pylodstorage-0.2.14 → pylodstorage-0.3.0}/sampledata/wikidata.yaml +0 -0
- {pylodstorage-0.2.14 → pylodstorage-0.3.0}/setup.cfg +0 -0
- {pylodstorage-0.2.14 → pylodstorage-0.3.0}/setup.py +0 -0
|
@@ -6,11 +6,13 @@ Created on 2022-04-14
|
|
|
6
6
|
import datetime
|
|
7
7
|
from lodstorage.sparql import SPARQL
|
|
8
8
|
from lodstorage.query import Query,QueryManager,YamlPath
|
|
9
|
+
from lodstorage.version import Version
|
|
9
10
|
from pathlib import Path
|
|
10
11
|
import os
|
|
11
12
|
import textwrap
|
|
12
13
|
import re
|
|
13
14
|
|
|
15
|
+
|
|
14
16
|
class Variable:
|
|
15
17
|
'''
|
|
16
18
|
Variable e.g. name handling
|
|
@@ -368,43 +370,81 @@ WHERE
|
|
|
368
370
|
return qm
|
|
369
371
|
return None
|
|
370
372
|
|
|
371
|
-
|
|
372
|
-
def generateSparqlQuery(self,lang:str='en',naive:bool=True)->str:
|
|
373
|
+
def generateSparqlQuery(self,genMap:dict,listSeparator:str="⇹",naive:bool=True,lang:str='en')->str:
|
|
373
374
|
'''
|
|
374
375
|
generate a SPARQL Query
|
|
376
|
+
|
|
377
|
+
Args:
|
|
378
|
+
genMap(dict): a dictionary of generation items aggregates/ignores/labels
|
|
379
|
+
listSeparator(str): the symbole to use as a list separator for GROUP_CONCAT
|
|
380
|
+
naive(bool): if True - generate a naive straight forward SPARQL query
|
|
381
|
+
if False generate a proper truly tabular aggregate query
|
|
382
|
+
lang(str): the language to generate for
|
|
383
|
+
|
|
384
|
+
Returns:
|
|
385
|
+
str: the generated SPARQL Query
|
|
375
386
|
'''
|
|
387
|
+
# The Wikidata item to generate the query for
|
|
376
388
|
item=self.item
|
|
389
|
+
# the name of this script
|
|
377
390
|
script=Path(__file__).name
|
|
391
|
+
# the mode of generation
|
|
378
392
|
naiveText="naive" if naive else "aggregate"
|
|
393
|
+
# start with th preamble and PREFIX section
|
|
394
|
+
# select the item and it's label
|
|
379
395
|
sparqlQuery=f"""# truly tabular {naiveText} query for
|
|
380
396
|
# {item.qid}:{item.qlabel}
|
|
381
|
-
# generated by {script} on {self.isodate}
|
|
397
|
+
# generated by {script} version {Version.version} on {self.isodate}
|
|
382
398
|
PREFIX wd: <http://www.wikidata.org/entity/>
|
|
383
399
|
PREFIX wdt: <http://www.wikidata.org/prop/direct/>
|
|
384
400
|
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
|
|
385
401
|
SELECT ?{item.varname} ?{item.varname}Label"""
|
|
402
|
+
# loop over all properties
|
|
386
403
|
for wdProp in self.properties.values():
|
|
387
404
|
if naive:
|
|
388
405
|
sparqlQuery+=f"\n ?{wdProp.varname}"
|
|
389
406
|
else:
|
|
390
|
-
|
|
407
|
+
if wdProp.pid in genMap:
|
|
408
|
+
genList=genMap[wdProp.pid]
|
|
409
|
+
for aggregate in genList:
|
|
410
|
+
if not aggregate in ["ignore","label"]:
|
|
411
|
+
if aggregate=="list":
|
|
412
|
+
aggregateFunc="GROUP_CONCAT"
|
|
413
|
+
aggregateParam=f';SEPARATOR="{listSeparator}"'
|
|
414
|
+
else:
|
|
415
|
+
aggregateFunc=aggregate.upper()
|
|
416
|
+
aggregateParam=""
|
|
417
|
+
sparqlQuery+=f"\n ({aggregateFunc} (?{wdProp.varname}{aggregateParam}) AS ?{wdProp.varname}_{aggregate})"
|
|
418
|
+
elif aggregate=="label":
|
|
419
|
+
sparqlQuery+=f"\n ?{wdProp.varname}Label"
|
|
391
420
|
sparqlQuery+=f"""
|
|
392
421
|
WHERE {{
|
|
393
422
|
# instanceof {item.qid}:{item.qlabel}
|
|
394
423
|
?{item.varname} wdt:P31 wd:{item.qid}.
|
|
395
424
|
# label
|
|
396
|
-
?{item.varname} rdfs:label ?{item.varname}Label
|
|
425
|
+
?{item.varname} rdfs:label ?{item.varname}Label.
|
|
397
426
|
FILTER (LANG(?{item.varname}Label) = "{lang}").
|
|
398
427
|
"""
|
|
399
428
|
for wdProp in self.properties.values():
|
|
400
|
-
|
|
401
|
-
OPTIONAL {{
|
|
402
|
-
"""
|
|
429
|
+
sparqlQuery+=f""" # {wdProp}
|
|
430
|
+
OPTIONAL {{
|
|
431
|
+
?{item.varname} wdt:{wdProp.pid} ?{wdProp.varname}. """
|
|
432
|
+
if wdProp.pid in genMap:
|
|
433
|
+
genList=genMap[wdProp.pid]
|
|
434
|
+
if "label" in genList:
|
|
435
|
+
sparqlQuery+=f"""\n ?{wdProp.varname} rdfs:label ?{wdProp.varname}Label."""
|
|
436
|
+
sparqlQuery+=f"""\n FILTER (LANG(?{wdProp.varname}Label) = "{lang}")."""
|
|
437
|
+
sparqlQuery+="\n }\n"
|
|
403
438
|
# close where Clause
|
|
404
439
|
sparqlQuery+="""}\n"""
|
|
405
440
|
# optionally add Aggregate
|
|
406
441
|
if not naive:
|
|
407
442
|
sparqlQuery+=f"GROUP BY ?{item.varname} ?{item.varname}Label"
|
|
443
|
+
for wdProp in self.properties.values():
|
|
444
|
+
if wdProp.pid in genMap:
|
|
445
|
+
genList=genMap[wdProp.pid]
|
|
446
|
+
if "ignore" in genList:
|
|
447
|
+
sparqlQuery+=f"\nHAVING (COUNT(?{wdProp.varname})=1)"
|
|
408
448
|
return sparqlQuery
|
|
409
449
|
|
|
410
450
|
def mostFrequentPropertiesQuery(self,whereClause:str=None):
|
|
@@ -9,7 +9,7 @@ class Version(object):
|
|
|
9
9
|
Version handling for pyLoDStorage
|
|
10
10
|
'''
|
|
11
11
|
name="pylodstorage"
|
|
12
|
-
version='0.
|
|
12
|
+
version='0.3.0'
|
|
13
13
|
date = '2020-09-10'
|
|
14
|
-
updated = '2022-07-
|
|
14
|
+
updated = '2022-07-28'
|
|
15
15
|
description='python List of Dict (Table) Storage library'
|
|
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
|
|
File without changes
|