Skip to content

Commit 8548265

Browse files
authored
Merge pull request #456 from Freeesia/feature/fix_fasttext
2 parents 037ece7 + 846ac9b commit 8548265

2 files changed

Lines changed: 6 additions & 13 deletions

File tree

Directory.Packages.props

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
<PackageVersion Include="Microsoft.Xaml.Behaviors.Wpf" Version="1.1.135" />
3232
<PackageVersion Include="Moq" Version="4.20.72" />
3333
<PackageVersion Include="Octokit" Version="14.0.0" />
34-
<PackageVersion Include="Panlingo.LanguageIdentification.FastText" Version="0.6.0" />
34+
<PackageVersion Include="Panlingo.LanguageIdentification.FastText" Version="0.6.1" />
3535
<PackageVersion Include="PInvoke.User32" Version="0.7.124" />
3636
<PackageVersion Include="PropertyTools" Version="3.1.0" />
3737
<PackageVersion Include="PropertyTools.Wpf" Version="3.1.0" />

Plugins/WindowTranslator.Plugin.OneOcrPlugin/OneOcr.cs

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ public sealed class OneOcr : IOcrModule, IDisposable
2121
{
2222
const string apiKey = "kj)TGtrK>f]b[Piow.gU+nC@s\"\"\"\"\"\"4";
2323
const int maxLineCount = 1000;
24-
private readonly FastTextDetector? fastText;
24+
private readonly FastTextDetector fastText;
2525
private readonly ILogger<OneOcr> logger;
2626
private readonly string source;
2727
private readonly HashSet<string> targets;
@@ -58,15 +58,8 @@ private static nint Context_ResolvingUnmanagedDll(Assembly assembly, string arg2
5858
public OneOcr(ILogger<OneOcr> logger, IOptionsSnapshot<LanguageOptions> langOptions, IOptionsSnapshot<BasicOcrParam> ocrParam)
5959
{
6060
this.logger = logger;
61-
try
62-
{
63-
this.fastText = new FastTextDetector();
64-
this.fastText.LoadDefaultModel();
65-
}
66-
catch (DllNotFoundException)
67-
{
68-
this.logger.LogError("FastTextのDLLが見つからないため、言語判定処理は利用出来ません");
69-
}
61+
this.fastText = new FastTextDetector();
62+
this.fastText.LoadDefaultModel();
7063
this.source = langOptions.Value.Source;
7164
this.targets = [langOptions.Value.Target[..2]];
7265
if (this.targets.Overlaps(["ja", "zh"]) && this.source[..2] is not "ja" and not "zh")
@@ -126,7 +119,7 @@ public OneOcr(ILogger<OneOcr> logger, IOptionsSnapshot<LanguageOptions> langOpti
126119

127120
public void Dispose()
128121
{
129-
this.fastText?.Dispose();
122+
this.fastText.Dispose();
130123
}
131124

132125
public async ValueTask<IEnumerable<TextRect>> RecognizeAsync(SoftwareBitmap bitmap)
@@ -160,7 +153,7 @@ public async ValueTask<IEnumerable<TextRect>> RecognizeAsync(SoftwareBitmap bitm
160153
}
161154

162155
private bool IsTargetLangText(string text)
163-
=> this.fastText?.Predict(text, 3, 0.7f).Any(p => this.targets.Contains(p.Label[(p.Label.LastIndexOf('_') + 1)..])) ?? false;
156+
=> this.fastText.Predict(text, 3, 0.7f).Any(p => this.targets.Contains(p.Label[(p.Label.LastIndexOf('_') + 1)..]));
164157

165158
private unsafe IEnumerable<TextRect> Recognize(SoftwareBitmap bitmap)
166159
{

0 commit comments

Comments
 (0)