/** * Convenience method to add a pair of sentences: an incorrect sentence and the same sentence * with the error corrected. * @since 2.5 */ protected void addExamplePair(IncorrectExample incorrectSentence, CorrectExample correctSentence) { String correctExample = correctSentence.getExample(); int markerStart= correctExample.indexOf("<marker>"); int markerEnd = correctExample.indexOf("</marker>"); if (markerStart != -1 && markerEnd != -1) { List<String> correction = Collections.singletonList(correctExample.substring(markerStart + "<marker>".length(), markerEnd)); incorrectExamples.add(new IncorrectExample(incorrectSentence.getExample(), correction)); } else { incorrectExamples.add(incorrectSentence); } correctExamples.add(correctSentence); }
/** * Create an example text (usually just one sentence) without an error - the fixed error (compared to the text created * with {@link #wrong(String)}) can be marked with {@code <marker>...</marker>}. * @since 2.5, return type modified in 3.5 */ public static CorrectExample fixed(String example) { return new CorrectExample(example); }
for (CorrectExample goodSentenceObj : goodSentences) { String goodSentence = goodSentenceObj.getExample().replaceAll("[\\n\\t]+", ""); goodSentence = cleanXML(goodSentence); assertTrue(lang + ": Empty correct example in rule " + rule.getFullId(), goodSentence.trim().length() > 0);
case EXAMPLE: if (inCorrectExample) { correctExamples.add(new CorrectExample(correctExample.toString())); } else if (inIncorrectExample) { incorrectExamples.add(new IncorrectExample(incorrectExample.toString()));
/** * Convenience method to add a pair of sentences: an incorrect sentence and the same sentence * with the error corrected. * @since 2.5 */ protected void addExamplePair(IncorrectExample incorrectSentence, CorrectExample correctSentence) { String correctExample = correctSentence.getExample(); int markerStart= correctExample.indexOf("<marker>"); int markerEnd = correctExample.indexOf("</marker>"); if (markerStart != -1 && markerEnd != -1) { List<String> correction = Collections.singletonList(correctExample.substring(markerStart + "<marker>".length(), markerEnd)); incorrectExamples.add(new IncorrectExample(incorrectSentence.getExample(), correction)); } else { incorrectExamples.add(incorrectSentence); } correctExamples.add(correctSentence); }
case EXAMPLE: if (inCorrectExample) { correctExamples.add(new CorrectExample(correctExample.toString())); } else if (inIncorrectExample) { IncorrectExample example;
private static String getExampleSentences(Rule rule, ResourceBundle messages) { StringBuilder examples = new StringBuilder(200); List<IncorrectExample> incorrectExamples = rule.getIncorrectExamples(); if (incorrectExamples.size() > 0) { String incorrectExample = incorrectExamples.iterator().next().getExample(); String sentence = incorrectExample.replace("<marker>", "<span style='background-color:#ff8080'>").replace("</marker>", "</span>"); examples.append("<br/>").append(sentence).append(" <span style='color:red;font-style:italic;font-weight:bold'>x</span>"); } List<CorrectExample> correctExamples = rule.getCorrectExamples(); if (correctExamples.size() > 0) { String correctExample = correctExamples.iterator().next().getExample(); String sentence = correctExample.replace("<marker>", "<span style='background-color:#80ff80'>").replace("</marker>", "</span>"); examples.append("<br/>").append(sentence).append(" <span style='color:green'>✓</span>"); } else if (incorrectExamples.size() > 0) { IncorrectExample incorrectExample = incorrectExamples.iterator().next(); List<String> corrections = incorrectExample.getCorrections(); if (!corrections.isEmpty()) { String incorrectSentence = incorrectExamples.iterator().next().getExample(); String correctedSentence = incorrectSentence.replaceAll("<marker>.*?</marker>", "<span style='background-color:#80ff80'>" + corrections.get(0) + "</span>"); examples.append("<br/>").append(correctedSentence).append(" <span style='color:green'>✓</span>"); } } if (examples.length() > 0) { examples.insert(0, "<br/><br/>" + messages.getString("guiExamples")); } return examples.toString(); }
/** * Create an example text (usually just one sentence) without an error - the fixed error (compared to the text created * with {@link #wrong(String)}) can be marked with {@code <marker>...</marker>}. * @since 2.5, return type modified in 3.5 */ public static CorrectExample fixed(String example) { return new CorrectExample(example); }
g.writeStartObject(); g.writeStringField("status", "correct"); g.writeStringField("sentence", example.getExample()); g.writeEndObject();
case EXAMPLE: if (inCorrectExample) { correctExamples.add(new CorrectExample(correctExample.toString())); } else if (inIncorrectExample) { incorrectExamples.add(new IncorrectExample(incorrectExample.toString()));
case EXAMPLE: if (inCorrectExample) { correctExamples.add(new CorrectExample(correctExample.toString())); } else if (inIncorrectExample) { IncorrectExample example;