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));
}
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));
}
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();
}
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));
}
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));
}
Aggregations