Non-Capturing groups in JAPE
Emml Asimadi
Dears, I need a rule like below that tags many phrases at once.... but I don't want to match the "red" pattern {Token.category != TO} even though it is important finding the desirable match (green).
( {Token.category != TO} ({Token.string =~ "any(one|body)"}{Token.string == "else"}) | {Token.string == "glint"} |
):tag --> RHS |
|
Diana Maynard
Hi
toggle quoted message
Show quoted text
Do you mean you want the red pattern to be part of the context but not included in the span of the annotation? If so, just move the round brackets that your tag label is attached to, to exclude that bit. Rule: TagManyPhrasesAtOnce ( {Token.category != TO} ) ( ({Token.string =~ "any(one|body)"}{Token.string == "else"}) {Token.string == "glint"} | {many more patterns} | ….. ):tag --> RHS Diana On 16 Jul 2018, at 10:41, easimadi via Groups.Io <easimadi@...> wrote: |
|
Emml Asimadi
Hello,
|
|
Ian Roberts
You can't put the same :tag label on
two different parts of the same rule, so the easiest way to
approach this would probably be to split this into two separate
rules with the :tag in the appropriate place on each - if the RHS
is complex you can define it as a macro to save having to type it
out twice:
Macro: TAG_PHRASES :tag.Something = {} // or whatever the RHS is Rule: AnybodyElse ( {Token.category != TO} ({Token.string =~ "any(one|body)"}{Token.string == "else"}):tag ) --> TAG_PHRASES Rule: OtherPhrases ( {Token.string == "glint"} | {another pattern} | ... ):tag --> TAG_PHRASES Ian On 16/07/2018 12:20, easimadi via Groups.Io wrote:
-- Ian Roberts | Department of Computer Science i.roberts@... | University of Sheffield, UK |
|
Ian Roberts
Alternatively, add an extra Phase to
your grammar before this one that just looks for the "anyone else"
bit in the right context and annotates that
Rule: AnybodyElse ( {Token.category != TO} ({Token.string =~ "any(one|body)"}{Token.string == "else"}):tag ) --> :tag.AnyoneElse = {} Then add AnyoneElse to the Input line of your main phase and use that in your main rule (at which point you don't need to check the context as that was done by the earlier phase) Rule: OtherPhrases ( {AnyoneElse} | {Token.string == "glint"} | {another pattern} | ... ):tag --> (original RHS) When you're developing big JAPE grammars it's good discipline to think first in terms of how you can break the overall problem down into smaller, simpler rules across phases, and try to keep each individual rule as simple as possible. If you can get used to developing your grammars in this way you'll find they are easier to understand and debug in future (and often faster to run as well). Ian On 16/07/2018 12:39, Ian Roberts wrote:
-- Ian Roberts | Department of Computer Science i.roberts@... | University of Sheffield, UK |
|
Emml Asimadi
Thank you, for the support and Macro on RHS is new to me and useful. Problem Statement
Given below patterns
context1 pattern1
context2 pattern2
pattern3 context3
context4 pattern4
context5 pattern5
ManyMoreContextAndPatterns
pattern6
pattern7
pattern8
pattern8
pattern9
pattern10
ManyMorePatterns
I want to extract the patterns and give them the same tag.
(pattern1, pattern2 ... pattern9, pattern10...) --> tag.theSametag
suggested Solution 1Rule: context1Rule
( {context1}
({pattern1}):tag
) --> :tag.cPatttern1
Rule: context2Rule
( {context2}
({pattern2}):tag
) --> :tag.cPatttern2
Rule: MainPatternRules
({cPattern1} | {cpattern2} | {pattern6} | {pattern7}) :tag --> tag.theSameTag
wished solution 2 :wished solution under existing constraints .... Just incase it better explains the problem or helps to arrive at a simpler solution. (
{context1}({pattern1}):p1|
{context2}({pattern2}):p2|
{context3}({pattern3}):p3|
pattern6
pattern7
pattern8
pattern9
pattern10
):tag --> :tag{ use context based RHS } //output theSameTag for all patterns.
Thank you once again, Emml. |
|
Ian Roberts
There's no reason why you couldn't just
have one rule for each pattern and create TheSameTag directly in
them all:
Macro: ADD_TAG :tag.TheSameTag = {...} Rule: Patt1 ( {context1} ({pattern1}):tag ) --> ADD_TAG Rule: Patt2 ( {context2} ({pattern2}):tag ) --> ADD_TAG Rule: Patt6 ( {pattern6} ):tag --> ADD_TAG // etc. etc. On 16/07/2018 14:52, Emml Asimadi via Groups.Io wrote:
-- Ian Roberts | Department of Computer Science i.roberts@... | University of Sheffield, UK |
|