Support corpus mappings

Change-Id: I25e987b0ca668a1cf733424b22edb4f0fca37bf2
diff --git a/mapper/mapper.go b/mapper/mapper.go
index d11ae01..e55e77a 100644
--- a/mapper/mapper.go
+++ b/mapper/mapper.go
@@ -13,8 +13,25 @@
 const (
 	AtoB Direction = true
 	BtoA Direction = false
+
+	RewriteEditor = "Koral-Mapper"
 )
 
+// newRewriteEntry creates a koral:rewrite annotation entry.
+func newRewriteEntry(scope string, original any) map[string]any {
+	r := map[string]any{
+		"@type":  "koral:rewrite",
+		"editor": RewriteEditor,
+	}
+	if scope != "" {
+		r["scope"] = scope
+	}
+	if original != nil {
+		r["original"] = original
+	}
+	return r
+}
+
 // String converts the Direction to its string representation
 func (d Direction) String() string {
 	if d {
@@ -37,15 +54,17 @@
 
 // Mapper handles the application of mapping rules to JSON objects
 type Mapper struct {
-	mappingLists map[string]*config.MappingList
-	parsedRules  map[string][]*parser.MappingResult
+	mappingLists      map[string]*config.MappingList
+	parsedQueryRules  map[string][]*parser.MappingResult
+	parsedCorpusRules map[string][]*parser.CorpusMappingResult
 }
 
 // NewMapper creates a new Mapper instance from a list of MappingLists
 func NewMapper(lists []config.MappingList) (*Mapper, error) {
 	m := &Mapper{
-		mappingLists: make(map[string]*config.MappingList),
-		parsedRules:  make(map[string][]*parser.MappingResult),
+		mappingLists:      make(map[string]*config.MappingList),
+		parsedQueryRules:  make(map[string][]*parser.MappingResult),
+		parsedCorpusRules: make(map[string][]*parser.CorpusMappingResult),
 	}
 
 	// Store mapping lists by ID
@@ -54,16 +73,22 @@
 			return nil, fmt.Errorf("duplicate mapping list ID found: %s", list.ID)
 		}
 
-		// Create a copy of the list to store
 		listCopy := list
 		m.mappingLists[list.ID] = &listCopy
 
-		// Parse the rules immediately
-		parsedRules, err := list.ParseMappings()
-		if err != nil {
-			return nil, fmt.Errorf("failed to parse mappings for list %s: %w", list.ID, err)
+		if list.IsCorpus() {
+			corpusRules, err := list.ParseCorpusMappings()
+			if err != nil {
+				return nil, fmt.Errorf("failed to parse corpus mappings for list %s: %w", list.ID, err)
+			}
+			m.parsedCorpusRules[list.ID] = corpusRules
+		} else {
+			queryRules, err := list.ParseMappings()
+			if err != nil {
+				return nil, fmt.Errorf("failed to parse mappings for list %s: %w", list.ID, err)
+			}
+			m.parsedQueryRules[list.ID] = queryRules
 		}
-		m.parsedRules[list.ID] = parsedRules
 	}
 
 	return m, nil