1

I have following text:

1 hwb wert: 330 kWh

In the first step, following mapping is tacking place:

330 kWh is mapped as: Lookup.major = "unit"

hwb wertis mapped as: Lookup.major = "keyword"

The JAPE Rules:

Phase: composedUnits
Input: Token Lookup
Options: control=appelt debug=true

Rule: TableRow
Priority:10
 (
  ({Lookup.majorType == "keyword"})
  ({Token.kind == punctuation})[0,4]
  ({Lookup.majorType == "unit"})
 )

Rule: ReversedTableRow
Priority: -2
(
 ({Token.kind == number})
 ({Lookup.majorType == "keyword"})
)

I can't understand why the ReversedTableRow-Rule is matched and not the TableRow.

Paul
  • 1,325
  • 2
  • 19
  • 41
  • 1
    Because the rules don't match the same text interval... – dedek Jul 21 '16 at 14:55
  • 1
    Btw `TableRow` cannot be matched on this text, because there is a colon (`:`) token in between the two Lookup-s – dedek Jul 21 '16 at 15:00
  • @dedek I updated the rule and still the other one is matched! If I remove the `reversedTableRow`rule, than the `tableRowRule`will be matched. What is now wrong? – Paul Jul 22 '16 at 06:04

1 Answers1

2

The appelt priorities work only for the same regions of text (e.g. earlier match wins and longer match wins). Text consumed by a previous rule cannot be matched by a later rule...

From the documentation:

With the appelt style, only one rule can be fired for the same region of text, according to a set of priority rules. Priority operates in the following way.

  1. From all the rules that match a region of the document starting at some point X, the one which matches the longest region is fired.
  2. If more than one rule matches the same region, the one with the highest priority is fired
  3. If there is more than one rule with the same priority, the one defined earlier in the grammar is fired.

...

Note also that depending on the control style, firing a rule may ‘consume’ that part of the text, making it unavailable to be matched by other rules. This can be a problem for example if one rule uses context to make it more specific, and that context is then missed by later rules, having been consumed due to use of for example the ‘Brill’ control style.



The rule TableRow can win as longer with following modification, note that I added the :tableRow label, which does not include the leading number token.

(
 ({Token.kind == number})?
 (
  ({Lookup.majorType == "keyword"})
  ({Token.kind == punctuation})[0,4]
  ({Lookup.majorType == "unit"})
 ):tableRow
)
dedek
  • 7,981
  • 3
  • 38
  • 68
  • thank you for your answer. is then there a way to solve it, other than by separating the rules in different files -> different phases? – Paul Jul 25 '16 at 08:52
  • @Paul Do you want `TableRow` to be fired and `ReversedTableRow` not to be fired on the example text? – dedek Jul 25 '16 at 08:56
  • @Paul : You can also have multiple phases in the same file. Just move `TableRow` to a separate first phase and inside of the `ReversedTableRow`, you can check something like `{Lookup.majorType == "keyword", !TableRow}` – dedek Jul 25 '16 at 09:12