private void assertBad(String s, int n, String... expectedSuggestions) throws IOException { RuleMatch[] matches = rule.match(langTool.getAnalyzedSentence(s)); assertEquals("Did not find " + n + " match(es) in sentence '" + s + "'", n, matches.length); if (expectedSuggestions.length > 0) { RuleMatch match = matches[0]; // When two errors are reported by the rule (so TODO above), it might happen that the first // match does not have the suggestions, but the second one if (matches.length > 1 && match.getSuggestedReplacements().size() == 0) { match = matches[1]; } List<String> suggestions = match.getSuggestedReplacements(); assertThat(suggestions, is(Arrays.asList(expectedSuggestions))); } }
public static void main(String[] args) throws TwitterException, IOException { Twitter twitter = TwitterFactory.getSingleton(); JLanguageTool langTool = new JLanguageTool(new AmericanEnglish()); List<String> twts = new ArrayList<String>(); for (String arg : args) { Query query = new Query(arg); QueryResult result; int counter = 0; do { result = twitter.search(query); List<Status> tweets = result.getTweets(); for (Status tweet : tweets) { if (isEligible(tweet)) { System.out.println("@" + tweet.getUser().getScreenName() + " - " + tweet.getText()); System.out.println(tweet.getLang()); twts.add(tweet.getText()); counter++; } } } while ((query = result.nextQuery()) != null && counter < 5); } for (String str : twts) { List<RuleMatch> matches = langTool.check(str); for (RuleMatch match : matches) { System.out.println( "Potential error at line " + match.getLine() + ", column " + match.getColumn() + ": " + match.getMessage()); System.out.println("Suggested correction: " + match.getSuggestedReplacements()); } } }
private void assertBad(String s, String... expectedSuggestions) throws IOException { RuleMatch[] matches = rule.match(langTool.getAnalyzedSentence(s)); assertEquals("Did not find one match in sentence '" + s + "'", 1, matches.length); if (expectedSuggestions.length > 0) { RuleMatch match = matches[0]; List<String> suggestions = match.getSuggestedReplacements(); assertThat(suggestions, is(Arrays.asList(expectedSuggestions))); } }