Revision: 6371
http://languagetool.svn.sourceforge.net/languagetool/?rev=6371&view=rev
Author: dnaber
Date: 2012-01-29 12:02:11 +0000 (Sun, 29 Jan 2012)
Log Message:
-----------
code cleanup: moving methods; re-throwing exceptions instead of just printing
them
Modified Paths:
--------------
trunk/JLanguageTool/src/dev/org/languagetool/dev/conversion/AtdRuleConverter.java
trunk/JLanguageTool/src/dev/org/languagetool/dev/conversion/RuleConverter.java
trunk/JLanguageTool/src/dev/org/languagetool/dev/conversion/RuleConverterMain.java
trunk/JLanguageTool/src/dev/org/languagetool/dev/conversion/RuleCoverage.java
trunk/JLanguageTool/src/dev/org/languagetool/dev/conversion/gui/Main.java
trunk/JLanguageTool/src/dev/org/languagetool/dev/conversion/gui/MainMenuBar.java
trunk/JLanguageTool/src/java/org/languagetool/Main.java
Modified:
trunk/JLanguageTool/src/dev/org/languagetool/dev/conversion/AtdRuleConverter.java
===================================================================
---
trunk/JLanguageTool/src/dev/org/languagetool/dev/conversion/AtdRuleConverter.java
2012-01-29 11:54:14 UTC (rev 6370)
+++
trunk/JLanguageTool/src/dev/org/languagetool/dev/conversion/AtdRuleConverter.java
2012-01-29 12:02:11 UTC (rev 6371)
@@ -41,16 +41,16 @@
import morfologik.stemming.IStemmer;
import morfologik.stemming.WordData;
-
public class AtdRuleConverter extends RuleConverter {
private static final Pattern nounInPattern =
Pattern.compile("NN(?!P|S|\\.)");
private static final Pattern wordReference =
Pattern.compile("\\\\(\\d+)"); // a word reference, e.g. \1
private static final Pattern wordReferenceTransform =
Pattern.compile("\\\\(\\d+):([^:]+)");
private static final Pattern uppercase = Pattern.compile("[A-Z]");
-
+ private static final String ENGLISH_DICT = "/en/english.dict";
+
private static IStemmer dictLookup = (DictionaryLookup) loadDictionary();
-
+
private String avoidMessage = "";
// default constructor
@@ -206,15 +206,14 @@
/**
* Takes a HashMap of an AtD rule, and returns a list of lines of XML in
LT format.
*
- * @param rule: HashMap of values like "pattern" and "message"
+ * @param ruleObject: HashMap of values like "pattern" and "message"
* @param id: String of rule id
* @param name: String of rule name
*
* @return list of XML lines
- *
*/
@SuppressWarnings("unchecked")
- @Override
+ @Override
public List<String> ltRuleAsList(Object ruleObject, String id, String
name, String type) {
ArrayList<HashMap<String,String>> outerList = new
ArrayList<HashMap<String,String>>();
HashMap<String,String> mainRule = (HashMap<String,String>)ruleObject;
@@ -811,26 +810,25 @@
// changes for later
private static boolean inDictionary(String word) {
if (dictLookup == null) {
- dictLookup = (DictionaryLookup) loadDictionary();
+ dictLookup = loadDictionary();
}
return !dictLookup.lookup(word).isEmpty();
}
// this should be general, not specific to English
private static IStemmer loadDictionary() {
- IStemmer dictLookup = null;
- String fileName = "/en/english.dict";
- URL url =
JLanguageTool.getDataBroker().getFromResourceDirAsUrl(fileName);
- File dictFile = null;
+ IStemmer dictLookup;
+ URL url =
JLanguageTool.getDataBroker().getFromResourceDirAsUrl(ENGLISH_DICT);
+ File dictFile;
try {
dictFile = new File(url.toURI());
} catch (URISyntaxException e) {
- e.printStackTrace();
+ throw new RuntimeException("Could not load " + ENGLISH_DICT, e);
}
try {
- dictLookup = new DictionaryLookup(Dictionary.read(dictFile));
+ dictLookup = new DictionaryLookup(Dictionary.read(dictFile));
} catch (IOException e) {
- e.printStackTrace();
+ throw new RuntimeException("Could not load " + dictFile, e);
}
return dictLookup;
}
@@ -838,23 +836,23 @@
/**
* Checks if an element of the AtD pattern has a specific postag.
* @param word: an element of an AtD pattern; (accepts both .\*\/NN and
<word> types)
- * @param postag: a specific postag (no regexes)
+ * @param posTag: a specific postag (no regexes)
* @return
*/
- public static boolean hasSpecificPosTag(String word, String postag) {
+ public static boolean hasSpecificPosTag(String word, String posTag) {
if (dictLookup == null) {
dictLookup = (DictionaryLookup) loadDictionary();
}
if (hasPosTag(word)) {
- String[] splitWord = word.split("/");
- if (Pattern.matches(splitWord[1], postag)) {
+ final String[] splitWord = word.split("/");
+ if (Pattern.matches(splitWord[1], posTag)) {
return true;
}
return false;
}
- List<WordData> lwd = dictLookup.lookup(word);
+ final List<WordData> lwd = dictLookup.lookup(word);
for (WordData wd : lwd) {
- if (wd.getTag().toString().equals(postag)) {
+ if (wd.getTag().toString().equals(posTag)) {
return true;
}
}
Modified:
trunk/JLanguageTool/src/dev/org/languagetool/dev/conversion/RuleConverter.java
===================================================================
---
trunk/JLanguageTool/src/dev/org/languagetool/dev/conversion/RuleConverter.java
2012-01-29 11:54:14 UTC (rev 6370)
+++
trunk/JLanguageTool/src/dev/org/languagetool/dev/conversion/RuleConverter.java
2012-01-29 12:02:11 UTC (rev 6371)
@@ -232,7 +232,7 @@
public static ArrayList<String> fileToListNoBlanks(String filename) {
ArrayList<String> returnList = new ArrayList<String>();
Scanner in = null;
- InputStream is = null;
+ InputStream is;
try {
is =
JLanguageTool.getDataBroker().getFromResourceDirAsStream(filename);
in = new Scanner(is);
@@ -243,9 +243,11 @@
}
}
} catch (Exception e) {
- e.printStackTrace();
+ throw new RuntimeException("Could not load " + filename, e);
} finally {
+ if (in != null) {
in.close();
+ }
}
return returnList;
}
Modified:
trunk/JLanguageTool/src/dev/org/languagetool/dev/conversion/RuleConverterMain.java
===================================================================
---
trunk/JLanguageTool/src/dev/org/languagetool/dev/conversion/RuleConverterMain.java
2012-01-29 11:54:14 UTC (rev 6370)
+++
trunk/JLanguageTool/src/dev/org/languagetool/dev/conversion/RuleConverterMain.java
2012-01-29 12:02:11 UTC (rev 6371)
@@ -26,10 +26,10 @@
public class RuleConverterMain {
- private String grammarfile;
+ private String grammarFile;
private String specificFiletype;
- private String discardfile;
- private String disambigfile;
+ private String discardFile;
+ private String disambigFile;
private RuleConverter rc;
private static String[] supportedGeneralFiletypes = {"atd","cg"};
@@ -43,23 +43,23 @@
System.exit(1);
}
- private RuleConverterMain(String infilename, String grammarfile, String
discardfile, String disambigfile, String generalFiletype, String
specificFiletype) {
- this.grammarfile = grammarfile;
- this.specificFiletype = specificFiletype;
- this.disambigfile = disambigfile;
- this.discardfile = discardfile;
- if (generalFiletype.equals("atd")) {
- rc = new AtdRuleConverter(infilename, grammarfile,
specificFiletype);
- } else if (generalFiletype.equals("cg")) {
- rc = new CgRuleConverter(infilename, grammarfile,
specificFiletype);
+ private RuleConverterMain(String inFilename, String grammarFile, String
discardFile, String disambigFile, String generalFileType, String
specificFileType) {
+ this.grammarFile = grammarFile;
+ this.specificFiletype = specificFileType;
+ this.disambigFile = disambigFile;
+ this.discardFile = discardFile;
+ if (generalFileType.equals("atd")) {
+ rc = new AtdRuleConverter(inFilename, grammarFile,
specificFileType);
+ } else if (generalFileType.equals("cg")) {
+ rc = new CgRuleConverter(inFilename, grammarFile,
specificFileType);
}
}
private void run() throws IOException {
rc.parseRuleFile();
- // write out the grammar rules to grammarfile
- PrintWriter w = new PrintWriter(new OutputStreamWriter(new
FileOutputStream(grammarfile),"UTF-8"));
+ // write out the grammar rules to grammarFile
+ PrintWriter w = new PrintWriter(new OutputStreamWriter(new
FileOutputStream(grammarFile),"UTF-8"));
w.write("<rules>\n");
w.write("<category name=\"Auto-generated rules\">\n");
@@ -76,32 +76,36 @@
* this will have to be added back in once I have the general format
figured out
// evaluate the rules to see which are already covered
RuleCoverage checker = new RuleCoverage(Language.ENGLISH);
- checker.splitOutCoveredRules(grammarfile,discardfile);
+ checker.splitOutCoveredRules(grammarFile,discardFile);
*/
// for now, write the disambiguation rules to a default file
if (rc.disambiguationRules.size() > 0) {
- w = new PrintWriter(new OutputStreamWriter(new
FileOutputStream(disambigfile), "UTF-8"));
+ w = new PrintWriter(new OutputStreamWriter(new
FileOutputStream(disambigFile), "UTF-8"));
for (List<String> killedRule : rc.disambiguationRules) {
for (String line : killedRule) {
w.write(line + '\n');
}
}
w.close();
- System.out.println(Integer.toString(rc.disambiguationRules.size())
+ " disambiguation rules written to " + disambigfile);
+ System.out.println(Integer.toString(rc.disambiguationRules.size())
+ " disambiguation rules written to " + disambigFile);
}
}
public static void main(String[] args) throws IOException {
- String grammarfile = null;
- String rulefile = null;
- String specificFiletype = null; // type of rule, specific to filetype
(e.g. "avoid")
- String generalFiletype= null; // type of file, like the syntax of the
other system (e.g. "atd") - i know this is confusing and needs to be fixed
- String discardfile = null;
- String disambigfile = null;
+ String grammarFile = null;
+ String ruleFile = null;
+ String specificFileType = null; // type of rule, specific to filetype
(e.g. "avoid")
+ String generalFiletType= null; // type of file, like the syntax of the
other system (e.g. "atd") - i know this is confusing and needs to be fixed
+ String discardFile = null;
+ String disambigFile = null;
- // this doesn't work because the output rules file is not a legit
rules file
+ if (args.length < 4) {
+ exitWithUsageMessage();
+ }
+
+ // this doesn't work because the output rules file is not a legit
rules file
//TODO: fix this so we can have this functionality
try {
if (args[0].equals("--check")) {
@@ -111,77 +115,73 @@
System.exit(1);
}
} catch (Exception e) {
- e.printStackTrace();
+ throw new RuntimeException(e);
}
- if (args.length < 4) {
- exitWithUsageMessage();
- }
-
for (int i=0;i<args.length;i++) {
if (args[i].equals("-h") || args[i].equals("--help") ||
args[i].equals("--?") || args[i].equals("-help")) {
exitWithUsageMessage();
}
else if (args[i].equals("-s") ||
args[i].equals("--specificFiletype")) {
- specificFiletype = getSpecificFiletypeOrExit(args[++i]);
+ specificFileType = getSpecificFiletypeOrExit(args[++i]);
}
else if (args[i].equals("-g") ||
args[i].equals("--generalFiletype")) {
- generalFiletype = getGeneralFiletypeOrExit(args[++i]);
+ generalFiletType = getGeneralFiletypeOrExit(args[++i]);
}
else if (args[i].equals("--outputFile") || args[i].equals("-o")) {
- grammarfile = args[++i];
+ grammarFile = args[++i];
}
else if (args[i].equals("--discardFile") || args[i].equals("-d")) {
- discardfile = args[++i];
+ discardFile = args[++i];
}
else if (args[i].equals("--disambigFile") || args[i].equals("-a"))
{
- disambigfile = args[++i];
+ disambigFile = args[++i];
}
else if (args[i].equals("--inputFile") || args[i].equals("-i")) {
- rulefile = args[++i];
+ ruleFile = args[++i];
}
else {
System.err.println("Unknown option: " + args[i]);
exitWithUsageMessage();
}
}
- if (specificFiletype == null) {
- specificFiletype = "default";
+ if (specificFileType == null) {
+ specificFileType = "default";
}
- if (generalFiletype == null) {
- generalFiletype = "atd";
+ if (generalFiletType == null) {
+ generalFiletType = "atd";
}
- if (grammarfile == null) {
+ if (grammarFile == null) {
System.err.println("Need to specify a grammar file");
exitWithUsageMessage();
}
- if (rulefile == null) {
+ if (ruleFile == null) {
System.err.println("Need to specify a rule file");
exitWithUsageMessage();
}
- if (disambigfile == null) {
- disambigfile = "disambig.xml";
+ if (disambigFile == null) {
+ disambigFile = "disambig.xml";
}
- if (discardfile == null) {
- discardfile = "discard.xml";
+ if (discardFile == null) {
+ discardFile = "discard.xml";
}
- RuleConverterMain prg = new RuleConverterMain(rulefile, grammarfile,
discardfile, disambigfile, generalFiletype, specificFiletype);
+ RuleConverterMain prg = new RuleConverterMain(ruleFile, grammarFile,
discardFile, disambigFile, generalFiletType, specificFileType);
prg.run();
}
public static String getSpecificFiletypeOrExit(String arg) {
String type = null;
- boolean foundtype = false;
+ boolean foundType = false;
for (String s : supportedSpecificFiletypes) {
if (arg.equals(s)) {
type = s;
- foundtype = true;
+ foundType = true;
break;
}
}
- if (!foundtype) {
+ if (!foundType) {
System.out.println("Unknown specific filetype " + arg);
System.out.print("Supported filetypes are");
for (String s : supportedSpecificFiletypes) {
@@ -195,15 +195,15 @@
public static String getGeneralFiletypeOrExit(String arg) {
String type = null;
- boolean foundtype = false;
+ boolean foundType = false;
for (String s : supportedGeneralFiletypes) {
if (arg.equals(s)) {
type = s;
- foundtype = true;
+ foundType = true;
break;
}
}
- if (!foundtype) {
+ if (!foundType) {
System.out.println("Unknown general filetype " + arg);
System.out.print("Supported filetypes are");
for (String s : supportedGeneralFiletypes) {
Modified:
trunk/JLanguageTool/src/dev/org/languagetool/dev/conversion/RuleCoverage.java
===================================================================
---
trunk/JLanguageTool/src/dev/org/languagetool/dev/conversion/RuleCoverage.java
2012-01-29 11:54:14 UTC (rev 6370)
+++
trunk/JLanguageTool/src/dev/org/languagetool/dev/conversion/RuleCoverage.java
2012-01-29 12:02:11 UTC (rev 6371)
@@ -46,7 +46,6 @@
import org.languagetool.rules.patterns.Element;
import org.languagetool.rules.patterns.PatternRule;
import org.languagetool.rules.patterns.PatternRuleLoader;
-import org.languagetool.dev.conversion.RuleConverter;
public class RuleCoverage {
@@ -317,7 +316,7 @@
int numResets = 0;
while (numResets < 2) {
if (!dictIterator.hasNext()) {
- dictIterator = resetDictIter();
+ dictIterator = resetDictIterator();
numResets++;
}
String word = dictIterator.next().getWord().toString();
@@ -389,7 +388,7 @@
int numResets = 0;
while (numResets < 2) {
if (!dictIterator.hasNext()) {
- dictIterator = resetDictIter();
+ dictIterator = resetDictIterator();
numResets++;
}
String word = dictIterator.next().getWord().toString();
@@ -783,19 +782,18 @@
// ** DICTIONARY METHODS **
- private DictionaryIterator resetDictIter() {
+ private DictionaryIterator resetDictIterator() {
DictionaryIterator ret = null;
try {
ret = new DictionaryIterator(Dictionary.read(dictFile),
Charset.forName("utf8").newDecoder(), true);
} catch (IOException e) {
- e.printStackTrace();
+ throw new RuntimeException("Could not read " + dictFile, e);
}
return ret;
}
private IStemmer loadDictionary() throws IOException {
- IStemmer dictLookup = null;
- dictLookup = new DictionaryLookup(Dictionary.read(dictFile));
+ IStemmer dictLookup = new DictionaryLookup(Dictionary.read(dictFile));
return dictLookup;
}
@@ -806,7 +804,7 @@
language.getShortName() + "/" +
language.getName().toLowerCase() + ".dict";
dictFile = new File(filename);
dictLookup = (DictionaryLookup) loadDictionary();
- dictIterator = resetDictIter();
+ dictIterator = resetDictIterator();
} catch (IOException e) {
try {
// a different formulation of the filename
@@ -814,9 +812,9 @@
language.getShortName()
+ "/" + language.getName().toLowerCase() + ".dict";
dictFile = new File(filename);
dictLookup = (DictionaryLookup) loadDictionary();
- dictIterator = resetDictIter();
+ dictIterator = resetDictIterator();
} catch (IOException e2) {
- e2.printStackTrace();
+ throw new RuntimeException(e2);
}
}
}
Modified:
trunk/JLanguageTool/src/dev/org/languagetool/dev/conversion/gui/Main.java
===================================================================
--- trunk/JLanguageTool/src/dev/org/languagetool/dev/conversion/gui/Main.java
2012-01-29 11:54:14 UTC (rev 6370)
+++ trunk/JLanguageTool/src/dev/org/languagetool/dev/conversion/gui/Main.java
2012-01-29 12:02:11 UTC (rev 6371)
@@ -1073,7 +1073,7 @@
displayCoveredBy();
}
} catch (IOException e) {
- e.printStackTrace();
+ throw new RuntimeException(e);
}
}
Modified:
trunk/JLanguageTool/src/dev/org/languagetool/dev/conversion/gui/MainMenuBar.java
===================================================================
---
trunk/JLanguageTool/src/dev/org/languagetool/dev/conversion/gui/MainMenuBar.java
2012-01-29 11:54:14 UTC (rev 6370)
+++
trunk/JLanguageTool/src/dev/org/languagetool/dev/conversion/gui/MainMenuBar.java
2012-01-29 12:02:11 UTC (rev 6371)
@@ -221,7 +221,7 @@
try {
prg.writeRulesToFile();
} catch (IOException ex) {
- ex.printStackTrace();
+ throw new RuntimeException("Could not write rules to file", ex);
}
} else if (e.getActionCommand().equals(nextRuleText)) {
prg.nextRule();
Modified: trunk/JLanguageTool/src/java/org/languagetool/Main.java
===================================================================
--- trunk/JLanguageTool/src/java/org/languagetool/Main.java 2012-01-29
11:54:14 UTC (rev 6370)
+++ trunk/JLanguageTool/src/java/org/languagetool/Main.java 2012-01-29
12:02:11 UTC (rev 6371)
@@ -48,6 +48,9 @@
*/
class Main {
+ /* maximum file size to read in a single read */
+ private static final int MAX_FILE_SIZE = 64000;
+
private final boolean verbose;
private final boolean apiFormat;
private final boolean taggerOnly;
@@ -65,9 +68,6 @@
private List<BitextRule> bRules;
private Rule currentRule;
- /* maximum file size to read in a single read */
- private static final int MAX_FILE_SIZE = 64000;
-
Main(final boolean verbose, final boolean taggerOnly,
final Language language, final Language motherTongue,
final String[] disabledRules, final String[] enabledRules,
@@ -92,9 +92,13 @@
lt.activateDefaultFalseFriendRules();
selectRules(lt, disabledRules, enabledRules);
}
-
+
+ JLanguageTool getJLanguageTool() {
+ return lt;
+ }
+
private void selectRules(final JLanguageTool lt, final String[]
disabledRules, final String[] enabledRules) {
- // disable rules that are disabled explicitly:
+ // disable rules that are disabled explicitly:
for (final String disabledRule : disabledRules) {
lt.disableRule(disabledRule);
}
@@ -126,18 +130,18 @@
final String[] disabledRules, final String[] enabledRules) throws
IOException, ParserConfigurationException, SAXException {
bitextMode = true;
final Language target = lt.getLanguage();
- lt = new JLanguageTool(target, null);
+ lt = new JLanguageTool(target, null);
srcLt = new JLanguageTool(sourceLang);
lt.activateDefaultPatternRules();
selectRules(lt, disabledRules, enabledRules);
selectRules(srcLt, disabledRules, enabledRules);
bRules = Tools.getBitextRules(sourceLang, lt.getLanguage());
- List<BitextRule> bRuleList = new ArrayList<BitextRule>(bRules);
- for (final BitextRule br : bRules) {
+ List<BitextRule> bRuleList = new ArrayList<BitextRule>(bRules);
+ for (final BitextRule bitextRule : bRules) {
for (final String disabledRule : disabledRules) {
- if (br.getId().equals(disabledRule)) {
- bRuleList.remove(br);
+ if (bitextRule.getId().equals(disabledRule)) {
+ bRuleList.remove(bitextRule);
}
}
}
@@ -145,9 +149,9 @@
if (enabledRules.length > 0) {
bRuleList = new ArrayList<BitextRule>();
for (final String enabledRule : enabledRules) {
- for (final BitextRule br : bRules) {
- if (br.getId().equals(enabledRule)) {
- bRuleList.add(br);
+ for (final BitextRule bitextRule : bRules) {
+ if (bitextRule.getId().equals(enabledRule)) {
+ bRuleList.add(bitextRule);
}
}
}
@@ -155,10 +159,6 @@
}
}
- JLanguageTool getJLanguageTool() {
- return lt;
- }
-
private void runOnFile(final String filename, final String encoding,
final boolean listUnknownWords) throws IOException {
boolean oneTime = false;
@@ -296,7 +296,6 @@
}
}
} finally {
-
if (sb.length() > 0) {
matches = handleLine(matches, tmpLineOffset - 1, sb);
sentences += lt.getSentenceCount();
@@ -304,15 +303,14 @@
sentences += lt.sentenceTokenize(sb.toString()).size();
}
if (listUnknownWords && !taggerOnly) {
- for (String word : lt.getUnknownWords())
+ for (String word : lt.getUnknownWords()) {
if (!unknownWords.contains(word)) {
unknownWords.add(word);
}
+ }
}
}
-
printTimingInformation(listUnknownWords, rules, unknownWords,
ruleIndex, matches, sentences, startTime);
-
if (br != null) {
br.close();
}
@@ -323,7 +321,8 @@
}
}
- private InputStreamReader getInputStreamReader(String filename, String
encoding, InputStreamReader isr) throws UnsupportedEncodingException,
FileNotFoundException {
+ private InputStreamReader getInputStreamReader(String filename, String
encoding, InputStreamReader isr)
+ throws UnsupportedEncodingException, FileNotFoundException {
if (!"-".equals(filename)) {
final File file = new File(filename);
if (encoding != null) {
@@ -335,8 +334,7 @@
}
} else {
if (encoding != null) {
- isr = new InputStreamReader(new BufferedInputStream(System.in),
- encoding);
+ isr = new InputStreamReader(new BufferedInputStream(System.in),
encoding);
} else {
isr = new InputStreamReader(new BufferedInputStream(System.in));
}
@@ -402,8 +400,7 @@
}
private void runRecursive(final String filename, final String encoding,
- final boolean listUnknown) throws IOException,
- ParserConfigurationException, SAXException {
+ final boolean listUnknown) throws IOException,
ParserConfigurationException, SAXException {
final File dir = new File(filename);
if (!dir.isDirectory()) {
throw new IllegalArgumentException(dir.getAbsolutePath()
@@ -422,12 +419,8 @@
/**
* Loads filename and filters out XML. Note that the XML
* filtering can lead to incorrect positions in the list of matching rules.
- *
- * @param filename
- * @throws IOException
*/
- private String getFilteredText(final String filename, final String encoding)
- throws IOException {
+ private String getFilteredText(final String filename, final String encoding)
throws IOException {
if (verbose) {
lt.setOutput(System.err);
}
@@ -439,20 +432,25 @@
return StringTools.filterXML(fileContents);
}
- private static void exitWithUsageMessage() {
- System.out
- .println("Usage: java org.languagetool.Main "
- + "[-r|--recursive] [-v|--verbose] [-l|--language LANG]
[-m|--mothertongue LANG] [-d|--disable RULES] [-adl|--autoDetect] "
- + "[-e|--enable RULES] [-c|--encoding] [-u|--list-unknown]
[-t|--taggeronly] [-b] [--api] [-a|--apply] "
- + "[-b2|--bitext] <file>");
- System.exit(1);
+ private void changeLanguage(Language language, Language motherTongue,
+ String[] disabledRules, String[] enabledRules) {
+ try {
+ lt = new JLanguageTool(language, motherTongue);
+ lt.activateDefaultPatternRules();
+ lt.activateDefaultFalseFriendRules();
+ selectRules(lt, disabledRules, enabledRules);
+ if (verbose) {
+ lt.setOutput(System.err);
+ }
+ } catch (Exception e) {
+ throw new RuntimeException("Could not create LanguageTool instance for
language " + language, e);
+ }
}
/**
* Command line tool to check plain text files.
*/
- public static void main(final String[] args) throws IOException,
- ParserConfigurationException, SAXException {
+ public static void main(final String[] args) throws IOException,
ParserConfigurationException, SAXException {
if (args.length < 1 || args.length > 10) {
exitWithUsageMessage();
}
@@ -493,7 +491,7 @@
} else if (args[i].equals("-r") || args[i].equals("--recursive")) {
recursive = true;
} else if (args[i].equals("-b2") || args[i].equals("--bitext")) {
- bitext = true;
+ bitext = true;
} else if (args[i].equals("-d") || args[i].equals("--disable")) {
if (enabledRules.length > 0) {
throw new IllegalArgumentException("You cannot specify both enabled
and disabled rules");
@@ -539,7 +537,7 @@
throw new IllegalArgumentException("API format makes no sense for
automatic application of suggestions.");
}
} else if (args[i].equals("-p") || args[i].equals("--profile")) {
- profile = true;
+ profile = true;
if (apiFormat) {
throw new IllegalArgumentException("API format makes no sense for
profiling.");
}
@@ -548,7 +546,7 @@
}
if (taggerOnly) {
throw new IllegalArgumentException("Tagging makes no sense for
profiling.");
- }
+ }
} else if (i == args.length - 1) {
filename = args[i];
} else {
@@ -559,16 +557,16 @@
if (filename == null) {
filename = "-";
}
-
+
if (language == null) {
if (!apiFormat && !autoDetect) {
System.err.println("No language specified, using English");
- }
+ }
language = Language.ENGLISH;
} else if (!apiFormat && !applySuggestions) {
System.out.println("Expected text language: " + language.getName());
- }
-
+ }
+
language.getSentenceTokenizer().setSingleLineBreaksMarksParagraph(
singleLineBreakMarksParagraph);
final Main prg = new Main(verbose, taggerOnly, language, motherTongue,
@@ -590,6 +588,15 @@
}
}
+ private static void exitWithUsageMessage() {
+ System.out
+ .println("Usage: java org.languagetool.Main "
+ + "[-r|--recursive] [-v|--verbose] [-l|--language LANG]
[-m|--mothertongue LANG] [-d|--disable RULES] [-adl|--autoDetect] "
+ + "[-e|--enable RULES] [-c|--encoding] [-u|--list-unknown]
[-t|--taggeronly] [-b] [--api] [-a|--apply] "
+ + "[-b2|--bitext] <file>");
+ System.exit(1);
+ }
+
private static void checkArguments(String option, int argParsingPos,
String[] args) {
if (argParsingPos + 1 >= args.length) {
throw new IllegalArgumentException("Missing argument to " + option + "
command line option.");
@@ -602,13 +609,13 @@
final String text = StringTools.readFile(new FileInputStream(filename),
encoding);
return detectLanguageOfString(text);
}
-
+
private static Language detectLanguageOfString(String text) {
final LanguageIdentifier identifier = new LanguageIdentifier(text);
final Language lang =
Language.getLanguageForShortName(identifier.getLanguage());
return lang;
}
-
+
private static Language getLanguageOrExit(final String userSuppliedLangCode)
{
final Language language =
Language.getLanguageForShortName(userSuppliedLangCode);
if (language == null) {
@@ -623,19 +630,4 @@
return language;
}
- private void changeLanguage(Language language, Language motherTongue,
- String[] disabledRules, String[] enabledRules) {
- try {
- lt = new JLanguageTool(language, motherTongue);
- lt.activateDefaultPatternRules();
- lt.activateDefaultFalseFriendRules();
- selectRules(lt, disabledRules, enabledRules);
- if (verbose) {
- lt.setOutput(System.err);
- }
- } catch (Exception e) {
- throw new RuntimeException("Could not create LanguageTool instance for
language " + language, e);
- }
- }
-
}
This was sent by the SourceForge.net collaborative development platform, the
world's largest Open Source development site.
------------------------------------------------------------------------------
Try before you buy = See our experts in action!
The most comprehensive online learning library for Microsoft developers
is just $99.99! Visual Studio, SharePoint, SQL - plus HTML5, CSS3, MVC3,
Metro Style Apps, more. Free future releases when you subscribe now!
http://p.sf.net/sfu/learndevnow-dev2
_______________________________________________
Languagetool-cvs mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/languagetool-cvs