-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #10 from zeeguu-ecosystem/refactoring_the_refactoring
Refactoring the refactoring
- Loading branch information
Showing
23 changed files
with
278 additions
and
278 deletions.
There are no files selected for viewing
Empty file.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
from wordstats.config import DATA_FOLDER_COGNATES, WHITELIST, BLACKLIST, RULES, CANDIDATES | ||
import os | ||
|
||
|
||
def path_of_cognate_languages(primary, secondary): | ||
package_directory = os.path.dirname(os.path.abspath(__file__)) + os.sep + ".." | ||
file_path = package_directory + os.sep + "{0}{1}{2}{3}".format(DATA_FOLDER_COGNATES, os.sep, primary, secondary) | ||
return file_path | ||
|
||
|
||
def path_of_cognate_candidates(primary, secondary, method_name): | ||
return _path_to_cognate_file(primary, secondary, CANDIDATES, method_name) | ||
|
||
|
||
def path_of_cognate_blacklist(primary, secondary, author: str = ""): | ||
return _path_to_cognate_file(primary, secondary, | ||
BLACKLIST if len(author) == 0 else (BLACKLIST + "_" + author)) | ||
|
||
|
||
def path_of_cognate_whitelist(primary, secondary, author: str = ""): | ||
return _path_to_cognate_file(primary, secondary, | ||
WHITELIST if len(author) == 0 else (WHITELIST + "_" + author)) | ||
|
||
|
||
def path_of_cognate_rules(primary, secondary, method_name, author: str = ""): | ||
return _path_to_cognate_file(primary, secondary, RULES if len(author) == 0 else (RULES + "_" + author) | ||
, method_name) | ||
|
||
|
||
def _path_to_cognate_file(primary, secondary, file_name, method_name=""): | ||
file_path = path_of_cognate_languages(primary, secondary) + os.sep | ||
if method_name is not "": | ||
file_path += method_name + os.sep | ||
file_path += file_name + ".txt" | ||
|
||
os.makedirs(os.path.dirname(file_path), exist_ok=True) | ||
|
||
return file_path |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import codecs | ||
|
||
|
||
# useful methods for handling files | ||
|
||
def load_from_path(path): | ||
try: | ||
with codecs.open(path, encoding="utf8") as file: | ||
content = file.read() | ||
|
||
except FileNotFoundError: | ||
print(path + " not found, creating empty file.") | ||
codecs.open(path, encoding="utf8", mode="w") | ||
content = load_from_path(path) | ||
|
||
return content | ||
|
||
|
||
def save_to_file(path, content): | ||
with codecs.open(path, encoding="utf8", mode="w") as words_file: | ||
words_file.write(content) | ||
|
||
|
||
def append_to_file(path, content): | ||
with codecs.open(path, encoding="utf8", mode="a") as words_file: | ||
words_file.writelines(content + "\n") |
Oops, something went wrong.