question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Parsing structures that are in the middle of a sentence- INFO request

See original GitHub issue

I am wondering how to parse the structures that are in the middle of a sentence.

Consider this example.

"Please join me on Fifteenth of May 2017 at three PM for a cup of coffee."

Here, I have the lark grammar to parse date -> "Fifteenth of May 2017 at three PM" Where the structure needs to parse is inside a sentence.
Is it possible to create a rule that can search for a pattern and parse it ?

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:15 (8 by maintainers)

github_iconTop GitHub Comments

1reaction
arunespkucommented, Dec 18, 2018
from lark import Lark

grammar = """
    status : /.*/ starter /.*/
    starter: STARTER? [date]
    STARTER: /(?:[a-zA-Z'-]+[^a-zA-Z'-]+){1,20}/

     date: [relative][number] [bet][dayes] [part] [month] [year] [hour]
     number: NUMBER [dayes] 
     part: PART
     month: [bet] MONTH [number] [bet] [MONTH]
     relative: RELATIVE
     year: YEAR
     hour: [number] [relative] HOUR
     HOUR:"hours"|"hrs"|"hour"
     dayes:  [PART][NUMBER][RELATIVE]DAYES [bet] [DAYES] [NUMBER] [PART][MONTH] [NUMBER] [partday]
     partday: [relative]PARTDAY
     bet:BET
     BET: "between"|"to"
     DAYES:"day"|"monday"|"tuesday"|"wednesday"|"saturday"|"sunday"|"friday"|"thursday"|"today"|"tommorrow"
     NUMBER:"first"|"second"|"third"|"fourth"|"fifth"|"seventh"|" twentith"
     |"eighth"|"one"|"two"|"three"|"four"|"five"
     PART: "of"|"in"|"at"
     MONTH: "January"|"February"|"March"|"April"|"May"|"June"|"July"|"August"|"Spetember"|"October"|"November"|"December"
     RELATIVE: "before"|"after" |"every"|"from"|"begining"|"end"|"by"
     YEAR: "two thousand eight"|"two thousand nine"|"two thousand seventeen"|"two thousand eighteen"|"two thousand ninteen"
     PARTDAY: "morning"|"evening"|"afternoon"|"midnight"
     
       
  
   %import common.WS
   %import common.ESCAPED_STRING
    %ignore WS
"""

parser = Lark(grammar, parser='earley', start ='status', lexer= 'dynamic_complete' )  in parse tree!
st = " Hello monday afternoon parse me"
tree = parser.parse(st)
print(tree)

File "parsingdemo.py", line 61, in <module>
    parser = Lark(grammar, parser='earley', start ='status', lexer= 'dynamic_complete' )  # Explicit ambiguity in parse tree!
  File "/home/../anaconda3/lib/python3.6/site-packages/lark/lark.py", line 165, in __init__
    self.parser = self._build_parser()
  File "/home/../anaconda3/lib/python3.6/site-packages/lark/lark.py", line 188, in _build_parser
    return self.parser_class(self.lexer_conf, parser_conf, options=self.options)
  File "/home/../anaconda3/lib/python3.6/site-packages/lark/parser_frontends.py", line 122, in __init__
    super(self).__init__(*args, complete_lex=True, **kw)

This leads to an error.

1reaction
erezshcommented, Dec 18, 2018

Only works with parser="earley", lexer="dynamic_complete"

Read more comments on GitHub >

github_iconTop Results From Across the Web

8. Analyzing Sentence Structure
The simplest kind of parser interprets a grammar as a specification of how to break a high-level goal into several lower-level subgoals. The...
Read more >
Constituency Parsing
Syntactic parsing is the task of assigning a syntactic structure to a sentence. This chapter focuses on constituency structures, those assigned by ...
Read more >
Analyze Sentence Structure Using Grammatical ...
Grammatical dependency parsing is the process of identifying the grammatic structure of a sentence by highlighting the dependencies between the words of the ......
Read more >
Parse a sentence
Type your sentence, and hit "Submit" to parse it. ... "Allow Null Links" selected, the parser will assign structure to as much of...
Read more >
Designing a BASIC Parser for CALL
BAP (BASIC parser) is described in terms of input processing, which normalizes the sentence; word-matching, which matches it against key structure words and ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found