-
Notifications
You must be signed in to change notification settings - Fork 27
improved docstrings #30
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,8 +12,16 @@ class ModeNotInstalled(ValueError): | |
pass | ||
|
||
|
||
def update_modes(pair_path): # type: (str) -> None | ||
modes = search_path(pair_path) | ||
def update_modes(path): # type: (str) -> None | ||
"""Updates the install modes | ||
|
||
Args: | ||
path(str): A string that is the absolute location to the modes to be installed | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This doesn't make it clear that this path will be added, the old ones won't be removed. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
|
||
Yelids: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
This won't be picked up by the parser. Moreover, it should probably be returns. Actually, does it even return anything? |
||
Updates the pairs, analyzers, generator dictionaries with entries | ||
""" | ||
modes = search_path(path) | ||
if modes['pair']: | ||
for path, lang_src, lang_trg in modes['pair']: | ||
pairs['%s-%s' % (lang_src, lang_trg)] = path | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,7 +8,20 @@ | |
|
||
|
||
class Analyzer: | ||
"""An Analyzer object containing it's analysis mode and langugage | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
|
||
Attributes: | ||
analyzer_cmds (Dict[str, List[List[str]]]): stores the commands for various analyzers to run succesfully. | ||
lang (str): Language of the text which is morphologically analyzed. | ||
path (str): Location to the analyzer mode for a particular language. | ||
mode (str): Name of the mode that for a particular lingustic task. | ||
""" | ||
def __init__(self, lang): # type: (Analyzer, str) -> None | ||
"""initializes the Analyzer object | ||
|
||
Args: | ||
lang (str): Language of the morphological analyzer | ||
""" | ||
self.analyzer_cmds = {} # type: Dict[str, List[List[str]]] | ||
self.lang = to_alpha3_code(lang) # type: str | ||
if self.lang not in apertium.analyzers: | ||
|
@@ -17,27 +30,32 @@ def __init__(self, lang): # type: (Analyzer, str) -> None | |
self.path, self.mode = apertium.analyzers[self.lang] | ||
|
||
def _get_commands(self): # type: (Analyzer) -> List[List[str]] | ||
""" | ||
Yeilds: the commands to run for the analysis mode | ||
""" | ||
if self.lang not in self.analyzer_cmds: | ||
mode_path, mode = apertium.analyzers[self.lang] | ||
self.analyzer_cmds[self.lang] = parse_mode_file(mode_path+'/modes/'+mode+'.mode') | ||
return self.analyzer_cmds[self.lang] | ||
|
||
def _postproc_text(self, result): # type: (Analyzer, str) -> List[LexicalUnit] | ||
""" | ||
postprocesses the input | ||
""" | ||
lexical_units = list(parse(result)) | ||
return lexical_units | ||
|
||
def analyze(self, in_text, formatting='txt'): # type: (Analyzer, str, str) -> List[LexicalUnit] | ||
""" | ||
runs apertium to analyze the input | ||
"""runs apertium to analyze the input | ||
|
||
Args: | ||
in_text (str): The text who's morphological analysis has to be generated | ||
formatting (str): The type of formatting for the output of the analysis | ||
""" | ||
commands = [['apertium', '-d', self.path, '-f', formatting, self.mode]] | ||
result = execute(in_text, commands) | ||
return self._postproc_text(result) | ||
|
||
|
||
def analyze(lang, in_text, formatting='txt'): # type: (str, str, str) -> List[LexicalUnit] | ||
"""directly returns the analysis from apertium | ||
""" | ||
analyzer = Analyzer(lang) | ||
return analyzer.analyze(in_text, formatting) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
install
=>installed