diff options
| author | Alon Levy <alon@pobox.com> | 2014-10-12 12:33:42 +0300 |
|---|---|---|
| committer | Alon Levy <alon@pobox.com> | 2014-10-12 12:33:42 +0300 |
| commit | 082d90e68a81f05c35f009bfdb2a8d131778af4b (patch) | |
| tree | 6699c1336b37dd02958ea26a9c6e985cb5e6753b /scripts | |
| parent | 85b7014b196a9d948d10486287f887542c08a3a9 (diff) | |
textanalysis: fix logic of allowed renames
Diffstat (limited to 'scripts')
| -rw-r--r-- | scripts/textanalysis.js | 30 |
1 files changed, 20 insertions, 10 deletions
diff --git a/scripts/textanalysis.js b/scripts/textanalysis.js index 68881fcc..58d05139 100644 --- a/scripts/textanalysis.js +++ b/scripts/textanalysis.js @@ -38,16 +38,26 @@ function autocompleteCallback(request, response_callback) response_callback(ret); } -function same_up_to_one_letter(s1, s2) -{ - return ((s1.length == s2.length + 1 && s1.substr(0, s2.length) == s2) || - (s2.length == s1.length + 1 && s2.substr(0, s1.length) == s1)); -} - +/* up_to_two_renames: + * + * allow one letter or 'new node' to anything changes */ function up_to_two_renames(graph, old_id, new_id) { var not_one_letter = false; var k; + /* Includes: + * single letter or no addition or removal after changing to lower case. + * older (s1) node being 'new node' + */ + function allowed_rename(s1, s2) + { + s1 = s1.toLowerCase(); + s2 = s2.toLowerCase(); + return (s1 == s2 || + s1 == 'new node' || + (s1.length == s2.length + 1 && s1.substr(0, s2.length) == s2) || + (s2.length == s1.length + 1 && s2.substr(0, s1.length) == s1)); + } if (old_id.length != new_id.length) { console.log('bug: up_to_two_renames: not equal inputs'); @@ -58,12 +68,12 @@ function up_to_two_renames(graph, old_id, new_id) return; } if (old_id.length == 2) { - if (same_up_to_one_letter(old_id[0], new_id[1]) && - same_up_to_one_letter(old_id[1], new_id[0])) { + if (allowed_rename(old_id[0], new_id[1]) && + allowed_rename(old_id[1], new_id[0])) { old_id = [old_id[1], old_id[0]]; } else { - if (!same_up_to_one_letter(old_id[0], new_id[0]) || - !same_up_to_one_letter(old_id[1], new_id[1])) { + if (!allowed_rename(old_id[0], new_id[0]) || + !allowed_rename(old_id[1], new_id[1])) { not_one_letter = true; } } |
