PLS implements PronouncingDictionary { @SuppressWarnings("unchecked") public PLS(String dictionaryFilename) throws DocumentException { SAXReader reader = new SAXReader(); Document document = reader.read(dictionaryFilename); dict = new MultiValueMap(); Element lexicon = document.getRootElement(); alphabetId = lexicon.attributeValue("alphabet"); dictionaryLanguage = lexicon.attributeValue("lang"); Map<String, String> namespaceMap = new HashMap<String, String>(); namespaceMap.put("rdf", "http: namespaceMap.put("dc", "http: XPath xpath = document.createXPath(" xpath.setNamespaceURIs(namespaceMap); Node node = xpath.selectSingleNode(lexicon); if (node != null) { dictionaryId = node.valueOf("@dc:title"); } else { dictionaryId = ""; } for (Iterator<Element> lexemeIterator = lexicon .elementIterator("lexeme"); lexemeIterator.hasNext();) { Element lexeme = lexemeIterator.next(); List<Element> graphemes = lexeme.selectNodes("grapheme"); List<Element> phonemes = lexeme.selectNodes("phoneme"); for (Element grapheme : graphemes) { for (Element phoneme : phonemes) { dict.put(grapheme.getText(), phoneme.getText()); } } } } @SuppressWarnings("unchecked")  PLS(String dictionaryFilename); @Override String getDictionaryId(); @Override String getAlphabetId(); @SuppressWarnings("unchecked") @Override List<String> getPronunciations(String word); @Override String getLanguage();  }
@Test public void testPLS() throws DocumentException, PronouncingDictionaryException { PLS dict = new PLS("src/test/resources/pls-sample.xml"); List<String> result; assertEquals("ipa", dict.getAlphabetId()); assertEquals("de-DE", dict.getLanguage()); assertEquals("A sample PLS German dictionary", dict.getDictionaryId()); result = dict.getPronunciations("10."); assertEquals(5, result.size()); assertEquals("t͡seːntən", result.get(4)); List<String> rauResult = dict.getPronunciations("rau"); List<String> rauhResult = dict.getPronunciations("rauh"); assertEquals(rauResult, rauhResult); assertEquals(1, rauResult.size()); }