Hi,

I've implemented a 'filter' element for XML which can be used to modify, 
keep, or reject a rule match. The first use case is a rule that checks 
if a weekday matches its date, e.g. "Monday, 7 October 2014" is 
inconsistent, as 2014-10-07 is not a Monday. The rule for that looks 
like this:

     <pattern>
         <token regexp="yes">&weekdays;</token>
         <token>,</token>
         <token regexp="yes">\d\d?</token>
         <token regexp="yes">&months;|&abbrevMonths;</token>
         <token regexp="yes">\d\d\d\d</token>
     </pattern>
     <filter class="org.languagetool.rules.en.DateCheckFilter" 
args="year:\5 month:\4 day:\3 weekDay:\1"/>
     <message>The date \3 \4 \5 is not a \1.</message>

The 'class' attribute refers to a Java class that implements the new 
RuleFilter interface. If this rule matches, the filter gets called with 
the 'args' attribute. Those "\5" etc. are actually the same items as in 
the message: they get replaced with the actual tokens that match the 
pattern. The rule filter can then modify the RuleMatch object or not, or 
it can return null. Returning null means that the rule match will be 
ignored. So this rule matches all dates of this format, and only keeps 
those rule matches where weekday and date do not match.

&weekdays;, &months;, and &abbrevMonths; are just XML entities that get 
expanded to "Monday|Tuesday|..." etc.

Please extend AbstractDateCheckFilter for your language and add rules to 
your grammar.xml if you want this check for your language.

If you have ideas how to implement this in a more clever way, or other 
comments, please let me know.

Regards
  Daniel


------------------------------------------------------------------------------
Slashdot TV.  
Video for Nerds.  Stuff that matters.
http://tv.slashdot.org/
_______________________________________________
Languagetool-devel mailing list
Languagetool-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/languagetool-devel

Reply via email to