Skip to content

Commit

Permalink
Updated for release 4.18.0
Browse files Browse the repository at this point in the history
  • Loading branch information
rmraya committed May 25, 2022
1 parent b92dc79 commit 2818b08
Show file tree
Hide file tree
Showing 10 changed files with 93 additions and 49 deletions.
4 changes: 2 additions & 2 deletions .settings/org.eclipse.jdt.core.prefs
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
org.eclipse.jdt.core.compiler.codegen.targetPlatform=11
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
org.eclipse.jdt.core.compiler.compliance=10
org.eclipse.jdt.core.compiler.compliance=17
org.eclipse.jdt.core.compiler.debug.lineNumber=generate
org.eclipse.jdt.core.compiler.debug.localVariable=generate
org.eclipse.jdt.core.compiler.debug.sourceFile=generate
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures=disabled
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
org.eclipse.jdt.core.compiler.source=11
org.eclipse.jdt.core.compiler.source=17
Binary file modified jars/openxliff.jar
Binary file not shown.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "swordfish",
"productName": "Swordfish",
"version": "4.17.1",
"version": "4.18.0",
"description": "Swordfish Translation Editor",
"main": "js/App.js",
"scripts": {
Expand All @@ -20,7 +20,7 @@
"url": "https://github.com/rmraya/Swordfish.git"
},
"devDependencies": {
"electron": "^18.2.3",
"electron": "^19.0.0",
"typescript": "^4.6.4"
}
}
4 changes: 2 additions & 2 deletions src/com/maxprograms/swordfish/Constants.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ private Constants() {
}

public static final String APPNAME = "Swordfish";
public static final String VERSION = "4.17.1";
public static final String BUILD = "20220512_1726";
public static final String VERSION = "4.18.0";
public static final String BUILD = "20220525_1411";

public static final String REASON = "reason";
public static final String STATUS = "status";
Expand Down
3 changes: 1 addition & 2 deletions src/com/maxprograms/swordfish/models/Memory.java
Original file line number Diff line number Diff line change
Expand Up @@ -158,8 +158,7 @@ public int compareTo(Memory o) {

@Override
public boolean equals(Object obj) {
if (obj instanceof Memory) {
Memory m = (Memory) obj;
if (obj instanceof Memory m) {
return id.equals(m.getId());
}
return false;
Expand Down
3 changes: 1 addition & 2 deletions src/com/maxprograms/swordfish/tm/FuzzyIndex.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,7 @@ NavigableSet<Fun.Tuple2<Integer, String>> getIndex(String lang) throws IOExcepti
if (!maps.containsKey(lang)) {
DB mapdb = null;
try {
mapdb = DBMaker.newFileDB(new File(folder, "index_" + lang)).closeOnJvmShutdown().asyncWriteEnable()
.make();
mapdb = DBMaker.newFileDB(new File(folder, "index_" + lang)).closeOnJvmShutdown().make();
} catch (Error ioe) {
throw new IOException(ioe.getMessage());
}
Expand Down
112 changes: 77 additions & 35 deletions src/com/maxprograms/swordfish/tm/InternalDatabase.java
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ public InternalDatabase(String dbname, String workFolder) throws SQLException, I
if (!exists) {
database.mkdirs();
}
url = "jdbc:h2:" + database.getAbsolutePath() + "/db";
url = "jdbc:h2:" + database.getAbsolutePath() + "/db;DB_CLOSE_ON_EXIT=FALSE";
conn = DriverManager.getConnection(url);

if (!exists) {
Expand Down Expand Up @@ -204,36 +204,46 @@ public void exportMemory(String tmxfile, Set<String> langs, String srcLang) thro
writeString("<body>\n");

try (PreparedStatement stmt = conn.prepareStatement("SELECT lang, seg FROM tuv WHERE tuid=?")) {
Set<Integer> set = tuDb.getKeys();
Iterator<Integer> it = set.iterator();
while (it.hasNext()) {
Element t = tuDb.getTu(it.next());
Element tu = new Element("tu");
tu.clone(t);
String tuid = tu.getAttributeValue("tuid");
stmt.setString(1, tuid);
int count = 0;
try (ResultSet rs = stmt.executeQuery()) {
while (rs.next()) {
String lang = rs.getString(1);
String seg = TMUtils.getString(rs.getNCharacterStream(2));
if (seg.equals("<seg></seg>") || !langs.contains(lang)) {
continue;
}
try (Statement tus = conn.createStatement()) {
try (ResultSet tuKeys = tus.executeQuery("SELECT DISTINCT TUID from TUV")) {
while (tuKeys.next()) {
String tuid = tuKeys.getString(1);
Element tu = new Element("tu");
try {
Element tuv = TMUtils.buildTuv(lang, seg);
tu.addContent(tuv);
count++;
} catch (Exception e) {
logger.log(Level.ERROR, "Error building tuv", e);
logger.log(Level.INFO, "seg: " + seg);
Element t = tuDb.getTu(tuid);
if (t != null) {
tu.clone(t);
} else {
tu.setAttribute("tuid", tuid);
}
} catch (RuntimeException re) {
tu.setAttribute("tuid", tuid);
}
stmt.setString(1, tuid);
int count = 0;
try (ResultSet rs = stmt.executeQuery()) {
while (rs.next()) {
String lang = rs.getString(1);
String seg = TMUtils.getString(rs.getNCharacterStream(2));
if (seg.equals("<seg></seg>") || !langs.contains(lang)) {
continue;
}
try {
Element tuv = TMUtils.buildTuv(lang, seg);
tu.addContent(tuv);
count++;
} catch (Exception e) {
logger.log(Level.ERROR, "Error building tuv", e);
logger.log(Level.INFO, "seg: " + seg);
}
}
}
if (count >= 2) {
Indenter.indent(tu, 2);
writeString(tu.toString() + "\n");
}
}
}
if (count >= 2) {
Indenter.indent(tu, 2);
writeString(tu.toString() + "\n");
}
}
}

Expand Down Expand Up @@ -360,7 +370,17 @@ public List<Match> searchTranslation(String searchStr, String srcLang, String tg
if (tgtFound) {
Element source = TMUtils.buildTuv(srcLang, srcSeg);
Map<String, String> propsMap = new Hashtable<>();
Element tu = getTu(tuid);
Element tu = new Element("tu");
try {
Element t = tuDb.getTu(tuid);
if (t != null) {
tu.clone(t);
} else {
tu.setAttribute("tuid", tuid);
}
} catch (RuntimeException re) {
tu.setAttribute("tuid", tuid);
}
List<Element> props = tu.getChildren("prop");
Iterator<Element> pt = props.iterator();
while (pt.hasNext()) {
Expand Down Expand Up @@ -418,9 +438,16 @@ public List<Element> concordanceSearch(String searchStr, String srcLang, int lim
Iterator<String> it = candidates.iterator();
while (it.hasNext()) {
String tuid = it.next();
Element tu = tuDb.getTu(tuid);
if (tu == null) {
throw new IOException("Memory has broken segments");
Element tu = new Element("tu");
try {
Element t = tuDb.getTu(tuid);
if (t != null) {
tu.clone(t);
} else {
tu.setAttribute("tuid", tuid);
}
} catch (RuntimeException re) {
tu.setAttribute("tuid", tuid);
}
stmt2.setString(1, tuid);
try (ResultSet rs2 = stmt2.executeQuery()) {
Expand Down Expand Up @@ -595,10 +622,15 @@ public void setCreationDate(String date) {
@Override
public Element getTu(String tuid) throws SQLException, SAXException, IOException, ParserConfigurationException {
Element tu = tuDb.getTu(tuid);
if (tu == null) {
tu = new Element("tu");
try {
Element t = tuDb.getTu(tuid);
if (t != null) {
tu.clone(t);
} else {
tu.setAttribute("tuid", tuid);
}
} catch (RuntimeException re) {
tu.setAttribute("tuid", tuid);
logger.log(Level.WARNING, "tu is null for tuid " + tuid); // TODO repair TU
}
try (PreparedStatement stmt = conn.prepareStatement("SELECT lang, seg FROM tuv WHERE tuid=?")) {
stmt.setString(1, tuid);
Expand Down Expand Up @@ -698,7 +730,17 @@ public List<Element> searchAll(String searchStr, String srcLang, int similarity,
distance = MatchQuality.similarity(searchStr.toLowerCase(), pure.toLowerCase());
}
if (distance >= similarity) {
Element tu = getTu(tuid);
Element tu = new Element("tu");
try {
Element t = tuDb.getTu(tuid);
if (t != null) {
tu.clone(t);
} else {
tu.setAttribute("tuid", tuid);
}
} catch (RuntimeException re) {
tu.setAttribute("tuid", tuid);
}
result.add(tu);
}
}
Expand Down
8 changes: 6 additions & 2 deletions src/com/maxprograms/swordfish/tm/TU.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

package com.maxprograms.swordfish.tm;

import java.io.Serializable;
import java.util.Collections;
import java.util.HashSet;
import java.util.Hashtable;
Expand All @@ -20,12 +21,15 @@
import java.util.Set;
import java.util.Vector;

public class TU {
public class TU implements Serializable {

private static final long serialVersionUID = 8284934106102485235L;

private Set<String> langs;
private Map<String, String> props;
private List<String> notes;
private String creationdate;
Map<String, Tuv> tuvs;
private Map<String, Tuv> tuvs;

public TU() {
langs = Collections.synchronizedSet(new HashSet<>());
Expand Down
2 changes: 1 addition & 1 deletion src/com/maxprograms/swordfish/tm/TuDatabase.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public class TuDatabase {
private Set<String> customers;

public TuDatabase(File folder) {
mapdb = DBMaker.newFileDB(new File(folder, "tudata")).closeOnJvmShutdown().asyncWriteEnable().make();
mapdb = DBMaker.newFileDB(new File(folder, "tudata")).closeOnJvmShutdown().make();
tumap = mapdb.getHashMap("tuvmap");
projects = mapdb.getHashSet("projects");
subjects = mapdb.getHashSet("subjects");
Expand Down
2 changes: 1 addition & 1 deletion src/com/maxprograms/swordfish/xliff/XliffStore.java
Original file line number Diff line number Diff line change
Expand Up @@ -963,7 +963,7 @@ public synchronized JSONObject saveSegment(JSONObject json)
result.put("tagErrors", tagErrors);
result.put("spaceErrors", spaceErrors);

if (!memory.equals(Constants.NONE) && !pureTarget.isBlank()) {
if (!memory.equals(Constants.NONE) && !pureTarget.isBlank() && confirm) {
Thread thread = new Thread() {
@Override
public void run() {
Expand Down

0 comments on commit 2818b08

Please sign in to comment.