pyLodStorage 0.2.9__tar.gz → 0.2.11__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.9/pylodstorage.egg-info → pylodstorage-0.2.11}/PKG-INFO +1 -1
- {pylodstorage-0.2.9 → pylodstorage-0.2.11}/lodstorage/sparql.py +5 -2
- {pylodstorage-0.2.9 → pylodstorage-0.2.11}/lodstorage/trulytabular.py +28 -12
- {pylodstorage-0.2.9 → pylodstorage-0.2.11}/lodstorage/version.py +2 -2
- {pylodstorage-0.2.9 → pylodstorage-0.2.11/pylodstorage.egg-info}/PKG-INFO +1 -1
- {pylodstorage-0.2.9 → pylodstorage-0.2.11}/LICENSE +0 -0
- {pylodstorage-0.2.9 → pylodstorage-0.2.11}/README.md +0 -0
- {pylodstorage-0.2.9 → pylodstorage-0.2.11}/lodstorage/__init__.py +0 -0
- {pylodstorage-0.2.9 → pylodstorage-0.2.11}/lodstorage/csv.py +0 -0
- {pylodstorage-0.2.9 → pylodstorage-0.2.11}/lodstorage/entity.py +0 -0
- {pylodstorage-0.2.9 → pylodstorage-0.2.11}/lodstorage/jsonable.py +0 -0
- {pylodstorage-0.2.9 → pylodstorage-0.2.11}/lodstorage/jsonpicklemixin.py +0 -0
- {pylodstorage-0.2.9 → pylodstorage-0.2.11}/lodstorage/lod.py +0 -0
- {pylodstorage-0.2.9 → pylodstorage-0.2.11}/lodstorage/mwTable.py +0 -0
- {pylodstorage-0.2.9 → pylodstorage-0.2.11}/lodstorage/plot.py +0 -0
- {pylodstorage-0.2.9 → pylodstorage-0.2.11}/lodstorage/query.py +0 -0
- {pylodstorage-0.2.9 → pylodstorage-0.2.11}/lodstorage/querymain.py +0 -0
- {pylodstorage-0.2.9 → pylodstorage-0.2.11}/lodstorage/sample.py +0 -0
- {pylodstorage-0.2.9 → pylodstorage-0.2.11}/lodstorage/schema.py +0 -0
- {pylodstorage-0.2.9 → pylodstorage-0.2.11}/lodstorage/sql.py +0 -0
- {pylodstorage-0.2.9 → pylodstorage-0.2.11}/lodstorage/storageconfig.py +0 -0
- {pylodstorage-0.2.9 → pylodstorage-0.2.11}/lodstorage/tabulateCounter.py +0 -0
- {pylodstorage-0.2.9 → pylodstorage-0.2.11}/lodstorage/uml.py +0 -0
- {pylodstorage-0.2.9 → pylodstorage-0.2.11}/lodstorage/xml.py +0 -0
- {pylodstorage-0.2.9 → pylodstorage-0.2.11}/lodstorage/yamlablemixin.py +0 -0
- {pylodstorage-0.2.9 → pylodstorage-0.2.11}/pylodstorage.egg-info/SOURCES.txt +0 -0
- {pylodstorage-0.2.9 → pylodstorage-0.2.11}/pylodstorage.egg-info/dependency_links.txt +0 -0
- {pylodstorage-0.2.9 → pylodstorage-0.2.11}/pylodstorage.egg-info/entry_points.txt +0 -0
- {pylodstorage-0.2.9 → pylodstorage-0.2.11}/pylodstorage.egg-info/requires.txt +0 -0
- {pylodstorage-0.2.9 → pylodstorage-0.2.11}/pylodstorage.egg-info/top_level.txt +0 -0
- {pylodstorage-0.2.9 → pylodstorage-0.2.11}/sampledata/__init__.py +0 -0
- {pylodstorage-0.2.9 → pylodstorage-0.2.11}/sampledata/endpoints.yaml +0 -0
- {pylodstorage-0.2.9 → pylodstorage-0.2.11}/sampledata/formats.yaml +0 -0
- {pylodstorage-0.2.9 → pylodstorage-0.2.11}/sampledata/queries.yaml +0 -0
- {pylodstorage-0.2.9 → pylodstorage-0.2.11}/sampledata/scholia.yaml +0 -0
- {pylodstorage-0.2.9 → pylodstorage-0.2.11}/sampledata/trulytabular.yaml +0 -0
- {pylodstorage-0.2.9 → pylodstorage-0.2.11}/sampledata/wf.yaml +0 -0
- {pylodstorage-0.2.9 → pylodstorage-0.2.11}/sampledata/wikidata.yaml +0 -0
- {pylodstorage-0.2.9 → pylodstorage-0.2.11}/setup.cfg +0 -0
- {pylodstorage-0.2.9 → pylodstorage-0.2.11}/setup.py +0 -0
|
@@ -22,7 +22,7 @@ class SPARQL(object):
|
|
|
22
22
|
:ivar sparql: the SPARQLWrapper2 instance to be used
|
|
23
23
|
:ivar method(str): the HTTP method to be used 'POST' or 'GET'
|
|
24
24
|
'''
|
|
25
|
-
def __init__(self,url,mode='query', debug=False, typedLiterals=False, profile=False, agent='PyLodStorage',method='POST'):
|
|
25
|
+
def __init__(self,url,mode='query', debug=False, isFuseki=False,typedLiterals=False, profile=False, agent='PyLodStorage',method='POST'):
|
|
26
26
|
'''
|
|
27
27
|
Constructor a SPARQL wrapper
|
|
28
28
|
|
|
@@ -35,7 +35,10 @@ class SPARQL(object):
|
|
|
35
35
|
agent(string): the User agent to use
|
|
36
36
|
method(string): the HTTP method to be used 'POST' or 'GET'
|
|
37
37
|
'''
|
|
38
|
-
|
|
38
|
+
if isFuseki:
|
|
39
|
+
self.url=f"{url}/{mode}"
|
|
40
|
+
else:
|
|
41
|
+
self.url=url
|
|
39
42
|
self.mode=mode
|
|
40
43
|
self.debug=debug
|
|
41
44
|
self.typedLiterals=typedLiterals
|
|
@@ -6,6 +6,7 @@ Created on 2022-04-14
|
|
|
6
6
|
from lodstorage.sparql import SPARQL
|
|
7
7
|
from lodstorage.query import Query,QueryManager,YamlPath
|
|
8
8
|
import os
|
|
9
|
+
import textwrap
|
|
9
10
|
import re
|
|
10
11
|
|
|
11
12
|
class WikidataProperty():
|
|
@@ -134,21 +135,22 @@ class WikidataItem:
|
|
|
134
135
|
sparql(SPARQL): the sparql access to use
|
|
135
136
|
'''
|
|
136
137
|
self.qid=qid
|
|
138
|
+
self.url=f"https://www.wikidata.org/wiki/{self.qid}"
|
|
137
139
|
self.lang=lang
|
|
138
140
|
self.sparql=sparql
|
|
139
141
|
if sparql is not None:
|
|
140
142
|
self.qlabel,self.description=WikidataItem.getLabelAndDescription(sparql, self.qid, self.lang)
|
|
141
143
|
|
|
142
144
|
def __str__(self):
|
|
143
|
-
|
|
144
145
|
return self.asText(long=False)
|
|
145
146
|
|
|
146
|
-
def asText(self,long:bool=True):
|
|
147
|
+
def asText(self,long:bool=True,wrapAt:int=0):
|
|
147
148
|
'''
|
|
148
149
|
returns my content as a text representation
|
|
149
150
|
|
|
150
151
|
Args:
|
|
151
152
|
long(bool): True if a long format including url is wished
|
|
153
|
+
wrapAt(int): wrap long lines at the given width (if >0)
|
|
152
154
|
|
|
153
155
|
Returns:
|
|
154
156
|
str: a text representation of my content
|
|
@@ -157,9 +159,12 @@ class WikidataItem:
|
|
|
157
159
|
if hasattr(self, "qlabel"):
|
|
158
160
|
text=f"{self.qlabel} ({self.qid})"
|
|
159
161
|
if hasattr(self,"description"):
|
|
160
|
-
|
|
162
|
+
desc=self.description
|
|
163
|
+
if wrapAt>0:
|
|
164
|
+
desc=textwrap.fill(desc,width=wrapAt)
|
|
165
|
+
text+=f"☞{desc}"
|
|
161
166
|
if long:
|
|
162
|
-
text+=f"
|
|
167
|
+
text+=f"→ {self.url}"
|
|
163
168
|
return text
|
|
164
169
|
|
|
165
170
|
@classmethod
|
|
@@ -269,7 +274,7 @@ class TrulyTabular(object):
|
|
|
269
274
|
self.queryManager=TrulyTabular.getQueryManager(debug=self.debug)
|
|
270
275
|
self.properties=WikidataProperty.getPropertiesByIds(self.sparql,propertyIds,lang)
|
|
271
276
|
self.properties.update(WikidataProperty.getPropertiesByLabels(self.sparql, propertyLabels, lang))
|
|
272
|
-
|
|
277
|
+
self.error=None
|
|
273
278
|
|
|
274
279
|
def __str__(self):
|
|
275
280
|
'''
|
|
@@ -282,8 +287,9 @@ class TrulyTabular(object):
|
|
|
282
287
|
'''
|
|
283
288
|
get my count
|
|
284
289
|
'''
|
|
285
|
-
|
|
286
|
-
# type
|
|
290
|
+
itemText=self.getItemText()
|
|
291
|
+
query=f"""# Count all items with the given type
|
|
292
|
+
# {itemText}
|
|
287
293
|
PREFIX wd: <http://www.wikidata.org/entity/>
|
|
288
294
|
PREFIX wdt: <http://www.wikidata.org/prop/direct/>
|
|
289
295
|
SELECT (COUNT (DISTINCT ?item) AS ?count)
|
|
@@ -295,6 +301,7 @@ WHERE
|
|
|
295
301
|
try:
|
|
296
302
|
count=self.sparql.getValue(query, "count")
|
|
297
303
|
except Exception as ex:
|
|
304
|
+
self.error=ex
|
|
298
305
|
count=None
|
|
299
306
|
|
|
300
307
|
return count
|
|
@@ -312,6 +319,12 @@ WHERE
|
|
|
312
319
|
text=self.item.asText(long)
|
|
313
320
|
return text
|
|
314
321
|
|
|
322
|
+
def getItemText(self):
|
|
323
|
+
# leads to 405 Method not allowed in SPARQLWrapper under certain circumstances
|
|
324
|
+
# itemText=self.asText(long=True)
|
|
325
|
+
itemText=self.itemQid
|
|
326
|
+
return itemText
|
|
327
|
+
|
|
315
328
|
@classmethod
|
|
316
329
|
def getQueryManager(cls,lang='sparql',name="trulytabular",debug=False):
|
|
317
330
|
'''
|
|
@@ -340,9 +353,10 @@ WHERE
|
|
|
340
353
|
if whereClause is None:
|
|
341
354
|
whereClause=f"?item wdt:P31 wd:{self.itemQid};";
|
|
342
355
|
else:
|
|
343
|
-
whereClause+=";"
|
|
344
|
-
|
|
345
|
-
query.
|
|
356
|
+
whereClause+=";"
|
|
357
|
+
itemText=self.getItemText()
|
|
358
|
+
query.title=f"most frequently used properties for {self.item.asText(long=True)}"
|
|
359
|
+
query.query=query.query % (itemText,whereClause,self.lang)
|
|
346
360
|
return query
|
|
347
361
|
|
|
348
362
|
def noneTabularQuery(self,wdProperty:WikidataProperty,asFrequency:bool=True):
|
|
@@ -384,7 +398,9 @@ ORDER BY DESC (?frequency)"""
|
|
|
384
398
|
sparql=f"""{sparql}
|
|
385
399
|
HAVING (COUNT (?value) > 1)
|
|
386
400
|
ORDER BY DESC(?count)"""
|
|
387
|
-
|
|
401
|
+
title=f"non tabular entries for {self.item.qlabel}/{propertyLabel}:{freqDesc}"
|
|
402
|
+
name=f"NonTabular {self.item.qlabel}/{propertyLabel}:{freqDesc}"
|
|
403
|
+
query=Query(query=sparql,name=name,title=title)
|
|
388
404
|
return query
|
|
389
405
|
|
|
390
406
|
def noneTabular(self,wdProperty:WikidataProperty):
|
|
@@ -435,7 +451,7 @@ ORDER BY DESC(?count)"""
|
|
|
435
451
|
if count>maxCount:
|
|
436
452
|
maxCount=count
|
|
437
453
|
total+=f
|
|
438
|
-
statsRow["
|
|
454
|
+
statsRow["maxf"]=maxCount
|
|
439
455
|
if withQuery:
|
|
440
456
|
statsRow["queryf"]=self.noneTabularQuery(wdProperty).query
|
|
441
457
|
statsRow["queryex"]=self.noneTabularQuery(wdProperty,asFrequency=False).query
|
|
@@ -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.11'
|
|
13
13
|
date = '2020-09-10'
|
|
14
|
-
updated = '2022-07-
|
|
14
|
+
updated = '2022-07-26'
|
|
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
|