def comb_source(file_name, tables_needed, cols_needed=[0]):
    count = 0
    cur_table = ""
    tables_got = defaultdict(bool)
    for x in tables_needed:
        tables_got[x] = False
    bn = os.path.basename(file_name)
    with open(file_name) as file:
        for (line_count, line) in enumerate(file, 1):
            if line.startswith("table of"):
                temp_table = re.sub(" *\[.*", "", line.strip())
                if (not len(tables_needed)) or temp_table in tables_got:
                    if tables_got[temp_table]:
                        print("WARNING duplicate table start", temp_table, bn,
                              line_count)
                    cur_table = temp_table
                    cur_table_start = line_count + 1
                    tables_got[temp_table] = True
                continue
            if not line.strip():
                cur_table = ""
            if not cur_table: continue
            if line_count == cur_table_start: continue  # get rid of header row
            ary = line.split("\t")
            err_list = []
            for col in cols_needed:
                hom_cand = ' '.join(ary[col].split('"')[1::2])
                a2 = hom_cand.split(" ")
                hom_got = []
                if '"' in ary[2]:
                    hom_got = ary[2][1:-1].split("|")
                for q in a2:
                    if q in hom.hom_list:
                        if q in hom_ignore: continue
                        if q in already_got and ignore_already_got: continue
                        need_hom = False
                        for x in hom.hom_list[q]:
                            if x in hom_got or x in hom_ignore: continue
                            need_hom = True
                            err_list.append(x)
                        if need_hom:
                            count += 1
                            print(
                                "{}: {}{} <{}> line {} col {} in <{}>/{} may need homophone: {}."
                                .format(
                                    count, "(already got) " if q in already_got
                                    else "", q, bn, line_count, col, cur_table,
                                    ary[col], ", ".join(err_list)))
                            already_got[q] = line_count
                            mt.add_postopen_file_line(file_name, line_count)
    if len(already_got):
        print("Summary of stuff to replace in {}: {}.",
              ', '.format(bn, join(sorted(already_got))))
    else:
        print("Nothing to replace in", bn)
    for x in tables_got:
        if not tables_got[x]: print("Did not find", x, "in", bn)
def get_ups():  # make sure up-(min/reg) isn't anywhere it shouldn't be
    new_rule = "<NO RULE YET>"
    rule_line = 0
    count = 0
    in_vr_rules = False
    out_of_place = []
    with open("story.ni") as file:
        for (line_count, line) in enumerate(file, 1):
            if in_vr_rules and is_outline_start(line):
                in_vr_rules = False
                in_vr_end = line_count
                continue
            if line.startswith("section vc vr rules"):
                in_vr_rules = True
                in_vr_start = line_count
            if not in_vr_rules and (line.startswith("this is the vr-")
                                    or line.startswith("this is the vc-")):
                out_of_place.append("OUT OF PLACE rule {0} at line {1}".format(
                    line.strip(), line_count))
            if not line.startswith("\t"):
                if not line.startswith("["):
                    new_rule = line.strip()
                    new_rule = re.sub(":.*", "", new_rule)
                    rule_line = line_count
            else:
                ls = line.strip()
                if ls.startswith("up-"):
                    if new_rule in ignore_rule: continue
                    count += 1
                    print("RULE", count, rule_line, new_rule)
                    print("    UP/DOWN", line_count, ls)
                    if "vc" in new_rule:
                        print("UH OH NEW RULE NEEDS ERASING.")
                        mt.add_postopen_file_line("story.ni", line_count, True)
                    else:
                        mt.add_postopen_file_line("story.ni", line_count)
    if len(out_of_place):
        print("vc vr rules between", in_vr_start, "and", in_vr_end)
        print("\n".join(out_of_place))
    else:
        print("Go me, or former me! All the vc/vr rules are ORGANIZED.")
    mt.postopen_files()
Beispiel #3
0
def check_invisiclues_vs_walkthrough():
    fname = "c:/writing/scripts/invis/vv.txt"
    in_invisiclues = defaultdict(int)
    first_invis = defaultdict(str)
    dubs = 0
    last_dup_comment = -1
    with open(fname) as file:
        for (line_count, line) in enumerate(file, 1):
            if "#duphint" in line: last_dup_comment = line_count
            for q in list(got_detail['nec']) + list(got_detail['opt']):
                if q.upper() in line:
                    if q in in_invisiclues:
                        if last_dup_comment == line_count - 1:
                            last_dup_comment = -1
                            continue
                        if last_dup_comment != -1:
                            print("Mistaken duphint line {} after {}.".format(
                                line_count, last_dup_comment))
                            mt.add_postopen_file_line(fname, line_count)
                            continue
                        dubs += 1
                        print(
                            "Potential double {} {} {} vs {}: {} / {}".format(
                                dubs, q.upper(), line_count, in_invisiclues[q],
                                line.strip(), first_invis[q]))
                        mt.add_postopen_file_line(fname, line_count)
                    else:
                        first_invis[q] = line.strip()
                    in_invisiclues[q] = line_count
            if last_dup_comment == line_count - 1:
                print(
                    "Uh oh, had a duphint which didn't precede any point scoring command at line {}."
                    .format(line_count))
                mt.add_postopen_file_line(fname, line_count)
    count = tot = 0
    for x in got_detail['nec']:
        if x not in in_invisiclues:
            count += 1
            tot += 1
            print(
                count, tot,
                "Necessary command {} not found in invisiclues.".format(
                    x.upper()))
    count = 0
    for x in got_detail['opt']:
        if x not in in_invisiclues:
            count += 1
            tot += 1
            print(
                count, tot,
                "Optional command {} not found in invisiclues.".format(
                    x.upper()))
    if last_dup_comment != -1:
        print("Unacknowledged duplicate comment at line {}.".format(
            last_dup_comment))
Beispiel #4
0
def check_any_or_dupe(my_line, my_dict, search_string, line_count):
    if not my_line.startswith("#" + search_string + " "): return False
    my_test = re.sub(".*?test +", "", my_line.strip())
    if my_test not in my_dict:
        print("Undefined test case {} for <{}> at line {} in {}.".format(
            my_test, search_string, line_count, rbr))
        mt.add_postopen_file_line(rbr, line_count)
        return True
    elif ' retest' in search_string and my_dict[my_test] == -1:
        print("Bogus duplicate test case {} for <{}> at line {} in {}.".format(
            my_test, search_string, line_count, rbr))
        mt.add_postopen_file_line(rbr, line_count, priority=9)
        return True
    elif ' test' in search_string and my_dict[my_test] > -1:
        print("Duplicate test case {} for <{}> at line {} in {}.".format(
            my_test, search_string, line_count, rbr))
        mt.add_postopen_file_line(rbr, line_count, priority=9)
        return True
    return False
Beispiel #5
0
def check_multiple_command_tests():
    need_base_test = defaultdict(int)
    need_mult_test = defaultdict(int)
    skip_cols = False
    in_verb_table = False
    fatal_error = 0
    with open(fin) as file:
        for (line_count, line) in enumerate(file, 1):
            if line.startswith("table of verb checks"):
                skip_cols = True
                in_verb_table = True
                continue
            if skip_cols:
                skip_cols = False
                continue
            if not in_verb_table: continue
            if not line.strip():
                in_verb_table = False
                continue
            tary = line.strip().split("\t")
            if True:
                if tary[topic_column].startswith('"'):
                    got_first = False
                    if '|' in tary[topic_column]:
                        print(
                            "OOPS need / not | at line {}".format(line_count))
                        sys.exit()
                    for q0 in i7.topx2ary(tary[topic_column]):
                        #print("C8 {} Need to verify {}".format(line_count, q0))
                        if got_first:
                            need_mult_test[q0] = 0
                        else:
                            need_base_test[q0] = 0
                        got_first = True
                elif '/' in tary[0] or '/' in tary[1]:
                    print(
                        "UH OH fatal error: need | and not / at line {} for {} and {}"
                        .format(line_count, tary[0], tary[1]))
                    fatal_error = 1
                    mt.add_postopen_file_line(fin, line_count)
                    continue
                elif '|' in tary[0] or '|' in tary[1]:
                    tz = (tary[0] + " " + tary[1]).replace('"', '')
                    if '/' in tz:
                        sys.exit(
                            "OOPS need | not / at line {}".format(line_count))
                    got_first = False
                    temp = i7.topx2ary(tz, div_char='|')
                    for q0 in temp:
                        #print("C1/2 {} Need to verify {}".format(line_count, q0))
                        if got_first:
                            need_mult_test[q0] = 0
                        else:
                            need_base_test[q0] = 0
                        got_first = True
                #sys.exit("Uh oh bad table line read {} len={} {}.".format(line_count, len(tary), tary))
    if fatal_error:
        mt.postopen_files()
    in_alt_verbs = False
    skip_next = False
    mult_err = 0
    need_byone = False
    need_undo = False
    rbr = i7.rbr()
    with open(rbr) as file:
        for (line_count, line) in enumerate(file, 1):
            if need_byone:
                if not line.startswith('by one point'):
                    print("Need -by one point- at line {}: {}.".format(
                        line_count, line.strip()))
                need_byone = False
                need_undo = True
                continue
            if need_undo:
                if not line.startswith(">") or 'undo' not in line:
                    print("Need -undo- at line {}: {}.".format(
                        line_count, line.strip()))
                need_undo = False
                continue
            if 'okdup' in line:
                skip_next = True
                continue
            if skip_next:
                skip_next = False
                continue
            if line.startswith("==t3") or line.startswith("@alt"):
                in_alt_verbs = True
                continue
            if in_alt_verbs and not line.strip():
                in_alt_verbs = False
                continue
            if not in_alt_verbs: continue
            if not line.startswith(">"): continue
            my_cmd = re.sub("^> *", "", line.strip().lower())
            if my_cmd == 'undo' or my_cmd == 'z': continue
            if my_cmd not in need_mult_test:
                mult_err += 1
                print(
                    mult_err, "Bad command {} at {} line {}.".format(
                        my_cmd, rbr, line_count))
            else:
                need_mult_test[my_cmd] += 1
                need_byone = True
    for x in sorted(need_mult_test):
        if need_mult_test[x] == 0:
            mult_err += 1
            if verbose_code:
                print("@alt\n> {}\nby one point\n>undo".format(x))
            else:
                print(mult_err, "No mult-cmd test for", x)
        elif need_mult_test[x] > 1:
            mult_err += 1
            print(mult_err, "Multiple mult-cmd test for", x)
    if mult_err: print(mult_err, "total multiple command test file errors")
    else: print("ALL MULTIPLE COMMANDS HAVE TEST CASE!")
Beispiel #6
0
        if ' ' in mist_quote:
            my_stuff = mist_quote.split(' ')
            mist_array = [
                "{} {}".format(x, y) for x in my_stuff[0].split("/")
                for y in my_stuff[1].split("/")
            ]
        else:
            mist_array = [mist_quote]
        for x in mist_array:
            if x in mist_done:
                print("<{}>".format(mist_quote), x, "in line", line_count,
                      "section",
                      cur_sec + ("/" + subsection if subsection else ""),
                      "is duplicated from", mist_done[x], "section",
                      mist_sec[x])
                mt.add_postopen_file_line(mi, line_count, rewrite=False)
                total_errs += 1
                if cur_sec == 'TO-DO':
                    errs_todo += 1
                else:
                    errs_table += 1
            else:
                mist_done[x] = line_count
                mist_sec[x] = cur_sec + ("/" +
                                         subsection if subsection else "")

cmd_count = 1
while cmd_count < len(sys.argv):
    arg = mt.nohy(sys.argv[cmd_count])
    if arg[:2] == 's:':
        search_for_opening(r'\[start (of )?{}\b'.format(arg[2:]))
def check_vc_rules(
):  # count # of rule succeeds/fails in VC rules. There should be 1.
    out_file = open("story.niv", "w", newline="\n")
    in_vc = False
    in_vr = False
    got_succeeds_yet = 0
    got_fails_yet = 0
    rule_start_line = 0
    rule_name = "<NO RULE>"
    mult_succ = 0
    mult_fail = 0
    no_succ = 0
    no_fail = 0
    any_say = total_say = say_rules = 0
    ex_vcp = 0
    suggested_changes = 0
    last_multi_tab = "continue the action"
    with open("story.ni") as file:
        for (line_count, line) in enumerate(file, 1):
            if line.startswith("this is the vc-"):
                in_vc = True
                got_succeeds_yet = 0
                got_fails_yet = 0
                any_say = 0
                rule_start_line = line_count
                rule_name = re.sub(".*vc-", "vc-", line).strip()
                rule_name = re.sub(" *rule:", "", rule_name)
                last_multi_tab = "continue the action"
            elif line.startswith("this is the vr-"):
                in_vr = True
                vcp_count = 0
                got_succeeds_yet = 0
                got_fails_yet = 0
                rule_start_line = line_count
                rule_name = re.sub(".*vr-", "vr-", line).strip()
                rule_name = re.sub(" *rule:", "", rule_name)
            elif in_vr and not line.strip():
                in_vc = False
                in_vr = False
                if vcp_count:
                    ex_vcp += 1
                    print("{} Extraneous VCP in {} lines {}-{}.".format(
                        ex_vcp, rule_name, rule_start_line, line_count))
                if got_succeeds_yet:
                    print("Harmless extra rule-succeeds in {} line {}.".format(
                        rule_name, line_count - 1))
                if got_fails_yet:
                    print("Harmless extra rule-fails in {} line {}.".format(
                        rule_name, line_count - 1))
            elif in_vc and not line.strip():
                if not got_succeeds_yet:
                    no_succ += 1
                    print(
                        "{}/{} Oops no 'rule succeeds' text in {} lines {}-{}."
                        .format(no_succ, no_fail + no_succ, rule_name,
                                rule_start_line, line_count))
                    mt.add_postopen_file_line("story.ni", line_count)
                elif got_succeeds_yet > 1 and rule_name not in mult_succ_fail_ok:
                    mult_succ += 1
                    print(
                        "{}/{}Oops multiple 'rule succeeds' text in {} lines {}-{}."
                        .format(no_succ, no_fail + no_succ, rule_name,
                                rule_start_line, line_count))
                    mt.add_postopen_file_line("story.ni", line_count)
                if not got_fails_yet and rule_name not in nofail_ok:
                    no_fail += 1
                    print("{}/{} Oops no 'rule fails' text in {} lines {}-{}.".
                          format(no_fail, no_fail + no_succ, rule_name,
                                 rule_start_line, line_count))
                    mt.add_postopen_file_line("story.ni", line_count)
                elif got_fails_yet > 1 and rule_name not in mult_succ_fail_ok:
                    no_fail += 1
                    print("{}/{} Oops no 'rule fails' text in {} lines {}-{}.".
                          format(no_fail, no_fail + no_succ, rule_name,
                                 rule_start_line, line_count))
                    mt.add_postopen_file_line("story.ni", line_count)
                if any_say:
                    say_rules += 1
                    total_say += any_say
                    print("{}{}/{} potential excess 'say' in {} lines {}-{}.".
                          format("****" if any_say > 1 else "", total_say,
                                 say_rules, rule_name, rule_start_line,
                                 line_count))
                    mt.add_postopen_file_line("story.ni", line_count)
                in_vc = False
                in_vr = False
            elif (in_vc or in_vr) and "instead;" in line:
                notabs = re.sub("[^\t]", "", line.rstrip())
                l2 = re.sub(" *instead;", ";", line)
                if "\tif" in l2:
                    l2 = re.sub(", *(say \")", ":\n" + notabs + "\t" + r'\1',
                                l2)
                    opt_tab = "\t"
                else:
                    opt_tab = ""
                out_file.write(l2)
                out_file.write(notabs + opt_tab + "continue the action;\n")
                suggested_changes += 1
                print("Suggested changes for {} at line {}.".format(
                    rule_name, line_count))
                continue
            elif in_vc:
                got_succeeds_yet += 'rule succeeds' in line
                got_fails_yet += 'rule fails' in line
                any_say += 'say "' in line and "[oksay]" not in line
                if line.startswith("\t\t"):
                    last_multi_tab = line
                elif line.startswith("\t"):
                    if 'continue the action' not in last_multi_tab:
                        print("May be missing CONTINUE THE ACTION in line",
                              line_count - 1)
            elif in_vr:
                vcp_count += 'vcp "' in line
                got_succeeds_yet += 'rule succeeds' in line
                got_fails_yet += 'rule fails' in line
            out_file.write(line)
    out_file.close()
    if suggested_changes:
        print(suggested_changes, "suggested changes.")
        mt.wm("story.ni", "story.niv")
    else:
        print("No suggested changes.")
    if no_succ or no_fail:
        print("Need {} 'rule succeeds' and {} 'rule fails'.".format(
            no_succ, no_fail))
    else:
        print("All rules have rule succeeds/rule fails in place.")
    if mult_succ or mult_fail:
        print(
            "Need to trim {} extra 'rule succeeds' and {} extra 'rule fails'.".
            format(mult_succ, mult_fail))
    else:
        print("No rules have excess rule succeeds/rule fails.")
    if say_rules:
        print("No fishy 'say' in vc- rules.")
    else:
        print(say_rules, "vc- rules have say, total =", total_say)
    if ex_vcp:
        print("Need to fix {} extraneous VCP in vr- rules.", format(ex_vcp))
    else:
        print("No extraneous VCP in vr- rules.")
    os.remove("story.niv")
    mt.postopen_files()
    exit()