use of org.omegat.core.data.TMXEntry in project omegat by omegat-org.
the class MainWindowMenuHandler method editExportSelectionMenuItemActionPerformed.
public void editExportSelectionMenuItemActionPerformed() {
if (!Core.getProject().isProjectLoaded()) {
return;
}
String selection = Core.getEditor().getSelectedText();
if (selection == null) {
SourceTextEntry ste = Core.getEditor().getCurrentEntry();
TMXEntry te = Core.getProject().getTranslationInfo(ste);
if (te.isTranslated()) {
selection = te.translation;
} else {
selection = ste.getSrcText();
}
}
SegmentExportImport.exportCurrentSelection(selection);
}
use of org.omegat.core.data.TMXEntry in project omegat by omegat-org.
the class TagIssue method doFix.
/**
* Fix all errors in a given report, and commit the changed translation to
* the project. Checks to make sure the translation has not been changed in
* the meantime.
*
* @param report
* The report to fix
* @return Whether or not the fix succeeded
*/
private static boolean doFix(ErrorReport report, String fixed) {
// Make sure the translation hasn't changed in the editor.
TMXEntry prevTrans = Core.getProject().getTranslationInfo(report.ste);
if (!report.translation.equals(prevTrans.translation)) {
return false;
}
// Put modified translation back into project.
Core.getEditor().gotoEntry(report.entryNum);
Core.getEditor().replaceEditTextAndMark(fixed);
return true;
}
use of org.omegat.core.data.TMXEntry in project omegat by omegat-org.
the class Searcher method searchMemory.
private void searchMemory() throws SearchLimitReachedException {
// search the Memory, if requested
if (searchExpression.memory) {
// search through all project entries
List<SourceTextEntry> allEntries = m_project.getAllEntries();
for (int i = 0; i < allEntries.size(); i++) {
// stop searching if the max. nr of hits has been reached
if (m_numFinds >= searchExpression.numberOfResults) {
throw new SearchLimitReachedException();
}
// get the source and translation of the next entry
SourceTextEntry ste = allEntries.get(i);
TMXEntry te = m_project.getTranslationInfo(ste);
checkEntry(ste.getSrcText(), te.translation, te.note, ste.getRawProperties(), te, i, null);
checkStop.checkInterrupted();
}
// search in orphaned
if (!searchExpression.excludeOrphans) {
m_project.iterateByDefaultTranslations(new IProject.DefaultTranslationsIterator() {
final String file = OStrings.getString("CT_ORPHAN_STRINGS");
public void iterate(String source, TMXEntry en) {
// stop searching if the max. nr of hits has been reached
if (m_numFinds >= searchExpression.numberOfResults) {
return;
}
checkStop.checkInterrupted();
if (m_project.isOrphaned(source)) {
checkEntry(en.source, en.translation, en.note, null, en, ENTRY_ORIGIN_ORPHAN, file);
}
}
});
m_project.iterateByMultipleTranslations(new IProject.MultipleTranslationsIterator() {
final String file = OStrings.getString("CT_ORPHAN_STRINGS");
public void iterate(EntryKey source, TMXEntry en) {
// reached
if (m_numFinds >= searchExpression.numberOfResults) {
return;
}
checkStop.checkInterrupted();
if (m_project.isOrphaned(source)) {
checkEntry(en.source, en.translation, en.note, null, en, ENTRY_ORIGIN_ORPHAN, file);
}
}
});
}
}
}
use of org.omegat.core.data.TMXEntry in project omegat by omegat-org.
the class FindMatches method search.
public List<NearString> search(final String searchText, final boolean requiresTranslation, final boolean fillSimilarityData, final IStopped stop) throws StoppedException {
result = new ArrayList<>(OConsts.MAX_NEAR_STRINGS + 1);
srcText = searchText;
removedText = "";
// of the translatable text
if (removePattern != null) {
StringBuilder removedBuffer = new StringBuilder();
Matcher removeMatcher = removePattern.matcher(srcText);
while (removeMatcher.find()) {
removedBuffer.append(removeMatcher.group());
}
srcText = removeMatcher.replaceAll("");
removedText = removedBuffer.toString();
}
// get tokens for original string
strTokensStem = tokenizeStem(srcText);
strTokensNoStem = tokenizeNoStem(srcText);
strTokensAll = tokenizeAll(srcText);
// travel by project entries, including orphaned
if (project.getProjectProperties().isSupportDefaultTranslations()) {
project.iterateByDefaultTranslations(new DefaultTranslationsIterator() {
public void iterate(String source, TMXEntry trans) {
checkStopped(stop);
if (!searchExactlyTheSame && source.equals(searchText)) {
// skip original==original entry comparison
return;
}
if (requiresTranslation && trans.translation == null) {
return;
}
String fileName = project.isOrphaned(source) ? ORPHANED_FILE_NAME : null;
processEntry(null, source, trans.translation, NearString.MATCH_SOURCE.MEMORY, false, 0, fileName, trans.creator, trans.creationDate, trans.changer, trans.changeDate, null);
}
});
}
project.iterateByMultipleTranslations(new MultipleTranslationsIterator() {
public void iterate(EntryKey source, TMXEntry trans) {
checkStopped(stop);
if (!searchExactlyTheSame && source.sourceText.equals(searchText)) {
// skip original==original entry comparison
return;
}
if (requiresTranslation && trans.translation == null) {
return;
}
String fileName = project.isOrphaned(source) ? ORPHANED_FILE_NAME : null;
processEntry(source, source.sourceText, trans.translation, NearString.MATCH_SOURCE.MEMORY, false, 0, fileName, trans.creator, trans.creationDate, trans.changer, trans.changeDate, null);
}
});
/*
Penalty applied for fuzzy matches in another language (if no match in the
target language was found).
*/
int foreignPenalty = Preferences.getPreferenceDefault(Preferences.PENALTY_FOR_FOREIGN_MATCHES, Preferences.PENALTY_FOR_FOREIGN_MATCHES_DEFAULT);
// travel by translation memories
for (Map.Entry<String, ExternalTMX> en : project.getTransMemories().entrySet()) {
int penalty = 0;
Matcher matcher = SEARCH_FOR_PENALTY.matcher(en.getKey());
if (matcher.find()) {
penalty = Integer.parseInt(matcher.group(1));
}
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.
continue;
}
if (requiresTranslation && tmen.getTranslationText() == null) {
continue;
}
int tmenPenalty = penalty;
if (tmen.hasPropValue(ExternalTMFactory.TMXLoader.PROP_FOREIGN_MATCH, "true")) {
tmenPenalty += foreignPenalty;
}
processEntry(null, tmen.getSourceText(), tmen.getTranslationText(), NearString.MATCH_SOURCE.TM, false, tmenPenalty, en.getKey(), tmen.getCreator(), tmen.getCreationDate(), tmen.getChanger(), tmen.getChangeDate(), tmen.getProperties());
}
}
// travel by all entries for check source file translations
for (SourceTextEntry ste : project.getAllEntries()) {
checkStopped(stop);
if (ste.getSourceTranslation() != null) {
processEntry(ste.getKey(), ste.getSrcText(), ste.getSourceTranslation(), NearString.MATCH_SOURCE.MEMORY, ste.isSourceTranslationFuzzy(), 0, ste.getKey().file, "", 0, "", 0, null);
}
}
if (separateSegmentMatcher != null) {
// split paragraph even when segmentation disabled, then find matches for every segment
List<StringBuilder> spaces = new ArrayList<StringBuilder>();
List<Rule> brules = new ArrayList<Rule>();
Language sourceLang = project.getProjectProperties().getSourceLanguage();
Language targetLang = project.getProjectProperties().getTargetLanguage();
List<String> segments = Core.getSegmenter().segment(sourceLang, srcText, spaces, brules);
if (segments.size() > 1) {
List<String> fsrc = new ArrayList<String>(segments.size());
List<String> ftrans = new ArrayList<String>(segments.size());
// multiple segments
for (short i = 0; i < segments.size(); i++) {
String onesrc = segments.get(i);
// find match for separate segment
List<NearString> segmentMatch = separateSegmentMatcher.search(onesrc, requiresTranslation, false, stop);
if (!segmentMatch.isEmpty() && segmentMatch.get(0).scores[0].score >= SUBSEGMENT_MATCH_THRESHOLD) {
fsrc.add(segmentMatch.get(0).source);
ftrans.add(segmentMatch.get(0).translation);
} else {
fsrc.add("");
ftrans.add("");
}
}
// glue found sources
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);
}
}
if (fillSimilarityData) {
// fill similarity data only for result
for (NearString near : result) {
// fix for bug 1586397
byte[] similarityData = FuzzyMatcher.buildSimilarityData(strTokensAll, tokenizeAll(near.source));
near.attr = similarityData;
}
}
return result;
}
use of org.omegat.core.data.TMXEntry in project omegat by omegat-org.
the class Main method runConsoleAlign.
public static int runConsoleAlign() throws Exception {
Log.log("Console alignment mode");
Log.log("");
if (projectLocation == null) {
System.out.println(OStrings.getString("PP_ERROR_UNABLE_TO_READ_PROJECT_FILE"));
return 1;
}
String dir = PARAMS.get(CLIParameters.ALIGNDIR);
if (dir == null) {
System.out.println(OStrings.getString("CONSOLE_TRANSLATED_FILES_LOC_UNDEFINED"));
return 1;
}
System.out.println(OStrings.getString("CONSOLE_INITIALIZING"));
Core.initializeConsole(PARAMS);
RealProject p = selectProjectConsoleMode(true);
validateTagsConsoleMode();
System.out.println(StringUtil.format(OStrings.getString("CONSOLE_ALIGN_AGAINST"), dir));
Map<String, TMXEntry> data = p.align(p.getProjectProperties(), new File(dir));
Map<String, PrepareTMXEntry> result = new TreeMap<>();
for (Map.Entry<String, TMXEntry> en : data.entrySet()) {
result.put(en.getKey(), new PrepareTMXEntry(en.getValue()));
}
String tmxFile = p.getProjectProperties().getProjectInternal() + "align.tmx";
TMXWriter.buildTMXFile(tmxFile, false, false, p.getProjectProperties(), result);
p.closeProject();
System.out.println(OStrings.getString("CONSOLE_FINISHED"));
return 0;
}
Aggregations