2121
2222
2323@click .command ()
24- @click .option ("--max-cutoff" , type = int , default = 3 , show_default = True )
24+ @click .option ("--max-cutoff" , type = int , default = 20 , show_default = True )
2525@click .option ("--links" , is_flag = True )
2626def main (max_cutoff : int , links : bool ):
2727 """Check schema usage."""
2828 _check_schema (max_cutoff = max_cutoff , links = links )
2929
3030
31- def _check_schema (max_cutoff : int = 3 , links : bool = True ):
31+ def _check_schema (max_cutoff : int , links : bool = True ):
3232 ontologies = get_data ()
3333
3434 property_usage = Counter ()
@@ -44,27 +44,31 @@ def _check_schema(max_cutoff: int = 3, links: bool = True):
4444 if key in data :
4545 r [key ].add (prefix )
4646
47- print (f"Fields used at most { max_cutoff } times:" )
48- print (
49- tabulate (
50- [
51- (
52- k ,
53- ", " .join (
54- (
55- f"[{ prefix } ](https://obofoundry.org/ontologies/{ prefix } )"
56- if links
57- else prefix
58- )
59- for prefix in prefixes
60- ),
61- )
62- for k , prefixes in r .items ()
63- ],
64- tablefmt = "github" ,
65- headers = ["key" , "ontologies" ],
47+ if r :
48+ print (f"Fields used at most { max_cutoff } times:" )
49+ print (
50+ tabulate (
51+ [
52+ (
53+ k ,
54+ len (prefixes ),
55+ ", " .join (
56+ (
57+ f"[{ prefix } ](https://obofoundry.org/ontologies/{ prefix } )"
58+ if links
59+ else prefix
60+ )
61+ for prefix in prefixes
62+ ),
63+ )
64+ for k , prefixes in r .items ()
65+ ],
66+ tablefmt = "github" ,
67+ headers = ["key" , "count" , "ontologies" ],
68+ )
6669 )
67- )
70+ else :
71+ print (f"No fields used less than { max_cutoff } times!" )
6872
6973 with SCHEMA_PATH .open () as file :
7074 schema = json .load (file )
@@ -73,8 +77,11 @@ def _check_schema(max_cutoff: int = 3, links: bool = True):
7377 for prop in schema ["properties" ]
7478 if prop not in property_usage and prop not in SKIP_KEYS
7579 }
76- print ("Unused properties:" )
77- print (* sorted (unused ), sep = "\n " )
80+ if unused :
81+ print ("Unused properties:" )
82+ print (* sorted (unused ), sep = "\n " )
83+ else :
84+ print ("No unused properties!" )
7885
7986
8087if __name__ == "__main__" :
0 commit comments