def structured_query(query_string): try: node_tree = grammar.parse(query_string) except IncompleteParseError: query_string = fix_quotes(query_string) node_tree = grammar.parse(query_string) return DictFormater().visit(node_tree)
def from_raw_query(cls, query_string): """Given a raw string (typically typed by the user), parse to a structured format and initialize the class. """ try: node_tree = grammar.parse(query_string) except IncompleteParseError: query_string = cls.fix_quotes(query_string) node_tree = grammar.parse(query_string) structured_query = DictFormater().visit(node_tree) return cls(structured_query)
def from_raw_query(cls, query_string): """Parse raw string to query. Given a raw string (typically typed by the user), parse to a structured format and initialize the class. """ try: node_tree = grammar.parse(query_string) except IncompleteParseError: query_string = cls.fix_quotes(query_string) node_tree = grammar.parse(query_string) structured_query = DictFormater().visit(node_tree) return cls( [t for t in structured_query if t[1].lower() not in STOPWORDS])