0

我想要的是解析日期的三个组成部分,将每个组成部分存储到自己的注释中,然后创建一个复杂的结构,代表整个日期。我尝试了以下方法,但没有奏效。

DECLARE Annotation CommDate (Annotation CMonth, Annotation CDate, Annotation CYear);    
DECLARE Annotation CommenceMonth;
DECLARE Annotation CommenceYear;
DECLARE Annotation CommenceDate;

    NUM{REGEXP("[0-3]?[0-9]?") -> MARK(CommenceMonth)};
    CommenceMonth SPECIAL NUM{REGEXP("[0-3]?[0-9]?") -> MARK(CommenceDate)};
    CommenceDate SPECIAL NUM{REGEXP("19..|20..") -> MARK(CommenceYear)};

    CommenceMonth CommenceDate CommenceYear {-> CREATE(CommDate, 1,2,3, "CMonth" = 1, "CDate" = 2,  "CYear" = 3) };

当我用类似“2014 年 12 月 31 日”的内容输入它时,虽然为三个 CommenceXXX 注释分配了值,但复杂的结构 CommDate 却没有。

4

1 回答 1

1

The first problem is that your last rule for creating the complex annotation missed the slashes (SPECIAL). The slashes are not part of the other annotations thus the last rule is not able to match on a follow-of CommenceDate since there is none yet, but a slash. The rule would work if either the slashes are included in the annotations CommenceDate and CommenceYear, or if the last rule includes the slashes in ther sequential pattern: CommenceMonth SPECIAL CommenceDate SPECIAL CommenceYear....

The second problem is the wrong usage of the CREATE action. The annotation values of features are assigned in the CREATE action using the type since this action tries to find the annoations within the matched context. The index of the rule elements is used in the GATHER action for assigning annoations outside of the matched context of the rule elements.

You could rewrite your last rule, for example, in these ways for solving your problem:

Using the action GATHER:

CommenceMonth SPECIAL CommenceDate SPECIAL CommenceYear 
    {-> GATHER(CommDate, 1, 5, "CMonth" = 1, "CDate" = 3,  "CYear" = 5) };

Using the action CREATE:

CommenceMonth SPECIAL CommenceDate SPECIAL CommenceYear 
    {-> CREATE(CommDate, 1, 5, "CMonth" = CommenceMonth, "CDate" = CommenceDate,  "CYear" = CommenceYear) };

A more compact representation of the example could be (using a bit different code style, but the same pattern):

DECLARE Month, Day, Year;
DECLARE Annotation Date (Month month, Day day, Year year);    
(NUM{REGEXP("[0-3]?[0-9]?") -> Month} SPECIAL NUM{REGEXP("[0-3]?[0-9]?")-> Day} 
  SPECIAL NUM{REGEXP("19..|20..") -> Year}){-> CREATE(Date, "month" = Month, "day" = Day, "year" = Year)};
于 2014-04-02T09:08:23.727 回答