FuzzyMatcher.st
author Claus Gittinger <cg@exept.de>
Sat, 02 May 2020 21:40:13 +0200
changeset 5476 7355a4b11cb6
parent 5376 61b8a719febd
permissions -rw-r--r--
#FEATURE by cg class: Socket class added: #newTCPclientToHost:port:domain:domainOrder:withTimeout: changed: #newTCPclientToHost:port:domain:withTimeout:
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
5376
61b8a719febd #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 4493
diff changeset
     1
"{ Encoding: utf8 }"
61b8a719febd #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 4493
diff changeset
     2
61b8a719febd #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 4493
diff changeset
     3
"
61b8a719febd #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 4493
diff changeset
     4
 COPYRIGHT (c) 2018 by eXept Software AG
61b8a719febd #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 4493
diff changeset
     5
              All Rights Reserved
61b8a719febd #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 4493
diff changeset
     6
61b8a719febd #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 4493
diff changeset
     7
 This software is furnished under a license and may be used
61b8a719febd #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 4493
diff changeset
     8
 only in accordance with the terms of that license and with the
61b8a719febd #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 4493
diff changeset
     9
 inclusion of the above copyright notice.   This software may not
61b8a719febd #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 4493
diff changeset
    10
 be provided or otherwise made available to, or used by, any
61b8a719febd #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 4493
diff changeset
    11
 other person.  No title to or ownership of the software is
61b8a719febd #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 4493
diff changeset
    12
 hereby transferred.
61b8a719febd #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 4493
diff changeset
    13
"
4459
cfbde361fe34 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    14
"{ Package: 'stx:libbasic2' }"
cfbde361fe34 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    15
cfbde361fe34 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    16
"{ NameSpace: Smalltalk }"
cfbde361fe34 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    17
cfbde361fe34 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    18
Object subclass:#FuzzyMatcher
cfbde361fe34 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    19
	instanceVariableNames:'pattern lowercasePattern indexes'
cfbde361fe34 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    20
	classVariableNames:''
cfbde361fe34 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    21
	poolDictionaries:''
cfbde361fe34 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    22
	category:'Collections-Text-Support'
cfbde361fe34 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    23
!
cfbde361fe34 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    24
cfbde361fe34 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    25
!FuzzyMatcher class methodsFor:'documentation'!
cfbde361fe34 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    26
5376
61b8a719febd #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 4493
diff changeset
    27
copyright
61b8a719febd #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 4493
diff changeset
    28
"
61b8a719febd #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 4493
diff changeset
    29
 COPYRIGHT (c) 2018 by eXept Software AG
61b8a719febd #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 4493
diff changeset
    30
              All Rights Reserved
61b8a719febd #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 4493
diff changeset
    31
61b8a719febd #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 4493
diff changeset
    32
 This software is furnished under a license and may be used
61b8a719febd #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 4493
diff changeset
    33
 only in accordance with the terms of that license and with the
61b8a719febd #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 4493
diff changeset
    34
 inclusion of the above copyright notice.   This software may not
61b8a719febd #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 4493
diff changeset
    35
 be provided or otherwise made available to, or used by, any
61b8a719febd #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 4493
diff changeset
    36
 other person.  No title to or ownership of the software is
61b8a719febd #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 4493
diff changeset
    37
 hereby transferred.
61b8a719febd #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 4493
diff changeset
    38
"
61b8a719febd #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 4493
diff changeset
    39
!
61b8a719febd #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 4493
diff changeset
    40
4459
cfbde361fe34 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    41
documentation
cfbde361fe34 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    42
"
4474
98208d107b52 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4470
diff changeset
    43
    FuzzyMatcher is an approximate string matching algorithm that can determine if a string includes a given pattern.
4459
cfbde361fe34 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    44
    For example, the string 'axby' matches both the pattern 'ab' and, 'ay', but not 'ba'. 
4492
05def04efc34 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4477
diff changeset
    45
    I.e. it matches if the searched string contains a sequence of chars, probably intermixed by other chars,
05def04efc34 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4477
diff changeset
    46
    which matches the given search pattern or part of it.
05def04efc34 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4477
diff changeset
    47
    
4459
cfbde361fe34 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    48
    The algorithm is based on lib_fts[1], and includes an optional scoring algorithm 
cfbde361fe34 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    49
    that can be used to sort all the matches based on their similarity to the pattern.
4492
05def04efc34 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4477
diff changeset
    50
    It is used (among others) in the sublime text editor.
4493
3961346f8256 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4492
diff changeset
    51
3961346f8256 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4492
diff changeset
    52
    [caveat:]
3961346f8256 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4492
diff changeset
    53
        although this works great for class searches,
3961346f8256 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4492
diff changeset
    54
        it is strange that 'dabc' scores lower against 'abc' than 'adbc'
3961346f8256 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4492
diff changeset
    55
        (dabc has a longer common subsequence without interruptions...)
3961346f8256 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4492
diff changeset
    56
4459
cfbde361fe34 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    57
    [see also:]
cfbde361fe34 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    58
        https://blog.forrestthewoods.com/reverse-engineering-sublime-text-s-fuzzy-match-4cffeed33fdb
cfbde361fe34 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    59
        https://github.com/forrestthewoods/lib_fts
cfbde361fe34 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    60
cfbde361fe34 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    61
"
4468
4da827f70608 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4459
diff changeset
    62
!
4da827f70608 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4459
diff changeset
    63
4da827f70608 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4459
diff changeset
    64
example
4da827f70608 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4459
diff changeset
    65
"
4493
3961346f8256 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4492
diff changeset
    66
    |matcher|
3961346f8256 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4492
diff changeset
    67
    
3961346f8256 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4492
diff changeset
    68
    matcher := FuzzyMatcher pattern:'abc'.
3961346f8256 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4492
diff changeset
    69
    matcher 
3961346f8256 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4492
diff changeset
    70
        match:'somearbitrarysequence'   
3961346f8256 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4492
diff changeset
    71
        ifScored: [:score | Transcript show:('''somearbitrarysequence'' scores '); showCR:score].
3961346f8256 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4492
diff changeset
    72
3961346f8256 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4492
diff changeset
    73
    matcher 
3961346f8256 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4492
diff changeset
    74
        match:'someabcd'   
3961346f8256 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4492
diff changeset
    75
        ifScored: [:score | Transcript show:('''someabcd'' scores '); showCR:score].
3961346f8256 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4492
diff changeset
    76
3961346f8256 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4492
diff changeset
    77
    matcher 
3961346f8256 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4492
diff changeset
    78
        match:'abcd'   
3961346f8256 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4492
diff changeset
    79
        ifScored: [:score | Transcript show:('''abcd'' scores '); showCR:score].
3961346f8256 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4492
diff changeset
    80
3961346f8256 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4492
diff changeset
    81
    matcher 
3961346f8256 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4492
diff changeset
    82
        match:'dabc'   
3961346f8256 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4492
diff changeset
    83
        ifScored: [:score | Transcript show:('''dabc'' scores '); showCR:score].
3961346f8256 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4492
diff changeset
    84
3961346f8256 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4492
diff changeset
    85
    matcher 
3961346f8256 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4492
diff changeset
    86
        match:'adbc'   
3961346f8256 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4492
diff changeset
    87
        ifScored: [:score | Transcript show:('''adbc'' scores '); showCR:score].
3961346f8256 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4492
diff changeset
    88
3961346f8256 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4492
diff changeset
    89
    matcher 
3961346f8256 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4492
diff changeset
    90
        match:'abc'   
3961346f8256 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4492
diff changeset
    91
        ifScored: [:score | Transcript show:('''abc'' scores '); showCR:score].
3961346f8256 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4492
diff changeset
    92
3961346f8256 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4492
diff changeset
    93
    
4468
4da827f70608 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4459
diff changeset
    94
    |top lv list field patternHolder names|
4da827f70608 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4459
diff changeset
    95
4da827f70608 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4459
diff changeset
    96
    patternHolder := '' asValue.
4da827f70608 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4459
diff changeset
    97
    list := List new.
4da827f70608 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4459
diff changeset
    98
    
4da827f70608 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4459
diff changeset
    99
    top := StandardSystemView new.
4da827f70608 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4459
diff changeset
   100
    lv := ListView origin:(0.0@30) corner:(1.0@1.0) in:top.
4da827f70608 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4459
diff changeset
   101
    lv model:list.
4da827f70608 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4459
diff changeset
   102
4da827f70608 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4459
diff changeset
   103
    field := EditField origin:(0.0@0.0) corner:(1.0@30) in:top.
4da827f70608 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4459
diff changeset
   104
    field model:patternHolder.
4da827f70608 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4459
diff changeset
   105
    field immediateAccept:true.
4da827f70608 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4459
diff changeset
   106
4da827f70608 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4459
diff changeset
   107
    names := Smalltalk allClasses collect:#name.
4da827f70608 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4459
diff changeset
   108
4da827f70608 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4459
diff changeset
   109
    patternHolder 
4da827f70608 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4459
diff changeset
   110
        onChangeEvaluate:[
4da827f70608 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4459
diff changeset
   111
            |matcher pattern matches|
4da827f70608 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4459
diff changeset
   112
4da827f70608 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4459
diff changeset
   113
            pattern := patternHolder value.
4da827f70608 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4459
diff changeset
   114
            pattern notEmpty ifTrue:[
4da827f70608 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4459
diff changeset
   115
                matcher := FuzzyMatcher pattern:pattern.
4da827f70608 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4459
diff changeset
   116
                
4da827f70608 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4459
diff changeset
   117
                matches := OrderedCollection new.
4da827f70608 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4459
diff changeset
   118
4da827f70608 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4459
diff changeset
   119
                names do:[:eachClassName | 
4da827f70608 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4459
diff changeset
   120
                    matcher 
4da827f70608 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4459
diff changeset
   121
                        match:eachClassName
4da827f70608 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4459
diff changeset
   122
                        ifScored: [ :score | matches add: eachClassName -> score ] 
4da827f70608 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4459
diff changeset
   123
                ].
4470
5825ccc0dabf #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4469
diff changeset
   124
                matches sort:[:a :b |
5825ccc0dabf #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4469
diff changeset
   125
                        a value < b value
5825ccc0dabf #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4469
diff changeset
   126
                        or:[ a value = b value and:[ a key > b key]]
5825ccc0dabf #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4469
diff changeset
   127
                ].
4468
4da827f70608 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4459
diff changeset
   128
4da827f70608 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4459
diff changeset
   129
                list removeAll.
4da827f70608 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4459
diff changeset
   130
                list addAllReversed:(matches 
4da827f70608 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4459
diff changeset
   131
                                collect:[:nameScoreAssoc | 
4da827f70608 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4459
diff changeset
   132
                                    '[%1] %2' bindWith:nameScoreAssoc value with:nameScoreAssoc key])
4da827f70608 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4459
diff changeset
   133
            ].    
4da827f70608 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4459
diff changeset
   134
        ].    
4da827f70608 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4459
diff changeset
   135
    top open.
4da827f70608 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4459
diff changeset
   136
    patternHolder value:'mph'.
4da827f70608 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4459
diff changeset
   137
"
4459
cfbde361fe34 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   138
! !
cfbde361fe34 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   139
cfbde361fe34 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   140
!FuzzyMatcher class methodsFor:'instance creation'!
cfbde361fe34 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   141
cfbde361fe34 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   142
new
cfbde361fe34 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   143
    "return an initialized instance"
cfbde361fe34 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   144
cfbde361fe34 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   145
    ^ self basicNew initialize.
4475
2e19c5a7452a #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4474
diff changeset
   146
!
4459
cfbde361fe34 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   147
cfbde361fe34 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   148
pattern: aString
4476
65686f14ebf4 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 4475
diff changeset
   149
    ^ self new pattern: aString
65686f14ebf4 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 4475
diff changeset
   150
65686f14ebf4 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 4475
diff changeset
   151
    "
65686f14ebf4 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 4475
diff changeset
   152
     (self pattern:'mrp') matches:'ButtonMorph'
4493
3961346f8256 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4492
diff changeset
   153
     (self pattern:'mrp') matches:'ButtonMorh'
3961346f8256 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4492
diff changeset
   154
3961346f8256 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4492
diff changeset
   155
     (self pattern:'mrp') matches:'ButtonMorph'
3961346f8256 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4492
diff changeset
   156
     (self pattern:'mrp') matches:'ButtonMorh'
4476
65686f14ebf4 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 4475
diff changeset
   157
    "
65686f14ebf4 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 4475
diff changeset
   158
4493
3961346f8256 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4492
diff changeset
   159
    "Modified (comment): / 02-08-2017 / 15:57:07 / cg"
4459
cfbde361fe34 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   160
! !
cfbde361fe34 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   161
cfbde361fe34 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   162
!FuzzyMatcher class methodsFor:'utilities api'!
cfbde361fe34 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   163
cfbde361fe34 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   164
allMatching: aPattern in: aCollection
4493
3961346f8256 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4492
diff changeset
   165
    "Assumes that the collection is a collection of Strings;
3961346f8256 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4492
diff changeset
   166
     return all those which match"
4474
98208d107b52 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4470
diff changeset
   167
98208d107b52 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4470
diff changeset
   168
    | matcher |
4459
cfbde361fe34 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   169
4474
98208d107b52 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4470
diff changeset
   170
    matcher := self pattern: aPattern.
98208d107b52 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4470
diff changeset
   171
    ^ aCollection select: [ :each | matcher matches: each ]
4459
cfbde361fe34 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   172
4474
98208d107b52 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4470
diff changeset
   173
    "
98208d107b52 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4470
diff changeset
   174
     self 
98208d107b52 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4470
diff changeset
   175
        allMatching:'clu' 
98208d107b52 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4470
diff changeset
   176
        in:(Smalltalk allClasses collect:#name)
98208d107b52 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4470
diff changeset
   177
    "
4459
cfbde361fe34 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   178
4493
3961346f8256 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4492
diff changeset
   179
    "Modified (comment): / 02-08-2017 / 16:02:44 / cg"
4459
cfbde361fe34 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   180
!
cfbde361fe34 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   181
cfbde361fe34 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   182
allMatching: aPattern in: aCollection by: aBlockReturningString
4475
2e19c5a7452a #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4474
diff changeset
   183
    "selects matching elements from aCollection.
2e19c5a7452a #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4474
diff changeset
   184
     aBlockReturningString is applied to elements to get the string representation
2e19c5a7452a #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4474
diff changeset
   185
     (can be used eg. to sort classes)"
2e19c5a7452a #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4474
diff changeset
   186
     
4474
98208d107b52 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4470
diff changeset
   187
    | matcher |
98208d107b52 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4470
diff changeset
   188
98208d107b52 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4470
diff changeset
   189
    matcher := self pattern: aPattern.
98208d107b52 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4470
diff changeset
   190
98208d107b52 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4470
diff changeset
   191
    ^ aCollection select: [ :each | matcher matches: (aBlockReturningString value: each) ]
4459
cfbde361fe34 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   192
4474
98208d107b52 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4470
diff changeset
   193
        "
98208d107b52 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4470
diff changeset
   194
         self 
98208d107b52 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4470
diff changeset
   195
            allMatching:'clu' 
98208d107b52 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4470
diff changeset
   196
            in:(Smalltalk allClasses)
98208d107b52 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4470
diff changeset
   197
            by:[:cls | cls name]
98208d107b52 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4470
diff changeset
   198
        "
98208d107b52 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4470
diff changeset
   199
        "
98208d107b52 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4470
diff changeset
   200
         self 
98208d107b52 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4470
diff changeset
   201
            allMatching:'clu' 
98208d107b52 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4470
diff changeset
   202
            in:(Smalltalk allClasses)
98208d107b52 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4470
diff changeset
   203
            by:#name
98208d107b52 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4470
diff changeset
   204
        "
98208d107b52 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4470
diff changeset
   205
4475
2e19c5a7452a #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4474
diff changeset
   206
    "Modified (comment): / 14-07-2017 / 12:21:40 / cg"
4459
cfbde361fe34 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   207
!
cfbde361fe34 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   208
cfbde361fe34 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   209
allSortedByScoreMatching: aPattern in: aCollection
4475
2e19c5a7452a #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4474
diff changeset
   210
    "Assumes that the collection is a collection of Strings;
2e19c5a7452a #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4474
diff changeset
   211
     returns matching strings sorted by score (level of similarity)"
4474
98208d107b52 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4470
diff changeset
   212
98208d107b52 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4470
diff changeset
   213
    ^ self allSortedByScoreMatching: aPattern in: aCollection by: [ :each | each ]
98208d107b52 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4470
diff changeset
   214
98208d107b52 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4470
diff changeset
   215
    "
98208d107b52 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4470
diff changeset
   216
     self 
98208d107b52 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4470
diff changeset
   217
        allSortedByScoreMatching:'clu' 
98208d107b52 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4470
diff changeset
   218
        in:(Smalltalk allClasses collect:#name)
98208d107b52 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4470
diff changeset
   219
    "
98208d107b52 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4470
diff changeset
   220
    "
98208d107b52 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4470
diff changeset
   221
     self 
98208d107b52 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4470
diff changeset
   222
        allSortedByScoreMatching:'nary' 
98208d107b52 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4470
diff changeset
   223
        in:(Smalltalk allClasses collect:#name)
98208d107b52 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4470
diff changeset
   224
    "
98208d107b52 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4470
diff changeset
   225
4475
2e19c5a7452a #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4474
diff changeset
   226
    "Modified (comment): / 14-07-2017 / 12:22:14 / cg"
4459
cfbde361fe34 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   227
!
cfbde361fe34 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   228
cfbde361fe34 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   229
allSortedByScoreMatching: aPattern in: aCollection by: aBlockReturningString
4475
2e19c5a7452a #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4474
diff changeset
   230
    "selects matching elements from aCollection.
2e19c5a7452a #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4474
diff changeset
   231
     aBlockReturningString is applied to elements to get the string representation.
2e19c5a7452a #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4474
diff changeset
   232
     Returns them sorted by score (i.e. similarity).
2e19c5a7452a #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4474
diff changeset
   233
     (can be used eg. to sort classes)"
4474
98208d107b52 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4470
diff changeset
   234
4475
2e19c5a7452a #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4474
diff changeset
   235
    | matchesAndScores |
4474
98208d107b52 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4470
diff changeset
   236
4475
2e19c5a7452a #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4474
diff changeset
   237
    matchesAndScores := self allWithScoresSortedByScoreMatching: aPattern in: aCollection by: aBlockReturningString.
2e19c5a7452a #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4474
diff changeset
   238
    ^ matchesAndScores collect: [ :each | each value ]
4474
98208d107b52 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4470
diff changeset
   239
4475
2e19c5a7452a #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4474
diff changeset
   240
    "
2e19c5a7452a #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4474
diff changeset
   241
     self 
2e19c5a7452a #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4474
diff changeset
   242
        allSortedByScoreMatching:'' 
2e19c5a7452a #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4474
diff changeset
   243
        in:(Smalltalk allClasses)
2e19c5a7452a #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4474
diff changeset
   244
        by:[:cls | cls name]
2e19c5a7452a #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4474
diff changeset
   245
    "
4474
98208d107b52 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4470
diff changeset
   246
    "
98208d107b52 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4470
diff changeset
   247
     self 
98208d107b52 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4470
diff changeset
   248
        allSortedByScoreMatching:'nary' 
98208d107b52 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4470
diff changeset
   249
        in:(Smalltalk allClasses)
98208d107b52 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4470
diff changeset
   250
        by:[:cls | cls name]
98208d107b52 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4470
diff changeset
   251
    "
98208d107b52 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4470
diff changeset
   252
    "
98208d107b52 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4470
diff changeset
   253
     self 
98208d107b52 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4470
diff changeset
   254
        allSortedByScoreMatching:'nary' 
98208d107b52 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4470
diff changeset
   255
        in:(Smalltalk allClasses)
98208d107b52 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4470
diff changeset
   256
        by:#name
98208d107b52 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4470
diff changeset
   257
    "
98208d107b52 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4470
diff changeset
   258
4475
2e19c5a7452a #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4474
diff changeset
   259
    "Modified: / 14-07-2017 / 12:43:14 / cg"
2e19c5a7452a #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4474
diff changeset
   260
!
2e19c5a7452a #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4474
diff changeset
   261
2e19c5a7452a #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4474
diff changeset
   262
allWithScoresSortedByScoreMatching: aPattern in: aCollection by: aBlockReturningString
2e19c5a7452a #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4474
diff changeset
   263
    "selects matching elements from aCollection.
2e19c5a7452a #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4474
diff changeset
   264
     aBlockReturningString is applied to elements to get the string representation.
2e19c5a7452a #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4474
diff changeset
   265
     Returns them sorted by score (i.e. similarity) associated to their scores.
2e19c5a7452a #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4474
diff changeset
   266
     (can be used eg. to sort classes)"
2e19c5a7452a #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4474
diff changeset
   267
2e19c5a7452a #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4474
diff changeset
   268
    |matcher matches|
2e19c5a7452a #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4474
diff changeset
   269
2e19c5a7452a #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4474
diff changeset
   270
2e19c5a7452a #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4474
diff changeset
   271
    matcher := self pattern: aPattern.
2e19c5a7452a #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4474
diff changeset
   272
    matches := OrderedCollection new: aCollection size // 2.
2e19c5a7452a #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4474
diff changeset
   273
2e19c5a7452a #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4474
diff changeset
   274
    aCollection do: [ :each | 
2e19c5a7452a #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4474
diff changeset
   275
        matcher 
2e19c5a7452a #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4474
diff changeset
   276
            match: (aBlockReturningString value: each) 
2e19c5a7452a #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4474
diff changeset
   277
            ifScored: [ :score | matches add: score -> each ] 
2e19c5a7452a #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4474
diff changeset
   278
    ].
2e19c5a7452a #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4474
diff changeset
   279
    matches sort: [ :a :b | a key > b key].
2e19c5a7452a #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4474
diff changeset
   280
    ^ matches asArray
2e19c5a7452a #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4474
diff changeset
   281
2e19c5a7452a #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4474
diff changeset
   282
    "
2e19c5a7452a #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4474
diff changeset
   283
     self 
2e19c5a7452a #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4474
diff changeset
   284
        allWithScoresSortedByScoreMatching:'' 
2e19c5a7452a #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4474
diff changeset
   285
        in:(Smalltalk allClasses)
2e19c5a7452a #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4474
diff changeset
   286
        by:[:cls | cls name]
2e19c5a7452a #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4474
diff changeset
   287
    "
2e19c5a7452a #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4474
diff changeset
   288
    "
2e19c5a7452a #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4474
diff changeset
   289
     self 
2e19c5a7452a #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4474
diff changeset
   290
        allWithScoresSortedByScoreMatching:'OC' 
2e19c5a7452a #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4474
diff changeset
   291
        in:(Smalltalk allClasses)
2e19c5a7452a #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4474
diff changeset
   292
        by:[:cls | cls name]
2e19c5a7452a #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4474
diff changeset
   293
    "
2e19c5a7452a #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4474
diff changeset
   294
    "
2e19c5a7452a #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4474
diff changeset
   295
     self 
2e19c5a7452a #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4474
diff changeset
   296
        allWithScoresSortedByScoreMatching:'nary' 
2e19c5a7452a #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4474
diff changeset
   297
        in:(Smalltalk allClasses)
2e19c5a7452a #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4474
diff changeset
   298
        by:[:cls | cls name]
2e19c5a7452a #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4474
diff changeset
   299
    "
2e19c5a7452a #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4474
diff changeset
   300
    "
2e19c5a7452a #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4474
diff changeset
   301
     self 
2e19c5a7452a #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4474
diff changeset
   302
        allWithScoresSortedByScoreMatching:'nary' 
2e19c5a7452a #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4474
diff changeset
   303
        in:(Smalltalk allClasses)
2e19c5a7452a #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4474
diff changeset
   304
        by:#name
2e19c5a7452a #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4474
diff changeset
   305
    "
2e19c5a7452a #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4474
diff changeset
   306
2e19c5a7452a #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4474
diff changeset
   307
    "Created: / 14-07-2017 / 12:25:19 / cg"
4459
cfbde361fe34 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   308
! !
cfbde361fe34 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   309
cfbde361fe34 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   310
!FuzzyMatcher methodsFor:'accessing'!
cfbde361fe34 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   311
4477
99941fe21a09 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4476
diff changeset
   312
indexes
99941fe21a09 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4476
diff changeset
   313
    "only valid inside the match callback block"
99941fe21a09 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4476
diff changeset
   314
    
99941fe21a09 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4476
diff changeset
   315
    ^ indexes
99941fe21a09 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4476
diff changeset
   316
99941fe21a09 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4476
diff changeset
   317
    "Created: / 15-07-2017 / 14:57:10 / cg"
99941fe21a09 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4476
diff changeset
   318
!
99941fe21a09 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 4476
diff changeset
   319
4459
cfbde361fe34 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   320
pattern
cfbde361fe34 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   321
cfbde361fe34 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   322
	^ pattern 
cfbde361fe34 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   323
!
cfbde361fe34 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   324
cfbde361fe34 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   325
pattern: aString
cfbde361fe34 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   326
4475
2e19c5a7452a #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4474
diff changeset
   327
        pattern := aString.
2e19c5a7452a #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4474
diff changeset
   328
        lowercasePattern := pattern asLowercase.
2e19c5a7452a #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4474
diff changeset
   329
        indexes := Array new: pattern size.
2e19c5a7452a #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4474
diff changeset
   330
2e19c5a7452a #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4474
diff changeset
   331
    "Modified (format): / 14-07-2017 / 12:59:15 / cg"
4459
cfbde361fe34 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   332
! !
cfbde361fe34 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   333
4493
3961346f8256 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4492
diff changeset
   334
!FuzzyMatcher methodsFor:'api - comparing'!
4459
cfbde361fe34 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   335
cfbde361fe34 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   336
match: aString ifScored: aBlock
4493
3961346f8256 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4492
diff changeset
   337
    "If there is a match, evaluate aBlock, passing the score value"
4475
2e19c5a7452a #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4474
diff changeset
   338
        
4493
3961346f8256 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4492
diff changeset
   339
    | scoreOrNil |
3961346f8256 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4492
diff changeset
   340
3961346f8256 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4492
diff changeset
   341
    scoreOrNil := self matchScoreOrNil: aString.
3961346f8256 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4492
diff changeset
   342
    scoreOrNil notNil ifTrue:[
3961346f8256 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4492
diff changeset
   343
        aBlock value:scoreOrNil
3961346f8256 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4492
diff changeset
   344
    ].
3961346f8256 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4492
diff changeset
   345
3961346f8256 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4492
diff changeset
   346
    "Modified: / 02-08-2017 / 16:00:59 / cg"
3961346f8256 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4492
diff changeset
   347
!
3961346f8256 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4492
diff changeset
   348
3961346f8256 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4492
diff changeset
   349
matchScoreOrNil: aString
3961346f8256 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4492
diff changeset
   350
    "return the scrore if there is a match; nil otherwise."
4475
2e19c5a7452a #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4474
diff changeset
   351
        
4493
3961346f8256 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4492
diff changeset
   352
    | score |
3961346f8256 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4492
diff changeset
   353
3961346f8256 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4492
diff changeset
   354
    pattern ifEmpty: [ ^ (aString size negated) ].
3961346f8256 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4492
diff changeset
   355
    (self matches: aString) ifFalse: [ ^ nil ].
3961346f8256 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4492
diff changeset
   356
3961346f8256 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4492
diff changeset
   357
    score := self firstScore: aString at: indexes first.
4475
2e19c5a7452a #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4474
diff changeset
   358
4493
3961346f8256 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4492
diff changeset
   359
    2 to: pattern size do: [ :pix | 
3961346f8256 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4492
diff changeset
   360
            score := score + (self score: aString at: (indexes at: pix) patternAt: pix)
3961346f8256 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4492
diff changeset
   361
    ].
3961346f8256 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4492
diff changeset
   362
3961346f8256 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4492
diff changeset
   363
    score := score + self indexScore + ((aString size - pattern size) * self unmatchedLetterPenalty).
3961346f8256 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4492
diff changeset
   364
3961346f8256 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4492
diff changeset
   365
    ^ score.
3961346f8256 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4492
diff changeset
   366
3961346f8256 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4492
diff changeset
   367
    "Created: / 02-08-2017 / 15:59:56 / cg"
4459
cfbde361fe34 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   368
!
cfbde361fe34 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   369
cfbde361fe34 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   370
matches: aString
4493
3961346f8256 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4492
diff changeset
   371
    "return true if there is a match; false otherwise."
3961346f8256 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4492
diff changeset
   372
     
3961346f8256 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4492
diff changeset
   373
    | idx |
4459
cfbde361fe34 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   374
4493
3961346f8256 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4492
diff changeset
   375
    pattern size > aString size ifTrue: [ ^ false ].
4459
cfbde361fe34 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   376
4493
3961346f8256 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4492
diff changeset
   377
    idx := 0.
3961346f8256 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4492
diff changeset
   378
    pattern withIndexDo: [ :each :i |
3961346f8256 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4492
diff changeset
   379
            idx := aString 
3961346f8256 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4492
diff changeset
   380
                    findString: each asString 
3961346f8256 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4492
diff changeset
   381
                    startingAt: idx + 1 
3961346f8256 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4492
diff changeset
   382
                    caseSensitive: false. 
4459
cfbde361fe34 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   383
4493
3961346f8256 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4492
diff changeset
   384
            idx == 0 ifTrue: [ ^ false ].
3961346f8256 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4492
diff changeset
   385
            indexes at: i put: idx.
3961346f8256 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4492
diff changeset
   386
    ].
3961346f8256 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4492
diff changeset
   387
    ^ true
3961346f8256 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4492
diff changeset
   388
3961346f8256 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4492
diff changeset
   389
    "Modified (format): / 02-08-2017 / 16:01:05 / cg"
4459
cfbde361fe34 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   390
! !
cfbde361fe34 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   391
cfbde361fe34 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   392
!FuzzyMatcher methodsFor:'initialization'!
cfbde361fe34 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   393
cfbde361fe34 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   394
initialize
cfbde361fe34 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   395
4475
2e19c5a7452a #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4474
diff changeset
   396
        super initialize.
4459
cfbde361fe34 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   397
4475
2e19c5a7452a #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4474
diff changeset
   398
        pattern := lowercasePattern := ''.
2e19c5a7452a #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4474
diff changeset
   399
        indexes := #().
2e19c5a7452a #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4474
diff changeset
   400
2e19c5a7452a #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4474
diff changeset
   401
    "Modified (format): / 14-07-2017 / 13:23:26 / cg"
4459
cfbde361fe34 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   402
! !
cfbde361fe34 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   403
cfbde361fe34 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   404
!FuzzyMatcher methodsFor:'private'!
cfbde361fe34 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   405
cfbde361fe34 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   406
firstScore: aString at: anIndex
cfbde361fe34 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   407
cfbde361fe34 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   408
	| score |
cfbde361fe34 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   409
cfbde361fe34 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   410
	score := (aString at: anIndex) = pattern first 
cfbde361fe34 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   411
		ifTrue: [ self caseEqualBonus ]
cfbde361fe34 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   412
		ifFalse: [ 0 ].
cfbde361fe34 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   413
	
cfbde361fe34 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   414
	anIndex = 1 	ifTrue: [ ^ score + self firstLetterBonus ].
cfbde361fe34 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   415
		
cfbde361fe34 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   416
	score := score + (((anIndex - 1) * self leadingLetterPenalty) max: self maxLeadingLetterPenalty).
cfbde361fe34 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   417
				
cfbde361fe34 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   418
	^ score 
cfbde361fe34 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   419
!
cfbde361fe34 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   420
cfbde361fe34 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   421
indexScore 
cfbde361fe34 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   422
4475
2e19c5a7452a #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4474
diff changeset
   423
        | sum ramp |
2e19c5a7452a #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4474
diff changeset
   424
        
2e19c5a7452a #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4474
diff changeset
   425
        ramp := 1.
2e19c5a7452a #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4474
diff changeset
   426
        sum := 0.
2e19c5a7452a #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4474
diff changeset
   427
        
2e19c5a7452a #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4474
diff changeset
   428
        1 to: indexes size - 1 do: [ :ix |
2e19c5a7452a #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4474
diff changeset
   429
                ramp := (indexes at: ix) + 1 = (indexes at: ix + 1) 
2e19c5a7452a #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4474
diff changeset
   430
                        ifTrue: [ ramp + (ramp * self adjacencyIncrease) ]
2e19c5a7452a #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4474
diff changeset
   431
                        ifFalse: [ 1 ].                 
2e19c5a7452a #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4474
diff changeset
   432
                
2e19c5a7452a #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4474
diff changeset
   433
                sum := sum + ramp - 1
2e19c5a7452a #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4474
diff changeset
   434
        ].
2e19c5a7452a #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4474
diff changeset
   435
        
2e19c5a7452a #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4474
diff changeset
   436
        ^ sum rounded
2e19c5a7452a #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4474
diff changeset
   437
2e19c5a7452a #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4474
diff changeset
   438
    "Modified (format): / 14-07-2017 / 13:24:07 / cg"
4459
cfbde361fe34 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   439
!
cfbde361fe34 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   440
cfbde361fe34 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   441
isSeparator: aCharacter
cfbde361fe34 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   442
        
cfbde361fe34 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   443
        ^  aCharacter = $_ or: [ aCharacter = $: ]
cfbde361fe34 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   444
cfbde361fe34 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   445
    "Created: / 13-07-2017 / 13:30:34 / cg"
cfbde361fe34 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   446
!
cfbde361fe34 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   447
cfbde361fe34 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   448
score: aString at: stringIndex patternAt: patternIndex
cfbde361fe34 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   449
cfbde361fe34 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   450
        | score prev |
cfbde361fe34 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   451
        
cfbde361fe34 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   452
        prev := (aString at: stringIndex - 1).
cfbde361fe34 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   453
        
cfbde361fe34 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   454
        score := (self isSeparator: prev) 
cfbde361fe34 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   455
                ifTrue: [ self separatorBonus ]
cfbde361fe34 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   456
                ifFalse: [ (prev asLowercase = (lowercasePattern at: patternIndex - 1))
cfbde361fe34 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   457
                        ifTrue: [ 
cfbde361fe34 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   458
                                self adjacencyBonus + 
cfbde361fe34 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   459
                                ((prev = (pattern at: patternIndex - 1)) ifTrue: [ self adjacentCaseEqualBonus ] ifFalse: [ 0 ]) 
cfbde361fe34 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   460
                        ] 
cfbde361fe34 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   461
                        ifFalse: [ 0 ] 
cfbde361fe34 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   462
                ].
cfbde361fe34 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   463
        
cfbde361fe34 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   464
        (aString at: stringIndex) = (pattern at: patternIndex) ifTrue: [ 
cfbde361fe34 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   465
                score := score + self caseEqualBonus.
cfbde361fe34 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   466
        ].
cfbde361fe34 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   467
cfbde361fe34 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   468
        ^ score
cfbde361fe34 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   469
cfbde361fe34 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   470
    "Modified: / 13-07-2017 / 13:30:57 / cg"
cfbde361fe34 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   471
! !
cfbde361fe34 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   472
cfbde361fe34 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   473
!FuzzyMatcher methodsFor:'scoring-bonus'!
cfbde361fe34 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   474
cfbde361fe34 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   475
adjacencyBonus
cfbde361fe34 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   476
cfbde361fe34 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   477
	^ 5
cfbde361fe34 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   478
!
cfbde361fe34 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   479
cfbde361fe34 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   480
adjacencyIncrease
cfbde361fe34 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   481
cfbde361fe34 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   482
	^ 1.2
cfbde361fe34 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   483
!
cfbde361fe34 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   484
cfbde361fe34 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   485
adjacentCaseEqualBonus
cfbde361fe34 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   486
cfbde361fe34 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   487
	^ 3
cfbde361fe34 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   488
!
cfbde361fe34 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   489
cfbde361fe34 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   490
caseEqualBonus
cfbde361fe34 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   491
cfbde361fe34 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   492
	^ 7
cfbde361fe34 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   493
!
cfbde361fe34 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   494
cfbde361fe34 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   495
firstLetterBonus
cfbde361fe34 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   496
cfbde361fe34 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   497
	^ 12
cfbde361fe34 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   498
!
cfbde361fe34 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   499
cfbde361fe34 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   500
separatorBonus
cfbde361fe34 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   501
cfbde361fe34 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   502
	^ 5
cfbde361fe34 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   503
! !
cfbde361fe34 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   504
cfbde361fe34 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   505
!FuzzyMatcher methodsFor:'scoring-penalty'!
cfbde361fe34 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   506
cfbde361fe34 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   507
leadingLetterPenalty
cfbde361fe34 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   508
cfbde361fe34 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   509
	^ -3
cfbde361fe34 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   510
!
cfbde361fe34 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   511
cfbde361fe34 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   512
maxLeadingLetterPenalty
cfbde361fe34 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   513
cfbde361fe34 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   514
	^ -9
cfbde361fe34 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   515
!
cfbde361fe34 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   516
cfbde361fe34 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   517
unmatchedLetterPenalty
cfbde361fe34 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   518
cfbde361fe34 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   519
	^ -1
cfbde361fe34 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   520
! !
cfbde361fe34 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   521
cfbde361fe34 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   522
!FuzzyMatcher class methodsFor:'documentation'!
cfbde361fe34 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   523
cfbde361fe34 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   524
version
cfbde361fe34 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   525
    ^ '$Header$'
cfbde361fe34 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   526
!
cfbde361fe34 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   527
cfbde361fe34 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   528
version_CVS
cfbde361fe34 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   529
    ^ '$Header$'
cfbde361fe34 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   530
! !
cfbde361fe34 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   531