Revision: 9874
http://languagetool.svn.sourceforge.net/languagetool/?rev=9874&view=rev
Author: jaumeortola
Date: 2013-04-04 21:42:07 +0000 (Thu, 04 Apr 2013)
Log Message:
-----------
[server] Use 'enabledOnly=yes' for disabling all the rules except those
explicitly enabled.
Ex.:
http://localhost:8081/?language=en&enabled=STRANGE_RULE,ANOTHER_RULE&enabledOnly=yes&text=my+text
Modified Paths:
--------------
trunk/languagetool/languagetool-core/src/main/java/org/languagetool/tools/Tools.java
trunk/languagetool/languagetool-server/src/main/java/org/languagetool/server/LanguageToolHttpHandler.java
trunk/languagetool/languagetool-server/src/test/java/org/languagetool/server/HTTPServerTest.java
trunk/languagetool/languagetool-standalone/CHANGES.txt
Modified:
trunk/languagetool/languagetool-core/src/main/java/org/languagetool/tools/Tools.java
===================================================================
---
trunk/languagetool/languagetool-core/src/main/java/org/languagetool/tools/Tools.java
2013-04-04 21:16:52 UTC (rev 9873)
+++
trunk/languagetool/languagetool-core/src/main/java/org/languagetool/tools/Tools.java
2013-04-04 21:42:07 UTC (rev 9874)
@@ -578,10 +578,10 @@
* @param enabledRules ids of the rules to be enabled
*/
public static void selectRules(final JLanguageTool lt, final String[]
disabledRules, final String[] enabledRules) {
- selectRules (lt, disabledRules, enabledRules, false);
+ selectRules (lt, disabledRules, enabledRules, true);
}
- public static void selectRules(final JLanguageTool lt, final String[]
disabledRules, final String[] enabledRules, boolean keepEnabledRulesByDefault) {
+ public static void selectRules(final JLanguageTool lt, final String[]
disabledRules, final String[] enabledRules, boolean useEnabledOnly) {
// disable rules that are disabled explicitly:
for (final String disabledRule : disabledRules) {
lt.disableRule(disabledRule);
@@ -594,7 +594,7 @@
lt.enableRule(ruleName);
}
// disable all rules except those enabled explicitly, if any:
- if (!keepEnabledRulesByDefault) {
+ if (useEnabledOnly) {
for (Rule rule : lt.getAllRules()) {
if (!enabledRuleIDs.contains(rule.getId())) {
lt.disableRule(rule.getId());
Modified:
trunk/languagetool/languagetool-server/src/main/java/org/languagetool/server/LanguageToolHttpHandler.java
===================================================================
---
trunk/languagetool/languagetool-server/src/main/java/org/languagetool/server/LanguageToolHttpHandler.java
2013-04-04 21:16:52 UTC (rev 9873)
+++
trunk/languagetool/languagetool-server/src/main/java/org/languagetool/server/LanguageToolHttpHandler.java
2013-04-04 21:42:07 UTC (rev 9874)
@@ -55,6 +55,7 @@
private String[] enabledRules = {};
private String[] disabledRules = {};
+ private boolean useEnabledOnly;
private int maxTextLength = Integer.MAX_VALUE;
/**
@@ -191,12 +192,22 @@
enabledRules = enabledParam.split(",");
}
+ useEnabledOnly = false;
+ final String enabledOnly = parameters.get("enabledOnly");
+ if (null != enabledOnly) {
+ useEnabledOnly = (enabledOnly.equals("yes"));
+ }
+
final String disabledParam = parameters.get("disabled");
disabledRules = new String[0];
if (null != disabledParam) {
disabledRules = disabledParam.split(",");
}
+ if (disabledRules.length > 0 && useEnabledOnly) {
+ throw new IllegalArgumentException("You cannot specify disabled rules
using enabledOnly=yes");
+ }
+
useQuerySettings = enabledRules.length > 0 || disabledRules.length > 0;
final List<RuleMatch> matches;
@@ -278,7 +289,7 @@
configureGUI(newLanguageTool);
}
if (useQuerySettings) {
- Tools.selectRules(newLanguageTool, disabledRules, enabledRules, true);
+ Tools.selectRules(newLanguageTool, disabledRules, enabledRules,
useEnabledOnly);
}
return newLanguageTool;
}
Modified:
trunk/languagetool/languagetool-server/src/test/java/org/languagetool/server/HTTPServerTest.java
===================================================================
---
trunk/languagetool/languagetool-server/src/test/java/org/languagetool/server/HTTPServerTest.java
2013-04-04 21:16:52 UTC (rev 9873)
+++
trunk/languagetool/languagetool-server/src/test/java/org/languagetool/server/HTTPServerTest.java
2013-04-04 21:42:07 UTC (rev 9874)
@@ -117,21 +117,25 @@
//test for no changed if no options set
final String[] nothing = new String[0];
assertEquals(check(english, german, "We will berate you"),
- checkWithOptions(english, german, "We will berate you",
nothing, nothing));
+ checkWithOptions(english, german, "We will berate you",
nothing, nothing, false));
//disabling
final String[] disableAvsAn = new String[1];
disableAvsAn[0] = "EN_A_VS_AN";
assertTrue(!checkWithOptions(
- english, german, "This is an test", nothing,
disableAvsAn).contains("an test"));
+ english, german, "This is an test", nothing, disableAvsAn,
false).contains("an test"));
//enabling
assertTrue(checkWithOptions(
- english, german, "This is an test", disableAvsAn,
nothing).contains("an test"));
+ english, german, "This is an test", disableAvsAn, nothing,
false).contains("an test"));
//should also mean _NOT_ disabling all other rules...
assertTrue(checkWithOptions(
- english, german, "We will berate you", disableAvsAn,
nothing).contains("BERATE"));
+ english, german, "We will berate you", disableAvsAn, nothing,
false).contains("BERATE"));
+ //..unless explicitly stated.
+ assertTrue(!checkWithOptions(
+ english, german, "We will berate you", disableAvsAn, nothing,
true).contains("BERATE"));
+
//test if two rules get enabled as well
final String[] twoRules = new String[2];
@@ -139,14 +143,14 @@
twoRules[1] = "BERATE";
String resultEn = checkWithOptions(
- english, german, "This is an test. We will berate you.", twoRules,
nothing);
+ english, german, "This is an test. We will berate you.", twoRules,
nothing, false);
assertTrue(resultEn.contains("EN_A_VS_AN"));
assertTrue(resultEn.contains("BERATE"));
//check two disabled options
resultEn = checkWithOptions(
- english, german, "This is an test. We will berate you.", nothing,
twoRules);
+ english, german, "This is an test. We will berate you.", nothing,
twoRules, false);
assertTrue(!resultEn.contains("EN_A_VS_AN"));
assertTrue(!resultEn.contains("BERATE"));
@@ -154,7 +158,7 @@
//two disabled, one enabled, so enabled wins
resultEn = checkWithOptions(
- english, german, "This is an test. We will berate you.",
disableAvsAn, twoRules);
+ english, german, "This is an test. We will berate you.",
disableAvsAn, twoRules, false);
assertTrue(resultEn.contains("EN_A_VS_AN"));
assertTrue(!resultEn.contains("BERATE"));
@@ -175,6 +179,22 @@
server.stop();
}
}
+
+ @Test
+ public void testEnabledOnlyParameter() throws Exception {
+ final HTTPServer server = new HTTPServer(new HTTPServerConfig(), false);
+ try {
+ server.run();
+ try {
+ System.out.println("Testing 'enabledOnly parameter' now, please ignore
the exception");
+ final URL url = new URL("http://localhost:" + DEFAULT_PORT +
"/?text=foo&language=en-US&disabled=EN_A_VS_AN&enabledOnly=yes");
+ HTTPTools.checkAtUrl(url);
+ fail();
+ } catch (IOException expected) {}
+ } finally {
+ server.stop();
+ }
+ }
@Test
public void testMissingLanguageParameter() throws Exception {
@@ -218,7 +238,7 @@
}
private String checkWithOptions(Language lang, Language motherTongue, String
text,
- String[] enabledRules, String[]
disabledRules) throws IOException {
+ String[] enabledRules, String[]
disabledRules, boolean useEnabledOnly) throws IOException {
String urlOptions = "/?language=" + lang.getShortName();
urlOptions += "&text=" + URLEncoder.encode(text, "UTF-8"); // latin1 is
not enough for languages like polish, romanian, etc
if (null != motherTongue) {
@@ -231,6 +251,9 @@
if (enabledRules.length > 0) {
urlOptions += "&enabled=" + StringUtils.join(enabledRules, ",");
}
+ if (useEnabledOnly) {
+ urlOptions += "&enabledOnly=yes";
+ }
final URL url = new URL("http://localhost:" + DEFAULT_PORT + urlOptions);
return HTTPTools.checkAtUrl(url);
Modified: trunk/languagetool/languagetool-standalone/CHANGES.txt
===================================================================
--- trunk/languagetool/languagetool-standalone/CHANGES.txt 2013-04-04
21:16:52 UTC (rev 9873)
+++ trunk/languagetool/languagetool-standalone/CHANGES.txt 2013-04-04
21:42:07 UTC (rev 9874)
@@ -2,9 +2,17 @@
2.2-dev (release planned for 2013-06-30)
+ -Catalan:
+ -improved rules
+ -fixed false alarms
+
+ -HTTP server:
+ -enabling and disabling rules at the same time (keeping the rest of the
default options) is now allowed.
+ To disable all the rules except those explicitly enabled, you can use the
parameter enabledOnly=yes. Ex.:
+
http://localhost:8081/?language=en&enabled=STRANGE_RULE,ANOTHER_RULE&enabledOnly=yes&text=my+text
+
-Updated Tika (used for language detection) from 0.9 to 1.3
-
2.1 (2013-03-31)
-Breton:
This was sent by the SourceForge.net collaborative development platform, the
world's largest Open Source development site.
------------------------------------------------------------------------------
Minimize network downtime and maximize team effectiveness.
Reduce network management and security costs.Learn how to hire
the most talented Cisco Certified professionals. Visit the
Employer Resources Portal
http://www.cisco.com/web/learning/employer_resources/index.html
_______________________________________________
Languagetool-commits mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/languagetool-commits