mirror of
https://github.com/MarginaliaSearch/MarginaliaSearch.git
synced 2025-10-05 21:22:39 +02:00
It's long surpassed the single-responsibility library it once was, and is as such out of place in its original location, and fits better among the function-type modules.
44 lines
1.1 KiB
Java
44 lines
1.1 KiB
Java
package nu.marginalia.segmentation;
|
|
|
|
import org.junit.jupiter.api.BeforeEach;
|
|
import org.junit.jupiter.api.Test;
|
|
|
|
import java.util.List;
|
|
|
|
import static org.junit.jupiter.api.Assertions.*;
|
|
|
|
class NgramLexiconTest {
|
|
NgramLexicon lexicon = new NgramLexicon();
|
|
@BeforeEach
|
|
public void setUp() {
|
|
lexicon.clear();
|
|
}
|
|
|
|
void addNgram(String... ngram) {
|
|
lexicon.incOrderedTitle(HasherGroup.ordered().rollingHash(ngram));
|
|
}
|
|
|
|
@Test
|
|
void findSegments() {
|
|
addNgram("hello", "world");
|
|
addNgram("rye", "bread");
|
|
addNgram("rye", "world");
|
|
|
|
List<String[]> segments = lexicon.findSegmentsStrings(2, 2, "hello", "world", "rye", "bread");
|
|
|
|
assertEquals(2, segments.size());
|
|
|
|
for (int i = 0; i < 2; i++) {
|
|
var segment = segments.get(i);
|
|
switch (i) {
|
|
case 0 -> {
|
|
assertArrayEquals(new String[]{"hello", "world"}, segment);
|
|
}
|
|
case 1 -> {
|
|
assertArrayEquals(new String[]{"rye", "bread"}, segment);
|
|
}
|
|
}
|
|
}
|
|
|
|
}
|
|
} |