Skip to content

Commit

Permalink
Merge pull request #26 from KatatsumuriPan/1.20.1/fabric-dev
Browse files Browse the repository at this point in the history
Update to v1.1.0(1.20.1Fabric)
  • Loading branch information
KatatsumuriPan authored Feb 16, 2024
2 parents bbd5049 + ad5e8fc commit 49ef7e0
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 7 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Change Log

### [1.20.1-fabric-1.1.0](https://github.com/KatatsumuriPan/BetterLineBreak/releases/tag/1.20.1-fabric-1.1.0) - 2024-02-16

- Fix not break with PHRASE mode.
- Fix not break with PHRASE mode.
- Cache budouX model.

### [1.20.1-fabric-1.0.1](https://github.com/KatatsumuriPan/BetterLineBreak/releases/tag/1.20.1-fabric-1.0.1) - 2024-01-31

- Fix freezing bug.
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ yarn_mappings=1.20.1+build.10
loader_version=0.15.6

# Mod Properties
mod_version=1.0.1
mod_version=1.1.0
maven_group=kpan.b_line_break
archives_base_name=BetterLineBreak-1.20.1(Fabric)

Expand Down
10 changes: 6 additions & 4 deletions src/main/java/kpan/b_line_break/LineBreakingUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -102,10 +102,10 @@ public static void wrapLines(TextHandlerAccessor textHandler, StringVisitable st
case PHRASE -> {
String language = MinecraftClient.getInstance().getLanguageManager().getLanguage();
return switch (language) {
case "ja_jp" -> Parser.loadByFileName("/models/ja_tuned.json");
case "zh_cn" -> Parser.loadDefaultSimplifiedChineseParser();
case "zh_tw" -> Parser.loadDefaultTraditionalChineseParser();
case "th_th" -> Parser.loadDefaultThaiParser();
case "ja_jp" -> Parser.Cache.getOrLoad("/models/ja_tuned.json");
case "zh_cn" -> Parser.Cache.getOrLoad("/models/zh-hans.json");
case "zh_tw" -> Parser.Cache.getOrLoad("/models/zh-hant.json");
case "th_th" -> Parser.Cache.getOrLoad("/models/th.json");
default -> null;
};
}
Expand Down Expand Up @@ -166,6 +166,8 @@ public static boolean canBreak(char prevChar, char c, int index, IntSet breakInd
return false;
if (isStartBracket(prevChar))
return false;
if (breakIndices.contains(index))
return true;
if (!isNormalAsciiLetter(prevChar) && isNormalAsciiLetter(c))
return true;
return false;
Expand Down
22 changes: 20 additions & 2 deletions src/main/java/kpan/b_line_break/budoux/Parser.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import com.google.gson.JsonIOException;
import com.google.gson.JsonSyntaxException;
import com.google.gson.reflect.TypeToken;
import org.jetbrains.annotations.Nullable;

import java.io.IOException;
import java.io.InputStream;
Expand All @@ -33,8 +34,9 @@
import java.util.Optional;

/*
・HTMLは使用しないので、translateHTMLStringを削除しています。
・totalScoreをキャッシュしています。
* HTMLは使用しないので、translateHTMLStringを削除しています。
* totalScoreをキャッシュしています。
* シンプルなCacheクラスを作成しています。
*/
public class Parser {
private final Map<String, Map<String, Integer>> model;
Expand Down Expand Up @@ -176,4 +178,20 @@ public List<String> parse(String sentence) {
return result;
}

/*
流石に毎回ファイルIOが走るのは良くないのでキャッシュ
*/
public static class Cache {

private static @Nullable String modelFileName = null;
private static Parser parser;

public static Parser getOrLoad(String modelFileName) {
if (modelFileName.equals(Cache.modelFileName))
return parser;
Cache.modelFileName = modelFileName;
parser = Parser.loadByFileName(modelFileName);
return parser;
}
}
}

0 comments on commit 49ef7e0

Please sign in to comment.