diff --git a/data-computer/README.md b/data-computer/README.md index 62e1445..0808b52 100644 --- a/data-computer/README.md +++ b/data-computer/README.md @@ -33,11 +33,14 @@ ## Utilisation - [v1/tree-segment](#v1%2ftree-segment) +- [v1/graph](#v1%2fgraph-segment) - [v1/lda](#v1%2flda) ### v1/tree-segment -Créer des segments 2 à 2 de tous les éléments d'un tableau et agrège ces segments pour les compter +Créer des segments glissant 2 à 2 de tous les éléments d'un tableau et agrège ces segments pour les compter. + +Le segment étant glissant, ce traitement sert à créer des segments qui représente un arbre hiérachique. par exemple avec ces données en entrée: @@ -90,6 +93,68 @@ cat output.json |curl --data-binary @- "http://localhost:31976/v1/retrieve" > output.tar.gz ``` + +### v1/graph-segment + +Créer des segments 2 à 2 avex tous les éléments d'un tableau et agrège ces segments pour les compter +Les segments reprsentent toutes la associations possibles, ce traitement sert à créer des segments qui représente un réesau. + +par exemple avec ces données en entrée: + +```json +[ + { "value": ["a", "b", "c"] }, + { "value": ["a", "c", "d"] }, + { "value": ["a", "b", "d"] }, + { "value": ["a", "b", "c", "d"] }, + { "value": ["a", "c", "d", "e"] } +] + +``` + +on obtiendra : + +```json +[ + {"source":"a","target":"b","weight":3,"origin":["#1","#3","#4"]}, + {"source":"a","target":"c","weight":4,"origin":["#1","#2","#4","#5"]}, + {"source":"b","target":"c","weight":2,"origin":["#1","#4"]}, + {"source":"a","target":"d","weight":4,"origin":["#2","#3","#4","#5"]}, + {"source":"c","target":"d","weight":3,"origin":["#2","#4","#5"]}, + {"source":"b","target":"d","weight":2,"origin":["#3","#4"]}, + {"source":"a","target":"e","weight":1,"origin":["#5"]}, + {"source":"c","target":"e","weight":1,"origin":["#5"]}, + {"source":"d","target":"e","weight":1,"origin":["#5"]} +] +``` + +> NOTE: Le service accepte des tableaux ou des tableaux de tableaux + +#### Paramètre(s) URL + +| nom | description | +| ------------------- | ------------------------------------------- | +| indent (true/false) | Indenter le résultat renvoyer immédiatement | + +#### Entête(s) HTTP + +| nom | description | +| ------ | ------------------------------------------------------------ | +| X-Hook | URL à appeler quand le résultat sera disponible (facultatif) | + +#### Exemple en ligne de commande + + +```bash +# Send data for batch processing +cat input.tar.gz |curl --data-binary @- -H "X-Hook: https://webhook.site/dce2fefa-9a72-4f76-96e5-059405a04f6c" "http://localhost:31976/v1/graph-segment" > output.json + +# When the corpus is processed, get the result +cat output.json |curl --data-binary @- "http://localhost:31976/v1/retrieve" > output.tar.gz + +``` + + ### v1/lda ... diff --git a/data-computer/examples.http b/data-computer/examples.http index 5da6633..87215eb 100644 --- a/data-computer/examples.http +++ b/data-computer/examples.http @@ -11,7 +11,7 @@ [ { - "value":"acUHX88Gb" + "value":"YAynRhVBJ" } ] ### @@ -25,6 +25,15 @@ ### +# @name graph-segment +POST {{baseUrl}}/v1/graph-segment HTTP/1.1 +Content-Type: application/x-tar +X-Hook: https://webhook.site/69300b22-a251-4c16-9905-f7ba218ae7e9 + +< ./example-json.tar.gz + +### + # @name lda POST {{baseUrl}}/v1/lda HTTP/1.1 Content-Type: application/x-tar diff --git a/data-computer/v1/graph-segment.ini b/data-computer/v1/graph-segment.ini new file mode 100644 index 0000000..4b81e0d --- /dev/null +++ b/data-computer/v1/graph-segment.ini @@ -0,0 +1,118 @@ +# Entrypoint output format +mimeType = application/json + +# OpenAPI Documentation - JSON format (dot notation) +post.operationId = post-v1-lda +post.description = Création de segments à partir de tableaux +post.summary = Le corpus est transformé en liste de segment (source, target, weight) à partir d'un tableau simple ou d'un tableau imbriqué +post.tags.0 = data-computer +post.requestBody.content.application/x-tar.schema.type = string +post.requestBody.content.application/x-tar.schema.format = binary +post.requestBody.required = true +post.responses.default.description = Informations permettant de récupérer les données le moment venu +post.parameters.0.description = Indenter le JSON résultant +post.parameters.0.in = query +post.parameters.0.name = indent +post.parameters.0.schema.type = boolean + +[use] +plugin = basics +plugin = analytics + +# Step 0 (générique) : Lire le fichier standard tar.gz +[TARExtract] +compress = true + +# Step 1 (générique) : Créer un identifiant unique pour le corpus reçu +[singleton] +[singleton/identify] +[singleton/env] +path = generator +value = graph-segment +path = identifier +value = get('uri').replace('uid:/', '') + +# Step 2 (générique): Traiter de manière asynchnore les items reçus +[fork] +standalone = true + +# Step 2.1 (générique): Lancer un calcul sur tous les items reçus +[fork/delegate] + +# Step 2.1.1 (spécifique): S'assurer d'avoir un tableau +[fork/delegate/replace] +path = id +value = get('id') +path = value +value = get('value').thru(x => x && Array.isArray(x[0])?x:[x]).flatten().filter(Boolean) + + +# Step 2.1.2 (spécifique): Créer des tableaux de paires des segments (ou Bigramme) +[fork/delegate/graph] +path = value +identifier = id + +[fork/delegate/debug] +text = apres + +# Step 2.1.3 (spécifique): Regrouper les segments +[fork/delegate/aggregate] + +# Step 2.1.4 (spécifique): Construire un résulat spécifique du calcul +[fork/delegate/replace] +path = source +value = get('id.0') +path = target +value = get('id.1') +path = weight +value = get('value').size() +path = origin +value = get('value').uniq() + +# Step 2.2 (générique): Création d'un fichier résulat standard +[fork/TARDump] +compress = true +manifest = fix({version: '1'}) +manifest = fix({identifier: env('identifier')}) +manifest = fix({generator: env('generator')}) + +# Step 2.3 (générique): Sauvegarder sur disque le résulat +[fork/FILESave] +location = /tmp/retrieve +identifier = env('identifier') +jsonl = false +compress = false + +# Step 2.4 (générique): Signaler le fin du traitement via un appel à un webhook (si il a été précisé) +[fork/swing] +test = env('headers.x-hook').startsWith('http') + +# Step 2.4.1 (générique): Séléctionner les informations à envoyer au webhook +[fork/swing/replace] +path = body +value = self().pick(['size', 'atime', 'mtime', 'ctime']).set('identifier', env('identifier')).set('generator', env('generator')).set('state', 'ready') + +# Step 2.4.2 (générique): Envoyer la requète HTTP +[fork/swing/URLFetch] +url = env('headers.x-hook') +path = body +headers = Content-Type:application/json + +# Step 2.4.3 (faculatif) : Ajouter une trace dans log +[fork/swing/debug] +text = webhook triggered + +# Step 2.5 (faculatif) : Ajouter une trace dans log +[fork/debug] +text = process completed + +# Step 3 : Renvoyer immédiatement seul élément indiquant comment récupérer le résulat quand il sera prêt +[shift] +[replace] +path = id +value = env('generator') +path = value +value = env('identifier') + +[JSONString] +indent = env('indent') diff --git a/data-computer/v1/tree-segment.ini b/data-computer/v1/tree-segment.ini index 930f25e..bbf107b 100644 --- a/data-computer/v1/tree-segment.ini +++ b/data-computer/v1/tree-segment.ini @@ -46,7 +46,7 @@ path = value value = get('value').thru(x => x && Array.isArray(x[0])?x:[x]) -# Step 2.1.2 (spécifique): Créer des tableaux de paires des segements (ou Bigramme) +# Step 2.1.2 (spécifique): Créer des tableaux de paires des segments (ou Bigramme) [fork/delegate/segment] aggregate = false path = value