From: <al...@us...> - 2009-10-02 08:27:58
|
Revision: 2370 http://omegat.svn.sourceforge.net/omegat/?rev=2370&view=rev Author: alex73 Date: 2009-10-02 08:27:47 +0000 (Fri, 02 Oct 2009) Log Message: ----------- Add new match statistics: 100% match removed, chars count added Modified Paths: -------------- trunk/src/org/omegat/Bundle.properties trunk/src/org/omegat/core/statistics/CalcMatchStatistics.java trunk/src/org/omegat/core/statistics/MatchStatisticsInfo.java trunk/src/org/omegat/core/statistics/Statistics.java trunk/src/org/omegat/gui/stat/StatisticsWindow.java Modified: trunk/src/org/omegat/Bundle.properties =================================================================== --- trunk/src/org/omegat/Bundle.properties 2009-10-02 08:21:56 UTC (rev 2369) +++ trunk/src/org/omegat/Bundle.properties 2009-10-02 08:27:47 UTC (rev 2370) @@ -429,11 +429,8 @@ CT_STATSMATCH_WindowHeader=Match Statistics -CT_STATSMATCH_ColumnSegments=Segments -CT_STATSMATCH_ColumnWords=Words CT_STATSMATCH_RowExactMatch=Exact match: -CT_STATSMATCH_RowMatch100=100%: -CT_STATSMATCH_RowMatch95=95%-99%: +CT_STATSMATCH_RowMatch95=95%-100%: CT_STATSMATCH_RowMatch85=85%-94%: CT_STATSMATCH_RowMatch75=75%-84%: CT_STATSMATCH_RowMatch50=50%-74%: Modified: trunk/src/org/omegat/core/statistics/CalcMatchStatistics.java =================================================================== --- trunk/src/org/omegat/core/statistics/CalcMatchStatistics.java 2009-10-02 08:21:56 UTC (rev 2369) +++ trunk/src/org/omegat/core/statistics/CalcMatchStatistics.java 2009-10-02 08:27:47 UTC (rev 2370) @@ -33,6 +33,7 @@ import org.omegat.core.matching.ISimilarityCalculator; import org.omegat.core.matching.LevenshteinDistance; import org.omegat.core.threads.LongProcessThread; +import org.omegat.util.StaticUtils; import org.omegat.util.Token; /** @@ -62,8 +63,14 @@ int p = Statistics.getMaxSimilarityPercent(ste, distanceCalculator, allEntries, tokensCache); int r = result.getRowByPercent(p); + result.rows[r].segments++; result.rows[r].words += Statistics.numberOfWords(ste.getSrcText()); + String charWithoutTags = StaticUtils.stripTags(ste.getSrcText()); + result.rows[r].charsWithoutSpaces += Statistics + .numberOfCharactersWithoutSpaces(charWithoutTags); + result.rows[r].charsWithSpaces += charWithoutTags.length(); + if (isStopped) { return; } Modified: trunk/src/org/omegat/core/statistics/MatchStatisticsInfo.java =================================================================== --- trunk/src/org/omegat/core/statistics/MatchStatisticsInfo.java 2009-10-02 08:21:56 UTC (rev 2369) +++ trunk/src/org/omegat/core/statistics/MatchStatisticsInfo.java 2009-10-02 08:27:47 UTC (rev 2370) @@ -37,14 +37,14 @@ public final Row[] rows; public MatchStatisticsInfo() { - rows = new Row[7]; + rows = new Row[6]; for (int i = 0; i < rows.length; i++) { rows[i] = new Row(); } } public static class Row { - public int segments, words; + public int segments, words, charsWithoutSpaces, charsWithSpaces; } /** @@ -58,18 +58,16 @@ if (percent == Integer.MAX_VALUE) { // exact match return 0; - } else if (percent == 100) { - return 1; } else if (percent >= 95) { - return 2; + return 1; } else if (percent >= 85) { - return 3; + return 2; } else if (percent >= 75) { - return 4; + return 3; } else if (percent >= 50) { - return 5; + return 4; } else { - return 6; + return 5; } } } Modified: trunk/src/org/omegat/core/statistics/Statistics.java =================================================================== --- trunk/src/org/omegat/core/statistics/Statistics.java 2009-10-02 08:21:56 UTC (rev 2369) +++ trunk/src/org/omegat/core/statistics/Statistics.java 2009-10-02 08:27:47 UTC (rev 2370) @@ -310,7 +310,7 @@ } /** Computes the number of characters excluding spaces in a string. */ - private static int numberOfCharactersWithoutSpaces(String str) { + public static int numberOfCharactersWithoutSpaces(String str) { int chars = 0; for (int i = 0; i < str.length(); i++) { if (!Character.isSpaceChar(str.charAt(i))) Modified: trunk/src/org/omegat/gui/stat/StatisticsWindow.java =================================================================== --- trunk/src/org/omegat/gui/stat/StatisticsWindow.java 2009-10-02 08:21:56 UTC (rev 2369) +++ trunk/src/org/omegat/gui/stat/StatisticsWindow.java 2009-10-02 08:27:47 UTC (rev 2370) @@ -70,10 +70,12 @@ }; String[] header = new String[] { "", - OStrings.getString("CT_STATSMATCH_ColumnSegments"), - OStrings.getString("CT_STATSMATCH_ColumnWords") }; + OStrings.getString("CT_STATS_Segments"), + OStrings.getString("CT_STATS_Words"), + OStrings.getString("CT_STATS_Characters_NOSP"), + OStrings.getString("CT_STATS_Characters") }; - boolean[] align = new boolean[] { false, true, true }; + boolean[] align = new boolean[] { false, true, true, true, true }; private JProgressBar progressBar; private JTextArea output; private LongProcessThread thread; @@ -197,7 +199,7 @@ * @return text table */ protected String[][] calcTable(final MatchStatisticsInfo result) { - String[][] table = new String[7][3]; + String[][] table = new String[6][5]; // dump result - will be changed for UI for (int i = 0; i < result.rows.length; i++) { switch (i) { @@ -205,26 +207,25 @@ table[i][0] = OStrings.getString("CT_STATSMATCH_RowExactMatch"); break; case 1: - table[i][0] = OStrings.getString("CT_STATSMATCH_RowMatch100"); + table[i][0] = OStrings.getString("CT_STATSMATCH_RowMatch95"); break; case 2: - table[i][0] = OStrings.getString("CT_STATSMATCH_RowMatch95"); + table[i][0] = OStrings.getString("CT_STATSMATCH_RowMatch85"); break; case 3: - table[i][0] = OStrings.getString("CT_STATSMATCH_RowMatch85"); + table[i][0] = OStrings.getString("CT_STATSMATCH_RowMatch75"); break; case 4: - table[i][0] = OStrings.getString("CT_STATSMATCH_RowMatch75"); + table[i][0] = OStrings.getString("CT_STATSMATCH_RowMatch50"); break; case 5: - table[i][0] = OStrings.getString("CT_STATSMATCH_RowMatch50"); - break; - case 6: table[i][0] = OStrings.getString("CT_STATSMATCH_RowNoMatch"); break; } table[i][1] = Integer.toString(result.rows[i].segments); table[i][2] = Integer.toString(result.rows[i].words); + table[i][3] = Integer.toString(result.rows[i].charsWithoutSpaces); + table[i][4] = Integer.toString(result.rows[i].charsWithSpaces); } return table; } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <al...@us...> - 2009-10-02 10:37:09
|
Revision: 2371 http://omegat.svn.sourceforge.net/omegat/?rev=2371&view=rev Author: alex73 Date: 2009-10-02 10:36:49 +0000 (Fri, 02 Oct 2009) Log Message: ----------- Add new match statistics: repetitions Modified Paths: -------------- trunk/src/org/omegat/Bundle.properties trunk/src/org/omegat/core/statistics/CalcMatchStatistics.java trunk/src/org/omegat/core/statistics/CalcStandardStatistics.java trunk/src/org/omegat/core/statistics/MatchStatisticsInfo.java trunk/src/org/omegat/core/statistics/Statistics.java trunk/src/org/omegat/gui/stat/StatisticsWindow.java Modified: trunk/src/org/omegat/Bundle.properties =================================================================== --- trunk/src/org/omegat/Bundle.properties 2009-10-02 08:27:47 UTC (rev 2370) +++ trunk/src/org/omegat/Bundle.properties 2009-10-02 10:36:49 UTC (rev 2371) @@ -429,6 +429,7 @@ CT_STATSMATCH_WindowHeader=Match Statistics +CT_STATSMATCH_RowRepetitions=Repetitions: CT_STATSMATCH_RowExactMatch=Exact match: CT_STATSMATCH_RowMatch95=95%-100%: CT_STATSMATCH_RowMatch85=85%-94%: Modified: trunk/src/org/omegat/core/statistics/CalcMatchStatistics.java =================================================================== --- trunk/src/org/omegat/core/statistics/CalcMatchStatistics.java 2009-10-02 08:27:47 UTC (rev 2370) +++ trunk/src/org/omegat/core/statistics/CalcMatchStatistics.java 2009-10-02 10:36:49 UTC (rev 2371) @@ -25,8 +25,10 @@ package org.omegat.core.statistics; import java.util.HashMap; +import java.util.HashSet; import java.util.List; import java.util.Map; +import java.util.Set; import org.omegat.core.Core; import org.omegat.core.data.SourceTextEntry; @@ -46,6 +48,9 @@ /** Hash for exact tokens. Only for statistics calculation. */ private Map<String, Token[]> tokensCache = new HashMap<String, Token[]>(); + + /** Already processed segments. Used for repetitions detect.*/ + private Set<String> alreadyProcessed = new HashSet<String>(); public CalcMatchStatistics(Callback callback) { this.callback = callback; @@ -61,7 +66,7 @@ for (int i = 0; i < allEntries.size(); i++) { SourceTextEntry ste = allEntries.get(i); int p = Statistics.getMaxSimilarityPercent(ste, distanceCalculator, - allEntries, tokensCache); + allEntries, tokensCache, alreadyProcessed); int r = result.getRowByPercent(p); result.rows[r].segments++; Modified: trunk/src/org/omegat/core/statistics/CalcStandardStatistics.java =================================================================== --- trunk/src/org/omegat/core/statistics/CalcStandardStatistics.java 2009-10-02 08:27:47 UTC (rev 2370) +++ trunk/src/org/omegat/core/statistics/CalcStandardStatistics.java 2009-10-02 10:36:49 UTC (rev 2371) @@ -31,6 +31,8 @@ /** * Thread for calculate standard statistics. * + * TODO: move this statistics into pane in main window + * * @author Alex Buloichik (ale...@gm...) */ public class CalcStandardStatistics extends LongProcessThread { Modified: trunk/src/org/omegat/core/statistics/MatchStatisticsInfo.java =================================================================== --- trunk/src/org/omegat/core/statistics/MatchStatisticsInfo.java 2009-10-02 08:27:47 UTC (rev 2370) +++ trunk/src/org/omegat/core/statistics/MatchStatisticsInfo.java 2009-10-02 10:36:49 UTC (rev 2371) @@ -37,7 +37,7 @@ public final Row[] rows; public MatchStatisticsInfo() { - rows = new Row[6]; + rows = new Row[7]; for (int i = 0; i < rows.length; i++) { rows[i] = new Row(); } @@ -55,19 +55,22 @@ * @return row index */ public int getRowByPercent(int percent) { - if (percent == Integer.MAX_VALUE) { + if (percent == Statistics.PERCENT_REPETITIONS) { + // repetitions + return 0; + } else if (percent == Statistics.PERCENT_EXACT_MATCH) { // exact match - return 0; + return 1; } else if (percent >= 95) { - return 1; + return 2; } else if (percent >= 85) { - return 2; + return 3; } else if (percent >= 75) { - return 3; + return 4; } else if (percent >= 50) { - return 4; + return 5; } else { - return 5; + return 6; } } } Modified: trunk/src/org/omegat/core/statistics/Statistics.java =================================================================== --- trunk/src/org/omegat/core/statistics/Statistics.java 2009-10-02 08:27:47 UTC (rev 2370) +++ trunk/src/org/omegat/core/statistics/Statistics.java 2009-10-02 10:36:49 UTC (rev 2371) @@ -34,6 +34,7 @@ import java.text.BreakIterator; import java.util.List; import java.util.Map; +import java.util.Set; import java.util.TreeMap; import org.omegat.core.Core; @@ -231,6 +232,9 @@ return result.toString(); } + protected static final int PERCENT_EXACT_MATCH = 101; + protected static final int PERCENT_REPETITIONS = 101; + /** * Calculate max similarity percent for one entry. * @@ -245,12 +249,14 @@ public static int getMaxSimilarityPercent(final SourceTextEntry ste, final ISimilarityCalculator distanceCalculator, final List<SourceTextEntry> allEntries, - final Map<String, Token[]> tokensCache) { + final Map<String, Token[]> tokensCache,final Set<String> alreadyProcessed) { + + boolean isFirst=alreadyProcessed.add(ste.getSrcText()); if (!StringUtil.isEmpty(ste.getTranslation())) { // segment has translation - should be calculated as // "Exact matched" - return Integer.MAX_VALUE; + return PERCENT_EXACT_MATCH; } Token[] strTokensStem = tokenizeExactlyWithCache(tokensCache, ste @@ -287,6 +293,15 @@ strTokensStem, candTokens); maxSimilarity = Math.max(maxSimilarity, newSimilarity); } + + if (maxSimilarity < 50) { + // No match. Need to add only first segment. Next segments will + // be 'repetition'. + if (!isFirst) { + maxSimilarity = PERCENT_REPETITIONS; + } + } + return maxSimilarity; } Modified: trunk/src/org/omegat/gui/stat/StatisticsWindow.java =================================================================== --- trunk/src/org/omegat/gui/stat/StatisticsWindow.java 2009-10-02 08:27:47 UTC (rev 2370) +++ trunk/src/org/omegat/gui/stat/StatisticsWindow.java 2009-10-02 10:36:49 UTC (rev 2371) @@ -199,26 +199,29 @@ * @return text table */ protected String[][] calcTable(final MatchStatisticsInfo result) { - String[][] table = new String[6][5]; + String[][] table = new String[7][5]; // dump result - will be changed for UI for (int i = 0; i < result.rows.length; i++) { switch (i) { case 0: + table[i][0] = OStrings.getString("CT_STATSMATCH_RowRepetitions"); + break; + case 1: table[i][0] = OStrings.getString("CT_STATSMATCH_RowExactMatch"); break; - case 1: + case 2: table[i][0] = OStrings.getString("CT_STATSMATCH_RowMatch95"); break; - case 2: + case 3: table[i][0] = OStrings.getString("CT_STATSMATCH_RowMatch85"); break; - case 3: + case 4: table[i][0] = OStrings.getString("CT_STATSMATCH_RowMatch75"); break; - case 4: + case 5: table[i][0] = OStrings.getString("CT_STATSMATCH_RowMatch50"); break; - case 5: + case 6: table[i][0] = OStrings.getString("CT_STATSMATCH_RowNoMatch"); break; } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <al...@us...> - 2009-10-05 08:05:59
|
Revision: 2390 http://omegat.svn.sourceforge.net/omegat/?rev=2390&view=rev Author: alex73 Date: 2009-10-05 08:05:49 +0000 (Mon, 05 Oct 2009) Log Message: ----------- Add new match statistics: code clearing Modified Paths: -------------- trunk/src/org/omegat/core/statistics/CalcMatchStatistics.java trunk/src/org/omegat/core/statistics/CalcStandardStatistics.java trunk/src/org/omegat/gui/stat/StatisticsWindow.java Added Paths: ----------- trunk/src/org/omegat/core/statistics/StatCount.java Removed Paths: ------------- trunk/src/org/omegat/core/statistics/MatchStatisticsInfo.java Modified: trunk/src/org/omegat/core/statistics/CalcMatchStatistics.java =================================================================== --- trunk/src/org/omegat/core/statistics/CalcMatchStatistics.java 2009-10-05 07:17:48 UTC (rev 2389) +++ trunk/src/org/omegat/core/statistics/CalcMatchStatistics.java 2009-10-05 08:05:49 UTC (rev 2390) @@ -24,6 +24,10 @@ package org.omegat.core.statistics; +import java.io.FileOutputStream; +import java.io.OutputStreamWriter; +import java.text.DateFormat; +import java.util.Date; import java.util.HashMap; import java.util.HashSet; import java.util.List; @@ -35,6 +39,10 @@ import org.omegat.core.matching.ISimilarityCalculator; import org.omegat.core.matching.LevenshteinDistance; import org.omegat.core.threads.LongProcessThread; +import org.omegat.gui.stat.StatisticsWindow; +import org.omegat.util.Log; +import org.omegat.util.OConsts; +import org.omegat.util.OStrings; import org.omegat.util.StaticUtils; import org.omegat.util.Token; @@ -44,21 +52,32 @@ * @author Alex Buloichik (ale...@gm...) */ public class CalcMatchStatistics extends LongProcessThread { - private Callback callback; + private String[] header = new String[] { "", + OStrings.getString("CT_STATS_Segments"), + OStrings.getString("CT_STATS_Words"), + OStrings.getString("CT_STATS_Characters_NOSP"), + OStrings.getString("CT_STATS_Characters") }; + private boolean[] align = new boolean[] { false, true, true, true, true }; + + private StatisticsWindow callback; + /** Hash for exact tokens. Only for statistics calculation. */ private Map<String, Token[]> tokensCache = new HashMap<String, Token[]>(); - - /** Already processed segments. Used for repetitions detect.*/ + + /** Already processed segments. Used for repetitions detect. */ private Set<String> alreadyProcessed = new HashSet<String>(); - public CalcMatchStatistics(Callback callback) { + public CalcMatchStatistics(StatisticsWindow callback) { this.callback = callback; } public void run() { + StatCount[] result = new StatCount[7]; + for (int i = 0; i < result.length; i++) { + result[i] = new StatCount(); + } ISimilarityCalculator distanceCalculator = new LevenshteinDistance(); - MatchStatisticsInfo result = new MatchStatisticsInfo(); List<SourceTextEntry> allEntries = Core.getProject().getAllEntries(); // We should iterate all segments from all files in project. @@ -67,14 +86,14 @@ SourceTextEntry ste = allEntries.get(i); int p = Statistics.getMaxSimilarityPercent(ste, distanceCalculator, allEntries, tokensCache, alreadyProcessed); - int r = result.getRowByPercent(p); + int r = getRowByPercent(p); - result.rows[r].segments++; - result.rows[r].words += Statistics.numberOfWords(ste.getSrcText()); + result[r].segments++; + result[r].words += Statistics.numberOfWords(ste.getSrcText()); String charWithoutTags = StaticUtils.stripTags(ste.getSrcText()); - result.rows[r].charsWithoutSpaces += Statistics + result[r].charsWithoutSpaces += Statistics .numberOfCharactersWithoutSpaces(charWithoutTags); - result.rows[r].charsWithSpaces += charWithoutTags.length(); + result[r].charsWithSpaces += charWithoutTags.length(); if (isStopped) { return; @@ -85,12 +104,158 @@ percent = newPercent; } } - callback.displayData(result); + + final String[][] table = calcTable(result); + final String outText = showTextTable(header, table, align); + + callback.displayData(outText); + + String fn = Core.getProject().getProjectProperties() + .getProjectInternal() + + OConsts.STATS_MATCH_FILENAME; + try { + OutputStreamWriter out = new OutputStreamWriter( + new FileOutputStream(fn), OConsts.UTF8); + try { + out.write(DateFormat.getInstance().format(new Date()) + "\n"); + out.write(outText); + out.flush(); + } finally { + out.close(); + } + } catch (Exception ex) { + Log.log(ex); + } } - public interface Callback { - void displayData(MatchStatisticsInfo result); + /** + * Get row index by match percent. + * + * @param percent + * match percent + * @return row index + */ + public int getRowByPercent(int percent) { + if (percent == Statistics.PERCENT_REPETITIONS) { + // repetitions + return 0; + } else if (percent == Statistics.PERCENT_EXACT_MATCH) { + // exact match + return 1; + } else if (percent >= 95) { + return 2; + } else if (percent >= 85) { + return 3; + } else if (percent >= 75) { + return 4; + } else if (percent >= 50) { + return 5; + } else { + return 6; + } + } - void showProgress(int percent); + /** + * Extract result to text table. + * + * @param result + * result + * @return text table + */ + protected String[][] calcTable(final StatCount[] result) { + String[][] table = new String[result.length][5]; + // dump result - will be changed for UI + for (int i = 0; i < result.length; i++) { + switch (i) { + case 0: + table[i][0] = OStrings + .getString("CT_STATSMATCH_RowRepetitions"); + break; + case 1: + table[i][0] = OStrings.getString("CT_STATSMATCH_RowExactMatch"); + break; + case 2: + table[i][0] = OStrings.getString("CT_STATSMATCH_RowMatch95"); + break; + case 3: + table[i][0] = OStrings.getString("CT_STATSMATCH_RowMatch85"); + break; + case 4: + table[i][0] = OStrings.getString("CT_STATSMATCH_RowMatch75"); + break; + case 5: + table[i][0] = OStrings.getString("CT_STATSMATCH_RowMatch50"); + break; + case 6: + table[i][0] = OStrings.getString("CT_STATSMATCH_RowNoMatch"); + break; + } + table[i][1] = Integer.toString(result[i].segments); + table[i][2] = Integer.toString(result[i].words); + table[i][3] = Integer.toString(result[i].charsWithoutSpaces); + table[i][4] = Integer.toString(result[i].charsWithSpaces); + } + return table; } + + /** + * Draw text table with columns align. + * + * @param columnHeaders + * column headers + * @param table + * table data + * @return text + */ + protected static String showTextTable(String[] columnHeaders, + String[][] table, boolean[] alignRight) { + StringBuilder out = new StringBuilder(); + + // calculate max column size + int maxColSize[] = new int[columnHeaders.length]; + for (int c = 0; c < columnHeaders.length; c++) { + maxColSize[c] = columnHeaders[c].length(); + } + for (int r = 0; r < table.length; r++) { + for (int c = 0; c < table[r].length; c++) { + maxColSize[c] = Math.max(maxColSize[c], table[r][c].length()); + } + } + + for (int c = 0; c < columnHeaders.length; c++) { + appendField(out, columnHeaders[c], maxColSize[c], alignRight[c]); + } + out.append('\n'); + for (int r = 0; r < table.length; r++) { + for (int c = 0; c < table[r].length; c++) { + appendField(out, table[r][c], maxColSize[c], alignRight[c]); + } + out.append('\n'); + } + return out.toString(); + } + + /** + * Output field with specified length. + * + * @param out + * output stream + * @param data + * field data + * @param colSize + * field size + */ + private static void appendField(StringBuilder out, String data, + int colSize, boolean alignRight) { + if (!alignRight) { + out.append(data); + } + for (int i = data.length(); i < colSize; i++) { + out.append(' '); + } + if (alignRight) { + out.append(data); + } + out.append("\t"); + } } Modified: trunk/src/org/omegat/core/statistics/CalcStandardStatistics.java =================================================================== --- trunk/src/org/omegat/core/statistics/CalcStandardStatistics.java 2009-10-05 07:17:48 UTC (rev 2389) +++ trunk/src/org/omegat/core/statistics/CalcStandardStatistics.java 2009-10-05 08:05:49 UTC (rev 2390) @@ -27,18 +27,17 @@ import org.omegat.core.Core; import org.omegat.core.data.IProject; import org.omegat.core.threads.LongProcessThread; +import org.omegat.gui.stat.StatisticsWindow; /** * Thread for calculate standard statistics. * - * TODO: move this statistics into pane in main window - * * @author Alex Buloichik (ale...@gm...) */ public class CalcStandardStatistics extends LongProcessThread { - private Callback callback; + private StatisticsWindow callback; - public CalcStandardStatistics(Callback callback) { + public CalcStandardStatistics(StatisticsWindow callback) { this.callback = callback; } Deleted: trunk/src/org/omegat/core/statistics/MatchStatisticsInfo.java =================================================================== --- trunk/src/org/omegat/core/statistics/MatchStatisticsInfo.java 2009-10-05 07:17:48 UTC (rev 2389) +++ trunk/src/org/omegat/core/statistics/MatchStatisticsInfo.java 2009-10-05 08:05:49 UTC (rev 2390) @@ -1,76 +0,0 @@ -/************************************************************************** - OmegaT - Computer Assisted Translation (CAT) tool - with fuzzy matching, translation memory, keyword search, - glossaries, and translation leveraging into updated projects. - - Copyright (C) 2009 Alex Buloichik - Home page: http://www.omegat.org/ - Support center: http://groups.yahoo.com/group/OmegaT/ - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - **************************************************************************/ - -package org.omegat.core.statistics; - -/** - * Bean for store matches statistics info. - * - * It required 7 rows to output: - * "Exact match","100%","95% - 99%","85% - 94%","75% - 84%",50% - 74%","No - * Match" - * - * @author Alex Buloichik (ale...@gm...) - */ -public class MatchStatisticsInfo { - public final Row[] rows; - - public MatchStatisticsInfo() { - rows = new Row[7]; - for (int i = 0; i < rows.length; i++) { - rows[i] = new Row(); - } - } - - public static class Row { - public int segments, words, charsWithoutSpaces, charsWithSpaces; - } - - /** - * Get row index by match percent. - * - * @param percent - * match percent - * @return row index - */ - public int getRowByPercent(int percent) { - if (percent == Statistics.PERCENT_REPETITIONS) { - // repetitions - return 0; - } else if (percent == Statistics.PERCENT_EXACT_MATCH) { - // exact match - return 1; - } else if (percent >= 95) { - return 2; - } else if (percent >= 85) { - return 3; - } else if (percent >= 75) { - return 4; - } else if (percent >= 50) { - return 5; - } else { - return 6; - } - } -} Copied: trunk/src/org/omegat/core/statistics/StatCount.java (from rev 2386, trunk/src/org/omegat/core/statistics/MatchStatisticsInfo.java) =================================================================== --- trunk/src/org/omegat/core/statistics/StatCount.java (rev 0) +++ trunk/src/org/omegat/core/statistics/StatCount.java 2009-10-05 08:05:49 UTC (rev 2390) @@ -0,0 +1,34 @@ +/************************************************************************** + OmegaT - Computer Assisted Translation (CAT) tool + with fuzzy matching, translation memory, keyword search, + glossaries, and translation leveraging into updated projects. + + Copyright (C) 2009 Alex Buloichik + Home page: http://www.omegat.org/ + Support center: http://groups.yahoo.com/group/OmegaT/ + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + **************************************************************************/ + +package org.omegat.core.statistics; + +/** + * Bean for store counts in statistics. + * + * @author Alex Buloichik (ale...@gm...) + */ +public class StatCount { + public int segments, words, charsWithoutSpaces, charsWithSpaces; +} Modified: trunk/src/org/omegat/gui/stat/StatisticsWindow.java =================================================================== --- trunk/src/org/omegat/gui/stat/StatisticsWindow.java 2009-10-05 07:17:48 UTC (rev 2389) +++ trunk/src/org/omegat/gui/stat/StatisticsWindow.java 2009-10-05 08:05:49 UTC (rev 2390) @@ -30,10 +30,6 @@ import java.awt.event.KeyEvent; import java.awt.event.WindowAdapter; import java.awt.event.WindowEvent; -import java.io.FileOutputStream; -import java.io.OutputStreamWriter; -import java.text.DateFormat; -import java.util.Date; import javax.swing.AbstractAction; import javax.swing.Action; @@ -50,10 +46,7 @@ import org.omegat.core.Core; import org.omegat.core.statistics.CalcMatchStatistics; import org.omegat.core.statistics.CalcStandardStatistics; -import org.omegat.core.statistics.MatchStatisticsInfo; import org.omegat.core.threads.LongProcessThread; -import org.omegat.util.Log; -import org.omegat.util.OConsts; import org.omegat.util.OStrings; import org.omegat.util.gui.DockingUI; @@ -62,20 +55,12 @@ * * @author Alex Buloichik (ale...@gm...) */ -public class StatisticsWindow extends JDialog implements - CalcMatchStatistics.Callback, CalcStandardStatistics.Callback { +public class StatisticsWindow extends JDialog { public static enum STAT_TYPE { STANDARD, MATCHES }; - String[] header = new String[] { "", - OStrings.getString("CT_STATS_Segments"), - OStrings.getString("CT_STATS_Words"), - OStrings.getString("CT_STATS_Characters_NOSP"), - OStrings.getString("CT_STATS_Characters") }; - - boolean[] align = new boolean[] { false, true, true, true, true }; private JProgressBar progressBar; private JTextArea output; private LongProcessThread thread; @@ -158,141 +143,4 @@ } }); } - - public void displayData(final MatchStatisticsInfo result) { - SwingUtilities.invokeLater(new Runnable() { - public void run() { - progressBar.setValue(100); - progressBar.setString(""); - progressBar.setVisible(false); - } - }); - - final String[][] table = calcTable(result); - final String data = showTextTable(header, table, align); - SwingUtilities.invokeLater(new Runnable() { - public void run() { - output.setText(data); - } - }); - String fn = Core.getProject().getProjectProperties() - .getProjectInternal() - + OConsts.STATS_MATCH_FILENAME; - try { - OutputStreamWriter out = new OutputStreamWriter( - new FileOutputStream(fn), OConsts.UTF8); - try { - out.write(DateFormat.getInstance().format(new Date()) + "\n"); - out.write(data); - out.flush(); - } finally { - out.close(); - } - } catch (Exception ex) { - Log.log(ex); - } - } - - /** - * Extract result to text table. - * - * @param result - * result - * @return text table - */ - protected String[][] calcTable(final MatchStatisticsInfo result) { - String[][] table = new String[7][5]; - // dump result - will be changed for UI - for (int i = 0; i < result.rows.length; i++) { - switch (i) { - case 0: - table[i][0] = OStrings.getString("CT_STATSMATCH_RowRepetitions"); - break; - case 1: - table[i][0] = OStrings.getString("CT_STATSMATCH_RowExactMatch"); - break; - case 2: - table[i][0] = OStrings.getString("CT_STATSMATCH_RowMatch95"); - break; - case 3: - table[i][0] = OStrings.getString("CT_STATSMATCH_RowMatch85"); - break; - case 4: - table[i][0] = OStrings.getString("CT_STATSMATCH_RowMatch75"); - break; - case 5: - table[i][0] = OStrings.getString("CT_STATSMATCH_RowMatch50"); - break; - case 6: - table[i][0] = OStrings.getString("CT_STATSMATCH_RowNoMatch"); - break; - } - table[i][1] = Integer.toString(result.rows[i].segments); - table[i][2] = Integer.toString(result.rows[i].words); - table[i][3] = Integer.toString(result.rows[i].charsWithoutSpaces); - table[i][4] = Integer.toString(result.rows[i].charsWithSpaces); - } - return table; - } - - /** - * Draw text table with columns align. - * - * @param columnHeaders - * column headers - * @param table - * table data - * @return text - */ - protected static String showTextTable(String[] columnHeaders, - String[][] table, boolean[] alignRight) { - StringBuilder out = new StringBuilder(); - - // calculate max column size - int maxColSize[] = new int[columnHeaders.length]; - for (int c = 0; c < columnHeaders.length; c++) { - maxColSize[c] = columnHeaders[c].length(); - } - for (int r = 0; r < table.length; r++) { - for (int c = 0; c < table[r].length; c++) { - maxColSize[c] = Math.max(maxColSize[c], table[r][c].length()); - } - } - - for (int c = 0; c < columnHeaders.length; c++) { - appendField(out, columnHeaders[c], maxColSize[c], alignRight[c]); - } - out.append('\n'); - for (int r = 0; r < table.length; r++) { - for (int c = 0; c < table[r].length; c++) { - appendField(out, table[r][c], maxColSize[c], alignRight[c]); - } - out.append('\n'); - } - return out.toString(); - } - - /** - * Output field with specified length. - * - * @param out - * output stream - * @param data - * field data - * @param colSize - * field size - */ - private static void appendField(StringBuilder out, String data, - int colSize, boolean alignRight) { - if (!alignRight) { - out.append(data); - } - for (int i = data.length(); i < colSize; i++) { - out.append(' '); - } - if (alignRight) { - out.append(data); - } - out.append("\t"); - } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <al...@us...> - 2009-10-05 13:22:57
|
Revision: 2392 http://omegat.svn.sourceforge.net/omegat/?rev=2392&view=rev Author: alex73 Date: 2009-10-05 13:22:47 +0000 (Mon, 05 Oct 2009) Log Message: ----------- Add new match statistics: formatting old statistics Modified Paths: -------------- trunk/src/org/omegat/core/statistics/CalcMatchStatistics.java trunk/src/org/omegat/core/statistics/CalcStandardStatistics.java trunk/src/org/omegat/core/statistics/Statistics.java Added Paths: ----------- trunk/src/org/omegat/util/gui/TextUtil.java Modified: trunk/src/org/omegat/core/statistics/CalcMatchStatistics.java =================================================================== --- trunk/src/org/omegat/core/statistics/CalcMatchStatistics.java 2009-10-05 12:24:15 UTC (rev 2391) +++ trunk/src/org/omegat/core/statistics/CalcMatchStatistics.java 2009-10-05 13:22:47 UTC (rev 2392) @@ -45,6 +45,7 @@ import org.omegat.util.OStrings; import org.omegat.util.StaticUtils; import org.omegat.util.Token; +import org.omegat.util.gui.TextUtil; /** * Thread for calculate match statistics. @@ -106,7 +107,7 @@ } final String[][] table = calcTable(result); - final String outText = showTextTable(header, table, align); + final String outText = TextUtil.showTextTable(header, table, align); callback.displayData(outText); @@ -162,7 +163,7 @@ * result * @return text table */ - protected String[][] calcTable(final StatCount[] result) { + public String[][] calcTable(final StatCount[] result) { String[][] table = new String[result.length][5]; // dump result - will be changed for UI for (int i = 0; i < result.length; i++) { @@ -198,64 +199,4 @@ return table; } - /** - * Draw text table with columns align. - * - * @param columnHeaders - * column headers - * @param table - * table data - * @return text - */ - protected static String showTextTable(String[] columnHeaders, - String[][] table, boolean[] alignRight) { - StringBuilder out = new StringBuilder(); - - // calculate max column size - int maxColSize[] = new int[columnHeaders.length]; - for (int c = 0; c < columnHeaders.length; c++) { - maxColSize[c] = columnHeaders[c].length(); - } - for (int r = 0; r < table.length; r++) { - for (int c = 0; c < table[r].length; c++) { - maxColSize[c] = Math.max(maxColSize[c], table[r][c].length()); - } - } - - for (int c = 0; c < columnHeaders.length; c++) { - appendField(out, columnHeaders[c], maxColSize[c], alignRight[c]); - } - out.append('\n'); - for (int r = 0; r < table.length; r++) { - for (int c = 0; c < table[r].length; c++) { - appendField(out, table[r][c], maxColSize[c], alignRight[c]); - } - out.append('\n'); - } - return out.toString(); - } - - /** - * Output field with specified length. - * - * @param out - * output stream - * @param data - * field data - * @param colSize - * field size - */ - private static void appendField(StringBuilder out, String data, - int colSize, boolean alignRight) { - if (!alignRight) { - out.append(data); - } - for (int i = data.length(); i < colSize; i++) { - out.append(' '); - } - if (alignRight) { - out.append(data); - } - out.append("\t"); - } } Modified: trunk/src/org/omegat/core/statistics/CalcStandardStatistics.java =================================================================== --- trunk/src/org/omegat/core/statistics/CalcStandardStatistics.java 2009-10-05 12:24:15 UTC (rev 2391) +++ trunk/src/org/omegat/core/statistics/CalcStandardStatistics.java 2009-10-05 13:22:47 UTC (rev 2392) @@ -28,6 +28,7 @@ import org.omegat.core.data.IProject; import org.omegat.core.threads.LongProcessThread; import org.omegat.gui.stat.StatisticsWindow; +import org.omegat.util.OStrings; /** * Thread for calculate standard statistics. @@ -35,6 +36,13 @@ * @author Alex Buloichik (ale...@gm...) */ public class CalcStandardStatistics extends LongProcessThread { + private String[] header = new String[] { "", + OStrings.getString("CT_STATS_Segments"), + OStrings.getString("CT_STATS_Words"), + OStrings.getString("CT_STATS_Characters_NOSP"), + OStrings.getString("CT_STATS_Characters") }; + private boolean[] align = new boolean[] { false, true, true, true, true }; + private StatisticsWindow callback; public CalcStandardStatistics(StatisticsWindow callback) { @@ -49,9 +57,12 @@ callback.displayData(result); } - public interface Callback { - void displayData(String result); + public static class FileData { + public StatCount total, remaining; - void showProgress(int percent); + public FileData() { + total = new StatCount(); + remaining = new StatCount(); + } } } Modified: trunk/src/org/omegat/core/statistics/Statistics.java =================================================================== --- trunk/src/org/omegat/core/statistics/Statistics.java 2009-10-05 12:24:15 UTC (rev 2391) +++ trunk/src/org/omegat/core/statistics/Statistics.java 2009-10-05 13:22:47 UTC (rev 2392) @@ -45,6 +45,7 @@ import org.omegat.core.matching.FuzzyMatcher; import org.omegat.core.matching.ISimilarityCalculator; import org.omegat.core.matching.Tokenizer; +import org.omegat.core.statistics.CalcStandardStatistics.FileData; import org.omegat.util.OConsts; import org.omegat.util.OStrings; import org.omegat.util.PatternConsts; @@ -71,9 +72,12 @@ public static String buildProjectStats(final List<StringEntry> m_strEntryList, final List<SourceTextEntry> m_srcTextEntryArray, final ProjectProperties m_config, final int numberofTranslatedSegments) { - int I_WORDS = 0, I_WORDSLEFT = 1, I_CHARSNSP = 2, I_CHARSNSPLEFT = 3, I_CHARS = 4, I_CHARSLEFT = 5; + //int I_WORDS = 0, I_WORDSLEFT = 1, I_CHARSNSP = 2, I_CHARSNSPLEFT = 3, I_CHARS = 4, I_CHARSLEFT = 5; - int totalWords = 0, uniqueWords = 0, totalCharsNoSpaces = 0, uniqueCharsNoSpaces = 0, totalChars = 0, uniqueChars = 0, remainingUniqueWords = 0, remainingUniqueCharsNoSpaces = 0, remainingUniqueChars = 0, remainingSegments = 0; + StatCount total = new StatCount(); + StatCount remaining = new StatCount(); + StatCount unique = new StatCount(); + StatCount remainingUnique = new StatCount(); String charWithoutTags; @@ -82,57 +86,57 @@ int dups = se.getParentList().size(); int words = numberOfWords(src); - uniqueWords += words; - totalWords += words * dups; + unique.words += words; + total.words += words * dups; charWithoutTags = StaticUtils.stripTags(src); int charsNoSpaces = numberOfCharactersWithoutSpaces(charWithoutTags); - uniqueCharsNoSpaces += charsNoSpaces; - totalCharsNoSpaces += charsNoSpaces * dups; + unique.charsWithoutSpaces += charsNoSpaces; + total.charsWithoutSpaces += charsNoSpaces * dups; int chars = charWithoutTags.length(); - uniqueChars += chars; - totalChars += chars * dups; + unique.charsWithSpaces += chars; + total.charsWithSpaces += chars * dups; if (!se.isTranslated()) { - remainingUniqueWords += words; - remainingUniqueCharsNoSpaces += charsNoSpaces; - remainingUniqueChars += chars; - remainingSegments += dups; + remainingUnique.words += words; + remainingUnique.charsWithoutSpaces += charsNoSpaces; + remainingUnique.charsWithSpaces += chars; + remaining.segments += dups; } } - int remainingUniqueSegments = m_strEntryList.size() - numberofTranslatedSegments; + remainingUnique.segments = m_strEntryList.size() - numberofTranslatedSegments; - int remainingWords = 0; - int remainingCharsNoSpaces = 0; - int remainingChars = 0; - Map<String, int[]> counts = new TreeMap<String, int[]>(); + Map<String, FileData> counts = new TreeMap<String, FileData>(); for (SourceTextEntry ste : m_srcTextEntryArray) { String fileName = ste.getSrcFile().name; fileName = StaticUtils.makeFilenameRelative(fileName, m_config.getSourceRoot()); - int[] numbers; // [0] - words, [1] - left words - if (counts.containsKey(fileName)) - numbers = counts.get(fileName); - else - numbers = new int[] { 0, 0, 0, 0, 0, 0 }; + + FileData numbers = counts.get(fileName); + if (numbers==null) { + numbers = new FileData(); + counts.put(fileName, numbers); + } + + String src = ste.getSrcText(); charWithoutTags = StaticUtils.stripTags(src); int words = numberOfWords(src); - numbers[I_WORDS] += words; + numbers.total.words += words; int charsNoSpaces = numberOfCharactersWithoutSpaces(charWithoutTags); - numbers[I_CHARSNSP] += charsNoSpaces; + numbers.total.charsWithoutSpaces += charsNoSpaces; int chars = charWithoutTags.length(); - numbers[I_CHARS] += chars; + numbers.total.charsWithSpaces += chars; if (!ste.isTranslated()) { - remainingWords += words; - numbers[I_WORDSLEFT] += words; - remainingCharsNoSpaces += charsNoSpaces; - numbers[I_CHARSNSPLEFT] += charsNoSpaces; - remainingChars += chars; - numbers[I_CHARSLEFT] += chars; + remaining.words += words; + numbers.remaining.words += words; + remaining.charsWithoutSpaces += charsNoSpaces; + numbers.remaining.charsWithoutSpaces += charsNoSpaces; + remaining.charsWithSpaces += chars; + numbers.remaining.charsWithSpaces += chars; } counts.put(fileName, numbers); } @@ -155,53 +159,55 @@ Writer ofp = new OutputStreamWriter(new FileOutputStream(fn), OConsts.UTF8); result.append(OStrings.getString("CT_STATS_Project_Statistics") + "\n\n"); // NOI18N + total.segments=m_srcTextEntryArray.size(); + // TOTAL result.append(OStrings.getString("CT_STATS_Total") + "\n"); // NOI18N result.append("\t" + // NOI18N - OStrings.getString("CT_STATS_Segments") + "\t" + m_srcTextEntryArray.size() + "\n"); // NOI18N + OStrings.getString("CT_STATS_Segments") + "\t" + total.segments + "\n"); // NOI18N result.append("\t" + // NOI18N - OStrings.getString("CT_STATS_Words") + "\t" + totalWords + "\n"); // NOI18N + OStrings.getString("CT_STATS_Words") + "\t" + total.words + "\n"); // NOI18N result.append("\t" + // NOI18N - OStrings.getString("CT_STATS_Characters_NOSP") + "\t" + totalCharsNoSpaces + "\n"); // NOI18N + OStrings.getString("CT_STATS_Characters_NOSP") + "\t" + total.charsWithoutSpaces + "\n"); // NOI18N result.append("\t" + // NOI18N - OStrings.getString("CT_STATS_Characters") + "\t" + totalChars + "\n"); // NOI18N + OStrings.getString("CT_STATS_Characters") + "\t" + total.charsWithSpaces + "\n"); // NOI18N // REMAINING result.append(OStrings.getString("CT_STATS_Remaining") + "\n"); // NOI18N result.append("\t" + // NOI18N - OStrings.getString("CT_STATS_Segments") + "\t" + remainingSegments + "\n"); // NOI18N + OStrings.getString("CT_STATS_Segments") + "\t" + remaining.segments + "\n"); // NOI18N result.append("\t" + // NOI18N - OStrings.getString("CT_STATS_Words") + "\t" + remainingWords + "\n"); // NOI18N + OStrings.getString("CT_STATS_Words") + "\t" + remaining.words + "\n"); // NOI18N result.append("\t" + // NOI18N - OStrings.getString("CT_STATS_Characters_NOSP") + "\t" + remainingCharsNoSpaces + "\n"); // NOI18N + OStrings.getString("CT_STATS_Characters_NOSP") + "\t" + remaining.charsWithoutSpaces + "\n"); // NOI18N result.append("\t" + // NOI18N - OStrings.getString("CT_STATS_Characters") + "\t" + remainingChars + "\n"); // NOI18N + OStrings.getString("CT_STATS_Characters") + "\t" + remaining.charsWithSpaces + "\n"); // NOI18N // UNIQUE - + unique.segments=m_strEntryList.size(); result.append(OStrings.getString("CT_STATS_Unique") + "\n"); // NOI18N result.append("\t" + // NOI18N - OStrings.getString("CT_STATS_Segments") + "\t" + m_strEntryList.size() + "\n"); // NOI18N + OStrings.getString("CT_STATS_Segments") + "\t" + unique.segments + "\n"); // NOI18N result.append("\t" + // NOI18N - OStrings.getString("CT_STATS_Words") + "\t" + uniqueWords + "\n"); // NOI18N + OStrings.getString("CT_STATS_Words") + "\t" + unique.words + "\n"); // NOI18N result.append("\t" + // NOI18N - OStrings.getString("CT_STATS_Characters_NOSP") + "\t" + uniqueCharsNoSpaces + "\n"); // NOI18N + OStrings.getString("CT_STATS_Characters_NOSP") + "\t" + unique.charsWithoutSpaces + "\n"); // NOI18N result.append("\t" + // NOI18N - OStrings.getString("CT_STATS_Characters") + "\t" + uniqueChars + "\n"); // NOI18N + OStrings.getString("CT_STATS_Characters") + "\t" + unique.charsWithSpaces + "\n"); // NOI18N // UNIQUE REMAINING result.append(OStrings.getString("CT_STATS_Unique_Remaining") + "\n"); // NOI18N result.append("\t" + // NOI18N - OStrings.getString("CT_STATS_Segments") + "\t" + remainingUniqueSegments + "\n"); // NOI18N + OStrings.getString("CT_STATS_Segments") + "\t" + remainingUnique.segments + "\n"); // NOI18N result.append("\t" + // NOI18N - OStrings.getString("CT_STATS_Words") + "\t" + remainingUniqueWords + "\n"); // NOI18N + OStrings.getString("CT_STATS_Words") + "\t" + remainingUnique.words + "\n"); // NOI18N result.append("\t" + // NOI18N - OStrings.getString("CT_STATS_Characters_NOSP") + "\t" + remainingUniqueCharsNoSpaces + "\n"); // NOI18N + OStrings.getString("CT_STATS_Characters_NOSP") + "\t" + remainingUnique.charsWithoutSpaces + "\n"); // NOI18N result.append("\t" + // NOI18N - OStrings.getString("CT_STATS_Characters") + "\t" + remainingUniqueChars + "\n"); + OStrings.getString("CT_STATS_Characters") + "\t" + remainingUnique.charsWithSpaces + "\n"); result.append("\n"); // NOI18N // STATISTICS BY FILE @@ -217,10 +223,10 @@ OStrings.getString("CT_STATS_FILE_Remaining_Characters") + "\n"); // NOI18N for (String filename : counts.keySet()) { - int[] numbers = counts.get(filename); - result.append(filename + "\t" + numbers[I_WORDS] + "\t" + numbers[I_WORDSLEFT] + // NOI18N - "\t" + numbers[I_CHARSNSP] + "\t" + numbers[I_CHARSNSPLEFT] + // NOI18N - "\t" + numbers[I_CHARS] + "\t" + numbers[I_CHARSLEFT] + // NOI18N + FileData numbers = counts.get(filename); + result.append(filename + "\t" + numbers.total.words + "\t" + numbers.remaining.words + // NOI18N + "\t" + numbers.total.charsWithoutSpaces + "\t" + numbers.remaining.charsWithoutSpaces + // NOI18N + "\t" + numbers.total.charsWithSpaces + "\t" + numbers.remaining.charsWithSpaces + // NOI18N "\n"); // NOI18N } Added: trunk/src/org/omegat/util/gui/TextUtil.java =================================================================== --- trunk/src/org/omegat/util/gui/TextUtil.java (rev 0) +++ trunk/src/org/omegat/util/gui/TextUtil.java 2009-10-05 13:22:47 UTC (rev 2392) @@ -0,0 +1,94 @@ +/************************************************************************** + OmegaT - Computer Assisted Translation (CAT) tool + with fuzzy matching, translation memory, keyword search, + glossaries, and translation leveraging into updated projects. + + Copyright (C) 2009 Alex Buloichik + Home page: http://www.omegat.org/ + Support center: http://groups.yahoo.com/group/OmegaT/ + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + **************************************************************************/ + +package org.omegat.util.gui; + +/** + * Some utilities for display text tables with aligning. + * + * @author Alex Buloichik (ale...@gm...) + */ +public class TextUtil { + + /** + * Draw text table with columns align. + * + * @param columnHeaders + * column headers + * @param table + * table data + * @return text + */ + public static String showTextTable(String[] columnHeaders, + String[][] table, boolean[] alignRight) { + StringBuilder out = new StringBuilder(); + + // calculate max column size + int maxColSize[] = new int[columnHeaders.length]; + for (int c = 0; c < columnHeaders.length; c++) { + maxColSize[c] = columnHeaders[c].length(); + } + for (int r = 0; r < table.length; r++) { + for (int c = 0; c < table[r].length; c++) { + maxColSize[c] = Math.max(maxColSize[c], table[r][c].length()); + } + } + + for (int c = 0; c < columnHeaders.length; c++) { + appendField(out, columnHeaders[c], maxColSize[c], alignRight[c]); + } + out.append('\n'); + for (int r = 0; r < table.length; r++) { + for (int c = 0; c < table[r].length; c++) { + appendField(out, table[r][c], maxColSize[c], alignRight[c]); + } + out.append('\n'); + } + return out.toString(); + } + + /** + * Output field with specified length. + * + * @param out + * output stream + * @param data + * field data + * @param colSize + * field size + */ + public static void appendField(StringBuilder out, String data, int colSize, + boolean alignRight) { + if (!alignRight) { + out.append(data); + } + for (int i = data.length(); i < colSize; i++) { + out.append(' '); + } + if (alignRight) { + out.append(data); + } + out.append("\t"); + } +} Property changes on: trunk/src/org/omegat/util/gui/TextUtil.java ___________________________________________________________________ Added: svn:mime-type + text/x-java Added: svn:eol-style + native This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <al...@us...> - 2009-10-05 14:13:10
|
Revision: 2393 http://omegat.svn.sourceforge.net/omegat/?rev=2393&view=rev Author: alex73 Date: 2009-10-05 14:13:00 +0000 (Mon, 05 Oct 2009) Log Message: ----------- Add new match statistics: formatting old statistics Modified Paths: -------------- trunk/src/org/omegat/core/data/RealProject.java trunk/src/org/omegat/core/statistics/CalcMatchStatistics.java trunk/src/org/omegat/core/statistics/CalcStandardStatistics.java trunk/src/org/omegat/core/statistics/Statistics.java trunk/src/org/omegat/util/gui/TextUtil.java Modified: trunk/src/org/omegat/core/data/RealProject.java =================================================================== --- trunk/src/org/omegat/core/data/RealProject.java 2009-10-05 13:22:47 UTC (rev 2392) +++ trunk/src/org/omegat/core/data/RealProject.java 2009-10-05 14:13:00 UTC (rev 2393) @@ -43,6 +43,7 @@ import org.omegat.core.Core; import org.omegat.core.CoreEvents; import org.omegat.core.events.IProjectEventListener; +import org.omegat.core.statistics.CalcStandardStatistics; import org.omegat.core.statistics.Statistics; import org.omegat.core.statistics.StatisticsInfo; import org.omegat.filters2.TranslationException; @@ -177,7 +178,12 @@ } // build word count - Statistics.buildProjectStats(m_strEntryList, m_srcTextEntryArray, m_config, numberofTranslatedSegments); + String stat = CalcStandardStatistics.buildProjectStats( + m_strEntryList, m_srcTextEntryArray, m_config, + numberofTranslatedSegments); + String fn = getProjectProperties().getProjectInternal() + + OConsts.STATS_FILENAME; + Statistics.writeStat(fn, stat); // Project Loaded... Core.getMainWindow().showStatusMessageRB(null); @@ -402,7 +408,12 @@ } // update statistics - Statistics.buildProjectStats(m_strEntryList, m_srcTextEntryArray, m_config, numberofTranslatedSegments); + String stat = CalcStandardStatistics.buildProjectStats( + m_strEntryList, m_srcTextEntryArray, m_config, + numberofTranslatedSegments); + String fn = getProjectProperties().getProjectInternal() + + OConsts.STATS_FILENAME; + Statistics.writeStat(fn, stat); CoreEvents.fireProjectChange(IProjectEventListener.PROJECT_CHANGE_TYPE.SAVE); Modified: trunk/src/org/omegat/core/statistics/CalcMatchStatistics.java =================================================================== --- trunk/src/org/omegat/core/statistics/CalcMatchStatistics.java 2009-10-05 13:22:47 UTC (rev 2392) +++ trunk/src/org/omegat/core/statistics/CalcMatchStatistics.java 2009-10-05 14:13:00 UTC (rev 2393) @@ -24,10 +24,6 @@ package org.omegat.core.statistics; -import java.io.FileOutputStream; -import java.io.OutputStreamWriter; -import java.text.DateFormat; -import java.util.Date; import java.util.HashMap; import java.util.HashSet; import java.util.List; @@ -40,7 +36,6 @@ import org.omegat.core.matching.LevenshteinDistance; import org.omegat.core.threads.LongProcessThread; import org.omegat.gui.stat.StatisticsWindow; -import org.omegat.util.Log; import org.omegat.util.OConsts; import org.omegat.util.OStrings; import org.omegat.util.StaticUtils; @@ -59,6 +54,15 @@ OStrings.getString("CT_STATS_Words"), OStrings.getString("CT_STATS_Characters_NOSP"), OStrings.getString("CT_STATS_Characters") }; + + private String[] rows = new String[] { + OStrings.getString("CT_STATSMATCH_RowRepetitions"), + OStrings.getString("CT_STATSMATCH_RowExactMatch"), + OStrings.getString("CT_STATSMATCH_RowMatch95"), + OStrings.getString("CT_STATSMATCH_RowMatch85"), + OStrings.getString("CT_STATSMATCH_RowMatch75"), + OStrings.getString("CT_STATSMATCH_RowMatch50"), + OStrings.getString("CT_STATSMATCH_RowNoMatch") }; private boolean[] align = new boolean[] { false, true, true, true, true }; private StatisticsWindow callback; @@ -114,19 +118,7 @@ String fn = Core.getProject().getProjectProperties() .getProjectInternal() + OConsts.STATS_MATCH_FILENAME; - try { - OutputStreamWriter out = new OutputStreamWriter( - new FileOutputStream(fn), OConsts.UTF8); - try { - out.write(DateFormat.getInstance().format(new Date()) + "\n"); - out.write(outText); - out.flush(); - } finally { - out.close(); - } - } catch (Exception ex) { - Log.log(ex); - } + Statistics.writeStat(fn, outText); } /** @@ -165,32 +157,10 @@ */ public String[][] calcTable(final StatCount[] result) { String[][] table = new String[result.length][5]; + // dump result - will be changed for UI for (int i = 0; i < result.length; i++) { - switch (i) { - case 0: - table[i][0] = OStrings - .getString("CT_STATSMATCH_RowRepetitions"); - break; - case 1: - table[i][0] = OStrings.getString("CT_STATSMATCH_RowExactMatch"); - break; - case 2: - table[i][0] = OStrings.getString("CT_STATSMATCH_RowMatch95"); - break; - case 3: - table[i][0] = OStrings.getString("CT_STATSMATCH_RowMatch85"); - break; - case 4: - table[i][0] = OStrings.getString("CT_STATSMATCH_RowMatch75"); - break; - case 5: - table[i][0] = OStrings.getString("CT_STATSMATCH_RowMatch50"); - break; - case 6: - table[i][0] = OStrings.getString("CT_STATSMATCH_RowNoMatch"); - break; - } + table[i][0] = rows[i]; table[i][1] = Integer.toString(result[i].segments); table[i][2] = Integer.toString(result[i].words); table[i][3] = Integer.toString(result[i].charsWithoutSpaces); Modified: trunk/src/org/omegat/core/statistics/CalcStandardStatistics.java =================================================================== --- trunk/src/org/omegat/core/statistics/CalcStandardStatistics.java 2009-10-05 13:22:47 UTC (rev 2392) +++ trunk/src/org/omegat/core/statistics/CalcStandardStatistics.java 2009-10-05 14:13:00 UTC (rev 2393) @@ -24,11 +24,22 @@ package org.omegat.core.statistics; +import java.io.File; +import java.util.List; +import java.util.Map; +import java.util.TreeMap; + import org.omegat.core.Core; import org.omegat.core.data.IProject; +import org.omegat.core.data.ProjectProperties; +import org.omegat.core.data.SourceTextEntry; +import org.omegat.core.data.StringEntry; import org.omegat.core.threads.LongProcessThread; import org.omegat.gui.stat.StatisticsWindow; +import org.omegat.util.OConsts; import org.omegat.util.OStrings; +import org.omegat.util.StaticUtils; +import org.omegat.util.gui.TextUtil; /** * Thread for calculate standard statistics. @@ -36,13 +47,33 @@ * @author Alex Buloichik (ale...@gm...) */ public class CalcStandardStatistics extends LongProcessThread { - private String[] header = new String[] { "", + + private static final String[] htHeaders = new String[] { "", OStrings.getString("CT_STATS_Segments"), OStrings.getString("CT_STATS_Words"), OStrings.getString("CT_STATS_Characters_NOSP"), OStrings.getString("CT_STATS_Characters") }; - private boolean[] align = new boolean[] { false, true, true, true, true }; + private static final String[] htRows = new String[] { + OStrings.getString("CT_STATS_Total"), + OStrings.getString("CT_STATS_Remaining"), + OStrings.getString("CT_STATS_Unique"), + OStrings.getString("CT_STATS_Unique_Remaining") }; + private static final boolean[] htAlign = new boolean[] { false, true, true, + true, true }; + + private static final String[] ftHeaders = new String[] { + OStrings.getString("CT_STATS_FILE_Name"), + OStrings.getString("CT_STATS_FILE_Total_Words"), + OStrings.getString("CT_STATS_FILE_Remaining_Words"), + OStrings.getString("CT_STATS_FILE_Total_Characters_NOSP"), + OStrings.getString("CT_STATS_FILE_Remaining_Characters_NOSP"), + OStrings.getString("CT_STATS_FILE_Total_Characters"), + OStrings.getString("CT_STATS_FILE_Remaining_Characters") }; + + private static final boolean[] ftAlign = new boolean[] { false, true, true, + true, true, true, true, true }; + private StatisticsWindow callback; public CalcStandardStatistics(StatisticsWindow callback) { @@ -51,12 +82,157 @@ public void run() { IProject p = Core.getProject(); - String result = Statistics.buildProjectStats(p.getUniqueEntries(), p + String result = buildProjectStats(p.getUniqueEntries(), p .getAllEntries(), p.getProjectProperties(), p.getStatistics().numberofTranslatedSegments); callback.displayData(result); + + String internalDir = p.getProjectProperties().getProjectInternal(); + // removing old stats + try { + File oldstats = new File(internalDir + "word_counts"); + if (oldstats.exists()) + oldstats.delete(); + } catch (Exception e) { + } + + // now dump file based word counts to disk + String fn = internalDir + OConsts.STATS_FILENAME; + Statistics.writeStat(fn, result); } + /** + * Builds a file with statistic info about the project. The total word & + * character count of the project, the total number of unique segments, plus + * the details for each file. + */ + public static String buildProjectStats( + final List<StringEntry> m_strEntryList, + final List<SourceTextEntry> m_srcTextEntryArray, + final ProjectProperties m_config, + final int numberofTranslatedSegments) { + + StatCount total = new StatCount(); + StatCount remaining = new StatCount(); + StatCount unique = new StatCount(); + StatCount remainingUnique = new StatCount(); + + String charWithoutTags; + + total.segments = m_srcTextEntryArray.size(); + for (StringEntry se : m_strEntryList) { + String src = se.getSrcText(); + int dups = se.getParentList().size(); + + int words = Statistics.numberOfWords(src); + unique.words += words; + total.words += words * dups; + + charWithoutTags = StaticUtils.stripTags(src); + int charsNoSpaces = Statistics + .numberOfCharactersWithoutSpaces(charWithoutTags); + unique.charsWithoutSpaces += charsNoSpaces; + total.charsWithoutSpaces += charsNoSpaces * dups; + + int chars = charWithoutTags.length(); + unique.charsWithSpaces += chars; + total.charsWithSpaces += chars * dups; + + if (!se.isTranslated()) { + remainingUnique.words += words; + remainingUnique.charsWithoutSpaces += charsNoSpaces; + remainingUnique.charsWithSpaces += chars; + remaining.segments += dups; + } + } + + remainingUnique.segments = m_strEntryList.size() + - numberofTranslatedSegments; + + Map<String, FileData> counts = new TreeMap<String, FileData>(); + for (SourceTextEntry ste : m_srcTextEntryArray) { + String fileName = ste.getSrcFile().name; + fileName = StaticUtils.makeFilenameRelative(fileName, m_config + .getSourceRoot()); + + FileData numbers = counts.get(fileName); + if (numbers == null) { + numbers = new FileData(); + counts.put(fileName, numbers); + } + + String src = ste.getSrcText(); + charWithoutTags = StaticUtils.stripTags(src); + int words = Statistics.numberOfWords(src); + numbers.total.words += words; + int charsNoSpaces = Statistics + .numberOfCharactersWithoutSpaces(charWithoutTags); + numbers.total.charsWithoutSpaces += charsNoSpaces; + int chars = charWithoutTags.length(); + numbers.total.charsWithSpaces += chars; + + if (!ste.isTranslated()) { + remaining.words += words; + numbers.remaining.words += words; + remaining.charsWithoutSpaces += charsNoSpaces; + numbers.remaining.charsWithoutSpaces += charsNoSpaces; + remaining.charsWithSpaces += chars; + numbers.remaining.charsWithSpaces += chars; + } + counts.put(fileName, numbers); + } + + StringBuilder result = new StringBuilder(); + + result.append(OStrings.getString("CT_STATS_Project_Statistics") + + "\n\n"); + + String[][] headerTable = calcHeaderTable(new StatCount[] { total, + remaining, unique, remainingUnique }); + result.append(TextUtil.showTextTable(htHeaders, headerTable, htAlign)); + result.append("\n\n"); + + // STATISTICS BY FILE + result.append(OStrings.getString("CT_STATS_FILE_Statistics") + "\n\n"); + String[][] filesTable = calcFilesTable(counts); + result.append(TextUtil.showTextTable(ftHeaders, filesTable, ftAlign)); + + return result.toString(); + } + + protected static String[][] calcHeaderTable(final StatCount[] result) { + String[][] table = new String[result.length][5]; + + for (int i = 0; i < result.length; i++) { + table[i][0] = htRows[i]; + table[i][1] = Integer.toString(result[i].segments); + table[i][2] = Integer.toString(result[i].words); + table[i][3] = Integer.toString(result[i].charsWithoutSpaces); + table[i][4] = Integer.toString(result[i].charsWithSpaces); + } + return table; + } + + protected static String[][] calcFilesTable( + final Map<String, FileData> counts) { + String[][] table = new String[counts.size()][7]; + + int r = 0; + for (String filename : counts.keySet()) { + FileData numbers = counts.get(filename); + table[r][0] = filename; + table[r][1] = Integer.toString(numbers.total.words); + table[r][2] = Integer.toString(numbers.remaining.words); + table[r][3] = Integer.toString(numbers.total.charsWithoutSpaces); + table[r][4] = Integer + .toString(numbers.remaining.charsWithoutSpaces); + table[r][5] = Integer.toString(numbers.total.charsWithSpaces); + table[r][6] = Integer.toString(numbers.remaining.charsWithSpaces); + r++; + } + return table; + } + public static class FileData { public StatCount total, remaining; Modified: trunk/src/org/omegat/core/statistics/Statistics.java =================================================================== --- trunk/src/org/omegat/core/statistics/Statistics.java 2009-10-05 13:22:47 UTC (rev 2392) +++ trunk/src/org/omegat/core/statistics/Statistics.java 2009-10-05 14:13:00 UTC (rev 2393) @@ -22,34 +22,28 @@ You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -**************************************************************************/ + **************************************************************************/ package org.omegat.core.statistics; -import java.io.File; import java.io.FileOutputStream; -import java.io.IOException; import java.io.OutputStreamWriter; -import java.io.Writer; import java.text.BreakIterator; +import java.text.DateFormat; +import java.util.Date; import java.util.List; import java.util.Map; import java.util.Set; -import java.util.TreeMap; import org.omegat.core.Core; -import org.omegat.core.data.ProjectProperties; import org.omegat.core.data.SourceTextEntry; -import org.omegat.core.data.StringEntry; import org.omegat.core.data.TransMemory; import org.omegat.core.matching.FuzzyMatcher; import org.omegat.core.matching.ISimilarityCalculator; import org.omegat.core.matching.Tokenizer; -import org.omegat.core.statistics.CalcStandardStatistics.FileData; +import org.omegat.util.Log; import org.omegat.util.OConsts; -import org.omegat.util.OStrings; import org.omegat.util.PatternConsts; -import org.omegat.util.StaticUtils; import org.omegat.util.StringUtil; import org.omegat.util.Token; @@ -64,183 +58,10 @@ * @author Alex Buloichik (ale...@gm...) */ public class Statistics { - /** - * Builds a file with statistic info about the project. The total word & - * character count of the project, the total number of unique segments, plus - * the details for each file. - */ - public static String buildProjectStats(final List<StringEntry> m_strEntryList, - final List<SourceTextEntry> m_srcTextEntryArray, final ProjectProperties m_config, - final int numberofTranslatedSegments) { - //int I_WORDS = 0, I_WORDSLEFT = 1, I_CHARSNSP = 2, I_CHARSNSPLEFT = 3, I_CHARS = 4, I_CHARSLEFT = 5; - StatCount total = new StatCount(); - StatCount remaining = new StatCount(); - StatCount unique = new StatCount(); - StatCount remainingUnique = new StatCount(); - - String charWithoutTags; - - for (StringEntry se : m_strEntryList) { - String src = se.getSrcText(); - int dups = se.getParentList().size(); - - int words = numberOfWords(src); - unique.words += words; - total.words += words * dups; - - charWithoutTags = StaticUtils.stripTags(src); - int charsNoSpaces = numberOfCharactersWithoutSpaces(charWithoutTags); - unique.charsWithoutSpaces += charsNoSpaces; - total.charsWithoutSpaces += charsNoSpaces * dups; - - int chars = charWithoutTags.length(); - unique.charsWithSpaces += chars; - total.charsWithSpaces += chars * dups; - - if (!se.isTranslated()) { - remainingUnique.words += words; - remainingUnique.charsWithoutSpaces += charsNoSpaces; - remainingUnique.charsWithSpaces += chars; - remaining.segments += dups; - } - } - - remainingUnique.segments = m_strEntryList.size() - numberofTranslatedSegments; - - Map<String, FileData> counts = new TreeMap<String, FileData>(); - for (SourceTextEntry ste : m_srcTextEntryArray) { - String fileName = ste.getSrcFile().name; - fileName = StaticUtils.makeFilenameRelative(fileName, m_config.getSourceRoot()); - - FileData numbers = counts.get(fileName); - if (numbers==null) { - numbers = new FileData(); - counts.put(fileName, numbers); - } - - - - String src = ste.getSrcText(); - charWithoutTags = StaticUtils.stripTags(src); - int words = numberOfWords(src); - numbers.total.words += words; - int charsNoSpaces = numberOfCharactersWithoutSpaces(charWithoutTags); - numbers.total.charsWithoutSpaces += charsNoSpaces; - int chars = charWithoutTags.length(); - numbers.total.charsWithSpaces += chars; - - if (!ste.isTranslated()) { - remaining.words += words; - numbers.remaining.words += words; - remaining.charsWithoutSpaces += charsNoSpaces; - numbers.remaining.charsWithoutSpaces += charsNoSpaces; - remaining.charsWithSpaces += chars; - numbers.remaining.charsWithSpaces += chars; - } - counts.put(fileName, numbers); - } - - - StringBuilder result=new StringBuilder(); - - try { - // removing old stats - try { - File oldstats = new File(m_config.getProjectInternal() + "word_counts"); // NOI18N - if (oldstats.exists()) - oldstats.delete(); - } catch (Exception e) { - } - - - // now dump file based word counts to disk - String fn = m_config.getProjectInternal() + OConsts.STATS_FILENAME; - Writer ofp = new OutputStreamWriter(new FileOutputStream(fn), OConsts.UTF8); - result.append(OStrings.getString("CT_STATS_Project_Statistics") + "\n\n"); // NOI18N - - total.segments=m_srcTextEntryArray.size(); - - // TOTAL - - result.append(OStrings.getString("CT_STATS_Total") + "\n"); // NOI18N - result.append("\t" + // NOI18N - OStrings.getString("CT_STATS_Segments") + "\t" + total.segments + "\n"); // NOI18N - result.append("\t" + // NOI18N - OStrings.getString("CT_STATS_Words") + "\t" + total.words + "\n"); // NOI18N - result.append("\t" + // NOI18N - OStrings.getString("CT_STATS_Characters_NOSP") + "\t" + total.charsWithoutSpaces + "\n"); // NOI18N - result.append("\t" + // NOI18N - OStrings.getString("CT_STATS_Characters") + "\t" + total.charsWithSpaces + "\n"); // NOI18N - - // REMAINING - - result.append(OStrings.getString("CT_STATS_Remaining") + "\n"); // NOI18N - result.append("\t" + // NOI18N - OStrings.getString("CT_STATS_Segments") + "\t" + remaining.segments + "\n"); // NOI18N - result.append("\t" + // NOI18N - OStrings.getString("CT_STATS_Words") + "\t" + remaining.words + "\n"); // NOI18N - result.append("\t" + // NOI18N - OStrings.getString("CT_STATS_Characters_NOSP") + "\t" + remaining.charsWithoutSpaces + "\n"); // NOI18N - result.append("\t" + // NOI18N - OStrings.getString("CT_STATS_Characters") + "\t" + remaining.charsWithSpaces + "\n"); // NOI18N - - // UNIQUE - unique.segments=m_strEntryList.size(); - result.append(OStrings.getString("CT_STATS_Unique") + "\n"); // NOI18N - result.append("\t" + // NOI18N - OStrings.getString("CT_STATS_Segments") + "\t" + unique.segments + "\n"); // NOI18N - result.append("\t" + // NOI18N - OStrings.getString("CT_STATS_Words") + "\t" + unique.words + "\n"); // NOI18N - result.append("\t" + // NOI18N - OStrings.getString("CT_STATS_Characters_NOSP") + "\t" + unique.charsWithoutSpaces + "\n"); // NOI18N - result.append("\t" + // NOI18N - OStrings.getString("CT_STATS_Characters") + "\t" + unique.charsWithSpaces + "\n"); // NOI18N - - // UNIQUE REMAINING - - result.append(OStrings.getString("CT_STATS_Unique_Remaining") + "\n"); // NOI18N - result.append("\t" + // NOI18N - OStrings.getString("CT_STATS_Segments") + "\t" + remainingUnique.segments + "\n"); // NOI18N - result.append("\t" + // NOI18N - OStrings.getString("CT_STATS_Words") + "\t" + remainingUnique.words + "\n"); // NOI18N - result.append("\t" + // NOI18N - OStrings.getString("CT_STATS_Characters_NOSP") + "\t" + remainingUnique.charsWithoutSpaces + "\n"); // NOI18N - result.append("\t" + // NOI18N - OStrings.getString("CT_STATS_Characters") + "\t" + remainingUnique.charsWithSpaces + "\n"); - result.append("\n"); // NOI18N - - // STATISTICS BY FILE - - result.append(OStrings.getString("CT_STATS_FILE_Statistics") + "\n\n"); // NOI18N - - result.append(OStrings.getString("CT_STATS_FILE_Name") + "\t" + // NOI18N - OStrings.getString("CT_STATS_FILE_Total_Words") + "\t" + // NOI18N - OStrings.getString("CT_STATS_FILE_Remaining_Words") + "\t" + // NOI18N - OStrings.getString("CT_STATS_FILE_Total_Characters_NOSP") + "\t" + // NOI18N - OStrings.getString("CT_STATS_FILE_Remaining_Characters_NOSP") + "\t" + // NOI18N - OStrings.getString("CT_STATS_FILE_Total_Characters") + "\t" + // NOI18N - OStrings.getString("CT_STATS_FILE_Remaining_Characters") + "\n"); // NOI18N - - for (String filename : counts.keySet()) { - FileData numbers = counts.get(filename); - result.append(filename + "\t" + numbers.total.words + "\t" + numbers.remaining.words + // NOI18N - "\t" + numbers.total.charsWithoutSpaces + "\t" + numbers.remaining.charsWithoutSpaces + // NOI18N - "\t" + numbers.total.charsWithSpaces + "\t" + numbers.remaining.charsWithSpaces + // NOI18N - "\n"); // NOI18N - } - - ofp.write(result.toString()); - ofp.close(); - - } catch (IOException e) { - } - return result.toString(); - } - protected static final int PERCENT_EXACT_MATCH = 101; protected static final int PERCENT_REPETITIONS = 102; - + /** * Calculate max similarity percent for one entry. * @@ -255,10 +76,11 @@ public static int getMaxSimilarityPercent(final SourceTextEntry ste, final ISimilarityCalculator distanceCalculator, final List<SourceTextEntry> allEntries, - final Map<String, Token[]> tokensCache,final Set<String> alreadyProcessed) { - - boolean isFirst=alreadyProcessed.add(ste.getSrcText()); + final Map<String, Token[]> tokensCache, + final Set<String> alreadyProcessed) { + boolean isFirst = alreadyProcessed.add(ste.getSrcText()); + if (!StringUtil.isEmpty(ste.getTranslation())) { // segment has translation - should be calculated as // "Exact matched" @@ -352,7 +174,8 @@ String tokenStr = new String(); int start = breaker.first(); - for (int end = breaker.next(); end != BreakIterator.DONE; start = end, end = breaker.next()) { + for (int end = breaker.next(); end != BreakIterator.DONE; start = end, end = breaker + .next()) { tokenStr = str.substring(start, end); boolean word = false; for (int i = 0; i < tokenStr.length(); i++) { @@ -368,4 +191,26 @@ } return nTokens; } + + /** + * Write text to file. + * + * @param filename + * @param data + */ + public static void writeStat(String filename, String text) { + try { + OutputStreamWriter out = new OutputStreamWriter( + new FileOutputStream(filename), OConsts.UTF8); + try { + out.write(DateFormat.getInstance().format(new Date()) + "\n"); + out.write(text); + out.flush(); + } finally { + out.close(); + } + } catch (Exception ex) { + Log.log(ex); + } + } } Modified: trunk/src/org/omegat/util/gui/TextUtil.java =================================================================== --- trunk/src/org/omegat/util/gui/TextUtil.java 2009-10-05 13:22:47 UTC (rev 2392) +++ trunk/src/org/omegat/util/gui/TextUtil.java 2009-10-05 14:13:00 UTC (rev 2393) @@ -24,6 +24,7 @@ package org.omegat.util.gui; + /** * Some utilities for display text tables with aligning. * This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <mar...@us...> - 2009-10-08 13:00:14
|
Revision: 2395 http://omegat.svn.sourceforge.net/omegat/?rev=2395&view=rev Author: martinfleurke Date: 2009-10-08 12:24:29 +0000 (Thu, 08 Oct 2009) Log Message: ----------- improved translation/description for srt-files. (there are other formats for subtitles than subrip: http://en.wikipedia.org/wiki/Subtitle_%28captioning%29#Subtitle_formats, so it is wise to name it SubRip explicitly). Modified Paths: -------------- trunk/src/org/omegat/Bundle.properties trunk/src/org/omegat/Bundle_nl.properties Modified: trunk/src/org/omegat/Bundle.properties =================================================================== --- trunk/src/org/omegat/Bundle.properties 2009-10-06 12:43:37 UTC (rev 2394) +++ trunk/src/org/omegat/Bundle.properties 2009-10-08 12:24:29 UTC (rev 2395) @@ -1,6 +1,6 @@ #/************************************************************************** -# OmegaT - Computer Assisted Translation (CAT) tool -# with fuzzy matching, translation memory, keyword search, +# OmegaT - Computer Assisted Translation (CAT) tool +# with fuzzy matching, translation memory, keyword search, # glossaries, and translation leveraging into updated projects. # # Copyright (C) 2000-2006 Keith Godfrey, Maxym Mykhalchuk, and Henry Pijffers @@ -258,11 +258,11 @@ MW_STATUS_SAVED=Project saved -MW_SEGMENT_LENGTH_DEFAULT=\ --/-- +MW_SEGMENT_LENGTH_DEFAULT=\ --/-- MW_QUIT_CONFIRM=Do you really want to quit? MW_SEGMENT_LENGTH_TOOLTIP=Source/translation lengths (characters) -MW_PROGRESS_DEFAULT=\ --/-- (--/--, --) +MW_PROGRESS_DEFAULT=\ --/-- (--/--, --) MW_PROGRESS_TOOLTIP=File: translated / number of segments \ (project: unique translated / unique, total number of segments) @@ -272,7 +272,7 @@ # NOTE: segment start is assumed to end with "0000" string to overwrite # with entry number. If zeros not detected, entry number will not be # displayed -TF_CUR_SEGMENT_START=<segment 0000> +TF_CUR_SEGMENT_START=<segment 0000> TF_CUR_SEGMENT_END=<end segment> @@ -298,7 +298,7 @@ PF_NUM_SEGMENTS=Number of Segments -PF_STAT_PATH=You can find detailed statistic information in the file:\n{0} +PF_STAT_PATH=You can find detailed statistic information in the file:\n{0} GUI_PROJECT_TOTAL_SEGMENTS=Total number of segments @@ -310,7 +310,7 @@ # Help Frame HF_WINDOW_TITLE=User's Manual -HF_CANT_FIND_HELP=Cannot locate help file: +HF_CANT_FIND_HELP=Cannot locate help file: HF_ERROR_EXTLINK_TITLE=Cannot open the link {0} @@ -379,7 +379,7 @@ CT_ERROR_ACCESS_GLOSSARY_DIR=Cannot access glossary folder! -CT_ERROR_CREATING_TARGET_DIR=Cannot create folder for translated files: +CT_ERROR_CREATING_TARGET_DIR=Cannot create folder for translated files: # 0 - Name of TMX file CT_ERROR_CANNOT_FIND_TMX=Cannot find saved TMX: {0} @@ -448,7 +448,7 @@ PP_SRC_ROOT=Source Files Folder: -PP_LOC_ROOT=Translated Files Folder: +PP_LOC_ROOT=Translated Files Folder: PP_GLOS_ROOT=Glossary Folder: @@ -458,7 +458,7 @@ PP_LOC_LANG=&Translated Files Language: -PP_DICT_ROOT=Dictionary Folder: +PP_DICT_ROOT=Dictionary Folder: PP_BUTTON_BROWSE_SRC=&Browse @@ -534,7 +534,7 @@ OFC_NEW_DIR_ERROR=An error occurred while trying to create a new folder #SearchWindow -SW_SEARCH_TEXT=Search for: +SW_SEARCH_TEXT=Search for: SW_WORD_SEARCH=&Keyword search @@ -596,7 +596,7 @@ XSR_ERROR_CANNOT_LOAD_XML=Cannot load specified XML file! \n -XSR_ERROR_IOEXCEPTION=IOException encountered: +XSR_ERROR_IOEXCEPTION=IOException encountered: # {0} - character # {1} - stream reader state @@ -604,17 +604,17 @@ XSR_ERROR_CONFUSED=Confused by false start of comment tag! -XSR_ERROR_TAG_NAME=\nTag name: +XSR_ERROR_TAG_NAME=\nTag name: -XSR_ERROR_COMMENT_TAG=(comment tag) +XSR_ERROR_COMMENT_TAG=(comment tag) XSR_ERROR_FLOATING_QUESTION_MARK=Floating '?' character not tied to '>'! -XSR_ERROR_EMPTY_TAG=(empty tag) +XSR_ERROR_EMPTY_TAG=(empty tag) -XSR_ERROR_CLOSE_TAG=(close tag) +XSR_ERROR_CLOSE_TAG=(close tag) -XSR_ERROR_LOADED=loaded +XSR_ERROR_LOADED=loaded XSR_ERROR_ATTRIBUTES= attributes. @@ -809,7 +809,7 @@ DocBook_HINT=Note\: DocBook files are recognized not only by file extension, but they also must have a DOCTYPE declaration\: <\!DOCTYPE book PUBLIC \\"-//OASIS//DTD DocBook XML... for DocBook 4, or a Namespace\: xmlns="http\://docbook.org/ns/docbook" for DocBook 5 # SrtFilter.java -SRTFILTER_FILTER_NAME=Subtitles Files +SRTFILTER_FILTER_NAME=SubRip Subtitles Files # AndroidFilter.java Android_FILTER_NAME=Android Resource Files @@ -829,7 +829,7 @@ OpenDoc_TRANSLATE_BOOKMARKREFS=Bookmark &references OpenDoc_TRANSLATE_NOTES=&Notes OpenDoc_TRANSLATE_COMMENTS=&Comments -OpenDoc_ERROR_IN_FILE=Error in file +OpenDoc_ERROR_IN_FILE=Error in file # org.omegat.filters3.xml.openxml.OpenXMLFilter @@ -1069,7 +1069,7 @@ WF_OPTION_INSERT_FUZZY_PREFIX=&Prefix: -WF_DEFAULT_PREFIX=[fuzzy]\ +WF_DEFAULT_PREFIX=[fuzzy]\ WF_OPTION_ALLOW_TRANS_EQ_TO_SRC=&Allow translation to be equal to source WF_OPTION_EXPORT__CURRENT_SEGMENT=Export the segment to text files @@ -1134,13 +1134,13 @@ LOG_INFO_EVENT_PROJECT_CHANGE=Event: project change - "{0}" -LOG_INFO_EVENT_APPLICATION_STARTUP=Event: application startup +LOG_INFO_EVENT_APPLICATION_STARTUP=Event: application startup LOG_INFO_EVENT_APPLICATION_SHUTDOWN=Event: application shutdown LOG_INFO_EVENT_ENTRY_NEWFILE=Event: new file activated ({0}) LOG_INFO_EVENT_ENTRY_ACTIVATED=Event: new entry activated -LOG_INFO_EVENT_FONT_CHANGED=Event: font changed -LOG_ERROR_MUST_BE_SWING_THREAD=This call MUST be in swing thread -LOG_ERROR_MUSTNOT_BE_SWING_THREAD=This call MUST NOT be in swing thread +LOG_INFO_EVENT_FONT_CHANGED=Event: font changed +LOG_ERROR_MUST_BE_SWING_THREAD=This call MUST be in swing thread +LOG_ERROR_MUSTNOT_BE_SWING_THREAD=This call MUST NOT be in swing thread LOG_DATAENGINE_LOAD_START=Project loading start LOG_DATAENGINE_LOAD_END=Project loading end Modified: trunk/src/org/omegat/Bundle_nl.properties =================================================================== --- trunk/src/org/omegat/Bundle_nl.properties 2009-10-06 12:43:37 UTC (rev 2394) +++ trunk/src/org/omegat/Bundle_nl.properties 2009-10-08 12:24:29 UTC (rev 2395) @@ -1,6 +1,6 @@ #/************************************************************************** -# OmegaT - Computer Assisted Translation (CAT) tool -# with fuzzy matching, translation memory, keyword search, +# OmegaT - Computer Assisted Translation (CAT) tool +# with fuzzy matching, translation memory, keyword search, # glossaries, and translation leveraging into updated projects. # # Copyright (C) 2000-2006 Keith Godfrey, Maxym Mykhalchuk, and Henry Pijffers @@ -234,11 +234,11 @@ MW_STATUS_SAVED=Project opgeslagen -MW_SEGMENT_LENGTH_DEFAULT=\ --/-- +MW_SEGMENT_LENGTH_DEFAULT=\ --/-- MW_QUIT_CONFIRM=Wilt u werkelijk afsluiten? MW_SEGMENT_LENGTH_TOOLTIP=Lengte bron/vertaling (tekens) -MW_PROGRESS_DEFAULT=\ --/-- (--/--, --) +MW_PROGRESS_DEFAULT=\ --/-- (--/--, --) MW_PROGRESS_TOOLTIP=Bestand: vertaald / aantal segmenten (project: unieke vertaalde / unieke, totaal aantal segmenten) @@ -247,7 +247,7 @@ # NOTE: segment start is assumed to end with "0000" string to overwrite # with entry number. If zeros not detected, entry number will not be # displayed -TF_CUR_SEGMENT_START=<segment 0000> +TF_CUR_SEGMENT_START=<segment 0000> TF_CUR_SEGMENT_END=<einde segment> @@ -273,7 +273,7 @@ PF_NUM_SEGMENTS=Aantal segmenten -PF_STAT_PATH=U vindt gedetailleerde statistische informatie in het bestand:\n{0} +PF_STAT_PATH=U vindt gedetailleerde statistische informatie in het bestand:\n{0} GUI_PROJECT_TOTAL_SEGMENTS=Totaal aantal segmenten @@ -285,7 +285,7 @@ # Help Frame HF_WINDOW_TITLE=Gebr&uikershandleiding... -HF_CANT_FIND_HELP=Kan helpbestand niet vinden. Bestand: +HF_CANT_FIND_HELP=Kan helpbestand niet vinden. Bestand: HF_ERROR_EXTLINK_TITLE=Kan de koppeling niet openen {0} @@ -349,7 +349,7 @@ CT_ERROR_ACCESS_GLOSSARY_DIR=Kan map van de woordenlijst niet openen! -CT_ERROR_CREATING_TARGET_DIR=Kan map voor de vertaalde bestanden niet maken: +CT_ERROR_CREATING_TARGET_DIR=Kan map voor de vertaalde bestanden niet maken: # 0 - Name of TMX file CT_ERROR_CANNOT_FIND_TMX=Kan opgeslagen TMX niet vinden: {0} @@ -404,7 +404,7 @@ PP_SRC_ROOT=map Bronbestanden: -PP_LOC_ROOT=map Vertaalde documenten: +PP_LOC_ROOT=map Vertaalde documenten: PP_GLOS_ROOT=map Woordenlijst: @@ -414,7 +414,7 @@ PP_LOC_LANG=&Taal vertaalde bestanden: -PP_DICT_ROOT=map Woordenboek: +PP_DICT_ROOT=map Woordenboek: PP_BUTTON_BROWSE_SRC=&Bladeren @@ -483,7 +483,7 @@ OFC_NEW_DIR_ERROR=Er trad een fout op bij het maken van een nieuwe map #SearchWindow -SW_SEARCH_TEXT=Zoeken naar: +SW_SEARCH_TEXT=Zoeken naar: SW_WORD_SEARCH=Sleutelwoorden zoeken @@ -533,7 +533,7 @@ XSR_ERROR_CANNOT_LOAD_XML=Kan gespecificeerde XML-bestand niet laden! \n -XSR_ERROR_IOEXCEPTION=IO Uitzondering opgetreden: +XSR_ERROR_IOEXCEPTION=IO Uitzondering opgetreden: # {0} - character # {1} - stream reader state @@ -541,17 +541,17 @@ XSR_ERROR_CONFUSED=Verwarring bij valse start van een opmerking-tag! -XSR_ERROR_TAG_NAME=\nTagnaam: +XSR_ERROR_TAG_NAME=\nTagnaam: -XSR_ERROR_COMMENT_TAG=(opmerking-tag) +XSR_ERROR_COMMENT_TAG=(opmerking-tag) XSR_ERROR_FLOATING_QUESTION_MARK=Zwevend teken '?' niet verbonden aan '>'! -XSR_ERROR_EMPTY_TAG=(lege tag) +XSR_ERROR_EMPTY_TAG=(lege tag) -XSR_ERROR_CLOSE_TAG=(sluitingstag) +XSR_ERROR_CLOSE_TAG=(sluitingstag) -XSR_ERROR_LOADED=geladen +XSR_ERROR_LOADED=geladen XSR_ERROR_ATTRIBUTES= attributen. @@ -737,7 +737,7 @@ DocBook_HINT=Opmerking: DocBook-bestanden worden niet alleen herkend aan hun bestandsextensie, maar zij moeten ook een DOCTYPE-declaratie hebben: <!DOCTYPE book PUBLIC \\"-//OASIS//DTD DocBook XML... voor DocBook 4 of een naamruimte: xmlns="http://docbook.org/ns/docbook" voor DocBook 5 # SrtFilter.java -SRTFILTER_FILTER_NAME=Ondertitels van bestanden +SRTFILTER_FILTER_NAME=SubRip Ondertitel-bestanden # INIFilter.java @@ -754,7 +754,7 @@ OpenDoc_TRANSLATE_BOOKMARKREFS=Ve&rwijzingen naar bladwijzers OpenDoc_TRANSLATE_NOTES=&Notities OpenDoc_TRANSLATE_COMMENTS=&Opmerkingen -OpenDoc_ERROR_IN_FILE=Fout in bestand +OpenDoc_ERROR_IN_FILE=Fout in bestand # org.omegat.filters3.xml.openxml.OpenXMLFilter @@ -966,7 +966,7 @@ WF_OPTION_INSERT_FUZZY_PREFIX=&Voorvoegsel: -WF_DEFAULT_PREFIX=[fuzzy] +WF_DEFAULT_PREFIX=[fuzzy] WF_OPTION_ALLOW_TRANS_EQ_TO_SRC=Vert&aling mag gelijk zijn aan brontekst WF_OPTION_EXPORT__CURRENT_SEGMENT=Exporteer het segment naar tekstbestanden @@ -1017,13 +1017,13 @@ LOG_INFO_EVENT_PROJECT_CHANGE=Gebeurtenis: project wijziging - "{0}" -LOG_INFO_EVENT_APPLICATION_STARTUP=Gebeurtenis: starten van toepassing +LOG_INFO_EVENT_APPLICATION_STARTUP=Gebeurtenis: starten van toepassing LOG_INFO_EVENT_APPLICATION_SHUTDOWN=Gebeurtenis: stoppen van toepassing LOG_INFO_EVENT_ENTRY_NEWFILE=Gebeurtenis: nieuw bestand geactiveerd ({0}) LOG_INFO_EVENT_ENTRY_ACTIVATED=Gebeurtenis: nieuw item geactiveerd -LOG_INFO_EVENT_FONT_CHANGED=Gebeurtenis: lettertype gewijzigd -LOG_ERROR_MUST_BE_SWING_THREAD=Deze aanroep MOET in swing-thread zijn -LOG_ERROR_MUSTNOT_BE_SWING_THREAD=Deze aanroep MOET NIET in swing-thread zijn +LOG_INFO_EVENT_FONT_CHANGED=Gebeurtenis: lettertype gewijzigd +LOG_ERROR_MUST_BE_SWING_THREAD=Deze aanroep MOET in swing-thread zijn +LOG_ERROR_MUSTNOT_BE_SWING_THREAD=Deze aanroep MOET NIET in swing-thread zijn LOG_DATAENGINE_LOAD_START=Laden van project gestart LOG_DATAENGINE_LOAD_END=Laden van project be\u00ebindigd This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <al...@us...> - 2009-10-19 05:52:01
|
Revision: 2432 http://omegat.svn.sourceforge.net/omegat/?rev=2432&view=rev Author: alex73 Date: 2009-10-19 05:51:52 +0000 (Mon, 19 Oct 2009) Log Message: ----------- Project memory storage refactoring: separate TMX prepare and save Modified Paths: -------------- trunk/src/org/omegat/Main.java trunk/src/org/omegat/core/data/RealProject.java trunk/src/org/omegat/util/TMXWriter.java Modified: trunk/src/org/omegat/Main.java =================================================================== --- trunk/src/org/omegat/Main.java 2009-10-19 05:21:59 UTC (rev 2431) +++ trunk/src/org/omegat/Main.java 2009-10-19 05:51:52 UTC (rev 2432) @@ -271,7 +271,10 @@ fname=""; } try { - TMXWriter.buildTMXFile(fname, false, false, true, m_config, m_strEntryList, m_orphanedList, true, pseudoTranslateType); + Map<String, String> tmx = TMXWriter.prepareTMXData(false, + m_strEntryList, m_orphanedList, true, + pseudoTranslateType); + TMXWriter.buildTMXFile(fname, false, true, m_config, tmx); } catch (IOException e) { Log.logErrorRB("CT_ERROR_CREATING_TMX"); Log.log(e); Modified: trunk/src/org/omegat/core/data/RealProject.java =================================================================== --- trunk/src/org/omegat/core/data/RealProject.java 2009-10-19 05:21:59 UTC (rev 2431) +++ trunk/src/org/omegat/core/data/RealProject.java 2009-10-19 05:51:52 UTC (rev 2432) @@ -259,20 +259,22 @@ // - TMX Level 2, with OmegaT formatting tags wrapped in TMX inline tags try { + Map<String,String> tmx = TMXWriter.prepareTMXData(false, m_strEntryList, m_orphanedList, false, null); + // build TMX with OmegaT tags String fname = m_config.getProjectRoot() + m_config.getProjectName() + OConsts.OMEGAT_TMX + OConsts.TMX_EXTENSION; - TMXWriter.buildTMXFile(fname, false, false, false, m_config, m_strEntryList, m_orphanedList, false, null); + TMXWriter.buildTMXFile(fname, false, false, m_config, tmx); // build TMX level 1 compliant file fname = m_config.getProjectRoot() + m_config.getProjectName() + OConsts.LEVEL1_TMX + OConsts.TMX_EXTENSION; - TMXWriter.buildTMXFile(fname, true, false, false, m_config, m_strEntryList, m_orphanedList, false, null); + TMXWriter.buildTMXFile(fname, true, false, m_config, tmx); // build three-quarter-assed TMX level 2 file fname = m_config.getProjectRoot() + m_config.getProjectName() + OConsts.LEVEL2_TMX + OConsts.TMX_EXTENSION; - TMXWriter.buildTMXFile(fname, false, false, true, m_config, m_strEntryList, m_orphanedList, false, null); + TMXWriter.buildTMXFile(fname, false, true, m_config, tmx); } catch (IOException e) { @@ -384,8 +386,9 @@ try { saveProjectProperties(); - - TMXWriter.buildTMXFile(s, false, true, false, m_config, m_strEntryList, m_orphanedList, false, null); + + Map<String,String> tmx = TMXWriter.prepareTMXData(true, m_strEntryList, m_orphanedList, false, null); + TMXWriter.buildTMXFile(s, false, false, m_config, tmx); m_modifiedFlag = false; } catch (IOException e) Modified: trunk/src/org/omegat/util/TMXWriter.java =================================================================== --- trunk/src/org/omegat/util/TMXWriter.java 2009-10-19 05:21:59 UTC (rev 2431) +++ trunk/src/org/omegat/util/TMXWriter.java 2009-10-19 05:51:52 UTC (rev 2432) @@ -5,6 +5,7 @@ Copyright (C) 2000-2006 Keith Godfrey, Maxym Mykhalchuk, and Henry Pijffers Portions copyright 2007 Zoltan Bartko - bar...@ba... + 2009 Alex Buloichik Home page: http://www.omegat.org/ Support center: http://groups.yahoo.com/group/OmegaT/ @@ -29,7 +30,9 @@ import java.io.IOException; import java.io.OutputStreamWriter; import java.io.PrintWriter; +import java.util.HashMap; import java.util.List; +import java.util.Map; import java.util.regex.Matcher; import java.util.regex.Pattern; @@ -42,30 +45,82 @@ * Class that store TMX (Translation Memory Exchange) files. */ public class TMXWriter { - /* + /** + * Prepare TMX data for export to file. + * + * @param addOrphans + * When true, the segments in the m_orphanedList are added to the + * TMX as well. + * @param m_strEntryList + * List of translated segments + * @param m_orphanedList + * List of translated segments that have no match in the current + * sources + * @param pseudoTranslate + * When true, a tu-section is created for every segment in the + * sources, even when there is no translation available. + * @param pseudo_translate_type + * When pseudo-translate is true:<br> + * If 'equal' then the translation that is written is equal to + * the source.<br> + * If 'empty', the translation is an empty string.<br> + * When pseudoTranslate is false, this parameter is ignored. + * @return map of strings for TMX + */ + public static Map<String, String> prepareTMXData(final boolean addOrphans, + final List<StringEntry> m_strEntryList, + final List<TransMemory> m_orphanedList, + final boolean pseudoTranslate, + PSEUDO_TRANSLATE_TYPE pseudo_translate_type) { + Map<String, String> result = new HashMap<String, String>(); + String source = null; + String target = null; + for (StringEntry se : m_strEntryList) { + source = se.getSrcText(); + if (!pseudoTranslate) { + target = se.getTranslation(); + if (target.length() == 0) + continue; + } else { + if (pseudo_translate_type.equals(PSEUDO_TRANSLATE_TYPE.EQUAL)) { + target = source; + } else { + // must be PSEUDO_TRANSLATE_TYPE.EMPTY + target = ""; + } + } + result.put(source, target); + } + + // Write orphan strings. Assume N/A when pseudo-translate. + if (addOrphans) { + for (TransMemory transMem : m_orphanedList) { + if (transMem.target.length() == 0) + continue; + source = transMem.source; + target = transMem.target; + if (target.length() == 0) + continue; + result.put(source, target); + } + } + return result; + } + + /** * Saves a TMX file to disk * * @author Henry Pijffers (hen...@sa...) * @author Maxym Mykhalchuk * @param filename The name of the file to create * @param forceValidTMX When true, OmegaT-tags are stripped from the segments. - * @param addOrphans When true, the segments in the m_orphanedList are added - * to the TMX as well. * @param levelTwo When true, the tmx is made compatible with level 2 (TMX version 1.4) * @param m_config Project configuration, to get the languages - * @param m_strEntryList List of translated segments - * @param m_orphanedList List of translated segments that have no match in the current sources - * @param pseudoTranslate When true, a tu-section is created for every segment in the sources, even when there is no translation available. - * @param pseudo_translate_type When pseudo-translate is true:<br> - * If 'equal' then the translation that is written is equal to the source.<br> - * If 'empty', the translation is an empty string.<br> - * When pseudoTranslate is false, this parameter is ignored. + * @param data Data for save to TMX * @throws IOException */ - public static void buildTMXFile(final String filename, final boolean forceValidTMX, final boolean addOrphans, - final boolean levelTwo, final ProjectProperties m_config, final List<StringEntry> m_strEntryList, - final List<TransMemory> m_orphanedList, - final boolean pseudoTranslate, PSEUDO_TRANSLATE_TYPE pseudo_translate_type) throws IOException { + public static void buildTMXFile(final String filename, final boolean forceValidTMX, + final boolean levelTwo, final ProjectProperties m_config, final Map<String,String> data) throws IOException { // we got this far, so assume lang codes are proper String sourceLocale = m_config.getSourceLanguage().toString(); String targetLocale = m_config.getTargetLanguage().toString(); @@ -110,65 +165,27 @@ // Write TUs String source = null; String target = null; - for (StringEntry se : m_strEntryList) { - source = forceValidTMX ? StaticUtils.stripTags(se.getSrcText()) : se.getSrcText(); - if (!pseudoTranslate) { - target = forceValidTMX ? StaticUtils.stripTags(se.getTranslation()) : se.getTranslation(); - if (target.length() == 0) - continue; - } else { - if (pseudo_translate_type.equals(PSEUDO_TRANSLATE_TYPE.EQUAL)) { - target = source; - } else { - //must be PSEUDO_TRANSLATE_TYPE.EMPTY - target = ""; - } - } - source = StaticUtils.makeValidXML(source); - target = StaticUtils.makeValidXML(target); - - // TO DO: This *possibly* converts occurrences in the actual text of <fX> - // which it should not. + for(Map.Entry<String, String> en:data.entrySet()) { + source = forceValidTMX ? StaticUtils.stripTags(en.getKey()) : en + .getKey(); + target = forceValidTMX ? StaticUtils.stripTags(en.getValue()) : en + .getValue(); if (levelTwo) { source = makeLevelTwo(source); target = makeLevelTwo(target); } - out.println(" <tu>"); // NOI18N - out.println(" <tuv " + langAttr + "=\"" + sourceLocale + "\">"); // NOI18N - out.println(" <seg>" + source + "</seg>"); // NOI18N - out.println(" </tuv>"); // NOI18N - out.println(" <tuv " + langAttr + "=\"" + targetLocale + "\">"); // NOI18N - out.println(" <seg>" + target + "</seg>"); // NOI18N - out.println(" </tuv>"); // NOI18N - out.println(" </tu>"); // NOI18N + source = StaticUtils.makeValidXML(source); + target = StaticUtils.makeValidXML(target); + out.println(" <tu>"); + out.println(" <tuv " + langAttr + "=\"" + sourceLocale + "\">"); + out.println(" <seg>" + source + "</seg>"); + out.println(" </tuv>"); + out.println(" <tuv " + langAttr + "=\"" + targetLocale + "\">"); + out.println(" <seg>" + target + "</seg>"); + out.println(" </tuv>"); + out.println(" </tu>"); } - // Write orphan strings. Assume N/A when pseudo-translate. - if (addOrphans) { - for (TransMemory transMem : m_orphanedList) { - if (transMem.target.length() == 0) - continue; - source = forceValidTMX ? StaticUtils.stripTags(transMem.source) : transMem.source; - target = forceValidTMX ? StaticUtils.stripTags(transMem.target) : transMem.target; - if (levelTwo) { - source = makeLevelTwo(source); - target = makeLevelTwo(target); - } - if (target.length() == 0) - continue; - source = StaticUtils.makeValidXML(source); - target = StaticUtils.makeValidXML(target); - out.println(" <tu>"); // NOI18N - out.println(" <tuv " + langAttr + "=\"" + sourceLocale + "\">"); // NOI18N - out.println(" <seg>" + source + "</seg>"); // NOI18N - out.println(" </tuv>"); // NOI18N - out.println(" <tuv " + langAttr + "=\"" + targetLocale + "\">"); // NOI18N - out.println(" <seg>" + target + "</seg>"); // NOI18N - out.println(" </tuv>"); // NOI18N - out.println(" </tu>"); // NOI18N - } - } - // Write TMX footer out.println(" </body>"); // NOI18N out.println("</tmx>"); // NOI18N This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <al...@us...> - 2009-10-19 06:03:46
|
Revision: 2433 http://omegat.svn.sourceforge.net/omegat/?rev=2433&view=rev Author: alex73 Date: 2009-10-19 06:03:36 +0000 (Mon, 19 Oct 2009) Log Message: ----------- Project memory storage refactoring: TMX: orphaned usage Modified Paths: -------------- trunk/src/org/omegat/Main.java trunk/src/org/omegat/core/data/RealProject.java trunk/src/org/omegat/util/TMXWriter.java Modified: trunk/src/org/omegat/Main.java =================================================================== --- trunk/src/org/omegat/Main.java 2009-10-19 05:51:52 UTC (rev 2432) +++ trunk/src/org/omegat/Main.java 2009-10-19 06:03:36 UTC (rev 2433) @@ -255,7 +255,6 @@ ProjectProperties m_config = p.getProjectProperties(); List<StringEntry> m_strEntryList = p.getUniqueEntries(); - ArrayList<TransMemory> m_orphanedList = new ArrayList<TransMemory>(); String pseudoTranslateTMXFilename = RuntimePreferences.getPseudoTranslateTMXFile(); PSEUDO_TRANSLATE_TYPE pseudoTranslateType = RuntimePreferences.getPseudoTranslateType(); @@ -271,8 +270,8 @@ fname=""; } try { - Map<String, String> tmx = TMXWriter.prepareTMXData(false, - m_strEntryList, m_orphanedList, true, + Map<String, String> tmx = TMXWriter.prepareTMXData( + m_strEntryList, null, true, pseudoTranslateType); TMXWriter.buildTMXFile(fname, false, true, m_config, tmx); } catch (IOException e) { Modified: trunk/src/org/omegat/core/data/RealProject.java =================================================================== --- trunk/src/org/omegat/core/data/RealProject.java 2009-10-19 05:51:52 UTC (rev 2432) +++ trunk/src/org/omegat/core/data/RealProject.java 2009-10-19 06:03:36 UTC (rev 2433) @@ -259,7 +259,7 @@ // - TMX Level 2, with OmegaT formatting tags wrapped in TMX inline tags try { - Map<String,String> tmx = TMXWriter.prepareTMXData(false, m_strEntryList, m_orphanedList, false, null); + Map<String,String> tmx = TMXWriter.prepareTMXData(m_strEntryList, null, false, null); // build TMX with OmegaT tags String fname = m_config.getProjectRoot() + m_config.getProjectName() + OConsts.OMEGAT_TMX @@ -387,7 +387,7 @@ { saveProjectProperties(); - Map<String,String> tmx = TMXWriter.prepareTMXData(true, m_strEntryList, m_orphanedList, false, null); + Map<String,String> tmx = TMXWriter.prepareTMXData(m_strEntryList, m_orphanedList, false, null); TMXWriter.buildTMXFile(s, false, false, m_config, tmx); m_modifiedFlag = false; } Modified: trunk/src/org/omegat/util/TMXWriter.java =================================================================== --- trunk/src/org/omegat/util/TMXWriter.java 2009-10-19 05:51:52 UTC (rev 2432) +++ trunk/src/org/omegat/util/TMXWriter.java 2009-10-19 06:03:36 UTC (rev 2433) @@ -67,7 +67,7 @@ * When pseudoTranslate is false, this parameter is ignored. * @return map of strings for TMX */ - public static Map<String, String> prepareTMXData(final boolean addOrphans, + public static Map<String, String> prepareTMXData( final List<StringEntry> m_strEntryList, final List<TransMemory> m_orphanedList, final boolean pseudoTranslate, @@ -93,7 +93,7 @@ } // Write orphan strings. Assume N/A when pseudo-translate. - if (addOrphans) { + if (m_orphanedList != null) { for (TransMemory transMem : m_orphanedList) { if (transMem.target.length() == 0) continue; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <al...@us...> - 2009-10-19 06:21:11
|
Revision: 2434 http://omegat.svn.sourceforge.net/omegat/?rev=2434&view=rev Author: alex73 Date: 2009-10-19 06:20:56 +0000 (Mon, 19 Oct 2009) Log Message: ----------- Project memory storage refactoring: remove pseudo-translate from main application flow Modified Paths: -------------- trunk/src/org/omegat/Main.java trunk/src/org/omegat/core/data/RealProject.java trunk/src/org/omegat/util/RuntimePreferences.java trunk/src/org/omegat/util/TMXWriter.java Modified: trunk/src/org/omegat/Main.java =================================================================== --- trunk/src/org/omegat/Main.java 2009-10-19 06:03:36 UTC (rev 2433) +++ trunk/src/org/omegat/Main.java 2009-10-19 06:20:56 UTC (rev 2434) @@ -27,8 +27,8 @@ import java.io.File; import java.io.IOException; -import java.util.ArrayList; import java.util.Date; +import java.util.HashMap; import java.util.List; import java.util.Locale; import java.util.Map; @@ -45,15 +45,13 @@ import org.omegat.core.data.ProjectFactory; import org.omegat.core.data.ProjectProperties; import org.omegat.core.data.RealProject; -import org.omegat.core.data.StringEntry; -import org.omegat.core.data.TransMemory; +import org.omegat.core.data.SourceTextEntry; import org.omegat.util.Log; import org.omegat.util.OConsts; import org.omegat.util.OStrings; import org.omegat.util.ProjectFileStorage; import org.omegat.util.RuntimePreferences; import org.omegat.util.TMXWriter; -import org.omegat.util.RuntimePreferences.PSEUDO_TRANSLATE_TYPE; import com.vlsolutions.swing.docking.DockingDesktop; @@ -77,7 +75,24 @@ } } }; + + /** + * Choice of types of translation for all segments in the optional, special + * TMX file that contains all segments of the project. + */ + enum PSEUDO_TRANSLATE_TYPE { + EQUAL, EMPTY; + public static PSEUDO_TRANSLATE_TYPE parse(String s) { + try { + return valueOf(s.toUpperCase().replace('-', '_')); + } catch (Exception ex) { + // default mode + return EQUAL; + } + } + }; + /** Regexp for parse parameters. */ protected static final Pattern PARAM = Pattern .compile("\\-\\-([A-Za-z\\-]+)(=(.+))?"); @@ -129,11 +144,6 @@ RuntimePreferences.setQuietMode(true); } - if (params.containsKey("pseudotranslatetmx")) { - RuntimePreferences.setPseudoTranslateTMXFile(params.get("pseudotranslatetmx")); - RuntimePreferences.setPseudoTranslateType(params.get("pseudotranslatetype")); - } - Log.log("\n" + // NOI18N "===================================================================" @@ -151,8 +161,10 @@ runGUI(); break; case CONSOLE_TRANSLATE: + runConsoleTranslate(); + break; case CONSOLE_CREATEPSEUDOTRANSLATETMX: - runConsoleTranslate(runMode); + runCreatePseudoTranslateTMX(); break; } } @@ -213,7 +225,7 @@ /** * Execute in console mode for translate. */ - protected static void runConsoleTranslate(RUN_MODE runMode) { + protected static void runConsoleTranslate() { Log.log("Console mode"); Log.log(""); @@ -245,44 +257,92 @@ RealProject p = new RealProject(projectProperties, false); Core.setProject(p); - switch (runMode) { - case CONSOLE_TRANSLATE: - System.out.println("Translating Project"); - p.compileProject(); - break; - case CONSOLE_CREATEPSEUDOTRANSLATETMX: - System.out.println("Translating Project"); + System.out.println("Translating Project"); + p.compileProject(); - ProjectProperties m_config = p.getProjectProperties(); - List<StringEntry> m_strEntryList = p.getUniqueEntries(); - String pseudoTranslateTMXFilename = RuntimePreferences.getPseudoTranslateTMXFile(); - PSEUDO_TRANSLATE_TYPE pseudoTranslateType = RuntimePreferences.getPseudoTranslateType(); + System.out.println("Finished"); + } catch (Exception e) { + System.err.println("An error has occured: " + e.toString()); + System.exit(1); + } + } - String fname; - if (pseudoTranslateTMXFilename != null && pseudoTranslateTMXFilename.length()>0) { - if (!pseudoTranslateTMXFilename.endsWith(OConsts.TMX_EXTENSION)) { - fname = pseudoTranslateTMXFilename+"."+OConsts.TMX_EXTENSION; - } else { - fname = pseudoTranslateTMXFilename; - } - + /** + * Execute in console mode for translate. + */ + protected static void runCreatePseudoTranslateTMX() { + Log.log("Console mode"); + Log.log(""); + + System.out.println("Initializing"); + try { + Core.initializeConsole(params); + } catch (Throwable ex) { + showError(ex); + } + try { + System.out.println("Loading Project"); + + // check if project okay + ProjectProperties projectProperties = null; + try { + projectProperties = ProjectFileStorage + .loadProjectProperties(projectLocation); + if (!projectProperties.verifyProject()) { + System.out.println("The project cannot be verified"); + System.exit(1); + } + } catch (Exception ex) { + Log.logErrorRB(ex, "PP_ERROR_UNABLE_TO_READ_PROJECT_FILE"); + System.out.println(OStrings.getString + ("PP_ERROR_UNABLE_TO_READ_PROJECT_FILE")); + System.exit(1); + } + + RealProject p = new RealProject(projectProperties, false); + Core.setProject(p); + + System.out.println("Create pseudo-translate TMX"); + + ProjectProperties m_config = p.getProjectProperties(); + List<SourceTextEntry> entries = p.getAllEntries(); + String pseudoTranslateTMXFilename = params.get("pseudotranslatetmx"); + PSEUDO_TRANSLATE_TYPE pseudoTranslateType = PSEUDO_TRANSLATE_TYPE.parse(params.get("pseudotranslatetype")); + + String fname; + if (pseudoTranslateTMXFilename != null && pseudoTranslateTMXFilename.length()>0) { + if (!pseudoTranslateTMXFilename.endsWith(OConsts.TMX_EXTENSION)) { + fname = pseudoTranslateTMXFilename+"."+OConsts.TMX_EXTENSION; } else { - fname=""; + fname = pseudoTranslateTMXFilename; } - try { - Map<String, String> tmx = TMXWriter.prepareTMXData( - m_strEntryList, null, true, - pseudoTranslateType); - TMXWriter.buildTMXFile(fname, false, true, m_config, tmx); - } catch (IOException e) { - Log.logErrorRB("CT_ERROR_CREATING_TMX"); - Log.log(e); - throw new IOException(OStrings.getString("CT_ERROR_CREATING_TMX") + - "\n" + // NOI18N - e.getMessage()); + + } else { + fname=""; + } + + // prepare tmx + Map<String, String> tmx = new HashMap<String, String>(); + for(SourceTextEntry ste: entries) { + switch (pseudoTranslateType) { + case EQUAL: + tmx.put(ste.getSrcText(), ste.getSrcText()); + break; + case EMPTY: + tmx.put(ste.getSrcText(), ""); + break; } - break; } + + try { + TMXWriter.buildTMXFile(fname, false, true, m_config, tmx); + } catch (IOException e) { + Log.logErrorRB("CT_ERROR_CREATING_TMX"); + Log.log(e); + throw new IOException(OStrings.getString("CT_ERROR_CREATING_TMX") + + "\n" + // NOI18N + e.getMessage()); + } System.out.println("Finished"); } catch (Exception e) { Modified: trunk/src/org/omegat/core/data/RealProject.java =================================================================== --- trunk/src/org/omegat/core/data/RealProject.java 2009-10-19 06:03:36 UTC (rev 2433) +++ trunk/src/org/omegat/core/data/RealProject.java 2009-10-19 06:20:56 UTC (rev 2434) @@ -259,7 +259,7 @@ // - TMX Level 2, with OmegaT formatting tags wrapped in TMX inline tags try { - Map<String,String> tmx = TMXWriter.prepareTMXData(m_strEntryList, null, false, null); + Map<String,String> tmx = TMXWriter.prepareTMXData(m_strEntryList, null); // build TMX with OmegaT tags String fname = m_config.getProjectRoot() + m_config.getProjectName() + OConsts.OMEGAT_TMX @@ -387,7 +387,7 @@ { saveProjectProperties(); - Map<String,String> tmx = TMXWriter.prepareTMXData(m_strEntryList, m_orphanedList, false, null); + Map<String,String> tmx = TMXWriter.prepareTMXData(m_strEntryList, m_orphanedList); TMXWriter.buildTMXFile(s, false, false, m_config, tmx); m_modifiedFlag = false; } Modified: trunk/src/org/omegat/util/RuntimePreferences.java =================================================================== --- trunk/src/org/omegat/util/RuntimePreferences.java 2009-10-19 06:03:36 UTC (rev 2433) +++ trunk/src/org/omegat/util/RuntimePreferences.java 2009-10-19 06:20:56 UTC (rev 2434) @@ -38,32 +38,6 @@ /** Force use specified config dir. */ private static String configDir; - /** - * Filename to use for creating a TMX that contains all segments in the project. - */ - private static String pseudoTranslateTMXFile; - - /** - * Choice of types of translation for all segments in the optional, special - * TMX file that contains all segments of the project. - */ - public enum PSEUDO_TRANSLATE_TYPE { - EQUAL, EMPTY; - public static PSEUDO_TRANSLATE_TYPE parse(String s) { - try { - return valueOf(s.toUpperCase().replace('-', '_')); - } catch (Exception ex) { - // default mode - return EQUAL; - } - } - }; - /** - * Type of translation for all segments in the optional, special TMX file - * that contains all segments of the project. - */ - private static PSEUDO_TRANSLATE_TYPE pseudo_translate_type = PSEUDO_TRANSLATE_TYPE.EQUAL; - public static boolean isQuietMode() { return quietMode; } @@ -79,20 +53,4 @@ public static void setConfigDir(String v) { configDir = v; } - - public static void setPseudoTranslateTMXFile(String filename) { - pseudoTranslateTMXFile = filename; - } - - public static String getPseudoTranslateTMXFile() { - return pseudoTranslateTMXFile; - } - - public static void setPseudoTranslateType(String type) { - pseudo_translate_type = PSEUDO_TRANSLATE_TYPE.parse(type); - } - - public static PSEUDO_TRANSLATE_TYPE getPseudoTranslateType() { - return pseudo_translate_type; - } } Modified: trunk/src/org/omegat/util/TMXWriter.java =================================================================== --- trunk/src/org/omegat/util/TMXWriter.java 2009-10-19 06:03:36 UTC (rev 2433) +++ trunk/src/org/omegat/util/TMXWriter.java 2009-10-19 06:20:56 UTC (rev 2434) @@ -39,7 +39,6 @@ import org.omegat.core.data.ProjectProperties; import org.omegat.core.data.StringEntry; import org.omegat.core.data.TransMemory; -import org.omegat.util.RuntimePreferences.PSEUDO_TRANSLATE_TYPE; /** * Class that store TMX (Translation Memory Exchange) files. @@ -56,40 +55,18 @@ * @param m_orphanedList * List of translated segments that have no match in the current * sources - * @param pseudoTranslate - * When true, a tu-section is created for every segment in the - * sources, even when there is no translation available. - * @param pseudo_translate_type - * When pseudo-translate is true:<br> - * If 'equal' then the translation that is written is equal to - * the source.<br> - * If 'empty', the translation is an empty string.<br> - * When pseudoTranslate is false, this parameter is ignored. * @return map of strings for TMX */ public static Map<String, String> prepareTMXData( final List<StringEntry> m_strEntryList, - final List<TransMemory> m_orphanedList, - final boolean pseudoTranslate, - PSEUDO_TRANSLATE_TYPE pseudo_translate_type) { + final List<TransMemory> m_orphanedList) { Map<String, String> result = new HashMap<String, String>(); String source = null; String target = null; for (StringEntry se : m_strEntryList) { - source = se.getSrcText(); - if (!pseudoTranslate) { - target = se.getTranslation(); - if (target.length() == 0) - continue; - } else { - if (pseudo_translate_type.equals(PSEUDO_TRANSLATE_TYPE.EQUAL)) { - target = source; - } else { - // must be PSEUDO_TRANSLATE_TYPE.EMPTY - target = ""; - } + if (se.isTranslated()) { + result.put(se.getSrcText(), se.getTranslation()); } - result.put(source, target); } // Write orphan strings. Assume N/A when pseudo-translate. This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <al...@us...> - 2009-10-19 06:27:21
|
Revision: 2436 http://omegat.svn.sourceforge.net/omegat/?rev=2436&view=rev Author: alex73 Date: 2009-10-19 06:27:13 +0000 (Mon, 19 Oct 2009) Log Message: ----------- Project memory storage refactoring: TMX: use full entries list instead unique Modified Paths: -------------- trunk/src/org/omegat/core/data/RealProject.java trunk/src/org/omegat/util/TMXWriter.java Modified: trunk/src/org/omegat/core/data/RealProject.java =================================================================== --- trunk/src/org/omegat/core/data/RealProject.java 2009-10-19 06:24:40 UTC (rev 2435) +++ trunk/src/org/omegat/core/data/RealProject.java 2009-10-19 06:27:13 UTC (rev 2436) @@ -259,7 +259,7 @@ // - TMX Level 2, with OmegaT formatting tags wrapped in TMX inline tags try { - Map<String,String> tmx = TMXWriter.prepareTMXData(m_strEntryList, null); + Map<String,String> tmx = TMXWriter.prepareTMXData(m_srcTextEntryArray, null); // build TMX with OmegaT tags String fname = m_config.getProjectRoot() + m_config.getProjectName() + OConsts.OMEGAT_TMX @@ -387,7 +387,7 @@ { saveProjectProperties(); - Map<String,String> tmx = TMXWriter.prepareTMXData(m_strEntryList, m_orphanedList); + Map<String,String> tmx = TMXWriter.prepareTMXData(m_srcTextEntryArray, m_orphanedList); TMXWriter.buildTMXFile(s, false, false, m_config, tmx); m_modifiedFlag = false; } Modified: trunk/src/org/omegat/util/TMXWriter.java =================================================================== --- trunk/src/org/omegat/util/TMXWriter.java 2009-10-19 06:24:40 UTC (rev 2435) +++ trunk/src/org/omegat/util/TMXWriter.java 2009-10-19 06:27:13 UTC (rev 2436) @@ -37,7 +37,7 @@ import java.util.regex.Pattern; import org.omegat.core.data.ProjectProperties; -import org.omegat.core.data.StringEntry; +import org.omegat.core.data.SourceTextEntry; import org.omegat.core.data.TransMemory; /** @@ -58,14 +58,14 @@ * @return map of strings for TMX */ public static Map<String, String> prepareTMXData( - final List<StringEntry> m_strEntryList, + final List<SourceTextEntry> m_srcTextEntryArray, final List<TransMemory> m_orphanedList) { Map<String, String> result = new HashMap<String, String>(); String source = null; String target = null; - for (StringEntry se : m_strEntryList) { - if (se.isTranslated()) { - result.put(se.getSrcText(), se.getTranslation()); + for (SourceTextEntry ste : m_srcTextEntryArray) { + if (ste.isTranslated()) { + result.put(ste.getSrcText(), ste.getTranslation()); } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <did...@us...> - 2009-10-21 11:05:07
|
Revision: 2449 http://omegat.svn.sourceforge.net/omegat/?rev=2449&view=rev Author: didierbr Date: 2009-10-21 11:04:54 +0000 (Wed, 21 Oct 2009) Log Message: ----------- Typo3 LocManager File Filter Modified Paths: -------------- trunk/src/org/omegat/Bundle.properties trunk/src/org/omegat/Bundle_fr.properties trunk/src/org/omegat/filters2/master/FilterMaster.java trunk/src/org/omegat/filters3/xml/DefaultXMLDialect.java trunk/src/org/omegat/filters3/xml/Handler.java trunk/src/org/omegat/filters3/xml/XMLDialect.java Added Paths: ----------- trunk/src/org/omegat/filters3/xml/typo3/ trunk/src/org/omegat/filters3/xml/typo3/Typo3Dialect.java trunk/src/org/omegat/filters3/xml/typo3/Typo3Filter.java Modified: trunk/src/org/omegat/Bundle.properties =================================================================== --- trunk/src/org/omegat/Bundle.properties 2009-10-19 12:25:20 UTC (rev 2448) +++ trunk/src/org/omegat/Bundle.properties 2009-10-21 11:04:54 UTC (rev 2449) @@ -800,6 +800,9 @@ # RESXFilter.java RESX_FILTER_NAME=ResX Files +# Typo3Filter.java +TYPO3_FILTER_NAME=Typo3 LocManager Files + # org.omegat.filters3.xml.Handler XML_FATAL_ERROR=Error in file {0}, line {1} Modified: trunk/src/org/omegat/Bundle_fr.properties =================================================================== --- trunk/src/org/omegat/Bundle_fr.properties 2009-10-19 12:25:20 UTC (rev 2448) +++ trunk/src/org/omegat/Bundle_fr.properties 2009-10-21 11:04:54 UTC (rev 2449) @@ -748,6 +748,9 @@ # RESXFilter.java RESX_FILTER_NAME=Fichiers ResX +# Typo3Filter.java +TYPO3_FILTER_NAME=Fichiers LocManager Typo3 + # org.omegat.filters3.xml.Handler XML_FATAL_ERROR=Erreur dans le fichier {0} \u00e0 la ligne {1} Modified: trunk/src/org/omegat/filters2/master/FilterMaster.java =================================================================== --- trunk/src/org/omegat/filters2/master/FilterMaster.java 2009-10-19 12:25:20 UTC (rev 2448) +++ trunk/src/org/omegat/filters2/master/FilterMaster.java 2009-10-21 11:04:54 UTC (rev 2449) @@ -67,6 +67,7 @@ import org.omegat.filters3.xml.opendoc.OpenDocFilter; import org.omegat.filters3.xml.openxml.OpenXMLFilter; import org.omegat.filters3.xml.resx.ResXFilter; +import org.omegat.filters3.xml.typo3.Typo3Filter; import org.omegat.filters3.xml.xhtml.XHTMLFilter; import org.omegat.filters3.xml.xliff.XLIFFFilter; import org.omegat.util.LFileCopy; @@ -548,6 +549,7 @@ res.addFilter(new OneFilter(new SrtFilter(), false)); res.addFilter(new OneFilter(new XtagFilter(), false)); res.addFilter(new OneFilter(new ResXFilter(), false)); + res.addFilter(new OneFilter(new Typo3Filter(), false)); return res; } Modified: trunk/src/org/omegat/filters3/xml/DefaultXMLDialect.java =================================================================== --- trunk/src/org/omegat/filters3/xml/DefaultXMLDialect.java 2009-10-19 12:25:20 UTC (rev 2448) +++ trunk/src/org/omegat/filters3/xml/DefaultXMLDialect.java 2009-10-21 11:04:54 UTC (rev 2449) @@ -261,7 +261,7 @@ * translated, depending on the content of one attribute and the presence * or absence of other attributes. * For instance, in the ResX filter, - * tags should not be translated when then contain the attribute "type", or + * tags should not be translated when they contain the attribute "type", or * when the attribute "name" starts with "&gt"; * @param tag The tag that could be translated * @param atts The list of the tag attributes @@ -272,6 +272,24 @@ return false; } + /** + * For a given tag, return wether the content of this tag should be + * translated, depending on the content of one attribute and the presence + * or absence of other attributes. + * For instance, in the Typo3 filter, + * tags should be translated when the attribute locazible="1". + * Contrary to validateIntactTag, this applies only to the current tag, + * and the tags contained in it are not affected. + * @param tag The tag that could be translated + * @param atts The list of the tag attributes + * @return <code>true</code> or <code>false</code> + */ + public Boolean validateTranslatableTag(String tag, + Attributes atts){ + return true; + } + + /** * For a given tag, return wether the content of this tag is a * paragraph tag, depending on the content of one attribute @@ -359,4 +377,26 @@ { return shortcuts; } + + /** + * The parameter setting wether closing tags should be used + */ + private boolean closingTagRequired = false; + + /** + * Sets closingTag to <code>true</code> or <code>false</code> + * @param onOff The parameter setting wether closing tags should be used + * or not for empty tags. + */ + public void setClosingTagRequired(boolean onOff){ + closingTagRequired = onOff; + } + + /** + * Gives the value of closingTag + */ + public Boolean getClosingTagRequired(){ + return closingTagRequired; + } + } Modified: trunk/src/org/omegat/filters3/xml/Handler.java =================================================================== --- trunk/src/org/omegat/filters3/xml/Handler.java 2009-10-19 12:25:20 UTC (rev 2448) +++ trunk/src/org/omegat/filters3/xml/Handler.java 2009-10-21 11:04:54 UTC (rev 2449) @@ -116,6 +116,8 @@ Stack<String> paragraphTagName = new Stack<String>(); /** Names of possible preformat tags. */ Stack<String> preformatTagName = new Stack<String>(); + /** Name of the current variable translatable tag */ + Stack<String> translatableTagName = new Stack<String>(); /** Now we collect out-of-turn entry. */ private boolean collectingOutOfTurnText() @@ -129,6 +131,10 @@ return intacttagEntry!=null; } + private boolean isTranslatableTag(){ + return !translatableTagName.empty(); + } + /** * Returns current entry we collect text into. * If we collect normal text, returns {@link #entry}, @@ -414,6 +420,7 @@ { Tag xmltag; XMLIntactTag intacttag = null; + setTranslatableTag(tag, XMLUtils.convertAttributes(attributes)); if (!collectingIntactText() && isIntactTag(tag, XMLUtils.convertAttributes(attributes))) { @@ -432,32 +439,31 @@ if (!collectingIntactText()) { - for (int i=0; i<xmltag.getAttributes().size(); i++) - { - Attribute attr = xmltag.getAttributes().get(i); - if ((dialect.getTranslatableAttributes().contains(attr.getName()) - || - dialect.getTranslatableTagAttributes().containsPair(tag, attr.getName()) - ) - && dialect.validateTranslatableTagAttribute(tag, attr.getName(), xmltag.getAttributes() ) - ) + for (int i=0; i<xmltag.getAttributes().size(); i++) { - attr.setValue(translator.translate(attr.getValue())); + Attribute attr = xmltag.getAttributes().get(i); + if ((dialect.getTranslatableAttributes().contains(attr.getName()) + || + dialect.getTranslatableTagAttributes().containsPair(tag, attr.getName()) + ) + && dialect.validateTranslatableTagAttribute(tag, attr.getName(), xmltag.getAttributes() ) + ) + { + attr.setValue(translator.translate(attr.getValue())); + } } } } - } private void queueEndTag(String tag) { int len = currEntry().size(); if (len>0 && (currEntry().get(len-1) instanceof XMLTag) && - ((XMLTag)currEntry().get(len-1)).getTag().equals(tag) && - ((XMLTag)currEntry().get(len-1)).getType()==Tag.TYPE_BEGIN) - { + (((XMLTag)currEntry().get(len-1)).getTag().equals(tag) && + ((XMLTag)currEntry().get(len-1)).getType()==Tag.TYPE_BEGIN) && + !isClosingTagRequired()) { ((XMLTag)currEntry().get(len-1)).setType(Tag.TYPE_ALONE); } - else - { + else { currEntry().add(new XMLTag(tag, getShortcut(tag), Tag.TYPE_END, null)); } } @@ -514,6 +520,7 @@ && !collectingIntactText()) translateAndFlush(); } + removeTranslatableTag(); } /** @@ -528,17 +535,17 @@ String src = currEntry().sourceToShortcut(); Element lead = currEntry().get(0); - String translation; - if ((lead instanceof Tag) && + String translation = src; + if ( (lead instanceof Tag) && isPreformattingTag(((Tag)lead).getTag(), - ((Tag)lead).getAttributes())) - { + ((Tag)lead).getAttributes()) && + isTranslatableTag() + ) { translation = translator.translate(src); - } - else - { + } else { String compressed = StaticUtils.compressSpaces(src); - translation = translator.translate(compressed); + if (isTranslatableTag()) + translation = translator.translate(compressed); // untranslated is written out uncompressed if( compressed.equals(translation) ) translation = src; @@ -668,6 +675,39 @@ } } + /** + * If we are not inside a translatable tag, and if the dialect says + * the new one is translatable, add the new tag to the stack + * @param tag The current opening tag + * @param atts The attributes of the current tag + */ + // TODO: The concept works only perfectly if the first tag with + // translatable content inside the translatable tag is a paragraph + // tag + void setTranslatableTag(String tag, + org.omegat.filters3.Attributes atts) { + + if ( !isTranslatableTag() ) { // If stack is empty + if (dialect.validateTranslatableTag(tag, atts) ) + translatableTagName.push(tag); + } else { + translatableTagName.push(tag); + } + } + + /** + * Remove a tag from the stack of translatable tags + */ + void removeTranslatableTag() { + if ( isTranslatableTag() ) // If there is something in the stack + translatableTagName.pop(); // Remove it + } + + + private boolean isClosingTagRequired(){ + return dialect.getClosingTagRequired(); + } + /** Returns whether we face out of turn tag we should collect separately. */ private boolean isOutOfTurnTag(String tag) { Modified: trunk/src/org/omegat/filters3/xml/XMLDialect.java =================================================================== --- trunk/src/org/omegat/filters3/xml/XMLDialect.java 2009-10-19 12:25:20 UTC (rev 2448) +++ trunk/src/org/omegat/filters3/xml/XMLDialect.java 2009-10-21 11:04:54 UTC (rev 2449) @@ -99,7 +99,7 @@ * translated, depending on the content of one attribute and the presence * or absence of other attributes. * For instance, in the ResX filter, - * tags should not be translated when then contain the attribute "type", or + * tags should not be translated when they contain the attribute "type", or * when the attribute "name" starts with "&gt"; * @param tag The tag that could be translated * @param atts The list of the tag attributes @@ -107,6 +107,18 @@ */ Boolean validateIntactTag(String tag, Attributes atts); + /** + * For a given tag, return wether the content of this tag should be + * translated, depending on the content of one attribute and the presence + * or absence of other attributes. + * For instance, in the Typo3 filter, + * tags should be translated when the attribute locazible="1". + * @param tag The tag that could be translated + * @param atts The list of the tag attributes + * @return <code>true</code> or <code>false</code> + */ + Boolean validateTranslatableTag(String tag, + Attributes atts); /** * For a given tag, return wether the content of this tag is a @@ -187,4 +199,16 @@ * Should return <code>null</code> if it doesn't or cannot. */ InputSource resolveEntity(String publicId, String systemId); + + /** + * Sets closingTag to <code>true</code> or <code>false</code> + * @param onOff The parameter setting wether closing tags should be used + * or not for empty tags. + */ + void setClosingTagRequired(boolean onOff); + + /** + * Gives the value of closingTagRequired. + */ + Boolean getClosingTagRequired(); } Added: trunk/src/org/omegat/filters3/xml/typo3/Typo3Dialect.java =================================================================== --- trunk/src/org/omegat/filters3/xml/typo3/Typo3Dialect.java (rev 0) +++ trunk/src/org/omegat/filters3/xml/typo3/Typo3Dialect.java 2009-10-21 11:04:54 UTC (rev 2449) @@ -0,0 +1,83 @@ +/************************************************************************** + OmegaT - Computer Assisted Translation (CAT) tool + with fuzzy matching, translation memory, keyword search, + glossaries, and translation leveraging into updated projects. + + Copyright (C) 2000-2006 Keith Godfrey and Maxym Mykhalchuk + (C) 2009 Didier Briel + + Home page: http://www.omegat.org/ + Support center: http://groups.yahoo.com/group/OmegaT/ + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +**************************************************************************/ + +package org.omegat.filters3.xml.typo3; + +import org.omegat.filters3.xml.DefaultXMLDialect; +import org.omegat.filters3.Attributes; +import org.omegat.filters3.Attribute; + +/** + * This class specifies the ResX XML Dialect. + * + * @author Didier Briel + */ +public class Typo3Dialect extends DefaultXMLDialect +{ + public Typo3Dialect(){ + defineParagraphTags(new String[] { + "title", + "subtitle", + "p", + "br", + "header", + "li", + "td", + }); + + defineIntactTags(new String[] { + "l18n_diffsource", + }); + + // Typo3 requires empty tags to have a closing tag + // E.g., <title></title> instead of <title/> + setClosingTagRequired(true); + } + + + + /** + * In the Typo3 LocManager filter, content should be translated in the + * following condition: + * The attribute localizable should be = "1" + * @param tag An XML tag + * @param atts The attributes associated with the tag + * @return <code>true</code> if the content of this tag should be + * translated, <code>false</code> otherwise + */ + public Boolean validateTranslatableTag(String tag, + Attributes atts) { + if (atts != null) { + for (int i=0; i < atts.size(); i++) { + Attribute oneAttribute = atts.get(i); + if ( oneAttribute.getName().equalsIgnoreCase("localizable") && + oneAttribute.getValue().equalsIgnoreCase("1") ) + return true; + } + } + return false; + } +} Property changes on: trunk/src/org/omegat/filters3/xml/typo3/Typo3Dialect.java ___________________________________________________________________ Added: svn:mime-type + text/x-java Added: svn:keywords + Author Date Id Revision Added: svn:eol-style + native Added: trunk/src/org/omegat/filters3/xml/typo3/Typo3Filter.java =================================================================== --- trunk/src/org/omegat/filters3/xml/typo3/Typo3Filter.java (rev 0) +++ trunk/src/org/omegat/filters3/xml/typo3/Typo3Filter.java 2009-10-21 11:04:54 UTC (rev 2449) @@ -0,0 +1,93 @@ +/************************************************************************** + OmegaT - Computer Assisted Translation (CAT) tool + with fuzzy matching, translation memory, keyword search, + glossaries, and translation leveraging into updated projects. + + Copyright (C) 2000-2006 Keith Godfrey and Maxym Mykhalchuk + 2009 Didier Briel + Home page: http://www.omegat.org/ + Support center: http://groups.yahoo.com/group/OmegaT/ + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +**************************************************************************/ + +package org.omegat.filters3.xml.typo3; + +import org.omegat.filters2.Instance; +import org.omegat.filters3.xml.XMLFilter; +import org.omegat.util.OStrings; + +/** + * Filter for ResX files. + * + * @author Didier Briel + */ +public class Typo3Filter extends XMLFilter +{ + + /** + * Creates a new instance of ResXFilter + */ + public Typo3Filter() + { + super(new Typo3Dialect()); + } + + /** + * Human-readable name of the File Format this filter supports. + * + * @return File format name + */ + public String getFileFormatName() + { + return OStrings.getString("TYPO3_FILTER_NAME"); + } + + + /** + * The default list of filter instances that this filter class has. + * One filter class may have different filter instances, different + * by source file mask, encoding of the source file etc. + * <p> + * Note that the user may change the instances freely. + * + * @return Default filter instances + */ + public Instance[] getDefaultInstances() + { + return new Instance[] + { + new Instance("*.xml", null, null), + }; + } + + /** + * Either the encoding can be read, or it is UTF-8. + * @return <code>false</code> + */ + public boolean isSourceEncodingVariable() + { + return false; + } + + /** + * Yes, Typo3 LocManager may be written out in a variety of encodings. + * @return <code>true</code> + */ + public boolean isTargetEncodingVariable() + { + return true; + } +} Property changes on: trunk/src/org/omegat/filters3/xml/typo3/Typo3Filter.java ___________________________________________________________________ Added: svn:mime-type + text/x-java Added: svn:keywords + Author Date Id Revision Added: svn:eol-style + native This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <al...@us...> - 2009-10-23 06:24:15
|
Revision: 2464 http://omegat.svn.sourceforge.net/omegat/?rev=2464&view=rev Author: alex73 Date: 2009-10-23 06:24:05 +0000 (Fri, 23 Oct 2009) Log Message: ----------- Project memory storage refactoring: simplify NearString storage Modified Paths: -------------- trunk/src/org/omegat/core/matching/NearString.java trunk/src/org/omegat/gui/main/MainWindow.java trunk/src/org/omegat/gui/matches/FindMatchesThread.java trunk/src/org/omegat/gui/matches/MatchesTextArea.java Modified: trunk/src/org/omegat/core/matching/NearString.java =================================================================== --- trunk/src/org/omegat/core/matching/NearString.java 2009-10-23 06:15:12 UTC (rev 2463) +++ trunk/src/org/omegat/core/matching/NearString.java 2009-10-23 06:24:05 UTC (rev 2464) @@ -4,6 +4,7 @@ glossaries, and translation leveraging into updated projects. Copyright (C) 2000-2006 Keith Godfrey and Maxym Mykhalchuk + 2009 Alex Buloichik Home page: http://www.omegat.org/ Support center: http://groups.yahoo.com/group/OmegaT/ @@ -20,27 +21,22 @@ You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -**************************************************************************/ + **************************************************************************/ package org.omegat.core.matching; -import org.omegat.core.data.StringEntry; - /** * Class to hold a single fuzzy match. - * + * * @author Keith Godfrey */ -public class NearString -{ - public NearString(StringEntry strEntry, - int nearScore, - int nearScoreNoStem, - int adjustedScore, - byte[] nearData, - String projName) - { - str = strEntry; +public class NearString { + public NearString(final String source, final String translation, + final int nearScore, final int nearScoreNoStem, + final int adjustedScore, final byte[] nearData, + final String projName) { + this.source = source; + this.translation = translation; score = nearScore; scoreNoStem = nearScoreNoStem; this.adjustedScore = adjustedScore; @@ -48,10 +44,19 @@ if (projName != null) proj = projName; } - - public StringEntry str; - public int score, scoreNoStem; // similarity score for match without non-word tokens - public int adjustedScore; // adjusted similarity score for match including all tokens - public byte[] attr; // matching attributes of near strEntry - public String proj = ""; // NOI18N + + public String source; + public String translation; + + public int score; + + /** similarity score for match without non-word tokens */ + public int scoreNoStem; + + /** adjusted similarity score for match including all tokens */ + public int adjustedScore; + + /** matching attributes of near strEntry */ + public byte[] attr; + public String proj = ""; } Modified: trunk/src/org/omegat/gui/main/MainWindow.java =================================================================== --- trunk/src/org/omegat/gui/main/MainWindow.java 2009-10-23 06:15:12 UTC (rev 2463) +++ trunk/src/org/omegat/gui/main/MainWindow.java 2009-10-23 06:24:05 UTC (rev 2464) @@ -206,7 +206,7 @@ NearString near = Core.getMatcher().getActiveMatch(); if (near != null) { - Core.getEditor().insertText(near.str.getTranslation()); + Core.getEditor().insertText(near.translation); } } @@ -218,7 +218,7 @@ NearString near = Core.getMatcher().getActiveMatch(); if (near != null) { - Core.getEditor().replaceEditText(near.str.getTranslation()); + Core.getEditor().replaceEditText(near.translation); } } Modified: trunk/src/org/omegat/gui/matches/FindMatchesThread.java =================================================================== --- trunk/src/org/omegat/gui/matches/FindMatchesThread.java 2009-10-23 06:15:12 UTC (rev 2463) +++ trunk/src/org/omegat/gui/matches/FindMatchesThread.java 2009-10-23 06:24:05 UTC (rev 2464) @@ -137,7 +137,8 @@ // skip original==original entry comparison continue; } - processEntry(candEntry.getStrEntry(), null); + processEntry(candEntry.getSrcText(), candEntry.getTranslation(), + null); } // travel by translation memories @@ -151,14 +152,17 @@ if (StringUtil.isEmpty(candEntry.getTranslation())) { continue; } - processEntry(candEntry, mem.getName()); + processEntry(candEntry.getSrcText(), + candEntry.getTranslation(), mem.getName()); } } // fill similarity data only for result for (NearString near : result) { // fix for bug 1586397 - byte[] similarityData = FuzzyMatcher.buildSimilarityData(strTokensAll, Core.getTokenizer().tokenizeAllExactly(near.str.getSrcText())); + byte[] similarityData = FuzzyMatcher.buildSimilarityData( + strTokensAll, Core.getTokenizer().tokenizeAllExactly( + near.source)); near.attr = similarityData; } @@ -196,10 +200,10 @@ * @param candEntry * entry to compare */ - protected void processEntry(final StringEntry candEntry, + protected void processEntry(final String source, final String translation, final String tmxName) { - Token[] candTokens = Core.getTokenizer().tokenizeWords( - candEntry.getSrcText(), ITokenizer.StemmingMode.MATCHING); + Token[] candTokens = Core.getTokenizer().tokenizeWords(source, + ITokenizer.StemmingMode.MATCHING); if (candTokens.length == 0) { return; } @@ -210,16 +214,16 @@ return; Token[] candTokensNoStem = Core.getTokenizer().tokenizeWords( - candEntry.getSrcText(), ITokenizer.StemmingMode.NONE); + source, ITokenizer.StemmingMode.NONE); int similarityNoStem = FuzzyMatcher.calcSimilarity(distance, strTokensNoStem, candTokensNoStem); if (haveChanceToAdd(similarityStem, similarityNoStem)) { Token[] candTokensAll = Core.getTokenizer().tokenizeAllExactly( - candEntry.getSrcText()); + source); int simAdjusted = FuzzyMatcher.calcSimilarity(distance, strTokensAll, candTokensAll); - addNearString(candEntry, similarityStem, similarityNoStem, - simAdjusted, null, tmxName); + addNearString(source, translation, similarityStem, + similarityNoStem, simAdjusted, null, tmxName); } } @@ -249,7 +253,7 @@ * Add near string into result list. * Near strings sorted by "similarity,simAdjusted" */ - protected void addNearString(final StringEntry candEntry, + protected void addNearString(final String source, final String translation, final int similarity, final int similarityNoStem, final int simAdjusted, final byte[] similarityData, final String tmxName) { @@ -257,7 +261,7 @@ int pos = 0; for (int i = 0; i < result.size(); i++) { NearString st = result.get(i); - if (tmxName==null && st.proj.length()==0 && candEntry.getSrcText().equals(st.str.getSrcText())) { + if (tmxName==null && st.proj.length()==0 && source.equals(st.source)) { // the same source text already in list - don't need to add // only if they are from translations return; @@ -278,8 +282,8 @@ pos = i + 1; } - result.add(pos, new NearString(candEntry, similarity, similarityNoStem, - simAdjusted, similarityData, tmxName)); + result.add(pos, new NearString(source, translation, similarity, + similarityNoStem, simAdjusted, similarityData, tmxName)); if (result.size() > OConsts.MAX_NEAR_STRINGS) { result.remove(result.size() - 1); } Modified: trunk/src/org/omegat/gui/matches/MatchesTextArea.java =================================================================== --- trunk/src/org/omegat/gui/matches/MatchesTextArea.java 2009-10-23 06:15:12 UTC (rev 2463) +++ trunk/src/org/omegat/gui/matches/MatchesTextArea.java 2009-10-23 06:24:05 UTC (rev 2464) @@ -152,10 +152,9 @@ for (int i = 0; i < newMatches.size(); i++) { NearString match = newMatches.get(i); displayBuffer.append(MessageFormat.format( - "{0}) {1}\n{2}\n<{3}/{4}/{5}% {6} >", i + 1, match.str - .getSrcText(), match.str.getTranslation(), - match.score, match.scoreNoStem, match.adjustedScore, - match.proj)); + "{0}) {1}\n{2}\n<{3}/{4}/{5}% {6} >", i + 1, match.source, + match.translation, match.score, match.scoreNoStem, + match.adjustedScore, match.proj)); if (i < (newMatches.size() - 1)) displayBuffer.append("\n\n"); // NOI18N @@ -199,7 +198,7 @@ if (thebest.score >= percentage) { String translation = Preferences.getPreferenceDefault(Preferences.BEST_MATCH_EXPLANATORY_TEXT, OStrings .getString("WF_DEFAULT_PREFIX")) - + thebest.str.getTranslation(); + + thebest.translation; SourceTextEntry currentEntry = Core.getEditor().getCurrentEntry(); if (StringUtil.isEmpty(currentEntry.getTranslation())) { Core.getEditor().replaceEditText(translation); @@ -229,7 +228,7 @@ NearString match = matches.get(activeMatch); // List tokens = match.str.getSrcTokenList(); - Token[] tokens = Core.getTokenizer().tokenizeAllExactly(match.str.getSrcText()); // fix for bug 1586397 + Token[] tokens = Core.getTokenizer().tokenizeAllExactly(match.source); // fix for bug 1586397 byte[] attributes = match.attr; for (int i = 0; i < tokens.length; i++) { Token token = tokens[i]; @@ -335,7 +334,7 @@ int entryNum = 0; for (int i = 0; i < entries.size(); i++) { if (entries.get(i).getSrcText().equals( - ns.str.getSrcText())) { + ns.source)) { // found entry with the same source entryNum = i; break; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <al...@us...> - 2009-10-23 06:42:35
|
Revision: 2465 http://omegat.svn.sourceforge.net/omegat/?rev=2465&view=rev Author: alex73 Date: 2009-10-23 06:42:25 +0000 (Fri, 23 Oct 2009) Log Message: ----------- Plugins: add filters config converter Added Paths: ----------- trunk/src/org/omegat/convert/ trunk/src/org/omegat/convert/v20to21/ trunk/src/org/omegat/convert/v20to21/Convert20to21.java trunk/src/org/omegat/convert/v20to21/data/ trunk/src/org/omegat/convert/v20to21/data/Filters.java trunk/src/org/omegat/convert/v20to21/data/Instance.java trunk/src/org/omegat/convert/v20to21/data/OneFilter.java Added: trunk/src/org/omegat/convert/v20to21/Convert20to21.java =================================================================== --- trunk/src/org/omegat/convert/v20to21/Convert20to21.java (rev 0) +++ trunk/src/org/omegat/convert/v20to21/Convert20to21.java 2009-10-23 06:42:25 UTC (rev 2465) @@ -0,0 +1,33 @@ +/************************************************************************** + OmegaT - Computer Assisted Translation (CAT) tool + with fuzzy matching, translation memory, keyword search, + glossaries, and translation leveraging into updated projects. + + Copyright (C) 2009 Alex Buloichik + Home page: http://www.omegat.org/ + Support center: http://groups.yahoo.com/group/OmegaT/ + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + **************************************************************************/ +package org.omegat.convert.v20to21; + +/** + * Convert some configs from v2.0 to v2.1 + * + * @author Alex Buloichik (ale...@gm...) + */ +public class Convert20to21 { + +} Property changes on: trunk/src/org/omegat/convert/v20to21/Convert20to21.java ___________________________________________________________________ Added: svn:mime-type + text/x-java Added: svn:keywords + Author Date Id Revision Added: svn:eol-style + native Added: trunk/src/org/omegat/convert/v20to21/data/Filters.java =================================================================== --- trunk/src/org/omegat/convert/v20to21/data/Filters.java (rev 0) +++ trunk/src/org/omegat/convert/v20to21/data/Filters.java 2009-10-23 06:42:25 UTC (rev 2465) @@ -0,0 +1,54 @@ +/************************************************************************** + OmegaT - Computer Assisted Translation (CAT) tool + with fuzzy matching, translation memory, keyword search, + glossaries, and translation leveraging into updated projects. + + Copyright (C) 2000-2006 Keith Godfrey and Maxym Mykhalchuk + Home page: http://www.omegat.org/ + Support center: http://groups.yahoo.com/group/OmegaT/ + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + **************************************************************************/ + +package org.omegat.convert.v20to21.data; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + +/** + * Wrapper around all the file filter classes. Is a JavaBean, so that it's easy + * to write/read it to/from XML file and provides a table model. + * + * @author Maxym Mykhalchuk + */ +public class Filters { + /** Holds the list of available filters. */ + private List<OneFilter> filters = new ArrayList<OneFilter>(); + + /** + * Returns all the filters as an array. + */ + public OneFilter[] getFilter() { + return filters.toArray(new OneFilter[0]); + } + + /** + * Sets all filters from the array. + */ + public void setFilter(OneFilter[] filter) { + filters = new ArrayList<OneFilter>(Arrays.asList(filter)); + } +} Property changes on: trunk/src/org/omegat/convert/v20to21/data/Filters.java ___________________________________________________________________ Added: svn:mime-type + text/x-java Added: svn:keywords + Author Date Id Revision Added: svn:eol-style + native Added: trunk/src/org/omegat/convert/v20to21/data/Instance.java =================================================================== --- trunk/src/org/omegat/convert/v20to21/data/Instance.java (rev 0) +++ trunk/src/org/omegat/convert/v20to21/data/Instance.java 2009-10-23 06:42:25 UTC (rev 2465) @@ -0,0 +1,131 @@ +/************************************************************************** + OmegaT - Computer Assisted Translation (CAT) tool + with fuzzy matching, translation memory, keyword search, + glossaries, and translation leveraging into updated projects. + + Copyright (C) 2000-2006 Keith Godfrey and Maxym Mykhalchuk + Home page: http://www.omegat.org/ + Support center: http://groups.yahoo.com/group/OmegaT/ + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + **************************************************************************/ + +package org.omegat.convert.v20to21.data; + +import org.omegat.util.OStrings; + +/** + * + * @author Maxym Mykhalchuk + */ +public class Instance { + + /** + * This value represents to the user that the encoding is determined by the + * filter itself. "In code" the <code>null</code> is used to represent + * automatic encoding selection. + */ + public static String ENCODING_AUTO_HUMAN = OStrings + .getString("ENCODING_AUTO"); + + /** The original filename (with extension). */ + public static final String TFP_FILENAME = "${filename}"; // NOI18N + + /** + * The default output filename pattern. + * <p> + * It is equal to "${filename}", which means that the name of the translated + * file should be the same as the name of the input file. + */ + public static String TARGET_DEFAULT = TFP_FILENAME; + + private String sourceFilenameMask; + + public String getSourceFilenameMask() { + return sourceFilenameMask; + } + + public void setSourceFilenameMask(String sourceFilenameMask) { + this.sourceFilenameMask = sourceFilenameMask; + } + + private String sourceEncoding; + + public String getSourceEncodingHuman() { + if (sourceEncoding == null) + return ENCODING_AUTO_HUMAN; + else + return sourceEncoding; + } + + public String getSourceEncoding() { + return sourceEncoding; + } + + public void setSourceEncoding(String sourceEncoding) { + if (sourceEncoding == null + || sourceEncoding.equals(ENCODING_AUTO_HUMAN)) + this.sourceEncoding = null; + else + this.sourceEncoding = sourceEncoding; + } + + private String targetEncoding; + + public String getTargetEncodingHuman() { + if (targetEncoding == null) + return ENCODING_AUTO_HUMAN; + else + return targetEncoding; + } + + public String getTargetEncoding() { + return targetEncoding; + } + + public void setTargetEncoding(String targetEncoding) { + if (targetEncoding == null + || targetEncoding.equals(ENCODING_AUTO_HUMAN)) + this.targetEncoding = null; + else + this.targetEncoding = targetEncoding; + } + + private String targetFilenamePattern; + + public String getTargetFilenamePattern() { + return targetFilenamePattern; + } + + public void setTargetFilenamePattern(String targetFilenamePattern) { + this.targetFilenamePattern = targetFilenamePattern; + } + + private void init(String sourceFilenameMask, String sourceEncoding, + String targetEncoding, String targetFilenamePattern) { + setSourceFilenameMask(sourceFilenameMask); + setSourceEncoding(sourceEncoding); + setTargetEncoding(targetEncoding); + setTargetFilenamePattern(targetFilenamePattern); + } + + /** + * Creates a new Filter Instance, uninitialized. Is here to support + * JavaBeans specification, <b>don't use</b> it in filters. + */ + public Instance() { + init("*.*", null, null, TARGET_DEFAULT); + } +} Property changes on: trunk/src/org/omegat/convert/v20to21/data/Instance.java ___________________________________________________________________ Added: svn:mime-type + text/x-java Added: svn:keywords + Author Date Id Revision Added: svn:eol-style + native Added: trunk/src/org/omegat/convert/v20to21/data/OneFilter.java =================================================================== --- trunk/src/org/omegat/convert/v20to21/data/OneFilter.java (rev 0) +++ trunk/src/org/omegat/convert/v20to21/data/OneFilter.java 2009-10-23 06:42:25 UTC (rev 2465) @@ -0,0 +1,72 @@ +/************************************************************************** + OmegaT - Computer Assisted Translation (CAT) tool + with fuzzy matching, translation memory, keyword search, + glossaries, and translation leveraging into updated projects. + + Copyright (C) 2000-2006 Keith Godfrey and Maxym Mykhalchuk + Home page: http://www.omegat.org/ + Support center: http://groups.yahoo.com/group/OmegaT/ + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + **************************************************************************/ + +package org.omegat.convert.v20to21.data; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + + +/** + * Wrapper around a single file filter class Manages entries in XML config file + * and provides a table model. + * + * @author Maxym Mykhalchuk + */ +public class OneFilter { + /** Holds the class name of the filter */ + private String className = null; + + /** + * Returns the class name of the filter. + */ + public String getClassName() { + return className; + } + + /** + * Sets the class name of the filter. + */ + public void setClassName(String value) { + className = value; + } + + /** Holds instances property. */ + private List<Instance> instances = new ArrayList<Instance>(); + + /** + * Returns all the instances of the filter. + */ + public Instance[] getInstance() { + return instances.toArray(new Instance[0]); + } + + /** + * Sets all the instances of the filter at once. + */ + public void setInstance(Instance[] instance) { + instances = new ArrayList<Instance>(Arrays.asList(instance)); + } +} Property changes on: trunk/src/org/omegat/convert/v20to21/data/OneFilter.java ___________________________________________________________________ Added: svn:mime-type + text/x-java Added: svn:keywords + Author Date Id Revision Added: svn:eol-style + native This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <al...@us...> - 2009-10-27 06:47:50
|
Revision: 2468 http://omegat.svn.sourceforge.net/omegat/?rev=2468&view=rev Author: alex73 Date: 2009-10-27 06:47:42 +0000 (Tue, 27 Oct 2009) Log Message: ----------- Plugins: load on startup Modified Paths: -------------- trunk/src/org/omegat/core/Core.java trunk/src/org/omegat/filters2/master/PluginUtils.java Modified: trunk/src/org/omegat/core/Core.java =================================================================== --- trunk/src/org/omegat/core/Core.java 2009-10-27 06:35:34 UTC (rev 2467) +++ trunk/src/org/omegat/core/Core.java 2009-10-27 06:47:42 UTC (rev 2468) @@ -35,6 +35,7 @@ import org.omegat.core.spellchecker.SpellChecker; import org.omegat.core.threads.IAutoSave; import org.omegat.core.threads.SaveThread; +import org.omegat.filters2.master.PluginUtils; import org.omegat.gui.dictionaries.DictionariesTextArea; import org.omegat.gui.editor.EditorController; import org.omegat.gui.editor.IEditor; @@ -147,6 +148,8 @@ tokenizer = createComponent(ITokenizer.class, new Tokenizer(), params); spellChecker = new SpellChecker(); + PluginUtils.loadPlugins2(); + SaveThread th = new SaveThread(); saveThread = th; th.start(); Modified: trunk/src/org/omegat/filters2/master/PluginUtils.java =================================================================== --- trunk/src/org/omegat/filters2/master/PluginUtils.java 2009-10-27 06:35:34 UTC (rev 2467) +++ trunk/src/org/omegat/filters2/master/PluginUtils.java 2009-10-27 06:47:42 UTC (rev 2468) @@ -274,7 +274,6 @@ .getResources("META-INF/MANIFEST.MF"); mlist .hasMoreElements();) { URL mu = mlist.nextElement(); - System.out.println(mu); InputStream in = mu.openStream(); Manifest m; try { @@ -288,10 +287,9 @@ foundMain = true; } loadByManifest(m, cls); - System.out.println(); } if (!foundMain) { - // development mode - load main menifest template + // development mode - load main manifest template File mf = new File("manifest-template.mf"); if (mf.exists()) { InputStream in = new FileInputStream(mf); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <al...@us...> - 2009-10-29 08:05:33
|
Revision: 2473 http://omegat.svn.sourceforge.net/omegat/?rev=2473&view=rev Author: alex73 Date: 2009-10-29 08:05:27 +0000 (Thu, 29 Oct 2009) Log Message: ----------- Plugins: find in subdirectories Modified Paths: -------------- trunk/src/org/omegat/filters2/master/PluginUtils.java trunk/src/org/omegat/util/FileUtil.java Modified: trunk/src/org/omegat/filters2/master/PluginUtils.java =================================================================== --- trunk/src/org/omegat/filters2/master/PluginUtils.java 2009-10-28 20:40:24 UTC (rev 2472) +++ trunk/src/org/omegat/filters2/master/PluginUtils.java 2009-10-29 08:05:27 UTC (rev 2473) @@ -44,6 +44,7 @@ import org.omegat.filters2.AbstractFilter; import org.omegat.filters2.TranslationException; +import org.omegat.util.FileUtil; import org.omegat.util.Log; /** @@ -256,16 +257,15 @@ File pluginsDir = new File("plugins/"); try { URLClassLoader cls; - URL[] urls; // list all jars in /plugins/ - File[] fs = pluginsDir.listFiles(new JARorFolderFileFilter()); - if (fs != null) { - urls = new URL[fs.length]; - for (int i = 0; i < urls.length; i++) { - urls[i] = fs[i].toURL(); + List<File> fs = FileUtil.findFiles(pluginsDir, new FileFilter() { + public boolean accept(File pathname) { + return pathname.getName().endsWith(".jar"); } - } else { - urls = new URL[0]; + }); + URL[] urls = new URL[fs.size()]; + for (int i = 0; i < urls.length; i++) { + urls[i] = fs.get(i).toURL(); } boolean foundMain = false; // look on all manifests Modified: trunk/src/org/omegat/util/FileUtil.java =================================================================== --- trunk/src/org/omegat/util/FileUtil.java 2009-10-28 20:40:24 UTC (rev 2472) +++ trunk/src/org/omegat/util/FileUtil.java 2009-10-29 08:05:27 UTC (rev 2473) @@ -31,8 +31,10 @@ import java.io.FileOutputStream; import java.io.IOException; import java.io.OutputStreamWriter; +import java.util.ArrayList; import java.util.Arrays; import java.util.Comparator; +import java.util.List; /** * Files processing utilities. @@ -112,4 +114,44 @@ } + /** + * Find files in subdirectories. + * + * @param dir + * directory to start find + * @param filter + * filter for found files + * @return list of filtered found files + */ + public static List<File> findFiles(final File dir, final FileFilter filter) { + final List<File> result = new ArrayList<File>(); + findFiles(dir, filter, result); + return result; + } + + /** + * Internal find method, which calls himself recursively. + * + * @param dir + * directory to start find + * @param filter + * filter for found files + * @param result + * list of filtered found files + */ + private static void findFiles(final File dir, final FileFilter filter, + final List<File> result) { + File[] list = dir.listFiles(); + if (list != null) { + for (File f : list) { + if (f.isDirectory()) { + findFiles(f, filter, result); + } else { + if (filter.accept(f)) { + result.add(f); + } + } + } + } + } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <al...@us...> - 2009-11-06 08:12:28
|
Revision: 2492 http://omegat.svn.sourceforge.net/omegat/?rev=2492&view=rev Author: alex73 Date: 2009-11-06 08:12:17 +0000 (Fri, 06 Nov 2009) Log Message: ----------- Plugins: move to new config Modified Paths: -------------- trunk/src/org/omegat/convert/ConvertConfigs.java trunk/src/org/omegat/filters2/AbstractFilter.java trunk/src/org/omegat/filters2/html2/HTMLFilter2.java trunk/src/org/omegat/filters2/master/FilterMaster.java trunk/src/org/omegat/filters2/master/PluginUtils.java trunk/src/org/omegat/filters2/text/TextFilter.java trunk/src/org/omegat/filters3/xml/opendoc/OpenDocFilter.java trunk/src/org/omegat/filters3/xml/openxml/OpenXMLFilter.java trunk/src/org/omegat/filters3/xml/xhtml/XHTMLFilter.java trunk/src/org/omegat/gui/filters2/FilterEditor.java trunk/src/org/omegat/gui/filters2/FiltersCustomizer.java trunk/src/org/omegat/gui/main/MainWindowMenuHandler.java Added Paths: ----------- trunk/src/org/omegat/filters2/master/FiltersTableModel.java trunk/src/org/omegat/filters2/master/OneFilterTableModel.java Removed Paths: ------------- trunk/src/org/omegat/filters2/master/Filters.java trunk/src/org/omegat/filters2/master/OneFilter.java Modified: trunk/src/org/omegat/convert/ConvertConfigs.java =================================================================== --- trunk/src/org/omegat/convert/ConvertConfigs.java 2009-11-04 07:21:38 UTC (rev 2491) +++ trunk/src/org/omegat/convert/ConvertConfigs.java 2009-11-06 08:12:17 UTC (rev 2492) @@ -37,10 +37,10 @@ */ public class ConvertConfigs { public static void convert() { - File oldFilters = new File(StaticUtils.getConfigDir() + "filters.conf"); - if (oldFilters.exists()) { - File newFilters = new File(StaticUtils.getConfigDir() - + "filters.xml"); + File newFilters = new File(StaticUtils.getConfigDir() + "filters.xml"); + if (!newFilters.exists()) { + File oldFilters = new File(StaticUtils.getConfigDir() + + "filters.conf"); try { Convert20to21.convertFiltersConfig(oldFilters, newFilters); } catch (Exception ex) { Modified: trunk/src/org/omegat/filters2/AbstractFilter.java =================================================================== --- trunk/src/org/omegat/filters2/AbstractFilter.java 2009-11-04 07:21:38 UTC (rev 2491) +++ trunk/src/org/omegat/filters2/AbstractFilter.java 2009-11-06 08:12:17 UTC (rev 2492) @@ -223,6 +223,10 @@ return false; } + public Class getOptionsClass() { + return null; + } + /** Holds filter's options. */ private Serializable options = null; Modified: trunk/src/org/omegat/filters2/html2/HTMLFilter2.java =================================================================== --- trunk/src/org/omegat/filters2/html2/HTMLFilter2.java 2009-11-04 07:21:38 UTC (rev 2491) +++ trunk/src/org/omegat/filters2/html2/HTMLFilter2.java 2009-11-06 08:12:17 UTC (rev 2492) @@ -251,6 +251,10 @@ { return true; } + + public Class getOptionsClass() { + return HTMLOptions.class; + } /** * (X)HTML Filter shows a <b>modal</b> dialog to edit its own options. Modified: trunk/src/org/omegat/filters2/master/FilterMaster.java =================================================================== --- trunk/src/org/omegat/filters2/master/FilterMaster.java 2009-11-04 07:21:38 UTC (rev 2491) +++ trunk/src/org/omegat/filters2/master/FilterMaster.java 2009-11-06 08:12:17 UTC (rev 2492) @@ -8,7 +8,7 @@ 2006 Martin Wunderlich 2006-2007 Didier Briel 2008 Martin Fleurke, Didier Briel - 2009 Didier Briel, Arno Peters + 2009 Didier Briel, Arno Peters, Alex Buloichik Home page: http://www.omegat.org/ Support center: http://groups.yahoo.com/group/OmegaT/ @@ -30,51 +30,37 @@ package org.omegat.filters2.master; -import java.beans.ExceptionListener; -import java.beans.XMLDecoder; -import java.beans.XMLEncoder; +import gen.core.filters.Files; +import gen.core.filters.Filter; +import gen.core.filters.Filters; +import gen.core.filters.Filter.Option; + +import java.beans.BeanInfo; +import java.beans.Introspector; +import java.beans.PropertyDescriptor; import java.io.File; -import java.io.FileInputStream; -import java.io.FileNotFoundException; -import java.io.FileOutputStream; import java.io.IOException; -import java.lang.reflect.Constructor; -import java.net.URL; +import java.io.Serializable; +import java.lang.reflect.Method; import java.nio.charset.Charset; import java.util.ArrayList; -import java.util.HashSet; import java.util.List; import java.util.Set; import javax.swing.JOptionPane; +import javax.xml.bind.JAXBContext; +import javax.xml.bind.Marshaller; +import javax.xml.bind.Unmarshaller; import org.omegat.core.Core; import org.omegat.filters2.AbstractFilter; import org.omegat.filters2.IParseCallback; import org.omegat.filters2.Instance; import org.omegat.filters2.TranslationException; -import org.omegat.filters2.xtagqxp.XtagFilter; -import org.omegat.filters2.hhc.HHCFilter2; -import org.omegat.filters2.html2.HTMLFilter2; -import org.omegat.filters2.latex.LatexFilter; -import org.omegat.filters2.po.PoFilter; -import org.omegat.filters2.subtitles.SrtFilter; -import org.omegat.filters2.text.TextFilter; -import org.omegat.filters2.text.bundles.ResourceBundleFilter; -import org.omegat.filters2.text.ini.INIFilter; -import org.omegat.filters3.xml.android.AndroidFilter; -import org.omegat.filters3.xml.docbook.DocBookFilter; -import org.omegat.filters3.xml.opendoc.OpenDocFilter; -import org.omegat.filters3.xml.openxml.OpenXMLFilter; -import org.omegat.filters3.xml.resx.ResXFilter; -import org.omegat.filters3.xml.typo3.Typo3Filter; -import org.omegat.filters3.xml.xhtml.XHTMLFilter; -import org.omegat.filters3.xml.xliff.XLIFFFilter; import org.omegat.util.LFileCopy; import org.omegat.util.Language; import org.omegat.util.Log; import org.omegat.util.OStrings; -import org.omegat.util.Preferences; import org.omegat.util.StaticUtils; /** @@ -87,11 +73,13 @@ * @author Didier Briel * @author Martin Fleurke * @author Arno Peters + * @author Alex Buloichik (ale...@gm...) */ -public class FilterMaster -{ - /** name of the filter configuration file */ - private final static String FILE_FILTERS = "filters.conf"; // NOI18N +public class FilterMaster { + /** name of the filter configuration file */ + private final static String FILE_FILTERS = "filters.xml"; + + private static final JAXBContext CONFIG_CTX; /** There was no version of file filters support (1.4.5 Beta 1 -- 1.6.0 RC12). */ public static String INITIAL_VERSION = new String(); @@ -103,40 +91,189 @@ /** Currently file filters support version. */ public static String CURRENT_VERSION = "2.0"; - /** Wrapper around filters storage in an XML file */ - private Filters filters; - /** Returns Wrapper around filters storage in an XML file */ - public Filters getFilters() - { - return filters; - } + /** FilterMaster instance. */ + private static FilterMaster master = null; + + /** Config file. */ + private File configFile = new File(StaticUtils.getConfigDir() + + FILE_FILTERS); + + /** Filters config stored in XML file. */ + private Filters config; + + /** Instances of all filter classes. */ + private List<AbstractFilter> filtersInstances; + static { + try { + CONFIG_CTX = JAXBContext.newInstance(Filters.class); + } catch (Exception ex) { + throw new ExceptionInInitializerError(ex); + } + } + /** * Create a new FilterMaster. */ - private FilterMaster() - { - PluginUtils.loadPlugins(); - if( configFile.exists() ) - loadConfig(); - else - filters = setupBuiltinFilters(); - loadFilterClassesFromPlugins(); + private FilterMaster() { + filtersInstances = new ArrayList<AbstractFilter>(); + for (Class c : PluginUtils.getFilterClasses()) { + try { + filtersInstances.add((AbstractFilter) c.newInstance()); + } catch (Exception ex) { + // error instantiate filter + Log.log(ex); + } + } + + loadConfig(); + + addNewFiltersToConfig(config); + + applyOptions(); + saveConfig(); } - private static FilterMaster master = null; /** + * Adds new filters(which was not exist in config yet) into config. + */ + private void addNewFiltersToConfig(final Filters conf) { + for (AbstractFilter f : filtersInstances) { + boolean found = false; + for (Filter fc : conf.getFilter()) { + if (f.getClass().getName().equals(fc.getClassName())) { + // filter already exist in config + found = true; + break; + } + } + if (!found) { + // filter not found in config + conf.getFilter().add( + getDefaultSettingsFromFilter(f.getClass().getName())); + } + } + } + + /** + * TODO: change filters to support text options + */ + public void applyOptions() { + for (AbstractFilter f : filtersInstances) { + if (!f.hasOptions()) { + // filter doesn't support options + continue; + } + for (Filter fc : config.getFilter()) { + if (!f.getClass().getName().equals(fc.getClassName())) { + continue; + } + f.setOptions(parseOptions(f.getOptionsClass(), fc.getOption())); + } + } + } + + /** + * TODO: change filters to support text options + */ + public static Serializable parseOptions(Class optClass, List<Option> configOpts) { + if (optClass == null) { + return null; + } + Serializable opts; + try { + opts = (Serializable) optClass.newInstance(); + } catch (Exception ex) { + Log.log(ex); + return null; + } + // found filter's config + try { + BeanInfo bi = Introspector.getBeanInfo(opts.getClass()); + for (PropertyDescriptor prop : bi.getPropertyDescriptors()) { + if ("class".equals(prop.getName())) { + continue; + } + // find option value in config + String val = null; + for (Option opt : configOpts) { + if (prop.getName().equals(opt.getName())) { + val = opt.getValue(); + break; + } + } + if (val == null) { + continue; + } + Method wr = prop.getWriteMethod(); + Class pt = wr.getParameterTypes()[0]; + if (pt == int.class) { + wr.invoke(opts, Integer.parseInt(val)); + } else if (pt == boolean.class) { + wr.invoke(opts, Boolean.parseBoolean(val)); + } else if (pt == String.class) { + wr.invoke(opts, val); + } else { + Log.log("Unknown param type:" + pt); + } + } + return opts; + } catch (Exception ex) { + Log.log(ex); + return null; + } + } + + /** + * TODO: change filters to support text options + */ + public static List<Option> parseToOptions(Object opts) { + List<Option> result = new ArrayList<Option>(); + try { + BeanInfo bi = Introspector.getBeanInfo(opts.getClass()); + for (PropertyDescriptor prop : bi.getPropertyDescriptors()) { + if ("class".equals(prop.getName())) { + continue; + } + Object value = prop.getReadMethod().invoke(opts); + Filter.Option op = new Filter.Option(); + op.setName(prop.getName()); + op.setValue(value.toString()); + result.add(op); + } + } catch (Exception ex) { + Log.log(ex); + } + return result; + } + + /** * Returns the only instance of this class. */ - public static FilterMaster getInstance() - { - if( master==null ) + public static FilterMaster getInstance() { + if (master == null) master = new FilterMaster(); return master; } /** + * Get filter's instance by filter class name. + * + * @param classname + * filter's class name + * @return filter instance + */ + public AbstractFilter getFilterInstance(final String classname) { + for (AbstractFilter f : filtersInstances) { + if (f.getClass().getName().equals(classname)) { + return f; + } + } + return null; + } + + /** * OmegaT core calls this method to load a source file. * * @param filename The name of the source file to load. @@ -154,7 +291,7 @@ return false; File inFile = new File(filename); - String inEncoding = lookup.inEncoding; + String inEncoding = lookup.outFilesInfo.getSourceEncoding(); AbstractFilter filterObject = lookup.filterObject; filterObject.setParseCallback(parseCallback); @@ -202,21 +339,20 @@ } File inFile = new File(sourcedir+File.separator+filename); - String inEncoding = lookup.inEncoding; + String inEncoding = lookup.outFilesInfo.getSourceEncoding(); String name = inFile.getName(); String path = filename.substring(0, filename.length()-name.length()); - Instance instance = lookup.instance; File outFile = new File( targetdir + File.separator + path + File.separator + constructTargetFilename( - instance.getSourceFilenameMask(), + lookup.outFilesInfo.getSourceFilenameMask(), name, - instance.getTargetFilenamePattern())); - String outEncoding = instance.getTargetEncoding(); + lookup.outFilesInfo.getTargetFilenamePattern())); + String outEncoding = lookup.outFilesInfo.getTargetEncoding(); AbstractFilter filterObject = lookup.filterObject; @@ -229,18 +365,13 @@ class LookupInformation { - public OneFilter filter; - public Instance instance; + public Files outFilesInfo; public AbstractFilter filterObject; - public String inEncoding; - public LookupInformation(OneFilter filter, Instance instance, - AbstractFilter filterObject, String inEncoding) + public LookupInformation(AbstractFilter filterObject, Files outFilesInfo) { - this.filter = filter; - this.instance = instance; this.filterObject = filterObject; - this.inEncoding = inEncoding; + this.outFilesInfo = outFilesInfo; } } @@ -264,41 +395,34 @@ * @return The filter to handle the inFile. */ private LookupInformation lookupFilter(String filename) - throws TranslationException, IOException - { + throws TranslationException, IOException { File inFile = new File(filename); String name = inFile.getName(); String path = inFile.getParent(); - if( path==null ) - path = ""; // NOI18N - - for(int i=0; i<getFilters().getFilter().length; i++) - { - OneFilter filter = getFilters().getFilter(i); - if( !filter.isOn() ) + if (path == null) + path = ""; + + for (Filter f : config.getFilter()) { + if (!f.isEnabled()) { continue; - for(int j=0; j<filter.getInstance().length; j++) - { - Instance instance = filter.getInstance(j); - if( matchesMask(name, instance.getSourceFilenameMask()) ) - { + } + for (Files ff : f.getFiles()) { + if (matchesMask(name, ff.getSourceFilenameMask())) { AbstractFilter filterObject; - filterObject = PluginUtils.instantiateFilter(filter); - - String inEncoding = instance.getSourceEncoding(); - if( !filterObject.isFileSupported(inFile, inEncoding) ) - { + filterObject = getFilterInstance(f.getClassName()); + + if (!filterObject.isFileSupported(inFile, ff + .getSourceEncoding())) { break; } - - return new LookupInformation(filter, instance, filterObject, inEncoding); + + return new LookupInformation(filterObject, ff); } } } return null; } - private static List<String> supportedEncodings = null; /** * Queries JRE for the list of supported encodings. @@ -332,289 +456,46 @@ * <li>Saves the configuration * </ul> */ - public void revertFiltersConfigToDefaults() - { - filters = setupBuiltinFilters(); - PluginUtils.loadPlugins(); - loadFilterClassesFromPlugins(); - saveConfig(); + public Filters createDefaultFiltersConfig() { + Filters c = new Filters(); + addNewFiltersToConfig(c); + return c; } - - /** XML file with filters configuration */ - private File configFile = new File(StaticUtils.getConfigDir() + FILE_FILTERS); - + /** - * My Own Class to listen to exceptions, - * occured while loading filters configuration. + * Loads information about the filters from an XML file. If there's an error + * loading a file, it calls <code>setupDefaultFilters</code>. */ - class MyExceptionListener implements ExceptionListener - { - private List<Exception> exceptionsList = new ArrayList<Exception>(); - private boolean exceptionOccured = false; - public void exceptionThrown(Exception e) - { - exceptionOccured = true; - exceptionsList.add(e); + public void loadConfig() { + if (!configFile.exists()) { + config = new Filters(); + return; } - - /** - * Returns whether any exceptions occured. - */ - public boolean isExceptionOccured() - { - return exceptionOccured; - } - /** - * Returns the list of occured exceptions. - */ - public List<Exception> getExceptionsList() - { - return exceptionsList; - } - } - - /** - * Loads information about the filters from an XML file. - * If there's an error loading a file, it calls <code>setupDefaultFilters</code>. - */ - public void loadConfig() - { - try - { - MyExceptionListener myel = new MyExceptionListener(); - XMLDecoder xmldec = new XMLDecoder(new FileInputStream(configFile), this, myel); - filters = (Filters)xmldec.readObject(); - xmldec.close(); - - if( myel.isExceptionOccured() ) - { - StringBuffer sb = new StringBuffer(); - for(Exception ex : myel.getExceptionsList()) - { - sb.append(" "); // NOI18N - sb.append(ex); - sb.append("\n"); // NOI18N - } - throw new Exception("Exceptions occured while loading file filters:\n"+sb.toString()); // NOI18N - } - - checkIfAllFilterPluginsAreAvailable(); - - // checking the version - if (CURRENT_VERSION.compareTo(Preferences.getPreference(Preferences.FILTERS_VERSION))>0) - { - // yep, the config file with filters settings is of the older version - - // initing defaults - Filters defaults = setupBuiltinFilters(); - // and merging them into loaded settings - filters = upgradeFilters(filters, defaults); - } - } - catch( Exception e ) - { + try { + Unmarshaller unm = CONFIG_CTX.createUnmarshaller(); + config = (Filters) unm.unmarshal(configFile); + } catch (Exception e) { Log.logErrorRB("FILTERMASTER_ERROR_LOADING_FILTERS_CONFIG"); Log.log(e); - filters = setupBuiltinFilters(); + config = new Filters(); } } - - /** Upgrades current filters settings using current defaults. */ - private Filters upgradeFilters(Filters filters, Filters defaults) - { - // upgrade if filters version is from before 1.6 RC12a/1.6.0/1.6.1 - String filtersVersion = Preferences.getPreference(Preferences.FILTERS_VERSION); - if ( !filtersVersion.equals(OT160FINAL_VERSION) // FIX: this is getting messier with each version... - && !filtersVersion.equals(OT161_VERSION) - && (filtersVersion.compareTo(OT160RC12a_VERSION) < 0)) - { - // removing old OO filter but moving all its instances to new OpenDoc one - for (int i = 0; i < filters.getFilter().length; i++) - { - OneFilter oo = filters.getFilter(i); - if (oo.getClassName().equals("org.omegat.filters2.xml.openoffice.OOFilter")) // NOI18N - { - OneFilter opendoc = new OneFilter(new OpenDocFilter(), false); - for (int j = 0; j < oo.getInstance().length; j++) - { - Instance ooi = oo.getInstance(j); - for (int k = 0; k < opendoc.getInstance().length; k++) - { - Instance odi = opendoc.getInstance(k); - if (odi.getSourceFilenameMask().equals(ooi.getSourceFilenameMask())) - { - opendoc.setInstance(k, ooi); - break; - } - } - } - filters.setFilter(i, opendoc); - break; - } - } - } - - // now adding those filters from defaults which appeared in new version only - Set<String> existing = new HashSet<String>(); - for (int i = 0; i < filters.getFilter().length; i++) - existing.add(filters.getFilter(i).getClassName()); - for (int i = 0; i < defaults.getFilter().length; i++) - { - OneFilter deffilter = defaults.getFilter(i); - if (!existing.contains(deffilter.getClassName())) - filters.addFilter(deffilter); - } - - return filters; - } - /** - * Goes through the list of loaded plugins to see if - * all the filters that are there in config file are present. - */ - private void checkIfAllFilterPluginsAreAvailable() - { - ClassLoader cl = PluginUtils.getPluginsClassloader(); - List<List<Object>> plugins = PluginUtils.getPlugins(); - - int k=0; - while( k<filters.filtersSize() ) - { - OneFilter onefilter = filters.getFilter(k); - if( !onefilter.isFromPlugin() ) - { - k++; - continue; - } - - for(List<Object> filterList : plugins) - { - for(int j=1; j<filterList.size(); j++) - { - String classname = (String)filterList.get(j); - if( onefilter.getClass().getName().equals(classname) ) - { - // trying to create - try - { - Class<?> filter_class = cl.loadClass(classname); - Constructor<?> filter_constructor = filter_class.getConstructor((Class[])null); - Object filter = filter_constructor.newInstance((Object[])null); - if( filter instanceof AbstractFilter ) - { - // OK - k++; - continue; - } - } - catch( Exception e ) - { - // couldn't load one of filters - // removing it - filters.removeFilter(k); - continue; - } - } - } - } - - // if we are here, it means that there's no such filter class - // in all the plugins currently present - // removing it - filters.removeFilter(k); - } - } - - /** - * Initializes Filter Master defaults - * by re-creating all information about built-in file filters. - */ - private Filters setupBuiltinFilters() - { - Filters res = new Filters(); - res.addFilter(new OneFilter(new AndroidFilter(), false)); - res.addFilter(new OneFilter(new TextFilter(), false)); - res.addFilter(new OneFilter(new LatexFilter(), false)); - res.addFilter(new OneFilter(new PoFilter(), false)); - res.addFilter(new OneFilter(new ResourceBundleFilter(), false)); - res.addFilter(new OneFilter(new XHTMLFilter(), false)); - res.addFilter(new OneFilter(new HTMLFilter2(), false)); - res.addFilter(new OneFilter(new HHCFilter2(), false)); - res.addFilter(new OneFilter(new INIFilter(), false)); - res.addFilter(new OneFilter(new DocBookFilter(), false)); - res.addFilter(new OneFilter(new OpenDocFilter(), false)); - res.addFilter(new OneFilter(new OpenXMLFilter(), false)); - res.addFilter(new OneFilter(new XLIFFFilter(), false)); - res.addFilter(new OneFilter(new SrtFilter(), false)); - res.addFilter(new OneFilter(new XtagFilter(), false)); - res.addFilter(new OneFilter(new ResXFilter(), false)); - res.addFilter(new OneFilter(new Typo3Filter(), false)); - return res; - } - - /** - * Loads filter classes from plugins. - * <p> - * Filter plugins should be situated in <OmegaT-install-dir>/plugins, - * and be packed as JAR files with manifest stating - * <pre> OmegaT-Plugin: true </pre> - * and then for each filter - * <pre> Name: the.package.name.TheFilterName - * OmegaT-Filter: true</pre> for each filter in a plugin - * (plugin may have more than one filter). - */ - private void loadFilterClassesFromPlugins() - { - ClassLoader cl = PluginUtils.getPluginsClassloader(); - List<List<Object>> plugins = PluginUtils.getPlugins(); - - for(int i=0; i<plugins.size(); i++) - { - List<Object> filterList = plugins.get(i); - for(int j=1; j<filterList.size(); j++) - { - try - { - Class<?> filter_class = cl.loadClass((String)filterList.get(j)); - Constructor<?> filter_constructor = filter_class.getConstructor((Class[])null); - Object filter = filter_constructor.newInstance((Object[])null); - if( filter instanceof AbstractFilter ) - { - OneFilter one_filter = new OneFilter((AbstractFilter)filter, true); - filters.addFilter(one_filter); - } - } - catch( Exception e ) - { - // couldn't load one of filters - // eat (almost) silently - Log.logErrorRB("FILTERMASTER_ERROR_LOADING_FILTER", - new Object[]{filterList.get(j), ((URL)filterList.get(0)).getFile()}); - } - } - } - } - - /** * Saves information about the filters to an XML file. */ - public void saveConfig() - { - try - { - XMLEncoder xmlenc = new XMLEncoder(new FileOutputStream(configFile)); - xmlenc.writeObject(filters); - xmlenc.close(); - Preferences.setPreference(Preferences.FILTERS_VERSION, CURRENT_VERSION); - } - catch( FileNotFoundException fnfe ) - { + public void saveConfig() { + try { + Marshaller m = CONFIG_CTX.createMarshaller(); + m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true); + m.marshal(config, configFile); + } catch (Exception e) { Log.logErrorRB("FILTERMASTER_ERROR_SAVING_FILTERS_CONFIG"); - Log.log(fnfe); - JOptionPane.showMessageDialog(null, - OStrings.getString("FILTERMASTER_ERROR_SAVING_FILTERS_CONFIG") + "\n" + fnfe, - OStrings.getString("ERROR_TITLE"), JOptionPane.ERROR_MESSAGE); + Log.log(e); + JOptionPane.showMessageDialog(null, OStrings + .getString("FILTERMASTER_ERROR_SAVING_FILTERS_CONFIG") + + "\n" + e, OStrings.getString("ERROR_TITLE"), + JOptionPane.ERROR_MESSAGE); } } @@ -740,4 +621,90 @@ pattern = "(?i)"+pattern; // NOI18N return pattern; } + + /** + * Set new config. Used by filter's editor. + * + * @param config + * new config + */ + public void setConfig(final Filters config) { + this.config = config; + applyOptions(); + } + + /** + * Clone config for editing + * + * @return new config instance + */ + public Filters cloneConfig() { + Filters c = new Filters(); + for (Filter f : config.getFilter()) { + c.getFilter().add(cloneFilter(f)); + } + return c; + } + + /** + * Clone one filter's config for editing. + * + * @param f + * one filter's config + * @return new config instance + */ + public Filter cloneFilter(Filter filter) { + Filter f = new Filter(); + f.setClassName(filter.getClassName()); + f.setEnabled(filter.isEnabled()); + for (Files ff : filter.getFiles()) { + f.getFiles().add(cloneFiles(ff)); + } + for(Option o:filter.getOption()) { + Option fo=new Option(); + fo.setName(o.getName()); + fo.setValue(o.getValue()); + f.getOption().add(fo); + } + return f; + } + + /** + * Clone one filter's instance config for editing. + * + * @param f + * new filter's instance config + * @return new config instance + */ + public Files cloneFiles(Files files) { + Files ff = new Files(); + ff.setSourceEncoding(files.getSourceEncoding()); + ff.setSourceFilenameMask(files.getSourceFilenameMask()); + ff.setTargetEncoding(files.getTargetEncoding()); + ff.setTargetFilenamePattern(files.getTargetFilenamePattern()); + return ff; + } + + /** + * Create default filter's config. + * + * @param filterClassname + * filter's classname + * @return default filter's config + */ + public Filter getDefaultSettingsFromFilter(final String filterClassname) { + AbstractFilter f = getFilterInstance(filterClassname); + Filter fc = new Filter(); + fc.setClassName(f.getClass().getName()); + fc.setEnabled(true); + for (Instance ins : f.getDefaultInstances()) { + Files ff = new Files(); + ff.setSourceEncoding(ins.getSourceEncoding()); + ff.setSourceFilenameMask(ins.getSourceFilenameMask()); + ff.setTargetEncoding(ins.getTargetEncoding()); + ff.setTargetFilenamePattern(ins.getTargetFilenamePattern()); + fc.getFiles().add(ff); + } + return fc; + } } Deleted: trunk/src/org/omegat/filters2/master/Filters.java =================================================================== --- trunk/src/org/omegat/filters2/master/Filters.java 2009-11-04 07:21:38 UTC (rev 2491) +++ trunk/src/org/omegat/filters2/master/Filters.java 2009-11-06 08:12:17 UTC (rev 2492) @@ -1,202 +0,0 @@ -/************************************************************************** - OmegaT - Computer Assisted Translation (CAT) tool - with fuzzy matching, translation memory, keyword search, - glossaries, and translation leveraging into updated projects. - - Copyright (C) 2000-2006 Keith Godfrey and Maxym Mykhalchuk - Home page: http://www.omegat.org/ - Support center: http://groups.yahoo.com/group/OmegaT/ - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -**************************************************************************/ - -package org.omegat.filters2.master; - -import java.io.Serializable; - -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; - -import javax.swing.table.AbstractTableModel; - -import org.omegat.util.OStrings; - - -/** - * Wrapper around all the file filter classes. - * Is a JavaBean, so that it's easy to write/read it to/from XML file - * and provides a table model. - * - * @author Maxym Mykhalchuk - */ -public class Filters extends AbstractTableModel implements Serializable -{ - - /** - * Create new empty Filters storage backend. - * Only for JavaBeans compliance here, do not call! - * <p> - * Call rather <code>FilterMaster.getInstance().getFilters()</code>. - */ - public Filters() - { - } - - /** Holds the list of available filters. */ - private List<OneFilter> filters = new ArrayList<OneFilter>(); - - /** - * Returns the number of filters. - */ - public int filtersSize() - { - return filters.size(); - } - - /** - * Returns all the filters as an array. - */ - public OneFilter[] getFilter() - { - return filters.toArray(new OneFilter[0]); - } - /** - * Sets all filters from the array. - */ - public void setFilter(OneFilter[] filter) - { - filters = new ArrayList<OneFilter>(Arrays.asList(filter)); - } - - /** - * Returns a filter by index. - */ - public OneFilter getFilter(int index) - { - return filters.get(index); - } - /** - * Sets a filter by index. - */ - public void setFilter(int index, OneFilter filter) - { - while( index>=filters.size() ) - filters.add(null); - filters.set(index, filter); - } - - /** - * Adds one filter to the list of filters. - * <p> - * Checks if there's already such a filter installed - * (by filter's class name). - */ - public void addFilter(OneFilter filter) - { - for(OneFilter f : filters) - if(f.getClassName().equals(filter.getClassName())) - return; - filters.add(filter); - } - /** - * Removes one filter from the list of filters. - * <p> - * It might happen if we loaded the filter from a plugin, - * and the plugin is no longer available. - */ - public void removeFilter(int index) - { - filters.remove(index); - } - - ////////////////////////////////////////////////////////////////////////// - // TableModel implementation - ////////////////////////////////////////////////////////////////////////// - - public int getColumnCount() - { - return 2; - } - - public String getColumnName(int columnIndex) - { - switch( columnIndex ) - { - case 0: - return OStrings.getString("FILTERS_FILE_FORMAT"); - case 1: - return OStrings.getString("FILTERS_ON"); - } - return null; - } - - public Class<?> getColumnClass(int columnIndex) - { - switch( columnIndex ) - { - case 0: - return String.class; - case 1: - return Boolean.class; - } - return null; - } - - public int getRowCount() - { - return getFilter().length; - } - - public Object getValueAt(int rowIndex, int columnIndex) - { - OneFilter filter = getFilter(rowIndex); - switch( columnIndex ) - { - case 0: - return filter.getHumanName(); - case 1: - return new Boolean(filter.isOn()); - } - return null; - } - - public void setValueAt(Object aValue, int rowIndex, int columnIndex) - { - OneFilter filter = getFilter(rowIndex); - switch( columnIndex ) - { - case 1: - filter.setOn(((Boolean)aValue).booleanValue()); - break; - default: - throw new IllegalArgumentException( - OStrings.getString("FILTERS_ERROR_COLUMN_INDEX_NOT_1")); - } - } - - public boolean isCellEditable(int rowIndex, int columnIndex) - { - switch( columnIndex ) - { - case 0: - return false; - case 1: - return true; - } - return false; - } - -} Added: trunk/src/org/omegat/filters2/master/FiltersTableModel.java =================================================================== --- trunk/src/org/omegat/filters2/master/FiltersTableModel.java (rev 0) +++ trunk/src/org/omegat/filters2/master/FiltersTableModel.java 2009-11-06 08:12:17 UTC (rev 2492) @@ -0,0 +1,129 @@ +/************************************************************************** + OmegaT - Computer Assisted Translation (CAT) tool + with fuzzy matching, translation memory, keyword search, + glossaries, and translation leveraging into updated projects. + + Copyright (C) 2000-2006 Keith Godfrey and Maxym Mykhalchuk + Home page: http://www.omegat.org/ + Support center: http://groups.yahoo.com/group/OmegaT/ + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +**************************************************************************/ + +package org.omegat.filters2.master; + +import gen.core.filters.Filter; +import gen.core.filters.Filters; + +import javax.swing.table.AbstractTableModel; + +import org.omegat.filters2.AbstractFilter; +import org.omegat.util.OStrings; + + +/** + * Wrapper around all the file filter classes. + * Is a JavaBean, so that it's easy to write/read it to/from XML file + * and provides a table model. + * + * @author Maxym Mykhalchuk + */ +public class FiltersTableModel extends AbstractTableModel { + + private final Filters config; + + public FiltersTableModel(final Filters config) { + this.config = config; + } + + ////////////////////////////////////////////////////////////////////////// + // TableModel implementation + ////////////////////////////////////////////////////////////////////////// + + public int getColumnCount() + { + return 2; + } + + public String getColumnName(int columnIndex) + { + switch( columnIndex ) + { + case 0: + return OStrings.getString("FILTERS_FILE_FORMAT"); + case 1: + return OStrings.getString("FILTERS_ON"); + } + return null; + } + + public Class<?> getColumnClass(int columnIndex) + { + switch( columnIndex ) + { + case 0: + return String.class; + case 1: + return Boolean.class; + } + return null; + } + + public int getRowCount() + { + return config.getFilter().size(); + } + + public Object getValueAt(int rowIndex, int columnIndex) + { + Filter filter = config.getFilter().get(rowIndex); + switch( columnIndex ) + { + case 0: + AbstractFilter f = FilterMaster.getInstance().getFilterInstance( + filter.getClassName()); + return f.getFileFormatName(); + case 1: + return new Boolean(filter.isEnabled()); + } + return null; + } + + public void setValueAt(Object aValue, int rowIndex, int columnIndex) + { + Filter filter = config.getFilter().get(rowIndex); + switch( columnIndex ) + { + case 1: + filter.setEnabled(((Boolean)aValue).booleanValue()); + break; + default: + throw new IllegalArgumentException( + OStrings.getString("FILTERS_ERROR_COLUMN_INDEX_NOT_1")); + } + } + + public boolean isCellEditable(int rowIndex, int columnIndex) + { + switch( columnIndex ) + { + case 0: + return false; + case 1: + return true; + } + return false; + } +} Property changes on: trunk/src/org/omegat/filters2/master/FiltersTableModel.java ___________________________________________________________________ Added: svn:mime-type + text/x-java Added: svn:keywords + Author Date Id Revision Added: svn:eol-style + native Deleted: trunk/src/org/omegat/filters2/master/OneFilter.java =================================================================== --- trunk/src/org/omegat/filters2/master/OneFilter.java 2009-11-04 07:21:38 UTC (rev 2491) +++ trunk/src/org/omegat/filters2/master/OneFilter.java 2009-11-06 08:12:17 UTC (rev 2492) @@ -1,396 +0,0 @@ -/************************************************************************** - OmegaT - Computer Assisted Translation (CAT) tool - with fuzzy matching, translation memory, keyword search, - glossaries, and translation leveraging into updated projects. - - Copyright (C) 2000-2006 Keith Godfrey and Maxym Mykhalchuk - Home page: http://www.omegat.org/ - Support center: http://groups.yahoo.com/group/OmegaT/ - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -**************************************************************************/ - -package org.omegat.filters2.master; - -import java.io.Serializable; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; -import javax.swing.table.AbstractTableModel; - -import org.omegat.filters2.AbstractFilter; -import org.omegat.filters2.Instance; -import org.omegat.util.Log; -import org.omegat.util.OStrings; - -/** - * Wrapper around a single file filter class - * Manages entries in XML config file and provides a table model. - * - * @author Maxym Mykhalchuk - */ -public class OneFilter extends AbstractTableModel implements Serializable -{ - ///////////////////////////////////////////////////////////////////////// - // Two different constructors - ///////////////////////////////////////////////////////////////////////// - - /** - * Creates an empty filter wrapper. - * Needed for JavaBeans compliance. - */ - public OneFilter() - { - } - - /** - * Creates a wrapper from a filter class. - * Needs to construct an XML element. - * - * @param fromPlugin is the filter loaded from a plugin? if yes, we'll check is the plugin still available upon loading configuration - */ - public OneFilter(AbstractFilter filter, boolean fromPlugin) - { - setClassName(filter.getClass().getName()); - setOn(true); - setFromPlugin(fromPlugin); - setSourceEncodingVariable(filter.isSourceEncodingVariable()); - setTargetEncodingVariable(filter.isTargetEncodingVariable()); - setInstance(filter.getDefaultInstances()); - } - - ///////////////////////////////////////////////////////////////////////// - // Properties - ///////////////////////////////////////////////////////////////////////// - - /** Holds the class name of the filter */ - private String className = null; - /** - * Returns the class name of the filter. - */ - public String getClassName() - { - return className; - } - /** - * Sets the class name of the filter. - */ - public void setClassName(String value) - { - className = value; - } - - /** - * Returns the human-readable name of the filter. - */ - public String getHumanName() - { - try - { - AbstractFilter filter = PluginUtils.instantiateFilter(this); - return filter.getFileFormatName(); - } - catch (Exception e) - { - Log.log(e); - return getClassName(); - } - } - /** - * Sets the "human" name of the filter. - * Since 1.6.0 RC7 does nothing. - */ - public void setHumanName(String value) {} - - /** If the filter is used. */ - private boolean on = true; - /** - * Returns whether the filter is on (used by OmegaT). - */ - public boolean isOn() - { - return on; - } - /** - * Sets whether the filter is on (used by OmegaT). - */ - public void setOn(boolean value) - { - on = value; - } - - - /** Holds whether this filter was loaded from a plugin */ - private boolean fromPlugin = false; - /** - * Returns whether this filter was loaded from a plugin - */ - public boolean isFromPlugin() - { - return fromPlugin; - } - /** - * Sets whether this filter was loaded from a plugin - */ - public void setFromPlugin(boolean fromPlugin) - { - this.fromPlugin = fromPlugin; - } - - /** Holds whether the filter's source encoding can be varied by user */ - private boolean sourceEncodingVariable; - /** - * Returns whether the filter's source encoding can be varied by user - */ - public boolean isSourceEncodingVariable() - { - return sourceEncodingVariable; - } - /** - * Sets whether the filter's source encoding can be varied by user - */ - public void setSourceEncodingVariable(boolean value) - { - sourceEncodingVariable = value; - } - - /** Holds whether the filter's target encoding can be varied by user */ - private boolean targetEncodingVariable; - /** - * Returns whether the filter's target encoding can be varied by user - */ - public boolean isTargetEncodingVariable() - { - return targetEncodingVariable; - } - /** - * Sets whether the filter's target encoding can be varied by user - */ - public void setTargetEncodingVariable(boolean value) - { - targetEncodingVariable = value; - } - - /** Holds instances property. */ - private List<Instance> instances = new ArrayList<Instance>(); - - /** - * Returns all the instances of the filter. - */ - public Instance[] getInstance() - { - return instances.toArray(new Instance[0]); - } - /** - * Sets all the instances of the filter at once. - */ - public void setInstance(Instance[] instance) - { - instances = new ArrayList<Instance>(Arrays.asList(instance)); - fireTableDataChanged(); - } - - /** - * Adds one the instance of the filter. - */ - public void addInstance(Instance instance) - { - instances.add(instance); - fireTableDataChanged(); - } - /** - * Removes one instance of the filter. - */ - public void removeInstance(int index) - { - instances.remove(index); - fireTableDataChanged(); - } - - /** Returns the filter instance #... */ - public Instance getInstance(int index) - { - return instances.get(index); - } - /** Sets the filter instance #... */ - public void setInstance(int index, Instance instance) - { - while( index>=instances.size() ) - instances.add(null); - instances.set(index, instance); - fireTableRowsUpdated(index, index); - } - - /** Returns the hint for editing the filter and adding/editing filter instance */ - public String getHint() - { - try - { - AbstractFilter filter = PluginUtils.instantiateFilter(this); - return filter.getHint(); - } - catch (Exception e) - { - Log.log(e); - return ""; // NOI18N - } - } - /** - * Sets the hint for editing the filter and adding/editing filter instance. - * Since 1.6.0 RC7 does nothing. - */ - public void setHint(String hint) {} - - /** Holds options of the filter. */ - private Serializable options = null; - - /** - * Returns filter's options. - * @return Filter options object. - */ - public Serializable getOptions() - { - return this.options; - } - - /** - * Setter for property options. - * @param options New value of property options. - */ - public void setOptions(Serializable options) - { - this.options = options; - } - - ////////////////////////////////////////////////////////////////////////// - // Filter Options - ////////////////////////////////////////////////////////////////////////// - - /** Returns whether the filter has options. */ - public boolean hasOptions() - { - try - { - AbstractFilter filter = PluginUtils.instantiateFilter(this); - return filter.hasOptions(); - } - catch (Exception e) - { - Log.log(e); - return false; - } - } - - /** Calls filter's modal dialog to change its options. */ - public void changeOptions(java.awt.Dialog parent) - { - try - { - AbstractFilter filter = PluginUtils.instantiateFilter(this); - setOptions(filter.changeOptions(parent, getOptions())); - } - catch (Exception e) - { - Log.log(e); - } - } - - ////////////////////////////////////////////////////////////////////////// - // TableModel implementation - ////////////////////////////////////////////////////////////////////////// - - public int getColumnCount() - { - return 4; - } - - public String getColumnName(int columnIndex) - { - switch( columnIndex ) - { - case 0: - return OStrings.getString("ONEFILTER_SOURCE_FILENAME_MASK"); - case 1: - return OStrings.getString("ONEFILTER_SOURCE_FILE_ENCODING"); - case 2: - return OStrings.getString("ONEFILTER_TARGET_FILE_ENCODING"); - case 3: - return OStrings.getString("ONEFILTER_TARGET_FILENAME_ENCODING"); - } - return null; - } - - public Class<?> getColumnClass(int columnIndex) - { - return String.class; - } - - public int getRowCount() - { - return getInstance().length; - } - - public Object getValueAt(int rowIndex, int columnIndex) - { - Instance instance = getInstance(rowIndex); - switch( columnIndex ) - { - case 0: - return instance.getSourceFilenameMask(); - case 1: - return instance.getSourceEncodingHuman(); - case 2: - return instance.getTargetEncodingHuman(); - case 3: - return instance.getTargetFilenamePattern(); - } - return null; - } - - public void setValueAt(Object aValue, int rowIndex, int columnIndex) - { - Instance instance = getInstance(rowIndex); - switch( columnIndex ) - { - case 0: - instance.setSourceFilenameMask(aValue.toString()); - break; - case 1: - instance.setSourceEncoding(aValue.toString()); - break; - case 2: - instance.setTargetEncoding(aValue.toString()); - break; - case 3: - instance.setTargetFilenamePattern(aValue.toString()); - break; - } - } - - public boolean isCellEditable(int rowIndex, int columnIndex) - { - switch( columnIndex ) - { - case 0: - case 3: - return true; - case 1: - return isSourceEncodingVariable(); - case 2: - return isTargetEncodingVariable(); - } - return false; - } -} Added: trunk/src/org/omegat/filters2/master/OneFilterTableModel.java =================================================================== --- trunk/src/org/omegat/filters2/master/OneFilterTableModel.java (rev 0) +++ trunk/src/org/omegat/filters2/master/OneFilterTableModel.java 2009-11-06 08:12:17 UTC (rev 2492) @@ -0,0 +1,144 @@ +/************************************************************************** + OmegaT - Computer Assisted Translation (CAT) tool + with fuzzy matching, translation memory, keyword search, + glossaries, and translation leveraging into updated projects. + + Copyright (C) 2000-2006 Keith Godfrey and Maxym Mykhalchuk + Home page: http://www.omegat.org/ + Support center: http://groups.yahoo.com/group/OmegaT/ + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +**************************************************************************/ + +package org.omegat.filters2.master; + +import gen.core.filters.Files; +import gen.core.filters.Filter; + +import javax.swing.table.AbstractTableModel; + +import org.omegat.filters2.AbstractFilter; +import org.omegat.util.OStrings; + +/** + * Wrapper around a single file filter class + * Manages entries in XML config file and provides a table model. + * + * @author Maxym Mykhalchuk + */ +public class OneFilterTableModel extends AbstractTableModel { + + private final Filter filter; + private boolean sourceEncodingVariable, targetEncodingVariable; + + public OneFilterTableModel(final Filter f) { + this.filter = f; + AbstractFilter fi = FilterMaster.getInstance().getFilterInstance( + f.getClassName()); + sourceEncodingVariable = fi.isSourceEncodingVariable(); + targetEncodingVariable = fi.isTargetEncodingVariable(); + } + + ////////////////////////////////////////////////////////////////////////// + // TableModel implementation + ////////////////////////////////////////////////////////////////////////// + + public int getColumnCount() + { + return 4; + } + + public String getColumnName(int columnIndex) + { + switch( columnIndex ) + { + case 0: + return OStrings.getString("ONEFILTER_SOURCE_FILENAME_MASK"); + case 1: + return OStrings.getString("ONEFILTER_SOURCE_FILE_ENCODING"); + case 2: + return OStrings.getString("ONEFILTER_TARGET_FILE_ENCODING"); + case 3: + return OStrings.getString("ONEFILTER_TARGET_FILENAME_ENCODING"); + } + return null; + } + + public Class<?> getColumnClass(int columnIndex) + { + return String.class; + } + + public int getRowCount() + { + return filter.getFiles().size(); + } + + public Object getValueAt(int rowIndex, int columnIndex) + { + Files instance = filter.getFiles().get(rowIndex); + switch( columnIndex ) + { + case 0: + return instance.getSourceFilenameMask(); + case 1: + return getEncodingName(instance.getSourceEncoding()); + case 2: + return getEncodingName(instance.getTargetEncoding()); + case 3: + return instance.getTargetFilenamePattern(); + } + return null; + } + + public void setValueAt(Object aValue, int rowIndex, int columnIndex) + { + Files instance = filter.getFiles().get(rowIndex); + switch( columnIndex ) + { + case 0: + instance.setSourceFilenameMask(aValue.toString()); + break; + case 1: + instance.setSourceEncoding(aValue.toString()); + break; + case 2: + instance.setTargetEncoding(aValue.toString()); + break; + case 3: + instance.setTargetFilenamePattern(aValue.toString()); + break; + } + } + + public boolean isCellEdita... [truncated message content] |
From: <al...@us...> - 2009-11-10 07:52:04
|
Revision: 2504 http://omegat.svn.sourceforge.net/omegat/?rev=2504&view=rev Author: alex73 Date: 2009-11-10 07:51:57 +0000 (Tue, 10 Nov 2009) Log Message: ----------- Project memory storage refactoring: use new storages Modified Paths: -------------- trunk/src/org/omegat/core/data/RealProject.java trunk/src/org/omegat/util/TMXWriter.java Modified: trunk/src/org/omegat/core/data/RealProject.java =================================================================== --- trunk/src/org/omegat/core/data/RealProject.java 2009-11-10 06:37:17 UTC (rev 2503) +++ trunk/src/org/omegat/core/data/RealProject.java 2009-11-10 07:51:57 UTC (rev 2504) @@ -407,7 +407,7 @@ { saveProjectProperties(); - Map<String,String> tmx = TMXWriter.prepareTMXData(m_srcTextEntryArray, m_orphanedList);//FIXME: change to new orphanedMap + Map<String,String> tmx = TMXWriter.prepareTMXData(m_srcTextEntryArray, orphanedSegments);//FIXME: change to new orphanedMap TMXWriter.buildTMXFile(s, false, false, m_config, tmx); m_modifiedFlag = false; } @@ -713,7 +713,9 @@ /* * Entry not found in source files - orphaned. */ - orphanedSegments.put(src, new TransEntry(trans)); + if (!StringUtil.isEmpty(trans)) { + orphanedSegments.put(src, new TransEntry(trans)); + } } else { se.setTranslation(trans); Modified: trunk/src/org/omegat/util/TMXWriter.java =================================================================== --- trunk/src/org/omegat/util/TMXWriter.java 2009-11-10 06:37:17 UTC (rev 2503) +++ trunk/src/org/omegat/util/TMXWriter.java 2009-11-10 07:51:57 UTC (rev 2504) @@ -38,6 +38,7 @@ import org.omegat.core.data.ProjectProperties; import org.omegat.core.data.SourceTextEntry; +import org.omegat.core.data.TransEntry; import org.omegat.core.data.TransMemory; /** @@ -59,7 +60,7 @@ */ public static Map<String, String> prepareTMXData( final List<SourceTextEntry> m_srcTextEntryArray, - final List<TransMemory> m_orphanedList) { + final Map<String, TransEntry> orphanedSegments) { Map<String, String> result = new HashMap<String, String>(); String source = null; String target = null; @@ -70,14 +71,10 @@ } // Write orphan strings. Assume N/A when pseudo-translate. - if (m_orphanedList != null) { - for (TransMemory transMem : m_orphanedList) { - if (transMem.target.length() == 0) - continue; - source = transMem.source; - target = transMem.target; - if (target.length() == 0) - continue; + if (orphanedSegments != null) { + for (Map.Entry<String, TransEntry> en : orphanedSegments.entrySet()) { + source = en.getKey(); + target = en.getValue().translation; result.put(source, target); } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <al...@us...> - 2009-11-11 06:36:05
|
Revision: 2507 http://omegat.svn.sourceforge.net/omegat/?rev=2507&view=rev Author: alex73 Date: 2009-11-11 06:35:47 +0000 (Wed, 11 Nov 2009) Log Message: ----------- Project memory storage refactoring: use new storages Modified Paths: -------------- trunk/src/org/omegat/core/data/RealProject.java trunk/src/org/omegat/util/TMXWriter.java Modified: trunk/src/org/omegat/core/data/RealProject.java =================================================================== --- trunk/src/org/omegat/core/data/RealProject.java 2009-11-10 14:12:20 UTC (rev 2506) +++ trunk/src/org/omegat/core/data/RealProject.java 2009-11-11 06:35:47 UTC (rev 2507) @@ -272,7 +272,7 @@ // - TMX Level 2, with OmegaT formatting tags wrapped in TMX inline tags try { - Map<String,String> tmx = TMXWriter.prepareTMXData(m_srcTextEntryArray, null); + Map<String,String> tmx = TMXWriter.prepareTMXData(translations, new TreeMap<String, TransEntry>()); // build TMX with OmegaT tags String fname = m_config.getProjectRoot() + m_config.getProjectName() + OConsts.OMEGAT_TMX @@ -400,7 +400,7 @@ { saveProjectProperties(); - Map<String,String> tmx = TMXWriter.prepareTMXData(m_srcTextEntryArray, orphanedSegments);//FIXME: change to new orphanedMap + Map<String,String> tmx = TMXWriter.prepareTMXData(translations, orphanedSegments); TMXWriter.buildTMXFile(s, false, false, m_config, tmx); m_modifiedFlag = false; } @@ -714,7 +714,9 @@ /* * Entry not found in source files - translation. */ - translations.put(src, new TransEntry(trans)); + if (!StringUtil.isEmpty(trans)) { + translations.put(src, new TransEntry(trans)); + } } } else @@ -773,10 +775,10 @@ * {@inheritDoc} */ public void setTranslation(final SourceTextEntry entry, String trans) { - if( trans==null ) { + if (trans == null) { trans = ""; } - +//FIXME: change to remove empty translations entry.setTranslation(trans); m_modifiedFlag = true; TransEntry prevTrEntry = translations.put(entry.getSrcText(), @@ -890,7 +892,10 @@ // entry doesn't exist yet - create and store it strEntry = new StringEntry(segmentSource); strEntry.setTranslation(segmentTranslation); - translations.put(segmentSource, new TransEntry(segmentTranslation)); + if (!StringUtil.isEmpty(segmentTranslation)) { + translations.put(segmentSource, new TransEntry( + segmentTranslation)); + } context.m_strEntryHash.put(segmentSource, strEntry); } SourceTextEntry srcTextEntry = new SourceTextEntry(strEntry, m_curFile, m_srcTextEntryArray.size()); Modified: trunk/src/org/omegat/util/TMXWriter.java =================================================================== --- trunk/src/org/omegat/util/TMXWriter.java 2009-11-10 14:12:20 UTC (rev 2506) +++ trunk/src/org/omegat/util/TMXWriter.java 2009-11-11 06:35:47 UTC (rev 2507) @@ -31,15 +31,12 @@ import java.io.OutputStreamWriter; import java.io.PrintWriter; import java.util.HashMap; -import java.util.List; import java.util.Map; import java.util.regex.Matcher; import java.util.regex.Pattern; import org.omegat.core.data.ProjectProperties; -import org.omegat.core.data.SourceTextEntry; import org.omegat.core.data.TransEntry; -import org.omegat.core.data.TransMemory; /** * Class that store TMX (Translation Memory Exchange) files. @@ -59,24 +56,18 @@ * @return map of strings for TMX */ public static Map<String, String> prepareTMXData( - final List<SourceTextEntry> m_srcTextEntryArray, + final Map<String, TransEntry> translations, final Map<String, TransEntry> orphanedSegments) { - Map<String, String> result = new HashMap<String, String>(); - String source = null; - String target = null; - for (SourceTextEntry ste : m_srcTextEntryArray) { - if (ste.isTranslated()) { - result.put(ste.getSrcText(), ste.getTranslation()); - } + int sz = translations.size() + orphanedSegments.size(); + Map<String, String> result = new HashMap<String, String>(sz); + + for (Map.Entry<String, TransEntry> en : translations.entrySet()) { + result.put(en.getKey(), en.getValue().translation); } // Write orphan strings. Assume N/A when pseudo-translate. - if (orphanedSegments != null) { - for (Map.Entry<String, TransEntry> en : orphanedSegments.entrySet()) { - source = en.getKey(); - target = en.getValue().translation; - result.put(source, target); - } + for (Map.Entry<String, TransEntry> en : orphanedSegments.entrySet()) { + result.put(en.getKey(), en.getValue().translation); } return result; } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <al...@us...> - 2009-11-11 06:52:13
|
Revision: 2508 http://omegat.svn.sourceforge.net/omegat/?rev=2508&view=rev Author: alex73 Date: 2009-11-11 06:52:03 +0000 (Wed, 11 Nov 2009) Log Message: ----------- Project memory storage refactoring: use new storages Modified Paths: -------------- trunk/src/org/omegat/core/data/RealProject.java trunk/src/org/omegat/gui/matches/FindMatchesThread.java Modified: trunk/src/org/omegat/core/data/RealProject.java =================================================================== --- trunk/src/org/omegat/core/data/RealProject.java 2009-11-11 06:35:47 UTC (rev 2507) +++ trunk/src/org/omegat/core/data/RealProject.java 2009-11-11 06:52:03 UTC (rev 2508) @@ -775,14 +775,15 @@ * {@inheritDoc} */ public void setTranslation(final SourceTextEntry entry, String trans) { - if (trans == null) { - trans = ""; - } -//FIXME: change to remove empty translations entry.setTranslation(trans); m_modifiedFlag = true; - TransEntry prevTrEntry = translations.put(entry.getSrcText(), - new TransEntry(trans)); + + TransEntry prevTrEntry = translations.get(entry.getSrcText()); + if (StringUtil.isEmpty(trans)) { + translations.remove(entry.getSrcText()); + } else { + translations.put(entry.getSrcText(), new TransEntry(trans)); + } String prevTranslation = prevTrEntry != null ? prevTrEntry.translation : null; Modified: trunk/src/org/omegat/gui/matches/FindMatchesThread.java =================================================================== --- trunk/src/org/omegat/gui/matches/FindMatchesThread.java 2009-11-11 06:35:47 UTC (rev 2507) +++ trunk/src/org/omegat/gui/matches/FindMatchesThread.java 2009-11-11 06:52:03 UTC (rev 2508) @@ -45,7 +45,6 @@ import org.omegat.core.matching.NearString; import org.omegat.util.OConsts; import org.omegat.util.OStrings; -import org.omegat.util.StringUtil; import org.omegat.util.Token; /** @@ -99,6 +98,7 @@ @Override public void run() { final List<SourceTextEntry> entries = Core.getProject().getAllEntries(); + Map<String, TransEntry> translations = Core.getProject().getTranslations(); Map<String, TransEntry> orphaned = Core.getProject() .getOrphanedSegments(); Map<String, List<TransMemory>> memories = Core.getProject() @@ -129,20 +129,15 @@ strTokensAll = Core.getTokenizer().tokenizeAllExactly(processedEntry.getSrcText());// HP: includes non-word tokens // travel by project entries - // FIXME: iterate by unique entries, not by all segments - for (SourceTextEntry candEntry : entries) { + for (Map.Entry<String, TransEntry> en : translations.entrySet()) { if (needStop()) { return; } - if (StringUtil.isEmpty(candEntry.getTranslation())) { - continue; - } - if (candEntry.getStrEntry() == processedEntry) { + if (en.getKey().equals(processedEntry.getSrcText())) { // skip original==original entry comparison continue; } - processEntry(candEntry.getSrcText(), candEntry.getTranslation(), - null); + processEntry(en.getKey(), en.getValue().translation, null); } // travel by orphaned This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <al...@us...> - 2009-11-12 06:10:43
|
Revision: 2511 http://omegat.svn.sourceforge.net/omegat/?rev=2511&view=rev Author: alex73 Date: 2009-11-12 06:10:37 +0000 (Thu, 12 Nov 2009) Log Message: ----------- Project memory storage refactoring: use new storages Modified Paths: -------------- trunk/src/org/omegat/core/CoreEvents.java trunk/src/org/omegat/core/events/IEntryEventListener.java trunk/src/org/omegat/gui/common/EntryInfoPane.java trunk/src/org/omegat/gui/common/EntryInfoSearchThread.java trunk/src/org/omegat/gui/dictionaries/DictionariesTextArea.java trunk/src/org/omegat/gui/editor/EditorController.java trunk/src/org/omegat/gui/exttrans/GoogleTranslateTextArea.java trunk/src/org/omegat/gui/filelist/ProjectFrame.java trunk/src/org/omegat/gui/glossary/FindGlossaryThread.java trunk/src/org/omegat/gui/glossary/GlossaryTextArea.java trunk/src/org/omegat/gui/matches/FindMatchesThread.java trunk/src/org/omegat/gui/matches/MatchesTextArea.java Modified: trunk/src/org/omegat/core/CoreEvents.java =================================================================== --- trunk/src/org/omegat/core/CoreEvents.java 2009-11-11 07:59:49 UTC (rev 2510) +++ trunk/src/org/omegat/core/CoreEvents.java 2009-11-12 06:10:37 UTC (rev 2511) @@ -30,7 +30,7 @@ import javax.swing.SwingUtilities; -import org.omegat.core.data.StringEntry; +import org.omegat.core.data.SourceTextEntry; import org.omegat.core.events.IApplicationEventListener; import org.omegat.core.events.IEditorEventListener; import org.omegat.core.events.IEntryEventListener; @@ -192,7 +192,7 @@ } /** Fire event. */ - public static void fireEntryActivated(final StringEntry newEntry) { + public static void fireEntryActivated(final SourceTextEntry newEntry) { SwingUtilities.invokeLater(new Runnable() { public void run() { Log.logInfoRB("LOG_INFO_EVENT_ENTRY_ACTIVATED"); Modified: trunk/src/org/omegat/core/events/IEntryEventListener.java =================================================================== --- trunk/src/org/omegat/core/events/IEntryEventListener.java 2009-11-11 07:59:49 UTC (rev 2510) +++ trunk/src/org/omegat/core/events/IEntryEventListener.java 2009-11-12 06:10:37 UTC (rev 2511) @@ -23,7 +23,7 @@ **************************************************************************/ package org.omegat.core.events; -import org.omegat.core.data.StringEntry; +import org.omegat.core.data.SourceTextEntry; /** * Listener interface for entry change events. @@ -46,5 +46,5 @@ * new entry instance which activated, or null if entry * deactivated */ - void onEntryActivated(StringEntry newEntry); + void onEntryActivated(SourceTextEntry newEntry); } Modified: trunk/src/org/omegat/gui/common/EntryInfoPane.java =================================================================== --- trunk/src/org/omegat/gui/common/EntryInfoPane.java 2009-11-11 07:59:49 UTC (rev 2510) +++ trunk/src/org/omegat/gui/common/EntryInfoPane.java 2009-11-12 06:10:37 UTC (rev 2511) @@ -30,7 +30,7 @@ import org.omegat.core.Core; import org.omegat.core.CoreEvents; -import org.omegat.core.data.StringEntry; +import org.omegat.core.data.SourceTextEntry; import org.omegat.core.events.IEntryEventListener; import org.omegat.core.events.IFontChangedEventListener; import org.omegat.core.events.IProjectEventListener; @@ -45,7 +45,7 @@ */ public abstract class EntryInfoPane<T> extends JTextPane implements IProjectEventListener, IEntryEventListener { - StringEntry currentlyProcessedEntry; + SourceTextEntry currentlyProcessedEntry; public EntryInfoPane(final boolean useApplicationFont) { if (useApplicationFont) { @@ -85,7 +85,7 @@ currentlyProcessedEntry = null; } - public void onEntryActivated(StringEntry newEntry) { + public void onEntryActivated(SourceTextEntry newEntry) { currentlyProcessedEntry = newEntry; startSearchThread(newEntry); } @@ -96,7 +96,7 @@ * @param newEntry * new entry for find */ - protected abstract void startSearchThread(final StringEntry newEntry); + protected abstract void startSearchThread(final SourceTextEntry newEntry); /** * Callback from search thread. Modified: trunk/src/org/omegat/gui/common/EntryInfoSearchThread.java =================================================================== --- trunk/src/org/omegat/gui/common/EntryInfoSearchThread.java 2009-11-11 07:59:49 UTC (rev 2510) +++ trunk/src/org/omegat/gui/common/EntryInfoSearchThread.java 2009-11-12 06:10:37 UTC (rev 2511) @@ -26,7 +26,7 @@ import javax.swing.SwingUtilities; -import org.omegat.core.data.StringEntry; +import org.omegat.core.data.SourceTextEntry; /** * Base class for search info about current entry in the separate thread. @@ -48,7 +48,7 @@ * If entry in pane was changed, it means user was moved to other entry, and * there is no sense to continue search. */ - private final StringEntry currentlyProcessedEntry; + private final SourceTextEntry currentlyProcessedEntry; /** * Constructor. @@ -59,7 +59,7 @@ * current entry */ public EntryInfoSearchThread(final EntryInfoPane<T> pane, - final StringEntry entry) { + final SourceTextEntry entry) { this.pane = pane; this.currentlyProcessedEntry = entry; Modified: trunk/src/org/omegat/gui/dictionaries/DictionariesTextArea.java =================================================================== --- trunk/src/org/omegat/gui/dictionaries/DictionariesTextArea.java 2009-11-11 07:59:49 UTC (rev 2510) +++ trunk/src/org/omegat/gui/dictionaries/DictionariesTextArea.java 2009-11-12 06:10:37 UTC (rev 2511) @@ -45,7 +45,6 @@ import org.omegat.core.Core; import org.omegat.core.CoreEvents; import org.omegat.core.data.SourceTextEntry; -import org.omegat.core.data.StringEntry; import org.omegat.core.dictionaries.DictionariesManager; import org.omegat.core.dictionaries.DictionaryEntry; import org.omegat.core.events.IEditorEventListener; @@ -138,7 +137,7 @@ } @Override - protected void startSearchThread(StringEntry newEntry) { + protected void startSearchThread(SourceTextEntry newEntry) { new DictionaryEntriesSearchThread(newEntry).start(); } @@ -148,7 +147,7 @@ public void refresh() { SourceTextEntry ste = Core.getEditor().getCurrentEntry(); if (ste != null) { - startSearchThread(ste.getStrEntry()); + startSearchThread(ste); } } @@ -216,7 +215,7 @@ EntryInfoSearchThread<List<DictionaryEntry>> { protected final String src; - public DictionaryEntriesSearchThread(final StringEntry newEntry) { + public DictionaryEntriesSearchThread(final SourceTextEntry newEntry) { super(DictionariesTextArea.this, newEntry); src = newEntry.getSrcText(); } Modified: trunk/src/org/omegat/gui/editor/EditorController.java =================================================================== --- trunk/src/org/omegat/gui/editor/EditorController.java 2009-11-11 07:59:49 UTC (rev 2510) +++ trunk/src/org/omegat/gui/editor/EditorController.java 2009-11-12 06:10:37 UTC (rev 2511) @@ -52,7 +52,6 @@ import org.omegat.core.CoreEvents; import org.omegat.core.data.IProject; import org.omegat.core.data.SourceTextEntry; -import org.omegat.core.data.StringEntry; import org.omegat.core.events.IEntryEventListener; import org.omegat.core.events.IFontChangedEventListener; import org.omegat.core.events.IProjectEventListener; @@ -182,7 +181,7 @@ updateState(SHOW_TYPE.NO_CHANGE); } - public void onEntryActivated(StringEntry newEntry) { + public void onEntryActivated(SourceTextEntry newEntry) { } }); @@ -493,7 +492,7 @@ editor.repaint(); // fire event about new segment activated - CoreEvents.fireEntryActivated(ste.getStrEntry()); + CoreEvents.fireEntryActivated(ste); } /** Modified: trunk/src/org/omegat/gui/exttrans/GoogleTranslateTextArea.java =================================================================== --- trunk/src/org/omegat/gui/exttrans/GoogleTranslateTextArea.java 2009-11-11 07:59:49 UTC (rev 2510) +++ trunk/src/org/omegat/gui/exttrans/GoogleTranslateTextArea.java 2009-11-12 06:10:37 UTC (rev 2511) @@ -29,6 +29,7 @@ import java.util.regex.Pattern; import org.omegat.core.Core; +import org.omegat.core.data.SourceTextEntry; import org.omegat.core.data.StringEntry; import org.omegat.gui.common.EntryInfoPane; import org.omegat.gui.common.EntryInfoSearchThread; @@ -61,7 +62,7 @@ } @Override - protected void startSearchThread(final StringEntry newEntry) { + protected void startSearchThread(final SourceTextEntry newEntry) { UIThreadsUtil.mustBeSwingThread(); if (Preferences.isPreference(Preferences.ALLOW_GOOGLE_TRANSLATE)) { new FindThread(newEntry).start(); @@ -80,7 +81,7 @@ protected class FindThread extends EntryInfoSearchThread<String> { private final String src; - public FindThread(final StringEntry newEntry) { + public FindThread(final SourceTextEntry newEntry) { super(GoogleTranslateTextArea.this, newEntry); src = newEntry.getSrcText(); } Modified: trunk/src/org/omegat/gui/filelist/ProjectFrame.java =================================================================== --- trunk/src/org/omegat/gui/filelist/ProjectFrame.java 2009-11-11 07:59:49 UTC (rev 2510) +++ trunk/src/org/omegat/gui/filelist/ProjectFrame.java 2009-11-12 06:10:37 UTC (rev 2511) @@ -77,7 +77,7 @@ import org.omegat.core.Core; import org.omegat.core.CoreEvents; import org.omegat.core.data.IProject; -import org.omegat.core.data.StringEntry; +import org.omegat.core.data.SourceTextEntry; import org.omegat.core.events.IEntryEventListener; import org.omegat.core.events.IFontChangedEventListener; import org.omegat.core.events.IProjectEventListener; @@ -251,7 +251,7 @@ * Updates the number of translated segments only, does not rebuild * the whole display. */ - public void onEntryActivated(StringEntry newEntry) { + public void onEntryActivated(SourceTextEntry newEntry) { UIThreadsUtil.mustBeSwingThread(); modelTotal.fireTableDataChanged(); } Modified: trunk/src/org/omegat/gui/glossary/FindGlossaryThread.java =================================================================== --- trunk/src/org/omegat/gui/glossary/FindGlossaryThread.java 2009-11-11 07:59:49 UTC (rev 2510) +++ trunk/src/org/omegat/gui/glossary/FindGlossaryThread.java 2009-11-12 06:10:37 UTC (rev 2511) @@ -32,7 +32,7 @@ import java.util.List; import org.omegat.core.Core; -import org.omegat.core.data.StringEntry; +import org.omegat.core.data.SourceTextEntry; import org.omegat.core.matching.ITokenizer; import org.omegat.core.matching.Tokenizer; import org.omegat.gui.common.EntryInfoSearchThread; @@ -69,7 +69,7 @@ private final GlossaryManager manager; public FindGlossaryThread(final GlossaryTextArea pane, - final StringEntry newEntry, final GlossaryManager manager) { + final SourceTextEntry newEntry, final GlossaryManager manager) { super(pane, newEntry); src = newEntry.getSrcText(); this.manager = manager; @@ -217,8 +217,8 @@ } } - // \xB7\xB7 Sort items with same locTxt - // \xB7\xB7\xB7\xB7\xB7\xB7\xB7\xB7\xB7\xB7\xB7\xB7\xB7\xB7\xB7\xB7\xB7\xB7\xB7\xB7\xB7\xB7\xB7\xB7\xB7\xB7\xB7\xB7\xB7\xB7\xB7\xB7\xB7\xB7\xB7 + // �� Sort items with same locTxt + // ����������������������������������� List<GlossaryEntry> sortList = new LinkedList<GlossaryEntry>(); if (srcList.size() > 1) { for (int k = 0; k < srcList.size(); k++) { @@ -244,7 +244,7 @@ } else { sortList = srcList; } - // \xB7\xB7\xB7\xB7\xB7\xB7\xB7\xB7\xB7\xB7\xB7\xB7\xB7\xB7\xB7\xB7\xB7\xB7\xB7\xB7\xB7\xB7\xB7\xB7\xB7\xB7\xB7\xB7\xB7\xB7\xB7\xB7\xB7\xB7\xB7\xB7\xB7\xB7\xB7\xB7\xB7\xB7\xB7\xB7\xB7\xB7\xB7\xB7\xB7\xB7\xB7\xB7\xB7\xB7\xB7\xB7\xB7\xB7\xB7\xB7\xB7\xB7\xB7\xB7\xB7\xB7 + // ������������������������������������������������������������������ // == Now put the sortedList together // =============================== Modified: trunk/src/org/omegat/gui/glossary/GlossaryTextArea.java =================================================================== --- trunk/src/org/omegat/gui/glossary/GlossaryTextArea.java 2009-11-11 07:59:49 UTC (rev 2510) +++ trunk/src/org/omegat/gui/glossary/GlossaryTextArea.java 2009-11-12 06:10:37 UTC (rev 2511) @@ -84,7 +84,7 @@ } @Override - protected void startSearchThread(StringEntry newEntry) { + protected void startSearchThread(SourceTextEntry newEntry) { new FindGlossaryThread(GlossaryTextArea.this, newEntry, manager) .start(); } @@ -95,7 +95,7 @@ public void refresh() { SourceTextEntry ste = Core.getEditor().getCurrentEntry(); if (ste != null) { - startSearchThread(ste.getStrEntry()); + startSearchThread(ste); } } Modified: trunk/src/org/omegat/gui/matches/FindMatchesThread.java =================================================================== --- trunk/src/org/omegat/gui/matches/FindMatchesThread.java 2009-11-11 07:59:49 UTC (rev 2510) +++ trunk/src/org/omegat/gui/matches/FindMatchesThread.java 2009-11-12 06:10:37 UTC (rev 2511) @@ -35,7 +35,6 @@ import org.omegat.core.Core; import org.omegat.core.data.SourceTextEntry; -import org.omegat.core.data.StringEntry; import org.omegat.core.data.TransEntry; import org.omegat.core.data.TransMemory; import org.omegat.core.matching.FuzzyMatcher; @@ -77,7 +76,7 @@ * If entry in controller was changed, it means user has moved to another * entry, and there is no sense to continue. */ - private final StringEntry processedEntry; + private final SourceTextEntry processedEntry; /** Result list. */ private List<NearString> result = new ArrayList<NearString>(OConsts.MAX_NEAR_STRINGS + 1); @@ -90,7 +89,7 @@ /** Tokens for original string, includes numbers and tags. */ private Token[] strTokensAll; - public FindMatchesThread(final MatchesTextArea matcherController, final StringEntry entry) { + public FindMatchesThread(final MatchesTextArea matcherController, final SourceTextEntry entry) { this.matcherController = matcherController; this.processedEntry = entry; } Modified: trunk/src/org/omegat/gui/matches/MatchesTextArea.java =================================================================== --- trunk/src/org/omegat/gui/matches/MatchesTextArea.java 2009-11-11 07:59:49 UTC (rev 2510) +++ trunk/src/org/omegat/gui/matches/MatchesTextArea.java 2009-11-12 06:10:37 UTC (rev 2511) @@ -73,7 +73,7 @@ private final MainWindow mw; - protected StringEntry processedEntry; + protected SourceTextEntry processedEntry; /** Creates new form MatchGlossaryPane */ public MatchesTextArea(MainWindow mw) { @@ -98,7 +98,7 @@ public void onNewFile(String activeFileName) { } - public void onEntryActivated(final StringEntry newEntry) { + public void onEntryActivated(final SourceTextEntry newEntry) { processedEntry = newEntry; new FindMatchesThread(MatchesTextArea.this, newEntry).start(); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <al...@us...> - 2009-11-12 07:06:26
|
Revision: 2512 http://omegat.svn.sourceforge.net/omegat/?rev=2512&view=rev Author: alex73 Date: 2009-11-12 07:06:13 +0000 (Thu, 12 Nov 2009) Log Message: ----------- Project memory storage refactoring: use new storages Modified Paths: -------------- trunk/src/org/omegat/core/statistics/CalcStandardStatistics.java trunk/src/org/omegat/gui/tagvalidation/TagValidationFrame.java trunk/src/org/omegat/gui/tagvalidation/TagValidationTool.java Modified: trunk/src/org/omegat/core/statistics/CalcStandardStatistics.java =================================================================== --- trunk/src/org/omegat/core/statistics/CalcStandardStatistics.java 2009-11-12 06:10:37 UTC (rev 2511) +++ trunk/src/org/omegat/core/statistics/CalcStandardStatistics.java 2009-11-12 07:06:13 UTC (rev 2512) @@ -119,7 +119,7 @@ Map<String, FileData> counts = new TreeMap<String, FileData>(); for (SourceTextEntry ste : entries) { - String src = ste.getStrEntry().getSrcText(); + String src = ste.getSrcText(); int words = Statistics.numberOfWords(src); String noTags = StaticUtils.stripTags(src); @@ -134,7 +134,7 @@ total.charsWithSpaces += chars; // add to remaining - TransEntry tr = project.getTranslations().get(ste.getSrcText()); + TransEntry tr = project.getTranslations().get(src); if (tr == null) { remaining.segments++; remaining.words += words; @@ -166,14 +166,14 @@ Set<String> translated = new HashSet<String>( entries.size() / 2); for (SourceTextEntry ste : entries) { - String src = ste.getStrEntry().getSrcText(); + String src = ste.getSrcText(); Integer count = uniqueSegment.get(src); if (count == null) { uniqueSegment.put(src, 1); } else { uniqueSegment.put(src, count + 1); } - TransEntry tr = project.getTranslations().get(ste.getSrcText()); + TransEntry tr = project.getTranslations().get(src); if (tr != null) { translated.add(src); } Modified: trunk/src/org/omegat/gui/tagvalidation/TagValidationFrame.java =================================================================== --- trunk/src/org/omegat/gui/tagvalidation/TagValidationFrame.java 2009-11-12 06:10:37 UTC (rev 2511) +++ trunk/src/org/omegat/gui/tagvalidation/TagValidationFrame.java 2009-11-12 07:06:13 UTC (rev 2512) @@ -48,6 +48,7 @@ import org.omegat.core.CoreEvents; import org.omegat.core.data.SourceTextEntry; import org.omegat.core.data.StringEntry; +import org.omegat.core.data.TransEntry; import org.omegat.core.events.IFontChangedEventListener; import org.omegat.gui.HListener; import org.omegat.gui.main.MainWindow; @@ -233,11 +234,9 @@ output.append("<table BORDER COLS=3 WIDTH=\"100%\" NOSAVE>\n"); // NOI18N for (SourceTextEntry ste : stringList) { - StringEntry se = ste.getStrEntry(); - String src = se.getSrcText(); - String trans = se.getTranslation(); - if (src.length()>0 && trans.length()>0) - { + String src = ste.getSrcText(); + TransEntry trans = Core.getProject().getTranslations().get(src); + if (src.length() > 0 && trans != null) { int entryNum = ste.entryNum() + 1; output.append("<tr>"); // NOI18N output.append("<td>"); // NOI18N @@ -253,7 +252,7 @@ output.append(colorTags(htmlize(src), "blue")); // NOI18N output.append("</td>"); // NOI18N output.append("<td>"); // NOI18N - output.append(colorTags(htmlize(trans), "blue")); // NOI18N + output.append(colorTags(htmlize(trans.translation), "blue")); // NOI18N output.append("</td>"); // NOI18N output.append("</tr>\n"); // NOI18N } Modified: trunk/src/org/omegat/gui/tagvalidation/TagValidationTool.java =================================================================== --- trunk/src/org/omegat/gui/tagvalidation/TagValidationTool.java 2009-11-12 06:10:37 UTC (rev 2511) +++ trunk/src/org/omegat/gui/tagvalidation/TagValidationTool.java 2009-11-12 07:06:13 UTC (rev 2512) @@ -36,7 +36,7 @@ import org.omegat.core.CoreEvents; import org.omegat.core.data.ProjectFileData; import org.omegat.core.data.SourceTextEntry; -import org.omegat.core.data.StringEntry; +import org.omegat.core.data.TransEntry; import org.omegat.core.events.IProjectEventListener; import org.omegat.gui.main.MainWindow; import org.omegat.util.OStrings; @@ -100,25 +100,23 @@ private List<SourceTextEntry> listInvalidTags() { int j; String s; - String t; + TransEntry te; List<String> srcTags = new ArrayList<String>(32); List<String> locTags = new ArrayList<String>(32); List<SourceTextEntry> suspects = new ArrayList<SourceTextEntry>(16); - StringEntry se; - // PO validation: pattern to detect printf variables (%s and %n\$s) Pattern printfPattern = PatternConsts.PRINTF_VARS; for (SourceTextEntry ste : Core.getProject().getAllEntries()) { - se = ste.getStrEntry(); - s = se.getSrcText(); - t = se.getTranslation(); + s = ste.getSrcText(); + te = Core.getProject().getTranslations().get(s); // if there's no translation, skip the string // bugfix for http://sourceforge.net/support/tracker.php?aid=1209839 - if (t == null || t.length() == 0) + if (te == null) { continue; + } //Extra checks for PO files: ProjectFileData sourceFileData = ste.getSrcFile(); @@ -143,7 +141,7 @@ } } HashSet<String> printfTargetSet = new HashSet<String>(); - printfMatcher = printfPattern.matcher(t); + printfMatcher = printfPattern.matcher(te.translation); index=1; while (printfMatcher.find()) { String printfVariable = printfMatcher.group(0); @@ -161,7 +159,7 @@ } // check PO line ending: Boolean s_ends_lf = s.endsWith("\n"); - Boolean t_ends_lf = t.endsWith("\n"); + Boolean t_ends_lf = te.translation.endsWith("\n"); if (s_ends_lf && !t_ends_lf || !s_ends_lf && t_ends_lf) { suspects.add(ste); continue; @@ -170,7 +168,7 @@ // OmegaT tags check: // extract tags from src and loc string StaticUtils.buildTagList(s, srcTags); - StaticUtils.buildTagList(t, locTags); + StaticUtils.buildTagList(te.translation, locTags); // make sure lists match // for now, insist on exact match @@ -180,7 +178,7 @@ // compare one by one for (j = 0; j < srcTags.size(); j++) { s = srcTags.get(j); - t = locTags.get(j); + String t = locTags.get(j); if (!s.equals(t)) { suspects.add(ste); break; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <al...@us...> - 2009-11-12 07:17:16
|
Revision: 2513 http://omegat.svn.sourceforge.net/omegat/?rev=2513&view=rev Author: alex73 Date: 2009-11-12 07:17:10 +0000 (Thu, 12 Nov 2009) Log Message: ----------- Project memory storage refactoring: move translation choose into project core Modified Paths: -------------- trunk/src/org/omegat/core/data/IProject.java trunk/src/org/omegat/core/data/NotLoadedProject.java trunk/src/org/omegat/core/data/RealProject.java trunk/src/org/omegat/core/data/SourceTextEntry.java trunk/src/org/omegat/core/statistics/CalcStandardStatistics.java trunk/src/org/omegat/gui/matches/FindMatchesThread.java trunk/src/org/omegat/gui/tagvalidation/TagValidationFrame.java trunk/src/org/omegat/gui/tagvalidation/TagValidationTool.java Modified: trunk/src/org/omegat/core/data/IProject.java =================================================================== --- trunk/src/org/omegat/core/data/IProject.java 2009-11-12 07:06:13 UTC (rev 2512) +++ trunk/src/org/omegat/core/data/IProject.java 2009-11-12 07:17:10 UTC (rev 2513) @@ -28,6 +28,7 @@ import java.util.ArrayList; import java.util.List; import java.util.Map; +import java.util.Set; import org.omegat.core.statistics.StatisticsInfo; import org.omegat.filters2.TranslationException; @@ -110,9 +111,19 @@ /** * Get all translations for current project. + * * @return all translations map */ - Map<String, TransEntry> getTranslations(); + Set<Map.Entry<String, TransEntry>> getTranslationsSet(); + + /** + * Get translation for specified entry. + * + * @param ste + * source entry + * @return translation, or null if translation not exist + */ + TransEntry getTranslation(SourceTextEntry ste); /** * Get all translation memories from /tm/ folder. Modified: trunk/src/org/omegat/core/data/NotLoadedProject.java =================================================================== --- trunk/src/org/omegat/core/data/NotLoadedProject.java 2009-11-12 07:06:13 UTC (rev 2512) +++ trunk/src/org/omegat/core/data/NotLoadedProject.java 2009-11-12 07:17:10 UTC (rev 2513) @@ -27,6 +27,8 @@ import java.io.IOException; import java.util.List; import java.util.Map; +import java.util.Set; +import java.util.Map.Entry; import org.omegat.core.statistics.StatisticsInfo; import org.omegat.filters2.TranslationException; @@ -58,8 +60,12 @@ public List<LegacyTM> getMemory() { return null; } + + public TransEntry getTranslation(SourceTextEntry ste) { + return null; + } - public Map<String, TransEntry> getTranslations() { + public Set<Entry<String, TransEntry>> getTranslationsSet() { return null; } Modified: trunk/src/org/omegat/core/data/RealProject.java =================================================================== --- trunk/src/org/omegat/core/data/RealProject.java 2009-11-12 07:06:13 UTC (rev 2512) +++ trunk/src/org/omegat/core/data/RealProject.java 2009-11-12 07:17:10 UTC (rev 2513) @@ -39,6 +39,7 @@ import java.util.Map; import java.util.Set; import java.util.TreeMap; +import java.util.Map.Entry; import java.util.logging.Logger; import org.omegat.core.Core; @@ -753,9 +754,13 @@ /** * {@inheritDoc} */ - public Map<String, TransEntry> getTranslations() { - return Collections.unmodifiableMap(translations); + public Set<Entry<String, TransEntry>> getTranslationsSet() { + return Collections.unmodifiableSet(translations.entrySet()); } + + public TransEntry getTranslation(SourceTextEntry ste) { + return translations.get(ste.getSrcText()); + } /** * Returns the active Project's Properties. Modified: trunk/src/org/omegat/core/data/SourceTextEntry.java =================================================================== --- trunk/src/org/omegat/core/data/SourceTextEntry.java 2009-11-12 07:06:13 UTC (rev 2512) +++ trunk/src/org/omegat/core/data/SourceTextEntry.java 2009-11-12 07:17:10 UTC (rev 2513) @@ -87,7 +87,7 @@ public String getTranslation() { // TODO: move outside - TransEntry tr = Core.getProject().getTranslations().get(src); + TransEntry tr = Core.getProject().getTranslation(this); return tr != null ? tr.translation : ""; } @@ -98,7 +98,7 @@ public boolean isTranslated() { // TODO: move outside - TransEntry tr = Core.getProject().getTranslations().get(src); + TransEntry tr = Core.getProject().getTranslation(this); return tr != null; } Modified: trunk/src/org/omegat/core/statistics/CalcStandardStatistics.java =================================================================== --- trunk/src/org/omegat/core/statistics/CalcStandardStatistics.java 2009-11-12 07:06:13 UTC (rev 2512) +++ trunk/src/org/omegat/core/statistics/CalcStandardStatistics.java 2009-11-12 07:17:10 UTC (rev 2513) @@ -134,7 +134,7 @@ total.charsWithSpaces += chars; // add to remaining - TransEntry tr = project.getTranslations().get(src); + TransEntry tr = project.getTranslation(ste); if (tr == null) { remaining.segments++; remaining.words += words; @@ -173,7 +173,7 @@ } else { uniqueSegment.put(src, count + 1); } - TransEntry tr = project.getTranslations().get(src); + TransEntry tr = project.getTranslation(ste); if (tr != null) { translated.add(src); } Modified: trunk/src/org/omegat/gui/matches/FindMatchesThread.java =================================================================== --- trunk/src/org/omegat/gui/matches/FindMatchesThread.java 2009-11-12 07:06:13 UTC (rev 2512) +++ trunk/src/org/omegat/gui/matches/FindMatchesThread.java 2009-11-12 07:17:10 UTC (rev 2513) @@ -28,6 +28,7 @@ import java.util.ArrayList; import java.util.List; import java.util.Map; +import java.util.Set; import java.util.logging.Level; import java.util.logging.Logger; @@ -97,7 +98,8 @@ @Override public void run() { final List<SourceTextEntry> entries = Core.getProject().getAllEntries(); - Map<String, TransEntry> translations = Core.getProject().getTranslations(); + Set<Map.Entry<String, TransEntry>> translations = Core.getProject() + .getTranslationsSet(); Map<String, TransEntry> orphaned = Core.getProject() .getOrphanedSegments(); Map<String, List<TransMemory>> memories = Core.getProject() @@ -128,7 +130,7 @@ strTokensAll = Core.getTokenizer().tokenizeAllExactly(processedEntry.getSrcText());// HP: includes non-word tokens // travel by project entries - for (Map.Entry<String, TransEntry> en : translations.entrySet()) { + for (Map.Entry<String, TransEntry> en : translations) { if (needStop()) { return; } Modified: trunk/src/org/omegat/gui/tagvalidation/TagValidationFrame.java =================================================================== --- trunk/src/org/omegat/gui/tagvalidation/TagValidationFrame.java 2009-11-12 07:06:13 UTC (rev 2512) +++ trunk/src/org/omegat/gui/tagvalidation/TagValidationFrame.java 2009-11-12 07:17:10 UTC (rev 2513) @@ -235,7 +235,7 @@ for (SourceTextEntry ste : stringList) { String src = ste.getSrcText(); - TransEntry trans = Core.getProject().getTranslations().get(src); + TransEntry trans = Core.getProject().getTranslation(ste); if (src.length() > 0 && trans != null) { int entryNum = ste.entryNum() + 1; output.append("<tr>"); // NOI18N Modified: trunk/src/org/omegat/gui/tagvalidation/TagValidationTool.java =================================================================== --- trunk/src/org/omegat/gui/tagvalidation/TagValidationTool.java 2009-11-12 07:06:13 UTC (rev 2512) +++ trunk/src/org/omegat/gui/tagvalidation/TagValidationTool.java 2009-11-12 07:17:10 UTC (rev 2513) @@ -110,7 +110,7 @@ for (SourceTextEntry ste : Core.getProject().getAllEntries()) { s = ste.getSrcText(); - te = Core.getProject().getTranslations().get(s); + te = Core.getProject().getTranslation(ste); // if there's no translation, skip the string // bugfix for http://sourceforge.net/support/tracker.php?aid=1209839 This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <al...@us...> - 2009-11-12 07:19:59
|
Revision: 2514 http://omegat.svn.sourceforge.net/omegat/?rev=2514&view=rev Author: alex73 Date: 2009-11-12 07:19:48 +0000 (Thu, 12 Nov 2009) Log Message: ----------- Project memory storage refactoring: move translation choose into project core Modified Paths: -------------- trunk/src/org/omegat/core/data/SourceTextEntry.java trunk/src/org/omegat/gui/editor/EditorController.java trunk/src/org/omegat/gui/main/MainWindowMenuHandler.java Modified: trunk/src/org/omegat/core/data/SourceTextEntry.java =================================================================== --- trunk/src/org/omegat/core/data/SourceTextEntry.java 2009-11-12 07:17:10 UTC (rev 2513) +++ trunk/src/org/omegat/core/data/SourceTextEntry.java 2009-11-12 07:19:48 UTC (rev 2514) @@ -91,17 +91,6 @@ return tr != null ? tr.translation : ""; } - /** - * Returns whether this entry is translated - * (shortcut for <code>getStrEntry().isTranslated(t)</code>). - */ - public boolean isTranslated() - { - // TODO: move outside - TransEntry tr = Core.getProject().getTranslation(this); - return tr != null; - } - /** Returns the number of this entry is a project. */ public int entryNum() { Modified: trunk/src/org/omegat/gui/editor/EditorController.java =================================================================== --- trunk/src/org/omegat/gui/editor/EditorController.java 2009-11-12 07:17:10 UTC (rev 2513) +++ trunk/src/org/omegat/gui/editor/EditorController.java 2009-11-12 07:19:48 UTC (rev 2514) @@ -575,9 +575,11 @@ .get(displayedFileIndex); int translatedInFile = 0; for (int i = 0; i < fi.size; i++) { - if (project.getAllEntries().get(i + fi.firstEntryIndexInGlobalList) - .isTranslated()) + SourceTextEntry ste = project.getAllEntries().get( + i + fi.firstEntryIndexInGlobalList); + if (project.getTranslation(ste) != null) { translatedInFile++; + } } StatisticsInfo stat = project.getStatistics(); Modified: trunk/src/org/omegat/gui/main/MainWindowMenuHandler.java =================================================================== --- trunk/src/org/omegat/gui/main/MainWindowMenuHandler.java 2009-11-12 07:17:10 UTC (rev 2513) +++ trunk/src/org/omegat/gui/main/MainWindowMenuHandler.java 2009-11-12 07:19:48 UTC (rev 2514) @@ -32,6 +32,7 @@ import javax.swing.JOptionPane; import org.omegat.core.Core; +import org.omegat.core.data.SourceTextEntry; import org.omegat.core.spellchecker.ISpellChecker; import org.omegat.filters2.master.FilterMaster; import org.omegat.gui.dialogs.AboutDialog; @@ -254,7 +255,8 @@ String selection = Core.getEditor().getSelectedText(); if (selection == null) { - if ( Core.getEditor().getCurrentEntry().isTranslated() ) + SourceTextEntry ste = Core.getEditor().getCurrentEntry(); + if (Core.getProject().getTranslation(ste) != null) selection = Core.getEditor().getCurrentEntry().getTranslation(); else selection = Core.getEditor().getCurrentEntry().getSrcText(); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <al...@us...> - 2009-11-12 07:33:16
|
Revision: 2515 http://omegat.svn.sourceforge.net/omegat/?rev=2515&view=rev Author: alex73 Date: 2009-11-12 07:33:08 +0000 (Thu, 12 Nov 2009) Log Message: ----------- Project memory storage refactoring: use new storages Modified Paths: -------------- trunk/src/org/omegat/core/data/SourceTextEntry.java trunk/src/org/omegat/core/statistics/Statistics.java trunk/src/org/omegat/core/threads/SearchThread.java trunk/src/org/omegat/gui/editor/EditorController.java trunk/src/org/omegat/gui/editor/SegmentBuilder.java trunk/src/org/omegat/gui/main/MainWindowMenuHandler.java trunk/src/org/omegat/gui/matches/MatchesTextArea.java Modified: trunk/src/org/omegat/core/data/SourceTextEntry.java =================================================================== --- trunk/src/org/omegat/core/data/SourceTextEntry.java 2009-11-12 07:19:48 UTC (rev 2514) +++ trunk/src/org/omegat/core/data/SourceTextEntry.java 2009-11-12 07:33:08 UTC (rev 2515) @@ -80,17 +80,6 @@ return src; } - /** - * Returns the translation - * (shortcut for <code>getStrEntry().getTranslation()</code>). - */ - public String getTranslation() - { - // TODO: move outside - TransEntry tr = Core.getProject().getTranslation(this); - return tr != null ? tr.translation : ""; - } - /** Returns the number of this entry is a project. */ public int entryNum() { Modified: trunk/src/org/omegat/core/statistics/Statistics.java =================================================================== --- trunk/src/org/omegat/core/statistics/Statistics.java 2009-11-12 07:19:48 UTC (rev 2514) +++ trunk/src/org/omegat/core/statistics/Statistics.java 2009-11-12 07:33:08 UTC (rev 2515) @@ -37,6 +37,7 @@ import org.omegat.core.Core; import org.omegat.core.data.SourceTextEntry; +import org.omegat.core.data.TransEntry; import org.omegat.core.data.TransMemory; import org.omegat.core.matching.FuzzyMatcher; import org.omegat.core.matching.ISimilarityCalculator; @@ -44,7 +45,6 @@ import org.omegat.util.Log; import org.omegat.util.OConsts; import org.omegat.util.PatternConsts; -import org.omegat.util.StringUtil; import org.omegat.util.Token; /** @@ -81,7 +81,7 @@ boolean isFirst = alreadyProcessed.add(ste.getSrcText()); - if (!StringUtil.isEmpty(ste.getTranslation())) { + if (Core.getProject().getTranslation(ste) != null) { // segment has translation - should be calculated as // "Exact matched" return PERCENT_EXACT_MATCH; @@ -99,7 +99,8 @@ // source entry continue; } - if (StringUtil.isEmpty(cand.getTranslation())) { + TransEntry te = Core.getProject().getTranslation(cand); + if (te == null) { // target without translation - skip continue; } Modified: trunk/src/org/omegat/core/threads/SearchThread.java =================================================================== --- trunk/src/org/omegat/core/threads/SearchThread.java 2009-11-12 07:19:48 UTC (rev 2514) +++ trunk/src/org/omegat/core/threads/SearchThread.java 2009-11-12 07:33:08 UTC (rev 2515) @@ -293,7 +293,8 @@ // get the source and translation of the next entry SourceTextEntry ste = dataEngine.getAllEntries().get(i); String srcText = ste.getSrcText(); - String locText = ste.getTranslation(); + TransEntry te = Core.getProject().getTranslation(ste); + String locText = te != null ? te.translation : ""; // if the source or translation contain all // search strings, report the hit Modified: trunk/src/org/omegat/gui/editor/EditorController.java =================================================================== --- trunk/src/org/omegat/gui/editor/EditorController.java 2009-11-12 07:19:48 UTC (rev 2514) +++ trunk/src/org/omegat/gui/editor/EditorController.java 2009-11-12 07:33:08 UTC (rev 2515) @@ -52,6 +52,7 @@ import org.omegat.core.CoreEvents; import org.omegat.core.data.IProject; import org.omegat.core.data.SourceTextEntry; +import org.omegat.core.data.TransEntry; import org.omegat.core.events.IEntryEventListener; import org.omegat.core.events.IFontChangedEventListener; import org.omegat.core.events.IProjectEventListener; @@ -559,7 +560,8 @@ */ private void exportCurrentSegment(final SourceTextEntry ste) { String s1 = ste.getSrcText(); - String s2 = ste.getTranslation(); + TransEntry te = Core.getProject().getTranslation(ste); + String s2 = te != null ? te.translation : ""; FileUtil.writeScriptFile(s1, OConsts.SOURCE_EXPORT); // NOI18N FileUtil.writeScriptFile(s2, OConsts.TARGET_EXPORT); // NOI18N @@ -637,19 +639,23 @@ if (newTrans != null) { // segment was active SourceTextEntry entry = m_docSegList[displayedEntryIndex].ste; + + TransEntry oldTE = Core.getProject().getTranslation(entry); + String old_translation = oldTE != null ? oldTE.translation : ""; - String old_translation = entry.getTranslation(); // update memory if (newTrans.equals(entry.getSrcText()) && !Preferences - .isPreference(Preferences.ALLOW_TRANS_EQUAL_TO_SRC)) + .isPreference(Preferences.ALLOW_TRANS_EQUAL_TO_SRC)) { Core.getProject().setTranslation(entry, ""); - else + newTrans = ""; + } else { Core.getProject().setTranslation(entry, newTrans); + } m_docSegList[displayedEntryIndex].createSegmentElement(false); - if (!entry.getTranslation().equals(old_translation)) { + if (!newTrans.equals(old_translation)) { // find all identical strings and redraw them for (int i = 0; i < m_docSegList.length; i++) { @@ -759,8 +765,7 @@ + displayedEntryIndex; SourceTextEntry ste = Core.getProject().getAllEntries().get( globalEntryIndex); - if (ste.getTranslation() == null - || ste.getTranslation().length() == 0) { + if (Core.getProject().getTranslation(ste) == null) { // It's untranslated. break; } Modified: trunk/src/org/omegat/gui/editor/SegmentBuilder.java =================================================================== --- trunk/src/org/omegat/gui/editor/SegmentBuilder.java 2009-11-12 07:19:48 UTC (rev 2514) +++ trunk/src/org/omegat/gui/editor/SegmentBuilder.java 2009-11-12 07:33:08 UTC (rev 2515) @@ -32,7 +32,9 @@ import javax.swing.text.Position; import javax.swing.text.SimpleAttributeSet; +import org.omegat.core.Core; import org.omegat.core.data.SourceTextEntry; +import org.omegat.core.data.TransEntry; import org.omegat.util.OConsts; import org.omegat.util.Preferences; import org.omegat.util.gui.Styles; @@ -115,14 +117,13 @@ offset = doc.getLength(); } - boolean translationExists = ste.getTranslation() != null - && ste.getTranslation().length() > 0; + TransEntry trans = Core.getProject().getTranslation(ste); int beginOffset = offset; if (isActive) { - createActiveSegmentElement(translationExists); + createActiveSegmentElement(trans); } else { - createInactiveSegmentElement(translationExists); + createInactiveSegmentElement(trans); } int endOffset = offset; @@ -157,19 +158,18 @@ /** * Create method for active segment. */ - private void createActiveSegmentElement(boolean translationExists) + private void createActiveSegmentElement(TransEntry trans) throws BadLocationException { addInactiveSegPart(true, ste.getSrcText(), ATTR_SOURCE); String activeText; - if (translationExists) { + if (trans != null) { // translation exist - activeText = ste.getTranslation(); + activeText = trans.translation; if (settings.isAutoSpellChecking()) { // spell it - doc.controller.spellCheckerThread.addForCheck(ste - .getTranslation()); + doc.controller.spellCheckerThread.addForCheck(trans.translation); } } else if (!Preferences .isPreference(Preferences.DONT_INSERT_SOURCE_TEXT)) { @@ -203,23 +203,23 @@ /** * Create method for inactive segment. */ - private void createInactiveSegmentElement(boolean translationExists) + private void createInactiveSegmentElement(TransEntry trans) throws BadLocationException { if (settings.isDisplaySegmentSources()) { addInactiveSegPart(true, ste.getSrcText(), ATTR_SOURCE); } boolean needToCheckSpelling = false; - if (translationExists) { + if (trans!=null) { // translation exist if (settings.isAutoSpellChecking()) { // spell it needToCheckSpelling = true; - doc.controller.spellCheckerThread.addForCheck(ste - .getTranslation()); + doc.controller.spellCheckerThread + .addForCheck(trans.translation); } int prevOffset = offset; - addInactiveSegPart(false, ste.getTranslation(), settings + addInactiveSegPart(false, trans.translation, settings .getTranslatedAttributeSet()); if (needToCheckSpelling) { Modified: trunk/src/org/omegat/gui/main/MainWindowMenuHandler.java =================================================================== --- trunk/src/org/omegat/gui/main/MainWindowMenuHandler.java 2009-11-12 07:19:48 UTC (rev 2514) +++ trunk/src/org/omegat/gui/main/MainWindowMenuHandler.java 2009-11-12 07:33:08 UTC (rev 2515) @@ -33,6 +33,7 @@ import org.omegat.core.Core; import org.omegat.core.data.SourceTextEntry; +import org.omegat.core.data.TransEntry; import org.omegat.core.spellchecker.ISpellChecker; import org.omegat.filters2.master.FilterMaster; import org.omegat.gui.dialogs.AboutDialog; @@ -256,10 +257,12 @@ String selection = Core.getEditor().getSelectedText(); if (selection == null) { SourceTextEntry ste = Core.getEditor().getCurrentEntry(); - if (Core.getProject().getTranslation(ste) != null) - selection = Core.getEditor().getCurrentEntry().getTranslation(); - else - selection = Core.getEditor().getCurrentEntry().getSrcText(); + TransEntry te = Core.getProject().getTranslation(ste); + if (te != null) { + selection = te.translation; + } else { + selection = ste.getSrcText(); + } } FileUtil.writeScriptFile(selection, OConsts.SELECTION_EXPORT); Modified: trunk/src/org/omegat/gui/matches/MatchesTextArea.java =================================================================== --- trunk/src/org/omegat/gui/matches/MatchesTextArea.java 2009-11-12 07:19:48 UTC (rev 2514) +++ trunk/src/org/omegat/gui/matches/MatchesTextArea.java 2009-11-12 07:33:08 UTC (rev 2515) @@ -43,6 +43,7 @@ import org.omegat.core.data.SourceTextEntry; import org.omegat.core.data.StringData; import org.omegat.core.data.StringEntry; +import org.omegat.core.data.TransEntry; import org.omegat.core.events.IEntryEventListener; import org.omegat.core.events.IFontChangedEventListener; import org.omegat.core.events.IProjectEventListener; @@ -199,8 +200,10 @@ String translation = Preferences.getPreferenceDefault(Preferences.BEST_MATCH_EXPLANATORY_TEXT, OStrings .getString("WF_DEFAULT_PREFIX")) + thebest.translation; - SourceTextEntry currentEntry = Core.getEditor().getCurrentEntry(); - if (StringUtil.isEmpty(currentEntry.getTranslation())) { + SourceTextEntry currentEntry = Core.getEditor() + .getCurrentEntry(); + TransEntry te = Core.getProject().getTranslation(currentEntry); + if (te == null) { Core.getEditor().replaceEditText(translation); } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <al...@us...> - 2009-11-13 06:42:15
|
Revision: 2517 http://omegat.svn.sourceforge.net/omegat/?rev=2517&view=rev Author: alex73 Date: 2009-11-13 06:42:04 +0000 (Fri, 13 Nov 2009) Log Message: ----------- Project memory storage refactoring: use new storages Modified Paths: -------------- trunk/src/org/omegat/core/data/RealProject.java trunk/src/org/omegat/core/data/SourceTextEntry.java trunk/src/org/omegat/core/statistics/CalcStandardStatistics.java trunk/src/org/omegat/gui/tagvalidation/TagValidationTool.java Removed Paths: ------------- trunk/src/org/omegat/core/data/ProjectFileData.java Deleted: trunk/src/org/omegat/core/data/ProjectFileData.java =================================================================== --- trunk/src/org/omegat/core/data/ProjectFileData.java 2009-11-13 05:58:55 UTC (rev 2516) +++ trunk/src/org/omegat/core/data/ProjectFileData.java 2009-11-13 06:42:04 UTC (rev 2517) @@ -1,38 +0,0 @@ -/************************************************************************** - OmegaT - Computer Assisted Translation (CAT) tool - with fuzzy matching, translation memory, keyword search, - glossaries, and translation leveraging into updated projects. - - Copyright (C) 2000-2006 Keith Godfrey and Maxym Mykhalchuk - Home page: http://www.omegat.org/ - Support center: http://groups.yahoo.com/group/OmegaT/ - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -**************************************************************************/ - -package org.omegat.core.data; - -/** - * keeps track of specific attributes for project files - * - * @author Keith Godfrey - */ - public class ProjectFileData - { - public String name; - public int firstEntry; - public int lastEntry; - } - Modified: trunk/src/org/omegat/core/data/RealProject.java =================================================================== --- trunk/src/org/omegat/core/data/RealProject.java 2009-11-13 05:58:55 UTC (rev 2516) +++ trunk/src/org/omegat/core/data/RealProject.java 2009-11-13 06:42:04 UTC (rev 2517) @@ -86,9 +86,8 @@ private boolean m_modifiedFlag; - /** List of all segments in project. - * @deprecated */ - private List<SourceTextEntry> m_srcTextEntryArray; + /** List of all segments in project. */ + private List<SourceTextEntry> allProjectEntries; private final StatisticsInfo hotStat = new StatisticsInfo(); @@ -128,7 +127,7 @@ * true if project need to be created */ public RealProject(final ProjectProperties props, final boolean isNewProject) { - m_srcTextEntryArray = new ArrayList<SourceTextEntry>(4096); + allProjectEntries = new ArrayList<SourceTextEntry>(4096); m_tmList = new ArrayList<TransMemory>(); m_legacyTMs = new ArrayList<LegacyTM>(); transMemories = new TreeMap<String, List<TransMemory>>(); @@ -141,7 +140,7 @@ loadProject(props); // make required collections unmodifiable - m_srcTextEntryArray = Collections.unmodifiableList(m_srcTextEntryArray); + allProjectEntries = Collections.unmodifiableList(allProjectEntries); m_legacyTMs = Collections.unmodifiableList(m_legacyTMs); m_tmList = Collections.unmodifiableList(m_tmList); } @@ -214,7 +213,7 @@ // but since we didn't, do a bit of cleaning up now, otherwise // we can't even inform the user about our slacking off. context = null; - m_srcTextEntryArray.clear(); + allProjectEntries.clear(); m_legacyTMs.clear(); m_tmList.clear(); transMemories.clear(); @@ -331,8 +330,8 @@ LoadContext context = new LoadContext(); // prepare context data. TODO: remove if not need in future - for (int i = 0; i < m_srcTextEntryArray.size(); i++) { - SourceTextEntry ste = m_srcTextEntryArray.get(i); + for (int i = 0; i < allProjectEntries.size(); i++) { + SourceTextEntry ste = allProjectEntries.get(i); StringEntry se = ste.getStrEntry(); StringEntry hse = context.m_strEntryHash.get(se.getSrcText()); if (hse == null) { @@ -569,26 +568,24 @@ LoadFilesCallback loadFilesCallback = new LoadFilesCallback(context); - ProjectFileData m_curFile = new ProjectFileData(); - m_curFile.name = filename; - m_curFile.firstEntry = m_srcTextEntryArray.size(); + int ffirstEntry = allProjectEntries.size(); FileInfo fi = new FileInfo(); fi.filePath = filepath; - loadFilesCallback.setCurrentFile(m_curFile, fi); + loadFilesCallback.setCurrentFile(fi); boolean fileLoaded = fm.loadFile(filename, processedFiles, loadFilesCallback); - m_curFile.lastEntry = m_srcTextEntryArray.size()-1; + int flastEntry = allProjectEntries.size()-1; - if( fileLoaded && (m_curFile.lastEntry>=m_curFile.firstEntry) ) + if( fileLoaded && (flastEntry>=ffirstEntry) ) { - fi.firstEntryIndex=m_srcTextEntryArray.size(); + fi.firstEntryIndex=allProjectEntries.size(); fi.firstEntryIndexInGlobalList=firstEntry; - fi.size=m_srcTextEntryArray.size()-firstEntry; + fi.size=allProjectEntries.size()-firstEntry; projectFilesList.add(fi); - firstEntry=m_srcTextEntryArray.size(); + firstEntry=allProjectEntries.size(); } } Core.getMainWindow().showStatusMessageRB("CT_LOAD_SRC_COMPLETE"); @@ -748,7 +745,7 @@ * {@inheritDoc} */ public List<SourceTextEntry> getAllEntries() { - return m_srcTextEntryArray; + return allProjectEntries; } /** @@ -825,11 +822,6 @@ private class LoadFilesCallback extends ParseEntry { private final LoadContext context; - /** - * Keeps track of file specific data to feed to SourceTextEntry objects - * so they can have a bigger picture of what's where. - */ - private ProjectFileData m_curFile; private FileInfo fileInfo; private LegacyTM legacyFileTM; private List<TransMemory> tmForFile; @@ -839,8 +831,7 @@ this.context = context; } - protected void setCurrentFile(ProjectFileData file, FileInfo fi) { - m_curFile = file; + protected void setCurrentFile(FileInfo fi) { fileInfo = fi; legacyFileTM = null; tmForFile = null; @@ -886,8 +877,8 @@ strEntry = new StringEntry(srcText); context.m_strEntryHash.put(srcText, strEntry); } - SourceTextEntry srcTextEntry = new SourceTextEntry(strEntry, m_curFile, m_srcTextEntryArray.size()); - m_srcTextEntryArray.add(srcTextEntry); + SourceTextEntry srcTextEntry = new SourceTextEntry(strEntry, allProjectEntries.size()); + allProjectEntries.add(srcTextEntry); fileInfo.entries.add(srcTextEntry); } @@ -908,8 +899,8 @@ } context.m_strEntryHash.put(segmentSource, strEntry); } - SourceTextEntry srcTextEntry = new SourceTextEntry(strEntry, m_curFile, m_srcTextEntryArray.size()); - m_srcTextEntryArray.add(srcTextEntry); + SourceTextEntry srcTextEntry = new SourceTextEntry(strEntry, allProjectEntries.size()); + allProjectEntries.add(srcTextEntry); fileInfo.entries.add(srcTextEntry); } @Override @@ -931,16 +922,12 @@ return; } if (legacyFileTM == null) { - String fn = StaticUtils.makeFilenameRelative(m_curFile.name, - m_config.getSourceRoot()); - legacyFileTM = new LegacyTM(fn, new ArrayList<StringEntry>()); + legacyFileTM = new LegacyTM(fileInfo.filePath, new ArrayList<StringEntry>()); getMemory().add(legacyFileTM); } if (tmForFile == null) { - String fn = StaticUtils.makeFilenameRelative(m_curFile.name, - m_config.getSourceRoot()); tmForFile = new ArrayList<TransMemory>(); - transMemories.put(fn, tmForFile); + transMemories.put(fileInfo.filePath, tmForFile); } StringEntry en = new StringEntry(source); en.setTranslation(translation); Modified: trunk/src/org/omegat/core/data/SourceTextEntry.java =================================================================== --- trunk/src/org/omegat/core/data/SourceTextEntry.java 2009-11-13 05:58:55 UTC (rev 2516) +++ trunk/src/org/omegat/core/data/SourceTextEntry.java 2009-11-13 06:42:04 UTC (rev 2517) @@ -21,13 +21,10 @@ You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -**************************************************************************/ + **************************************************************************/ package org.omegat.core.data; -import org.omegat.core.Core; - - /* * Source text entry represents an individual segment for * translation pulled directly from the input files. @@ -37,57 +34,46 @@ * @author Keith Godfrey * @author Alex Buloichik (ale...@gm...) */ -public class SourceTextEntry -{ +public class SourceTextEntry { /** Source entry text. */ private String src; - /** + /** * Creates a new source text entry. - * - * @param str unique StringEntry that holds source and translation of - * this entry. - * @param file information about the file this entry belongs to. - * @param entryNum the number of this entry in a project. + * + * @param str + * unique StringEntry that holds source and translation of this + * entry. + * @param entryNum + * the number of this entry in a project. */ - public SourceTextEntry(StringEntry str, ProjectFileData file, - int entryNum) - { - m_srcFile = file; + public SourceTextEntry(StringEntry str, int entryNum) { m_strEntry = str; m_entryNum = entryNum; src = str.getSrcText(); } - - /** Returns information about the file this entry belongs to. */ - public ProjectFileData getSrcFile() - { - return m_srcFile; + + /** + * Returns the unique StringEntry that holds source and translation of this + * entry. + */ + public StringEntry getStrEntry() { + return m_strEntry; } - - /** Returns the unique StringEntry that holds source and translation of this entry. */ - public StringEntry getStrEntry() - { - return m_strEntry; - } - - /** - * Returns the source text - * (shortcut for <code>getStrEntry().getSrcText()</code>). + + /** + * Returns the source text (shortcut for + * <code>getStrEntry().getSrcText()</code>). */ - public String getSrcText() - { + public String getSrcText() { return src; } - + /** Returns the number of this entry is a project. */ - public int entryNum() - { + public int entryNum() { return m_entryNum; } - - /** Holds information about the file this entry belongs to. */ - private ProjectFileData m_srcFile; + /** Holds the unique StringEntry of this segment. */ private StringEntry m_strEntry; /** Holds the number of this entry in a project. */ Modified: trunk/src/org/omegat/core/statistics/CalcStandardStatistics.java =================================================================== --- trunk/src/org/omegat/core/statistics/CalcStandardStatistics.java 2009-11-13 05:58:55 UTC (rev 2516) +++ trunk/src/org/omegat/core/statistics/CalcStandardStatistics.java 2009-11-13 06:42:04 UTC (rev 2517) @@ -25,18 +25,19 @@ package org.omegat.core.statistics; import java.io.File; +import java.util.ArrayList; import java.util.HashMap; import java.util.HashSet; import java.util.List; import java.util.Map; import java.util.Set; -import java.util.TreeMap; import org.omegat.core.Core; import org.omegat.core.data.IProject; import org.omegat.core.data.ProjectProperties; import org.omegat.core.data.SourceTextEntry; import org.omegat.core.data.TransEntry; +import org.omegat.core.data.IProject.FileInfo; import org.omegat.core.threads.LongProcessThread; import org.omegat.gui.stat.StatisticsWindow; import org.omegat.util.OConsts; @@ -115,57 +116,53 @@ StatCount unique = new StatCount(); StatCount remainingUnique = new StatCount(); - List<SourceTextEntry> entries = project.getAllEntries(); - - Map<String, FileData> counts = new TreeMap<String, FileData>(); - for (SourceTextEntry ste : entries) { - String src = ste.getSrcText(); - - int words = Statistics.numberOfWords(src); - String noTags = StaticUtils.stripTags(src); - int charsNoSpaces = Statistics - .numberOfCharactersWithoutSpaces(noTags); - int chars = noTags.length(); - - // add to total - total.segments++; - total.words += words; - total.charsWithoutSpaces += charsNoSpaces; - total.charsWithSpaces += chars; - - // add to remaining - TransEntry tr = project.getTranslation(ste); - if (tr == null) { - remaining.segments++; - remaining.words += words; - remaining.charsWithoutSpaces += charsNoSpaces; - remaining.charsWithSpaces += chars; + List<FileData> counts = new ArrayList<FileData>(); + for (FileInfo file : project.getProjectFiles()) { + FileData numbers = new FileData(); + numbers.filename = file.filePath; + counts.add(numbers); + for (SourceTextEntry ste : file.entries) { + String src = ste.getSrcText(); + + int words = Statistics.numberOfWords(src); + String noTags = StaticUtils.stripTags(src); + int charsNoSpaces = Statistics + .numberOfCharactersWithoutSpaces(noTags); + int chars = noTags.length(); + + // add to total + total.segments++; + total.words += words; + total.charsWithoutSpaces += charsNoSpaces; + total.charsWithSpaces += chars; + + // add to remaining + TransEntry tr = project.getTranslation(ste); + if (tr == null) { + remaining.segments++; + remaining.words += words; + remaining.charsWithoutSpaces += charsNoSpaces; + remaining.charsWithSpaces += chars; + } + + // add to file's info + numbers.total.segments++; + numbers.total.words += words; + numbers.total.charsWithoutSpaces += charsNoSpaces; + numbers.total.charsWithSpaces += chars; + if (tr == null) { + numbers.remaining.segments++; + numbers.remaining.words += words; + numbers.remaining.charsWithoutSpaces += charsNoSpaces; + numbers.remaining.charsWithSpaces += chars; + } } - - // add to file's info - FileData numbers = counts.get(ste.getSrcFile().name); - if (numbers == null) { - numbers = new FileData(); - counts.put(ste.getSrcFile().name, numbers); - } - numbers.total.segments++; - numbers.total.words += words; - numbers.total.charsWithoutSpaces += charsNoSpaces; - numbers.total.charsWithSpaces += chars; - if (tr == null) { - numbers.remaining.segments++; - numbers.remaining.words += words; - numbers.remaining.charsWithoutSpaces += charsNoSpaces; - numbers.remaining.charsWithSpaces += chars; - } - } - + } + // find unique segments - Map<String, Integer> uniqueSegment = new HashMap<String, Integer>( - entries.size() / 2); - Set<String> translated = new HashSet<String>( - entries.size() / 2); - for (SourceTextEntry ste : entries) { + Map<String, Integer> uniqueSegment = new HashMap<String, Integer>(); + Set<String> translated = new HashSet<String>(); + for (SourceTextEntry ste : project.getAllEntries()) { String src = ste.getSrcText(); Integer count = uniqueSegment.get(src); if (count == null) { @@ -219,7 +216,7 @@ hotStat.numberofTranslatedSegments = translated.size(); hotStat.numberOfUniqueSegments = unique.segments; } - + return result.toString(); } @@ -236,15 +233,14 @@ return table; } - protected static String[][] calcFilesTable(final ProjectProperties m_config, - final Map<String, FileData> counts) { + protected static String[][] calcFilesTable( + final ProjectProperties m_config, final List<FileData> counts) { String[][] table = new String[counts.size()][7]; int r = 0; - for (String filename : counts.keySet()) { - FileData numbers = counts.get(filename); - table[r][0] = StaticUtils.makeFilenameRelative(filename, m_config - .getSourceRoot()); + for (FileData numbers : counts) { + table[r][0] = StaticUtils.makeFilenameRelative(numbers.filename, + m_config.getSourceRoot()); table[r][1] = Integer.toString(numbers.total.words); table[r][2] = Integer.toString(numbers.remaining.words); table[r][3] = Integer.toString(numbers.total.charsWithoutSpaces); @@ -258,6 +254,7 @@ } public static class FileData { + public String filename; public StatCount total, remaining; public FileData() { Modified: trunk/src/org/omegat/gui/tagvalidation/TagValidationTool.java =================================================================== --- trunk/src/org/omegat/gui/tagvalidation/TagValidationTool.java 2009-11-13 05:58:55 UTC (rev 2516) +++ trunk/src/org/omegat/gui/tagvalidation/TagValidationTool.java 2009-11-13 06:42:04 UTC (rev 2517) @@ -34,9 +34,9 @@ import org.omegat.core.Core; import org.omegat.core.CoreEvents; -import org.omegat.core.data.ProjectFileData; import org.omegat.core.data.SourceTextEntry; import org.omegat.core.data.TransEntry; +import org.omegat.core.data.IProject.FileInfo; import org.omegat.core.events.IProjectEventListener; import org.omegat.gui.main.MainWindow; import org.omegat.util.OStrings; @@ -108,7 +108,8 @@ // PO validation: pattern to detect printf variables (%s and %n\$s) Pattern printfPattern = PatternConsts.PRINTF_VARS; - for (SourceTextEntry ste : Core.getProject().getAllEntries()) { + for(FileInfo fi:Core.getProject().getProjectFiles()) { + for (SourceTextEntry ste : fi.entries) { s = ste.getSrcText(); te = Core.getProject().getTranslation(ste); @@ -119,8 +120,7 @@ } //Extra checks for PO files: - ProjectFileData sourceFileData = ste.getSrcFile(); - if (sourceFileData.name.endsWith(".po") || sourceFileData.name.endsWith(".pot")) { //TODO: check with source-files settings for PO instead of hardcoded? + if (fi.filePath.endsWith(".po") || fi.filePath.endsWith(".pot")) { //TODO: check with source-files settings for PO instead of hardcoded? // PO printf variables should be equal. // we check this by adding the string "index+typespecifier" of every // found variable to a set. @@ -188,6 +188,7 @@ srcTags.clear(); locTags.clear(); + } } return suspects; } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |