1313from linkml_runtime .utils .namespaces import Namespaces
1414from linkml_runtime .utils .strictness import is_strict
1515
16+ from linkml_runtime .utils .uri_validator import validate_uri
17+ from linkml_runtime .utils .uri_validator import validate_uri_reference
18+ from linkml_runtime .utils .uri_validator import validate_curie
19+
1620# Reference Decimal to make sure it stays in the imports
1721_z = Decimal (1 )
1822
@@ -105,17 +109,21 @@ def is_valid(cls, v: Union[str, URIRef, "Curie", "URIorCURIE"]) -> bool:
105109 if not isinstance (v , (str , URIRef , Curie , URIorCURIE )):
106110 return False
107111 v = str (v )
108- if ':' in v and '://' not in v :
109- return URIorCURIE .is_curie (v )
112+ if validate_uri (v ):
113+ return True
114+ elif validate_uri_reference (v ):
115+ return True
110116 else :
111- return URI . is_valid (v )
117+ return URIorCURIE . is_curie (v )
112118
113119 @staticmethod
114120 def is_absolute (v : str ) -> bool :
115121 return bool (urlparse (v ).netloc )
116122
117123 @staticmethod
118124 def is_curie (v : str , nsm : Optional [Namespaces ] = None ) -> bool :
125+ if not validate_curie (v ):
126+ return False
119127 if ':' in v and '://' not in v :
120128 ns , ln = v .split (':' , 1 )
121129 return len (ns ) == 0 or (NCName .is_valid (ns ) and
@@ -136,13 +144,14 @@ def __init__(self, v: str) -> None:
136144 raise ValueError (f"'{ v } ': is not a valid URI" )
137145 super ().__init__ (v )
138146
139- # this is more inclusive than the W3C specification
140- #uri_re = re.compile("^[A-Za-z]\\S*$")
141- uri_re = re .compile ("^\\ S+$" )
142-
143147 @classmethod
144148 def is_valid (cls , v : str ) -> bool :
145- return v is not None and not URIorCURIE .is_curie (v ) and cls .uri_re .match (v )
149+ if validate_uri (v ):
150+ return True
151+ elif validate_uri_reference (v ):
152+ return True
153+ else :
154+ return False
146155
147156
148157class Curie (URIorCURIE ):
@@ -174,6 +183,8 @@ def ns_ln(cls, v: str) -> Optional[Tuple[str, str]]:
174183
175184 @classmethod
176185 def is_valid (cls , v : str ) -> bool :
186+ if not validate_curie (v ):
187+ return False
177188 pnln = cls .ns_ln (v )
178189 #return pnln is not None and (not pnln[0] or isinstance(pnln[0], PN_PREFIX))
179190 return pnln is not None
0 commit comments