Skip to content

Commit

Permalink
enabled redpen-server to accept error level threshold
Browse files Browse the repository at this point in the history
  • Loading branch information
norm-ideal committed Sep 20, 2020
1 parent cf5336a commit f01cf2e
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 2 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 = "error";
String threshold = "info";

int limit = DEFAULT_LIMIT;

Expand Down
5 changes: 4 additions & 1 deletion redpen-core/src/main/java/cc/redpen/RedPen.java
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@ 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 @@ -140,7 +143,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, "error");
return validate(documents, errorLevel);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ public class RedPenResource {
private static final String DEFAULT_LANG = "en";
private static final String DEFAULT_CONFIGURATION = "en";
private static final String DEFAULT_FORMAT = "json";
private static final String DEFAULT_ERROR_LEVEL = "error";

/*package*/ static final String MIME_TYPE_XML = "application/xml; charset=utf-8";
/*package*/ static final String MIME_TYPE_JSON = "application/json; charset=utf-8";
Expand Down Expand Up @@ -99,6 +100,7 @@ public Response validateDocument(@FormParam("document") @DefaultValue("") String
@FormParam("documentParser") @DefaultValue(DEFAULT_DOCUMENT_PARSER) String documentParser,
@FormParam("lang") @DefaultValue(DEFAULT_CONFIGURATION) String lang,
@FormParam("format") @DefaultValue(DEFAULT_FORMAT) String format,
@FormParam("errorLevel") @DefaultValue(DEFAULT_ERROR_LEVEL) String errorLevel,
@FormParam("config") String config) throws RedPenException {

LOG.info("Validating document");
Expand All @@ -108,6 +110,7 @@ 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);

Expand Down

0 comments on commit f01cf2e

Please sign in to comment.