Skip to content

Commit

Permalink
RedPen class is reverted not to use state variable, with a new valida…
Browse files Browse the repository at this point in the history
…te interface
  • Loading branch information
norm-ideal committed Oct 20, 2020
1 parent 4705c11 commit aa31d0e
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 8 deletions.
2 changes: 1 addition & 1 deletion redpen-cli/src/main/java/cc/redpen/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ public static int run(String... args) throws RedPenException {
String resultFormat = "plain";
String inputSentence = null;
String language = "en";
String threshold = "info";
String threshold = "error";

int limit = DEFAULT_LIMIT;

Expand Down
18 changes: 13 additions & 5 deletions redpen-core/src/main/java/cc/redpen/RedPen.java
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,6 @@ public class RedPen {
private final SentenceExtractor sentenceExtractor;
private final List<Validator> validators;

private String errorLevel = "info";
public void setErrorLevel( String level ) { errorLevel = level; };

/**
* constructs RedPen with specified config file.
*
Expand Down Expand Up @@ -143,7 +140,7 @@ public List<Document> parse(DocumentParser parser, File[] files) throws RedPenEx
* @return list of validation errors
*/
public Map<Document, List<ValidationError>> validate(List<Document> documents) {
return validate(documents, errorLevel);
return validate(documents, "error");
}

/**
Expand All @@ -165,12 +162,23 @@ public Map<Document, List<ValidationError>> validate(List<Document> documents, S
}

/**
* validate the input document collection. Note that this method call is NOT thread safe. RedPen instances need to be crated for each thread.
* validate the input document. Note that this method call is NOT thread safe. RedPen instances need to be crated for each thread.
*
* @param document document to be validated
* @return list of validation errors
*/
public List<ValidationError> validate(Document document) {
return validate(document, "error");
}

/**
* validate the input document. Note that this method call is NOT thread safe. RedPen instances need to be crated for each thread.
*
* @param document document to be validated
* @param threshold threshold of error level
* @return list of validation errors
*/
public List<ValidationError> validate(Document document, String threshold) {
List<Document> documents = new ArrayList<>();
documents.add(document);
Map<Document, List<ValidationError>> documentListMap = validate(documents);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,9 +110,8 @@ public Response validateDocument(@FormParam("document") @DefaultValue("") String
} else {
redPen = new RedPen(new ConfigurationLoader().secure().loadFromString(config));
}
redPen.setErrorLevel( errorLevel );
Document parsedDocument = redPen.parse(DocumentParser.of(documentParser), document);
List<ValidationError> errors = redPen.validate(parsedDocument);
List<ValidationError> errors = redPen.validate(parsedDocument, errorLevel);

Formatter formatter = FormatterUtils.getFormatterByName(format);

Expand Down

0 comments on commit aa31d0e

Please sign in to comment.