#DOCUMENTATION by cg
authorClaus Gittinger <cg@exept.de>
Fri, 04 Nov 2016 13:14:03 +0100
changeset 4188 f823326d96a3
parent 4187 064b249c5e3d
child 4189 77a437cb158c
#DOCUMENTATION by cg class: KeywordInContextIndexBuilder class definition added: #remapKeywordsWith: removed: #keywordMappingAlgorithm: changed: #addLine:reference:ignoreCase:
KeywordInContextIndexBuilder.st
--- a/KeywordInContextIndexBuilder.st	Fri Nov 04 12:53:50 2016 +0100
+++ b/KeywordInContextIndexBuilder.st	Fri Nov 04 13:14:03 2016 +0100
@@ -15,8 +15,7 @@
 
 Object subclass:#KeywordInContextIndexBuilder
 	instanceVariableNames:'keywordToLinesMapping excluded separatorAlgorithm
-		unquoteAlgorithm keywordMappingAlgorithm exclusionFilter
-		matchSorter'
+		unquoteAlgorithm exclusionFilter matchSorter'
 	classVariableNames:''
 	poolDictionaries:''
 	category:'Collections-Support'
@@ -312,16 +311,6 @@
     exclusionFilter := aBlock.
 !
 
-keywordMappingAlgorithm:aBlock
-    "define an additional mapper whih can map multiple different words to the same keword
-     it is given the word and the set of already known words as argument.
-     It may, for example figure out that a word with a long prefix is already in the
-     list and decide, that a new word should be brought into the same bucket.
-     For example, if 'starts' is already in the list, and 'startWith' is encountered."
-     
-    keywordMappingAlgorithm := aBlock.
-!
-
 matchSorter:aSortBlock
     "if set, matches will be enumerated in that sort order."
     
@@ -358,8 +347,8 @@
     "add a line to the kwic.
      The line is split up into words, and a reference to opaqueReference
      is added for each word.
-     The reference argument is stored as 'value' of the generated entries.
-     It can be anything"
+     The reference argument is stored as 'value' of the generated entries;
+     it can be anything"
      
     (separatorAlgorithm value:aLine optionalArgument:keywordToLinesMapping) do:[:eachWord |
         |set word|
@@ -377,22 +366,33 @@
             ]
         ]
     ].
+!
+
+remapKeywordsWith:keywordMappingAlgorithm 
+    "allows for an additional mapper to be applied (after the kwic has been constructed).
+     This can map multiple different words to the same keword.
+     It is given the word and the set of already known words as argument.
+     It may, for example figure out that a word with a long prefix is already in the
+     list and decide, that a new word should be brought into the same bucket.
+     For example, if 'starts' is already in the list, and 'startWith' is encountered."
+
+    |knownKeys|
     
-    keywordMappingAlgorithm notNil ifTrue:[
-        keywordToLinesMapping keys copy do:[:kw |
-            |mappedWord oldSet newSet|
-            
-            mappedWord := keywordToLinesMapping value:kw optionalArgument:keywordToLinesMapping.
-            mappedWord ~= kw ifTrue:[
-                oldSet := keywordToLinesMapping at:kw ifAbsent:[nil].
-                oldSet notNIl ifTrue:[
-                    newSet := keywordToLinesMapping at:mappedWord ifAbsentPut:[Set new].
-                    oldSet do:[:eachEntry |
-                        newSet add:eachEntry.
-                    ].
-                ]    
+    knownKeys := keywordToLinesMapping keys copy.
+    knownKeys do:[:kw |
+        |mappedWord oldSet newSet|
+
+        mappedWord := keywordMappingAlgorithm value:kw optionalArgument:knownKeys.
+        mappedWord ~= kw ifTrue:[
+            oldSet := keywordToLinesMapping at:kw ifAbsent:[nil].
+            oldSet notNil ifTrue:[
+                newSet := keywordToLinesMapping at:mappedWord ifAbsentPut:[Set new].
+                oldSet do:[:eachEntry |
+                    newSet add:eachEntry.
+                ].
+                keywordToLinesMapping removeKey:kw.
             ]    
-        ].
+        ]    
     ].
 ! !