-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
128 additions
and
30 deletions.
There are no files selected for viewing
38 changes: 38 additions & 0 deletions
38
packages/transformers/examples/convert-LODEX-model-to-ezs.ini
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
# | ||
# Tranforme un model lodex en script ezs | ||
# permet de récupérer les transformations | ||
# pour les rejouer à sans lodex | ||
# | ||
# La transformatino est brute, cad | ||
# qu'une foi le fichier généré il est necessaire | ||
# - de supprimer la ligne contenant AUTGENERATE_URI (qui n'a de sens que dans lodex) | ||
# - d'ajouter l'instruction : | ||
# [exchange] | ||
# value = omit('$origin') | ||
# en fin de script poiur éviter d'avoir le champ technique $origin dans son fichier résulat | ||
# | ||
# Exemple d'usage complet | ||
# Etape 1: on convertit le model en fichier ezs | ||
# ezs ./convert-LODEX-model-to-ezs.ini < ./modele-lodex.json > ./transformers.ini | ||
# | ||
# Etape 2 : on converit un fichier zip (dl.istex.fr) en json (lodex) | ||
# ezs ./zip.ini ./transformers.ini ./finalize.ini < istex-subset-2020-01-09.zip > output.json | ||
|
||
[use] | ||
plugin = basics | ||
plugin = analytics | ||
|
||
[JSONParse] | ||
|
||
[exploding] | ||
id = name | ||
value = transformers | ||
|
||
[replace] | ||
path = get('value.operation').split('').unshift('[transformers:$').push(']').join('') | ||
value = get('value.args').reduce((o, v) => (o[v.name] = String('fix(').concat(JSON.stringify(v.value)).concat(')') , o), {}) | ||
|
||
path = get('value.operation').split('').unshift('[transformers:$').push('].field').join('') | ||
value = get('id') | ||
|
||
[INIString] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
# | ||
# Script pratique à utiliser apres un fichier généré par ./convert-LODEX-model-to-ezs.ini | ||
# | ||
[exchange] | ||
value = omit('$origin') | ||
|
||
[dump] | ||
indent = true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,40 +1,42 @@ | ||
import _ from 'lodash'; | ||
|
||
export default async function dollar(statement, data, feed, transformer, doc) { | ||
export default async function dollar(statement, data, feed, transformer, useAllfields) { | ||
if (statement.isLast()) { | ||
return feed.close(); | ||
} | ||
const fields = statement.getParam('field'); | ||
const field = Array.isArray(fields) ? fields.shift() : fields; | ||
const { args } = transformer.getMetas(); | ||
let index = -1; | ||
const values = args.map((arg) => { | ||
const vals = statement.getParam(arg.name); | ||
if (Array.isArray(vals)) { | ||
index += 1; | ||
if (!statement.values) { | ||
const { args } = transformer.getMetas(); | ||
let index = -1; | ||
statement.values = args.map((arg) => { | ||
const vals = statement.getParam(arg.name); | ||
if (Array.isArray(vals)) { | ||
index += 1; | ||
return { | ||
...arg, | ||
value: vals[index], | ||
}; | ||
} | ||
return { | ||
...arg, | ||
value: vals[index], | ||
value: vals, | ||
}; | ||
} | ||
return { | ||
...arg, | ||
value: vals, | ||
}; | ||
}); | ||
let newData; | ||
if (data.$origin) { | ||
newData = { ...data }; | ||
} else { | ||
newData = { | ||
$origin: { ...data }, | ||
}; | ||
}); | ||
} | ||
const input = doc || _.get(data, field, null); | ||
|
||
const output = await transformer(input, values)(input); | ||
const source = data.$origin || data; | ||
const input = (useAllfields && source) || _.get(source, field) || _.get(data, field, null); | ||
const output = await transformer(input, statement.values)(input); | ||
|
||
_.set(newData, field, output); | ||
|
||
return feed.send(newData); | ||
if (!data.$origin) { | ||
const target = {}; | ||
_.set(target, '$origin', source); | ||
_.unset(target.$origin, field); | ||
_.set(target, field, output); | ||
return feed.send(target); | ||
} | ||
_.unset(data.$origin, field); | ||
_.set(data, field, output); | ||
return feed.send(data); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters