#! /usr/bin/python3 # Last edited on 2026-02-27 04:37:41 by stolfi import sys, os, re; from sys import stderr as err from error_funcs import arg_error, prog_error from process_funcs import bash from math import fabs from note_077_funcs import enc_from_unit import make_rules_077_funcs as mrf import make_rules_bencao as sbj import make_rules_starps as sps def add_all_double_hist_rules(pre, mak, tit): # Adds rules to make joint histogram plots of the SBJ chars per recipe # against SPS words or chars per unit, in "fu" and/or "gd" subsets. targets = [] unit0 = "ch" # sub1, unit1 in (("fu", "wp"), ("fu", "wc"), ("gd", "wp"), ("gd", "ec")): for bsub1, unit1 in ( ("fu", "wc",), ("gd", "wc",), ): bsub0 = "fu" name0 = f"bencao-{bsub0}-{unit0}" color0 = mrf.bencao_hist_color(bsub0, unit0) name1 = f"starps-{bsub1}-{unit1}" color1 = mrf.starps_hist_color(bsub1, unit1) bin_size = 1 target = mrf.add_double_size_hist_plot_rules(pre, mak, tit, name0, color0, name1, color1, bin_size) targets.append(target) return targets # ---------------------------------------------------------------------- def add_all_wpos_delta_plot_rules(pre, mak, tit): # Adds rules to make plots of points {(d1,d2)} where {d1} and {d2} # are distances between three occurrences of some character in the SBJ # or three occurrences of some word or pattern in the SPS file. sbj_word = "δΈ»"; sbj_tag = "zhu3" sbj_wpd_target, sbj_color = sbj.add_wpos_delta_file_rules(pre, mak, tit, sbj_word, sbj_tag) sbj_wpd_file = f"res/{sbj_wpd_target}" sps_bsub = "fu" sps_word = "[dlrspf]aiii?n"; sps_tag = "XAIIN" sps_wpd_target, sps_color = sps.add_wpos_delta_file_rules(pre, mak, tit, sps_bsub, sps_word, sps_tag) sps_wpd_file = f"res/{sps_wpd_target}" sbj_name = f"bencao-fu-{sbj_tag}" sps_name = f"starps-{sps_bsub}-{sps_tag}" target = f"{sbj_name}-{sps_name}-wpos-delta-plot.png" script = "plot_two_wpos_delta_files.sh" tit[target] = f"creating plot res/{target} from {sbj_wpd_file}, {sps_wpd_file}" pre[target] = [ script, sbj_wpd_file, sps_wpd_file, ] mak[target] = ( f"{script} " + " \\", f" {sps_wpd_file} '{sps_word}' '{sps_color}'" + " \\", f" {sbj_wpd_file} '{sbj_word}' '{sbj_color}'" + " \\", f" > res/{target}", ) return [ target, ] # ---------------------------------------------------------------------- def add_all_coin_image_rules(pre, mak, tit): # Adds rules and commands to create files # "res/{name0}-{name1}-coin-map.png" that shows coincidences of sizes # etc between the parags of the SBJ "in/{name0}.ivp" and those of the # SPS "res/{name1}.ivp". Returns the names of the targets (sans "res/"). targets = [] # sub1, unit1 in (("fu", "wp"), ("fu", "wc"), ("gd", "wp"), ("gd", "ec")): # for sub1, unit1 in (("gd", "ec",),): # dir0 = "in"; name0 = f"bencao-fu-ch" # dir1 = "res"; name1 = f"sps_-{sub1}-{unit1}" # target = add_parag_parag_coin_image_rules(pre, mak, tit, dir0, name0, dir1, name1) # targets.append(target) # return targets # ---------------------------------------------------------------------- def add_all_word_tuple_rules(pre, mak, tit): # Word tuples targets = [] for book, sub, unit, tsize in ( ( "bencao", "fu", "ch", 1, ), ( "bencao", "fu", "ch", 2, ), ( "bencao", "fu", "ch", 3, ), ( "starps", "fu", "ec", 5, ), ( "starps", "fu", "ec", 10, ), ( "starps", "fu", "wc", 1, ), ( "starps", "fu", "wc", 2, ), ( "starps", "fu", "wc", 3, ), ( "starps", "fu", "wp", 2, ), ): target = mrf.add_word_tuple_file_rules(pre, mak, tit, book, sub, unit, tsize) targets.append(target) return targets def add_all_rules(pre, mak, tit): # Adds rules to build the double histograms comparing SBJ and SPS parag sizes # of various flavors (three pinyin size units, two starps subsets (full, good), # three starps size units) # # Returns the list of ultimate targets (the plot files) targets = \ add_all_double_hist_rules(pre, mak, tit) + \ add_all_word_tuple_rules(pre, mak, tit) + \ add_all_coin_image_rules(pre, mak, tit) + \ add_all_wpos_delta_plot_rules(pre, mak, tit) # + add_all_word_pos_pos_plot_rules(pre, mak, tit) return targets # ----------------------------------------------------------------------