commit | 44108cfe66fd52b75bc0e31983600f576cd3b2e9 | [log] [tgz] |
---|---|---|
author | Akron <nils@diewald-online.de> | Fri May 30 15:11:49 2025 +0200 |
committer | Akron <nils@diewald-online.de> | Fri May 30 15:11:49 2025 +0200 |
tree | 0a2e2ec71475f636fa5821db8bc7611844fde8ae | |
parent | 9bff63a2387d5cc552ed47d39825f48d69fd82a4 [diff] |
Add readme Change-Id: Ib4e0d09d8af301a66f5884f7e60e71ea2a219e97
A web service for transforming JSON objects using term mapping rules.
This service provides a REST API for transforming JSON objects according to mapping rules defined in a YAML configuration file. The mappings can be applied in both directions (A to B or B to A) and support foundry and layer overrides.
go get github.com/KorAP/KoralPipe-TermMapper2
termmapper -c config.yaml -p 8080 -l info
Command line options:
--config
or -c
: YAML configuration file containing mapping directives (required)--port
or -p
: Port to listen on (default: 8080)--log-level
or -l
: Log level (debug, info, warn, error) (default: info)--help
or -h
: Show help messageThe configuration file should be in YAML format and contain a list of mapping definitions:
- id: opennlp-mapper foundryA: opennlp layerA: p foundryB: upos layerB: p mappings: - "[PIDAT] <> [opennlp/p=PIDAT & opennlp/p=AdjType:Pdt]" - "[DET] <> [opennlp/p=DET]" - id: simple-mapper mappings: - "[A] <> [B]"
Each mapping list has:
id
: Unique identifier for the mapping listfoundryA
, layerA
: Default foundry and layer for the left side of mappingsfoundryB
, layerB
: Default foundry and layer for the right side of mappingsmappings
: List of mapping rules in the format [pattern] <> [replacement]
POST /:map/query
Transform a JSON object using the specified mapping list.
Parameters:
:map
: ID of the mapping list to usedir
(query): Direction of transformation (atob
or btoa
, default: atob
)foundryA
(query): Override default foundryA from mapping listfoundryB
(query): Override default foundryB from mapping listlayerA
(query): Override default layerA from mapping listlayerB
(query): Override default layerB from mapping listRequest body: JSON object to transform
Example request:
POST /opennlp-mapper/query?dir=atob&foundryB=custom HTTP/1.1 Content-Type: application/json { "@type": "koral:token", "wrap": { "@type": "koral:term", "foundry": "opennlp", "key": "PIDAT", "layer": "p", "match": "match:eq" } }
Example response:
{ "@type": "koral:token", "wrap": { "@type": "koral:termGroup", "operands": [ { "@type": "koral:term", "foundry": "custom", "key": "PIDAT", "layer": "p", "match": "match:eq" }, { "@type": "koral:term", "foundry": "custom", "key": "AdjType", "layer": "p", "match": "match:eq", "value": "Pdt" } ], "relation": "relation:and" } }
GET /health
Returns "OK" if the service is running.
go test ./...
go build -o termmapper ./cmd/termmapper