pyLodStorage 0.4.3__tar.gz → 0.4.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.4.3/pylodstorage.egg-info → pylodstorage-0.4.5}/PKG-INFO +1 -1
- {pylodstorage-0.4.3 → pylodstorage-0.4.5}/lodstorage/trulytabular.py +29 -20
- {pylodstorage-0.4.3 → pylodstorage-0.4.5}/lodstorage/version.py +2 -2
- {pylodstorage-0.4.3 → pylodstorage-0.4.5/pylodstorage.egg-info}/PKG-INFO +1 -1
- {pylodstorage-0.4.3 → pylodstorage-0.4.5}/LICENSE +0 -0
- {pylodstorage-0.4.3 → pylodstorage-0.4.5}/README.md +0 -0
- {pylodstorage-0.4.3 → pylodstorage-0.4.5}/lodstorage/__init__.py +0 -0
- {pylodstorage-0.4.3 → pylodstorage-0.4.5}/lodstorage/csv.py +0 -0
- {pylodstorage-0.4.3 → pylodstorage-0.4.5}/lodstorage/entity.py +0 -0
- {pylodstorage-0.4.3 → pylodstorage-0.4.5}/lodstorage/jsonable.py +0 -0
- {pylodstorage-0.4.3 → pylodstorage-0.4.5}/lodstorage/jsonpicklemixin.py +0 -0
- {pylodstorage-0.4.3 → pylodstorage-0.4.5}/lodstorage/lod.py +0 -0
- {pylodstorage-0.4.3 → pylodstorage-0.4.5}/lodstorage/mwTable.py +0 -0
- {pylodstorage-0.4.3 → pylodstorage-0.4.5}/lodstorage/plot.py +0 -0
- {pylodstorage-0.4.3 → pylodstorage-0.4.5}/lodstorage/query.py +0 -0
- {pylodstorage-0.4.3 → pylodstorage-0.4.5}/lodstorage/querymain.py +0 -0
- {pylodstorage-0.4.3 → pylodstorage-0.4.5}/lodstorage/sample.py +0 -0
- {pylodstorage-0.4.3 → pylodstorage-0.4.5}/lodstorage/schema.py +0 -0
- {pylodstorage-0.4.3 → pylodstorage-0.4.5}/lodstorage/sparql.py +0 -0
- {pylodstorage-0.4.3 → pylodstorage-0.4.5}/lodstorage/sql.py +0 -0
- {pylodstorage-0.4.3 → pylodstorage-0.4.5}/lodstorage/storageconfig.py +0 -0
- {pylodstorage-0.4.3 → pylodstorage-0.4.5}/lodstorage/tabulateCounter.py +0 -0
- {pylodstorage-0.4.3 → pylodstorage-0.4.5}/lodstorage/uml.py +0 -0
- {pylodstorage-0.4.3 → pylodstorage-0.4.5}/lodstorage/xml.py +0 -0
- {pylodstorage-0.4.3 → pylodstorage-0.4.5}/lodstorage/yamlablemixin.py +0 -0
- {pylodstorage-0.4.3 → pylodstorage-0.4.5}/pylodstorage.egg-info/SOURCES.txt +0 -0
- {pylodstorage-0.4.3 → pylodstorage-0.4.5}/pylodstorage.egg-info/dependency_links.txt +0 -0
- {pylodstorage-0.4.3 → pylodstorage-0.4.5}/pylodstorage.egg-info/entry_points.txt +0 -0
- {pylodstorage-0.4.3 → pylodstorage-0.4.5}/pylodstorage.egg-info/requires.txt +0 -0
- {pylodstorage-0.4.3 → pylodstorage-0.4.5}/pylodstorage.egg-info/top_level.txt +0 -0
- {pylodstorage-0.4.3 → pylodstorage-0.4.5}/sampledata/__init__.py +0 -0
- {pylodstorage-0.4.3 → pylodstorage-0.4.5}/sampledata/endpoints.yaml +0 -0
- {pylodstorage-0.4.3 → pylodstorage-0.4.5}/sampledata/formats.yaml +0 -0
- {pylodstorage-0.4.3 → pylodstorage-0.4.5}/sampledata/got.yaml +0 -0
- {pylodstorage-0.4.3 → pylodstorage-0.4.5}/sampledata/queries.yaml +0 -0
- {pylodstorage-0.4.3 → pylodstorage-0.4.5}/sampledata/scholia.yaml +0 -0
- {pylodstorage-0.4.3 → pylodstorage-0.4.5}/sampledata/trulytabular.yaml +0 -0
- {pylodstorage-0.4.3 → pylodstorage-0.4.5}/sampledata/wf.yaml +0 -0
- {pylodstorage-0.4.3 → pylodstorage-0.4.5}/sampledata/wikidata.yaml +0 -0
- {pylodstorage-0.4.3 → pylodstorage-0.4.5}/setup.cfg +0 -0
- {pylodstorage-0.4.3 → pylodstorage-0.4.5}/setup.py +0 -0
|
@@ -9,6 +9,7 @@ from typing import Union
|
|
|
9
9
|
from lodstorage.sparql import SPARQL
|
|
10
10
|
from lodstorage.query import Query,QueryManager,YamlPath,Endpoint
|
|
11
11
|
from lodstorage.version import Version
|
|
12
|
+
import logging
|
|
12
13
|
from pathlib import Path
|
|
13
14
|
import os
|
|
14
15
|
import textwrap
|
|
@@ -143,6 +144,8 @@ SELECT ?property ?propertyLabel ?wbType WHERE {{
|
|
|
143
144
|
prop.url=url
|
|
144
145
|
wdProperties[prop.plabel]=prop
|
|
145
146
|
prop.varname=Variable.validVarName(prop.plabel)
|
|
147
|
+
prop.valueVarname=f"{prop.varname}Item" if "WikibaseItem" in prop.wbtype else "" f"{prop.varname}"
|
|
148
|
+
prop.labelVarname=f"{prop.varname}"
|
|
146
149
|
pass
|
|
147
150
|
return wdProperties
|
|
148
151
|
|
|
@@ -168,6 +171,8 @@ class WikidataItem:
|
|
|
168
171
|
if sparql is not None:
|
|
169
172
|
self.qlabel,self.description=WikidataItem.getLabelAndDescription(sparql, self.qid, self.lang)
|
|
170
173
|
self.varname=Variable.validVarName(self.qlabel)
|
|
174
|
+
self.itemVarname=f"{self.varname}Item"
|
|
175
|
+
self.labelVarname=f"{self.varname}"
|
|
171
176
|
|
|
172
177
|
def __str__(self):
|
|
173
178
|
return self.asText(long=False)
|
|
@@ -318,7 +323,7 @@ class TrulyTabular(object):
|
|
|
318
323
|
checks "how tabular" a query based on a list of properties of an itemclass is
|
|
319
324
|
'''
|
|
320
325
|
|
|
321
|
-
def __init__(self, itemQid, propertyLabels:list=[],propertyIds:list=[],where:str=None,endpointConf=None,lang="en",debug=False):
|
|
326
|
+
def __init__(self, itemQid, propertyLabels:list=[],propertyIds:list=[],subclassPredicate="wdt:P31",where:str=None,endpointConf=None,lang="en",debug=False):
|
|
322
327
|
'''
|
|
323
328
|
Constructor
|
|
324
329
|
|
|
@@ -326,6 +331,7 @@ class TrulyTabular(object):
|
|
|
326
331
|
itemQid(str): wikidata id of the type to analyze
|
|
327
332
|
propertyLabels(list): a list of labels of properties to be considered
|
|
328
333
|
propertyIds(list): a list of ids of properties to be considered
|
|
334
|
+
subclassPredicate(str): the subclass Predicate to use
|
|
329
335
|
where(str): extra where clause for instance selection (if any)
|
|
330
336
|
endpoint(str): the url of the SPARQL endpoint to be used
|
|
331
337
|
'''
|
|
@@ -336,6 +342,7 @@ class TrulyTabular(object):
|
|
|
336
342
|
self.endpointConf=endpointConf
|
|
337
343
|
self.sparql=SPARQL(endpointConf.endpoint,method=self.endpointConf.method)
|
|
338
344
|
self.sparql.debug=self.debug
|
|
345
|
+
self.subclassPredicate=subclassPredicate
|
|
339
346
|
self.where=f"\n {where}" if where is not None else ""
|
|
340
347
|
self.lang=lang
|
|
341
348
|
self.item=WikidataItem(itemQid,sparql=self.sparql,lang=lang)
|
|
@@ -364,7 +371,7 @@ SELECT (COUNT (DISTINCT ?item) AS ?count)
|
|
|
364
371
|
WHERE
|
|
365
372
|
{{
|
|
366
373
|
# instance of {self.item.qlabel}
|
|
367
|
-
?item
|
|
374
|
+
?item {self.subclassPredicate} wd:{self.item.qid}.{self.where}
|
|
368
375
|
}}"""
|
|
369
376
|
try:
|
|
370
377
|
count=self.sparql.getValue(query, "count")
|
|
@@ -438,11 +445,11 @@ WHERE
|
|
|
438
445
|
# {item.qid}:{item.qlabel}
|
|
439
446
|
# generated by {script} version {Version.version} on {self.isodate}
|
|
440
447
|
{WikidataItem.getPrefixes()}
|
|
441
|
-
SELECT ?{item.
|
|
448
|
+
SELECT ?{item.itemVarname} ?{item.labelVarname}"""
|
|
442
449
|
# loop over all properties
|
|
443
450
|
for wdProp in self.properties.values():
|
|
444
451
|
if naive:
|
|
445
|
-
sparqlQuery+=f"\n ?{wdProp.
|
|
452
|
+
sparqlQuery+=f"\n ?{wdProp.valueVarname}"
|
|
446
453
|
else:
|
|
447
454
|
if wdProp.pid in genMap:
|
|
448
455
|
genList=genMap[wdProp.pid]
|
|
@@ -458,42 +465,44 @@ SELECT ?{item.varname} ?{item.varname}Label"""
|
|
|
458
465
|
distinct="DISTINCT "
|
|
459
466
|
aggregateFunc=aggregate.upper()
|
|
460
467
|
aggregateParam=""
|
|
461
|
-
sparqlQuery+=f"\n ({aggregateFunc} ({distinct}?{wdProp.
|
|
468
|
+
sparqlQuery+=f"\n ({aggregateFunc} ({distinct}?{wdProp.valueVarname}{aggregateParam}) AS ?{wdProp.valueVarname}_{aggregate})"
|
|
462
469
|
elif aggregate=="label":
|
|
463
|
-
sparqlQuery+=f"\n ?{wdProp.
|
|
470
|
+
sparqlQuery+=f"\n ?{wdProp.labelVarname}"
|
|
464
471
|
elif aggregate=="ignore" and not "label" in genList:
|
|
465
|
-
sparqlQuery+=f"\n ?{wdProp.
|
|
472
|
+
sparqlQuery+=f"\n ?{wdProp.valueVarname}"
|
|
466
473
|
sparqlQuery+=f"""
|
|
467
474
|
WHERE {{
|
|
468
475
|
# instanceof {item.qid}:{item.qlabel}
|
|
469
|
-
?{item.
|
|
476
|
+
?{item.itemVarname} {self.subclassPredicate} wd:{item.qid}.
|
|
470
477
|
# label
|
|
471
|
-
?{item.
|
|
472
|
-
FILTER (LANG(?{item.
|
|
478
|
+
?{item.itemVarname} rdfs:label ?{item.labelVarname}.
|
|
479
|
+
FILTER (LANG(?{item.labelVarname}) = "{lang}").
|
|
473
480
|
"""
|
|
474
481
|
for wdProp in self.properties.values():
|
|
475
482
|
sparqlQuery+=f""" # {wdProp}
|
|
476
483
|
OPTIONAL {{
|
|
477
|
-
?{item.
|
|
484
|
+
?{item.itemVarname} wdt:{wdProp.pid} ?{wdProp.valueVarname}. """
|
|
478
485
|
if wdProp.pid in genMap:
|
|
479
486
|
genList=genMap[wdProp.pid]
|
|
480
487
|
if "label" in genList:
|
|
481
|
-
sparqlQuery+=f"""\n ?{wdProp.
|
|
482
|
-
sparqlQuery+=f"""\n FILTER (LANG(?{wdProp.
|
|
488
|
+
sparqlQuery+=f"""\n ?{wdProp.valueVarname} rdfs:label ?{wdProp.labelVarname}."""
|
|
489
|
+
sparqlQuery+=f"""\n FILTER (LANG(?{wdProp.labelVarname}) = "{lang}")."""
|
|
483
490
|
sparqlQuery+="\n }\n"
|
|
484
491
|
# close where Clause
|
|
485
492
|
sparqlQuery+="""}\n"""
|
|
486
493
|
# optionally add Aggregate
|
|
487
494
|
if not naive:
|
|
488
495
|
sparqlQuery+=f"""GROUP BY
|
|
489
|
-
?{item.
|
|
490
|
-
?{item.
|
|
496
|
+
?{item.itemVarname}
|
|
497
|
+
?{item.labelVarname}
|
|
491
498
|
"""
|
|
492
499
|
for wdProp in self.properties.values():
|
|
493
500
|
if wdProp.pid in genMap:
|
|
494
501
|
genList=genMap[wdProp.pid]
|
|
495
502
|
if "label" in genList:
|
|
496
|
-
sparqlQuery+=f"\n ?{wdProp.
|
|
503
|
+
sparqlQuery+=f"\n ?{wdProp.labelVarname}"
|
|
504
|
+
if "ignore" in genList and not "label" in genList:
|
|
505
|
+
sparqlQuery+=f"\n ?{wdProp.valueVarname}"
|
|
497
506
|
havingCount=0
|
|
498
507
|
havingDelim=" "
|
|
499
508
|
for wdProp in self.properties.values():
|
|
@@ -504,7 +513,7 @@ WHERE {{
|
|
|
504
513
|
if havingCount==1:
|
|
505
514
|
sparqlQuery+=f"\nHAVING ("
|
|
506
515
|
|
|
507
|
-
sparqlQuery+=f"\n {havingDelim}COUNT(?{wdProp.
|
|
516
|
+
sparqlQuery+=f"\n {havingDelim}COUNT(?{wdProp.valueVarname})<=1"
|
|
508
517
|
havingDelim="&& "
|
|
509
518
|
if havingCount>0:
|
|
510
519
|
sparqlQuery+=f"\n)"
|
|
@@ -518,7 +527,7 @@ WHERE {{
|
|
|
518
527
|
whereClause(str): an extra WhereClause to use
|
|
519
528
|
'''
|
|
520
529
|
if whereClause is None:
|
|
521
|
-
whereClause=f"?item
|
|
530
|
+
whereClause=f"?item {self.subclassPredicate} wd:{self.itemQid}";
|
|
522
531
|
if self.endpointConf.database!="qlever":
|
|
523
532
|
whereClause+=";?p ?id"
|
|
524
533
|
whereClause+="."
|
|
@@ -582,7 +591,7 @@ ORDER BY DESC (?count)
|
|
|
582
591
|
WHERE
|
|
583
592
|
{{
|
|
584
593
|
# instance of {self.item.qlabel}
|
|
585
|
-
?item
|
|
594
|
+
?item {self.subclassPredicate} wd:{self.itemQid}.{self.where}
|
|
586
595
|
?item rdfs:label ?itemLabel.
|
|
587
596
|
FILTER (LANG(?itemLabel) = "{self.lang}").
|
|
588
597
|
# {propertyLabel}
|
|
@@ -620,7 +629,7 @@ ORDER BY DESC(?count)"""
|
|
|
620
629
|
'''
|
|
621
630
|
query=self.noneTabularQuery(wdProperty)
|
|
622
631
|
if self.debug:
|
|
623
|
-
|
|
632
|
+
logging.info(query.query)
|
|
624
633
|
qlod=self.sparql.queryAsListOfDicts(query.query)
|
|
625
634
|
return qlod
|
|
626
635
|
|
|
@@ -9,7 +9,7 @@ class Version(object):
|
|
|
9
9
|
Version handling for pyLoDStorage
|
|
10
10
|
'''
|
|
11
11
|
name="pylodstorage"
|
|
12
|
-
version='0.4.
|
|
12
|
+
version='0.4.5'
|
|
13
13
|
date = '2020-09-10'
|
|
14
|
-
updated = '2022-08-
|
|
14
|
+
updated = '2022-08-07'
|
|
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
|
|
File without changes
|