items) {
if (items.size() == 1) {
- return items.get(0);
+ return items.getFirst();
}
if (items.size() == 2) {
// no comma if we just have two items.
diff --git a/src/main/java/org/monarchinitiative/phenopacket2prompt/output/impl/english/PPKtEnglishBuildingBlocks.java b/src/main/java/org/monarchinitiative/phenopacket2prompt/output/impl/english/PPKtEnglishBuildingBlocks.java
new file mode 100644
index 0000000..a69f7f2
--- /dev/null
+++ b/src/main/java/org/monarchinitiative/phenopacket2prompt/output/impl/english/PPKtEnglishBuildingBlocks.java
@@ -0,0 +1,291 @@
+package org.monarchinitiative.phenopacket2prompt.output.impl.english;
+
+import org.monarchinitiative.phenopacket2prompt.output.PPKtBuildingBlockGenerator;
+
+public class PPKtEnglishBuildingBlocks implements PPKtBuildingBlockGenerator {
+
+
+ @Override
+ public String days(int d) {
+ return d>1 ? "days" : "day";
+ }
+
+ @Override
+ public String months(int m) {
+ return m>1 ? "months" : "month";
+ }
+
+ @Override
+ public String years(int y) {
+ return y>1 ? "years" : "year";
+ }
+
+ @Override
+ public String yearsOld(int y) {
+ return String.format("%d-year-old", y);
+ }
+
+ @Override
+ public String monthsOld(int m) {
+ return String.format("%d-month-old", m);
+ }
+
+ @Override
+ public String daysOld(int d) {
+ return String.format("%d-%s old", d, days(d));
+ }
+
+ @Override
+ public String monthDayOld(int m, int d) {
+ if (m==0) {
+ return daysOld(d);
+ } else if (d==0) {
+ return monthsOld(m);
+ }
+ return String.format("%d-%s, %d-%s old", m, months(m), d, days(d));
+ }
+
+ @Override
+ public String yearsMonthsDaysOld(int y, int m, int d) {
+ if (y==0) {
+ return monthDayOld(m,d);
+ }
+ if (d==0) {
+ return String.format("%d-%s, %d-%s old", y, years(y), m, months(m));
+ }
+ return String.format("%d-%s, %d-%s, %d-%s old", y, years(y), m, months(m), d, days(d));
+ }
+
+ @Override
+ public String asNewborn() {
+ return "as a newborn";
+ }
+
+ @Override
+ public String atTheAgeOf() {
+ return "at the age of";
+ }
+
+
+ @Override
+ public String inFetalPeriod() {
+ return "in the fetal period";
+ }
+
+ @Override
+ public String isCongenital() {
+ return "at birth";
+ }
+
+ @Override
+ public String asInfant() {
+ return "as an infant";
+ }
+
+ @Override
+ public String inChildhood() {
+ return "in childhood";
+ }
+
+ @Override
+ public String asAdolescent() {
+ return "as an adolescent";
+ }
+
+ @Override
+ public String inAdulthoold() {
+ return "in adulthood";
+ }
+
+ @Override
+ public String she() {
+ return "she";
+ }
+
+ @Override
+ public String he() {
+ return "he";
+ }
+
+ @Override
+ public String theProband() {
+ return "the proband";
+ }
+
+ @Override
+ public String woman() {
+ return "woman";
+ }
+
+ @Override
+ public String man() {
+ return "man";
+ }
+
+ @Override
+ public String individual() {
+ return "individual";
+ }
+
+ @Override
+ public String theIndividual() {
+ return "the individual";
+ }
+
+ @Override
+ public String girl() {
+ return "girl";
+ }
+
+ @Override
+ public String boy() {
+ return "boy";
+ }
+
+ @Override
+ public String child() {
+ return "child";
+ }
+
+ @Override
+ public String adolescentGirl() {
+ return "adolescent girl";
+ }
+
+ @Override
+ public String adolescentBoy() {
+ return "adolescent boy";
+ }
+
+ @Override
+ public String adolescentChild() {
+ return "adolescent child";
+ }
+
+ @Override
+ public String maleInfant() {
+ return "male infant";
+ }
+
+ @Override
+ public String femaleInfant() {
+ return "female infant";
+ }
+
+ @Override
+ public String infant() {
+ return "infant";
+ }
+
+ @Override
+ public String newbornBoy() {
+ return "newborn boy";
+ }
+
+ @Override
+ public String newbornGirl() {
+ return "newborn girl";
+ }
+
+ @Override
+ public String newborn() {
+ return "newborn";
+ }
+
+ @Override
+ public String maleFetus() {
+ return "male fetus";
+ }
+
+ @Override
+ public String femaleFetus() {
+ return "female fetus";
+ }
+
+ @Override
+ public String fetus() {
+ return "fetus";
+ }
+
+ @Override
+ public String female() {
+ return "female";
+ }
+
+ @Override
+ public String male() {
+ return "male";
+ }
+
+ @Override
+ public String adult() {
+ return "adult";
+ }
+
+ @Override
+ public String probandWasA() {
+ return "The proband was a";
+ }
+
+ @Override
+ public String whoPresented() {
+ return "who presented";
+ }
+
+ @Override
+ public String presented() {
+ return "presented";
+ }
+
+ @Override
+ public String probandNoAgePresented() {
+ return "The proband presented";
+ }
+
+ @Override
+ public String probandNoAgePresentedWith() {
+ return "The proband presented with";
+ }
+
+ @Override
+ public String probandMaleNoAgePresentedWith() {
+ return "The proband was a male who presented with";
+ }
+
+ @Override
+ public String probandFemaleNoAgePresentedWith() {
+ return "The proband was a female who presented with";
+ }
+
+ @Override
+ public String presentedWith() {
+ return "presented with";
+ }
+
+ @Override
+ public String with() {
+ return "with";
+ }
+
+ @Override
+ public String probandFemaleNoAgeExcludedOnly() {
+ return "The proband was a female in whom the following clinical manifestations were excluded";
+ }
+
+ @Override
+ public String probandMaleNoAgeExcludedOnly() {
+ return "The proband was a male in whom the following clinical manifestations were excluded";
+ }
+
+ @Override
+ public String probandNoAgeExcludedOnly() {
+ return "The proband was a person in whom the following clinical manifestations were excluded";
+ }
+
+ @Override
+ public String inWhomManifestationsWereExcluded() {
+ return "in whom the following clinical manifestations were excluded";
+ }
+
+
+}
diff --git a/src/main/java/org/monarchinitiative/phenopacket2prompt/output/impl/english/PpktIndividualEnglish.java b/src/main/java/org/monarchinitiative/phenopacket2prompt/output/impl/english/PpktIndividualEnglish.java
index 03f7214..67c7f7b 100644
--- a/src/main/java/org/monarchinitiative/phenopacket2prompt/output/impl/english/PpktIndividualEnglish.java
+++ b/src/main/java/org/monarchinitiative/phenopacket2prompt/output/impl/english/PpktIndividualEnglish.java
@@ -2,16 +2,36 @@
import org.monarchinitiative.phenol.base.PhenolRuntimeException;
import org.monarchinitiative.phenopacket2prompt.model.*;
+import org.monarchinitiative.phenopacket2prompt.output.PPKtBuildingBlockGenerator;
import org.monarchinitiative.phenopacket2prompt.output.PPKtIndividualInfoGenerator;
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
+import java.util.Set;
+
+/**
+ * This class produces the very first sentence of the prompt, e.g.,
+ *
+ * "The proband was a 22-year-old woman who presented at the age of 13 years with ..."
+ *
+ *
+ * There are eight possible cases to take into account, depending on whether we have the age of onset and
+ * the age at last presentation (this makes 2^2=4 cases), and whether there are observed HPO terms at onset,
+ * which influences whether we can write "who presented with" or
+ * "in whom the "following clinical manifestations were excluded".
+ *
+ *
+ * The entry point to the generation of this sentence is the function {@code #getIndividualDescription}.
+ *
+ */
public class PpktIndividualEnglish implements PPKtIndividualInfoGenerator {
- public PpktIndividualEnglish() {
+ private final PPKtBuildingBlockGenerator buildBlocks;
+ public PpktIndividualEnglish() {
+ buildBlocks = new PPKtEnglishBuildingBlocks();
}
@@ -19,53 +39,42 @@ public String getIndividualDescription(PpktIndividual individual) {
if (individual.annotationCount() == 0) {
throw new PhenolRuntimeException("No HPO annotations");
}
+ boolean hasObservedHPO = individual.hasObservedPhenotypeFeatureAtOnset();
Optional lastExamOpt = individual.getAgeAtLastExamination();
Optional onsetOpt = individual.getAgeAtOnset();
PhenopacketSex psex = individual.getSex();
if (lastExamOpt.isPresent() && onsetOpt.isPresent()) {
- return onsetAndLastEncounterAvailable(psex, lastExamOpt.get(), onsetOpt.get());
+ return onsetAndLastEncounterAvailable(psex, lastExamOpt.get(), onsetOpt.get(), hasObservedHPO);
} else if (lastExamOpt.isPresent()) {
- return lastEncounterAvailable(psex, lastExamOpt.get());
+ return lastEncounterAvailable(psex, lastExamOpt.get(), hasObservedHPO);
} else if (onsetOpt.isPresent()) {
- return onsetAvailable(psex, onsetOpt.get());
+ return onsetAvailable(psex, onsetOpt.get(), hasObservedHPO);
} else {
- return ageNotAvailable(psex);
+ return ageNotAvailable(psex, hasObservedHPO);
}
}
+
+ /**
+ * NOTE THIS SHOULD BE REMOVED
+ * @param psex
+ * @return
+ */
@Override
public String heSheIndividual(PhenopacketSex psex) {
return switch (psex) {
- case FEMALE -> "she";
- case MALE -> "he";
- default -> "the individual";
+ case FEMALE -> buildBlocks.she();
+ case MALE -> buildBlocks.he();
+ default -> buildBlocks.theIndividual();
};
}
- private String iso8601ToYear(Iso8601Age iso8601Age) {
- return String.format("%d-year old", iso8601Age.getYears());
- }
-
- private String iso8601ToYearMonth(Iso8601Age iso8601Age) {
- if (iso8601Age.getMonths() == 0) {
- return String.format("%d-year old", iso8601Age.getYears());
- } else {
- return String.format("%d-year, %d-month old", iso8601Age.getYears(), iso8601Age.getMonths());
- }
- }
-
+/*
private String iso8601ToMonthDay(Iso8601Age iso8601Age) {
- int m = iso8601Age.getMonths();
- int d = iso8601Age.getDays();
- if (m == 0) {
- return String.format("%d-day old", d);
- } else if (d>0){
- return String.format("%d-month, %d-day old", m, d);
- } else {
- return String.format("%d-month old", m);
- }
+ return buildBlocks.monthDayOld(iso8601Age.getMonths(), iso8601Age.getDays());
}
+ */
/**
* Create a phrase such as "at the age of 7 years, 4 months, and 2 days"
@@ -77,38 +86,35 @@ private String iso8601AtAgeOf(Iso8601Age isoAge) {
List components = new ArrayList<>();
if (isoAge.getYears()>0) {
- String ystring = isoAge.getYears() == 1 ? "year" : "years";
- components.add(String.format("%d %s", isoAge.getYears(), ystring));
+ components.add(buildBlocks.years(isoAge.getYears()));
}
if (isoAge.getMonths() > 0) {
- String mstring = isoAge.getMonths() == 1 ? "month" : "months";
- components.add(String.format("%d %s", isoAge.getMonths(), mstring));
+ components.add(buildBlocks.months(isoAge.getMonths()));
}
if (isoAge.getDays()>0) {
- String dstring = isoAge.getDays() == 1 ? "day" : "days";
- components.add(String.format("%d %s", isoAge.getDays(), dstring));
+ components.add(buildBlocks.months(isoAge.getDays()));
}
if (components.isEmpty()) {
- return "as a newborn";
+ return buildBlocks.asNewborn();
} else if (components.size() == 1) {
- return "at the age of " + components.get(0);
+ return buildBlocks.atTheAgeOf() + " " + components.getFirst();
} else if (components.size() == 2) {
- return "at the age of " + components.get(0) + " and " + components.get(1);
+ return buildBlocks.atTheAgeOf() + " " + components.get(0) + " and " + components.get(1);
} else {
- return "at the age of " + components.get(0) + "m " + components.get(1) +
+ return buildBlocks.atTheAgeOf() + " " + components.get(0) + ", " + components.get(1) +
", and " + components.get(2);
}
}
private String onsetTermAtAgeOf(HpoOnsetAge hpoOnsetTermAge) {
if (hpoOnsetTermAge.isFetus()) {
- return "in the fetal period";
+ return buildBlocks.inFetalPeriod();
} else if (hpoOnsetTermAge.isCongenital()) {
- return "at birth";
+ return buildBlocks.isCongenital();
} else if (hpoOnsetTermAge.isInfant()) {
- return "as an infant";
+ return buildBlocks.asInfant();
} else if (hpoOnsetTermAge.isChild()) {
- return "in childhood";
+ return buildBlocks.inChildhood();
} else if (hpoOnsetTermAge.isJuvenile()) {
return "as an adolescent";
} else if (hpoOnsetTermAge.isNeonate()){
@@ -127,87 +133,110 @@ private String iso8601individualDescription(PhenopacketSex psex, Iso8601Age iso8
int d = iso8601Age.getDays();
// if older
if (y>17) {
+ String age = buildBlocks.yearsOld(y);
return switch (psex) {
- case FEMALE -> String.format("%d-year old woman", y);
- case MALE -> String.format("%d-year old man", y);
- default -> String.format("%d-year old individual", y);
+ case FEMALE -> String.format("%s %s", age, buildBlocks.woman());
+ case MALE -> String.format("%s %s", age, buildBlocks.man());
+ default -> String.format("%s %s", age, buildBlocks.individual());
};
} else if (y>9) {
+ String age = buildBlocks.yearsOld(y);
return switch (psex) {
- case FEMALE -> String.format("%d-year old adolescent female", y);
- case MALE -> String.format("%d-year old adolescent male", y);
- default -> String.format("%d-year old adolescent", y);
+ case FEMALE -> String.format("%s %s", age, buildBlocks.adolescentGirl());
+ case MALE -> String.format("%s %s", age, buildBlocks.adolescentBoy());
+ default -> String.format("%s %s", age, buildBlocks.adolescentChild());
};
} else if (y>0) {
+ String age = buildBlocks.yearsMonthsDaysOld(y, m, d);
return switch (psex) {
- case FEMALE -> String.format("%s girl", iso8601ToYearMonth(iso8601Age));
- case MALE -> String.format("%s boy", iso8601ToYearMonth(iso8601Age));
- default -> String.format("%s child", iso8601ToYearMonth(iso8601Age));
+ case FEMALE -> String.format("%s %s", age, buildBlocks.girl());
+ case MALE -> String.format("%s %s", age, buildBlocks.boy());
+ default -> String.format("%s %s", age, buildBlocks.child());
};
} else if (m>0 || d> 0) {
+ String age = buildBlocks.monthDayOld(m, d);
return switch (psex) {
- case FEMALE -> String.format("%s female infant", iso8601ToMonthDay(iso8601Age));
- case MALE -> String.format("%s male infant", iso8601ToMonthDay(iso8601Age));
- default -> String.format("%s infant", iso8601ToMonthDay(iso8601Age));
+ case FEMALE -> String.format("%s %s", age, buildBlocks.femaleInfant());
+ case MALE -> String.format("%s %s", age, buildBlocks.maleInfant());
+ default -> String.format("%s %s", age, buildBlocks.infant());
};
} else {
return switch (psex) {
- case FEMALE -> "newborn girl";
- case MALE -> "newborn boy";
- default -> "newborn";
+ case FEMALE -> buildBlocks.newbornGirl();
+ case MALE -> buildBlocks.newbornBoy();
+ default -> buildBlocks.newborn();
};
}
}
+
+ private String iso8601individualDescriptionAsA(PhenopacketSex psex, Iso8601Age iAge){
+ String onsetWithSex = iso8601individualDescription(psex, iAge);
+ return String.format("as a %s", onsetWithSex);
+ }
+
+ private String hpoOnsetAsA(PhenopacketSex psex, HpoOnsetAge hpoOnsetTermAge){
+ String onsetWithSex = hpoOnsetIndividualDescription(psex, hpoOnsetTermAge);
+ final Set vowels = Set.of('A', 'E', 'I', 'O', 'U');
+ if (vowels.contains(onsetWithSex.charAt(0))) {
+ return String.format("as an %s", onsetWithSex);
+ } else {
+ return String.format("as a %s", onsetWithSex);
+ }
+ }
+
private String hpoOnsetIndividualDescription(PhenopacketSex psex, HpoOnsetAge hpoOnsetTermAge) {
if (hpoOnsetTermAge.isFetus()) {
return switch (psex) {
- case FEMALE -> "female fetus";
- case MALE -> "male fetus";
- default -> "fetus";
+ case FEMALE -> buildBlocks.femaleFetus();
+ case MALE -> buildBlocks.maleFetus();
+ default -> buildBlocks.fetus();
};
} else if (hpoOnsetTermAge.isCongenital()) {
return switch (psex) {
- case FEMALE -> "female newborn";
- case MALE -> "male newborn";
- default -> "newborn";
+ case FEMALE -> buildBlocks.newbornGirl();
+ case MALE -> buildBlocks.newbornBoy();
+ default -> buildBlocks.newborn();
};
} else if (hpoOnsetTermAge.isInfant()) {
return switch (psex) {
- case FEMALE -> "female infant";
- case MALE -> "male infant";
- default -> "infant";
+ case FEMALE -> buildBlocks.femaleInfant();
+ case MALE -> buildBlocks.maleInfant();
+ default -> buildBlocks.infant();
};
} else if (hpoOnsetTermAge.isChild()) {
return switch (psex) {
- case FEMALE -> "girl";
- case MALE -> "boy";
- default -> "child";
+ case FEMALE -> buildBlocks.girl();
+ case MALE -> buildBlocks.boy();
+ default -> buildBlocks.child();
};
} else if (hpoOnsetTermAge.isJuvenile()) {
return switch (psex) {
- case FEMALE -> "female adolescent";
- case MALE -> "male adolescent";
- default -> "adolescent";
+ case FEMALE -> buildBlocks.adolescentGirl();
+ case MALE -> buildBlocks.adolescentBoy();
+ default -> buildBlocks.adolescentChild();
};
}else {
return switch (psex) {
- case FEMALE -> "woman";
- case MALE -> "man";
- default -> "adult";
+ case FEMALE -> buildBlocks.woman();
+ case MALE -> buildBlocks.male();
+ default -> buildBlocks.adult();
};
}
}
/**
- * A sentence such as The proband was a 39-year old woman who presented at the age of 12 years with
+ * A sentence such as The proband was a 39-year-old woman who presented at the age of 12 years with
* HPO1, HPO2, and HPO3. HPO4 and HPO5 were excluded. This method returns the phrase that ends with "with"
* @param psex
* @param lastExamAge
* @param onsetAge
* @return
*/
- private String onsetAndLastEncounterAvailable(PhenopacketSex psex, PhenopacketAge lastExamAge, PhenopacketAge onsetAge) {
+ private String onsetAndLastEncounterAvailable(PhenopacketSex psex,
+ PhenopacketAge lastExamAge,
+ PhenopacketAge onsetAge,
+ boolean hasObservedHPO) {
String individualDescription;
String onsetDescription;
if (lastExamAge.ageType().equals(PhenopacketAgeType.ISO8601_AGE_TYPE)) {
@@ -215,7 +244,7 @@ private String onsetAndLastEncounterAvailable(PhenopacketSex psex, PhenopacketAg
individualDescription = iso8601individualDescription(psex, isoAge);
} else if (lastExamAge.ageType().equals(PhenopacketAgeType.HPO_ONSET_AGE_TYPE)) {
HpoOnsetAge hpoOnsetTermAge = (HpoOnsetAge) lastExamAge;
- individualDescription = hpoOnsetIndividualDescription(psex,hpoOnsetTermAge);
+ individualDescription = hpoOnsetAsA(psex,hpoOnsetTermAge);
} else {
// should never happen
throw new PhenolRuntimeException("Did not recognize last exam age type " + lastExamAge.ageType());
@@ -230,17 +259,31 @@ private String onsetAndLastEncounterAvailable(PhenopacketSex psex, PhenopacketAg
// should never happen
throw new PhenolRuntimeException("Did not recognize onset age type " + onsetAge.ageType());
}
- return String.format("The proband was a %s who presented %s with", individualDescription, onsetDescription);
+ if (hasObservedHPO) {
+ return String.format("%s %s who presented %s with",
+ buildBlocks.probandWasA(),
+ individualDescription,
+ onsetDescription);
+ } else {
+ // i.e., we only have excluded HPO terms at onset
+ return String.format("%s %s %s %s:",
+ buildBlocks.probandWasA(),
+ individualDescription,
+ buildBlocks.inWhomManifestationsWereExcluded(),
+ onsetDescription);
+ }
}
/**
* Age at last examination available but age of onset not available
- * The proband was a 39-year old woman who presented with HPO1, HPO2, and HPO3. HPO4 and HPO5 were excluded.
+ * The proband was a 39-year-old woman who presented with HPO1, HPO2, and HPO3. HPO4 and HPO5 were excluded.
* @param psex
* @param lastExamAge
*/
- private String lastEncounterAvailable(PhenopacketSex psex, PhenopacketAge lastExamAge) {
+ private String lastEncounterAvailable(PhenopacketSex psex,
+ PhenopacketAge lastExamAge,
+ boolean hasObservedHPO) {
String individualDescription;
if (lastExamAge.ageType().equals(PhenopacketAgeType.ISO8601_AGE_TYPE)) {
Iso8601Age isoAge = (Iso8601Age) lastExamAge;
@@ -252,39 +295,80 @@ private String lastEncounterAvailable(PhenopacketSex psex, PhenopacketAge lastEx
// should never happen
throw new PhenolRuntimeException("Did not recognize last exam age type " + lastExamAge.ageType());
}
- return String.format("The proband was a %s who presented with", individualDescription);
+ if (hasObservedHPO) {
+ return String.format("%s %s %s",
+ buildBlocks.probandWasA(),
+ individualDescription,
+ buildBlocks.whoPresented());
+ } else {
+ return String.format("%s %s %s",
+ buildBlocks.probandWasA(),
+ individualDescription,
+ buildBlocks.inWhomManifestationsWereExcluded());
+ }
}
/**
* Age at last examination not available but age of onset available
* The proband presented at the age of 12 years with HPO1, HPO2, and HPO3. HPO4 and HPO5 were excluded.
- * @param psex
- * @param onsetAge
+ * @param psex sex of the proband
+ * @param onsetAge age at onset of disease
+ * @param hasObservedHPO whether the proband has HPO annotations for the onset of disease
* @return
*/
- private String onsetAvailable(PhenopacketSex psex, PhenopacketAge onsetAge) {
+ private String onsetAvailable(PhenopacketSex psex,
+ PhenopacketAge onsetAge,
+ boolean hasObservedHPO) {
String onsetDescription;
+ String individualDescription;
if (onsetAge.ageType().equals(PhenopacketAgeType.ISO8601_AGE_TYPE)) {
Iso8601Age isoAge = (Iso8601Age) onsetAge;
- onsetDescription = iso8601AtAgeOf(isoAge);
+ individualDescription = iso8601individualDescriptionAsA(psex, isoAge);
} else if (onsetAge.ageType().equals(PhenopacketAgeType.HPO_ONSET_AGE_TYPE)) {
HpoOnsetAge hpoOnsetTermAge = (HpoOnsetAge) onsetAge;
- onsetDescription = onsetTermAtAgeOf(hpoOnsetTermAge);
+ individualDescription = hpoOnsetAsA(psex,hpoOnsetTermAge);
} else {
// should never happen
throw new PhenolRuntimeException("Did not recognize onset age type " + onsetAge.ageType());
}
- return String.format("The proband presented %s with", onsetDescription, onsetDescription);
+ if (hasObservedHPO) {
+ // e.g., "The proband presented in childhood with"
+ return String.format("%s %s %s",
+ buildBlocks.probandNoAgePresented(),
+ individualDescription,
+ buildBlocks.with());
+ } else {
+ return String.format("%s %s %s",
+ buildBlocks.probandNoAgePresented(),
+ individualDescription,
+ buildBlocks.inWhomManifestationsWereExcluded());
+ }
+
}
- private String ageNotAvailable(PhenopacketSex psex) {
- return switch (psex) {
- case FEMALE -> "The proband was a female who presented with";
- case MALE -> "The proband was a male who presented with";
- default -> "The proband presented with";
- };
+ /**
+ * This method is called if we have no information at all about the age of the proband
+ * @param psex Sex of the proband
+ * @return A string such as "The proband was a female who presented with";
+ */
+ private String ageNotAvailable(PhenopacketSex psex,
+ boolean hasObservedHPO) {
+ if (hasObservedHPO) {
+ return switch (psex) {
+ case FEMALE -> buildBlocks.probandFemaleNoAgePresentedWith();
+ case MALE -> buildBlocks.probandMaleNoAgePresentedWith();
+ default -> buildBlocks.probandNoAgePresentedWith();
+ };
+ } else {
+ return switch (psex) {
+ case FEMALE -> buildBlocks.probandFemaleNoAgeExcludedOnly();
+ case MALE -> buildBlocks.probandMaleNoAgeExcludedOnly();
+ default -> buildBlocks.probandNoAgeExcludedOnly();
+ };
+ }
}
+ /*
private String individualName(PpktIndividual individual) {
PhenopacketSex psex = individual.getSex();
Optional ageOpt = individual.getAgeAtLastExamination();
@@ -301,9 +385,9 @@ private String individualName(PpktIndividual individual) {
PhenopacketAge age = ageOpt.get();;
if (age.isChild()) {
return switch (psex) {
- case FEMALE -> "girl";
- case MALE -> "boy";
- default -> "child";
+ case FEMALE -> buildBlocks.girl();
+ case MALE -> buildBlocks.boy();
+ default -> buildBlocks.child();
};
} else if (age.isCongenital()) {
return switch (psex) {
@@ -325,34 +409,16 @@ private String individualName(PpktIndividual individual) {
};
} else {
return switch (psex) {
- case FEMALE -> "woman";
- case MALE -> "man";
- default -> "individual";
+ case FEMALE -> buildBlocks.woman();
+ case MALE -> buildBlocks.man();
+ default -> buildBlocks.inAdulthoold();
};
}
}
+*/
- /* @Override
- public String individualWithAge(PhenopacketAge ppktAge) {
- if (ppktAge.ageType().equals(PhenopacketAgeType.ISO8601_AGE_TYPE)) {
- return ppktAge.age() + " old";
- } else if (ppktAge.ageType().equals(PhenopacketAgeType.HPO_ONSET_AGE_TYPE)) {
- String label = ppktAge.age(); // something like "Infantile onset"
- return switch (label) {
- case "Infantile onset" -> "infant";
- case "Childhood onset" -> "child";
- case "Neonatal onset" -> "neonate";
- case "Congenital onset" -> "born";
- case "Adult onset" -> "adult";
- default-> String.format("During the %s", label.replace(" onset", ""));
- };
- } else {
- return ""; // should never get here
- }
- }*/
-
@Override
public String atAge(PhenopacketAge ppktAge) {
if (ppktAge.ageType().equals(PhenopacketAgeType.ISO8601_AGE_TYPE)) {
diff --git a/src/main/java/org/monarchinitiative/phenopacket2prompt/output/impl/english/PpktPhenotypicFeatureEnglish.java b/src/main/java/org/monarchinitiative/phenopacket2prompt/output/impl/english/PpktPhenotypicFeatureEnglish.java
index 683afbd..1066ad8 100644
--- a/src/main/java/org/monarchinitiative/phenopacket2prompt/output/impl/english/PpktPhenotypicFeatureEnglish.java
+++ b/src/main/java/org/monarchinitiative/phenopacket2prompt/output/impl/english/PpktPhenotypicFeatureEnglish.java
@@ -1,5 +1,6 @@
package org.monarchinitiative.phenopacket2prompt.output.impl.english;
+import org.monarchinitiative.phenol.base.PhenolRuntimeException;
import org.monarchinitiative.phenopacket2prompt.model.OntologyTerm;
import org.monarchinitiative.phenopacket2prompt.output.PpktPhenotypicFeatureGenerator;
@@ -7,6 +8,63 @@
public class PpktPhenotypicFeatureEnglish implements PpktPhenotypicFeatureGenerator {
+ /**
+ * This method is called right after the demographic information are given, e.g.,
+ * The proband was a 32-year-old female who presented at the age of 2 years[...]"
+ * @param ontologyTerms
+ * @return
+ */
+ public String featuresAtPresentation(List ontologyTerms) {
+ List observed = getObservedFeaturesAsStr(ontologyTerms);
+ List excluded = getExcludedFeaturesAsStr(ontologyTerms);
+ if (! observed.isEmpty() && ! excluded.isEmpty()) {
+ return String.format("with %s. In contrast, %s %s excluded. ",
+ getOxfordCommaList(observed),
+ getOxfordCommaList(excluded),
+ excluded.size() > 1 ? "were" : "was");
+
+ } else if (!excluded.isEmpty()) {
+ return String.format(" with %s. ",
+ getOxfordCommaList(observed));
+ } else if (!observed.isEmpty()) {
+ return String.format(". %s %s excluded. ",
+ getOxfordCommaList(excluded),
+ excluded.size() > 1 ? "were" : "was");
+ } else {
+ throw new PhenolRuntimeException("No phenotypic features passed");
+ }
+ }
+
+
+ /**
+ * This method is called right after each subsequent age. For instance,
+ * At the age of 7 years, she[...]"
+ * @param ontologyTerms
+ * @return
+ */
+ public String featuresForVignette(List ontologyTerms) {
+ List observed = getObservedFeaturesAsStr(ontologyTerms);
+ List excluded = getExcludedFeaturesAsStr(ontologyTerms);
+ if (! observed.isEmpty() && ! excluded.isEmpty()) {
+ return String.format(" presented with %s. In contrast, %s %s excluded. ",
+ getOxfordCommaList(observed),
+ getOxfordCommaList(excluded),
+ excluded.size() > 1 ? "were" : "was");
+
+ } else if (!excluded.isEmpty()) {
+ return String.format(" presented with %s. ",
+ getOxfordCommaList(observed));
+ } else if (!observed.isEmpty()) {
+ return String.format(" . %s %s excluded. ",
+ getOxfordCommaList(excluded),
+ excluded.size() > 1 ? "were" : "was");
+ } else {
+ throw new PhenolRuntimeException("No phenotypic features passed");
+ }
+ }
+
+
+
private String getOxfordCommaList(List items) {
if (items.size() == 1) {
diff --git a/src/main/java/org/monarchinitiative/phenopacket2prompt/output/impl/german/GermanPromptGenerator.java b/src/main/java/org/monarchinitiative/phenopacket2prompt/output/impl/german/GermanPromptGenerator.java
index 25c2ace..d80869f 100644
--- a/src/main/java/org/monarchinitiative/phenopacket2prompt/output/impl/german/GermanPromptGenerator.java
+++ b/src/main/java/org/monarchinitiative/phenopacket2prompt/output/impl/german/GermanPromptGenerator.java
@@ -1,6 +1,5 @@
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;
diff --git a/src/main/java/org/monarchinitiative/phenopacket2prompt/output/impl/italian/ItalianPromptGenerator.java b/src/main/java/org/monarchinitiative/phenopacket2prompt/output/impl/italian/ItalianPromptGenerator.java
index 6016570..5842f24 100644
--- a/src/main/java/org/monarchinitiative/phenopacket2prompt/output/impl/italian/ItalianPromptGenerator.java
+++ b/src/main/java/org/monarchinitiative/phenopacket2prompt/output/impl/italian/ItalianPromptGenerator.java
@@ -1,6 +1,5 @@
package org.monarchinitiative.phenopacket2prompt.output.impl.italian;
-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;
diff --git a/src/main/java/org/monarchinitiative/phenopacket2prompt/output/impl/italian/PpktIndividualItalian.java b/src/main/java/org/monarchinitiative/phenopacket2prompt/output/impl/italian/PpktIndividualItalian.java
index c0868b4..7b761d0 100644
--- a/src/main/java/org/monarchinitiative/phenopacket2prompt/output/impl/italian/PpktIndividualItalian.java
+++ b/src/main/java/org/monarchinitiative/phenopacket2prompt/output/impl/italian/PpktIndividualItalian.java
@@ -213,7 +213,7 @@ private String iso8601AtAgeOf(Iso8601Age isoAge) {
if (components.isEmpty()) {
return "nel periodo neonatale";
} else if (components.size() == 1) {
- return "all'età di " + components.get(0);
+ return "all'età di " + components.getFirst();
} else if (components.size() == 2) {
return "all'età di " + components.get(0) + " e " + components.get(1);
} else {
diff --git a/src/main/java/org/monarchinitiative/phenopacket2prompt/output/impl/italian/PpktPhenotypicfeatureItalian.java b/src/main/java/org/monarchinitiative/phenopacket2prompt/output/impl/italian/PpktPhenotypicfeatureItalian.java
index 909a42f..9d81889 100644
--- a/src/main/java/org/monarchinitiative/phenopacket2prompt/output/impl/italian/PpktPhenotypicfeatureItalian.java
+++ b/src/main/java/org/monarchinitiative/phenopacket2prompt/output/impl/italian/PpktPhenotypicfeatureItalian.java
@@ -41,7 +41,7 @@ private List getTranslations(List ontologyTerms) {
private String getOxfordCommaList(List items) {
if (items.size() == 1) {
- return items.get(0);
+ return items.getFirst();
}
if (items.size() == 2) {
// no comma if we just have two items.
@@ -78,7 +78,7 @@ public String formatFeatures(List ontologyTerms) {
if (excludedLabels.size() > 1) {
return String.format("E' stata esclusa la presenza dei seguenti sintomi: %s.", getOxfordCommaList(excludedLabels));
} else {
- return String.format("E' stata esclusa la presenza del seguente sintomo: %s.",excludedLabels.get(0));
+ return String.format("E' stata esclusa la presenza del seguente sintomo: %s.",excludedLabels.getFirst());
}
} else {
String exclusion;
diff --git a/src/main/java/org/monarchinitiative/phenopacket2prompt/output/impl/spanish/PpktIndividualSpanish.java b/src/main/java/org/monarchinitiative/phenopacket2prompt/output/impl/spanish/PpktIndividualSpanish.java
index 060eaa0..5d19791 100644
--- a/src/main/java/org/monarchinitiative/phenopacket2prompt/output/impl/spanish/PpktIndividualSpanish.java
+++ b/src/main/java/org/monarchinitiative/phenopacket2prompt/output/impl/spanish/PpktIndividualSpanish.java
@@ -213,7 +213,7 @@ private String iso8601AtAgeOf(Iso8601Age isoAge) {
if (components.isEmpty()) {
return "en el período neonatal";
} else if (components.size() == 1) {
- return "a la edad de " + components.get(0);
+ return "a la edad de " + components.getFirst();
} else if (components.size() == 2) {
return "a la edad de " + components.get(0) + " y " + components.get(1);
} else {
diff --git a/src/main/java/org/monarchinitiative/phenopacket2prompt/output/impl/spanish/PpktPhenotypicfeatureSpanish.java b/src/main/java/org/monarchinitiative/phenopacket2prompt/output/impl/spanish/PpktPhenotypicfeatureSpanish.java
index 629ccb0..476ff09 100644
--- a/src/main/java/org/monarchinitiative/phenopacket2prompt/output/impl/spanish/PpktPhenotypicfeatureSpanish.java
+++ b/src/main/java/org/monarchinitiative/phenopacket2prompt/output/impl/spanish/PpktPhenotypicfeatureSpanish.java
@@ -40,7 +40,7 @@ String getConnector(String nextWord) {
if (nextWord.length() < 2) {
return "y"; // should never happen but do not want to crash
}
- Character letter = nextWord.charAt(0);
+ char letter = nextWord.charAt(0);
if (vowels.contains(letter)) {
return " i ";
}
diff --git a/src/main/java/org/monarchinitiative/phenopacket2prompt/output/impl/spanish/SpanishPromptGenerator.java b/src/main/java/org/monarchinitiative/phenopacket2prompt/output/impl/spanish/SpanishPromptGenerator.java
index 39ddb33..75df8cc 100644
--- a/src/main/java/org/monarchinitiative/phenopacket2prompt/output/impl/spanish/SpanishPromptGenerator.java
+++ b/src/main/java/org/monarchinitiative/phenopacket2prompt/output/impl/spanish/SpanishPromptGenerator.java
@@ -1,6 +1,5 @@
package org.monarchinitiative.phenopacket2prompt.output.impl.spanish;
-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;
diff --git a/src/test/java/org/monarchinitiative/phenopacket2prompt/model/PpktIndividualTest.java b/src/test/java/org/monarchinitiative/phenopacket2prompt/model/PpktIndividualTest.java
index 0bc9242..3d86f11 100644
--- a/src/test/java/org/monarchinitiative/phenopacket2prompt/model/PpktIndividualTest.java
+++ b/src/test/java/org/monarchinitiative/phenopacket2prompt/model/PpktIndividualTest.java
@@ -68,7 +68,7 @@ public void testPhenopacketOnset() {
public void testPhenopacketDisease() {
List diseases = ppktIndividual.getDiseases();
assertEquals(1, diseases.size());
- PhenopacketDisease disease = diseases.get(0);
+ PhenopacketDisease disease = diseases.getFirst();
TermId expectedId = TermId.of("OMIM:231670");
String expectedLabel = "Glutaricaciduria, type I";
assertEquals(expectedId, disease.getDiseaseId());
@@ -77,7 +77,7 @@ public void testPhenopacketDisease() {
@Test
public void testPhenotypicFeatures() {
- Map> ppktFeatureMap = ppktIndividual.getSpecifiedAgePhenotypicFeatures();
+ Map> ppktFeatureMap = ppktIndividual.extractSpecifiedAgePhenotypicFeatures();
assertFalse(ppktFeatureMap.isEmpty());
Predicate termPredicate = term -> term.getLabel().equals("Cerebral atrophy");
List otlist = new ArrayList<>();
diff --git a/src/test/java/org/monarchinitiative/phenopacket2prompt/output/impl/english/PpktIndividualEnglishTest.java b/src/test/java/org/monarchinitiative/phenopacket2prompt/output/impl/english/PpktIndividualEnglishTest.java
index 533d9d0..692facb 100644
--- a/src/test/java/org/monarchinitiative/phenopacket2prompt/output/impl/english/PpktIndividualEnglishTest.java
+++ b/src/test/java/org/monarchinitiative/phenopacket2prompt/output/impl/english/PpktIndividualEnglishTest.java
@@ -21,15 +21,15 @@ public class PpktIndividualEnglishTest extends PPKtIndividualBase{
private static Stream testGetIndividualDescription() {
return Stream.of(
new TestIndividual("46 year olf female, infantile onset",
- female46yearsInfantileOnset(), new TestOutcome.Ok("The proband was a 46-year old woman who presented as an infant with")),
+ female46yearsInfantileOnset(), new TestOutcome.Ok("The proband was a 46-year-old woman who presented as an infant with")),
new TestIndividual("male 4 months, congenital onset",
- male4monthsCongenitalOnset(), new TestOutcome.Ok("The proband was a 4-month old male infant who presented at birth with")),
+ male4monthsCongenitalOnset(), new TestOutcome.Ok("The proband was a 4-month-old male infant who presented at birth with")),
new TestIndividual("female, no onset",
femaleNoAge(), new TestOutcome.Ok("The proband was a female who presented with")),
new TestIndividual("female, no HPOs",
femaleNoHPOs(), new TestOutcome.Error(() -> new PhenolRuntimeException("No HPO annotations"))),
new TestIndividual("unknown sex, no 4yo",
- unknownSex4YearsOnset(), new TestOutcome.Ok("The proband presented in childhood with"))
+ unknownSex4YearsOnset(), new TestOutcome.Ok("The proband presented as a child with"))
);
}
diff --git a/src/test/java/org/monarchinitiative/phenopacket2prompt/output/impl/english/PpktPhenotypicFeatureEnglishTest.java b/src/test/java/org/monarchinitiative/phenopacket2prompt/output/impl/english/PpktPhenotypicFeatureEnglishTest.java
index 33d8f37..ae2a366 100644
--- a/src/test/java/org/monarchinitiative/phenopacket2prompt/output/impl/english/PpktPhenotypicFeatureEnglishTest.java
+++ b/src/test/java/org/monarchinitiative/phenopacket2prompt/output/impl/english/PpktPhenotypicFeatureEnglishTest.java
@@ -22,7 +22,7 @@ public class PpktPhenotypicFeatureEnglishTest {
private static Stream testGetIndividualPhenotypicFeatures() {
return Stream.of(
new PPKtIndividualBase.TestIndividual("46 year olf female, infantile onset",
- female46yearsInfantileOnset(), new PPKtIndividualBase.TestOutcome.Ok("Cerebellar atrophy and Ataxia. ")),
+ female46yearsInfantileOnset(), new PPKtIndividualBase.TestOutcome.Ok("Cerebellar atrophy and Ataxia. However, Bradyphrenia was excluded.")),
new PPKtIndividualBase.TestIndividual("male 4 months, congenital onset",
male4monthsCongenitalOnset(), new PPKtIndividualBase.TestOutcome.Ok("Postaxial polydactyly. "))
);