Last active
December 15, 2015 07:06
-
-
Save jtauber/ab691a5552d97a8c40c2 to your computer and use it in GitHub Desktop.
script for finding functional dependencies in MorphGNT columns
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
import argparse | |
import collections | |
import glob | |
parser = argparse.ArgumentParser(description="count (and optionally list) the entries where the determinant columns do not functionally determine the dependent columns.") | |
parser.add_argument("-v", "--verbose", help="output full results", action="store_true") | |
parser.add_argument("determinant", help="comma-separated list of columns") | |
parser.add_argument("dependent", help="comma-separated list of columns") | |
args = parser.parse_args() | |
values = collections.defaultdict(set) | |
for filename in glob.glob("*.txt"): | |
with open(filename) as f: | |
for line in f: | |
cells = line.strip().split() | |
left_cell = " ".join(cells[int(col) - 1] for col in args.determinant.split(",")) | |
right_cell = " ".join(cells[int(col) - 1] for col in args.dependent.split(",")) | |
values[left_cell].add(right_cell) | |
count = 0 | |
for k, v in values.items(): | |
if len(v) > 1: | |
count += 1 | |
if args.verbose: | |
print(k, v) | |
print(count) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment