Skip to content

Commit

Permalink
i18n+l10n (#15), hxl-processing-specs (#14): now is possible to speci…
Browse files Browse the repository at this point in the history
…fy more than one source; also content without translation will be prefixed with a single _
  • Loading branch information
fititnt committed Mar 14, 2021
1 parent 4819547 commit 57d2cca
Show file tree
Hide file tree
Showing 5 changed files with 66 additions and 22 deletions.
29 changes: 23 additions & 6 deletions hxlm/core/model/hdp.py
Original file line number Diff line number Diff line change
Expand Up @@ -231,14 +231,31 @@ def export_json_processing_specs(self, options=None) -> str:
if 'hrecipe' in hsilo:
for hrecipeitem in hsilo['hrecipe']:
recipeitem = {}
if 'iri_example' in hrecipeitem:
# Note: here is an list, but we're taking the first now
recipeitem['input'] = \
hrecipeitem['iri_example'][0]['iri']
if 'sheet_index' in hrecipeitem['iri_example'][0]:
# Code pré v0.7.4
# if 'iri_example' in hrecipeitem:
# # Note: here is an list, but we're taking the first
# recipeitem['input'] = \
# hrecipeitem['iri_example'][0]['iri']
# if 'sheet_index' in hrecipeitem['iri_example'][0]:
# recipeitem['sheet_index'] = \
# hrecipeitem['iri_example'][0]['sheet_index']
# recipeitem['recipe'] = hrecipeitem['recipe']

recipeitem['recipe'] = hrecipeitem['_recipe']

# print('eita123', hrecipeitem['exemplum'])
# print('eita123', hrecipeitem['exemplum'][0])

# TODO: this have the [0] hardoded. Should be generalized
if 'exemplum' in hrecipeitem and 'fontem' in hrecipeitem['exemplum'][0]: # noqa
# print('oioioi', hrecipeitem['exemplum'])
if 'iri' in hrecipeitem['exemplum'][0]['fontem']:
recipeitem['input'] = hrecipeitem['exemplum'][0]['fontem']['iri'] # noqa
if 'sheet_index' in hrecipeitem['exemplum'][0]:
recipeitem['sheet_index'] = \
hrecipeitem['iri_example'][0]['sheet_index']
recipeitem['recipe'] = hrecipeitem['recipe']
# recipeitem['recipe'] = hrecipeitem['recipe']

result.append(recipeitem)

# If the result already is exact one item, return just one
Expand Down
2 changes: 1 addition & 1 deletion hxlm/core/schema/hdp.json-schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@
"type": "object",
"required": [
"id",
"recipe"
"_recipe"
]
},
"minItems": 1
Expand Down
31 changes: 27 additions & 4 deletions tests/hrecipe/hello-world.hrecipe.hdp.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,39 @@
---
- hsilo:
nomen: hello-world.hrecipe.hdp.yml
linguam: mul # https://iso639-3.sil.org/code/mul
hrecipe:
- id: example-processing-with-a-JSON-spec
recipe:
_recipe:
- filter: count
patterns: "adm1+name,adm1+code"
aggregators:
- "sum(population) as Population#population"
- filter: clean_data
number: "population"
number_format: .0f
iri_example:
- iri: https://data.humdata.org/dataset/yemen-humanitarian-needs-overview
sheet_index: 1
# iri_example:
# - iri: https://data.humdata.org/dataset/yemen-humanitarian-needs-overview
# sheet_index: 1
exemplum:

# Example one
- fontem:
iri: https://data.humdata.org/dataset/yemen-humanitarian-needs-overview
_sheet_index: 1

# Example two includes both an inline data
- fontem:
# Note: fontem.datum not implemented
datum:
- ['header 1', 'header 2', 'header 3']
- ['#item +id', '#item +name', '#item +value']
- ['ACME1', 'ACME Inc.', '123']
- ['XPTO1', 'XPTO org', '456']
objectivum:
# Note: fontem.objectivum not implemented
datum:
- ['header 1', 'header 2', 'header 3']
- ['#item +id', '#item +name', '#item +value']
- ['ACME1', 'ACME Inc.', '123']
- ['XPTO1', 'XPTO org', '456']
9 changes: 5 additions & 4 deletions tests/hrecipe/yemen-01.hrecipe.hdp.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,15 @@
nomen: yemen-01.hrecipe.hdp.yml
hrecipe:
- id: example-processing-with-a-JSON-spec
recipe:
_recipe:
- filter: count
patterns: "adm1+name,adm1+code"
aggregators:
- "sum(population) as Population#population"
- filter: clean_data
number: "population"
number_format: .0f
iri_example:
- iri: https://data.humdata.org/dataset/yemen-humanitarian-needs-overview
sheet_index: 1
exemplum:
- fontem:
iri: https://data.humdata.org/dataset/yemen-humanitarian-needs-overview
_sheet_index: 1
17 changes: 10 additions & 7 deletions tests/hxl-processing-specs/hxl-processing-specs-test-01.hdp.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,27 +21,30 @@
- hsilo: "test1"
hrecipe:
- id: recipe1
iri_example:
- iri: https://docs.google.com/spreadsheets/d/12k4BWqq5c3mV9ihQscPIwtuDa_QRB-iFohO7dXSSptI/edit#gid=0
recipe:
_recipe:
- filter: with_columns
includes: "#vocab+id+v_iso6393_3letter,#vocab+code+v_6391,#vocab+name"
- filter: without_rows
queries: "#vocab+code+v_6391="
exemplum:
- fontem:
iri: https://docs.google.com/spreadsheets/d/12k4BWqq5c3mV9ihQscPIwtuDa_QRB-iFohO7dXSSptI/edit#gid=0

- hsilo:
nomen: "test1"
descriptionem: from https://docs.google.com/presentation/d/17vXOnq2atIDnrODGLs36P1EaUvT-vXPjsc2I1q1Qc50/
hrecipe:
- id: example-processing-with-a-JSON-spec
iri_example:
- iri: https://data.humdata.org/dataset/yemen-humanitarian-needs-overview
sheet_index: 1
recipe:
_recipe:
- filter: count
patterns: "adm1+name,adm1+code"
aggregators:
- "sum(population) as Population#population"
- filter: clean_data
number: "population"
number_format: .0f
exemplum:
- fontem:
iri: https://data.humdata.org/dataset/yemen-humanitarian-needs-overview
_sheet_index: 1

0 comments on commit 57d2cca

Please sign in to comment.