Skip to content

Commit

Permalink
Fixes Violation of triangle inequality in subsumption function for tr…
Browse files Browse the repository at this point in the history
…anspositions #2
  • Loading branch information
Dylon Edwards committed Jul 4, 2015
1 parent b7ead8b commit 0fa2238
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 11 deletions.
2 changes: 1 addition & 1 deletion .gitmodules
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
[submodule "shared"]
path = shared
url = https://github.com/dylon/liblevenshtein-shared.git
url = https://github.com/universal-automata/liblevenshtein-shared.git
14 changes: 8 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ as by selecting the sequence of terms that have the greatest probability of
appearing together).

For a quick demonstration, please visit the [Github Page,
here](http://dylon.github.io/liblevenshtein/).
here](http://universal-automata.github.io/liblevenshtein/).

The library is currently only written in CoffeeScript (and JavaScript), but I
The library is currently written in Java, CoffeeScript, and JavaScript, but I
will be porting it to other languages, soon. If you have a specific language
you would like to see it in, or package-management system you would like it
deployed to, let me know.
Expand All @@ -43,7 +43,7 @@ Install the module via `npm`:
info trying registry request attempt 1 at 12:59:16
http GET https://registry.npmjs.org/liblevenshtein
http 304 https://registry.npmjs.org/liblevenshtein
liblevenshtein@2.0.1 node_modules/liblevenshtein
liblevenshtein@2.0.2 node_modules/liblevenshtein
```

Then, you may `require` it to do whatever you need:
Expand Down Expand Up @@ -85,7 +85,7 @@ To use the library on your website, reference the desired file from the
<head>
<!-- stuff ... -->
<script type="text/javascript"
src="http://dylon.github.com/liblevenshtein/javascripts/2.0.1/levenshtein-transducer.min.js">
src="http://universal-automata.github.com/liblevenshtein/javascripts/2.0.2/levenshtein-transducer.min.js">
</script>
<!-- more stuff ... -->
</head>
Expand All @@ -96,7 +96,7 @@ To use the library on your website, reference the desired file from the
```

Once the script loads, you should construct a transducer via the [Builder
Api](http://dylon.github.io/liblevenshtein/docs/coffeescript/builder.html):
Api](http://universal-automata.github.io/liblevenshtein/docs/coffeescript/builder.html):

```javascript
$(function ($) {
Expand Down Expand Up @@ -136,10 +136,12 @@ $(function ($) {

This will give the user autocompletion hints as he types in the search box.

### Reference

This library is based largely on the work of [Stoyan
Mihov](http://www.lml.bas.bg/~stoyan/), [Klaus
Schulz](http://www.cis.uni-muenchen.de/people/schulz.html), and Petar Nikolaev Mitankin: "[Fast
String Correction with
Levenshtein-Automata](http://citeseerx.ist.psu.edu/viewdoc/summary?doi=10.1.1.16.652
"Klaus Schulz and Stoyan Mihov (2002)")". For more details, please see the
[wiki](https://github.com/dylon/liblevenshtein/wiki).
[wiki](https://github.com/universal-automata/liblevenshtein/wiki).
21 changes: 17 additions & 4 deletions src/levenshtein/builder.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -467,12 +467,25 @@ class Builder
(f == n) && (i == j)
else
if t is 1
#(e < f) && Math.abs(j - (i - 1)) <= (f - e)
# We have two cases:
#
# NOTE: This is how I derived what follows:
# Math.abs(j - (i - 1)) = Math.abs(j - i + 1) = Math.abs(j - i) + 1
# Case 1: (j < i) => (j - i) = - (i - j)
# => |j - (i - 1)| = |j - i + 1|
# = |-(i - j) + 1|
# = |-(i - j - 1)|
# = i - j - 1
#
((i < j) && (j - i) || (i - j)) + 1 <= (f - e)
# Case 1 holds, because i and j are integers, and j < i implies i is at
# least 1 unit greater than j, further implying that i - j - 1 is
# non-negative.
#
# Case 2: (j >= i) => |j - (i - 1)| = |j - i + 1| = j - i + 1
#
# Case 2 holds for the same reason case 1 does, in that j - i >= 0, and
# adding 1 to the difference will only strengthen its non-negativity.
#
#Math.abs(j - (i - 1)) <= (f - e);
(if (j < i) then (i - j - 1) else (j - i + 1)) <= (f - e)
else
#(e < f) && Math.abs(j - i) <= (f - e)
((i < j) && (j - i) || (i - j)) <= (f - e)
Expand Down

0 comments on commit 0fa2238

Please sign in to comment.