mirror of
https://github.com/explosion/spaCy.git
synced 2025-02-14 02:20:34 +03:00
Check in PatternParser that the generated Pattern is valid
This commit is contained in:
parent
e55199d454
commit
8ff4f512a2
|
@ -38,8 +38,18 @@ class PatternParser(object):
|
||||||
if not pattern.nodes:
|
if not pattern.nodes:
|
||||||
return
|
return
|
||||||
|
|
||||||
|
cls.check_pattern(pattern)
|
||||||
return pattern
|
return pattern
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def check_pattern(pattern):
|
||||||
|
if not pattern.is_connected():
|
||||||
|
raise ValueError("The pattern tree must be a fully connected "
|
||||||
|
"graph.")
|
||||||
|
|
||||||
|
if pattern.root_node is None:
|
||||||
|
raise ValueError("The root node of the tree could not be found.")
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def _parse_line(cls, stream, pattern, lineno):
|
def _parse_line(cls, stream, pattern, lineno):
|
||||||
while not stream.closed:
|
while not stream.closed:
|
||||||
|
|
Loading…
Reference in New Issue
Block a user