KeywordInContextIndexBuilder.st
author Claus Gittinger <cg@exept.de>
Thu, 13 Oct 2016 14:57:17 +0200
changeset 4130 2532973b50e6
parent 4129 04b54f7b1a82
child 4131 b4294ed81d7d
permissions -rw-r--r--
#FEATURE by cg class: KeywordInContextIndexBuilder class definition added: #exclusionFilter: #unquoteAlgorithm: changed: #addLine:reference:ignoreCase: #initialize
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
2532973b50e6 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4129
diff changeset
    18
		unquoteAlgorithm exclusionFilter'
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
    To ignore fill words (such as 'and', 'the', 'in', etc.), define those with: #excluded:
0f3c785bb689 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4126
diff changeset
    49
    this is defined 
0f3c785bb689 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4126
diff changeset
    50
    
1375
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    51
    [author:]
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    52
        Claus Gittinger (cg@alan)
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    53
4126
4d3ec803fddf #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4125
diff changeset
    54
    [examples:]
4d3ec803fddf #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4125
diff changeset
    55
        see examples method
1375
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    56
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    57
    [see also:]
4125
d597206782cc #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4124
diff changeset
    58
        https://en.wikipedia.org/wiki/Key_Word_in_Context (english)
d597206782cc #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4124
diff changeset
    59
        https://de.wikipedia.org/wiki/Permutiertes_Register (german)
d597206782cc #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4124
diff changeset
    60
        
1375
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    61
"
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    62
!
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    63
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    64
examples
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    65
"
4126
4d3ec803fddf #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4125
diff changeset
    66
    building a kwic; print as kwic and kwoc
1375
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    67
                                                                [exBegin]
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    68
    |kwic|
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    69
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    70
    kwic := KeywordInContextIndexBuilder new.
4127
0f3c785bb689 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4126
diff changeset
    71
    kwic excluded:#('the' 'and' 'a' 'an' 'in').
1375
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    72
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    73
    kwic addLine:'bla bla bla' reference:1.
4126
4d3ec803fddf #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4125
diff changeset
    74
    kwic addLine:'foo, bar. baz' reference:2.
4d3ec803fddf #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4125
diff changeset
    75
    kwic addLine:'one two three' reference:3.
4d3ec803fddf #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4125
diff changeset
    76
    kwic addLine:'a cat and a dog' reference:4.
4d3ec803fddf #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4125
diff changeset
    77
    kwic addLine:'the man in the middle' reference:5.
4d3ec803fddf #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4125
diff changeset
    78
    kwic addLine:'the man with the dog' reference:6.
1375
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    79
4126
4d3ec803fddf #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4125
diff changeset
    80
    Transcript showCR:'Printed as KWIC:'.
1375
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    81
    kwic 
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    82
        entriesDo:[:word :left :right :ref |
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    83
            Transcript 
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    84
                show:((left contractTo:20) leftPaddedTo:20);
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    85
                space;
4124
2d4e83bec872 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
    86
                show:((word contractTo:10) leftPaddedTo:10) allBold;
1375
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    87
                space;
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    88
                show:((right contractTo:20) leftPaddedTo:20);
2536
8907a20de2dc changed: #examples
Claus Gittinger <cg@exept.de>
parents: 1375
diff changeset
    89
                space;
8907a20de2dc changed: #examples
Claus Gittinger <cg@exept.de>
parents: 1375
diff changeset
    90
                show:'['; show:ref; show:']';
1375
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    91
                cr    
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    92
        ].
4126
4d3ec803fddf #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4125
diff changeset
    93
4d3ec803fddf #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4125
diff changeset
    94
    Transcript cr.
4d3ec803fddf #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4125
diff changeset
    95
    Transcript showCR:'Printed as KWOC:'.
4d3ec803fddf #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4125
diff changeset
    96
    kwic 
4128
4cc1535fa7dc #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4127
diff changeset
    97
        entriesDo:[:word :left :right :ref :fullText :context |
4126
4d3ec803fddf #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4125
diff changeset
    98
            Transcript 
4d3ec803fddf #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4125
diff changeset
    99
                show:((word contractTo:10) paddedTo:10) allBold;
4d3ec803fddf #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4125
diff changeset
   100
                space;
4128
4cc1535fa7dc #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4127
diff changeset
   101
                show:((context contractTo:60) paddedTo:60);
4126
4d3ec803fddf #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4125
diff changeset
   102
                space;
4d3ec803fddf #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4125
diff changeset
   103
                show:'['; show:ref; show:']';
4d3ec803fddf #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4125
diff changeset
   104
                cr    
4d3ec803fddf #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4125
diff changeset
   105
        ].
1375
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   106
                                                                [exEnd]
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   107
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   108
3184
27271594c7d8 comments
Claus Gittinger <cg@exept.de>
parents: 2536
diff changeset
   109
  KWIC index over method selector components; build a little browser window:
1375
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   110
                                                                [exBegin]
3184
27271594c7d8 comments
Claus Gittinger <cg@exept.de>
parents: 2536
diff changeset
   111
    |kwic v s c list refs|
1375
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   112
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   113
    kwic := KeywordInContextIndexBuilder new.
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   114
    Smalltalk allClassesDo:[:eachClass |
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   115
        eachClass instAndClassSelectorsAndMethodsDo:[:sel :mthd |
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   116
            kwic addLine:sel reference:mthd.
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   117
        ]
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   118
    ].
3184
27271594c7d8 comments
Claus Gittinger <cg@exept.de>
parents: 2536
diff changeset
   119
27271594c7d8 comments
Claus Gittinger <cg@exept.de>
parents: 2536
diff changeset
   120
    v := StandardSystemView new.
27271594c7d8 comments
Claus Gittinger <cg@exept.de>
parents: 2536
diff changeset
   121
    v addComponent:(s := HVScrollableView for:SelectionInListView).
27271594c7d8 comments
Claus Gittinger <cg@exept.de>
parents: 2536
diff changeset
   122
    s origin:0.0@0.0 corner:1.0@0.5.
27271594c7d8 comments
Claus Gittinger <cg@exept.de>
parents: 2536
diff changeset
   123
    v addComponent:(c := HVScrollableView for:CodeView).
27271594c7d8 comments
Claus Gittinger <cg@exept.de>
parents: 2536
diff changeset
   124
    c origin:0.0@0.5 corner:1.0@1.0.
27271594c7d8 comments
Claus Gittinger <cg@exept.de>
parents: 2536
diff changeset
   125
27271594c7d8 comments
Claus Gittinger <cg@exept.de>
parents: 2536
diff changeset
   126
    refs := OrderedCollection new.
27271594c7d8 comments
Claus Gittinger <cg@exept.de>
parents: 2536
diff changeset
   127
    list := OrderedCollection new.
1375
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   128
    kwic 
3184
27271594c7d8 comments
Claus Gittinger <cg@exept.de>
parents: 2536
diff changeset
   129
        entriesDo:[:word :left :right :ref |
27271594c7d8 comments
Claus Gittinger <cg@exept.de>
parents: 2536
diff changeset
   130
            list add:(word,' ',left,' ',word allBold,' ',right,' (',ref mclass name,')').
27271594c7d8 comments
Claus Gittinger <cg@exept.de>
parents: 2536
diff changeset
   131
            refs add:ref].
27271594c7d8 comments
Claus Gittinger <cg@exept.de>
parents: 2536
diff changeset
   132
    s list:list.
27271594c7d8 comments
Claus Gittinger <cg@exept.de>
parents: 2536
diff changeset
   133
    s action:[:lNr | c contents:(refs at:lNr) source].
27271594c7d8 comments
Claus Gittinger <cg@exept.de>
parents: 2536
diff changeset
   134
    v open.
1375
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   135
                                                                [exEnd]
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   136
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   137
  KWIC index over method selector components, with word separation:
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   138
                                                                [exBegin]
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   139
    |kwic|
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   140
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   141
    kwic := KeywordInContextIndexBuilder forMethodSelectorIndex.
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   142
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   143
    Smalltalk allClassesDo:[:eachClass |
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   144
        eachClass instAndClassSelectorsAndMethodsDo:[:sel :mthd |
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   145
            kwic addLine:sel reference:mthd.
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   146
        ]
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   147
    ].
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   148
    kwic
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   149
                                                                [exEnd]
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   150
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   151
  KWIC index over method comments:
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   152
                                                                [exBegin]
4124
2d4e83bec872 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
   153
    |kwic v s c refs list|
1375
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 := KeywordInContextIndexBuilder forMethodComments.
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   156
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   157
    Smalltalk allClassesDo:[:eachClass |
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   158
        eachClass instAndClassSelectorsAndMethodsDo:[:sel :mthd |
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   159
            |comment|
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   160
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   161
            (sel == #documentation) ifTrue:[
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   162
                comment := mthd comment.
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   163
                comment notNil ifTrue:[
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   164
                    kwic addLine:comment reference:mthd mclass ignoreCase:true.
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   165
                ]
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   166
            ] ifFalse:[
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   167
                (sel ~~ #examples
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   168
                and:[ sel ~~ #copyright
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   169
                and:[ sel ~~ #version]]) ifTrue:[
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   170
                    comment := mthd comment.
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   171
                    comment notNil ifTrue:[
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   172
                        kwic addLine:comment reference:mthd ignoreCase:true.
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   173
                    ]
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   174
                ]
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   175
            ]
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   176
        ]
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   177
    ].
4124
2d4e83bec872 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4108
diff changeset
   178
    kwic.
1375
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   179
                                                                [exEnd]
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   180
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   181
  KWIC index over class comments:
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   182
                                                                [exBegin]
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   183
    |kwic|
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   184
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   185
    kwic := KeywordInContextIndexBuilder forMethodComments.
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   186
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   187
    Smalltalk allClassesDo:[:eachClass |
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   188
        |mthd comment|
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   189
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   190
        mthd := eachClass theMetaclass compiledMethodAt:#documentation.
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   191
        mthd notNil ifTrue:[
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   192
            comment := mthd comment.
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   193
            comment notNil ifTrue:[
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   194
                kwic addLine:comment reference:eachClass theNonMetaclass ignoreCase:true.
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   195
            ]
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   196
        ]
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   197
    ].
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   198
    kwic
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   199
                                                                [exEnd]
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   200
"
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   201
! !
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   202
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   203
!KeywordInContextIndexBuilder class methodsFor:'instance creation'!
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   204
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   205
forMethodComments
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   206
    "return an indexer for method comments"
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   207
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   208
    |sepChars sep kwic|
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   209
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   210
    sepChars := '.,;:_ !![]()''"#?<>|' , Character return, Character lf, Character tab.
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   211
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   212
    sep := [:lines | lines asString asCollectionOfSubstringsSeparatedByAny:sepChars].
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   213
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   214
    kwic := self new.
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   215
    kwic separatorAlgorithm:sep.
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   216
    kwic excluded:#('the' 'and' 'a' 'an' 'for' 'with' 'no').
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
!
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   219
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   220
forMethodSelectorIndex
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   221
    "return an indexer for method selector components, with word separation at case boundaries"
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   222
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   223
    |sep kwic sepUCWords|
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   224
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   225
    sepUCWords := [:word :keyWords| 
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   226
                    |s w c lastC last2C frag|
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   227
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   228
                    word asLowercase = word ifTrue:[
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   229
                        keyWords add:word.
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   230
                    ] ifFalse:[
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   231
                        s := word readStream.
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   232
                        w := '' writeStream.
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   233
                        [s atEnd] whileFalse:[
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   234
                            c := s next.
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   235
                            (c isUppercase) ifTrue:[
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   236
                                (lastC notNil and:[lastC isUppercase not]) ifTrue:[
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   237
                                    keyWords add:w contents.
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   238
                                    w := '' writeStream.
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   239
                                ].
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   240
                            ] ifFalse:[
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   241
                                (last2C notNil and:[last2C isUppercase and:[lastC isUppercase]]) ifTrue:[
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   242
                                    c isLetter ifTrue:[
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   243
                                        frag := w contents.
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   244
                                        w := '' writeStream.
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   245
                                        w nextPut:(frag last).
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   246
                                        keyWords add:(frag allButLast).
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   247
                                    ] ifFalse:[
4108
667d0bdaf609 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 3184
diff changeset
   248
                                       "/ frag := w contents.
667d0bdaf609 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 3184
diff changeset
   249
                                       "/ w := '' writeStream.
667d0bdaf609 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 3184
diff changeset
   250
                                       "/ keyWords add:frag.
1375
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   251
                                    ].
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   252
                                ].
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   253
                            ].
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   254
                            w nextPut:c.
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   255
                            last2C := lastC.
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   256
                            lastC := c.
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   257
                        ].
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   258
                    ].
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   259
                  ].
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   260
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   261
    sep := [:line | 
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   262
                |words keyWords|
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   263
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   264
                words := line asCollectionOfSubstringsSeparatedByAny:'.,;:_ '.
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   265
                keyWords := OrderedCollection new.
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   266
                words do:[:eachWord | sepUCWords value:eachWord value:keyWords].
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   267
                keyWords
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   268
            ].
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   269
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   270
    kwic := self new.
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   271
    kwic separatorAlgorithm:sep.
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   272
    ^ kwic
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   273
!
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   274
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   275
new
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   276
    ^ self basicNew initialize
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
!KeywordInContextIndexBuilder methodsFor:'accessing'!
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   280
4128
4cc1535fa7dc #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4127
diff changeset
   281
excluded:aListOfExcludedWords
4cc1535fa7dc #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4127
diff changeset
   282
    "define words which are to be ignored.
4cc1535fa7dc #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4127
diff changeset
   283
     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
   284
     
4cc1535fa7dc #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4127
diff changeset
   285
    excluded := aListOfExcludedWords asSet.
1375
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   286
!
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   287
4130
2532973b50e6 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4129
diff changeset
   288
exclusionFilter:aBlock
2532973b50e6 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4129
diff changeset
   289
    "define an additional filter to exclude more complicated patterns.
2532973b50e6 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4129
diff changeset
   290
     This is invoked after filtering by the exclusion list.
2532973b50e6 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4129
diff changeset
   291
     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
   292
     
2532973b50e6 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4129
diff changeset
   293
    exclusionFilter := aBlock.
2532973b50e6 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4129
diff changeset
   294
!
2532973b50e6 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4129
diff changeset
   295
4128
4cc1535fa7dc #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4127
diff changeset
   296
separatorAlgorithm:aBlock
4cc1535fa7dc #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4127
diff changeset
   297
    "define the algorithm to split a given string into words.
4cc1535fa7dc #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4127
diff changeset
   298
     The default is to split at punctuation and whitespace
4cc1535fa7dc #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4127
diff changeset
   299
     (see #initialize)"
4cc1535fa7dc #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4127
diff changeset
   300
     
4cc1535fa7dc #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4127
diff changeset
   301
    separatorAlgorithm := aBlock.
4130
2532973b50e6 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4129
diff changeset
   302
!
2532973b50e6 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4129
diff changeset
   303
2532973b50e6 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4129
diff changeset
   304
unquoteAlgorithm:aBlock
2532973b50e6 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4129
diff changeset
   305
    "define the algorithm to unquote words.
2532973b50e6 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4129
diff changeset
   306
     The default is to unquote single and double quotes
2532973b50e6 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4129
diff changeset
   307
     (see #initialize)"
2532973b50e6 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4129
diff changeset
   308
     
2532973b50e6 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4129
diff changeset
   309
    unquoteAlgorithm := aBlock.
1375
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   310
! !
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   311
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   312
!KeywordInContextIndexBuilder methodsFor:'building'!
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   313
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   314
addLine:aLine reference:opaqueReference
3184
27271594c7d8 comments
Claus Gittinger <cg@exept.de>
parents: 2536
diff changeset
   315
    "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
   316
     The reference argument is stored as 'value' of the generated entries.
4cc1535fa7dc #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4127
diff changeset
   317
     It can be anything"
3184
27271594c7d8 comments
Claus Gittinger <cg@exept.de>
parents: 2536
diff changeset
   318
4128
4cc1535fa7dc #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4127
diff changeset
   319
    self addLine:aLine reference:opaqueReference ignoreCase:true
1375
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   320
!
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   321
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   322
addLine:aLine reference:opaqueReference ignoreCase:ignoreCase
4128
4cc1535fa7dc #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4127
diff changeset
   323
    "add a line to the kwic.
4cc1535fa7dc #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4127
diff changeset
   324
     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
   325
     is added for each word.
4cc1535fa7dc #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4127
diff changeset
   326
     The reference argument is stored as 'value' of the generated entries.
4cc1535fa7dc #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4127
diff changeset
   327
     It can be anything"
4cc1535fa7dc #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4127
diff changeset
   328
     
1375
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   329
    (separatorAlgorithm value:aLine) do:[:eachWord |
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   330
        |set word|
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   331
4130
2532973b50e6 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4129
diff changeset
   332
        word := unquoteAlgorithm value:eachWord.
1375
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   333
        ignoreCase ifTrue:[
4130
2532973b50e6 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4129
diff changeset
   334
            word := word asLowercase.
1375
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   335
        ].
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   336
        (excluded includes:word) ifFalse:[
4130
2532973b50e6 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4129
diff changeset
   337
            (exclusionFilter isNil or:[ (exclusionFilter value:word) not]) ifTrue:[
2532973b50e6 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4129
diff changeset
   338
                set := keywordToLinesMapping at:word ifAbsentPut:[Set new].
2532973b50e6 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4129
diff changeset
   339
                set add:(aLine -> opaqueReference).
2532973b50e6 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4129
diff changeset
   340
            ]
1375
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   341
        ]
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   342
    ].
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   343
! !
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   344
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   345
!KeywordInContextIndexBuilder methodsFor:'enumerating'!
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   346
4128
4cc1535fa7dc #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4127
diff changeset
   347
entriesDo:aFourToSixArgBlock
4126
4d3ec803fddf #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4125
diff changeset
   348
    "evaluate the argument, for each entry.
4d3ec803fddf #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4125
diff changeset
   349
     If it is a 4-arg block, it is called with:
4d3ec803fddf #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4125
diff changeset
   350
        kwic-word, 
4d3ec803fddf #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4125
diff changeset
   351
        left-text, 
4d3ec803fddf #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4125
diff changeset
   352
        right text 
4d3ec803fddf #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4125
diff changeset
   353
        and reference
4d3ec803fddf #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4125
diff changeset
   354
     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
   355
     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
   356
     (stupid, but done for backward compatibility)"
3184
27271594c7d8 comments
Claus Gittinger <cg@exept.de>
parents: 2536
diff changeset
   357
4128
4cc1535fa7dc #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4127
diff changeset
   358
    |fourArgBlock|
4126
4d3ec803fddf #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4125
diff changeset
   359
4128
4cc1535fa7dc #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4127
diff changeset
   360
    aFourToSixArgBlock numArgs == 4 ifTrue:[
4cc1535fa7dc #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4127
diff changeset
   361
        fourArgBlock := aFourToSixArgBlock 
4126
4d3ec803fddf #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4125
diff changeset
   362
    ].    
1375
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   363
    keywordToLinesMapping keys asSortedCollection do:[:eachKey |
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   364
        |setOfMatches lcKey|
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   365
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   366
        setOfMatches := keywordToLinesMapping at:eachKey.
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   367
        lcKey := eachKey asLowercase.
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   368
        setOfMatches do:[:eachAssoc |
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   369
            |text ref lines idx lIdx context left right word prevLine nextLine|
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   370
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   371
            text := eachAssoc key.
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   372
            ref := eachAssoc value.
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   373
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   374
            lines := text asCollectionOfLines.
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   375
            idx := lines findFirst:[:line | line asLowercase includesString:lcKey].
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   376
            idx ~~ 0 ifTrue:[
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   377
                context := lines at:idx.
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   378
                idx > 1 ifTrue:[
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   379
                    prevLine := (lines at:idx-1).
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   380
                    context := prevLine , ' ' , context.
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   381
                ].
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   382
                idx < lines size ifTrue:[
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   383
                    nextLine := (lines at:idx+1).
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   384
                    context :=  context , ' ' , nextLine.
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   385
                ].
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   386
                lIdx := context asLowercase findString:lcKey.
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   387
                left := (context copyTo:lIdx - 1) withoutSeparators.
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   388
                right := (context copyFrom:lIdx + lcKey size) withoutSeparators.
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   389
                word := (context copyFrom:lIdx to:lIdx + lcKey size - 1) withoutSeparators.
4126
4d3ec803fddf #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4125
diff changeset
   390
                fourArgBlock notNil ifTrue:[
4d3ec803fddf #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4125
diff changeset
   391
                    fourArgBlock value:word value:left value:right value:ref.
4d3ec803fddf #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4125
diff changeset
   392
                ] ifFalse:[
4128
4cc1535fa7dc #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4127
diff changeset
   393
                    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
   394
                ].    
1375
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   395
            ].
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   396
        ]
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
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   400
!KeywordInContextIndexBuilder methodsFor:'initialization'!
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   401
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   402
initialize
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   403
    keywordToLinesMapping := Dictionary new.
4129
04b54f7b1a82 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4128
diff changeset
   404
    self excluded:(Set new).
4130
2532973b50e6 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4129
diff changeset
   405
    self exclusionFilter:nil.
4129
04b54f7b1a82 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4128
diff changeset
   406
    self separatorAlgorithm:[:line | line asCollectionOfSubstringsSeparatedByAny:' .:,;-'].
4130
2532973b50e6 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4129
diff changeset
   407
    self unquoteAlgorithm:[:word | (word unquote:$") unquote:$' ].
1375
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   408
! !
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   409
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   410
!KeywordInContextIndexBuilder class methodsFor:'documentation'!
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   411
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   412
version
4108
667d0bdaf609 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 3184
diff changeset
   413
    ^ '$Header$'
2536
8907a20de2dc changed: #examples
Claus Gittinger <cg@exept.de>
parents: 1375
diff changeset
   414
!
8907a20de2dc changed: #examples
Claus Gittinger <cg@exept.de>
parents: 1375
diff changeset
   415
8907a20de2dc changed: #examples
Claus Gittinger <cg@exept.de>
parents: 1375
diff changeset
   416
version_CVS
4108
667d0bdaf609 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 3184
diff changeset
   417
    ^ '$Header$'
1375
e034d3e027f2 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   418
! !
3184
27271594c7d8 comments
Claus Gittinger <cg@exept.de>
parents: 2536
diff changeset
   419