Skip to content

Commit

Permalink
Updated for release 4.21.0
Browse files Browse the repository at this point in the history
  • Loading branch information
rmraya committed Jul 25, 2022
1 parent ca42e96 commit b7527dd
Show file tree
Hide file tree
Showing 5 changed files with 83 additions and 41 deletions.
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.20.0",
"version": "4.21.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": "^19.0.8",
"electron": "^19.0.9",
"typescript": "^4.7.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.20.0";
public static final String BUILD = "20220714_1219";
public static final String VERSION = "4.21.0";
public static final String BUILD = "20220725_0908";

public static final String REASON = "reason";
public static final String STATUS = "status";
Expand Down
3 changes: 2 additions & 1 deletion src/com/maxprograms/swordfish/am/MatchAssembler.java
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,8 @@ public static Match assembleMatch(String textOnly, List<Match> tmMatches, ITmEng
List<Match> res = glossEngine.searchTranslation(term, srcLang, tgtLang, 100, true);
if (!res.isEmpty()) {
Match m = res.get(0);
terms.add(new Term(m.getSource().getText(), m.getTarget().getText()));
terms.add(new Term(m.getSource().getText(), m.getTarget().getText(), srcLang, tgtLang,
glossEngine.getName()));
}
}
}
Expand Down
52 changes: 51 additions & 1 deletion src/com/maxprograms/swordfish/am/Term.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,30 @@

package com.maxprograms.swordfish.am;

import org.json.JSONObject;

public class Term implements Comparable<Term> {

private String source;
private String target;
private String srcLang;
private String tgtLang;
private String origin;

public Term(String source, String target) {
public Term(String source, String target, String srcLang, String tgtLang, String origin) {
this.source = source;
this.target = target;
this.srcLang = srcLang;
this.tgtLang = tgtLang;
this.origin = origin;
}

public Term(JSONObject json) {
this.source = json.getString("source");
this.target = json.getString("target");
this.srcLang = json.getString("srcLang");
this.tgtLang = json.getString("tgtLang");
this.origin = json.getString("origin");
}

@Override
Expand Down Expand Up @@ -54,4 +70,38 @@ public String getSource() {
public String getTarget() {
return target;
}

public String getSrcLang() {
return srcLang;
}

public void setSrcLang(String srcLang) {
this.srcLang = srcLang;
}

public String getTgtLang() {
return tgtLang;
}

public void setTgtLang(String tgtLang) {
this.tgtLang = tgtLang;
}

public void setOrigin(String origin) {
this.origin = origin;
}

public String getOrigin() {
return origin;
}

public JSONObject toJSON() {
JSONObject json = new org.json.JSONObject();
json.put("source", source);
json.put("target", target);
json.put("srcLang", srcLang);
json.put("tgtLang", tgtLang);
json.put("origin", origin);
return json;
}
}
61 changes: 26 additions & 35 deletions src/com/maxprograms/swordfish/xliff/XliffStore.java
Original file line number Diff line number Diff line change
Expand Up @@ -3500,18 +3500,14 @@ public JSONArray getSegmentTerms(JSONObject json)
if (!visited.containsKey(term)) {
visited.put(term, "");
List<Element> res = engine.searchAll(term, srcLang, similarity, caseSensitiveSearches);
for (int j = 0; j < res.size(); j++) {
JSONArray array = parseMatches(res);
for (int h = 0; h < array.length(); h++) {
JSONObject match = array.getJSONObject(h);
Term candidate = new Term(match.getString("source"), match.getString("target"));
if (!terms.contains(candidate)) {
terms.add(candidate);
match.put("origin", glossaryName);
result.put(match);
saveTerm(json.getString("file"), json.getString("unit"), json.getString("segment"),
glossaryName, match.getString("source"), match.getString("target"));
}
List<Term> array = parseMatches(res, glossaryName);
for (int h = 0; h < array.size(); h++) {
Term candidate = array.get(h);
if (!terms.contains(candidate)) {
terms.add(candidate);
result.put(candidate.toJSON());
saveTerm(json.getString("file"), json.getString("unit"), json.getString("segment"),
glossaryName, candidate.getSource(), candidate.getTarget());
}
}
}
Expand All @@ -3523,20 +3519,20 @@ public JSONArray getSegmentTerms(JSONObject json)
}

private JSONArray sortTerms(JSONArray array) {
if (array.length() == 0) {
return array;
}
JSONArray result = new JSONArray();
List<Term> terms = new Vector<>();
Map<Integer, JSONObject> map = new Hashtable<>();
for (int i = 0; i < array.length(); i++) {
JSONObject obj = array.getJSONObject(i);
Term term = new Term(obj.getString("source"), obj.getString("target"));
terms.add(term);
map.put(term.hashCode(), obj);
terms.add(new Term(array.getJSONObject(i)));
}
// sort ignoring term length
Collections.sort(terms, (Term o1, Term o2) -> o1.getSource().compareToIgnoreCase(o2.getSource()));
Iterator<Term> it = terms.iterator();
while (it.hasNext()) {
Term term = it.next();
result.put(map.get(term.hashCode()));
result.put(term.toJSON());
}
return result;
}
Expand Down Expand Up @@ -3575,15 +3571,12 @@ public int getProjectTerms(String glossary)
visited.put(term, "");
List<Element> res = engine.searchAll(term, srcLang, similarity,
caseSensitiveSearches);
for (int j = 0; j < res.size(); j++) {
JSONArray array = parseMatches(res);
for (int h = 0; h < array.length(); h++) {
JSONObject match = array.getJSONObject(h);
match.put("origin", glossaryName);
saveTerm(file, unit, segment, glossaryName, match.getString("source"),
match.getString("target"));
added = true;
}
List<Term> array = parseMatches(res, glossaryName);
for (int h = 0; h < array.size(); h++) {
Term candidate = array.get(h);
saveTerm(file, unit, segment, glossaryName, candidate.getSource(),
candidate.getTarget());
added = true;
}
}
}
Expand Down Expand Up @@ -3624,22 +3617,20 @@ private void saveTerm(String file, String unit, String segment, String origin, S
}
}

private JSONArray parseMatches(List<Element> matches) {
JSONArray result = new JSONArray();
private List<Term> parseMatches(List<Element> matches, String glossaryName) {
List<Term> result = new Vector<>();
for (int i = 0; i < matches.size(); i++) {
Map<String, String> map = new Hashtable<>();
Element element = matches.get(i);
List<Element> tuvs = element.getChildren("tuv");
Element tu = matches.get(i);
List<Element> tuvs = tu.getChildren("tuv");
Iterator<Element> it = tuvs.iterator();
while (it.hasNext()) {
Element tuv = it.next();
map.put(tuv.getAttributeValue("xml:lang"), MemoriesHandler.pureText(tuv.getChild("seg")));
}
if (map.containsKey(tgtLang)) {
JSONObject obj = new JSONObject();
obj.put("source", map.get(srcLang));
obj.put("target", map.get(tgtLang));
result.put(obj);
Term term = new Term(map.get(srcLang), map.get(tgtLang), srcLang, tgtLang, glossaryName);
result.add(term);
}
}
return result;
Expand Down

0 comments on commit b7527dd

Please sign in to comment.