Skip to content
This repository was archived by the owner on Nov 22, 2022. It is now read-only.

Commit 3bba58a

Browse files
geof90facebook-github-bot
authored andcommitted
Add templated generation
Reviewed By: AkshatSh Differential Revision: D21531436 fbshipit-source-id: 8b0e8f66eac8ea913d5aa187083937bc75b7ba55
1 parent 5b64307 commit 3bba58a

File tree

1 file changed

+18
-14
lines changed

1 file changed

+18
-14
lines changed

pytext/data/data_structures/annotation.py

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -198,10 +198,10 @@ def list_ancestors(self):
198198
ancestors += self.parent.list_ancestors()
199199
return ancestors
200200

201-
def validate_node(self):
201+
def validate_node(self, *args):
202202
if self.children:
203203
for child in self.children:
204-
child.validate_node()
204+
child.validate_node(*args)
205205

206206
# Returns all tokens in the span covered by this node
207207
def list_tokens(self):
@@ -304,8 +304,8 @@ class Root(Node):
304304
def __init__(self):
305305
super().__init__("ROOT")
306306

307-
def validate_node(self):
308-
super().validate_node()
307+
def validate_node(self, *args):
308+
super().validate_node(*args)
309309
for child in self.children:
310310
if type(child) == Slot or type(child) == Root:
311311
raise TypeError(
@@ -324,8 +324,8 @@ class Intent(Node):
324324
def __init__(self, label):
325325
super().__init__(label)
326326

327-
def validate_node(self):
328-
super().validate_node()
327+
def validate_node(self, *args):
328+
super().validate_node(*args)
329329
for child in self.children:
330330
if type(child) == Intent or type(child) == Root:
331331
raise TypeError(
@@ -342,8 +342,12 @@ class Slot(Node):
342342
def __init__(self, label):
343343
super().__init__(label)
344344

345-
def validate_node(self):
346-
super().validate_node()
345+
def validate_node(self, allow_empty_slots=True, *args):
346+
super().validate_node(*args)
347+
if not allow_empty_slots:
348+
if len(self.children) == 0:
349+
raise TypeError("Empty slot found: " + self.label)
350+
347351
for child in self.children:
348352
if type(child) == Slot or type(child) == Root:
349353
raise TypeError(
@@ -362,7 +366,7 @@ def __init__(self, label, index):
362366
self.index = index
363367
self.children = None
364368

365-
def validate_node(self):
369+
def validate_node(self, *args):
366370
if self.children is not None:
367371
raise TypeError(
368372
"A token node is terminal and should not \
@@ -508,7 +512,7 @@ def __init__(
508512
+ "Utterance is: {}".format(utterance)
509513
)
510514

511-
def validate_tree(self):
515+
def validate_tree(self, allow_empty_slots=True):
512516
"""
513517
This is a method for checking that roots/intents/slots are
514518
nested correctly.
@@ -525,16 +529,16 @@ def validate_tree(self):
525529
COMBINATION_SLOT_LABEL,
526530
)
527531
)
528-
self.recursive_validation(self.root)
532+
self.recursive_validation(self.root, allow_empty_slots)
529533
except TypeError as t:
530534
raise ValueError(
531535
"Failed validation for {}".format(self.root) + "\n" + str(t)
532536
)
533537

534-
def recursive_validation(self, node):
535-
node.validate_node()
538+
def recursive_validation(self, node, *args):
539+
node.validate_node(*args)
536540
for child in node.children:
537-
child.validate_node()
541+
child.validate_node(*args)
538542

539543
def print_tree(self):
540544
print(self.flat_str())

0 commit comments

Comments
 (0)