-
-
Notifications
You must be signed in to change notification settings - Fork 113
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
[BUGS#1251][6.0][backport] fix: FindMatches#search ignore penalty when segmented matches #1215
Open
miurahr
wants to merge
4
commits into
releases/6.0
Choose a base branch
from
topic/miurahr/releases/6.0/backport/find-matches-ignore-penalty
base: releases/6.0
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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 | ||||
---|---|---|---|---|---|---|
|
@@ -30,10 +30,12 @@ | |||||
|
||||||
import java.util.ArrayList; | ||||||
import java.util.HashMap; | ||||||
import java.util.HashSet; | ||||||
import java.util.List; | ||||||
import java.util.Locale; | ||||||
import java.util.Map; | ||||||
import java.util.Objects; | ||||||
import java.util.Set; | ||||||
import java.util.regex.Matcher; | ||||||
import java.util.regex.Pattern; | ||||||
|
||||||
|
@@ -273,6 +275,8 @@ public void iterate(EntryKey source, TMXEntry trans) { | |||||
if (separateSegmentMatcher != null) { | ||||||
// split paragraph even when segmentation disabled, then find | ||||||
// matches for every segment | ||||||
int maxPenalty = 0; | ||||||
Set<String> tmxNames = new HashSet<>(); | ||||||
List<StringBuilder> spaces = new ArrayList<StringBuilder>(); | ||||||
List<Rule> brules = new ArrayList<Rule>(); | ||||||
Language sourceLang = project.getProjectProperties().getSourceLanguage(); | ||||||
|
@@ -292,6 +296,14 @@ public void iterate(EntryKey source, TMXEntry trans) { | |||||
&& segmentMatch.get(0).scores[0].score >= SUBSEGMENT_MATCH_THRESHOLD) { | ||||||
fsrc.add(segmentMatch.get(0).source); | ||||||
ftrans.add(segmentMatch.get(0).translation); | ||||||
segmentMatch.stream().filter(match -> !match.projs[0].isEmpty()) | ||||||
.map(match -> match.projs[0]).forEach(tmxNames::add); | ||||||
if (segmentMatch.get(0).fuzzyMark) { | ||||||
if (maxPenalty < PENALTY_FOR_FUZZY) { | ||||||
maxPenalty = PENALTY_FOR_FUZZY; | ||||||
} | ||||||
} | ||||||
maxPenalty = Math.max(maxPenalty, segmentMatch.get(0).scores[0].penalty); | ||||||
} else { | ||||||
fsrc.add(""); | ||||||
ftrans.add(""); | ||||||
|
@@ -301,8 +313,8 @@ public void iterate(EntryKey source, TMXEntry trans) { | |||||
String foundSrc = Core.getSegmenter().glue(sourceLang, sourceLang, fsrc, spaces, brules); | ||||||
// glue found translations | ||||||
String foundTrans = Core.getSegmenter().glue(sourceLang, targetLang, ftrans, spaces, brules); | ||||||
processEntry(null, foundSrc, foundTrans, NearString.MATCH_SOURCE.TM, false, 0, "", "", 0, "", | ||||||
0, null); | ||||||
processEntry(null, foundSrc, foundTrans, NearString.MATCH_SOURCE.TM_SUBSEG, false, maxPenalty, | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
String.join(",", tmxNames), "", 0, "", 0, null); | ||||||
} | ||||||
} | ||||||
|
||||||
|
@@ -421,8 +433,9 @@ protected void processEntry(EntryKey key, String source, String translation, | |||||
return; | ||||||
} | ||||||
|
||||||
addNearString(key, source, translation, comesFrom, fuzzy, similarityStem, similarityNoStem, | ||||||
simAdjusted, null, tmxName, creator, creationDate, changer, changedDate, props); | ||||||
addNearString(key, source, translation, comesFrom, fuzzy, new NearString.Scores(similarityStem, | ||||||
similarityNoStem, simAdjusted, penalty), | ||||||
null, tmxName, creator, creationDate, changer, changedDate, props); | ||||||
} | ||||||
|
||||||
/** | ||||||
|
@@ -457,8 +470,7 @@ protected boolean haveChanceToAdd(final int simStem, final int simNoStem, final | |||||
* "similarity,simAdjusted" | ||||||
*/ | ||||||
protected void addNearString(final EntryKey key, final String source, final String translation, | ||||||
NearString.MATCH_SOURCE comesFrom, final boolean fuzzy, final int similarity, | ||||||
final int similarityNoStem, final int simAdjusted, final byte[] similarityData, | ||||||
NearString.MATCH_SOURCE comesFrom, final boolean fuzzy, NearString.Scores scores, final byte[] similarityData, | ||||||
final String tmxName, final String creator, final long creationDate, final String changer, | ||||||
final long changedDate, final List<TMXProp> tuProperties) { | ||||||
// find position for new data | ||||||
|
@@ -470,25 +482,25 @@ protected void addNearString(final EntryKey key, final String source, final Stri | |||||
// single NearString with | ||||||
// multiple project entries. | ||||||
result.set(i, | ||||||
NearString.merge(st, key, source, translation, comesFrom, fuzzy, similarity, | ||||||
similarityNoStem, simAdjusted, similarityData, tmxName, creator, creationDate, | ||||||
NearString.merge(st, key, source, translation, comesFrom, fuzzy, | ||||||
scores, similarityData, tmxName, creator, creationDate, | ||||||
changer, changedDate, tuProperties)); | ||||||
return; | ||||||
} | ||||||
if (st.scores[0].score < similarity) { | ||||||
if (st.scores[0].score < scores.score) { | ||||||
break; | ||||||
} | ||||||
if (st.scores[0].score == similarity) { | ||||||
if (st.scores[0].scoreNoStem < similarityNoStem) { | ||||||
if (st.scores[0].score == scores.score) { | ||||||
if (st.scores[0].scoreNoStem < scores.scoreNoStem) { | ||||||
break; | ||||||
} | ||||||
if (st.scores[0].scoreNoStem == similarityNoStem) { | ||||||
if (st.scores[0].adjustedScore < simAdjusted) { | ||||||
if (st.scores[0].scoreNoStem == scores.scoreNoStem) { | ||||||
if (st.scores[0].adjustedScore < scores.adjustedScore) { | ||||||
break; | ||||||
} | ||||||
// Patch contributed by Antonio Vilei | ||||||
// text with the same case has precedence | ||||||
if (similarity == 100 && !st.source.equals(srcText) && source.equals(srcText)) { | ||||||
if (scores.score == 100 && !st.source.equals(srcText) && source.equals(srcText)) { | ||||||
break; | ||||||
} | ||||||
} | ||||||
|
@@ -497,9 +509,8 @@ protected void addNearString(final EntryKey key, final String source, final Stri | |||||
} | ||||||
|
||||||
result.add(pos, | ||||||
new NearString(key, source, translation, comesFrom, fuzzy, similarity, similarityNoStem, | ||||||
simAdjusted, similarityData, tmxName, creator, creationDate, changer, changedDate, | ||||||
tuProperties)); | ||||||
new NearString(key, source, translation, comesFrom, fuzzy, scores, similarityData, tmxName, creator, | ||||||
creationDate, changer, changedDate, tuProperties)); | ||||||
if (result.size() > maxCount) { | ||||||
result.remove(result.size() - 1); | ||||||
} | ||||||
|
@@ -508,9 +519,9 @@ protected void addNearString(final EntryKey key, final String source, final Stri | |||||
/* | ||||||
* Methods for tokenize strings with caching. | ||||||
*/ | ||||||
Map<String, Token[]> tokenizeStemCache = new HashMap<String, Token[]>(); | ||||||
Map<String, Token[]> tokenizeNoStemCache = new HashMap<String, Token[]>(); | ||||||
Map<String, Token[]> tokenizeAllCache = new HashMap<String, Token[]>(); | ||||||
Map<String, Token[]> tokenizeStemCache = new HashMap<>(); | ||||||
Map<String, Token[]> tokenizeNoStemCache = new HashMap<>(); | ||||||
Map<String, Token[]> tokenizeAllCache = new HashMap<>(); | ||||||
|
||||||
public Token[] tokenizeStem(String str) { | ||||||
Token[] tokens = tokenizeStemCache.get(str); | ||||||
|
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> |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.