From 53854ed7b38bf3c06dcf4b939bdb6ff52ca9e1dc Mon Sep 17 00:00:00 2001 From: Hiroshi Miura Date: Sat, 30 Nov 2024 11:50:57 +0900 Subject: [PATCH 1/9] feat: introduce matchSource match template variable - Change default fuzzy match pane template with matchSource - Add method MatchesVarExpansion#expandMatchSource - Extend NearString.MATCH_SOURCE to have TM_SUBSEG - Update test expectations of MatchesTextAreaTest, and FindMatchesTest - Add human-readable names of MATCH_SOURCE in Bundle.properties Signed-off-by: Hiroshi Miura --- src/org/omegat/Bundle.properties | 5 ++++ src/org/omegat/core/matching/NearString.java | 7 ++++-- .../omegat/core/statistics/FindMatches.java | 5 ++-- .../gui/matches/MatchesVarExpansion.java | 25 +++++++++++++++++-- .../gui/matches/MatchesVarExpansionTest.java | 3 ++- 5 files changed, 38 insertions(+), 7 deletions(-) diff --git a/src/org/omegat/Bundle.properties b/src/org/omegat/Bundle.properties index 19327348bb..c69d8ad647 100644 --- a/src/org/omegat/Bundle.properties +++ b/src/org/omegat/Bundle.properties @@ -2947,3 +2947,8 @@ DICTIONARY_LOAD_FILE=Loaded dictionary from '{0}': {1} ms DICTIONARY_LOAD_ERROR=Error load dictionary from '{0}': {1} DICTIONARY_MANAGER_ERROR_SAVE_IGNORE=Error saving ignore words" EDITOR_CONTROLLER_EXCEPTION=bad location exception when changing case + +MATCHES_COMES_FROM_TM=From TM +MATCHES_COMES_FROM_FILES=Files +MATCHES_COMES_FROM_MEMORY=From Project +MATCHES_COMES_FROM_TM_SUBSEG=Sub-segmented match diff --git a/src/org/omegat/core/matching/NearString.java b/src/org/omegat/core/matching/NearString.java index 827da2f4e5..b3f40cdda7 100644 --- a/src/org/omegat/core/matching/NearString.java +++ b/src/org/omegat/core/matching/NearString.java @@ -49,8 +49,11 @@ */ public class NearString { public enum MATCH_SOURCE { - MEMORY, TM, FILES - }; + MEMORY, + TM, + FILES, + TM_SUBSEG; + } public enum SORT_KEY { SCORE, SCORE_NO_STEM, ADJUSTED_SCORE diff --git a/src/org/omegat/core/statistics/FindMatches.java b/src/org/omegat/core/statistics/FindMatches.java index e6cbfcedd9..415d9e3531 100644 --- a/src/org/omegat/core/statistics/FindMatches.java +++ b/src/org/omegat/core/statistics/FindMatches.java @@ -235,8 +235,8 @@ public List search(String searchText, boolean requiresTranslation, b for (ITMXEntry tmen : en.getValue().getEntries()) { checkStopped(stop); if (tmen.getSourceText() == null) { - // Not all TMX entries have a source; in that case there can - // be no meaningful match, so skip. + // Not all TMX entries have a source; skip it in + // the case, because of no meaningful. continue; } if (requiresTranslation && tmen.getTranslationText() == null) { @@ -249,6 +249,7 @@ public List search(String searchText, boolean requiresTranslation, b processEntry(null, tmen, en.getKey(), NearString.MATCH_SOURCE.TM, false, tmenPenalty); } } + // travel by all entries for check source file translations for (SourceTextEntry ste : project.getAllEntries()) { checkStopped(stop); diff --git a/src/org/omegat/gui/matches/MatchesVarExpansion.java b/src/org/omegat/gui/matches/MatchesVarExpansion.java index 850daf5272..9ea1f692de 100644 --- a/src/org/omegat/gui/matches/MatchesVarExpansion.java +++ b/src/org/omegat/gui/matches/MatchesVarExpansion.java @@ -90,11 +90,13 @@ public class MatchesVarExpansion extends VarExpansion { public static final String VAR_DIFF_REVERSED = "${diffReversed}"; public static final String VAR_SOURCE_LANGUAGE = "${sourceLanguage}"; public static final String VAR_TARGET_LANGUAGE = "${targetLanguage}"; + public static final String VAR_MATCH_SOURCE = "${matchSource}"; private static final String[] MATCHES_VARIABLES = { VAR_ID, VAR_SOURCE_TEXT, VAR_DIFF, VAR_DIFF_REVERSED, VAR_TARGET_TEXT, VAR_SCORE_BASE, VAR_SCORE_NOSTEM, VAR_SCORE_ADJUSTED, VAR_FILE_NAME_ONLY, VAR_FILE_PATH, VAR_FILE_SHORT_PATH, VAR_INITIAL_CREATION_ID, VAR_INITIAL_CREATION_DATE, - VAR_CHANGED_ID, VAR_CHANGED_DATE, VAR_FUZZY_FLAG, VAR_SOURCE_LANGUAGE, VAR_TARGET_LANGUAGE }; + VAR_CHANGED_ID, VAR_CHANGED_DATE, VAR_FUZZY_FLAG, VAR_SOURCE_LANGUAGE, VAR_TARGET_LANGUAGE, + VAR_MATCH_SOURCE }; public static List getMatchesVariables() { return Collections.unmodifiableList(Arrays.asList(MATCHES_VARIABLES)); @@ -102,7 +104,7 @@ public static List getMatchesVariables() { public static final String DEFAULT_TEMPLATE = VAR_ID + ". " + VAR_FUZZY_FLAG + VAR_SOURCE_TEXT + "\n" + VAR_TARGET_TEXT + "\n" + "<" + VAR_SCORE_BASE + "/" + VAR_SCORE_NOSTEM + "/" - + VAR_SCORE_ADJUSTED + "% " + VAR_FILE_PATH + ">"; + + VAR_SCORE_ADJUSTED + "%" + VAR_MATCH_SOURCE + VAR_FILE_PATH + ">"; public static final Pattern PATTERN_SINGLE_PROPERTY = Pattern.compile("@\\{(.+?)\\}"); public static final Pattern PATTERN_PROPERTY_GROUP = Pattern @@ -222,6 +224,22 @@ private String getPropValue(List props, String type) { return null; } + private String expandMatchSource(String localTemplate, NearString.MATCH_SOURCE comesFrom) { + switch(comesFrom) { + case TM: + return localTemplate.replace(VAR_MATCH_SOURCE, OStrings.getString("MATCHES_COMES_FROM_TM") + " "); + case FILES: + return localTemplate.replace(VAR_MATCH_SOURCE, OStrings.getString("MATCHES_COMES_FROM_FILES")); + case MEMORY: + return localTemplate.replace(VAR_MATCH_SOURCE, OStrings.getString( "MATCHES_COMES_FROM_MEMORY")); + case TM_SUBSEG: + return localTemplate.replace(VAR_MATCH_SOURCE, OStrings.getString( + "MATCHES_COMES_FROM_TM_SUBSEG") + " "); + default: + return localTemplate.replace(VAR_MATCH_SOURCE, ""); + } + } + @Override public String expandVariables(NearString match) { // do not modify template directly, so that we can reuse for another @@ -285,6 +303,9 @@ public String expandVariables(NearString match) { } else { localTemplate = localTemplate.replace(VAR_TARGET_TEXT, match.translation); } + + localTemplate = expandMatchSource(localTemplate, match.comesFrom); + return localTemplate; } diff --git a/test/src/org/omegat/gui/matches/MatchesVarExpansionTest.java b/test/src/org/omegat/gui/matches/MatchesVarExpansionTest.java index 8a552c120e..48ead68b18 100644 --- a/test/src/org/omegat/gui/matches/MatchesVarExpansionTest.java +++ b/test/src/org/omegat/gui/matches/MatchesVarExpansionTest.java @@ -45,6 +45,7 @@ import org.omegat.core.data.ProjectProperties; import org.omegat.core.data.SourceTextEntry; import org.omegat.core.matching.NearString; +import org.omegat.core.matching.NearString.MATCH_SOURCE; import org.omegat.gui.editor.IEditor; import org.omegat.gui.editor.IEditorFilter; import org.omegat.gui.editor.IEditorSettings; @@ -208,7 +209,7 @@ public NearString getMockNearString() { entry.changeDate = 20020523; entry.otherProperties = testProps; NearString.Scores scores = new NearString.Scores(20, 40, 60); - return new NearString(null, entry, null, false, scores, null, "mock testing project"); + return new NearString(null, entry, MATCH_SOURCE.TM, false, scores, null, "mock testing project"); }; private void setupProject(Language sourceLanguage, Language targetLanguage) { From 6452974e93ab93840cffc7c58da7c791d4c63fcd Mon Sep 17 00:00:00 2001 From: Hiroshi Miura Date: Wed, 18 Dec 2024 08:36:21 +0900 Subject: [PATCH 2/9] chore: update checkstyle suppressions Signed-off-by: Hiroshi Miura --- config/checkstyle/suppressions.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config/checkstyle/suppressions.xml b/config/checkstyle/suppressions.xml index 0d41dd0143..06fb21a291 100644 --- a/config/checkstyle/suppressions.xml +++ b/config/checkstyle/suppressions.xml @@ -140,7 +140,7 @@ - + From 7df4e20ca5d54f5a05985559580f331e84612689 Mon Sep 17 00:00:00 2001 From: Hiroshi Miura Date: Wed, 18 Dec 2024 08:40:51 +0900 Subject: [PATCH 3/9] style: MatchesVarExpansion spacing Signed-off-by: Hiroshi Miura --- src/org/omegat/gui/matches/MatchesVarExpansion.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/org/omegat/gui/matches/MatchesVarExpansion.java b/src/org/omegat/gui/matches/MatchesVarExpansion.java index 9ea1f692de..a9756ad46b 100644 --- a/src/org/omegat/gui/matches/MatchesVarExpansion.java +++ b/src/org/omegat/gui/matches/MatchesVarExpansion.java @@ -225,13 +225,13 @@ private String getPropValue(List props, String type) { } private String expandMatchSource(String localTemplate, NearString.MATCH_SOURCE comesFrom) { - switch(comesFrom) { + switch (comesFrom) { case TM: return localTemplate.replace(VAR_MATCH_SOURCE, OStrings.getString("MATCHES_COMES_FROM_TM") + " "); case FILES: return localTemplate.replace(VAR_MATCH_SOURCE, OStrings.getString("MATCHES_COMES_FROM_FILES")); case MEMORY: - return localTemplate.replace(VAR_MATCH_SOURCE, OStrings.getString( "MATCHES_COMES_FROM_MEMORY")); + return localTemplate.replace(VAR_MATCH_SOURCE, OStrings.getString("MATCHES_COMES_FROM_MEMORY")); case TM_SUBSEG: return localTemplate.replace(VAR_MATCH_SOURCE, OStrings.getString( "MATCHES_COMES_FROM_TM_SUBSEG") + " "); From dca463900e64ec5f31f11f75b2dd2be8d837e83b Mon Sep 17 00:00:00 2001 From: Hiroshi Miura Date: Wed, 18 Dec 2024 12:57:05 +0900 Subject: [PATCH 4/9] docs: Update NearString javadoc Signed-off-by: Hiroshi Miura --- src/org/omegat/core/matching/NearString.java | 102 ++++++++++++++----- 1 file changed, 76 insertions(+), 26 deletions(-) diff --git a/src/org/omegat/core/matching/NearString.java b/src/org/omegat/core/matching/NearString.java index b3f40cdda7..48e5654c7a 100644 --- a/src/org/omegat/core/matching/NearString.java +++ b/src/org/omegat/core/matching/NearString.java @@ -49,40 +49,81 @@ */ public class NearString { public enum MATCH_SOURCE { + /** From project memory */ MEMORY, + /** From external TM in project tm/ folder */ TM, + /** From files */ FILES, - TM_SUBSEG; + /** From sub-segmented match */ + TM_SUBSEG } public enum SORT_KEY { - SCORE, SCORE_NO_STEM, ADJUSTED_SCORE + /** normal score */ + SCORE, + /** score without stemming */ + SCORE_NO_STEM, + /** adjusted score */ + ADJUSTED_SCORE } - public NearString(EntryKey key, ITMXEntry entry, MATCH_SOURCE comesFrom, boolean fuzzyMark, - Scores scores, byte[] nearData, String projName) { - this(key, entry.getSourceText(), entry.getTranslationText(), comesFrom, fuzzyMark, scores, - nearData, projName, entry.getCreator(), entry.getCreationDate(), entry.getChanger(), + /** + * Constructor. + * + * @param key + * entry key + * @param entry + * the TMX entry that has source text, translation text, creator, + * creation date, changer, change date and properties. + * @param comesFrom + * origin + * @param fuzzyMark + * fuzzy or not + * @param scores + * score values + * @param nearData + * similarity data. + * @param projName + * project name. + */ + public NearString(EntryKey key, ITMXEntry entry, MATCH_SOURCE comesFrom, boolean fuzzyMark, Scores scores, + byte[] nearData, String projName) { + this(key, entry.getSourceText(), entry.getTranslationText(), comesFrom, fuzzyMark, scores, nearData, + projName, entry.getCreator(), entry.getCreationDate(), entry.getChanger(), entry.getChangeDate(), entry.getProperties()); } /** * Constructor, backward compatible. - * @param key entry key - * @param source source text - * @param translation translation text - * @param comesFrom origin - * @param fuzzyMark fuzzy or not + * + * @param key + * entry key + * @param source + * source text + * @param translation + * translation text + * @param comesFrom + * origin + * @param fuzzyMark + * fuzzy or not * @param nearScore * @param nearScoreNoStem * @param adjustedScore - * @param nearData similarity data. - * @param projName project name. - * @param creator creator name - * @param creationDate creation date - * @param changer changer name - * @param changedDate changer date - * @param props properties of entry. + * @param nearData + * similarity data. + * @param projName + * project name. + * @param creator + * creator name + * @param creationDate + * creation date + * @param changer + * changer name + * @param changedDate + * changer date + * @param props + * properties of entry. */ @Deprecated public NearString(EntryKey key, String source, String translation, MATCH_SOURCE comesFrom, @@ -113,14 +154,23 @@ private NearString(EntryKey key, String source, String translation, MATCH_SOURCE /** * Merge NearString object. - * @param ns NearString to merge. - * @param key entry key. - * @param entry TMXEntry entry - * @param comesFrom origin - * @param fuzzyMark fuzzy or not - * @param scores similarity score - * @param nearData similarity data - * @param projName project name + * + * @param ns + * NearString to merge. + * @param key + * entry key. + * @param entry + * TMXEntry entry + * @param comesFrom + * origin + * @param fuzzyMark + * fuzzy or not + * @param scores + * similarity score + * @param nearData + * similarity data + * @param projName + * project name * @return NearString merged. */ public static NearString merge(NearString ns, EntryKey key, ITMXEntry entry, MATCH_SOURCE comesFrom, From 078aacfe8abde179a28a57c7cbbf2616baf7e2a7 Mon Sep 17 00:00:00 2001 From: Hiroshi Miura Date: Thu, 19 Dec 2024 14:53:05 +0900 Subject: [PATCH 5/9] style: update checkstyle suppressions.xml - Ignore NearString warnings Signed-off-by: Hiroshi Miura --- config/checkstyle/suppressions.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/config/checkstyle/suppressions.xml b/config/checkstyle/suppressions.xml index 06fb21a291..3ccb714770 100644 --- a/config/checkstyle/suppressions.xml +++ b/config/checkstyle/suppressions.xml @@ -139,8 +139,8 @@ lines="90,91,92,96,100,104,105,107,264,275,276,284,286,293,294,308,309,359,361,449,495,605,674,710"/> - - + + From 7fffdf09ed4073930f7355498b738af515d9f396 Mon Sep 17 00:00:00 2001 From: Hiroshi Miura Date: Thu, 19 Dec 2024 17:25:54 +0900 Subject: [PATCH 6/9] fix: update bundle key and string to adjust for review feedback Signed-off-by: Hiroshi Miura --- src/org/omegat/Bundle.properties | 8 ++++---- src/org/omegat/gui/matches/MatchesVarExpansion.java | 8 ++++---- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/org/omegat/Bundle.properties b/src/org/omegat/Bundle.properties index c69d8ad647..6bd5b780df 100644 --- a/src/org/omegat/Bundle.properties +++ b/src/org/omegat/Bundle.properties @@ -2948,7 +2948,7 @@ DICTIONARY_LOAD_ERROR=Error load dictionary from '{0}': {1} DICTIONARY_MANAGER_ERROR_SAVE_IGNORE=Error saving ignore words" EDITOR_CONTROLLER_EXCEPTION=bad location exception when changing case -MATCHES_COMES_FROM_TM=From TM -MATCHES_COMES_FROM_FILES=Files -MATCHES_COMES_FROM_MEMORY=From Project -MATCHES_COMES_FROM_TM_SUBSEG=Sub-segmented match +MATCHES_VAR_EXPANSION_MATCH_COMES_FROM_TM=External TM +MATCHES_VAR_EXPANSION_MATCH_COMES_FROM_FILES=Source Files +MATCHES_VAR_EXPANSION_MATCH_COMES_FROM_MEMORY=Project +MATCHES_VAR_EXPANSION_MATCH_COMES_FROM_TM_SUBSEG=Sub-segmented match diff --git a/src/org/omegat/gui/matches/MatchesVarExpansion.java b/src/org/omegat/gui/matches/MatchesVarExpansion.java index a9756ad46b..67d950cdeb 100644 --- a/src/org/omegat/gui/matches/MatchesVarExpansion.java +++ b/src/org/omegat/gui/matches/MatchesVarExpansion.java @@ -227,14 +227,14 @@ private String getPropValue(List props, String type) { private String expandMatchSource(String localTemplate, NearString.MATCH_SOURCE comesFrom) { switch (comesFrom) { case TM: - return localTemplate.replace(VAR_MATCH_SOURCE, OStrings.getString("MATCHES_COMES_FROM_TM") + " "); + return localTemplate.replace(VAR_MATCH_SOURCE, OStrings.getString("MATCHES_VAR_EXPANSION_MATCH_COMES_FROM_TM") + " "); case FILES: - return localTemplate.replace(VAR_MATCH_SOURCE, OStrings.getString("MATCHES_COMES_FROM_FILES")); + return localTemplate.replace(VAR_MATCH_SOURCE, OStrings.getString("MATCHES_VAR_EXPANSION_MATCH_COMES_FROM_FILES")); case MEMORY: - return localTemplate.replace(VAR_MATCH_SOURCE, OStrings.getString("MATCHES_COMES_FROM_MEMORY")); + return localTemplate.replace(VAR_MATCH_SOURCE, OStrings.getString("MATCHES_VAR_EXPANSION_MATCH_COMES_FROM_MEMORY")); case TM_SUBSEG: return localTemplate.replace(VAR_MATCH_SOURCE, OStrings.getString( - "MATCHES_COMES_FROM_TM_SUBSEG") + " "); + "MATCHES_VAR_EXPANSION_MATCH_COMES_FROM_TM_SUBSEG") + " "); default: return localTemplate.replace(VAR_MATCH_SOURCE, ""); } From 4db0ff1b818516182341385cdf19c80e92217947 Mon Sep 17 00:00:00 2001 From: Hiroshi Miura Date: Thu, 19 Dec 2024 17:29:47 +0900 Subject: [PATCH 7/9] fix: update acceptance test expectation Signed-off-by: Hiroshi Miura --- .../src/org/omegat/gui/matches/MatchesTextAreaTest.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/test-acceptance/src/org/omegat/gui/matches/MatchesTextAreaTest.java b/test-acceptance/src/org/omegat/gui/matches/MatchesTextAreaTest.java index 252a7db7d9..76754584d0 100644 --- a/test-acceptance/src/org/omegat/gui/matches/MatchesTextAreaTest.java +++ b/test-acceptance/src/org/omegat/gui/matches/MatchesTextAreaTest.java @@ -53,7 +53,8 @@ public void testFuzzyMatches() throws Exception { window.textBox("matches_pane").requireNotEditable(); Pattern pattern = Pattern.compile("1. Error while reading MT results\\n" + "Erreur lors de la lecture des résultats de TA\\n" - + "<\\d+/\\d+/\\d+%\\s*>"); + + "<\\d+/\\d+/\\d+%\\s*" + OStrings.getString( + "MATCHES_VAR_EXPANSION_MATCH_COMES_FROM_MEMORY") + "\\s*>"); window.textBox("matches_pane").requireText(pattern); closeProject(); } From e9db7fbc7b4fa936cde081b655542a478445488e Mon Sep 17 00:00:00 2001 From: Hiroshi Miura Date: Thu, 26 Dec 2024 07:17:06 +0900 Subject: [PATCH 8/9] Apply suggestions from code review --- src/org/omegat/core/matching/NearString.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/org/omegat/core/matching/NearString.java b/src/org/omegat/core/matching/NearString.java index 48e5654c7a..bdaef735fa 100644 --- a/src/org/omegat/core/matching/NearString.java +++ b/src/org/omegat/core/matching/NearString.java @@ -53,10 +53,10 @@ public enum MATCH_SOURCE { MEMORY, /** From external TM in project tm/ folder */ TM, - /** From files */ + /** From source files */ FILES, /** From sub-segmented match */ - TM_SUBSEG + SUBSEGMENTS } public enum SORT_KEY { From 8cf99d028596a3cd931b0e745b58b0b8ba2010f6 Mon Sep 17 00:00:00 2001 From: Hiroshi Miura Date: Thu, 26 Dec 2024 07:19:54 +0900 Subject: [PATCH 9/9] Apply suggestions from code review --- src/org/omegat/gui/matches/MatchesVarExpansion.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/org/omegat/gui/matches/MatchesVarExpansion.java b/src/org/omegat/gui/matches/MatchesVarExpansion.java index 67d950cdeb..f54fc87ef3 100644 --- a/src/org/omegat/gui/matches/MatchesVarExpansion.java +++ b/src/org/omegat/gui/matches/MatchesVarExpansion.java @@ -232,7 +232,7 @@ private String expandMatchSource(String localTemplate, NearString.MATCH_SOURCE c return localTemplate.replace(VAR_MATCH_SOURCE, OStrings.getString("MATCHES_VAR_EXPANSION_MATCH_COMES_FROM_FILES")); case MEMORY: return localTemplate.replace(VAR_MATCH_SOURCE, OStrings.getString("MATCHES_VAR_EXPANSION_MATCH_COMES_FROM_MEMORY")); - case TM_SUBSEG: + case SUBSEGMENTS: return localTemplate.replace(VAR_MATCH_SOURCE, OStrings.getString( "MATCHES_VAR_EXPANSION_MATCH_COMES_FROM_TM_SUBSEG") + " "); default: