Search in sources :

Example 1 with Match

use of org.languagetool.rules.patterns.Match in project languagetool by languagetool-org.

the class BitextPatternRuleHandler method endElement.

@Override
public void endElement(String namespaceURI, String sName, String qName) throws SAXException {
    switch(qName) {
        case RULE:
            trgRule.setMessage(message.toString());
            for (Match m : suggestionMatches) {
                trgRule.addSuggestionMatch(m);
            }
            if (phrasePatternTokens.size() <= 1) {
                suggestionMatches.clear();
            }
            BitextPatternRule bRule = new BitextPatternRule(srcRule, trgRule);
            bRule.setCorrectBitextExamples(correctExamples);
            bRule.setIncorrectBitextExamples(incorrectExamples);
            bRule.setSourceLanguage(srcLang);
            rules.add(bRule);
            break;
        case SRC_EXAMPLE:
            srcExample = setExample();
            break;
        case TRG_EXAMPLE:
            trgExample = setExample();
            break;
        case SOURCE:
            srcRule = finalizeRule();
            break;
        case TARGET:
            trgRule = finalizeRule();
            break;
        case EXAMPLE:
            if (inCorrectExample) {
                correctExamples.add(new StringPair(srcExample.getExample(), trgExample.getExample()));
            } else if (inIncorrectExample) {
                StringPair examplePair = new StringPair(srcExample.getExample(), trgExample.getExample());
                if (trgExample.getCorrections().isEmpty()) {
                    incorrectExamples.add(new IncorrectBitextExample(examplePair));
                } else {
                    List<String> corrections = trgExample.getCorrections();
                    incorrectExamples.add(new IncorrectBitextExample(examplePair, corrections));
                }
            }
            inCorrectExample = false;
            inIncorrectExample = false;
            inErrorTriggerExample = false;
            break;
        default:
            super.endElement(namespaceURI, sName, qName);
            break;
    }
}
Also used : StringPair(org.languagetool.bitext.StringPair) ArrayList(java.util.ArrayList) List(java.util.List) IncorrectBitextExample(org.languagetool.rules.bitext.IncorrectBitextExample) Match(org.languagetool.rules.patterns.Match)

Example 2 with Match

use of org.languagetool.rules.patterns.Match in project languagetool by languagetool-org.

the class MatchTest method testSpeller.

@Test
public void testSpeller() throws Exception {
    //tests with synthesizer
    Match match = getMatch("POS1", "POS2", true);
    final Polish polish = new Polish();
    MatchState matchState = new MatchState(match, polish.getSynthesizer());
    matchState.setToken(getAnalyzedTokenReadings("inflectedform11", "POS1", "Lemma1"));
    //getting empty strings, which is what we want
    assertEquals("[]", Arrays.toString(matchState.toFinalString(polish)));
    // contrast with a speller = false!
    match = getMatch("POS1", "POS2", false);
    matchState = new MatchState(match, polish.getSynthesizer());
    matchState.setToken(getAnalyzedTokenReadings("inflectedform11", "POS1", "Lemma1"));
    assertEquals("[(inflectedform11)]", Arrays.toString(matchState.toFinalString(polish)));
    //and now a real word - we should get something
    match = getMatch("subst:sg:acc.nom:m3", "subst:sg:gen:m3", true);
    matchState = new MatchState(match, polish.getSynthesizer());
    matchState.setToken(getAnalyzedTokenReadings("AON", "subst:sg:acc.nom:m3", "AON"));
    assertEquals("[AON-u]", Arrays.toString(matchState.toFinalString(polish)));
    //and now pure text changes        
    match = getTextMatch("^(.*)$", "$0-u", true);
    match.setLemmaString("AON");
    matchState = new MatchState(match, polish.getSynthesizer());
    assertEquals("[AON-u]", Arrays.toString(matchState.toFinalString(polish)));
    match.setLemmaString("batalion");
    //should be empty
    matchState = new MatchState(match, polish.getSynthesizer());
    assertEquals("[]", Arrays.toString(matchState.toFinalString(polish)));
    match.setLemmaString("ASEAN");
    //and this one not
    matchState = new MatchState(match, polish.getSynthesizer());
    assertEquals("[ASEAN-u]", Arrays.toString(matchState.toFinalString(polish)));
}
Also used : Polish(org.languagetool.language.Polish) MatchState(org.languagetool.rules.patterns.MatchState) Match(org.languagetool.rules.patterns.Match) Test(org.junit.Test)

Aggregations

Match (org.languagetool.rules.patterns.Match)2 ArrayList (java.util.ArrayList)1 List (java.util.List)1 Test (org.junit.Test)1 StringPair (org.languagetool.bitext.StringPair)1 Polish (org.languagetool.language.Polish)1 IncorrectBitextExample (org.languagetool.rules.bitext.IncorrectBitextExample)1 MatchState (org.languagetool.rules.patterns.MatchState)1