Allow for mapping descriptions
Change-Id: I6e0124c36bb89226524c41d19cf69d04d8e19a79
diff --git a/cmd/termmapper/main.go b/cmd/termmapper/main.go
index e945572..fcc3ad7 100644
--- a/cmd/termmapper/main.go
+++ b/cmd/termmapper/main.go
@@ -28,6 +28,11 @@
LogLevel *string `kong:"short='l',help='Log level (debug, info, warn, error)'"`
}
+type TemplateMapping struct {
+ ID string
+ Description string
+}
+
// TemplateData holds data for the Kalamar plugin template
type TemplateData struct {
Title string
@@ -38,7 +43,7 @@
Server string
SDK string
MapID string
- MappingIDs []string
+ Mappings []TemplateMapping
}
func parseConfig() *appConfig {
@@ -256,10 +261,13 @@
return func(c *fiber.Ctx) error {
mapID := c.Params("map")
- // Get list of available mapping IDs
- var mappingIDs []string
+ // Get list of available mappings
+ var mappings []TemplateMapping
for _, list := range yamlConfig.Lists {
- mappingIDs = append(mappingIDs, list.ID)
+ mappings = append(mappings, TemplateMapping{
+ ID: list.ID,
+ Description: list.Description,
+ })
}
// Use values from config (defaults are already applied during parsing)
@@ -276,7 +284,7 @@
Server: server,
SDK: sdk,
MapID: mapID,
- MappingIDs: mappingIDs,
+ Mappings: mappings,
}
// Generate HTML
@@ -324,15 +332,15 @@
</dl>
<h2>Available Term Mappings</h2>
- <ul>`
+ <dl>`
- for _, id := range data.MappingIDs {
- html += `
- <li>` + id + `</li>`
+ for _, m := range data.Mappings {
+ html += `<dt><tt>` + m.ID + `</tt></dt>`
+ html += `<dd>` + m.Description + `</dd>`
}
html += `
- </ul>`
+ </dl>`
if data.MapID != "" {
html += ` <script>
diff --git a/config/config.go b/config/config.go
index ff0db31..dd1e3e9 100644
--- a/config/config.go
+++ b/config/config.go
@@ -21,12 +21,13 @@
// MappingList represents a list of mapping rules with metadata
type MappingList struct {
- ID string `yaml:"id"`
- FoundryA string `yaml:"foundryA,omitempty"`
- LayerA string `yaml:"layerA,omitempty"`
- FoundryB string `yaml:"foundryB,omitempty"`
- LayerB string `yaml:"layerB,omitempty"`
- Mappings []MappingRule `yaml:"mappings"`
+ ID string `yaml:"id"`
+ Description string `yaml:"desc,omitempty"`
+ FoundryA string `yaml:"foundryA,omitempty"`
+ LayerA string `yaml:"layerA,omitempty"`
+ FoundryB string `yaml:"foundryB,omitempty"`
+ LayerB string `yaml:"layerB,omitempty"`
+ Mappings []MappingRule `yaml:"mappings"`
}
// MappingConfig represents the root configuration containing multiple mapping lists
diff --git a/config/config_test.go b/config/config_test.go
index f2678fb..a3f1d0c 100644
--- a/config/config_test.go
+++ b/config/config_test.go
@@ -503,78 +503,6 @@
assert.Equal(t, "ADJ", lowerTerm4.Key)
}
-func TestExistingUposYaml(t *testing.T) {
- // Test that the existing upos.yaml file can be parsed correctly
- config, err := LoadConfig("../upos.yaml")
- require.NoError(t, err)
-
- // Verify the configuration loaded correctly
- require.Len(t, config.Lists, 1)
- list := config.Lists[0]
- assert.Equal(t, "stts-ud", list.ID)
- assert.Equal(t, "opennlp", list.FoundryA)
- assert.Equal(t, "p", list.LayerA)
- assert.Equal(t, "upos", list.FoundryB)
- assert.Equal(t, "p", list.LayerB)
- require.Len(t, list.Mappings, 54) // Should have 54 mapping rules
-
- // Test that all mapping rules can be parsed successfully
- results, err := list.ParseMappings()
- require.NoError(t, err)
- require.Len(t, results, 54)
-
- // Test a few specific mappings to ensure they parse correctly
-
- // Test the special character mappings
- firstMapping := results[0] // "[$\\(] <> [PUNCT & PunctType=Brck]"
- upperTerm := firstMapping.Upper.Wrap.(*ast.Term)
- assert.Equal(t, "$(", upperTerm.Key)
- assert.Equal(t, "opennlp", upperTerm.Foundry)
- assert.Equal(t, "p", upperTerm.Layer)
-
- lowerGroup := firstMapping.Lower.Wrap.(*ast.TermGroup)
- require.Len(t, lowerGroup.Operands, 2)
- assert.Equal(t, ast.AndRelation, lowerGroup.Relation)
-
- punctTerm := lowerGroup.Operands[0].(*ast.Term)
- assert.Equal(t, "PUNCT", punctTerm.Key)
- assert.Equal(t, "upos", punctTerm.Foundry)
- assert.Equal(t, "p", punctTerm.Layer)
-
- punctTypeTerm := lowerGroup.Operands[1].(*ast.Term)
- assert.Equal(t, "PunctType", punctTypeTerm.Layer)
- assert.Equal(t, "Brck", punctTypeTerm.Key)
- assert.Equal(t, "upos", punctTypeTerm.Foundry)
-
- // Test a complex mapping with multiple attributes
- // "[PIDAT] <> [DET & AdjType=Pdt & (PronType=Ind | PronType=Neg | PronType=Tot)]"
- pidatMapping := results[24] // This should be the PIDAT mapping
- pidatUpper := pidatMapping.Upper.Wrap.(*ast.Term)
- assert.Equal(t, "PIDAT", pidatUpper.Key)
-
- pidatLower := pidatMapping.Lower.Wrap.(*ast.TermGroup)
- assert.Equal(t, ast.AndRelation, pidatLower.Relation)
- require.Len(t, pidatLower.Operands, 3) // DET, AdjType=Pdt, and the parenthesized group
-
- detTerm := pidatLower.Operands[0].(*ast.Term)
- assert.Equal(t, "DET", detTerm.Key)
-
- adjTypeTerm := pidatLower.Operands[1].(*ast.Term)
- assert.Equal(t, "AdjType", adjTypeTerm.Layer)
- assert.Equal(t, "Pdt", adjTypeTerm.Key)
-
- // The third operand should be a nested TermGroup with OR relation
- nestedGroup := pidatLower.Operands[2].(*ast.TermGroup)
- assert.Equal(t, ast.OrRelation, nestedGroup.Relation)
- require.Len(t, nestedGroup.Operands, 3) // PronType=Ind, PronType=Neg, PronType=Tot
-
- for i, expectedValue := range []string{"Ind", "Neg", "Tot"} {
- pronTypeTerm := nestedGroup.Operands[i].(*ast.Term)
- assert.Equal(t, "PronType", pronTypeTerm.Layer)
- assert.Equal(t, expectedValue, pronTypeTerm.Key)
- }
-}
-
func TestConfigWithSdkAndServer(t *testing.T) {
tests := []struct {
name string