Skip to content

Commit 2ab16d8

Browse files
committed
hxlquickmeta (#9): MVP of hxlquickmeta (not at least do something); works both for inline debug and inspection of local or remote file
1 parent fea25b0 commit 2ab16d8

File tree

3 files changed

+91
-29
lines changed

3 files changed

+91
-29
lines changed

README.md

Lines changed: 40 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@ exported from HXL (The Humanitarian Exchange Language)**
1616
- [1.2 `HXL2` Command line tools](#12-hxl2-command-line-tools)
1717
- [1.2.1 `hxl2example`: create your own exporter/importer](#121-hxl2example-create-your-own-exporterimporter)
1818
- [1.2.2 `hxl2tab`: tab format, focused for compatibility with Orange Data Mining](#122-hxl2tab-tab-format-focused-for-compatibility-with-orange-data-mining)
19-
- [1.2.3 `hxlquickimport`: (like the `hxltag`)](#123-hxlquickimport-like-the-hxltag)
19+
- [1.2.3 `hxlquickmeta`:](#123-hxlquickmeta)
20+
- [1.2.4 `hxlquickimport`: (like the `hxltag`)](#124-hxlquickimport-like-the-hxltag)
2021
- [2. Reasons behind](#2-reasons-behind)
2122
- [2.1 Why?](#21-why)
2223
- [2.2 How?](#22-how)
@@ -105,7 +106,44 @@ instead of cli to generate the file. Uses [hug 🐨 🤗](https://github.com/hug
105106

106107
> If you want quick expose outside localhost, try [ngrok](https://ngrok.com/).
107108
108-
##### 1.2.3 `hxlquickimport`: (like the `hxltag`)
109+
##### 1.2.3 `hxlquickmeta`:
110+
- Main issue: <https://github.com/EticaAI/HXL-Data-Science-file-formats/issues/6>
111+
- Source code: [bin/hxlquickmeta](bin/hxlquickmeta)
112+
113+
What it does: `hxlquickmeta` output information about a local or remote
114+
dataset. If the file already is HXLated, it will print even more information.
115+
116+
**Quick examples**
117+
118+
```bash
119+
#### inline result for and hashtag and (optional) value ________________________
120+
121+
hxlquickmeta --hxlquickmeta-hashtag="#adm2+code" --hxlquickmeta-value="BR3106200"
122+
# > get_hashtag_info
123+
# >> hashtag: #adm2+code
124+
# >>> HXLMeta._parse_heading: #adm2+code
125+
# >>> HXLMeta.is_hashtag_base_valid: None
126+
# >>> libhxl_is_token None
127+
# >> value: BR3106200
128+
# >>> libhxl_is_empty False
129+
# >>> libhxl_is_date False
130+
# >>> libhxl_is_number False
131+
# >>> libhxl_is_string True
132+
# >>> libhxl_is_token None
133+
# >>> libhxl_is_truthy False
134+
# >>> libhxl_typeof string
135+
136+
#### Output information for an file, and (if any) HXLated information __________
137+
# Local file
138+
hxlquickmeta tests/files/iris_hxlated-csv.csv
139+
140+
# Remove file
141+
hxlquickmeta https://docs.google.com/spreadsheets/u/1/d/1l7POf1WPfzgJb-ks4JM86akFSvaZOhAUWqafSJsm3Y4/edit#gid=634938833
142+
143+
144+
```
145+
146+
##### 1.2.4 `hxlquickimport`: (like the `hxltag`)
109147
- Main issue: <https://github.com/EticaAI/HXL-Data-Science-file-formats/issues/6>
110148
- Source code: [bin/hxlquickimport](bin/hxlquickimport)
111149

bin/hxlquickmeta

Lines changed: 46 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,9 @@
99
# hug -f bin/hxlquickmeta
1010
# ngrok http 8000
1111
#
12-
# DESCRIPTION: hxlquickmeta is ...
12+
# DESCRIPTION: hxlquickmeta output information about a local or remote
13+
# dataset. If the file already is HXLated, it will print
14+
# even more information.
1315
#
1416
# Hug API can be used to create an ad-hoc web interface to your
1517
# script. This can be both useful if you are using an software
@@ -58,8 +60,7 @@ STDIN = sys.stdin.buffer
5860

5961
class HXLQuickMeta:
6062
"""
61-
HXLQuickMeta is a classe to export already HXLated data in the format
62-
example.
63+
HXLQuickMeta is the main class used on hxlquickmeta. (...)
6364
"""
6465

6566
def __init__(self):
@@ -79,10 +80,9 @@ class HXLQuickMeta:
7980

8081
self.hxlhelper = HXLUtils()
8182
parser = self.hxlhelper.make_args(
82-
description=("hxlquickmeta is an example script to create other "
83-
"scripts with some bare minimum command line "
84-
"interfaces that could work to export HXL files to "
85-
"other formats."))
83+
description=("hxlquickmeta output information about a local or "
84+
+ "remote dataset. If the file already is HXLated, "
85+
+ "it will print even more information."))
8686

8787
# TODO: implement draft of --hxlmeta-rebuild/--hxlmeta-path
8888
# parser.add_argument(
@@ -161,15 +161,20 @@ class HXLQuickMeta:
161161
temp = tempfile.NamedTemporaryFile()
162162
args.outfile = temp.name
163163

164+
print('> Connection overview')
165+
print(' >> TODO: implement raw connection, HTTP headers, etc')
166+
print(' >> (this should output debug information even')
167+
print(' >> for inputs that would break libhxl)')
168+
164169
with self.hxlhelper.make_source(args, stdin) as source, \
165170
self.hxlhelper.make_output(args, stdout) as output:
166171
hxl.io.write_hxl(output.output, source,
167172
show_tags=not args.strip_tags)
168173

169174
if True: # if args.hxlmeta:
170-
print('TODO: hxlmeta')
171-
print('output.output', output.output)
172-
print('source', source)
175+
print('> lihxl-python overview')
176+
print(' >> output.output', output.output)
177+
print(' >> source', source)
173178
# print('source.columns', source.headers())
174179
hxlmeta = HXLMeta(local_hxl_file=output.output.name)
175180
hxlmeta.debuginfo()
@@ -816,7 +821,7 @@ class HXLMeta:
816821
return heading1
817822

818823
def debuginfo(self):
819-
print('debuginfo')
824+
print('> HXLMeta debuginfo')
820825
with open(self.local_hxl_file, 'r') as csv_file:
821826
csv_reader = csv.reader(csv_file)
822827
line_1st = next(csv_reader)
@@ -839,27 +844,45 @@ class HXLMeta:
839844

840845
# Hotfix: skip first non-HXL header. Ideally I think the already
841846
# exported HXlated file should already save without headers.
842-
print('self.text_headers', self.text_headers)
843-
print('self.hxl_headers', self.hxl_headers)
847+
print(' >> HXLMeta.text_headers', self.text_headers)
848+
print(' >> HXLMeta.hxl_headers', self.hxl_headers)
849+
850+
for header in self.hxl_headers:
851+
self.get_hashtag_info(header)
852+
844853
# header_original = next(csv_reader)
845854
# print('header_original', header_original)
846855

847856
# hxlquickmeta --hxlquickmeta-hashtag="#adm2+code"
848857
# --hxlquickmeta-value="BR3106200"
849-
def get_hashtag_info(self, hashtag, value = None):
850-
print('> get_hashtag_info')
858+
859+
# TODO: implement some type of external webservice checking to print
860+
# more information when an value is an PCode. Maybe
861+
# https://gistmaps.itos.uga.edu/arcgis/rest/services/COD_External
862+
# have this?
863+
def get_hashtag_info(self, hashtag, value=None):
864+
print('> get_hashtag_info [', hashtag, ']', '[', value, ']')
851865
print('>> hashtag:', hashtag)
852866
print('>>> HXLMeta._parse_heading:', self._parse_heading(hashtag))
853867
print('>>> HXLMeta.is_hashtag_base_valid:',
854868
self.is_hashtag_base_valid(hashtag))
855-
856-
print('>> value:', value)
857-
print('>>> libhxl_is_empty', self.HXLMetaType.libhxl_is_empty(value))
858-
print('>>> libhxl_is_date', self.HXLMetaType.libhxl_is_date(value))
859-
print('>>> libhxl_is_number', self.HXLMetaType.libhxl_is_number(value))
860-
print('>>> libhxl_is_string', self.HXLMetaType.libhxl_is_string(value))
861-
print('>>> libhxl_is_truthy', self.HXLMetaType.libhxl_is_truthy(value))
862-
print('>>> libhxl_typeof', self.HXLMetaType.libhxl_typeof(value))
869+
print('>>> libhxl_is_token', self.HXLMetaType.libhxl_is_token(hashtag))
870+
871+
if value is not None:
872+
print('>> value:', value)
873+
print('>>> libhxl_is_empty',
874+
self.HXLMetaType.libhxl_is_empty(value))
875+
print('>>> libhxl_is_date', self.HXLMetaType.libhxl_is_date(value))
876+
print('>>> libhxl_is_number',
877+
self.HXLMetaType.libhxl_is_number(value))
878+
print('>>> libhxl_is_string',
879+
self.HXLMetaType.libhxl_is_string(value))
880+
print('>>> libhxl_is_token',
881+
self.HXLMetaType.libhxl_is_token(hashtag))
882+
print('>>> libhxl_is_truthy',
883+
self.HXLMetaType.libhxl_is_truthy(value))
884+
print('>>> libhxl_typeof',
885+
self.HXLMetaType.libhxl_typeof(value))
863886

864887
def is_hashtag_base_valid(self, term, strict=True):
865888
if strict:

tests/manual-tests.sh

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,11 +50,12 @@ hug -f bin/hxl2tab
5050
# others to use your computer as quick interface
5151

5252
### hxlquickmeta ---------------------------------------------------------------
53+
hxlquickmeta --hxlquickmeta-hashtag="#adm2+code" --hxlquickmeta-value="BR3106200"
5354

54-
hxlquickmeta tests/files/iris_hxlated-csv.csv | head
55-
hxlquickmeta tests/files/iris_hxlated-csv.csv temp/iris.tab
56-
hxlquickmeta https://docs.google.com/spreadsheets/u/1/d/1l7POf1WPfzgJb-ks4JM86akFSvaZOhAUWqafSJsm3Y4/edit#gid=634938833 | head
57-
hxlquickmeta https://docs.google.com/spreadsheets/u/1/d/1l7POf1WPfzgJb-ks4JM86akFSvaZOhAUWqafSJsm3Y4/edit#gid=634938833 data-mining-projects/output/HXL-CPLP-Exemplar_iris.tab
55+
hxlquickmeta tests/files/iris_hxlated-csv.csv
56+
hxlquickmeta tests/files/iris_hxlated-csv.csv
57+
hxlquickmeta https://docs.google.com/spreadsheets/u/1/d/1l7POf1WPfzgJb-ks4JM86akFSvaZOhAUWqafSJsm3Y4/edit#gid=634938833
58+
hxlquickmeta https://docs.google.com/spreadsheets/u/1/d/1l7POf1WPfzgJb-ks4JM86akFSvaZOhAUWqafSJsm3Y4/edit#gid=634938833
5859

5960
## hug -f bin/hxlquickmeta ......................................................
6061
#@see https://hugapi.github.io/hug/

0 commit comments

Comments
 (0)