Skip to content

Commit

Permalink
german translation
Browse files Browse the repository at this point in the history
  • Loading branch information
pnrobinson committed May 11, 2024
1 parent df015bd commit 3134826
Show file tree
Hide file tree
Showing 9 changed files with 659 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ public Integer call() throws Exception {
// output all non-English languages here
PromptGenerator spanish = PromptGenerator.spanish(hpo, internationalMap.get("es"));
outputPromptsInternational(ppktFiles, hpo, "es", spanish);
PromptGenerator german = PromptGenerator.german(hpo, internationalMap.get("de"));
outputPromptsInternational(ppktFiles, hpo, "de", german);
// output file with correct diagnosis list
outputCorrectResults(correctResultList);
return 0;
Expand Down Expand Up @@ -97,7 +99,7 @@ private void outputPromptsInternational(List<File> ppktFiles, Ontology hpo, Stri
PpktIndividual individual = new PpktIndividual(f);
List<PhenopacketDisease> diseaseList = individual.getDiseases();
if (diseaseList.size() != 1) {
System.err.println(String.format("[ERROR] Got %d diseases for %s.\n", diseaseList.size(), individual.getPhenopacketId()));
System.err.printf("[ERROR] Got %d diseases for %s.\n", diseaseList.size(), individual.getPhenopacketId());
continue;
}
PhenopacketDisease pdisease = diseaseList.get(0);
Expand All @@ -123,7 +125,7 @@ private List<CorrectResult> outputPromptsEnglish(List<File> ppktFiles, Ontology
PpktIndividual individual = new PpktIndividual(f);
List<PhenopacketDisease> diseaseList = individual.getDiseases();
if (diseaseList.size() != 1) {
System.err.println(String.format("[ERROR] Got %d diseases for %s.\n", diseaseList.size(), individual.getPhenopacketId()));
System.err.printf("[ERROR] Got %d diseases for %s.\n", diseaseList.size(), individual.getPhenopacketId());
continue;
}
PhenopacketDisease pdisease = diseaseList.get(0);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,10 @@ public Integer call() throws Exception {
PromptGenerator spanish = PromptGenerator.spanish(hpo, internationalMap.get("es"));
prompt = spanish.createPrompt(individual);
System.out.println(prompt);
System.out.println("GERMAN");
PromptGenerator german = PromptGenerator.spanish(hpo, internationalMap.get("de"));
prompt = german.createPrompt(individual);
System.out.println(prompt);

return 0;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public Optional<String> getTranslation(String annots) {
public HpInternationalOboParser(File file) {
languageToInternationalMap = new HashMap<>();
String pattern = "id: (HP:\\d{7,7})";
Set<String> acronyms = Set.of("cs", "en", "es", "fr", "ja", "nl", "nna", "tr", "tw", "zh");
Set<String> acronyms = Set.of("cs", "en", "de", "it", "es", "fr", "ja", "nl", "nna", "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 @@ -7,6 +7,8 @@
import org.monarchinitiative.phenopacket2prompt.model.PhenopacketSex;
import org.monarchinitiative.phenopacket2prompt.model.PpktIndividual;
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.spanish.*;

import java.util.List;
Expand All @@ -33,6 +35,11 @@ static PromptGenerator spanish(Ontology hpo, HpInternational international) {
return new SpanishPromptGenerator(hpo, pfgen);
}

static PromptGenerator german(Ontology hpo, HpInternational international) {
PpktPhenotypicFeatureGenerator pfgen = new PpktPhenotypicfeatureGerman(international);
return new GermanPromptGenerator(hpo, pfgen);
}

/**
* The following structure should work for most other languages, but the function
* can be overridden if necessary.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
package org.monarchinitiative.phenopacket2prompt.output.impl.german;

import org.monarchinitiative.phenol.ontology.data.Ontology;
import org.monarchinitiative.phenopacket2prompt.model.OntologyTerm;
import org.monarchinitiative.phenopacket2prompt.model.PhenopacketAge;
import org.monarchinitiative.phenopacket2prompt.model.PhenopacketSex;
import org.monarchinitiative.phenopacket2prompt.model.PpktIndividual;
import org.monarchinitiative.phenopacket2prompt.output.PhenopacketIndividualInformationGenerator;
import org.monarchinitiative.phenopacket2prompt.output.PhenopacketTextGenerator;
import org.monarchinitiative.phenopacket2prompt.output.PpktPhenotypicFeatureGenerator;
import org.monarchinitiative.phenopacket2prompt.output.PromptGenerator;

import java.util.List;

public class GermanPromptGenerator implements PromptGenerator {

private final Ontology hpo;


private final PhenopacketIndividualInformationGenerator ppktAgeSexGenerator;

private final PhenopacketTextGenerator ppktTextGenerator;

private final PpktPhenotypicFeatureGenerator ppktPhenotypicFeatureGenerator;



public GermanPromptGenerator(Ontology hpo, PpktPhenotypicFeatureGenerator pfgen) {
this.hpo = hpo;
ppktAgeSexGenerator = new PpktIndividualGerman();
ppktTextGenerator = new PpktTextGerman();
this.ppktPhenotypicFeatureGenerator = pfgen;
}

@Override
public String queryHeader() {
return ppktTextGenerator.QUERY_HEADER();
}

@Override
public String getIndividualInformation(PpktIndividual ppktIndividual) {
return this.ppktAgeSexGenerator.getIndividualDescription(ppktIndividual);
}

@Override
public String formatFeatures(List<OntologyTerm> ontologyTerms) {
return ppktPhenotypicFeatureGenerator.formatFeatures(ontologyTerms);
}

@Override
public String getVignetteAtAge(PhenopacketAge page, PhenopacketSex psex, List<OntologyTerm> terms) {
String ageString = this.ppktAgeSexGenerator.atAge(page);
String features = formatFeatures(terms);
return String.format("%s, %s presentó %s", ageString, ppktAgeSexGenerator.heSheIndividual(psex), features);
}







}
Loading

0 comments on commit 3134826

Please sign in to comment.