Skip to content

Commit

Permalink
Japanese translation (#76)
Browse files Browse the repository at this point in the history
* Adding pilot Japanese translation

* Adding pilot Japanese translation

* new HPO contains portuguese, fixed code so it does not output error. In Japanese it said the instructions were given in German, probably a copy paste error, fixed

* got rid of leftover German translations using DeepL

---------

Co-authored-by: Leonardo macOS <[email protected]>
  • Loading branch information
pnrobinson and leokim-l authored Jan 8, 2025
1 parent 5cc0aa2 commit f18fe0e
Show file tree
Hide file tree
Showing 28 changed files with 1,105 additions and 26 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>org.monarchinitiative</groupId>
<artifactId>phenopacket2prompt</artifactId>
<version>0.4.6</version>
<version>0.4.7</version>

<name>phenopacket2prompt</name>
<url>https://github.com/monarch-initiative/phenopacket2prompt</url>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.List;
Expand Down Expand Up @@ -49,7 +48,7 @@ public class BatchMineCommand implements Callable<Integer> {


@Override
public Integer call() throws Exception {
public Integer call() {
File inDirectory = new File(input);
if (!inDirectory.isDirectory()) {
throw new PhenolRuntimeException("Could not find directory at " + input);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public class GbtTranslateBatchCommand implements Callable<Integer> {


@Override
public Integer call() throws Exception {
public Integer call() {
File hpJsonFile = new File(hpoJsonPath);
boolean useExactMatching = true;
if (! hpJsonFile.isFile()) {
Expand Down Expand Up @@ -107,6 +107,13 @@ public Integer call() throws Exception {
Utility.writeMissingTranslations(chinese.getMissingTranslations(),
missingTranslationsPath, "chinese.txt");

// Japanese
// Note official two-letter language code for Japanese is JP, but our files have JA
PromptGenerator japanese = utility.japanese();
Utility.outputPromptsInternational(ppktFiles,"ja", japanese);
Utility.writeMissingTranslations(japanese.getMissingTranslations(),
missingTranslationsPath, "japanese.txt");

// output original phenopackets
PpktCopy pcopy = new PpktCopy(new File(outdirname));
for (var file : ppktFiles) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public class GptTranslateCommand implements Callable<Integer> {


@Override
public Integer call() throws Exception {
public Integer call() {
File hpJsonFile = new File(hpoJsonPath);
if (! hpJsonFile.isFile()) {
throw new PhenolRuntimeException("Could not find hp.json at " + hpJsonFile.getAbsolutePath());
Expand Down Expand Up @@ -84,6 +84,11 @@ public Integer call() throws Exception {
PromptGenerator italian = PromptGenerator.italian(internationalMap.get("it"));
prompt = italian.createPrompt(individual);
}
case "jp" -> {
// Note the official code for Japanese is jp, but our files have ja
PromptGenerator japanese = PromptGenerator.japanese(internationalMap.get("ja"));
prompt = japanese.createPrompt(individual);
}
case "tr" -> {
PromptGenerator turkish = PromptGenerator.turkish(internationalMap.get("tr"));
prompt = turkish.createPrompt(individual);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -346,15 +346,21 @@ public Integer call() {
sb.append("German\n");
sb.append(HEADER_LINE);
sb.append(deText);
// ITALIAN
String itText = createPrompts(individualList, utility.italian());
sb.append("Italian\n");
sb.append(HEADER_LINE);
sb.append(itText);
// ITALIAN
// Turkish
String trText = createPrompts(individualList, utility.turkish());
sb.append("Turkish\n");
sb.append(HEADER_LINE);
sb.append(trText);
// Japanese
String jpText = createPrompts(individualList, utility.japanese());
sb.append("Japanese");
sb.append(HEADER_LINE);
sb.append(jpText);
System.out.println(sb);
System.out.println("Wrote to " + outfileName);
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public class TextMineCommand implements Callable<Integer> {


@Override
public Integer call() throws Exception {
public Integer call() {
LOGGER.info("TextMine command, input = {}", input);
File hpoJsonFile = new File(datadir + File.separator + "hp.json");
if (! hpoJsonFile.isFile()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,10 @@ public PromptGenerator chinese() {
return PromptGenerator.chinese(internationalMap.get("zh"));
}

public PromptGenerator japanese() {
return PromptGenerator.japanese(internationalMap.get("ja"));
}

public PromptGenerator czech() {
return PromptGenerator.czech(internationalMap.get("cs"));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public static Optional<String> getLanguage(String annots) {
public HpInternationalOboParser(File file) {
languageToInternationalMap = new HashMap<>();
String pattern = "id: (HP:\\d{7,7})";
Set<String> acronyms = Set.of("cs", "en", "de", "dtp", "it", "es", "fr", "ja", "nl", "nna", "tr", "tw", "zh");
Set<String> acronyms = Set.of("cs", "en", "de", "dtp", "es", "fr", "it", "ja", "nl", "nna", "pt", "tr", "tw", "zh");
for (String acronym : acronyms) {
languageToInternationalMap.put(acronym, new HpInternational(acronym));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
import org.monarchinitiative.phenopacket2prompt.output.impl.english.EnglishPromptGenerator;
import org.monarchinitiative.phenopacket2prompt.output.impl.german.GermanPromptGenerator;
import org.monarchinitiative.phenopacket2prompt.output.impl.german.PpktPhenotypicfeatureGerman;
import org.monarchinitiative.phenopacket2prompt.output.impl.japanese.JapanesePromptGenerator;
import org.monarchinitiative.phenopacket2prompt.output.impl.japanese.PpktPhenotypicfeatureJapanese;
import org.monarchinitiative.phenopacket2prompt.output.impl.spanish.*;
import org.monarchinitiative.phenopacket2prompt.output.impl.dutch.*;
import org.monarchinitiative.phenopacket2prompt.output.impl.italian.*;
Expand Down Expand Up @@ -65,6 +67,11 @@ static PromptGenerator italian(HpInternational international) {
return new ItalianPromptGenerator(pfgen);
}

static PromptGenerator japanese(HpInternational international) {
PpktPhenotypicFeatureGenerator pfgen = new PpktPhenotypicfeatureJapanese(international);
return new JapanesePromptGenerator(pfgen);
}

static PromptGenerator turkish(HpInternational international) {
PpktPhenotypicFeatureGenerator pfgen = new PpktPhenotypicfeatureTurkish(international);
return new TurkishPromptGenerator(pfgen);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public String monthDayOld(int m, int d) {
if (components.isEmpty()) {
return "自出生起";
} else if (components.size() == 1) {
return components.get(0);
return components.getFirst();
} else {
return String.format("%s%s大时", components.get(0), components.get(1));
}
Expand All @@ -70,7 +70,7 @@ public String yearsMonthsDaysOld(int y, int m, int d) {
if (components.isEmpty()) {
return "自出生起";
} else if (components.size() == 1) {
return components.get(0);
return components.getFirst();
} else if (components.size() == 2) {
return String.format("%s%s大时", components.get(0), components.get(1));
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ private String ymd(Iso8601Age iso8601Age) {
if (components.isEmpty()) {
return "刚出生";
} else if (components.size() == 1) {
return components.get(0);
return components.getFirst();
} else if (components.size() == 2) {
return String.format("%s%s大", components.get(0), components.get(1));
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ private String getCommaList(List<String> items) {
String penultimate = items.stream()
.limit(items.size() - 1)
.collect(Collectors.joining(","));
String ultimate = items.get(items.size() - 1);
String ultimate = items.getLast();
return penultimate + "和" + ultimate;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ private String getCommaList(List<String> items) {
String penultimate = items.stream()
.limit(items.size() - 1)
.collect(Collectors.joining(", "));
String ultimate = items.get(items.size() - 1);
String ultimate = items.getLast();
return penultimate + " en " + ultimate;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public String monthDayOld(int m, int d) {
if (components.isEmpty()) {
return "am ersten Lebenstag";
} else if (components.size() == 1) {
return components.get(0);
return components.getFirst();
} else {
return String.format("im Alter von %s und %s", components.get(0), components.get(1));
}
Expand All @@ -70,7 +70,7 @@ public String yearsMonthsDaysOld(int y, int m, int d) {
if (components.isEmpty()) {
return "am ersten Lebenstag";
} else if (components.size() == 1) {
return components.get(0);
return components.getFirst();
} else if (components.size() == 2) {
return String.format("im Alter von %s und %s", components.get(0), components.get(1));
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,7 @@ private String dAlter(Iso8601Age iso8601Age, GrammatikalischesGeschlecht geschle
if (components.isEmpty()) {
ymd = "";
} else if (components.size() == 1) {
ymd = components.get(0);
ymd = components.getFirst();
} else if (components.size() == 2) {
ymd = String.format("%s und %s", components.get(0), components.get(1));
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ private String getCommaList(List<String> items) {
String penultimate = items.stream()
.limit(items.size() - 1)
.collect(Collectors.joining(", "));
String ultimate = items.get(items.size() - 1);
String ultimate = items.getLast();
return penultimate + " und " + ultimate;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ private String ymd(Iso8601Age iso8601Age) {
if (components.isEmpty()) {
return "nel primo giorno di vita";
} else if (components.size() == 1) {
return components.get(0);
return components.getFirst();
} else if (components.size() == 2) {
return String.format("all'età di %s y %s", components.get(0), components.get(1));
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ private String getCommaList(List<String> items) {
String penultimate = items.stream()
.limit(items.size() - 1)
.collect(Collectors.joining(", "));
String ultimate = items.get(items.size() - 1);
String ultimate = items.getLast();
return penultimate + getConnector(ultimate) + ultimate;
}

Expand Down
Loading

0 comments on commit f18fe0e

Please sign in to comment.