pyLodStorage 0.2.11__tar.gz → 0.2.13__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.11/pylodstorage.egg-info → pylodstorage-0.2.13}/PKG-INFO +1 -1
- {pylodstorage-0.2.11 → pylodstorage-0.2.13}/lodstorage/querymain.py +11 -1
- {pylodstorage-0.2.11 → pylodstorage-0.2.13}/lodstorage/trulytabular.py +67 -8
- {pylodstorage-0.2.11 → pylodstorage-0.2.13}/lodstorage/version.py +2 -2
- {pylodstorage-0.2.11 → pylodstorage-0.2.13/pylodstorage.egg-info}/PKG-INFO +1 -1
- {pylodstorage-0.2.11 → pylodstorage-0.2.13}/LICENSE +0 -0
- {pylodstorage-0.2.11 → pylodstorage-0.2.13}/README.md +0 -0
- {pylodstorage-0.2.11 → pylodstorage-0.2.13}/lodstorage/__init__.py +0 -0
- {pylodstorage-0.2.11 → pylodstorage-0.2.13}/lodstorage/csv.py +0 -0
- {pylodstorage-0.2.11 → pylodstorage-0.2.13}/lodstorage/entity.py +0 -0
- {pylodstorage-0.2.11 → pylodstorage-0.2.13}/lodstorage/jsonable.py +0 -0
- {pylodstorage-0.2.11 → pylodstorage-0.2.13}/lodstorage/jsonpicklemixin.py +0 -0
- {pylodstorage-0.2.11 → pylodstorage-0.2.13}/lodstorage/lod.py +0 -0
- {pylodstorage-0.2.11 → pylodstorage-0.2.13}/lodstorage/mwTable.py +0 -0
- {pylodstorage-0.2.11 → pylodstorage-0.2.13}/lodstorage/plot.py +0 -0
- {pylodstorage-0.2.11 → pylodstorage-0.2.13}/lodstorage/query.py +0 -0
- {pylodstorage-0.2.11 → pylodstorage-0.2.13}/lodstorage/sample.py +0 -0
- {pylodstorage-0.2.11 → pylodstorage-0.2.13}/lodstorage/schema.py +0 -0
- {pylodstorage-0.2.11 → pylodstorage-0.2.13}/lodstorage/sparql.py +0 -0
- {pylodstorage-0.2.11 → pylodstorage-0.2.13}/lodstorage/sql.py +0 -0
- {pylodstorage-0.2.11 → pylodstorage-0.2.13}/lodstorage/storageconfig.py +0 -0
- {pylodstorage-0.2.11 → pylodstorage-0.2.13}/lodstorage/tabulateCounter.py +0 -0
- {pylodstorage-0.2.11 → pylodstorage-0.2.13}/lodstorage/uml.py +0 -0
- {pylodstorage-0.2.11 → pylodstorage-0.2.13}/lodstorage/xml.py +0 -0
- {pylodstorage-0.2.11 → pylodstorage-0.2.13}/lodstorage/yamlablemixin.py +0 -0
- {pylodstorage-0.2.11 → pylodstorage-0.2.13}/pylodstorage.egg-info/SOURCES.txt +0 -0
- {pylodstorage-0.2.11 → pylodstorage-0.2.13}/pylodstorage.egg-info/dependency_links.txt +0 -0
- {pylodstorage-0.2.11 → pylodstorage-0.2.13}/pylodstorage.egg-info/entry_points.txt +0 -0
- {pylodstorage-0.2.11 → pylodstorage-0.2.13}/pylodstorage.egg-info/requires.txt +0 -0
- {pylodstorage-0.2.11 → pylodstorage-0.2.13}/pylodstorage.egg-info/top_level.txt +0 -0
- {pylodstorage-0.2.11 → pylodstorage-0.2.13}/sampledata/__init__.py +0 -0
- {pylodstorage-0.2.11 → pylodstorage-0.2.13}/sampledata/endpoints.yaml +0 -0
- {pylodstorage-0.2.11 → pylodstorage-0.2.13}/sampledata/formats.yaml +0 -0
- {pylodstorage-0.2.11 → pylodstorage-0.2.13}/sampledata/queries.yaml +0 -0
- {pylodstorage-0.2.11 → pylodstorage-0.2.13}/sampledata/scholia.yaml +0 -0
- {pylodstorage-0.2.11 → pylodstorage-0.2.13}/sampledata/trulytabular.yaml +0 -0
- {pylodstorage-0.2.11 → pylodstorage-0.2.13}/sampledata/wf.yaml +0 -0
- {pylodstorage-0.2.11 → pylodstorage-0.2.13}/sampledata/wikidata.yaml +0 -0
- {pylodstorage-0.2.11 → pylodstorage-0.2.13}/setup.cfg +0 -0
- {pylodstorage-0.2.11 → pylodstorage-0.2.13}/setup.py +0 -0
|
@@ -4,6 +4,7 @@ Created on 2022-02-13
|
|
|
4
4
|
@author: wf
|
|
5
5
|
'''
|
|
6
6
|
from lodstorage.version import Version
|
|
7
|
+
from pathlib import Path
|
|
7
8
|
__version__ = Version.version
|
|
8
9
|
__date__ = Version.date
|
|
9
10
|
__updated__ = Version.updated
|
|
@@ -20,7 +21,7 @@ from argparse import ArgumentParser
|
|
|
20
21
|
from argparse import RawDescriptionHelpFormatter
|
|
21
22
|
|
|
22
23
|
from lodstorage.csv import CSV
|
|
23
|
-
from lodstorage.query import QueryManager, EndpointManager, Format, ValueFormatter
|
|
24
|
+
from lodstorage.query import Query,QueryManager, EndpointManager, Format, ValueFormatter
|
|
24
25
|
from lodstorage.sparql import SPARQL
|
|
25
26
|
from lodstorage.sql import SQLDB
|
|
26
27
|
from lodstorage.xml import Lod2Xml
|
|
@@ -42,6 +43,7 @@ class QueryMain:
|
|
|
42
43
|
debug=args.debug
|
|
43
44
|
endpoints=EndpointManager.getEndpoints(args.endpointPath)
|
|
44
45
|
qm=QueryManager(lang=args.language,debug=debug,queriesPath=args.queriesPath)
|
|
46
|
+
query=None
|
|
45
47
|
queryCode=args.query
|
|
46
48
|
endpointConf=None
|
|
47
49
|
formats=None
|
|
@@ -66,6 +68,13 @@ class QueryMain:
|
|
|
66
68
|
if debug or args.showQuery:
|
|
67
69
|
if hasattr(query, "description") and query.description is not None:
|
|
68
70
|
print(query.description)
|
|
71
|
+
if query is None:
|
|
72
|
+
name="?"
|
|
73
|
+
if queryCode is None and args.queryFile is not None:
|
|
74
|
+
queryFilePath=Path(args.queryFile)
|
|
75
|
+
queryCode = queryFilePath.read_text()
|
|
76
|
+
name=queryFilePath.stem
|
|
77
|
+
query=Query(name="?",query=queryCode,lang=args.language)
|
|
69
78
|
if queryCode:
|
|
70
79
|
if debug or args.showQuery:
|
|
71
80
|
print(f"{args.language}:\n{queryCode}")
|
|
@@ -199,6 +208,7 @@ USAGE
|
|
|
199
208
|
parser.add_argument('-sq','--showQuery',action="store_true",help="show the query")
|
|
200
209
|
parser.add_argument('-qp', '--queriesPath',help="path to YAML file with query definitions")
|
|
201
210
|
parser.add_argument("-q", "--query",help="the query to run")
|
|
211
|
+
parser.add_argument("-qf", "--queryFile",help="the query file to run")
|
|
202
212
|
parser.add_argument("-qn","--queryName",help="run a named query")
|
|
203
213
|
parser.add_argument("-raw",action="store_true", help="return the raw query result from the endpoint. (MIME type defined over -f or -m)")
|
|
204
214
|
parser.add_argument('-V', '--version', action='version', version=program_version_message)
|
|
@@ -3,12 +3,32 @@ Created on 2022-04-14
|
|
|
3
3
|
|
|
4
4
|
@author: wf
|
|
5
5
|
'''
|
|
6
|
+
import datetime
|
|
6
7
|
from lodstorage.sparql import SPARQL
|
|
7
8
|
from lodstorage.query import Query,QueryManager,YamlPath
|
|
9
|
+
from pathlib import Path
|
|
8
10
|
import os
|
|
9
11
|
import textwrap
|
|
10
12
|
import re
|
|
11
13
|
|
|
14
|
+
class Variable:
|
|
15
|
+
'''
|
|
16
|
+
Variable e.g. name handling
|
|
17
|
+
'''
|
|
18
|
+
@classmethod
|
|
19
|
+
def validVarName(cls,varStr:str)->str:
|
|
20
|
+
'''
|
|
21
|
+
convert the given potential variable name string to a valid
|
|
22
|
+
variable name
|
|
23
|
+
|
|
24
|
+
Args:
|
|
25
|
+
varStr(str): the string to convert
|
|
26
|
+
|
|
27
|
+
Returns:
|
|
28
|
+
str: a valid variable name
|
|
29
|
+
'''
|
|
30
|
+
return re.sub('\W|^(?=\d)','_', varStr)
|
|
31
|
+
|
|
12
32
|
class WikidataProperty():
|
|
13
33
|
'''
|
|
14
34
|
a WikidataProperty
|
|
@@ -29,13 +49,13 @@ class WikidataProperty():
|
|
|
29
49
|
get me as a Predicate
|
|
30
50
|
'''
|
|
31
51
|
reverseToken="^" if self.reverse else ""
|
|
32
|
-
|
|
33
|
-
return
|
|
52
|
+
plabel=f"{reverseToken}wdt:{self.pid}"
|
|
53
|
+
return plabel
|
|
34
54
|
|
|
35
55
|
def __str__(self):
|
|
36
56
|
text=self.pid
|
|
37
|
-
if hasattr(self, "
|
|
38
|
-
text=f"{self.
|
|
57
|
+
if hasattr(self, "plabel"):
|
|
58
|
+
text=f"{self.plabel} ({self.pid})"
|
|
39
59
|
return text
|
|
40
60
|
|
|
41
61
|
@classmethod
|
|
@@ -115,9 +135,10 @@ SELECT ?property ?propertyLabel WHERE {
|
|
|
115
135
|
url=record["property"]
|
|
116
136
|
pid=re.sub(r"http://www.wikidata.org/entity/(.*)",r"\1",url)
|
|
117
137
|
prop=WikidataProperty(pid)
|
|
118
|
-
prop.
|
|
138
|
+
prop.plabel=record["propertyLabel"]
|
|
119
139
|
prop.url=url
|
|
120
|
-
wdProperties[prop.
|
|
140
|
+
wdProperties[prop.plabel]=prop
|
|
141
|
+
prop.varname=Variable.validVarName(prop.plabel)
|
|
121
142
|
pass
|
|
122
143
|
return wdProperties
|
|
123
144
|
|
|
@@ -140,6 +161,7 @@ class WikidataItem:
|
|
|
140
161
|
self.sparql=sparql
|
|
141
162
|
if sparql is not None:
|
|
142
163
|
self.qlabel,self.description=WikidataItem.getLabelAndDescription(sparql, self.qid, self.lang)
|
|
164
|
+
self.varname=Variable.validVarName(self.qlabel)
|
|
143
165
|
|
|
144
166
|
def __str__(self):
|
|
145
167
|
return self.asText(long=False)
|
|
@@ -238,6 +260,7 @@ WHERE {
|
|
|
238
260
|
item=WikidataItem(qid)
|
|
239
261
|
item.url=url
|
|
240
262
|
item.qlabel=record["itemLabel"]
|
|
263
|
+
item.varname=Variable.validVarName(item.qlabel)
|
|
241
264
|
item.description=record["itemDescription"]
|
|
242
265
|
items.append(item)
|
|
243
266
|
return items
|
|
@@ -274,6 +297,7 @@ class TrulyTabular(object):
|
|
|
274
297
|
self.queryManager=TrulyTabular.getQueryManager(debug=self.debug)
|
|
275
298
|
self.properties=WikidataProperty.getPropertiesByIds(self.sparql,propertyIds,lang)
|
|
276
299
|
self.properties.update(WikidataProperty.getPropertiesByLabels(self.sparql, propertyLabels, lang))
|
|
300
|
+
self.isodate=datetime.datetime.now().isoformat()
|
|
277
301
|
self.error=None
|
|
278
302
|
|
|
279
303
|
def __str__(self):
|
|
@@ -342,6 +366,41 @@ WHERE
|
|
|
342
366
|
return qm
|
|
343
367
|
return None
|
|
344
368
|
|
|
369
|
+
|
|
370
|
+
|
|
371
|
+
def generateSparqlQuery(self,lang:str='en',naive:bool=True)->str:
|
|
372
|
+
'''
|
|
373
|
+
generate a SPARQL Query
|
|
374
|
+
'''
|
|
375
|
+
item=self.item
|
|
376
|
+
script=Path(__file__).name
|
|
377
|
+
sparqlQuery=f"""
|
|
378
|
+
# truly tabular query for
|
|
379
|
+
# {item.qid}:{item.qlabel}
|
|
380
|
+
# generated by {script} on {self.isodate}
|
|
381
|
+
PREFIX wd: <http://www.wikidata.org/entity/>
|
|
382
|
+
PREFIX wdt: <http://www.wikidata.org/prop/direct/>
|
|
383
|
+
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
|
|
384
|
+
SELECT ?{item.varname} ?{item.varname}Label"""
|
|
385
|
+
for wdProp in self.properties.values():
|
|
386
|
+
sparqlQuery+=f"\n ?{wdProp.varname}"
|
|
387
|
+
sparqlQuery+=f"""
|
|
388
|
+
WHERE {{
|
|
389
|
+
# instanceof {item.qid}:{item.qlabel}
|
|
390
|
+
?{item.varname} wdt:P31 wd:{item.qid}.
|
|
391
|
+
# label
|
|
392
|
+
?{item.varname} rdfs:label ?{item.varname}Label
|
|
393
|
+
FILTER (LANG(?{item.varname}Label) = "{lang}").
|
|
394
|
+
"""
|
|
395
|
+
if naive:
|
|
396
|
+
for wdProp in self.properties.values():
|
|
397
|
+
sparqlQuery+=f""" # {wdProp}
|
|
398
|
+
OPTIONAL {{ ?{item.varname} wdt:{wdProp.pid} ?{wdProp.varname}. }}
|
|
399
|
+
"""
|
|
400
|
+
pass
|
|
401
|
+
sparqlQuery+="""}\n"""
|
|
402
|
+
return sparqlQuery
|
|
403
|
+
|
|
345
404
|
def mostFrequentPropertiesQuery(self,whereClause:str=None):
|
|
346
405
|
'''
|
|
347
406
|
get the most frequently used properties
|
|
@@ -367,7 +426,7 @@ WHERE
|
|
|
367
426
|
wdProperty(WikidataProperty): the property to analyze
|
|
368
427
|
asFrequency(bool): if true do a frequency analysis
|
|
369
428
|
'''
|
|
370
|
-
propertyLabel=wdProperty.
|
|
429
|
+
propertyLabel=wdProperty.plabel
|
|
371
430
|
propertyId=wdProperty.pid
|
|
372
431
|
# work around https://github.com/RDFLib/sparqlwrapper/issues/211
|
|
373
432
|
if "described at" in propertyLabel:
|
|
@@ -436,7 +495,7 @@ ORDER BY DESC(?count)"""
|
|
|
436
495
|
dict: a statistics row
|
|
437
496
|
'''
|
|
438
497
|
ntlod=self.noneTabular(wdProperty)
|
|
439
|
-
statsRow={"property":wdProperty.
|
|
498
|
+
statsRow={"property":wdProperty.plabel}
|
|
440
499
|
total=0
|
|
441
500
|
nttotal=0
|
|
442
501
|
maxCount=0
|
|
@@ -9,7 +9,7 @@ class Version(object):
|
|
|
9
9
|
Version handling for pyLoDStorage
|
|
10
10
|
'''
|
|
11
11
|
name="pylodstorage"
|
|
12
|
-
version='0.2.
|
|
12
|
+
version='0.2.13'
|
|
13
13
|
date = '2020-09-10'
|
|
14
|
-
updated = '2022-07-
|
|
14
|
+
updated = '2022-07-27'
|
|
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
|