Skip to content

Commit 126c830

Browse files
committed
Update models
Add clear methods for clearing phrases in a text, words in a phrase, and so on.
1 parent f8c7cd7 commit 126c830

File tree

1 file changed

+33
-2
lines changed

1 file changed

+33
-2
lines changed

typecraft_python/models.py

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,22 @@ def remove_metadata(self, key):
113113
if key in self.metadata:
114114
del self.metadata[key]
115115

116+
def clear_phrases(self):
117+
"""
118+
Clears all phrases of the text.
119+
120+
:return:
121+
"""
122+
self.phrases = []
123+
124+
def clear_metadata(self):
125+
"""
126+
Clears all metadata of the text.
127+
128+
:return:
129+
"""
130+
self.metadata = {}
131+
116132
def clear_tags(self):
117133
"""
118134
Clears all tags in the text. Specifically, call clear_tags on all the phrases of the text
@@ -316,6 +332,14 @@ def remove_global_tag_by_level(self, global_tag_level):
316332
"""
317333
self.global_tags = list(map(lambda x: x.level != global_tag_level, self.global_tags))
318334

335+
def clear_words(self):
336+
"""
337+
Clears all words in phrase. This method does not touch on the "phrase" variable, but rather
338+
the Word children objects.
339+
:return:
340+
"""
341+
self.words = []
342+
319343
def clear_tags(self):
320344
"""
321345
Clears all tags in phrase. This involves clearing all words and their constituent morphemes
@@ -405,7 +429,7 @@ def add_morphemes(self, morphemes):
405429
Adds an iterable of morphemes to this word.
406430
407431
:param morphemes:
408-
:return: Nothing
432+
:return: void
409433
"""
410434
for morpheme in morphemes:
411435
self.add_morpheme(morpheme)
@@ -415,10 +439,17 @@ def remove_morpheme(self, morpheme):
415439
Removes a morpheme from the word if it exists.
416440
417441
:param morpheme:
418-
:return:
442+
:return: void
419443
"""
420444
self.morphemes.remove(morpheme)
421445

446+
def clear_morphemes(self):
447+
"""
448+
Clears all morphemes of the word.
449+
:return: void
450+
"""
451+
self.morphemes = []
452+
422453
def clear_tags(self):
423454
"""
424455
Clears all tags of the word. This means resetting the pos tag

0 commit comments

Comments
 (0)