-
-
Notifications
You must be signed in to change notification settings - Fork 114
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1222 from omegat-org/topic/miurahr/matches/refact…
…or-find-matches-class refactor: FindMatches class
- Loading branch information
Showing
8 changed files
with
397 additions
and
59 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,6 +7,7 @@ | |
2008 Alex Buloichik | ||
2012 Thomas Cordonnier, Martin Fleurke | ||
2013 Aaron Madlon-Kay | ||
2024 Hiroshi Miura | ||
Home page: https://www.omegat.org/ | ||
Support center: https://omegat.org/support | ||
|
@@ -32,17 +33,22 @@ | |
import java.util.List; | ||
import java.util.logging.Logger; | ||
|
||
import org.omegat.core.Core; | ||
import org.omegat.core.data.IProject; | ||
import org.omegat.core.data.SourceTextEntry; | ||
import org.omegat.core.events.IStopped; | ||
import org.omegat.core.matching.NearString; | ||
import org.omegat.core.segmentation.Segmenter; | ||
import org.omegat.core.statistics.FindMatches; | ||
import org.omegat.gui.common.EntryInfoSearchThread; | ||
import org.omegat.util.OConsts; | ||
import org.omegat.util.Preferences; | ||
|
||
/** | ||
* Find matches in separate thread then show result in the matches pane. | ||
* Find matches in separate thread then show a result in the matches' pane. | ||
* | ||
* @author Alex Buloichik ([email protected]) | ||
* @author Hiroshi Miura | ||
*/ | ||
public class FindMatchesThread extends EntryInfoSearchThread<List<NearString>> { | ||
private static final Logger LOGGER = Logger.getLogger(FindMatchesThread.class.getName()); | ||
|
@@ -52,9 +58,9 @@ public class FindMatchesThread extends EntryInfoSearchThread<List<NearString>> { | |
|
||
/** | ||
* Entry which is processed currently. | ||
* | ||
* If entry in controller was changed, it means user has moved to another entry, and there is no sense to | ||
* continue. | ||
* <p> | ||
* If entry in controller was changed, it means the user has moved to | ||
* another entry, and there is no sense to continue. | ||
*/ | ||
private final SourceTextEntry processedEntry; | ||
|
||
|
@@ -79,12 +85,26 @@ protected List<NearString> search() throws Exception { | |
long before = System.currentTimeMillis(); | ||
|
||
try { | ||
FindMatches finder = new FindMatches(project, OConsts.MAX_NEAR_STRINGS, true, false); | ||
List<NearString> result = finder.search(processedEntry.getSrcText(), true, true, this::isEntryChanged); | ||
List<NearString> result = finderSearch(project, Core.getSegmenter(), processedEntry.getSrcText(), | ||
this::isEntryChanged, Preferences.getPreferenceDefault( | ||
Preferences.EXT_TMX_FUZZY_MATCH_THRESHOLD, OConsts.FUZZY_MATCH_THRESHOLD)); | ||
LOGGER.finer(() -> "Time for find matches: " + (System.currentTimeMillis() - before)); | ||
return result; | ||
} catch (FindMatches.StoppedException ex) { | ||
throw new EntryChangedException(); | ||
} | ||
} | ||
|
||
/** | ||
* Search matches (static for test purpose). | ||
* @param project OmegaT project. | ||
* @param srcText source text to look for. | ||
* @param isEntryChanged stop and raise StopException when it returns true. | ||
* @return result as a list of NearString. | ||
*/ | ||
protected static List<NearString> finderSearch(IProject project, Segmenter segmenter, String srcText, | ||
IStopped isEntryChanged, int threshold) { | ||
FindMatches finder = new FindMatches(project, segmenter, OConsts.MAX_NEAR_STRINGS, false, threshold); | ||
return finder.search(srcText, true, isEntryChanged); | ||
} | ||
} |
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,16 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!DOCTYPE tmx PUBLIC "-//LISA OSCAR:1998//DTD for Translation Memory eXchange//EN" "tmx14.dtd"> | ||
|
||
<tmx version="1.4"> | ||
<header creationtoolversion="0.1" adminlang="en" segtype="paragraph" creationdate="20230930T155211Z" datatype="unknown" srclang="ja" creationtool="txt2tmx" o-tmf="TextEdit"></header> | ||
<body> | ||
<tu> | ||
<tuv xml:lang="fr"> | ||
<seg>weird behavior</seg> | ||
</tuv> | ||
<tuv xml:lang="ja"> | ||
<seg>地力の搾取と浪費が現われる。(1)</seg> | ||
</tuv> | ||
</tu> | ||
</body> | ||
</tmx> |
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,46 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!DOCTYPE tmx SYSTEM "tmx14.dtd"> | ||
<tmx version="1.4"> | ||
<header datatype="plaintext" srclang="en-US" adminlang="EN-US" o-tmf="OmegaT TMX" segtype="sentence" | ||
creationtoolversion="test" creationtool="test"/> | ||
<body> | ||
<!-- Default translations --> | ||
<tu> | ||
<tuv lang="en-US"> | ||
<seg>Other</seg> | ||
</tuv> | ||
<tuv lang="co" changeid="id" changedate="20200523T143256Z"> | ||
<seg>Altre</seg> | ||
</tuv> | ||
</tu> | ||
<tu> | ||
<tuv lang="en-US"> | ||
<seg>For installation on Linux.</seg> | ||
</tuv> | ||
<tuv lang="co" changeid="id" changedate="20200526T131725Z" creationid="id" creationdate="20200526T131725Z"> | ||
<seg>Per l’installazioni nant’à i sistemi Linux.</seg> | ||
</tuv> | ||
</tu> | ||
<tu> | ||
<tuv lang="en-US"> | ||
<seg>For installation on other operating systems (such as FreeBSD and Solaris).</seg> | ||
</tuv> | ||
<tuv lang="co" changeid="id" changedate="20200526T131840Z" creationid="id" | ||
creationdate="20200526T131840Z"> | ||
<seg>Per l’installazioni nant’à d’altri sistemi (cum’è FreeBSD è Solaris).</seg> | ||
</tuv> | ||
</tu> | ||
<!-- Alternative translations --> | ||
<tu> | ||
<prop type="file">website/download.html</prop> | ||
<prop type="prev">For installation on Linux.</prop> | ||
<prop type="next">For installation on other operating systems (such as FreeBSD and Solaris).<br0/></prop> | ||
<tuv lang="en-US"> | ||
<seg>Other</seg> | ||
</tuv> | ||
<tuv lang="co" changeid="id" changedate="20200526T131742Z" creationid="id" creationdate="20200526T131742Z"> | ||
<seg>Altri</seg> | ||
</tuv> | ||
</tu> | ||
</body> | ||
</tmx> |
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
Oops, something went wrong.