Search in sources :

Example 1 with AnnotatedTextBuilder

use of org.languagetool.markup.AnnotatedTextBuilder in project languagetool by languagetool-org.

the class JLanguageToolTest method testAnnotateTextCheckMultipleSentences.

@Test
public void testAnnotateTextCheckMultipleSentences() throws IOException {
    JLanguageTool languageTool = new JLanguageTool(english);
    AnnotatedText annotatedText = new AnnotatedTextBuilder().addMarkup("<b>").addText("here").addMarkup("</b>").addText(" is an error. And ").addMarkup("<i attr='foo'>").addText("here is also").addMarkup("</i>").addText(" a error.").build();
    List<RuleMatch> matches = languageTool.check(annotatedText);
    assertThat(matches.size(), is(2));
    assertThat(matches.get(0).getFromPos(), is(3));
    assertThat(matches.get(0).getToPos(), is(7));
    assertThat(matches.get(1).getFromPos(), is(60));
    assertThat(matches.get(1).getToPos(), is(61));
}
Also used : RuleMatch(org.languagetool.rules.RuleMatch) AnnotatedTextBuilder(org.languagetool.markup.AnnotatedTextBuilder) AnnotatedText(org.languagetool.markup.AnnotatedText) Test(org.junit.Test)

Example 2 with AnnotatedTextBuilder

use of org.languagetool.markup.AnnotatedTextBuilder in project languagetool by languagetool-org.

the class JLanguageToolTest method testAnnotateTextCheckMultipleSentences2.

@Test
public void testAnnotateTextCheckMultipleSentences2() throws IOException {
    JLanguageTool languageTool = new JLanguageTool(english);
    AnnotatedText annotatedText = new AnnotatedTextBuilder().addText("here").addText(" is an error. And ").addMarkup("<i attr='foo'/>").addText("here is also ").addMarkup("<i>").addText("a").addMarkup("</i>").addText(" error.").build();
    List<RuleMatch> matches = languageTool.check(annotatedText);
    assertThat(matches.size(), is(2));
    assertThat(matches.get(0).getFromPos(), is(0));
    assertThat(matches.get(0).getToPos(), is(4));
    assertThat(matches.get(1).getFromPos(), is(53));
    assertThat(matches.get(1).getToPos(), is(54));
}
Also used : RuleMatch(org.languagetool.rules.RuleMatch) AnnotatedTextBuilder(org.languagetool.markup.AnnotatedTextBuilder) AnnotatedText(org.languagetool.markup.AnnotatedText) Test(org.junit.Test)

Example 3 with AnnotatedTextBuilder

use of org.languagetool.markup.AnnotatedTextBuilder in project languagetool by languagetool-org.

the class PedlerCorpus method makeAnnotatedText.

private AnnotatedText makeAnnotatedText(String pseudoXml) {
    AnnotatedTextBuilder builder = new AnnotatedTextBuilder();
    StringTokenizer tokenizer = new StringTokenizer(pseudoXml, "<>", true);
    boolean inMarkup = false;
    while (tokenizer.hasMoreTokens()) {
        String part = tokenizer.nextToken();
        if (part.startsWith("<")) {
            builder.addMarkup(part);
            inMarkup = true;
        } else if (part.startsWith(">")) {
            inMarkup = false;
            builder.addMarkup(part);
        } else {
            if (inMarkup) {
                builder.addMarkup(part);
            } else {
                builder.addText(part);
            }
        }
    }
    return builder.build();
}
Also used : StringTokenizer(java.util.StringTokenizer) AnnotatedTextBuilder(org.languagetool.markup.AnnotatedTextBuilder)

Example 4 with AnnotatedTextBuilder

use of org.languagetool.markup.AnnotatedTextBuilder in project languagetool by languagetool-org.

the class JLanguageToolTest method testAnnotateTextCheckPlainText.

@Test
public void testAnnotateTextCheckPlainText() throws IOException {
    JLanguageTool languageTool = new JLanguageTool(english);
    AnnotatedText annotatedText = new AnnotatedTextBuilder().addText("A good sentence. But here's a error.").build();
    List<RuleMatch> matches = languageTool.check(annotatedText);
    assertThat(matches.size(), is(1));
    assertThat(matches.get(0).getFromPos(), is(28));
    assertThat(matches.get(0).getToPos(), is(29));
}
Also used : RuleMatch(org.languagetool.rules.RuleMatch) AnnotatedTextBuilder(org.languagetool.markup.AnnotatedTextBuilder) AnnotatedText(org.languagetool.markup.AnnotatedText) Test(org.junit.Test)

Example 5 with AnnotatedTextBuilder

use of org.languagetool.markup.AnnotatedTextBuilder in project languagetool by languagetool-org.

the class JLanguageToolTest method testAnnotateTextCheck.

@Test
public void testAnnotateTextCheck() throws IOException {
    JLanguageTool languageTool = new JLanguageTool(english);
    AnnotatedText annotatedText = new AnnotatedTextBuilder().addMarkup("<b>").addText("here").addMarkup("</b>").addText(" is an error").build();
    List<RuleMatch> matches = languageTool.check(annotatedText);
    assertThat(matches.size(), is(1));
    assertThat(matches.get(0).getFromPos(), is(3));
    assertThat(matches.get(0).getToPos(), is(7));
}
Also used : RuleMatch(org.languagetool.rules.RuleMatch) AnnotatedTextBuilder(org.languagetool.markup.AnnotatedTextBuilder) AnnotatedText(org.languagetool.markup.AnnotatedText) Test(org.junit.Test)

Aggregations

AnnotatedTextBuilder (org.languagetool.markup.AnnotatedTextBuilder)7 Test (org.junit.Test)4 AnnotatedText (org.languagetool.markup.AnnotatedText)4 RuleMatch (org.languagetool.rules.RuleMatch)4 HashSet (java.util.HashSet)1 StringTokenizer (java.util.StringTokenizer)1