Issue #1 fixed bug in compareTo method of Interval. Problem was the compareTo only worked on start position, whereas it should also work on end position.
This commit is contained in:
parent
1785a554f3
commit
4c8ea8ba57
4
.gitignore
vendored
4
.gitignore
vendored
@ -1,3 +1,5 @@
|
|||||||
.idea
|
.idea
|
||||||
*.iml
|
*.iml
|
||||||
src/main/java/Main.java
|
src/main/java/Main.java
|
||||||
|
*.txt
|
||||||
|
docs
|
||||||
@ -52,6 +52,13 @@ public class Interval implements Intervalable {
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
Intervalable other = (Intervalable)o;
|
Intervalable other = (Intervalable)o;
|
||||||
return this.start - other.getStart();
|
int comparison = this.start - other.getStart();
|
||||||
|
return comparison != 0 ? comparison : this.end - other.getEnd();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return this.start + ":" + this.end;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -16,4 +16,9 @@ public class Emit extends Interval implements Intervalable {
|
|||||||
return this.keyword;
|
return this.keyword;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return super.toString() + "=" + this.keyword;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -102,12 +102,33 @@ public class TrieTest {
|
|||||||
trie.addKeyword("cba");
|
trie.addKeyword("cba");
|
||||||
trie.addKeyword("ababc");
|
trie.addKeyword("ababc");
|
||||||
Collection<Emit> emits = trie.parseText("ababcbab");
|
Collection<Emit> emits = trie.parseText("ababcbab");
|
||||||
|
assertEquals(2, emits.size());
|
||||||
Iterator<Emit> iterator = emits.iterator();
|
Iterator<Emit> iterator = emits.iterator();
|
||||||
// With overlaps: ab@1, ab@3, ababc@4, cba@6, ab@7
|
// With overlaps: ab@1, ab@3, ababc@4, cba@6, ab@7
|
||||||
checkEmit(iterator.next(), 0, 4, "ababc");
|
checkEmit(iterator.next(), 0, 4, "ababc");
|
||||||
checkEmit(iterator.next(), 6, 7, "ab");
|
checkEmit(iterator.next(), 6, 7, "ab");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void startOfChurchillSpeech() {
|
||||||
|
Trie trie = new Trie().removeOverlaps();
|
||||||
|
trie.addKeyword("T");
|
||||||
|
trie.addKeyword("u");
|
||||||
|
trie.addKeyword("ur");
|
||||||
|
trie.addKeyword("r");
|
||||||
|
trie.addKeyword("urn");
|
||||||
|
trie.addKeyword("ni");
|
||||||
|
trie.addKeyword("i");
|
||||||
|
trie.addKeyword("in");
|
||||||
|
trie.addKeyword("n");
|
||||||
|
trie.addKeyword("urning");
|
||||||
|
Collection<Emit> emits = trie.parseText("Turning");
|
||||||
|
for (Emit emit : emits) {
|
||||||
|
System.out.println(emit.getStart()+":"+emit.getEnd()+"="+emit.getKeyword());
|
||||||
|
}
|
||||||
|
assertEquals(2, emits.size());
|
||||||
|
}
|
||||||
|
|
||||||
private void checkEmit(Emit next, int expectedStart, int expectedEnd, String expectedKeyword) {
|
private void checkEmit(Emit next, int expectedStart, int expectedEnd, String expectedKeyword) {
|
||||||
assertEquals(expectedStart, next.getStart());
|
assertEquals(expectedStart, next.getStart());
|
||||||
assertEquals(expectedEnd, next.getEnd());
|
assertEquals(expectedEnd, next.getEnd());
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user