Search in sources :

Example 1 with Experimental

use of org.languagetool.Experimental in project languagetool by languagetool-org.

the class RuleMatchesAsJsonSerializer method ruleMatchesToJson.

/**
   * @param incompleteResults use true to indicate that results are incomplete (e.g. due to a timeout) - a 'warnings'
   *                          section will be added to the JSON
   * @since 3.7
   */
@Experimental
public String ruleMatchesToJson(List<RuleMatch> matches, String text, int contextSize, Language lang, boolean incompleteResults) {
    ContextTools contextTools = new ContextTools();
    contextTools.setEscapeHtml(false);
    contextTools.setContextSize(contextSize);
    contextTools.setErrorMarkerStart(START_MARKER);
    contextTools.setErrorMarkerEnd("");
    StringWriter sw = new StringWriter();
    try {
        try (JsonGenerator g = factory.createGenerator(sw)) {
            g.writeStartObject();
            writeSoftwareSection(g);
            writeWarningsSection(g, incompleteResults);
            writeLanguageSection(g, lang);
            writeMatchesSection(g, matches, text, contextTools);
            g.writeEndObject();
        }
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
    return sw.toString();
}
Also used : StringWriter(java.io.StringWriter) JsonGenerator(com.fasterxml.jackson.core.JsonGenerator) IOException(java.io.IOException) Experimental(org.languagetool.Experimental)

Aggregations

JsonGenerator (com.fasterxml.jackson.core.JsonGenerator)1 IOException (java.io.IOException)1 StringWriter (java.io.StringWriter)1 Experimental (org.languagetool.Experimental)1