44from typing import TYPE_CHECKING
55
66import hyperbase .constants as const
7+ from hyperbase .constants import EdgeType
78
89if TYPE_CHECKING :
910 from hyperbase .hyperedge import Atom , Hyperedge
@@ -21,7 +22,14 @@ def _check_atom(atom: Atom) -> dict[Hyperedge, list[tuple[str, str]]]:
2122 errors : list [tuple [str , str ]] = []
2223
2324 at = atom .mtype ()
24- if at not in {"C" , "P" , "M" , "B" , "T" , "J" }:
25+ if at not in {
26+ EdgeType .CONCEPT ,
27+ EdgeType .PREDICATE ,
28+ EdgeType .MODIFIER ,
29+ EdgeType .BUILDER ,
30+ EdgeType .TRIGGER ,
31+ EdgeType .CONJUNCTION ,
32+ }:
2533 errors .append (("bad-atom-type" , f"{ at } is not a valid atom type" ))
2634
2735 if len (errors ) > 0 :
@@ -36,49 +44,55 @@ def _check_edge(edge: Hyperedge) -> dict[Hyperedge, list[tuple[str, str]]]:
3644
3745 ct = edge [0 ].mtype ()
3846 # check if connector has valid type
39- if ct not in {"P" , "M" , "B" , "T" , "J" }:
47+ if ct not in {
48+ EdgeType .PREDICATE ,
49+ EdgeType .MODIFIER ,
50+ EdgeType .BUILDER ,
51+ EdgeType .TRIGGER ,
52+ EdgeType .CONJUNCTION ,
53+ }:
4054 errors .append (("conn-bad-type" , f"connector has incorrect type: { ct } " ))
4155 # check if modifier structure is correct
42- if ct == "M" :
56+ if ct == EdgeType . MODIFIER :
4357 if len (edge ) != 2 :
4458 errors .append (("mod-1-arg" , "modifiers can only have one argument" ))
4559 # check if builder structure is correct
46- elif ct == "B" :
60+ elif ct == EdgeType . BUILDER :
4761 if len (edge ) != 3 :
4862 errors .append (("build-2-args" , "builders can only have two arguments" ))
4963 for arg in edge [1 :]:
5064 at = arg .mtype ()
51- if at != "C" :
65+ if at != EdgeType . CONCEPT :
5266 e = f"builder argument { arg !s} has incorrect type: { at } "
5367 errors .append (("build-arg-bad-type" , e ))
5468 # check if trigger structure is correct
55- elif ct == "T" :
69+ elif ct == EdgeType . TRIGGER :
5670 if len (edge ) != 2 :
5771 errors .append (("trig-1-arg" , "triggers can only have one arguments" ))
5872 for arg in edge [1 :]:
5973 at = arg .mtype ()
60- if at not in {"C" , "R" }:
74+ if at not in {EdgeType . CONCEPT , EdgeType . RELATION }:
6175 e = f"trigger argument { arg !s} has incorrect type: { at } "
6276 errors .append (("trig-bad-arg-type" , e ))
6377 # check if predicate structure is correct
64- elif ct == "P" :
78+ elif ct == EdgeType . PREDICATE :
6579 for arg in edge [1 :]:
6680 at = arg .mtype ()
67- if at not in {"C" , "R" , "S" }:
81+ if at not in {EdgeType . CONCEPT , EdgeType . RELATION , EdgeType . SPECIFIER }:
6882 e = f"predicate argument { arg !s} has incorrect type: { at } "
6983 errors .append (("pred-arg-bad-type" , e ))
7084 # check if conjunction structure is correct
71- elif ct == "J" and len (edge ) < 3 :
85+ elif ct == EdgeType . CONJUNCTION and len (edge ) < 3 :
7286 errors .append (
7387 ("conj-2-args-min" , "conjunctions must have at least two arguments" )
7488 )
7589
7690 # check argrole counts
77- if ct in {"P" , "B" }:
91+ if ct in {EdgeType . PREDICATE , EdgeType . BUILDER }:
7892 try :
7993 ars = edge .argroles ()
8094 if len (ars ) > 0 :
81- if ct == "P" :
95+ if ct == EdgeType . PREDICATE :
8296 for ar in ars :
8397 if ar not in const .valid_p_argroles :
8498 errors .append (
@@ -88,7 +102,7 @@ def _check_edge(edge: Hyperedge) -> dict[Hyperedge, list[tuple[str, str]]]:
88102 "for connector of type P" ,
89103 )
90104 )
91- elif ct == "B" :
105+ elif ct == EdgeType . BUILDER :
92106 for ar in ars :
93107 if ar not in const .valid_b_argroles :
94108 errors .append (
0 commit comments