Package org.languagetool.markup
Class AnnotatedTextBuilder
- java.lang.Object
-
- org.languagetool.markup.AnnotatedTextBuilder
-
public class AnnotatedTextBuilder extends Object
Use this builder to create input of text with markup for LanguageTool, so that it can check only the plain text parts and ignore the markup, yet still calculate the positions of errors so that they refer to the complete text, including markup.It's up to you to split the input into parts that are plain text and parts that are markup.
For example, text with XML markup like
Here is <b>some text</b>
needs to be prepared like this:
new AnnotatedTextBuilder() .addText("Here is ").addMarkup("<b>").addText("some text").addMarkup("</b>") .build()
- Since:
- 2.3
-
-
Constructor Summary
Constructors Constructor Description AnnotatedTextBuilder()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description AnnotatedTextBuilder
addGlobalMetaData(String key, String value)
Add any global meta data about the document to be checked.AnnotatedTextBuilder
addGlobalMetaData(AnnotatedText.MetaDataKey key, String value)
Add global meta data like document title or receiver name (when writing an email).AnnotatedTextBuilder
addMarkup(String markup)
Add a markup text snippet like<b attr='something'>
or<div>
.AnnotatedTextBuilder
addMarkup(String markup, String interpretAs)
Add a markup text snippet like<b attr='something'>
or<div>
.AnnotatedTextBuilder
addText(String text)
Add a plain text snippet, to be checked by LanguageTool when usingJLanguageTool.check(AnnotatedText)
.AnnotatedText
build()
Create the annotated text to be passed intoJLanguageTool.check(AnnotatedText)
.
-
-
-
Method Detail
-
addGlobalMetaData
public AnnotatedTextBuilder addGlobalMetaData(AnnotatedText.MetaDataKey key, String value)
Add global meta data like document title or receiver name (when writing an email). Some rules may use this information.- Since:
- 3.9
-
addGlobalMetaData
public AnnotatedTextBuilder addGlobalMetaData(String key, String value)
Add any global meta data about the document to be checked. Some rules may use this information. Unless you're using your own rules for which you know useful keys, you probably want to useaddGlobalMetaData(AnnotatedText.MetaDataKey, String)
.- Since:
- 3.9
-
addText
public AnnotatedTextBuilder addText(String text)
Add a plain text snippet, to be checked by LanguageTool when usingJLanguageTool.check(AnnotatedText)
.
-
addMarkup
public AnnotatedTextBuilder addMarkup(String markup)
Add a markup text snippet like<b attr='something'>
or<div>
. These parts will be ignored by LanguageTool when usingJLanguageTool.check(AnnotatedText)
.
-
addMarkup
public AnnotatedTextBuilder addMarkup(String markup, String interpretAs)
Add a markup text snippet like<b attr='something'>
or<div>
. These parts will be ignored by LanguageTool when usingJLanguageTool.check(AnnotatedText)
.- Parameters:
interpretAs
- A string that will be used by the checker instead of the markup. This is usually whitespace, e.g.\n\n
for<p>
-
build
public AnnotatedText build()
Create the annotated text to be passed intoJLanguageTool.check(AnnotatedText)
.
-
-