pytact.scripts.largest_global_context
Calculate the definition with the largest global context in a dataset.
1"""Calculate the definition with the largest global context in a dataset. 2""" 3 4from pathlib import Path 5import sys 6from pytact.data_reader import data_reader, GlobalContextSets 7 8def main(): 9 dataset_path = Path(sys.argv[1]).resolve() 10 maximum = 0 11 maxdef = '' 12 with data_reader(dataset_path) as data: 13 with GlobalContextSets.new_context() as global_contexts: 14 for datafile in data.values(): 15 with global_contexts.sub_context(lambda d: d.is_file_representative) as sub_global_contexts: 16 for d in datafile.definitions(): 17 deflen = len(sub_global_contexts.global_context_set(d)) 18 if deflen > maximum: 19 maximum = deflen 20 maxdef = d.name 21 print(f"{maxdef} : {maximum}") 22 23if __name__ == "__main__": 24 exit(main())
def
main():
9def main(): 10 dataset_path = Path(sys.argv[1]).resolve() 11 maximum = 0 12 maxdef = '' 13 with data_reader(dataset_path) as data: 14 with GlobalContextSets.new_context() as global_contexts: 15 for datafile in data.values(): 16 with global_contexts.sub_context(lambda d: d.is_file_representative) as sub_global_contexts: 17 for d in datafile.definitions(): 18 deflen = len(sub_global_contexts.global_context_set(d)) 19 if deflen > maximum: 20 maximum = deflen 21 maxdef = d.name 22 print(f"{maxdef} : {maximum}")