Revision: 6980
http://languagetool.svn.sourceforge.net/languagetool/?rev=6980&view=rev
Author: milek_pl
Date: 2012-05-19 09:13:46 +0000 (Sat, 19 May 2012)
Log Message:
-----------
be really silent about lack of dictionaries (will be true under LO)
Modified Paths:
--------------
trunk/JLanguageTool/src/java/org/languagetool/databroker/DefaultResourceDataBroker.java
trunk/JLanguageTool/src/java/org/languagetool/databroker/ResourceDataBroker.java
trunk/JLanguageTool/src/java/org/languagetool/rules/spelling/hunspell/HunspellRule.java
Modified:
trunk/JLanguageTool/src/java/org/languagetool/databroker/DefaultResourceDataBroker.java
===================================================================
---
trunk/JLanguageTool/src/java/org/languagetool/databroker/DefaultResourceDataBroker.java
2012-05-18 22:25:18 UTC (rev 6979)
+++
trunk/JLanguageTool/src/java/org/languagetool/databroker/DefaultResourceDataBroker.java
2012-05-19 09:13:46 UTC (rev 6980)
@@ -261,6 +261,31 @@
}
/**
+ * See: {@link ResourceDataBroker#resourceExists(java.lang.String)}
+ *
+ * Checks if a resource in the grammar checker's {@code /resource} exists.
+ * @param path Path to an item from the {@code /resource} directory.
+ * @return {@code true} if the resource file exists.
+ */
+ public boolean resourceExists(String path) {
+ final String completePath = this.getCompleteResourceUrl(path);
+ return ResourceDataBroker.class.getResource(completePath) != null;
+ }
+
+ /**
+ * See: {@link ResourceDataBroker#ruleFileExists(java.lang.String)}
+ *
+ * Checks if a resource in the grammar checker's {@code /rules} exists.
+ * @param path Path to an item from the {@code /rules} directory.
+ * @return {@code true} if the resource file exists.
+ */
+ public boolean ruleFileExists(String path) {
+ final String completePath = this.getCompleteRulesUrl(path);
+ return ResourceDataBroker.class.getResource(completePath) != null;
+ }
+
+
+ /**
* @return The directory's name of the grammar checker's resource directory.
* The default value equals
* {@link ResourceDataBroker#RESOURCE_DIR}.
Modified:
trunk/JLanguageTool/src/java/org/languagetool/databroker/ResourceDataBroker.java
===================================================================
---
trunk/JLanguageTool/src/java/org/languagetool/databroker/ResourceDataBroker.java
2012-05-18 22:25:18 UTC (rev 6979)
+++
trunk/JLanguageTool/src/java/org/languagetool/databroker/ResourceDataBroker.java
2012-05-19 09:13:46 UTC (rev 6980)
@@ -74,8 +74,22 @@
* wasn't found.
*/
public URL getFromResourceDirAsUrl(String path);
-
+
/**
+ * Checks if a resource in the grammar checker's {@code /resource} exists.
+ * @param path Path to an item from the {@code /resource} directory.
+ * @return {@code true} if the resource file exists.
+ */
+ public boolean resourceExists(String path);
+
+ /**
+ * Checks if a resource in the grammar checker's {@code /rules} exists.
+ * @param path Path to an item from the {@code /rules} directory.
+ * @return {@code true} if the resource file exists.
+ */
+ public boolean ruleFileExists(String path);
+
+ /**
* Gets any resource from the grammar checker's {@code /resource} directory.
*
* @param path Path to an item from the {@code /resource} directory.
Modified:
trunk/JLanguageTool/src/java/org/languagetool/rules/spelling/hunspell/HunspellRule.java
===================================================================
---
trunk/JLanguageTool/src/java/org/languagetool/rules/spelling/hunspell/HunspellRule.java
2012-05-18 22:25:18 UTC (rev 6979)
+++
trunk/JLanguageTool/src/java/org/languagetool/rules/spelling/hunspell/HunspellRule.java
2012-05-19 09:13:46 UTC (rev 6980)
@@ -64,22 +64,25 @@
+ "/hunspell/"
+ language.getShortName()
+ "_"
- + language.getCountryVariants()[0];
-
- // FIXME: need to change behavior of hunspell library, this is
a hack to
- // test hunspell
-
- String dictionaryPath =
-
JLanguageTool.getDataBroker().getFromResourceDirAsUrl(
- shortDicPath + ".dic").getPath();
-
- dictionaryPath = dictionaryPath.substring(0,
dictionaryPath.length() - 4);
+ + language.getCountryVariants()[0]
+ + ".dic";
- // Note: the class will silently ignore the non-existence of
- // dictionaries!
- if (JLanguageTool.getDataBroker().getFromResourceDirAsUrl(
- shortDicPath + ".dic") != null) {
- dictionary =
Hunspell.getInstance().getDictionary(dictionaryPath);
+ //set dictionary only if there are dictionary files
+ if (JLanguageTool.getDataBroker().resourceExists(shortDicPath))
{
+ // FIXME: need to change behavior of hunspell library,
this is a hack to
+ // test hunspell
+ String dictionaryPath =
+
JLanguageTool.getDataBroker().getFromResourceDirAsUrl(
+ shortDicPath).getPath();
+
+ dictionaryPath = dictionaryPath.substring(0,
dictionaryPath.length() - 4);
+
+ // Note: the class will silently ignore the
non-existence of
+ // dictionaries!
+ if
(JLanguageTool.getDataBroker().getFromResourceDirAsUrl(
+ shortDicPath) != null) {
+ dictionary =
Hunspell.getInstance().getDictionary(dictionaryPath);
+ }
}
}
@@ -102,7 +105,7 @@
// some languages might not have a dictionary, be silent about
it
if (dictionary == null)
- return null;
+ return toRuleMatchArray(ruleMatches);
// starting with the first token to skip the zero-length
START_SENT
for (int i = 1; i < tokens.length; i++) {
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