def test_ranking_parser_whitespace_partial_token_matches(): expected_result = ("The_orange_cat", "The_grey_cat") rp = RankingParser() result = rp.parse_statements([ "The orange cat before The grey cat", ]) assert (result == expected_result)
def test_ranking_parser_whitespace_partial_token_matches_missed_capital(): expected_result = ("The_orange_cat", "Grey_cat") rp = RankingParser() result = rp.parse_statements([ "The orange cat is before the Grey cat", ]) assert (result == expected_result)
def solve_challenge(): rl = RankingLexer() hl = HighLighter(rl, STYLE_MAP) print() for s in programmer_riddle: print(hl.highlight(s)) print() print("Solving by specifying rules") print(Fore.CYAN + ("=" * 30) + Fore.RESET) r = RankingProblem() r.set_items(["Jessie", "Evan", "John", "Sarah", "Matt"]).\ not_first("Jessie").not_last("Evan").\ not_first("John").not_last("John").\ is_before("Sarah", "Evan").\ not_directly_before_or_after("Matt", "John").\ not_directly_before_or_after("John", "Evan") solutions = r.solve() for s in solutions: typewrite_print(", ".join(s)) print() print("Solving by parsing") print(Fore.CYAN + ("=" * 30) + Fore.RESET) rp = RankingParser() typewrite_print(", ".join(rp.parse_statements(programmer_riddle)))
def test_ranking_parser_parse_whitespace_in_brackets(): expected_result = ("Captain_Blackbeard", "Long_John_Silver") rp = RankingParser() result = rp.parse_statements([ "[Captain Blackbeard] is not last", "[Long John Silver] is not first" ]) assert (result == expected_result)
def test_ranking_parser_parse_whitespace_no_brackets_multiline(): expected_result = [("Walk_the_dog", "Feed_the_cat")] rp = RankingParser() rp.build() rp.parse("""Walk the dog is not last Feed the cat is not first""") result = rp.solve() assert (result == expected_result)
def __init__(self, project_id=None, log_history=True): self.generated_project = True self.log_history = log_history self.project_id = None self.set_project_id(project_id) self._rp = RankingParser() self._rl = RankingLexer() self.lexer = self._rl.build() self._rp.build() self._hl = HighLighter(self._rl, STYLE_MAP) self.history = list() self.pp = pprint.PrettyPrinter(indent=4)
def test_ranking_parser_parse_statements(): expected_result = ( "Sarah", "John", "Jessie", "Evan", "Matt", ) rp = RankingParser() result = rp.parse_statements(programmer_riddle) print(result) assert (result == expected_result)
def test_ranking_parser_multi_line_input(): multi_line_input = """ [Green] before [Red] [Yellow] before [Green] """ expected_result = [("Yellow", "Green", "Red")] rp = RankingParser() rp.build() rp.parse(multi_line_input) assert (rp.solve() == expected_result)
def generate_viz_from_statements( statements: List[str], output_dot_viz: str = None, max_pen_width=12, ): rp = RankingParser() rp.build() for step in statements: rp.parse(step) solutions = rp.solve() return generate_viz_from_solutions(solutions, output_dot_viz, max_pen_width=max_pen_width)
def test_ranking_parser_parse_add_entity_statements(): rp = RankingParser() expected_result = [ "George_Harrison", "John_Lennon", "Paul_McCartney", "Ringo_Starr", ] result = rp.parse_statements([ "+[Ringo Starr]", "John Lennon", "[Paul McCartney]", "+George Harrison", ]) assert (sorted(result) == expected_result)
def test_export_csv(): test = RankingParser() lines = None filename = str(uuid.uuid1()) filename = f"{filename}.csv" solutions = test.parse_statements(tea_steps, return_last_parsed=False) try: export_csv(solutions, filename) with open(filename, "r") as txt_file: lines = txt_file.readlines() finally: os.remove(filename) assert ("".join(lines) == tea_steps_result_csv)
def test_ranking_parser_parse_statements_no_statements(): rp = RankingParser() with pytest.raises(IncompleteResultsError): rp.parse_statements([])
def test_can_create_rule_parser(): rp = RankingParser() assert (isinstance(rp, RankingParser))
def test_ranking_parser_parse_statements_no_statements(): rp = RankingParser() result = rp.parse_statements([]) assert (result is None)
def reset_ranking_parser(self): self._rp = RankingParser() self._rp.build()