I'm writing a parser for english language. This is a simple function to identify, what kind of sentence we have. Do you think, this class wrapping is right to represent the result of the function? Further parsing then checks isinstance(text, Declarative). ------------------- class Sentence(str): pass class Declarative(Sentence): pass class Question(Sentence): pass class Command(Sentence): pass def identify_sentence(text): text = text.strip() if text[-1] == '.': return Declarative(text) elif text[-1] == '!': return Command(text) elif text[-1] == '?': return Question(text) return text ------------------- At first i just returned the class, then i decided to derive Sentence from str, so i can insert the text as well.
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4