Non-Capturing groups in JAPE
Dears,
I wish to tag multiple phrases taking advantage of previous annotations, and expressivity of JAPE.
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).
Rule: TagManyPhrasesAtOnce
(
{Token.category != TO} ({Token.string =~ "any(one|body)"}{Token.string == "else"}) |
{Token.string == "glint"} |
{many more patterns} | .....
):tag --> RHS
Regards,
Emml.
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:
Dears,
I wish to tag multiple phrases taking advantage of previous annotations, and expressivity of JAPE.
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).
Rule: TagManyPhrasesAtOnce
(
{Token.category != TO} ({Token.string =~ "any(one|body)"}{Token.string == "else"}) |
{Token.string == "glint"} |
{many more patterns} | .....
):tag --> RHS
Regards,
Emml.
Hello,
Thank you, Yes I want it to be the context but only for the specific pattern (the first pattern in this case) and not the other patterns.
Rule: TagManyPhrasesAtOnce
(
{Token.category != TO}
)
(
({Token.string =~ "any(one|body)"}{Token.string == "else"}) | // [context for only this pattern]
{Token.string == "glint"} [not for this pattern] | // [context is NOT for this pattern]
{many more patterns} | ….. // [context is NOT for this pattern]
{many more patterns} | ….. // [other context, other patterns]
):tag --> RHS
Thank you
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:
Hello,
Thank you, Yes I want it to be the context but only for the specific pattern (the first pattern in this case) and not the other patterns.
Rule: TagManyPhrasesAtOnce
(
{Token.category != TO}
)
(
({Token.string =~ "any(one|body)"}{Token.string == "else"}) | // [context for only this pattern]
{Token.string == "glint"} [not for this pattern] | // [context is NOT for this pattern]
{many more patterns} | ….. // [context is NOT for this pattern]
{many more patterns} | ….. // [other context, other patterns]
):tag --> RHS
Thank you
-- Ian Roberts | Department of Computer Science i.roberts@... | University of Sheffield, UK
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:
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:
Hello,
Thank you, Yes I want it to be the context but only for the specific pattern (the first pattern in this case) and not the other patterns.
Rule: TagManyPhrasesAtOnce
(
{Token.category != TO}
)
(
({Token.string =~ "any(one|body)"}{Token.string == "else"}) | // [context for only this pattern]
{Token.string == "glint"} [not for this pattern] | // [context is NOT for this pattern]
{many more patterns} | ….. // [context is NOT for this pattern]
{many more patterns} | ….. // [other context, other patterns]
):tag --> RHS
Thank you
-- Ian Roberts | Department of Computer Science i.roberts@... | University of Sheffield, UK
-- Ian Roberts | Department of Computer Science i.roberts@... | University of Sheffield, UK
Thank you, for the support and Macro on RHS is new to me and useful.
Based on your suggestions so far below is a more precise problem description. The last suggestion will work but it means I will need a rule for every ContextAndPattern (they could be many)
Problem Statement
suggested Solution 1
wished solution 2 :
wished solution under existing constraints .... Just incase it better explains the problem or helps to arrive at a simpler solution.
Emml.
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:
Thank you, for the support and Macro on RHS is new to me and useful.
Based on your suggestions so far below is a more precise problem description. The last suggestion will work but it means I will need a rule for every ContextAndPattern (they could be many)
Problem Statement
Given below patternscontext1 pattern1context2 pattern2pattern3 context3context4 pattern4context5 pattern5ManyMoreContextAndPatternspattern6pattern7pattern8pattern8pattern9pattern10ManyMorePatternsI want to extract the patterns and give them the same tag.(pattern1, pattern2 ... pattern9, pattern10...) --> tag.theSametagsuggested Solution 1
Rule: context1Rule( {context1}({pattern1}):tag) --> :tag.cPatttern1Rule: context2Rule( {context2}({pattern2}):tag) --> :tag.cPatttern2Rule: 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|pattern6pattern7pattern8pattern9pattern10):tag --> :tag{ use context based RHS } //output theSameTag for all patterns.Thank you once again,
Emml.
-- Ian Roberts | Department of Computer Science i.roberts@... | University of Sheffield, UK