Skip to content

Commit

Permalink
hxltm-cli-xliff (#19), hxltm-cli-tmx (#20): improved documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
fititnt committed Jul 2, 2021
1 parent 019ddbc commit b70dafc
Show file tree
Hide file tree
Showing 2 changed files with 75 additions and 5 deletions.
35 changes: 35 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -457,6 +457,26 @@ pip install hdp-toolchain

hxltmcli --help

```

**Advanced filter with HXL cli tools**
- See **https://github.com/HXLStandard/libhxl-python/wiki/HXL-cookbook**

```bash
# libhxl already is installed with hdp-toolchain

hxlselect --help
# Filter rows in a HXL dataset. (...)
hxlcut --help
# Cut columns from a HXL dataset.

## Examples with HXL TM (used before pass data to hxltmcli)
hxlcut --exclude item+i_la+i_lat+is_Latn --sheet 6 HXL-CPLP-Vocab_Auxilium-Humanitarium-API.xlsx | hxltmcli
# Excludes Latin before pass to hxltmcli, from Microsoft Excel

hxlcut --exclude item+i_la+i_lat+is_Latn https://docs.google.com/spreadsheets/d/1ih3ouvx_n8W5ntNcYBqoyZ2NRMdaA0LRg5F9mGriZm4/edit#gid=1292720422 | hxltmcli
# Excludes Latin before pass to hxltmcli, from Google Sheets

```
---

Expand Down Expand Up @@ -492,6 +512,14 @@ required).

```bash
hxltmcli https://docs.google.com/spreadsheets/d/1ih3ouvx_n8W5ntNcYBqoyZ2NRMdaA0LRg5F9mGriZm4/edit#gid=1292720422
# (will print out contents of Google Sheets, without exporting to other formats)

hxltmcli https://docs.google.com/spreadsheets/d/1ih3ouvx_n8W5ntNcYBqoyZ2NRMdaA0LRg5F9mGriZm4/edit#gid=1292720422 | grep UN_codicem_anglicum_IOM_HTCDS_nomen
# UN_codicem_anglicum_IOM_HTCDS_nomen,,,,13,1,UN,UN,codicem_anglicum,IOM,HTCDS,,,nomen,,,,,,,,,,,,,,∅,∅,Padrão de Dados de Casos de Tráfico Humano,∅,Revisão de texto requerida,Human Trafficking Case Data Standard,∅,∅,,∅,∅,,∅,∅,,∅,∅,,∅,∅

hxltmcli https://docs.google.com/spreadsheets/d/1ih3ouvx_n8W5ntNcYBqoyZ2NRMdaA0LRg5F9mGriZm4/edit#gid=1292720422 schemam-un-htcds.tm.hxl.csv
# (Instead of print to stdout, save the contents to a single CSV file)

```

**Write HXL TM data on Google Sheets**
Expand All @@ -514,6 +542,13 @@ required).
# the Google Sheets entire groups of HXL TMs on 2021-06-29. New versions are
# likely to be a different number than --sheet 6
hxltmcli --sheet 6 HXL-CPLP-Vocab_Auxilium-Humanitarium-API.xlsx
# (will print out contents of --sheet 6, without exporting to other formats)

hxltmcli --sheet 6 HXL-CPLP-Vocab_Auxilium-Humanitarium-API.xlsx | grep UN_codicem_anglicum_IOM_HTCDS_nomen
# UN_codicem_anglicum_IOM_HTCDS_nomen,,,,13,1,UN,UN,codicem_anglicum,IOM,HTCDS,,,nomen,,,,,,,,,,,,,,∅,∅,Padrão de Dados de Casos de Tráfico Humano,∅,Revisão de texto requerida,Human Trafficking Case Data Standard,∅,∅,,∅,∅,,∅,∅,,∅,∅,,∅,∅

hxltmcli --sheet 6 HXL-CPLP-Vocab_Auxilium-Humanitarium-API.xlsx schemam-un-htcds.tm.hxl.csv
# (Instead of print to stdout, save the contents to a single CSV file)
```

**Write HXL TM data on Microsoft Excel**
Expand Down
45 changes: 40 additions & 5 deletions bin/hxltmcli
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,8 @@ class HXLTMCLI:
'--archivum-extensionem',
help='File extension. .xlf, .csv or .tmx',
action='store',
default='.xlf',
# default='.xlf',
default=None,
nargs='?'
)

Expand Down Expand Up @@ -210,21 +211,55 @@ class HXLTMCLI:
# print('tmx!')
self.hxltm2tmx(args.outfile, self.original_outfile,
self.original_outfile_is_stdout, args)
else:
# self.hxl2tab(args.outfile, self.original_outfile,
# self.original_outfile_is_stdout, args)

elif args.archivum_extensionem == '.xliff' or args.archivum_extensionem == '.xlf':
# print('xliff!')
self.hxltm2csv(args.outfile, temp_csv4xliff.name,
False, args)
self.hxltm2xliff(temp_csv4xliff.name, self.original_outfile,
self.original_outfile_is_stdout, args)
else:
# self.hxl2tab(args.outfile, self.original_outfile,
# self.original_outfile_is_stdout, args)

# self.hxltm2csv(args.outfile, temp_csv4xliff.name,
# False, args)
# print('noop')
self.hxltm2noop(args.outfile, self.original_outfile,
self.original_outfile_is_stdout)

finally:
temp.close()
temp_csv4xliff.close()

return self.EXIT_OK

def hxltm2noop(self, hxlated_input, tab_output, is_stdout):
"""
hxltm2noop only export whatever the initial HXL input was.
Requires that the input must be a valid HXLated file
"""

with open(hxlated_input, 'r') as csv_file:
csv_reader = csv.reader(csv_file)

if is_stdout:
# txt_writer = csv.writer(sys.stdout, delimiter='\t')
txt_writer = csv.writer(sys.stdout)
# txt_writer.writerow(header_new)
for line in csv_reader:
txt_writer.writerow(line)
else:

tab_output_cleanup = open(tab_output, 'w')
tab_output_cleanup.truncate()
tab_output_cleanup.close()

with open(tab_output, 'a') as new_txt:
txt_writer = csv.writer(new_txt)
for line in csv_reader:
txt_writer.writerow(line)

def hxltm2csv(self, hxlated_input, tab_output, is_stdout, args):
"""
hxltm2csv pre-process the initial HXL TM on a intermediate format that
Expand Down

0 comments on commit b70dafc

Please sign in to comment.