Revision: 7203
http://languagetool.svn.sourceforge.net/languagetool/?rev=7203&view=rev
Author: dnaber
Date: 2012-06-03 10:34:18 +0000 (Sun, 03 Jun 2012)
Log Message:
-----------
[ca] small code cleanup
Modified Paths:
--------------
trunk/JLanguageTool/src/java/org/languagetool/synthesis/ca/CatalanSynthesizer.java
trunk/JLanguageTool/src/test/org/languagetool/synthesis/ca/CatalanSynthesizerTest.java
Modified:
trunk/JLanguageTool/src/java/org/languagetool/synthesis/ca/CatalanSynthesizer.java
===================================================================
---
trunk/JLanguageTool/src/java/org/languagetool/synthesis/ca/CatalanSynthesizer.java
2012-06-03 10:19:55 UTC (rev 7202)
+++
trunk/JLanguageTool/src/java/org/languagetool/synthesis/ca/CatalanSynthesizer.java
2012-06-03 10:34:18 UTC (rev 7203)
@@ -34,20 +34,19 @@
*
* There is a special addition:
* "add_DT" tag adds "el, la, l', els, les" according to the gender
- * and the numer of the word and the Catalan rules for apostrophation (l').
+ * and the number of the word and the Catalan rules for apostrophation (l').
*
* @author Jaume Ortolà i Font
*/
public class CatalanSynthesizer extends BaseSynthesizer {
private static final String RESOURCE_FILENAME = "/ca/catalan_synth.dict";
-
private static final String TAGS_FILE_NAME = "/ca/catalan_tags.txt";
/** A special tag to add determiner (el, la, l', els, les). **/
private static final String ADD_DETERMINER = "+DT";
- /** Patterns for numer and gender **/
+ /** Patterns for number and gender **/
private static final Pattern pMS =
Pattern.compile("(N|A.).[MC][SN].*|V.P.*[SN][MC]");
private static final Pattern pFS =
Pattern.compile("(N|A.).[FC][SN].*|V.P.*[SN][FC]");
private static final Pattern pMP =
Pattern.compile("(N|A.).[MC][PN].*|V.P.*[PN][MC]");
@@ -103,10 +102,10 @@
final Matcher mMP = pMP.matcher(posTag);
final Matcher mFP = pFP.matcher(posTag);
for (WordData wd : wordForms) {
- final String word = wd.getStem().toString();
+ final String word = wd.getStem().toString();
if (mMS.matches()) {
- final Matcher mMascYes =
pMascYes.matcher(wd.getStem().toString());
- final Matcher mMascNo =
pMascNo.matcher(wd.getStem().toString());
+ final Matcher mMascYes = pMascYes.matcher(word);
+ final Matcher mMascNo = pMascNo.matcher(word);
if (mMascYes.matches() && !mMascNo.matches()) {
results.add("l'" + word);
} else {
@@ -114,8 +113,8 @@
}
}
if (mFS.matches()) {
- final Matcher mFemYes =
pFemYes.matcher(wd.getStem().toString());
- final Matcher mFemNo = pFemNo.matcher(wd.getStem().toString());
+ final Matcher mFemYes = pFemYes.matcher(word);
+ final Matcher mFemNo = pFemNo.matcher(word);
if (mFemYes.matches() && !mFemNo.matches()) {
results.add("l'" + word);
} else {
Modified:
trunk/JLanguageTool/src/test/org/languagetool/synthesis/ca/CatalanSynthesizerTest.java
===================================================================
---
trunk/JLanguageTool/src/test/org/languagetool/synthesis/ca/CatalanSynthesizerTest.java
2012-06-03 10:19:55 UTC (rev 7202)
+++
trunk/JLanguageTool/src/test/org/languagetool/synthesis/ca/CatalanSynthesizerTest.java
2012-06-03 10:34:18 UTC (rev 7203)
@@ -27,22 +27,36 @@
public class CatalanSynthesizerTest extends TestCase {
+ private final CatalanSynthesizer synth = new CatalanSynthesizer();
+
public final void testSynthesizeStringString() throws IOException {
- final CatalanSynthesizer synth = new CatalanSynthesizer();
- assertEquals(synth.synthesize(dummyToken("blablabla"),
- "blablabla").length, 0);
+ assertEquals(0, synth.synthesize(dummyToken("blablabla"),
"blablabla").length);
- assertEquals("[nostres]",
Arrays.toString(synth.synthesize(dummyToken("nostre"), "PX1CP0P0")));
- assertEquals("[presidents]",
Arrays.toString(synth.synthesize(dummyToken("president"), "NCMP000")));
- assertEquals("[comprovat]",
Arrays.toString(synth.synthesize(dummyToken("comprovar"), "VMP00SM")));
- //with regular expressions
- assertEquals("[comprovades, comprovats, comprovada, comprovat]",
Arrays.toString(synth.synthesize(dummyToken("comprovar"), "V.P.*", true)));
- assertEquals("[contestant, contestar]",
Arrays.toString(synth.synthesize(dummyToken("contestar"), "VM[GN]0000", true)));
- //with special definite article
- assertEquals("[les universitats, la universitat]",
Arrays.toString(synth.synthesize(dummyToken("universitat"), "+DT", false)));
- assertEquals("[les úniques, l'única, els únics, l'únic]",
Arrays.toString(synth.synthesize(dummyToken("únic"), "+DT", false)));
+ assertEquals("[nostres]", synth("nostre", "PX1CP0P0"));
+ assertEquals("[presidents]", synth("president", "NCMP000"));
+ assertEquals("[comprovat]", synth("comprovar", "VMP00SM"));
+
+ //with regular expressions:
+ assertEquals("[comprovades, comprovats, comprovada, comprovat]",
synthRegex("comprovar", "V.P.*"));
+ assertEquals("[contestant, contestar]", synthRegex("contestar",
"VM[GN]0000"));
+
+ //with special definite article:
+ assertEquals("[les universitats, la universitat]",
synthNonRegex("universitat", "+DT"));
+ assertEquals("[les úniques, l'única, els únics, l'únic]",
synthNonRegex("únic", "+DT"));
}
+ private String synth(String word, String pos) throws IOException {
+ return Arrays.toString(synth.synthesize(dummyToken(word), pos));
+ }
+
+ private String synthRegex(String word, String pos) throws IOException {
+ return Arrays.toString(synth.synthesize(dummyToken(word), pos, true));
+ }
+
+ private String synthNonRegex(String word, String pos) throws IOException {
+ return Arrays.toString(synth.synthesize(dummyToken(word), pos, false));
+ }
+
private AnalyzedToken dummyToken(String tokenStr) {
return new AnalyzedToken(tokenStr, tokenStr, tokenStr);
}
This was sent by the SourceForge.net collaborative development platform, the
world's largest Open Source development site.
------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and
threat landscape has changed and how IT managers can respond. Discussions
will include endpoint security, mobile security and the latest in malware
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
_______________________________________________
Languagetool-cvs mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/languagetool-cvs