commit | e1cff7c75092f3305e1886341597d341cb44b6b2 | [log] [tgz] |
---|---|---|
author | Akron <nils@diewald-online.de> | Wed Jun 04 18:43:32 2025 +0200 |
committer | Akron <nils@diewald-online.de> | Wed Jun 04 18:43:32 2025 +0200 |
tree | b292d00e8b2ba1201d6e0c4628f14994288626ac | |
parent | c376dcce14cd0da8abf02f00730ce762b49c9898 [diff] |
Support loading multiple mapping files Change-Id: I3c6caaa3c4c3434dfacfb842f0407250b5e980f0
A KorAP service using the KoralPipe mechanism to rewrite terms in queries and responses between different annotations.
KoralPipe-TermMapper is a tool for transforming linguistic annotations between different annotation schemes. It allows you to define mapping rules in YAML configuration files and apply these mappings to JSON-encoded linguistic annotations.
go get github.com/KorAP/KoralPipe-TermMapper
termmapper -c config.yaml -m extra-mapper1.yaml -m extra-mapper2.yaml
Command Line Options
--config
or -c
: YAML configuration file containing mapping directives and global settings (optional)--mappings
or -m
: Individual YAML mapping files to load (can be used multiple times, optional)--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 messageNote: At least one mapping source must be provided
KoralPipe-TermMapper supports loading configuration from multiple sources:
-c
): Contains global settings (SDK, server endpoints) and optional mapping lists-m
): Contains single mapping lists, can be specified multiple timesThe main configuration provides global settings, and all mapping lists from both sources are combined. Duplicate mapping IDs across all sources will result in an error.
Configurations can contain global settings and mapping lists (used with the -c
flag):
# Optional: Custom SDK endpoint for Kalamar plugin integration sdk: "https://custom.example.com/js/korap-plugin.js" # Optional: Custom server endpoint for Kalamar plugin integration server: "https://custom.example.com/" # Optional: Mapping lists (same format as individual mapping files) lists: - id: mapping-list-id foundryA: source-foundry layerA: source-layer foundryB: target-foundry layerB: target-layer mappings: - "[pattern1] <> [replacement1]" - "[pattern2] <> [replacement2]"
Map files contain a single mapping list (used with the -m
flag):
id: mapping-list-id foundryA: source-foundry layerA: source-layer foundryB: target-foundry layerB: target-layer mappings: - "[pattern1] <> [replacement1]" - "[pattern2] <> [replacement2]"
The sdk
and server
fields in the main configuration file are optional and override the default endpoints used for Kalamar plugin integration:
sdk
: Custom SDK JavaScript file URL (default: https://korap.ids-mannheim.de/js/korap-plugin-latest.js
)server
: Custom server endpoint URL (default: https://korap.ids-mannheim.de/
)These values are applied during configuration parsing and affect the HTML plugin page served at the root endpoint (/
). When using only individual mapping files (-m
flags), default values are used.
Each mapping rule consists of two patterns separated by <>
. The patterns can be:
[key]
or [foundry/layer=key]
or [foundry/layer=key:value]
[term1 & term2]
or [term1 | term2]
or [term1 | (term2 & term3)]
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" } }
Serves the Kalamar plugin integration page. This HTML page includes:
sdk
and server
configuration fieldsThe SDK script and server data-attribute in the HTML are determined by the configuration file's sdk
and server
values, with fallback to default endpoints if not specified.
Health check endpoint that returns "OK" with HTTP 200 status.
Copyright (C) 2025, IDS Mannheim
Author: Nils Diewald
TermMapper is free software published under the BSD-2 License.
Disclaimer: This software was developed (as an experiment) with major assistance by AI (mainly Claude 3.5-sonnet and Claude 4-sonnet).