pyLodStorage 0.2.2__tar.gz → 0.2.4__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.2 → pylodstorage-0.2.4}/PKG-INFO +1 -1
- {pylodstorage-0.2.2 → pylodstorage-0.2.4}/lodstorage/querymain.py +14 -2
- {pylodstorage-0.2.2 → pylodstorage-0.2.4}/lodstorage/trulytabular.py +1 -0
- {pylodstorage-0.2.2 → pylodstorage-0.2.4}/lodstorage/version.py +2 -2
- pylodstorage-0.2.4/lodstorage/xml.py +49 -0
- {pylodstorage-0.2.2 → pylodstorage-0.2.4}/pylodstorage.egg-info/PKG-INFO +1 -1
- {pylodstorage-0.2.2 → pylodstorage-0.2.4}/pylodstorage.egg-info/SOURCES.txt +1 -0
- {pylodstorage-0.2.2 → pylodstorage-0.2.4}/sampledata/wikidata.yaml +44 -0
- {pylodstorage-0.2.2 → pylodstorage-0.2.4}/LICENSE +0 -0
- {pylodstorage-0.2.2 → pylodstorage-0.2.4}/README.md +0 -0
- {pylodstorage-0.2.2 → pylodstorage-0.2.4}/lodstorage/csv.py +0 -0
- {pylodstorage-0.2.2 → pylodstorage-0.2.4}/lodstorage/entity.py +0 -0
- {pylodstorage-0.2.2 → pylodstorage-0.2.4}/lodstorage/jsonable.py +0 -0
- {pylodstorage-0.2.2 → pylodstorage-0.2.4}/lodstorage/jsonpicklemixin.py +0 -0
- {pylodstorage-0.2.2 → pylodstorage-0.2.4}/lodstorage/lod.py +0 -0
- {pylodstorage-0.2.2 → pylodstorage-0.2.4}/lodstorage/mwTable.py +0 -0
- {pylodstorage-0.2.2 → pylodstorage-0.2.4}/lodstorage/plot.py +0 -0
- {pylodstorage-0.2.2 → pylodstorage-0.2.4}/lodstorage/query.py +0 -0
- {pylodstorage-0.2.2 → pylodstorage-0.2.4}/lodstorage/sample.py +0 -0
- {pylodstorage-0.2.2 → pylodstorage-0.2.4}/lodstorage/schema.py +0 -0
- {pylodstorage-0.2.2 → pylodstorage-0.2.4}/lodstorage/sparql.py +0 -0
- {pylodstorage-0.2.2 → pylodstorage-0.2.4}/lodstorage/sql.py +0 -0
- {pylodstorage-0.2.2 → pylodstorage-0.2.4}/lodstorage/storageconfig.py +0 -0
- {pylodstorage-0.2.2 → pylodstorage-0.2.4}/lodstorage/tabulateCounter.py +0 -0
- {pylodstorage-0.2.2 → pylodstorage-0.2.4}/lodstorage/uml.py +0 -0
- {pylodstorage-0.2.2 → pylodstorage-0.2.4}/lodstorage/yamlablemixin.py +0 -0
- {pylodstorage-0.2.2 → pylodstorage-0.2.4}/pylodstorage.egg-info/dependency_links.txt +0 -0
- {pylodstorage-0.2.2 → pylodstorage-0.2.4}/pylodstorage.egg-info/entry_points.txt +0 -0
- {pylodstorage-0.2.2 → pylodstorage-0.2.4}/pylodstorage.egg-info/requires.txt +0 -0
- {pylodstorage-0.2.2 → pylodstorage-0.2.4}/pylodstorage.egg-info/top_level.txt +0 -0
- {pylodstorage-0.2.2 → pylodstorage-0.2.4}/sampledata/__init__.py +0 -0
- {pylodstorage-0.2.2 → pylodstorage-0.2.4}/sampledata/endpoints.yaml +0 -0
- {pylodstorage-0.2.2 → pylodstorage-0.2.4}/sampledata/formats.yaml +0 -0
- {pylodstorage-0.2.2 → pylodstorage-0.2.4}/sampledata/queries.yaml +0 -0
- {pylodstorage-0.2.2 → pylodstorage-0.2.4}/sampledata/scholia.yaml +0 -0
- {pylodstorage-0.2.2 → pylodstorage-0.2.4}/sampledata/trulytabular.yaml +0 -0
- {pylodstorage-0.2.2 → pylodstorage-0.2.4}/sampledata/wf.yaml +0 -0
- {pylodstorage-0.2.2 → pylodstorage-0.2.4}/setup.cfg +0 -0
- {pylodstorage-0.2.2 → pylodstorage-0.2.4}/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):
|
|
@@ -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)
|
|
@@ -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
|
|
File without changes
|
|
File without changes
|