def build_date_parser(parser_type=reparse.basic_parser): return reparse.parser( parser_type=parser_type, functions=python_functions, expressions_yaml_path=path+'expressions.yaml', patterns_yaml_path=path+'patterns.yaml' )
""" # Example stuff ----------------------------------------------------- # Have to add the parent directory just in case you # run this file in the demo directory without installing Reparse import sys sys.path.append('../..') # If file was imported, include that path path = "" if '__file__' in globals(): import os path = str(os.path.dirname(__file__)) if path: path += "/" # Reparse ---------------------------------------------------------- from examples.colortime.functions import functions import reparse colortime_parser = reparse.parser( parser_type=reparse.basic_parser, expressions_yaml_path=path + "expressions.yaml", patterns_yaml_path=path + "patterns.yaml", functions=functions ) if __name__ == "__main__": print(colortime_parser("~ ~ ~ go to the store ~ buy green at 11pm! ~ ~"))
# Filter on query object 'QueryFilter': SelectQueryFilter, 'QueryFilterLocation': SelectQueryFilter, # 'QueryLocationFilter': SelectQueryFilter } # Get current path. Note: This won't work when not run # from the project folder. Once the project is further # along we will change this. path = os.getcwd()+os.sep # Prepare Parser query_parser = reparse.parser( parser_type=reparse.alt_parser, expressions_yaml_path=path + "expressions.yaml", patterns_yaml_path=path + "patterns.yaml", functions=parsing_functions ) # Run query q = query_parser(query) # check if sucessful if q != []: q = q[0][0] else: print "Invalid Query" exit() # Select query if q['Action'] == 'select':
# Filter on query object 'QueryFilter': SelectQueryFilter, 'QueryFilterLocation': SelectQueryFilter, # 'QueryLocationFilter': SelectQueryFilter } # Get current path. Note: This won't work when not run # from the project folder. Once the project is further # along we will change this. path = os.getcwd() + os.sep # Prepare Parser query_parser = reparse.parser(parser_type=reparse.alt_parser, expressions_yaml_path=path + "expressions.yaml", patterns_yaml_path=path + "patterns.yaml", functions=parsing_functions) # Run query q = query_parser(query) # check if sucessful if q != []: q = q[0][0] else: print "Invalid Query" exit() # Select query if q['Action'] == 'select':
"CHP: New accident on Highway 17 in Scotts Valley, vehicle is in \"turning lane to Timber Ridge.\" Tow truck en route", "San Jose man gets prison for bizarre Wal-mart, Chevron crashes that injured 7", "Oakland: Authorities ID man who crashed into estuary near Oakland Airport", "San Leandro: No charges in fatal stabbing during robbery", "San Ramon: Woman killed by falling tree identified as travel blogger", "Richmond: Source of diesel spill at Point Isabel investigated", "Denver police horse dies after officer forgot he was tied in stall without food or water", "Denver police horse dies after officer forgot he was tied in stall without food or water", "San Jose man gets prison for bizarre Wal-mart, Chevron crashes that injured 7", "Pleasant Hill: Car crashes into building", "San Jose: Driver dies in Highway 87 crash near airport" ] path = os.getcwd() + "/" parse_title = reparse.parser(parser_type=reparse.basic_parser, expressions_yaml_path=path + "expressions.yml", patterns_yaml_path=path + "patterns.yml", functions=functions) WEIGHT_THRESHOLD = 15 def total_weight(matches): sum = 0 for m in matches: sum += m.weight return sum for a in article_titles: matches = parse_title(a) if matches is None:
from reparse_functions import functions import reparse colortime_parser = reparse.parser( \ parser_type = reparse.basic_parser, expressions_yaml_path = '/Users/jianfeng/git_pyparser/pyParser/reparse/' + 'expressions.yaml', patterns_yaml_path= '/Users/jianfeng/git_pyparser/pyParser/reparse/' + 'patterns.yaml', functions = functions) if __name__ == '__main__': print(colortime_parser("Orange at 11pm! ~ ~")) print(colortime_parser("~ ~ ~ go to the store ~ buy green at 11pm! ~ ~"))