pyLodStorage 0.2.1__tar.gz → 0.2.3__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.1 → pylodstorage-0.2.3}/PKG-INFO +1 -1
- {pylodstorage-0.2.1 → pylodstorage-0.2.3}/lodstorage/querymain.py +14 -2
- {pylodstorage-0.2.1 → pylodstorage-0.2.3}/lodstorage/sql.py +20 -5
- {pylodstorage-0.2.1 → pylodstorage-0.2.3}/lodstorage/trulytabular.py +10 -2
- {pylodstorage-0.2.1 → pylodstorage-0.2.3}/lodstorage/version.py +2 -2
- pylodstorage-0.2.3/lodstorage/xml.py +49 -0
- {pylodstorage-0.2.1 → pylodstorage-0.2.3}/pylodstorage.egg-info/PKG-INFO +1 -1
- {pylodstorage-0.2.1 → pylodstorage-0.2.3}/pylodstorage.egg-info/SOURCES.txt +1 -0
- {pylodstorage-0.2.1 → pylodstorage-0.2.3}/sampledata/trulytabular.yaml +1 -1
- {pylodstorage-0.2.1 → pylodstorage-0.2.3}/sampledata/wikidata.yaml +44 -0
- {pylodstorage-0.2.1 → pylodstorage-0.2.3}/LICENSE +0 -0
- {pylodstorage-0.2.1 → pylodstorage-0.2.3}/README.md +0 -0
- {pylodstorage-0.2.1 → pylodstorage-0.2.3}/lodstorage/csv.py +0 -0
- {pylodstorage-0.2.1 → pylodstorage-0.2.3}/lodstorage/entity.py +0 -0
- {pylodstorage-0.2.1 → pylodstorage-0.2.3}/lodstorage/jsonable.py +0 -0
- {pylodstorage-0.2.1 → pylodstorage-0.2.3}/lodstorage/jsonpicklemixin.py +0 -0
- {pylodstorage-0.2.1 → pylodstorage-0.2.3}/lodstorage/lod.py +0 -0
- {pylodstorage-0.2.1 → pylodstorage-0.2.3}/lodstorage/mwTable.py +0 -0
- {pylodstorage-0.2.1 → pylodstorage-0.2.3}/lodstorage/plot.py +0 -0
- {pylodstorage-0.2.1 → pylodstorage-0.2.3}/lodstorage/query.py +0 -0
- {pylodstorage-0.2.1 → pylodstorage-0.2.3}/lodstorage/sample.py +0 -0
- {pylodstorage-0.2.1 → pylodstorage-0.2.3}/lodstorage/schema.py +0 -0
- {pylodstorage-0.2.1 → pylodstorage-0.2.3}/lodstorage/sparql.py +0 -0
- {pylodstorage-0.2.1 → pylodstorage-0.2.3}/lodstorage/storageconfig.py +0 -0
- {pylodstorage-0.2.1 → pylodstorage-0.2.3}/lodstorage/tabulateCounter.py +0 -0
- {pylodstorage-0.2.1 → pylodstorage-0.2.3}/lodstorage/uml.py +0 -0
- {pylodstorage-0.2.1 → pylodstorage-0.2.3}/lodstorage/yamlablemixin.py +0 -0
- {pylodstorage-0.2.1 → pylodstorage-0.2.3}/pylodstorage.egg-info/dependency_links.txt +0 -0
- {pylodstorage-0.2.1 → pylodstorage-0.2.3}/pylodstorage.egg-info/entry_points.txt +0 -0
- {pylodstorage-0.2.1 → pylodstorage-0.2.3}/pylodstorage.egg-info/requires.txt +0 -0
- {pylodstorage-0.2.1 → pylodstorage-0.2.3}/pylodstorage.egg-info/top_level.txt +0 -0
- {pylodstorage-0.2.1 → pylodstorage-0.2.3}/sampledata/__init__.py +0 -0
- {pylodstorage-0.2.1 → pylodstorage-0.2.3}/sampledata/endpoints.yaml +0 -0
- {pylodstorage-0.2.1 → pylodstorage-0.2.3}/sampledata/formats.yaml +0 -0
- {pylodstorage-0.2.1 → pylodstorage-0.2.3}/sampledata/queries.yaml +0 -0
- {pylodstorage-0.2.1 → pylodstorage-0.2.3}/sampledata/scholia.yaml +0 -0
- {pylodstorage-0.2.1 → pylodstorage-0.2.3}/sampledata/wf.yaml +0 -0
- {pylodstorage-0.2.1 → pylodstorage-0.2.3}/setup.cfg +0 -0
- {pylodstorage-0.2.1 → pylodstorage-0.2.3}/setup.py +0 -0
|
@@ -15,17 +15,22 @@ import requests
|
|
|
15
15
|
import sys
|
|
16
16
|
import traceback
|
|
17
17
|
import os
|
|
18
|
+
|
|
18
19
|
from argparse import ArgumentParser
|
|
19
20
|
from argparse import RawDescriptionHelpFormatter
|
|
20
|
-
|
|
21
|
+
|
|
22
|
+
from lodstorage.csv import CSV
|
|
23
|
+
from lodstorage.query import QueryManager, EndpointManager, Format, ValueFormatter
|
|
21
24
|
from lodstorage.sparql import SPARQL
|
|
22
25
|
from lodstorage.sql import SQLDB
|
|
23
|
-
from lodstorage.
|
|
26
|
+
from lodstorage.xml import Lod2Xml
|
|
27
|
+
|
|
24
28
|
|
|
25
29
|
class QueryMain:
|
|
26
30
|
'''
|
|
27
31
|
Commandline handler
|
|
28
32
|
'''
|
|
33
|
+
|
|
29
34
|
@classmethod
|
|
30
35
|
def main(cls,args):
|
|
31
36
|
'''
|
|
@@ -99,6 +104,13 @@ class QueryMain:
|
|
|
99
104
|
print (docstr)
|
|
100
105
|
elif args.format in [Format.json]:
|
|
101
106
|
print(json.dumps(qlod))
|
|
107
|
+
elif args.format in [Format.xml]:
|
|
108
|
+
lod2xml=Lod2Xml(qlod)
|
|
109
|
+
xml=lod2xml.asXml()
|
|
110
|
+
print(xml)
|
|
111
|
+
|
|
112
|
+
else:
|
|
113
|
+
raise Exception(f"format {args.format} not supported yet")
|
|
102
114
|
|
|
103
115
|
@staticmethod
|
|
104
116
|
def rawQuery(endpoint, query, resultFormat, mimeType):
|
|
@@ -173,9 +173,9 @@ class SQLDB(object):
|
|
|
173
173
|
msg="%s\nfailed:%s%s" % (insertCmd,str(ex),debugInfo)
|
|
174
174
|
raise Exception(msg)
|
|
175
175
|
|
|
176
|
-
def
|
|
176
|
+
def queryGen(self,sqlQuery,params=None):
|
|
177
177
|
'''
|
|
178
|
-
run the given sqlQuery
|
|
178
|
+
run the given sqlQuery a a generator for dicts
|
|
179
179
|
|
|
180
180
|
Args:
|
|
181
181
|
|
|
@@ -183,7 +183,7 @@ class SQLDB(object):
|
|
|
183
183
|
params(tuple): the query params, if any
|
|
184
184
|
|
|
185
185
|
Returns:
|
|
186
|
-
|
|
186
|
+
a generator of dicts
|
|
187
187
|
'''
|
|
188
188
|
if self.debug:
|
|
189
189
|
print(sqlQuery)
|
|
@@ -196,17 +196,32 @@ class SQLDB(object):
|
|
|
196
196
|
else:
|
|
197
197
|
query = cur.execute(sqlQuery)
|
|
198
198
|
colname = [ d[0] for d in query.description ]
|
|
199
|
-
resultList=[]
|
|
200
199
|
try:
|
|
201
200
|
# loop over all rows
|
|
202
201
|
for row in query:
|
|
203
202
|
record=dict(zip(colname, row))
|
|
204
|
-
|
|
203
|
+
yield record
|
|
205
204
|
except Exception as ex:
|
|
206
205
|
msg=str(ex)
|
|
207
206
|
self.logError(msg)
|
|
208
207
|
pass
|
|
209
208
|
cur.close()
|
|
209
|
+
|
|
210
|
+
def query(self,sqlQuery,params=None):
|
|
211
|
+
'''
|
|
212
|
+
run the given sqlQuery and return a list of Dicts
|
|
213
|
+
|
|
214
|
+
Args:
|
|
215
|
+
|
|
216
|
+
sqlQuery(string): the SQL query to be executed
|
|
217
|
+
params(tuple): the query params, if any
|
|
218
|
+
|
|
219
|
+
Returns:
|
|
220
|
+
list: a list of Dicts
|
|
221
|
+
'''
|
|
222
|
+
resultList=[]
|
|
223
|
+
for record in self.queryGen(sqlQuery, params):
|
|
224
|
+
resultList.append(record)
|
|
210
225
|
return resultList
|
|
211
226
|
|
|
212
227
|
def queryAll(self,entityInfo,fixDates=True):
|
|
@@ -262,6 +262,7 @@ class TrulyTabular(object):
|
|
|
262
262
|
endpoint=TrulyTabular.endpoint
|
|
263
263
|
self.endpoint=endpoint
|
|
264
264
|
self.sparql=SPARQL(endpoint,method=method)
|
|
265
|
+
self.sparql.debug=self.debug
|
|
265
266
|
self.where=f"\n {where}" if where is not None else ""
|
|
266
267
|
self.lang=lang
|
|
267
268
|
self.item=WikidataItem(itemQid,sparql=self.sparql,lang=lang)
|
|
@@ -323,13 +324,20 @@ WHERE
|
|
|
323
324
|
return qm
|
|
324
325
|
return None
|
|
325
326
|
|
|
326
|
-
def mostFrequentPropertiesQuery(self):
|
|
327
|
+
def mostFrequentPropertiesQuery(self,whereClause:str=None):
|
|
327
328
|
'''
|
|
328
329
|
get the most frequently used properties
|
|
330
|
+
|
|
331
|
+
Args:
|
|
332
|
+
whereClause(str): an extra WhereClause to use
|
|
329
333
|
'''
|
|
330
334
|
query=self.queryManager.queriesByName["mostFrequentProperties"]
|
|
335
|
+
if whereClause is None:
|
|
336
|
+
whereClause=f"?item wdt:P31 wd:{self.itemQid};";
|
|
337
|
+
else:
|
|
338
|
+
whereClause+=";"
|
|
331
339
|
query.title=f"most frequently used properties for {self.asText(long=True)}"
|
|
332
|
-
query.query=query.query % (self.item.asText(long=True),
|
|
340
|
+
query.query=query.query % (self.item.asText(long=True),whereClause,self.lang)
|
|
333
341
|
return query
|
|
334
342
|
|
|
335
343
|
def noneTabularQuery(self,wdProperty:WikidataProperty,asFrequency:bool=True):
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
'''
|
|
2
|
+
Created on 2022-06-20
|
|
3
|
+
|
|
4
|
+
see
|
|
5
|
+
https://github.com/tyleradams/json-toolkit
|
|
6
|
+
https://stackoverflow.com/questions/36021526/converting-an-array-dict-to-xml-in-python
|
|
7
|
+
|
|
8
|
+
@author: tyleradams
|
|
9
|
+
@author: wf
|
|
10
|
+
'''
|
|
11
|
+
from dicttoxml import dicttoxml
|
|
12
|
+
from xml.dom.minidom import parseString
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
class Lod2Xml():
|
|
16
|
+
'''
|
|
17
|
+
convert a list of dicts to XML
|
|
18
|
+
'''
|
|
19
|
+
|
|
20
|
+
def __init__(self,lod,root:str="root",node_name:callable=(lambda x:'node')):
|
|
21
|
+
'''
|
|
22
|
+
construct me with the given list of dicts
|
|
23
|
+
|
|
24
|
+
Args:
|
|
25
|
+
lod(list): the list of dicts to convert to XML
|
|
26
|
+
root(str): the name of the root nod
|
|
27
|
+
item_name(func): the function to use to calculate node names
|
|
28
|
+
'''
|
|
29
|
+
self.lod=lod
|
|
30
|
+
self.root=root
|
|
31
|
+
self.item_name=node_name
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
def asXml(self,pretty:bool=True):
|
|
35
|
+
'''
|
|
36
|
+
convert result to XML
|
|
37
|
+
|
|
38
|
+
Args:
|
|
39
|
+
pretty(bool): if True pretty print the result
|
|
40
|
+
|
|
41
|
+
'''
|
|
42
|
+
xml=dicttoxml(self.lod, custom_root=self.root,item_func=self.item_name, attr_type=False)
|
|
43
|
+
if pretty:
|
|
44
|
+
dom=parseString(xml)
|
|
45
|
+
prettyXml=dom.toprettyxml()
|
|
46
|
+
else:
|
|
47
|
+
prettyXml=xml
|
|
48
|
+
return prettyXml
|
|
49
|
+
|
|
@@ -79,3 +79,47 @@
|
|
|
79
79
|
}
|
|
80
80
|
}
|
|
81
81
|
ORDER BY(?playerLabel)
|
|
82
|
+
'Top200HumanSettlementClasses':
|
|
83
|
+
title: top 200 human settlement classes https://www.wikidata.org/wiki/Q486972
|
|
84
|
+
description: based on wdtaxonomy Q486972 -c -d -m = using https://www.npmjs.com/package/wikidata-taxonomy
|
|
85
|
+
formats:
|
|
86
|
+
- item:wikidata
|
|
87
|
+
sparql: |
|
|
88
|
+
# relevant human settlement classes in wikidata
|
|
89
|
+
# based on wdtaxonomy Q486972 -c -d -m = -s
|
|
90
|
+
# WF 2021-08-25
|
|
91
|
+
SELECT ?item ?itemLabel ?itemDescription ?instances ?sites WITH {
|
|
92
|
+
SELECT DISTINCT ?item { ?item wdt:P279* wd:Q486972 }
|
|
93
|
+
} AS %items WHERE {
|
|
94
|
+
INCLUDE %items .
|
|
95
|
+
{
|
|
96
|
+
SELECT ?item (count(distinct ?element) as ?instances) {
|
|
97
|
+
INCLUDE %items.
|
|
98
|
+
OPTIONAL { ?element wdt:P31 ?item }
|
|
99
|
+
} GROUP BY ?item
|
|
100
|
+
}
|
|
101
|
+
{
|
|
102
|
+
SELECT ?item (count(distinct ?site) as ?sites) {
|
|
103
|
+
INCLUDE %items.
|
|
104
|
+
OPTIONAL { ?site schema:about ?item }
|
|
105
|
+
} GROUP BY ?item
|
|
106
|
+
}
|
|
107
|
+
SERVICE wikibase:label {
|
|
108
|
+
bd:serviceParam wikibase:language "en"
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
FILTER(?instances>700)
|
|
112
|
+
} ORDER BY DESC (?instances)
|
|
113
|
+
LIMIT 200
|
|
114
|
+
'AcademicConferenceItemLabel':
|
|
115
|
+
sparql: |
|
|
116
|
+
# get the label for the given item
|
|
117
|
+
SELECT ?itemLabel
|
|
118
|
+
WHERE
|
|
119
|
+
{
|
|
120
|
+
VALUES (?item) {
|
|
121
|
+
(wd:Q2020153)
|
|
122
|
+
}
|
|
123
|
+
?item rdfs:label ?itemLabel.
|
|
124
|
+
filter (lang(?itemLabel) = "en").
|
|
125
|
+
}
|
|
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
|