--- a/KeywordInContextIndexBuilder.st Sun Feb 23 02:14:33 2014 +0100
+++ b/KeywordInContextIndexBuilder.st Tue Feb 25 08:19:54 2014 +0100
@@ -36,8 +36,11 @@
documentation
"
- A support class for building a KWIC (Keyword in Context) indices.
+ A support class for building a KWIC (Keyword in Context) index.
(for example, to build a KWIC index on html pages or class documentation).
+ To generate a kwic, add each line together with a reference (or page number, or whatever),
+ using addLine:reference:.
+ Then, when finished, enumerate the kwic.
[author:]
Claus Gittinger (cg@alan)
@@ -80,9 +83,9 @@
[exEnd]
- KWIC index over method selector components:
+ KWIC index over method selector components; build a little browser window:
[exBegin]
- |kwic|
+ |kwic v s c list refs|
kwic := KeywordInContextIndexBuilder new.
Smalltalk allClassesDo:[:eachClass |
@@ -90,7 +93,22 @@
kwic addLine:sel reference:mthd.
]
].
+
+ v := StandardSystemView new.
+ v addComponent:(s := HVScrollableView for:SelectionInListView).
+ s origin:0.0@0.0 corner:1.0@0.5.
+ v addComponent:(c := HVScrollableView for:CodeView).
+ c origin:0.0@0.5 corner:1.0@1.0.
+
+ refs := OrderedCollection new.
+ list := OrderedCollection new.
kwic
+ entriesDo:[:word :left :right :ref |
+ list add:(word,' ',left,' ',word allBold,' ',right,' (',ref mclass name,')').
+ refs add:ref].
+ s list:list.
+ s action:[:lNr | c contents:(refs at:lNr) source].
+ v open.
[exEnd]
KWIC index over method selector components, with word separation:
@@ -248,6 +266,9 @@
!KeywordInContextIndexBuilder methodsFor:'building'!
addLine:aLine reference:opaqueReference
+ "add a text line; the line is split at words and entered into the kwic.
+ the reference argument is stored as 'value' of the generated entries"
+
self addLine:aLine reference:opaqueReference ignoreCase:false
!
@@ -273,7 +294,9 @@
!KeywordInContextIndexBuilder methodsFor:'enumerating'!
-entriesDo:aBlock
+entriesDo:aFourArgBlock
+ "evaluate the argument, aFourArgBlock for each triple of kwic-word, left-text, right text and reference"
+
keywordToLinesMapping keys asSortedCollection do:[:eachKey |
|setOfMatches lcKey|
@@ -301,7 +324,7 @@
left := (context copyTo:lIdx - 1) withoutSeparators.
right := (context copyFrom:lIdx + lcKey size) withoutSeparators.
word := (context copyFrom:lIdx to:lIdx + lcKey size - 1) withoutSeparators.
- aBlock value:word value:left value:right value:ref.
+ aFourArgBlock value:word value:left value:right value:ref.
].
]
]
@@ -318,9 +341,10 @@
!KeywordInContextIndexBuilder class methodsFor:'documentation'!
version
- ^ '$Header: /cvs/stx/stx/libbasic2/KeywordInContextIndexBuilder.st,v 1.2 2011-02-14 17:39:30 cg Exp $'
+ ^ '$Header: /cvs/stx/stx/libbasic2/KeywordInContextIndexBuilder.st,v 1.3 2014-02-25 07:19:54 cg Exp $'
!
version_CVS
- ^ '$Header: /cvs/stx/stx/libbasic2/KeywordInContextIndexBuilder.st,v 1.2 2011-02-14 17:39:30 cg Exp $'
+ ^ '$Header: /cvs/stx/stx/libbasic2/KeywordInContextIndexBuilder.st,v 1.3 2014-02-25 07:19:54 cg Exp $'
! !
+