Skip to content

Commit

Permalink
added chinese, compiles and runs, fixes needed
Browse files Browse the repository at this point in the history
  • Loading branch information
leokim-l committed Aug 28, 2024
1 parent f537aa9 commit 951adea
Show file tree
Hide file tree
Showing 10 changed files with 125 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,12 @@ public Integer call() throws Exception {
// ITALIAN
PromptGenerator italian = utility.italian();
Utility.outputPromptsInternational(ppktFiles,"it", italian);

//Turkish
PromptGenerator turkish = utility.turkish();
Utility.outputPromptsInternational(ppktFiles,"tr", turkish);
// chinese
PromptGenerator chinese = utility.chinese();
Utility.outputPromptsInternational(ppktFiles,"zh", chinese);

// output original phenopackets
PpktCopy pcopy = new PpktCopy(new File(outdirname));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,9 @@ public PromptGenerator italian() {
return PromptGenerator.italian(internationalMap.get("it"));
}

public PromptGenerator chinese() {
return PromptGenerator.chinese(internationalMap.get("zh"));
}


public static String getFileName(String phenopacketID, String languageCode) {
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import org.monarchinitiative.phenopacket2prompt.output.impl.italian.*;
import org.monarchinitiative.phenopacket2prompt.output.impl.turkish.PpktPhenotypicfeatureTurkish;
import org.monarchinitiative.phenopacket2prompt.output.impl.turkish.TurkishPromptGenerator;
import org.monarchinitiative.phenopacket2prompt.output.impl.chinese.*;


import java.util.List;
Expand Down Expand Up @@ -67,6 +68,11 @@ static PromptGenerator turkish(HpInternational international) {
return new TurkishPromptGenerator(pfgen);
}

static PromptGenerator chinese(HpInternational international) {
PpktPhenotypicFeatureGenerator pfgen = new PpktPhenotypicfeatureChinese(international);
return new ChinesePromptGenerator(pfgen);
}


/**
* The following structure should work for most other languages, but the function
Expand Down
Empty file.
Original file line number Diff line number Diff line change
Expand Up @@ -323,4 +323,9 @@ public String asLateOnset() {
public String fromIso(Iso8601Age ppktAge) {
return "";
}

@Override
public String duringEmbryonic() {
return "";
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
package org.monarchinitiative.phenopacket2prompt.output.impl.chinese;

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.PPKtIndividualInfoGenerator;
import org.monarchinitiative.phenopacket2prompt.output.PhenopacketTextGenerator;
import org.monarchinitiative.phenopacket2prompt.output.PpktPhenotypicFeatureGenerator;
import org.monarchinitiative.phenopacket2prompt.output.PromptGenerator;

import java.util.List;
import java.util.Map;
import java.util.Set;

public class ChinesePromptGenerator implements PromptGenerator {

private final PPKtIndividualInfoGenerator ppktAgeSexGenerator;

private final PhenopacketTextGenerator ppktTextGenerator;

private final PpktPhenotypicFeatureGenerator ppktPhenotypicFeatureGenerator;



public ChinesePromptGenerator(PpktPhenotypicFeatureGenerator pfgen) {
ppktAgeSexGenerator = new PpktIndividualChinese();
ppktTextGenerator = new PpktTextChinese();
this.ppktPhenotypicFeatureGenerator = pfgen;
}




@Override
public String queryHeader() {
return ppktTextGenerator.GPT_PROMPT_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.atAgeForVignette(page);
String person = switch (psex) {
case MALE -> "er";
case FEMALE -> "sie";
default -> "die betroffene Person";
};
return this.ppktPhenotypicFeatureGenerator.featuresAtEncounter(person, ageString, terms);
}

@Override
public String getVignetteAtOnset(PpktIndividual individual){
String person = switch (individual.getSex()) {
case MALE -> "Er";
case FEMALE -> "Sie";
default -> "Die betroffene Person";
};
return this.ppktPhenotypicFeatureGenerator.featuresAtOnset(person, individual.getPhenotypicFeaturesAtOnset());
}



@Override
public Set<String> getMissingTranslations() {
return this.ppktPhenotypicFeatureGenerator.getMissingTranslations();
}

/**
* The following structure should work for most other languages, but the function
* can be overridden if necessary.
* @param individual The individual for whom we are creating the prompt
* @return the prompt text
*/
@Override
public String createPrompt(PpktIndividual individual) {
String individualInfo = getIndividualInformation(individual);
// For creating the prompt, we first report the onset and the unspecified terms together, and then
String onsetDescription = getVignetteAtOnset(individual);
Map<PhenopacketAge, List<OntologyTerm>> pfMap = individual.extractSpecifiedAgePhenotypicFeatures();
// We then report the rest, one for each specified time
//String onsetFeatures = formatFeatures(onsetTerms);
StringBuilder sb = new StringBuilder();
sb.append(queryHeader());
sb.append(individualInfo).append("\n").append(onsetDescription).append("\n");
for (var entry: pfMap.entrySet()) {
String vignette = getVignetteAtAge(entry.getKey(), individual.getSex(), entry.getValue());
sb.append(vignette).append("\n");
}
return sb.toString();
}



}
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,7 @@ private String dAlter(Iso8601Age iso8601Age, GrammatikalischesGeschlecht geschle
case NEUTRUM -> String.format("%s altes", ymd);
};
*/
return String.format("%s时",ymd)
return String.format("%s时",ymd);
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,15 @@ public class PpktPhenotypicfeatureChinese implements PpktPhenotypicFeatureGenera


public PpktPhenotypicfeatureChinese(HpInternational international) {
german = international;
chinese = international;
missingTranslations = new HashSet<>();
}


private List<String> getTranslations(List<OntologyTerm> ontologyTerms) {
List<String> labels = new ArrayList<>();
for (var term: ontologyTerms) {
Optional<String> opt = german.getLabel(term.getTid());
Optional<String> opt = chinese.getLabel(term.getTid());
if (opt.isPresent()) {
labels.add(opt.get());
} else {
Expand Down

0 comments on commit 951adea

Please sign in to comment.