Package org.languagetool.language

Examples of org.languagetool.language.English


 
  public void testFilter() throws Exception {
    final String input = "How do you thin?";

    final TokenStream stream = new AnyCharTokenizer(TEST_VERSION_CURRENT, new StringReader(input));
    final LanguageToolFilter filter = new LanguageToolFilter(stream, new JLanguageTool(new English()), false);
    //displayTokensWithFullDetails(filter);

    assertTokenStreamContents(filter, new String[] { "_POS_SENT_START", "How", "_POS_WRB", "do",
        "_POS_VBP", "_POS_VB", "you", "_POS_PRP", "thin", "_POS_VBP", "_POS_VB", "_POS_JJ", "?",
        "_POS_SENT_END" }, new int[] { 0, 0, 0, 4, 4, 4, 7, 7, 11, 11, 11, 11, 15, 15 }, new int[] {
View Full Code Here


    // comment in to test with external index:
    //directory = new SimpleFSDirectory(new File("/media/external-disk/corpus/languagetool/fast-rule-evaluation-de/"));
    //errorSearcher = new Searcher(directory);
   
    // TODO: make this work for all languages
    final Language language = new English();
    //final Language language = new French();
    //final Language language = new Spanish();
    //final Language language = new Polish(); // TODO: still "Clauses must have same field"
    //final Language language = new German();
    final JLanguageTool lt = new JLanguageTool(language);
View Full Code Here

  public void testIndexerSearcherWithEnglish() throws Exception {
    // Note that the second sentence ends with "lid" instead of "lids" (the inflated one)
    createIndex("How to move back and fourth from linux to xmb? Calcium deposits on eye lid.");
    SearcherResult searcherResult =
            errorSearcher.findRuleMatchesOnIndex(getRule("BACK_AND_FOURTH"), new English());
    assertEquals(2, searcherResult.getCheckedSentences());
    assertEquals(false, searcherResult.isResultIsTimeLimited());
    assertEquals(1, searcherResult.getMatchingSentences().size());

    searcherResult = errorSearcher.findRuleMatchesOnIndex(getRule("EYE_BROW"), new English());
    assertEquals(2, searcherResult.getCheckedSentences());
    assertEquals(false, searcherResult.isResultIsTimeLimited());
    assertEquals(1, searcherResult.getMatchingSentences().size());

    searcherResult = errorSearcher.findRuleMatchesOnIndex(getRule("ALL_OVER_THE_WORD"), new English());
    assertEquals(2, searcherResult.getCheckedSentences());
    assertEquals(false, searcherResult.isResultIsTimeLimited());
    assertEquals(0, searcherResult.getMatchingSentences().size());

    try {
      errorSearcher.findRuleMatchesOnIndex(getRule("Invalid Rule Id"), new English());
      fail("Exception should be thrown for invalid rule id.");
    } catch (PatternRuleNotFoundException expected) {}
  }
View Full Code Here

    createIndex("How to move back and fourth from linux to xmb?");
    final List<Element> elements = Arrays.asList(
            new Element("move", false, false, false),
            new Element("back", false, false, false)
    );
    final PatternRule rule1 = new PatternRule("RULE1", new English(), elements, "desc", "msg", "shortMsg");
    final Searcher errorSearcher = new Searcher(directory);
    final SearcherResult searcherResult = errorSearcher.findRuleMatchesOnIndex(rule1, new English());
    assertEquals(1, searcherResult.getCheckedSentences());
    assertEquals(1, searcherResult.getMatchingSentences().size());
    final List<RuleMatch> ruleMatches = searcherResult.getMatchingSentences().get(0).getRuleMatches();
    assertEquals(1, ruleMatches.size());
    final Rule rule = ruleMatches.get(0).getRule();
View Full Code Here

    createIndex("How to move back and fourth from linux to xmb?");
    final List<Element> elements = Arrays.asList(
            new Element("move", false, false, false),
            new Element("forth|back", false, true, false)
    );
    final PatternRule rule1 = new PatternRule("RULE1", new English(), elements, "desc", "msg", "shortMsg");
    final Searcher errorSearcher = new Searcher(directory);
    final SearcherResult searcherResult = errorSearcher.findRuleMatchesOnIndex(rule1, new English());
    assertEquals(1, searcherResult.getCheckedSentences());
    assertEquals(1, searcherResult.getMatchingSentences().size());
    final List<RuleMatch> ruleMatches = searcherResult.getMatchingSentences().get(0).getRuleMatches();
    assertEquals(1, ruleMatches.size());
    final Rule rule = ruleMatches.get(0).getRule();
View Full Code Here

    final List<Element> elements1 = Arrays.asList(
            new Element("Bleed", false, false, false),
            new Element("'", false, false, false),
            new Element("s", false, false, false)
    );
    final PatternRule rule1 = new PatternRule("RULE1", new English(), elements1, "desc", "msg", "shortMsg");

    final List<Element> elements2 = Arrays.asList(
            new Element("Bleed", false, false, false),
            new Element("'", false, false, false),
            new Element("x", false, false, false)
    );
    final PatternRule rule2 = new PatternRule("RULE", new English(), elements2, "desc", "msg", "shortMsg");

    final SearcherResult searcherResult1 = errorSearcher.findRuleMatchesOnIndex(rule1, new English());
    assertEquals(1, searcherResult1.getMatchingSentences().size());
    final List<RuleMatch> ruleMatches = searcherResult1.getMatchingSentences().get(0).getRuleMatches();
    assertEquals(1, ruleMatches.size());
    final Rule rule = ruleMatches.get(0).getRule();
    assertEquals("RULE1", rule.getId());

    final SearcherResult searcherResult2 = errorSearcher.findRuleMatchesOnIndex(rule2, new English());
    assertEquals(0, searcherResult2.getMatchingSentences().size());
  }
View Full Code Here

    exceptionElem.setStringPosException("exception", false, false, false, false, false, "POS", false, false);
    final List<Element> elements = Arrays.asList(
            new Element("move", false, false, false),
            exceptionElem
    );
    final PatternRule rule1 = new PatternRule("RULE1", new English(), elements, "desc", "msg", "shortMsg");
    final Searcher errorSearcher = new Searcher(directory);
    final SearcherResult searcherResult = errorSearcher.findRuleMatchesOnIndex(rule1, new English());
    assertEquals(1, searcherResult.getCheckedSentences());
    assertEquals(1, searcherResult.getMatchingSentences().size());
    final List<RuleMatch> ruleMatches = searcherResult.getMatchingSentences().get(0).getRuleMatches();
    assertEquals(1, ruleMatches.size());
    final Rule rule = ruleMatches.get(0).getRule();
View Full Code Here

    final List<Element> elements = Arrays.asList(
            negatedElement,
            new Element("How", false, false, false)
    );
    final Searcher errorSearcher = new Searcher(directory);
    final PatternRule rule1 = new PatternRule("RULE1", new English(), elements, "desc", "msg", "shortMsg");
    final SearcherResult searcherResult = errorSearcher.findRuleMatchesOnIndex(rule1, new English());
    assertEquals(1, searcherResult.getCheckedSentences());
    assertEquals(1, searcherResult.getMatchingSentences().size());
    final List<RuleMatch> ruleMatches = searcherResult.getMatchingSentences().get(0).getRuleMatches();
    assertEquals(1, ruleMatches.size());
    final Rule rule = ruleMatches.get(0).getRule();
View Full Code Here

    final Element exceptionElem = new Element("", false, true, false);
    exceptionElem.setStringPosException("exception", false, false, false, false, false, "POS", false, false);
    final List<Element> elements = Arrays.asList(
            exceptionElem
    );
    final PatternRule rule1 = new PatternRule("RULE1", new English(), elements, "desc", "msg", "shortMsg");
    final Searcher errorSearcher = new Searcher(directory);
    try {
      errorSearcher.findRuleMatchesOnIndex(rule1, new English());
      fail();
    } catch (UnsupportedPatternRuleException expected) {
    }
  }
View Full Code Here

  }

  private void createIndex(String content) throws IOException {
    directory = new RAMDirectory();
    //directory = FSDirectory.open(new File("/tmp/lucenetest"));  // for debugging
    Indexer.run(content, directory, new English(), false);
    errorSearcher = new Searcher(directory);
  }
View Full Code Here

TOP

Related Classes of org.languagetool.language.English

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.