@@ -0,0 +1,2169 @@
+# different_features.py%0A# Invoke on the command line like: python common_features.py pbtd aui%0A# Creates a set of features common to both groups and then outputs the%0A# difference between these sets.%0A%0A%0Afrom tabulate import tabulate%0Aimport csv%0Aimport sys%0Aimport os.path as path%0A%0Abase_directory = path.dirname(path.dirname(path.abspath(__file__)))%0Asys.path.append(base_directory)%0A%0A%0Adef load_segments(filename):%0A    '''Load a segment feature matrix from a CSV file, returning a list of%0A    dictionaries with information about each segment.%0A%0A    '''%0A    with open(filename, 'r') as f:%0A        return %5Bsegment for segment in csv.DictReader(f)%5D%0A%0A%0Adef feature_names(filename):%0A    '''Load a list of available features from a given feature matrix file.%0A%0A    '''%0A    with open(filename, 'r') as f:%0A        header = list(csv.reader(f))%5B0%5D%0A        return %5Bfeature for feature in header if feature != 'IPA'%5D%0A%0A%0Adef feature_set(segment_string):%0A    all_segments = load_segments(path.join(base_directory, 'engine', 'data',%0A                                           'features.csv'))%0A    target_segments = %5Bsegment for segment in all_segments if segment%5B'IPA'%5D in%0A                       segment_string%5D%0A%0A    common_features = %7B%7D%0A    for feature, value in target_segments%5B0%5D.items():%0A        if feature != 'IPA':%0A            if all(segment%5Bfeature%5D == value for segment in target_segments):%0A                common_features%5Bfeature%5D = value%0A%0A    return common_features%0A%0A%0Adef main(first, second):%0A    first_features = feature_set(first)%0A    second_features = feature_set(second)%0A%0A    all_features = feature_names(path.join(base_directory, 'engine', 'data',%0A                                           'features.csv'))%0A%0A    results = %5B%5D%0A    for feature in all_features:%0A        if feature in first_features and feature in second_features:%0A            if first_features%5Bfeature%5D != second_features%5Bfeature%5D:%0A                results.append(%5Bfeature, first_features%5Bfeature%5D,%0A                                second_features%5Bfeature%5D%5D)%0A%0A    print(tabulate(results, headers=%5B'Feature', f'Group 1 (%7Bfirst%7D)', f'Group 2 (%7Bsecond%7D)'%5D))%0A%0A%0Aif __name__ == '__main__':%0A    main(sys.argv%5B1%5D, sys.argv%5B2%5D)%0A

Add script to isolate differences between two groups of segments