| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
package dr.inferencexml.model; |
| 27 |
|
| 28 |
import dr.inference.model.RatioStatistic; |
| 29 |
import dr.inference.model.Statistic; |
| 30 |
import dr.xml.*; |
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
public class RatioStatisticParser extends AbstractXMLObjectParser { |
| 35 |
|
| 36 |
public static String RATIO_STATISTIC = "ratioStatistic"; |
| 37 |
public static String RATIO = "ratio"; |
| 38 |
|
| 39 |
public String[] getParserNames() { return new String[] { getParserName(), RATIO}; } |
| 40 |
public String getParserName() { return RATIO_STATISTIC; } |
| 41 |
|
| 42 |
public Object parseXMLObject(XMLObject xo) throws XMLParseException { |
| 43 |
|
| 44 |
Statistic numerator = (Statistic)xo.getChild(0); |
| 45 |
Statistic denominator = (Statistic)xo.getChild(1); |
| 46 |
|
| 47 |
RatioStatistic ratioStatistic; |
| 48 |
try { |
| 49 |
ratioStatistic = new RatioStatistic(RATIO_STATISTIC, numerator, denominator); |
| 50 |
} catch (IllegalArgumentException iae) { |
| 51 |
throw new XMLParseException("Error parsing " + getParserName() + " the numerator and denominator statistics " + |
| 52 |
"should be of the same dimension or of dimension 1"); |
| 53 |
} |
| 54 |
return ratioStatistic; |
| 55 |
} |
| 56 |
|
| 57 |
|
| 58 |
|
| 59 |
|
| 60 |
|
| 61 |
public String getParserDescription() { |
| 62 |
return "This element returns a statistic that is the ratio of the 2 child statistics."; |
| 63 |
} |
| 64 |
|
| 65 |
public Class getReturnType() { return RatioStatistic.class; } |
| 66 |
|
| 67 |
public XMLSyntaxRule[] getSyntaxRules() { return rules; } |
| 68 |
|
| 69 |
private final XMLSyntaxRule[] rules = { |
| 70 |
new ElementRule(Statistic.class, "The two operand statistics", 2, 2) |
| 71 |
}; |
| 72 |
|
| 73 |
} |