Skip to content

Commit

Permalink
Fixing another problem when the unit comes before in an atomic value #84
Browse files Browse the repository at this point in the history
  • Loading branch information
lfoppiano committed Apr 1, 2019
1 parent 9747bd7 commit 9d74580
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -55,26 +55,45 @@ protected Element trainingExtraction(List<Measurement> measurements, String text
endU = unit.getOffsetEnd();
}

boolean addedMeasure = false;
int initPos = pos;

while (pos < text.length()) {

if (pos == startQ) {
p.appendChild(text.substring(initPos, startQ));
measure.appendChild(text.substring(startQ, endQ));
if (quantifiedObject != null) {
measure.addAttribute(new Attribute("ptr", "#" + quantifiedObjectID));
// markPosition(measure, quantifiedObject, startQ);
if (!addedMeasure) {
if (quantifiedObject != null) {
measure.addAttribute(new Attribute("ptr", "#" + quantifiedObjectID));
}
p.appendChild(text.substring(initPos, startQ));
p.appendChild(measure);
addedMeasure = true;
} else {
measure.appendChild(text.substring(initPos, startQ));
}
p.appendChild(measure);
measure.appendChild(text.substring(startQ, endQ));
pos = endQ;
initPos = pos;
}
if (pos == startU) {
measure.appendChild(text.substring(initPos, startU));
if (!addedMeasure) {
if (quantifiedObject != null) {
measure.addAttribute(new Attribute("ptr", "#" + quantifiedObjectID));
}
p.appendChild(text.substring(initPos, startU));
p.appendChild(measure);
addedMeasure = true;
} else {
measure.appendChild(text.substring(initPos, startU));
}
measure.appendChild(text.substring(startU, endU));
pos = endU;
initPos = pos;

// measure.appendChild(text.substring(initPos, startU));
// measure.appendChild(text.substring(startU, endU));
// pos = endU;
// initPos = pos;
}
if (pos == startO) {
p.appendChild(text.substring(initPos, startO));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -421,4 +421,21 @@ public void testTrainingExtraction3() throws Exception {

}

@Test
public void testTriningExtraction4() throws Exception {
String text = "Because furosemide-midazolam incompatibility is pH-dependent, the impact of furosemide concentration is predictable. Furosemide in 10 mg/mL of saline is an alkaline solution (pH = 8.77). ";

LibraryLoader.load();
List<Measurement> measurements = QuantityParser.getInstance().process(text);
// final Element element = target.trainingExtraction(measurements, text);

Measurement measurement = new Measurement(UnitUtilities.Measurement_Type.VALUE);
measurement.setAtomicQuantity(new Quantity("8.77", new Unit("pH", 175, 177), 180, 184));

final Element element = target.trainingExtraction(Arrays.asList(measurement), text);

assertThat(element.toXML(), is("<p xmlns=\"http://www.tei-c.org/ns/1.0\">Because furosemide-midazolam incompatibility is pH-dependent, the impact of furosemide concentration is predictable. Furosemide in 10 mg/mL of saline is an alkaline solution (<measure type=\"value\">pH = 8.77</measure>). </p>"));

}

}

0 comments on commit 9d74580

Please sign in to comment.