Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrade morfologik from 1.10.0 to 2.0.1 #342

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion languagetool-core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,11 @@
<artifactId>morfologik-fsa</artifactId>
<version>${morfologik.version}</version>
</dependency>
<dependency>
<groupId>org.carrot2</groupId>
<artifactId>morfologik-fsa-builders</artifactId>
<version>${morfologik.version}</version>
</dependency>
<dependency>
<groupId>org.carrot2</groupId>
<artifactId>morfologik-speller</artifactId>
Expand All @@ -115,7 +120,7 @@
<!-- needed for building the Morfologik dict at runtime (for ignore.txt) -->
<groupId>com.carrotsearch</groupId>
<artifactId>hppc</artifactId>
<version>0.6.1</version>
<version>0.7.1</version>
</dependency>
<dependency>
<groupId>net.loomchild</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@
*/
package org.languagetool.rules.spelling.morfologik;

import morfologik.fsa.CFSA2Serializer;
import morfologik.fsa.FSA;
import morfologik.fsa.FSABuilder;
import morfologik.fsa.builders.CFSA2Serializer;
import morfologik.fsa.builders.FSABuilder;
import morfologik.stemming.Dictionary;
import org.jetbrains.annotations.Nullable;
import org.languagetool.JLanguageTool;
Expand Down Expand Up @@ -112,11 +112,14 @@ private Dictionary getDictionary(List<byte[]> lines, String dictPath) throws IOE
Collections.sort(lines, FSABuilder.LEXICAL_ORDERING);
FSA fsa = FSABuilder.build(lines);
ByteArrayOutputStream fsaOutStream = new CFSA2Serializer().serialize(fsa, new ByteArrayOutputStream());
ByteArrayInputStream fsaInStream = new ByteArrayInputStream(fsaOutStream.toByteArray());
String infoFile = dictPath.replace(".dict", ".info");
Dictionary dict = Dictionary.readAndClose(fsaInStream, JLanguageTool.getDataBroker().getFromResourceDirAsStream(infoFile));
dicPathToDict.put(dictPath, dict);
return dict;

try (InputStream fsaInStream = new ByteArrayInputStream(fsaOutStream.toByteArray());
InputStream metadataInStream = JLanguageTool.getDataBroker().getFromResourceDirAsStream(infoFile)) {
Dictionary dict = Dictionary.read(fsaInStream, metadataInStream);
dicPathToDict.put(dictPath, dict);
return dict;
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
import org.languagetool.tools.StringTools;

import java.io.IOException;
import java.nio.charset.CharacterCodingException;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.TimeUnit;
Expand Down Expand Up @@ -88,12 +87,8 @@ public boolean isMisspelled(String word) {

public List<String> getSuggestions(String word) {
final List<String> suggestions = new ArrayList<>();
try {
suggestions.addAll(speller.findReplacements(word));
suggestions.addAll(speller.replaceRunOnWords(word));
} catch (CharacterCodingException e) {
throw new RuntimeException(e);
}
suggestions.addAll(speller.findReplacements(word));
suggestions.addAll(speller.replaceRunOnWords(word));
// capitalize suggestions if necessary
if (dictionary.metadata.isConvertingCase() && StringTools.startsWithUppercase(word)) {
for (int i = 0; i < suggestions.size(); i++) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@
*/
package org.languagetool.rules.de;

import morfologik.fsa.CFSA2Serializer;
import morfologik.fsa.FSA;
import morfologik.fsa.FSABuilder;
import morfologik.fsa.builders.CFSA2Serializer;
import morfologik.fsa.builders.FSABuilder;
import morfologik.speller.Speller;
import morfologik.stemming.Dictionary;
import org.junit.Ignore;
Expand All @@ -42,9 +42,7 @@

import static junit.framework.TestCase.assertFalse;
import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.*;

public class GermanSpellerRuleTest {

Expand Down Expand Up @@ -321,8 +319,10 @@ private Dictionary getDictionary(List<byte[]> lines, InputStream infoFile) throw
Collections.sort(lines, FSABuilder.LEXICAL_ORDERING);
FSA fsa = FSABuilder.build(lines);
ByteArrayOutputStream fsaOutStream = new CFSA2Serializer().serialize(fsa, new ByteArrayOutputStream());
ByteArrayInputStream fsaInStream = new ByteArrayInputStream(fsaOutStream.toByteArray());
return Dictionary.readAndClose(fsaInStream, infoFile);
try (InputStream fsaInStream = new ByteArrayInputStream(fsaOutStream.toByteArray());
InputStream metadataInStream = infoFile) {
return Dictionary.read(fsaInStream, metadataInStream);
}
}

private void assertCorrection(HunspellRule rule, String input, String... expectedTerms) throws IOException {
Expand Down
6 changes: 6 additions & 0 deletions languagetool-standalone/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,12 @@
<version>${morfologik.version}</version>
</dependency>

<dependency>
<groupId>commons-cli</groupId>
<artifactId>commons-cli</artifactId>
<version>${commons.cli.version}</version>
</dependency>

<dependency>
<!-- to prevent "Failed to load class org.slf4j.impl.StaticLoggerBinder",
see http://www.slf4j.org/codes.html#StaticLoggerBinder -->
Expand Down
5 changes: 5 additions & 0 deletions languagetool-tools/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,11 @@
<artifactId>languagetool-core</artifactId>
<version>${languagetool.version}</version>
</dependency>
<dependency>
<groupId>commons-cli</groupId>
<artifactId>commons-cli</artifactId>
<version>${commons.cli.version}</version>
</dependency>
<dependency>
<groupId>org.carrot2</groupId>
<artifactId>morfologik-tools</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,28 +18,14 @@
*/
package org.languagetool.tools;

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Properties;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import morfologik.tools.FSABuild;
import morfologik.tools.Launcher;
import org.jetbrains.annotations.Nullable;

import morfologik.tools.FSABuildTool;
import morfologik.tools.Launcher;
import java.io.*;
import java.util.*;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
* Create a Morfologik binary dictionary from plain text data.
Expand Down Expand Up @@ -109,7 +95,7 @@ protected File buildDict(File tempFile) throws Exception {

String[] buildToolOptions = {"-f", "cfsa2", "-i", tempFile.getAbsolutePath(), "-o", resultFile.getAbsolutePath()};
System.out.println("Running Morfologik FSABuildTool.main with these options: " + Arrays.toString(buildToolOptions));
FSABuildTool.main(buildToolOptions);
FSABuild.main(buildToolOptions);
System.out.println("Done. The binary dictionary has been written to " + resultFile.getAbsolutePath());
return resultFile;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@
*/
package org.languagetool.tools;

import morfologik.tools.FSADumpTool;

import morfologik.tools.FSADump;

import java.io.File;

Expand All @@ -36,9 +37,11 @@ public static void main(String[] args) throws Exception {
String filename = args[0];
String path = new File(filename).getAbsolutePath();
if (path.contains("hunspell") || path.contains("spelling")) {
FSADumpTool.main("--raw-data", "-d", args[0]);
String[] options = {"--raw-data", "-d", args[0]};
FSADump.main(options);
} else {
FSADumpTool.main("--raw-data", "-x", "-d", args[0]);
String[] options = {"--raw-data", "-x", "-d", args[0]};
FSADump.main(options);
}
}

Expand Down
2 changes: 1 addition & 1 deletion languagetool-wikipedia/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@
<dependency>
<groupId>commons-cli</groupId>
<artifactId>commons-cli</artifactId>
<version>1.2</version>
<version>${commons.cli.version}</version>
</dependency>
<dependency>
<groupId>org.sweble.wikitext</groupId>
Expand Down
3 changes: 2 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,9 @@
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
<maven.build.timestamp.format>yyyy-MM-dd HH:mm</maven.build.timestamp.format>
<commons.cli.version>1.2</commons.cli.version>
<junit.version>4.12</junit.version>
<morfologik.version>1.10.0</morfologik.version>
<morfologik.version>2.0.1</morfologik.version>
<languagetool.version>3.3-SNAPSHOT</languagetool.version>
</properties>

Expand Down