Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 27cb1ee

Browse files
committed
Port LuxembourgishPhonemiser to Java
1 parent 4c9e679 commit 27cb1ee

File tree

2 files changed

+65
-68
lines changed

2 files changed

+65
-68
lines changed

marytts-languages/marytts-lang-lb/src/main/groovy/marytts/language/lb/LuxembourgishPhonemiser.groovy

Lines changed: 0 additions & 68 deletions
This file was deleted.
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
package marytts.language.lb;
2+
3+
import marytts.datatypes.MaryData;
4+
import marytts.datatypes.MaryXML;
5+
import marytts.exceptions.MaryConfigurationException;
6+
import marytts.language.fr.Phonemiser;
7+
import marytts.modules.JPhonemiser;
8+
import marytts.util.dom.MaryDomUtils;
9+
import org.w3c.dom.Document;
10+
import org.w3c.dom.Element;
11+
import org.w3c.dom.traversal.NodeIterator;
12+
13+
import java.io.IOException;
14+
15+
public class LuxembourgishPhonemiser extends JPhonemiser {
16+
17+
Phonemiser frenchPhonemiser;
18+
19+
public LuxembourgishPhonemiser() throws IOException, MaryConfigurationException {
20+
super("lb.");
21+
frenchPhonemiser = new Phonemiser();
22+
}
23+
24+
/**
25+
* Determine pronunciation for all tokens in the input, adding <code>ph</code> and <code>g2p_method</code> attributes.
26+
*
27+
* @param input MaryData to process
28+
* @return output processed MaryData
29+
*/
30+
@Override
31+
public MaryData process(MaryData input) {
32+
Document document = input.getDocument();
33+
34+
NodeIterator tokenIterator = MaryDomUtils.createNodeIterator(document, MaryXML.TOKEN);
35+
Element token;
36+
while ((token = (Element) tokenIterator.nextNode()) != null) {
37+
String transcription;
38+
String text = token.getTextContent().trim();
39+
String pos = token.getAttribute("pos");
40+
if ((transcription = userdictLookup(text, pos)) != null) {
41+
token.setAttribute(MaryXML.PHONE, transcription);
42+
token.setAttribute("g2p_method", "userdict");
43+
} else if ((transcription = lexiconLookup(text, pos)) != null) {
44+
token.setAttribute(MaryXML.PHONE, transcription);
45+
token.setAttribute("g2p_method", "lexicon");
46+
} else if ((transcription = frenchPhonemiser.lexiconLookup(text, pos)) != null) {
47+
token.setAttribute(MaryXML.PHONE, transcription);
48+
token.setAttribute("g2p_method", "lexicon_fr");
49+
} else {
50+
String phones = lts.predictPronunciation(text);
51+
try {
52+
transcription = lts.syllabify(phones);
53+
token.setAttribute(MaryXML.PHONE, transcription);
54+
token.setAttribute("g2p_method", "rules");
55+
} catch (IllegalArgumentException e) {
56+
logger.error(String.format("Problem with token <%s> [%s]: %s", text, phones, e.getMessage()));
57+
}
58+
}
59+
}
60+
61+
MaryData output = new MaryData(getOutputType(), input.getLocale());
62+
output.setDocument(document);
63+
return output;
64+
}
65+
}

0 commit comments

Comments
 (0)