KeywordInContextIndexBuilder.st
author Claus Gittinger <cg@exept.de>
Tue, 25 Jun 2019 14:28:51 +0200
changeset 5050 44fa8672d102
parent 4188 f823326d96a3
child 5223 94415e3adba0
permissions -rw-r--r--
#DOCUMENTATION by cg class: SharedQueue comment/format in: #next #nextWithTimeout:
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1375
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     1
"
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     2
 COPYRIGHT (c) 2003 by eXept Software AG
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     3
              All Rights Reserved
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     4
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     5
 This software is furnished under a license and may be used
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     6
 only in accordance with the terms of that license and with the
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     7
 inclusion of the above copyright notice.   This software may not
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     8
 be provided or otherwise made available to, or used by, any
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     9
 other person.  No title to or ownership of the software is
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    10
 hereby transferred.
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    11
"
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    12
"{ Package: 'stx:libbasic2' }"
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    13
4108
667d0bdaf609 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 3184
diff changeset
    14
"{ NameSpace: Smalltalk }"
667d0bdaf609 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 3184
diff changeset
    15
1375
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    16
Object subclass:#KeywordInContextIndexBuilder
4130
2532973b50e6 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4129
diff changeset
    17
	instanceVariableNames:'keywordToLinesMapping excluded separatorAlgorithm
4188
f823326d96a3 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4187
diff changeset
    18
		unquoteAlgorithm exclusionFilter matchSorter'
1375
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    19
	classVariableNames:''
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    20
	poolDictionaries:''
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    21
	category:'Collections-Support'
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    22
!
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    23
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    24
!KeywordInContextIndexBuilder class methodsFor:'documentation'!
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    25
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    26
copyright
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    27
"
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    28
 COPYRIGHT (c) 2003 by eXept Software AG
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    29
              All Rights Reserved
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    30
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    31
 This software is furnished under a license and may be used
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    32
 only in accordance with the terms of that license and with the
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    33
 inclusion of the above copyright notice.   This software may not
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    34
 be provided or otherwise made available to, or used by, any
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    35
 other person.  No title to or ownership of the software is
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    36
 hereby transferred.
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    37
"
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    38
!
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    39
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    40
documentation
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    41
"
4126
4d3ec803fddf #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4125
diff changeset
    42
    A support class for building KWIC (Keyword in Context) or KWOC (Keyword out of Context) indexes.
4d3ec803fddf #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4125
diff changeset
    43
    (for example, to build such indexes on html pages or class documentation).
4125
d597206782cc #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4124
diff changeset
    44
    
3184
27271594c7d8 comments
Claus Gittinger <cg@exept.de>
parents: 2536
diff changeset
    45
    To generate a kwic, add each line together with a reference (or page number, or whatever),
27271594c7d8 comments
Claus Gittinger <cg@exept.de>
parents: 2536
diff changeset
    46
    using addLine:reference:.
4126
4d3ec803fddf #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4125
diff changeset
    47
    Then, when finished, enumerate the kwic and print as kwic or kwoc.
4127
0f3c785bb689 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4126
diff changeset
    48
    
4187
064b249c5e3d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4132
diff changeset
    49
    To ignore fill words (such as 'and', 'the', 'in', etc.), 
064b249c5e3d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4132
diff changeset
    50
    define those with the #excluded: messages.
064b249c5e3d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4132
diff changeset
    51
064b249c5e3d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4132
diff changeset
    52
    The keyword handling is configurable by providing actions/lists for:
064b249c5e3d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4132
diff changeset
    53
        separatorAlgorithm      a block which separates lines into individual words
064b249c5e3d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4132
diff changeset
    54
                                gets a line; delivers a collection of words
064b249c5e3d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4132
diff changeset
    55
064b249c5e3d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4132
diff changeset
    56
        excluded                a collection of words which are to be ignored
064b249c5e3d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4132
diff changeset
    57
064b249c5e3d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4132
diff changeset
    58
        unquoteAlgorithm        a block to remove quotes around words. 
064b249c5e3d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4132
diff changeset
    59
                                gets word as argument, delivers unquoted word
064b249c5e3d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4132
diff changeset
    60
064b249c5e3d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4132
diff changeset
    61
        keywordMappingAlgorithm 
064b249c5e3d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4132
diff changeset
    62
                                maps keywords; for example, can be used to map 'startsWith'
064b249c5e3d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4132
diff changeset
    63
                                to 'start', so they appear in the same section.
064b249c5e3d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4132
diff changeset
    64
                                Gets the word and the set-of-all-words as arguments,
064b249c5e3d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4132
diff changeset
    65
                                delivers the key into which the word's entries should be placed  
064b249c5e3d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4132
diff changeset
    66
                                
064b249c5e3d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4132
diff changeset
    67
        matchSorter             determines the order in which keywords are listed
064b249c5e3d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4132
diff changeset
    68
        
1375
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    69
    [author:]
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    70
        Claus Gittinger (cg@alan)
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    71
4126
4d3ec803fddf #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4125
diff changeset
    72
    [examples:]
4d3ec803fddf #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4125
diff changeset
    73
        see examples method
1375
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    74
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    75
    [see also:]
4125
d597206782cc #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4124
diff changeset
    76
        https://en.wikipedia.org/wiki/Key_Word_in_Context (english)
d597206782cc #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4124
diff changeset
    77
        https://de.wikipedia.org/wiki/Permutiertes_Register (german)
d597206782cc #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4124
diff changeset
    78
        
1375
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    79
"
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    80
!
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    81
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    82
examples
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    83
"
4126
4d3ec803fddf #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4125
diff changeset
    84
    building a kwic; print as kwic and kwoc
1375
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    85
                                                                [exBegin]
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    86
    |kwic|
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    87
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    88
    kwic := KeywordInContextIndexBuilder new.
4127
0f3c785bb689 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4126
diff changeset
    89
    kwic excluded:#('the' 'and' 'a' 'an' 'in').
1375
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    90
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    91
    kwic addLine:'bla bla bla' reference:1.
4126
4d3ec803fddf #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4125
diff changeset
    92
    kwic addLine:'foo, bar. baz' reference:2.
4d3ec803fddf #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4125
diff changeset
    93
    kwic addLine:'one two three' reference:3.
4d3ec803fddf #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4125
diff changeset
    94
    kwic addLine:'a cat and a dog' reference:4.
4d3ec803fddf #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4125
diff changeset
    95
    kwic addLine:'the man in the middle' reference:5.
4d3ec803fddf #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4125
diff changeset
    96
    kwic addLine:'the man with the dog' reference:6.
1375
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    97
4126
4d3ec803fddf #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4125
diff changeset
    98
    Transcript showCR:'Printed as KWIC:'.
1375
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    99
    kwic 
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   100
        entriesDo:[:word :left :right :ref |
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   101
            Transcript 
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   102
                show:((left contractTo:20) leftPaddedTo:20);
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   103
                space;
4124
2d4e83bec872 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
   104
                show:((word contractTo:10) leftPaddedTo:10) allBold;
1375
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   105
                space;
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   106
                show:((right contractTo:20) leftPaddedTo:20);
2536
8907a20de2dc changed: #examples
Claus Gittinger <cg@exept.de>
parents: 1375
diff changeset
   107
                space;
8907a20de2dc changed: #examples
Claus Gittinger <cg@exept.de>
parents: 1375
diff changeset
   108
                show:'['; show:ref; show:']';
1375
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   109
                cr    
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   110
        ].
4126
4d3ec803fddf #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4125
diff changeset
   111
4d3ec803fddf #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4125
diff changeset
   112
    Transcript cr.
4d3ec803fddf #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4125
diff changeset
   113
    Transcript showCR:'Printed as KWOC:'.
4d3ec803fddf #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4125
diff changeset
   114
    kwic 
4128
4cc1535fa7dc #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4127
diff changeset
   115
        entriesDo:[:word :left :right :ref :fullText :context |
4126
4d3ec803fddf #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4125
diff changeset
   116
            Transcript 
4d3ec803fddf #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4125
diff changeset
   117
                show:((word contractTo:10) paddedTo:10) allBold;
4d3ec803fddf #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4125
diff changeset
   118
                space;
4128
4cc1535fa7dc #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4127
diff changeset
   119
                show:((context contractTo:60) paddedTo:60);
4126
4d3ec803fddf #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4125
diff changeset
   120
                space;
4d3ec803fddf #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4125
diff changeset
   121
                show:'['; show:ref; show:']';
4d3ec803fddf #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4125
diff changeset
   122
                cr    
4d3ec803fddf #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4125
diff changeset
   123
        ].
1375
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   124
                                                                [exEnd]
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   125
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   126
3184
27271594c7d8 comments
Claus Gittinger <cg@exept.de>
parents: 2536
diff changeset
   127
  KWIC index over method selector components; build a little browser window:
1375
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   128
                                                                [exBegin]
3184
27271594c7d8 comments
Claus Gittinger <cg@exept.de>
parents: 2536
diff changeset
   129
    |kwic v s c list refs|
1375
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   130
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   131
    kwic := KeywordInContextIndexBuilder new.
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   132
    Smalltalk allClassesDo:[:eachClass |
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   133
        eachClass instAndClassSelectorsAndMethodsDo:[:sel :mthd |
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   134
            kwic addLine:sel reference:mthd.
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   135
        ]
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   136
    ].
3184
27271594c7d8 comments
Claus Gittinger <cg@exept.de>
parents: 2536
diff changeset
   137
27271594c7d8 comments
Claus Gittinger <cg@exept.de>
parents: 2536
diff changeset
   138
    v := StandardSystemView new.
27271594c7d8 comments
Claus Gittinger <cg@exept.de>
parents: 2536
diff changeset
   139
    v addComponent:(s := HVScrollableView for:SelectionInListView).
27271594c7d8 comments
Claus Gittinger <cg@exept.de>
parents: 2536
diff changeset
   140
    s origin:0.0@0.0 corner:1.0@0.5.
27271594c7d8 comments
Claus Gittinger <cg@exept.de>
parents: 2536
diff changeset
   141
    v addComponent:(c := HVScrollableView for:CodeView).
27271594c7d8 comments
Claus Gittinger <cg@exept.de>
parents: 2536
diff changeset
   142
    c origin:0.0@0.5 corner:1.0@1.0.
27271594c7d8 comments
Claus Gittinger <cg@exept.de>
parents: 2536
diff changeset
   143
27271594c7d8 comments
Claus Gittinger <cg@exept.de>
parents: 2536
diff changeset
   144
    refs := OrderedCollection new.
27271594c7d8 comments
Claus Gittinger <cg@exept.de>
parents: 2536
diff changeset
   145
    list := OrderedCollection new.
1375
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   146
    kwic 
3184
27271594c7d8 comments
Claus Gittinger <cg@exept.de>
parents: 2536
diff changeset
   147
        entriesDo:[:word :left :right :ref |
27271594c7d8 comments
Claus Gittinger <cg@exept.de>
parents: 2536
diff changeset
   148
            list add:(word,' ',left,' ',word allBold,' ',right,' (',ref mclass name,')').
27271594c7d8 comments
Claus Gittinger <cg@exept.de>
parents: 2536
diff changeset
   149
            refs add:ref].
27271594c7d8 comments
Claus Gittinger <cg@exept.de>
parents: 2536
diff changeset
   150
    s list:list.
27271594c7d8 comments
Claus Gittinger <cg@exept.de>
parents: 2536
diff changeset
   151
    s action:[:lNr | c contents:(refs at:lNr) source].
27271594c7d8 comments
Claus Gittinger <cg@exept.de>
parents: 2536
diff changeset
   152
    v open.
1375
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   153
                                                                [exEnd]
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   154
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   155
  KWIC index over method selector components, with word separation:
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   156
                                                                [exBegin]
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   157
    |kwic|
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   158
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   159
    kwic := KeywordInContextIndexBuilder forMethodSelectorIndex.
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   160
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   161
    Smalltalk allClassesDo:[:eachClass |
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   162
        eachClass instAndClassSelectorsAndMethodsDo:[:sel :mthd |
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   163
            kwic addLine:sel reference:mthd.
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   164
        ]
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   165
    ].
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   166
    kwic
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   167
                                                                [exEnd]
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   168
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   169
  KWIC index over method comments:
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   170
                                                                [exBegin]
4124
2d4e83bec872 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
   171
    |kwic v s c refs list|
1375
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   172
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   173
    kwic := KeywordInContextIndexBuilder forMethodComments.
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   174
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   175
    Smalltalk allClassesDo:[:eachClass |
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   176
        eachClass instAndClassSelectorsAndMethodsDo:[:sel :mthd |
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   177
            |comment|
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   178
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   179
            (sel == #documentation) ifTrue:[
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   180
                comment := mthd comment.
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   181
                comment notNil ifTrue:[
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   182
                    kwic addLine:comment reference:mthd mclass ignoreCase:true.
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   183
                ]
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   184
            ] ifFalse:[
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   185
                (sel ~~ #examples
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   186
                and:[ sel ~~ #copyright
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   187
                and:[ sel ~~ #version]]) ifTrue:[
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   188
                    comment := mthd comment.
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   189
                    comment notNil ifTrue:[
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   190
                        kwic addLine:comment reference:mthd ignoreCase:true.
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   191
                    ]
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   192
                ]
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   193
            ]
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   194
        ]
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   195
    ].
4124
2d4e83bec872 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
   196
    kwic.
1375
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   197
                                                                [exEnd]
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   198
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   199
  KWIC index over class comments:
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   200
                                                                [exBegin]
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   201
    |kwic|
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   202
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   203
    kwic := KeywordInContextIndexBuilder forMethodComments.
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   204
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   205
    Smalltalk allClassesDo:[:eachClass |
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   206
        |mthd comment|
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   207
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   208
        mthd := eachClass theMetaclass compiledMethodAt:#documentation.
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   209
        mthd notNil ifTrue:[
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   210
            comment := mthd comment.
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   211
            comment notNil ifTrue:[
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   212
                kwic addLine:comment reference:eachClass theNonMetaclass ignoreCase:true.
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   213
            ]
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   214
        ]
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   215
    ].
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   216
    kwic
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   217
                                                                [exEnd]
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   218
"
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   219
! !
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   220
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   221
!KeywordInContextIndexBuilder class methodsFor:'instance creation'!
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   222
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   223
forMethodComments
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   224
    "return an indexer for method comments"
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   225
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   226
    |sepChars sep kwic|
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   227
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   228
    sepChars := '.,;:_ !![]()''"#?<>|' , Character return, Character lf, Character tab.
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   229
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   230
    sep := [:lines | lines asString asCollectionOfSubstringsSeparatedByAny:sepChars].
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   231
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   232
    kwic := self new.
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   233
    kwic separatorAlgorithm:sep.
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   234
    kwic excluded:#('the' 'and' 'a' 'an' 'for' 'with' 'no').
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   235
    ^ kwic
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   236
!
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   237
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   238
forMethodSelectorIndex
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   239
    "return an indexer for method selector components, with word separation at case boundaries"
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   240
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   241
    |sep kwic sepUCWords|
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   242
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   243
    sepUCWords := [:word :keyWords| 
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   244
                    |s w c lastC last2C frag|
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   245
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   246
                    word asLowercase = word ifTrue:[
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   247
                        keyWords add:word.
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   248
                    ] ifFalse:[
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   249
                        s := word readStream.
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   250
                        w := '' writeStream.
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   251
                        [s atEnd] whileFalse:[
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   252
                            c := s next.
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   253
                            (c isUppercase) ifTrue:[
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   254
                                (lastC notNil and:[lastC isUppercase not]) ifTrue:[
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   255
                                    keyWords add:w contents.
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   256
                                    w := '' writeStream.
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   257
                                ].
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   258
                            ] ifFalse:[
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   259
                                (last2C notNil and:[last2C isUppercase and:[lastC isUppercase]]) ifTrue:[
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   260
                                    c isLetter ifTrue:[
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   261
                                        frag := w contents.
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   262
                                        w := '' writeStream.
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   263
                                        w nextPut:(frag last).
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   264
                                        keyWords add:(frag allButLast).
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   265
                                    ] ifFalse:[
4108
667d0bdaf609 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 3184
diff changeset
   266
                                       "/ frag := w contents.
667d0bdaf609 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 3184
diff changeset
   267
                                       "/ w := '' writeStream.
667d0bdaf609 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 3184
diff changeset
   268
                                       "/ keyWords add:frag.
1375
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   269
                                    ].
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   270
                                ].
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   271
                            ].
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   272
                            w nextPut:c.
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   273
                            last2C := lastC.
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   274
                            lastC := c.
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   275
                        ].
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   276
                    ].
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   277
                  ].
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   278
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   279
    sep := [:line | 
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   280
                |words keyWords|
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   281
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   282
                words := line asCollectionOfSubstringsSeparatedByAny:'.,;:_ '.
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   283
                keyWords := OrderedCollection new.
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   284
                words do:[:eachWord | sepUCWords value:eachWord value:keyWords].
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   285
                keyWords
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   286
            ].
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   287
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   288
    kwic := self new.
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   289
    kwic separatorAlgorithm:sep.
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   290
    ^ kwic
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   291
!
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   292
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   293
new
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   294
    ^ self basicNew initialize
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   295
! !
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   296
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   297
!KeywordInContextIndexBuilder methodsFor:'accessing'!
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   298
4128
4cc1535fa7dc #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4127
diff changeset
   299
excluded:aListOfExcludedWords
4cc1535fa7dc #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4127
diff changeset
   300
    "define words which are to be ignored.
4cc1535fa7dc #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4127
diff changeset
   301
     Typically, this is a list of fillwords, such as 'and', 'the', 'in', etc."
4cc1535fa7dc #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4127
diff changeset
   302
     
4cc1535fa7dc #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4127
diff changeset
   303
    excluded := aListOfExcludedWords asSet.
1375
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   304
!
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   305
4130
2532973b50e6 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4129
diff changeset
   306
exclusionFilter:aBlock
2532973b50e6 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4129
diff changeset
   307
    "define an additional filter to exclude more complicated patterns.
2532973b50e6 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4129
diff changeset
   308
     This is invoked after filtering by the exclusion list.
2532973b50e6 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4129
diff changeset
   309
     If defined, this should return true,if the word is to be excluded."
2532973b50e6 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4129
diff changeset
   310
     
2532973b50e6 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4129
diff changeset
   311
    exclusionFilter := aBlock.
2532973b50e6 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4129
diff changeset
   312
!
2532973b50e6 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4129
diff changeset
   313
4132
f87c478424c7 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4131
diff changeset
   314
matchSorter:aSortBlock
4187
064b249c5e3d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4132
diff changeset
   315
    "if set, matches will be enumerated in that sort order."
4132
f87c478424c7 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4131
diff changeset
   316
    
f87c478424c7 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4131
diff changeset
   317
    matchSorter := aSortBlock.
f87c478424c7 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4131
diff changeset
   318
!
f87c478424c7 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4131
diff changeset
   319
4128
4cc1535fa7dc #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4127
diff changeset
   320
separatorAlgorithm:aBlock
4cc1535fa7dc #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4127
diff changeset
   321
    "define the algorithm to split a given string into words.
4cc1535fa7dc #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4127
diff changeset
   322
     The default is to split at punctuation and whitespace
4cc1535fa7dc #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4127
diff changeset
   323
     (see #initialize)"
4cc1535fa7dc #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4127
diff changeset
   324
     
4cc1535fa7dc #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4127
diff changeset
   325
    separatorAlgorithm := aBlock.
4130
2532973b50e6 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4129
diff changeset
   326
!
2532973b50e6 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4129
diff changeset
   327
2532973b50e6 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4129
diff changeset
   328
unquoteAlgorithm:aBlock
2532973b50e6 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4129
diff changeset
   329
    "define the algorithm to unquote words.
2532973b50e6 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4129
diff changeset
   330
     The default is to unquote single and double quotes
2532973b50e6 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4129
diff changeset
   331
     (see #initialize)"
2532973b50e6 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4129
diff changeset
   332
     
2532973b50e6 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4129
diff changeset
   333
    unquoteAlgorithm := aBlock.
1375
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   334
! !
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   335
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   336
!KeywordInContextIndexBuilder methodsFor:'building'!
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   337
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   338
addLine:aLine reference:opaqueReference
3184
27271594c7d8 comments
Claus Gittinger <cg@exept.de>
parents: 2536
diff changeset
   339
    "add a text line; the line is split at words and entered into the kwic.
4128
4cc1535fa7dc #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4127
diff changeset
   340
     The reference argument is stored as 'value' of the generated entries.
4cc1535fa7dc #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4127
diff changeset
   341
     It can be anything"
3184
27271594c7d8 comments
Claus Gittinger <cg@exept.de>
parents: 2536
diff changeset
   342
4128
4cc1535fa7dc #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4127
diff changeset
   343
    self addLine:aLine reference:opaqueReference ignoreCase:true
1375
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   344
!
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   345
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   346
addLine:aLine reference:opaqueReference ignoreCase:ignoreCase
4128
4cc1535fa7dc #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4127
diff changeset
   347
    "add a line to the kwic.
4cc1535fa7dc #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4127
diff changeset
   348
     The line is split up into words, and a reference to opaqueReference
4cc1535fa7dc #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4127
diff changeset
   349
     is added for each word.
4188
f823326d96a3 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4187
diff changeset
   350
     The reference argument is stored as 'value' of the generated entries;
f823326d96a3 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4187
diff changeset
   351
     it can be anything"
4128
4cc1535fa7dc #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4127
diff changeset
   352
     
4187
064b249c5e3d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4132
diff changeset
   353
    (separatorAlgorithm value:aLine optionalArgument:keywordToLinesMapping) do:[:eachWord |
1375
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   354
        |set word|
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   355
4131
b4294ed81d7d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4130
diff changeset
   356
        (excluded includes:eachWord) ifFalse:[
b4294ed81d7d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4130
diff changeset
   357
            word := unquoteAlgorithm value:eachWord.
b4294ed81d7d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4130
diff changeset
   358
            ignoreCase ifTrue:[
b4294ed81d7d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4130
diff changeset
   359
                word := word asLowercase.
b4294ed81d7d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4130
diff changeset
   360
            ].
b4294ed81d7d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4130
diff changeset
   361
            (excluded includes:word) ifFalse:[
b4294ed81d7d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4130
diff changeset
   362
                (exclusionFilter isNil or:[ (exclusionFilter value:word) not]) ifTrue:[
b4294ed81d7d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4130
diff changeset
   363
                    set := keywordToLinesMapping at:word ifAbsentPut:[Set new].
b4294ed81d7d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4130
diff changeset
   364
                    set add:(aLine -> opaqueReference).
b4294ed81d7d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4130
diff changeset
   365
                ]
4130
2532973b50e6 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4129
diff changeset
   366
            ]
1375
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   367
        ]
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   368
    ].
4188
f823326d96a3 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4187
diff changeset
   369
!
f823326d96a3 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4187
diff changeset
   370
f823326d96a3 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4187
diff changeset
   371
remapKeywordsWith:keywordMappingAlgorithm 
f823326d96a3 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4187
diff changeset
   372
    "allows for an additional mapper to be applied (after the kwic has been constructed).
f823326d96a3 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4187
diff changeset
   373
     This can map multiple different words to the same keword.
f823326d96a3 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4187
diff changeset
   374
     It is given the word and the set of already known words as argument.
f823326d96a3 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4187
diff changeset
   375
     It may, for example figure out that a word with a long prefix is already in the
f823326d96a3 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4187
diff changeset
   376
     list and decide, that a new word should be brought into the same bucket.
f823326d96a3 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4187
diff changeset
   377
     For example, if 'starts' is already in the list, and 'startWith' is encountered."
f823326d96a3 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4187
diff changeset
   378
f823326d96a3 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4187
diff changeset
   379
    |knownKeys|
4187
064b249c5e3d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4132
diff changeset
   380
    
4188
f823326d96a3 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4187
diff changeset
   381
    knownKeys := keywordToLinesMapping keys copy.
f823326d96a3 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4187
diff changeset
   382
    knownKeys do:[:kw |
f823326d96a3 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4187
diff changeset
   383
        |mappedWord oldSet newSet|
f823326d96a3 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4187
diff changeset
   384
f823326d96a3 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4187
diff changeset
   385
        mappedWord := keywordMappingAlgorithm value:kw optionalArgument:knownKeys.
f823326d96a3 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4187
diff changeset
   386
        mappedWord ~= kw ifTrue:[
f823326d96a3 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4187
diff changeset
   387
            oldSet := keywordToLinesMapping at:kw ifAbsent:[nil].
f823326d96a3 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4187
diff changeset
   388
            oldSet notNil ifTrue:[
f823326d96a3 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4187
diff changeset
   389
                newSet := keywordToLinesMapping at:mappedWord ifAbsentPut:[Set new].
f823326d96a3 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4187
diff changeset
   390
                oldSet do:[:eachEntry |
f823326d96a3 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4187
diff changeset
   391
                    newSet add:eachEntry.
f823326d96a3 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4187
diff changeset
   392
                ].
f823326d96a3 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4187
diff changeset
   393
                keywordToLinesMapping removeKey:kw.
4187
064b249c5e3d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4132
diff changeset
   394
            ]    
4188
f823326d96a3 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4187
diff changeset
   395
        ]    
4187
064b249c5e3d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4132
diff changeset
   396
    ].
1375
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   397
! !
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   398
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   399
!KeywordInContextIndexBuilder methodsFor:'enumerating'!
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   400
4128
4cc1535fa7dc #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4127
diff changeset
   401
entriesDo:aFourToSixArgBlock
4126
4d3ec803fddf #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4125
diff changeset
   402
    "evaluate the argument, for each entry.
4d3ec803fddf #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4125
diff changeset
   403
     If it is a 4-arg block, it is called with:
4d3ec803fddf #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4125
diff changeset
   404
        kwic-word, 
4d3ec803fddf #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4125
diff changeset
   405
        left-text, 
4d3ec803fddf #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4125
diff changeset
   406
        right text 
4d3ec803fddf #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4125
diff changeset
   407
        and reference
4d3ec803fddf #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4125
diff changeset
   408
     If it is a 5-arg block, the original text is passed as additional argument.
4128
4cc1535fa7dc #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4127
diff changeset
   409
     If it is a 6-arg block, the original text and the context are passed as additional argument.
4126
4d3ec803fddf #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4125
diff changeset
   410
     (stupid, but done for backward compatibility)"
3184
27271594c7d8 comments
Claus Gittinger <cg@exept.de>
parents: 2536
diff changeset
   411
4128
4cc1535fa7dc #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4127
diff changeset
   412
    |fourArgBlock|
4126
4d3ec803fddf #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4125
diff changeset
   413
4128
4cc1535fa7dc #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4127
diff changeset
   414
    aFourToSixArgBlock numArgs == 4 ifTrue:[
4cc1535fa7dc #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4127
diff changeset
   415
        fourArgBlock := aFourToSixArgBlock 
4126
4d3ec803fddf #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4125
diff changeset
   416
    ].    
1375
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   417
    keywordToLinesMapping keys asSortedCollection do:[:eachKey |
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   418
        |setOfMatches lcKey|
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   419
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   420
        setOfMatches := keywordToLinesMapping at:eachKey.
4132
f87c478424c7 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4131
diff changeset
   421
        matchSorter notNil ifTrue:[
f87c478424c7 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4131
diff changeset
   422
            setOfMatches := setOfMatches asSortedCollection:matchSorter
f87c478424c7 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4131
diff changeset
   423
        ].    
1375
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   424
        lcKey := eachKey asLowercase.
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   425
        setOfMatches do:[:eachAssoc |
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   426
            |text ref lines idx lIdx context left right word prevLine nextLine|
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   427
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   428
            text := eachAssoc key.
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   429
            ref := eachAssoc value.
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   430
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   431
            lines := text asCollectionOfLines.
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   432
            idx := lines findFirst:[:line | line asLowercase includesString:lcKey].
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   433
            idx ~~ 0 ifTrue:[
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   434
                context := lines at:idx.
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   435
                idx > 1 ifTrue:[
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   436
                    prevLine := (lines at:idx-1).
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   437
                    context := prevLine , ' ' , context.
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   438
                ].
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   439
                idx < lines size ifTrue:[
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   440
                    nextLine := (lines at:idx+1).
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   441
                    context :=  context , ' ' , nextLine.
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   442
                ].
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   443
                lIdx := context asLowercase findString:lcKey.
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   444
                left := (context copyTo:lIdx - 1) withoutSeparators.
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   445
                right := (context copyFrom:lIdx + lcKey size) withoutSeparators.
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   446
                word := (context copyFrom:lIdx to:lIdx + lcKey size - 1) withoutSeparators.
4126
4d3ec803fddf #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4125
diff changeset
   447
                fourArgBlock notNil ifTrue:[
4d3ec803fddf #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4125
diff changeset
   448
                    fourArgBlock value:word value:left value:right value:ref.
4d3ec803fddf #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4125
diff changeset
   449
                ] ifFalse:[
4128
4cc1535fa7dc #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4127
diff changeset
   450
                    aFourToSixArgBlock value:word optionalArgument:left and:right and:ref and:text and:context
4126
4d3ec803fddf #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4125
diff changeset
   451
                ].    
1375
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   452
            ].
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   453
        ]
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   454
    ]
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   455
! !
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   456
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   457
!KeywordInContextIndexBuilder methodsFor:'initialization'!
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   458
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   459
initialize
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   460
    keywordToLinesMapping := Dictionary new.
4129
04b54f7b1a82 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4128
diff changeset
   461
    self excluded:(Set new).
4130
2532973b50e6 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4129
diff changeset
   462
    self exclusionFilter:nil.
4129
04b54f7b1a82 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4128
diff changeset
   463
    self separatorAlgorithm:[:line | line asCollectionOfSubstringsSeparatedByAny:' .:,;-'].
4130
2532973b50e6 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4129
diff changeset
   464
    self unquoteAlgorithm:[:word | (word unquote:$") unquote:$' ].
1375
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   465
! !
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   466
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   467
!KeywordInContextIndexBuilder class methodsFor:'documentation'!
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   468
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   469
version
4108
667d0bdaf609 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 3184
diff changeset
   470
    ^ '$Header$'
2536
8907a20de2dc changed: #examples
Claus Gittinger <cg@exept.de>
parents: 1375
diff changeset
   471
!
8907a20de2dc changed: #examples
Claus Gittinger <cg@exept.de>
parents: 1375
diff changeset
   472
8907a20de2dc changed: #examples
Claus Gittinger <cg@exept.de>
parents: 1375
diff changeset
   473
version_CVS
4108
667d0bdaf609 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 3184
diff changeset
   474
    ^ '$Header$'
1375
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   475
! !
3184
27271594c7d8 comments
Claus Gittinger <cg@exept.de>
parents: 2536
diff changeset
   476