Preprocess extends InternalModule { protected void checkForNumbers(Document doc) { TreeWalker tw = ((DocumentTraversal) doc).createTreeWalker(doc, NodeFilter.SHOW_ELEMENT, new NameNodeFilter(MaryXML.TOKEN), false); Element t = null; while ((t = (Element) tw.nextNode()) != null) { if (MaryDomUtils.hasAncestor(t, MaryXML.SAYAS) || t.hasAttribute("ph") || t.hasAttribute("sounds_like")) { continue; } String origText = MaryDomUtils.tokenText(t); if (MaryDomUtils.tokenText(t).matches("\\d+(e|er|re|ère|ème)")) { String matched = MaryDomUtils.tokenText(t).split("e|ere|er|re|ère|ème")[0]; if (matched.equals("1")) { if (MaryDomUtils.tokenText(t).matches("\\d+er")) { MaryDomUtils.setTokenText(t, expandOrdinal(Double.parseDouble(matched))); } else { String s = expandOrdinal(Double.parseDouble(matched)); MaryDomUtils.setTokenText(t, s.replace("ier", "ière")); } } else { MaryDomUtils.setTokenText(t, expandOrdinal(Double.parseDouble(matched))); } } else if (MaryDomUtils.tokenText(t).matches("\\d+")) { MaryDomUtils.setTokenText(t, expandNumber(Double.parseDouble(MaryDomUtils.tokenText(t)))); } if (!origText.equals(MaryDomUtils.tokenText(t))) { MaryDomUtils.encloseWithMTU(t, origText, null); } } } Preprocess(); MaryData process(MaryData d);  }
@Test(dataProvider = "DocData") public void testSpellout(String tokenised, String expected) throws Exception { Document tokenisedDoc; Document expectedDoc; String tokens = "<maryxml xmlns=\"http: + tokenised + "</t></s></p></maryxml>"; tokenisedDoc = DomUtils.parseDocument(tokens); String words = "<maryxml xmlns=\"http: + tokenised + "\"><t>" + expected + "</t></mtu></s></p></maryxml>"; expectedDoc = DomUtils.parseDocument(words); module.checkForNumbers(tokenisedDoc); Diff diff = XMLUnit.compareXML(expectedDoc, tokenisedDoc); Assert.assertTrue(diff.identical()); }