Skip to content

Instantly share code, notes, and snippets.

@jtauber
Last active December 15, 2015 07:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jtauber/ab691a5552d97a8c40c2 to your computer and use it in GitHub Desktop.
Save jtauber/ab691a5552d97a8c40c2 to your computer and use it in GitHub Desktop.
script for finding functional dependencies in MorphGNT columns
#!/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