KeywordInContextIndexBuilder.st
author Claus Gittinger <cg@exept.de>
Fri, 04 Nov 2016 12:53:50 +0100
changeset 4187 064b249c5e3d
parent 4132 f87c478424c7
child 4188 f823326d96a3
permissions -rw-r--r--
#FEATURE by cg class: KeywordInContextIndexBuilder class definition added: #keywordMappingAlgorithm: comment/format in: #documentation #matchSorter: changed: #addLine:reference:ignoreCase:
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
4187
064b249c5e3d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4132
diff changeset
    18
		unquoteAlgorithm keywordMappingAlgorithm exclusionFilter
064b249c5e3d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4132
diff changeset
    19
		matchSorter'
1375
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    20
	classVariableNames:''
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    21
	poolDictionaries:''
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    22
	category:'Collections-Support'
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    23
!
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    24
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    25
!KeywordInContextIndexBuilder class methodsFor:'documentation'!
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    26
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    27
copyright
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    28
"
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    29
 COPYRIGHT (c) 2003 by eXept Software AG
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    30
              All Rights Reserved
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    31
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    32
 This software is furnished under a license and may be used
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    33
 only in accordance with the terms of that license and with the
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    34
 inclusion of the above copyright notice.   This software may not
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    35
 be provided or otherwise made available to, or used by, any
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    36
 other person.  No title to or ownership of the software is
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    37
 hereby transferred.
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
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    41
documentation
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    42
"
4126
4d3ec803fddf #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4125
diff changeset
    43
    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
    44
    (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
    45
    
3184
27271594c7d8 comments
Claus Gittinger <cg@exept.de>
parents: 2536
diff changeset
    46
    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
    47
    using addLine:reference:.
4126
4d3ec803fddf #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4125
diff changeset
    48
    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
    49
    
4187
064b249c5e3d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4132
diff changeset
    50
    To ignore fill words (such as 'and', 'the', 'in', etc.), 
064b249c5e3d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4132
diff changeset
    51
    define those with the #excluded: messages.
064b249c5e3d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4132
diff changeset
    52
064b249c5e3d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4132
diff changeset
    53
    The keyword handling is configurable by providing actions/lists for:
064b249c5e3d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4132
diff changeset
    54
        separatorAlgorithm      a block which separates lines into individual words
064b249c5e3d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4132
diff changeset
    55
                                gets a line; delivers a collection of words
064b249c5e3d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4132
diff changeset
    56
064b249c5e3d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4132
diff changeset
    57
        excluded                a collection of words which are to be ignored
064b249c5e3d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4132
diff changeset
    58
064b249c5e3d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4132
diff changeset
    59
        unquoteAlgorithm        a block to remove quotes around words. 
064b249c5e3d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4132
diff changeset
    60
                                gets word as argument, delivers unquoted word
064b249c5e3d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4132
diff changeset
    61
064b249c5e3d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4132
diff changeset
    62
        keywordMappingAlgorithm 
064b249c5e3d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4132
diff changeset
    63
                                maps keywords; for example, can be used to map 'startsWith'
064b249c5e3d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4132
diff changeset
    64
                                to 'start', so they appear in the same section.
064b249c5e3d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4132
diff changeset
    65
                                Gets the word and the set-of-all-words as arguments,
064b249c5e3d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4132
diff changeset
    66
                                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
    67
                                
064b249c5e3d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4132
diff changeset
    68
        matchSorter             determines the order in which keywords are listed
064b249c5e3d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4132
diff changeset
    69
        
1375
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    70
    [author:]
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    71
        Claus Gittinger (cg@alan)
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    72
4126
4d3ec803fddf #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4125
diff changeset
    73
    [examples:]
4d3ec803fddf #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4125
diff changeset
    74
        see examples method
1375
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    75
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    76
    [see also:]
4125
d597206782cc #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4124
diff changeset
    77
        https://en.wikipedia.org/wiki/Key_Word_in_Context (english)
d597206782cc #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4124
diff changeset
    78
        https://de.wikipedia.org/wiki/Permutiertes_Register (german)
d597206782cc #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4124
diff changeset
    79
        
1375
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
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    83
examples
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    84
"
4126
4d3ec803fddf #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4125
diff changeset
    85
    building a kwic; print as kwic and kwoc
1375
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    86
                                                                [exBegin]
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    87
    |kwic|
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    88
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    89
    kwic := KeywordInContextIndexBuilder new.
4127
0f3c785bb689 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4126
diff changeset
    90
    kwic excluded:#('the' 'and' 'a' 'an' 'in').
1375
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    91
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    92
    kwic addLine:'bla bla bla' reference:1.
4126
4d3ec803fddf #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4125
diff changeset
    93
    kwic addLine:'foo, bar. baz' reference:2.
4d3ec803fddf #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4125
diff changeset
    94
    kwic addLine:'one two three' reference:3.
4d3ec803fddf #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4125
diff changeset
    95
    kwic addLine:'a cat and a dog' reference:4.
4d3ec803fddf #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4125
diff changeset
    96
    kwic addLine:'the man in the middle' reference:5.
4d3ec803fddf #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4125
diff changeset
    97
    kwic addLine:'the man with the dog' reference:6.
1375
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    98
4126
4d3ec803fddf #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4125
diff changeset
    99
    Transcript showCR:'Printed as KWIC:'.
1375
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   100
    kwic 
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   101
        entriesDo:[:word :left :right :ref |
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   102
            Transcript 
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   103
                show:((left contractTo:20) leftPaddedTo:20);
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   104
                space;
4124
2d4e83bec872 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
   105
                show:((word contractTo:10) leftPaddedTo:10) allBold;
1375
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   106
                space;
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   107
                show:((right contractTo:20) leftPaddedTo:20);
2536
8907a20de2dc changed: #examples
Claus Gittinger <cg@exept.de>
parents: 1375
diff changeset
   108
                space;
8907a20de2dc changed: #examples
Claus Gittinger <cg@exept.de>
parents: 1375
diff changeset
   109
                show:'['; show:ref; show:']';
1375
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   110
                cr    
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   111
        ].
4126
4d3ec803fddf #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4125
diff changeset
   112
4d3ec803fddf #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4125
diff changeset
   113
    Transcript cr.
4d3ec803fddf #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4125
diff changeset
   114
    Transcript showCR:'Printed as KWOC:'.
4d3ec803fddf #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4125
diff changeset
   115
    kwic 
4128
4cc1535fa7dc #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4127
diff changeset
   116
        entriesDo:[:word :left :right :ref :fullText :context |
4126
4d3ec803fddf #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4125
diff changeset
   117
            Transcript 
4d3ec803fddf #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4125
diff changeset
   118
                show:((word contractTo:10) paddedTo:10) allBold;
4d3ec803fddf #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4125
diff changeset
   119
                space;
4128
4cc1535fa7dc #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4127
diff changeset
   120
                show:((context contractTo:60) paddedTo:60);
4126
4d3ec803fddf #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4125
diff changeset
   121
                space;
4d3ec803fddf #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4125
diff changeset
   122
                show:'['; show:ref; show:']';
4d3ec803fddf #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4125
diff changeset
   123
                cr    
4d3ec803fddf #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4125
diff changeset
   124
        ].
1375
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   125
                                                                [exEnd]
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   126
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   127
3184
27271594c7d8 comments
Claus Gittinger <cg@exept.de>
parents: 2536
diff changeset
   128
  KWIC index over method selector components; build a little browser window:
1375
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   129
                                                                [exBegin]
3184
27271594c7d8 comments
Claus Gittinger <cg@exept.de>
parents: 2536
diff changeset
   130
    |kwic v s c list refs|
1375
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   131
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   132
    kwic := KeywordInContextIndexBuilder new.
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   133
    Smalltalk allClassesDo:[:eachClass |
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   134
        eachClass instAndClassSelectorsAndMethodsDo:[:sel :mthd |
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   135
            kwic addLine:sel reference:mthd.
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   136
        ]
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   137
    ].
3184
27271594c7d8 comments
Claus Gittinger <cg@exept.de>
parents: 2536
diff changeset
   138
27271594c7d8 comments
Claus Gittinger <cg@exept.de>
parents: 2536
diff changeset
   139
    v := StandardSystemView new.
27271594c7d8 comments
Claus Gittinger <cg@exept.de>
parents: 2536
diff changeset
   140
    v addComponent:(s := HVScrollableView for:SelectionInListView).
27271594c7d8 comments
Claus Gittinger <cg@exept.de>
parents: 2536
diff changeset
   141
    s origin:0.0@0.0 corner:1.0@0.5.
27271594c7d8 comments
Claus Gittinger <cg@exept.de>
parents: 2536
diff changeset
   142
    v addComponent:(c := HVScrollableView for:CodeView).
27271594c7d8 comments
Claus Gittinger <cg@exept.de>
parents: 2536
diff changeset
   143
    c origin:0.0@0.5 corner:1.0@1.0.
27271594c7d8 comments
Claus Gittinger <cg@exept.de>
parents: 2536
diff changeset
   144
27271594c7d8 comments
Claus Gittinger <cg@exept.de>
parents: 2536
diff changeset
   145
    refs := OrderedCollection new.
27271594c7d8 comments
Claus Gittinger <cg@exept.de>
parents: 2536
diff changeset
   146
    list := OrderedCollection new.
1375
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   147
    kwic 
3184
27271594c7d8 comments
Claus Gittinger <cg@exept.de>
parents: 2536
diff changeset
   148
        entriesDo:[:word :left :right :ref |
27271594c7d8 comments
Claus Gittinger <cg@exept.de>
parents: 2536
diff changeset
   149
            list add:(word,' ',left,' ',word allBold,' ',right,' (',ref mclass name,')').
27271594c7d8 comments
Claus Gittinger <cg@exept.de>
parents: 2536
diff changeset
   150
            refs add:ref].
27271594c7d8 comments
Claus Gittinger <cg@exept.de>
parents: 2536
diff changeset
   151
    s list:list.
27271594c7d8 comments
Claus Gittinger <cg@exept.de>
parents: 2536
diff changeset
   152
    s action:[:lNr | c contents:(refs at:lNr) source].
27271594c7d8 comments
Claus Gittinger <cg@exept.de>
parents: 2536
diff changeset
   153
    v open.
1375
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   154
                                                                [exEnd]
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   155
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   156
  KWIC index over method selector components, with word separation:
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   157
                                                                [exBegin]
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   158
    |kwic|
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   159
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   160
    kwic := KeywordInContextIndexBuilder forMethodSelectorIndex.
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   161
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   162
    Smalltalk allClassesDo:[:eachClass |
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   163
        eachClass instAndClassSelectorsAndMethodsDo:[:sel :mthd |
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   164
            kwic addLine:sel reference:mthd.
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   165
        ]
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   166
    ].
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   167
    kwic
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   168
                                                                [exEnd]
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   169
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   170
  KWIC index over method comments:
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   171
                                                                [exBegin]
4124
2d4e83bec872 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
   172
    |kwic v s c refs list|
1375
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   173
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   174
    kwic := KeywordInContextIndexBuilder forMethodComments.
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   175
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   176
    Smalltalk allClassesDo:[:eachClass |
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   177
        eachClass instAndClassSelectorsAndMethodsDo:[:sel :mthd |
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   178
            |comment|
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   179
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   180
            (sel == #documentation) ifTrue:[
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   181
                comment := mthd comment.
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   182
                comment notNil ifTrue:[
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   183
                    kwic addLine:comment reference:mthd mclass ignoreCase:true.
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   184
                ]
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   185
            ] ifFalse:[
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   186
                (sel ~~ #examples
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   187
                and:[ sel ~~ #copyright
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   188
                and:[ sel ~~ #version]]) ifTrue:[
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   189
                    comment := mthd comment.
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   190
                    comment notNil ifTrue:[
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   191
                        kwic addLine:comment reference:mthd ignoreCase:true.
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
        ]
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   196
    ].
4124
2d4e83bec872 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
   197
    kwic.
1375
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   198
                                                                [exEnd]
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   199
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   200
  KWIC index over class comments:
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   201
                                                                [exBegin]
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   202
    |kwic|
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   203
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   204
    kwic := KeywordInContextIndexBuilder forMethodComments.
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   205
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   206
    Smalltalk allClassesDo:[:eachClass |
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   207
        |mthd comment|
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   208
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   209
        mthd := eachClass theMetaclass compiledMethodAt:#documentation.
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   210
        mthd notNil ifTrue:[
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   211
            comment := mthd comment.
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   212
            comment notNil ifTrue:[
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   213
                kwic addLine:comment reference:eachClass theNonMetaclass ignoreCase:true.
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
    ].
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   217
    kwic
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   218
                                                                [exEnd]
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
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   222
!KeywordInContextIndexBuilder class methodsFor:'instance creation'!
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   223
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   224
forMethodComments
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   225
    "return an indexer for method comments"
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   226
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   227
    |sepChars sep kwic|
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   228
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   229
    sepChars := '.,;:_ !![]()''"#?<>|' , Character return, Character lf, Character tab.
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   230
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   231
    sep := [:lines | lines asString asCollectionOfSubstringsSeparatedByAny:sepChars].
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   232
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   233
    kwic := self new.
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   234
    kwic separatorAlgorithm:sep.
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   235
    kwic excluded:#('the' 'and' 'a' 'an' 'for' 'with' 'no').
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   236
    ^ kwic
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   237
!
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   238
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   239
forMethodSelectorIndex
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   240
    "return an indexer for method selector components, with word separation at case boundaries"
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   241
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   242
    |sep kwic sepUCWords|
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   243
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   244
    sepUCWords := [:word :keyWords| 
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   245
                    |s w c lastC last2C frag|
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   246
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   247
                    word asLowercase = word ifTrue:[
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   248
                        keyWords add:word.
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   249
                    ] ifFalse:[
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   250
                        s := word readStream.
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   251
                        w := '' writeStream.
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   252
                        [s atEnd] whileFalse:[
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   253
                            c := s next.
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   254
                            (c isUppercase) ifTrue:[
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   255
                                (lastC notNil and:[lastC isUppercase not]) ifTrue:[
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   256
                                    keyWords add:w contents.
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   257
                                    w := '' writeStream.
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   258
                                ].
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   259
                            ] ifFalse:[
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   260
                                (last2C notNil and:[last2C isUppercase and:[lastC isUppercase]]) ifTrue:[
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   261
                                    c isLetter ifTrue:[
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   262
                                        frag := w contents.
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   263
                                        w := '' writeStream.
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   264
                                        w nextPut:(frag last).
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   265
                                        keyWords add:(frag allButLast).
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   266
                                    ] ifFalse:[
4108
667d0bdaf609 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 3184
diff changeset
   267
                                       "/ frag := w contents.
667d0bdaf609 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 3184
diff changeset
   268
                                       "/ w := '' writeStream.
667d0bdaf609 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 3184
diff changeset
   269
                                       "/ keyWords add:frag.
1375
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
                            ].
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   273
                            w nextPut:c.
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   274
                            last2C := lastC.
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   275
                            lastC := c.
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
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   280
    sep := [:line | 
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   281
                |words keyWords|
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   282
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   283
                words := line asCollectionOfSubstringsSeparatedByAny:'.,;:_ '.
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   284
                keyWords := OrderedCollection new.
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   285
                words do:[:eachWord | sepUCWords value:eachWord value:keyWords].
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   286
                keyWords
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   287
            ].
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   288
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   289
    kwic := self new.
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   290
    kwic separatorAlgorithm:sep.
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   291
    ^ kwic
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   292
!
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   293
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   294
new
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   295
    ^ self basicNew initialize
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   296
! !
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   297
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   298
!KeywordInContextIndexBuilder methodsFor:'accessing'!
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   299
4128
4cc1535fa7dc #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4127
diff changeset
   300
excluded:aListOfExcludedWords
4cc1535fa7dc #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4127
diff changeset
   301
    "define words which are to be ignored.
4cc1535fa7dc #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4127
diff changeset
   302
     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
   303
     
4cc1535fa7dc #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4127
diff changeset
   304
    excluded := aListOfExcludedWords asSet.
1375
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   305
!
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   306
4130
2532973b50e6 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4129
diff changeset
   307
exclusionFilter:aBlock
2532973b50e6 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4129
diff changeset
   308
    "define an additional filter to exclude more complicated patterns.
2532973b50e6 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4129
diff changeset
   309
     This is invoked after filtering by the exclusion list.
2532973b50e6 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4129
diff changeset
   310
     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
   311
     
2532973b50e6 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4129
diff changeset
   312
    exclusionFilter := aBlock.
2532973b50e6 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4129
diff changeset
   313
!
2532973b50e6 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4129
diff changeset
   314
4187
064b249c5e3d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4132
diff changeset
   315
keywordMappingAlgorithm:aBlock
064b249c5e3d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4132
diff changeset
   316
    "define an additional mapper whih can map multiple different words to the same keword
064b249c5e3d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4132
diff changeset
   317
     it is given the word and the set of already known words as argument.
064b249c5e3d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4132
diff changeset
   318
     It may, for example figure out that a word with a long prefix is already in the
064b249c5e3d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4132
diff changeset
   319
     list and decide, that a new word should be brought into the same bucket.
064b249c5e3d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4132
diff changeset
   320
     For example, if 'starts' is already in the list, and 'startWith' is encountered."
064b249c5e3d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4132
diff changeset
   321
     
064b249c5e3d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4132
diff changeset
   322
    keywordMappingAlgorithm := aBlock.
064b249c5e3d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4132
diff changeset
   323
!
064b249c5e3d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4132
diff changeset
   324
4132
f87c478424c7 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4131
diff changeset
   325
matchSorter:aSortBlock
4187
064b249c5e3d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4132
diff changeset
   326
    "if set, matches will be enumerated in that sort order."
4132
f87c478424c7 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4131
diff changeset
   327
    
f87c478424c7 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4131
diff changeset
   328
    matchSorter := aSortBlock.
f87c478424c7 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4131
diff changeset
   329
!
f87c478424c7 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4131
diff changeset
   330
4128
4cc1535fa7dc #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4127
diff changeset
   331
separatorAlgorithm:aBlock
4cc1535fa7dc #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4127
diff changeset
   332
    "define the algorithm to split a given string into words.
4cc1535fa7dc #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4127
diff changeset
   333
     The default is to split at punctuation and whitespace
4cc1535fa7dc #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4127
diff changeset
   334
     (see #initialize)"
4cc1535fa7dc #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4127
diff changeset
   335
     
4cc1535fa7dc #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4127
diff changeset
   336
    separatorAlgorithm := aBlock.
4130
2532973b50e6 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4129
diff changeset
   337
!
2532973b50e6 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4129
diff changeset
   338
2532973b50e6 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4129
diff changeset
   339
unquoteAlgorithm:aBlock
2532973b50e6 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4129
diff changeset
   340
    "define the algorithm to unquote words.
2532973b50e6 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4129
diff changeset
   341
     The default is to unquote single and double quotes
2532973b50e6 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4129
diff changeset
   342
     (see #initialize)"
2532973b50e6 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4129
diff changeset
   343
     
2532973b50e6 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4129
diff changeset
   344
    unquoteAlgorithm := aBlock.
1375
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   345
! !
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   346
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   347
!KeywordInContextIndexBuilder methodsFor:'building'!
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   348
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   349
addLine:aLine reference:opaqueReference
3184
27271594c7d8 comments
Claus Gittinger <cg@exept.de>
parents: 2536
diff changeset
   350
    "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
   351
     The reference argument is stored as 'value' of the generated entries.
4cc1535fa7dc #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4127
diff changeset
   352
     It can be anything"
3184
27271594c7d8 comments
Claus Gittinger <cg@exept.de>
parents: 2536
diff changeset
   353
4128
4cc1535fa7dc #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4127
diff changeset
   354
    self addLine:aLine reference:opaqueReference ignoreCase:true
1375
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   355
!
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   356
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   357
addLine:aLine reference:opaqueReference ignoreCase:ignoreCase
4128
4cc1535fa7dc #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4127
diff changeset
   358
    "add a line to the kwic.
4cc1535fa7dc #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4127
diff changeset
   359
     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
   360
     is added for each word.
4cc1535fa7dc #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4127
diff changeset
   361
     The reference argument is stored as 'value' of the generated entries.
4cc1535fa7dc #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4127
diff changeset
   362
     It can be anything"
4cc1535fa7dc #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4127
diff changeset
   363
     
4187
064b249c5e3d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4132
diff changeset
   364
    (separatorAlgorithm value:aLine optionalArgument:keywordToLinesMapping) do:[:eachWord |
1375
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   365
        |set word|
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   366
4131
b4294ed81d7d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4130
diff changeset
   367
        (excluded includes:eachWord) ifFalse:[
b4294ed81d7d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4130
diff changeset
   368
            word := unquoteAlgorithm value:eachWord.
b4294ed81d7d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4130
diff changeset
   369
            ignoreCase ifTrue:[
b4294ed81d7d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4130
diff changeset
   370
                word := word asLowercase.
b4294ed81d7d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4130
diff changeset
   371
            ].
b4294ed81d7d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4130
diff changeset
   372
            (excluded includes:word) ifFalse:[
b4294ed81d7d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4130
diff changeset
   373
                (exclusionFilter isNil or:[ (exclusionFilter value:word) not]) ifTrue:[
b4294ed81d7d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4130
diff changeset
   374
                    set := keywordToLinesMapping at:word ifAbsentPut:[Set new].
b4294ed81d7d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4130
diff changeset
   375
                    set add:(aLine -> opaqueReference).
b4294ed81d7d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4130
diff changeset
   376
                ]
4130
2532973b50e6 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4129
diff changeset
   377
            ]
1375
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   378
        ]
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   379
    ].
4187
064b249c5e3d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4132
diff changeset
   380
    
064b249c5e3d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4132
diff changeset
   381
    keywordMappingAlgorithm notNil ifTrue:[
064b249c5e3d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4132
diff changeset
   382
        keywordToLinesMapping keys copy do:[:kw |
064b249c5e3d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4132
diff changeset
   383
            |mappedWord oldSet newSet|
064b249c5e3d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4132
diff changeset
   384
            
064b249c5e3d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4132
diff changeset
   385
            mappedWord := keywordToLinesMapping value:kw optionalArgument:keywordToLinesMapping.
064b249c5e3d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4132
diff changeset
   386
            mappedWord ~= kw ifTrue:[
064b249c5e3d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4132
diff changeset
   387
                oldSet := keywordToLinesMapping at:kw ifAbsent:[nil].
064b249c5e3d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4132
diff changeset
   388
                oldSet notNIl ifTrue:[
064b249c5e3d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4132
diff changeset
   389
                    newSet := keywordToLinesMapping at:mappedWord ifAbsentPut:[Set new].
064b249c5e3d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4132
diff changeset
   390
                    oldSet do:[:eachEntry |
064b249c5e3d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4132
diff changeset
   391
                        newSet add:eachEntry.
064b249c5e3d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4132
diff changeset
   392
                    ].
064b249c5e3d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4132
diff changeset
   393
                ]    
064b249c5e3d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4132
diff changeset
   394
            ]    
064b249c5e3d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4132
diff changeset
   395
        ].
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