Skip to content

Instantly share code, notes, and snippets.

@takahi-i
Last active May 9, 2016 12:52
Show Gist options
  • Save takahi-i/d4bb579dd1cd493fde3af9de3bcc6e32 to your computer and use it in GitHub Desktop.
Save takahi-i/d4bb579dd1cd493fde3af9de3bcc6e32 to your computer and use it in GitHub Desktop.

Rule Validator

This validator checks a set of rules writers should adherre. The rules are written in the YAML format.

Format of Rules

In the rule file there are three block lang, name and pattern. Users specify target languages, and the name of the validator in lang and name blocks respectivly. In patterns block, users add the specific rules as pattern block. pattern block has block token or exp.

- lang: en
- name: redundant-expression-en

- patterns:
   - pattern:
     - toekn: is
     - token: considered
   - pattern:
     - token: it
     - token: is
     - token: *
     - token: that
   - pattern:
     - token: as
     - token: *
       - gap:
         - min: 1
         - max: 100
     - token: as
     - token: well
- lang: en
- name: redundant-expression-en

- patterns:
   - pattern:
     - toekn: *
       - exceptions:
         - token: is
         - token: are
         - token:
             - label[1]: V
     - token: considered
- lang: ja
- name: redundant-expression-ja

- pattern:
   - pattern:
       - regex: (する|した)ことが可能
   - pattern: だと考えられる
   - pattern:
     - token: で
     - token:
       - regex: あ(る|った)
       - label[1]: 助動詞
     - token: *
       - optional: true
     - token: かも
       - label[1]: 副詞

Validator configuration

RuleValidator contains a set of default rules for each language. When users want to suppress the validation with the specific rules, specify the rules in "remove" property. Add add property when users want to self defined rules (the rules are stored in $REDPEN_HOME/rule directory).

<redpen-conf lang="en">
    <validators>
        <validator name="Rule">
            <property name="suppress" value="redundant,tense"/>
            <property name="path" value="./" />
        </validator>
    </validators>
</redpen-conf>

Properties

  1. suppress: suppress the specified rules
  2. path: load user defined rules from the specified path
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment