-
Notifications
You must be signed in to change notification settings - Fork 44
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixes GH-85: Encoded sequences can clash with separator byte and caus…
…e assertion errors
- Loading branch information
Showing
9 changed files
with
145 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
63 changes: 63 additions & 0 deletions
63
morfologik-tools/src/test/java/morfologik/tools/DictCompileBug.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
package morfologik.tools; | ||
|
||
import java.io.Writer; | ||
import java.nio.charset.StandardCharsets; | ||
import java.nio.file.Files; | ||
import java.nio.file.Path; | ||
import java.util.LinkedHashSet; | ||
import java.util.Set; | ||
|
||
import org.assertj.core.api.Assertions; | ||
import org.junit.Test; | ||
|
||
import com.carrotsearch.randomizedtesting.RandomizedTest; | ||
|
||
import morfologik.stemming.Dictionary; | ||
import morfologik.stemming.DictionaryLookup; | ||
import morfologik.stemming.DictionaryMetadata; | ||
import morfologik.stemming.EncoderType; | ||
import morfologik.stemming.WordData; | ||
|
||
public class DictCompileBug extends RandomizedTest { | ||
@Test | ||
public void testSeparatorInEncoded() throws Exception { | ||
final Path input = newTempDir().toPath().resolve("dictionary.input"); | ||
final Path metadata = DictionaryMetadata.getExpectedMetadataLocation(input); | ||
|
||
char separator = '_'; | ||
try (Writer writer = Files.newBufferedWriter(metadata, StandardCharsets.UTF_8)) { | ||
DictionaryMetadata.builder() | ||
.separator(separator) | ||
.encoder(EncoderType.SUFFIX) | ||
.encoding(StandardCharsets.UTF_8) | ||
.build() | ||
.write(writer); | ||
} | ||
|
||
Set<String> sequences = new LinkedHashSet<>(); | ||
for (int seqs = randomIntBetween(0, 100); --seqs >= 0;) { | ||
sequences.add("anfragen_anfragen|VER:1:PLU:KJ1:SFT:NEB"); | ||
sequences.add("Anfragen_anfragen|VER:1:PLU:KJ1:SFT:NEB"); | ||
} | ||
|
||
try (Writer writer = Files.newBufferedWriter(input, StandardCharsets.UTF_8)) { | ||
for (String in : sequences) { | ||
writer.write(in); | ||
writer.write('\n'); | ||
} | ||
} | ||
|
||
Assertions.assertThat(new DictCompile(input, false, true, false, false, false).call()) | ||
.isEqualTo(ExitStatus.SUCCESS); | ||
|
||
Path dict = input.resolveSibling("dictionary.dict"); | ||
Assertions.assertThat(dict).isRegularFile(); | ||
|
||
// Verify the dictionary is valid. | ||
|
||
DictionaryLookup dictionaryLookup = new DictionaryLookup(Dictionary.read(dict)); | ||
for (WordData wd : dictionaryLookup) { | ||
System.out.println(wd); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters