-
Notifications
You must be signed in to change notification settings - Fork 1
Sourcery refactored main branch #1
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: main
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 |
|---|---|---|
|
|
@@ -21,9 +21,11 @@ def __init__(self, n: int, name="", auto_pickle=False): | |
| """ | ||
| self.n = n | ||
| self.pickle_path = self.pathify(name or self.gen_pickle_name()) | ||
| if path.exists(self.pickle_path): # Ask if they intend to overwrite existing pickle | ||
| if input(f"overwrite {self.pickle_path}? (Y/N)\n").upper() != "Y": | ||
| self.pickle_path = self.pathify(self.gen_pickle_name()) | ||
| if ( | ||
| path.exists(self.pickle_path) | ||
| and input(f"overwrite {self.pickle_path}? (Y/N)\n").upper() != "Y" | ||
| ): | ||
| self.pickle_path = self.pathify(self.gen_pickle_name()) | ||
| self.context_options: dict[tuple, Counter[str]] = defaultdict(Counter) | ||
| # dict [context, Counter of possible tokens] | ||
| self.num_tweets = 0 | ||
|
|
@@ -44,12 +46,10 @@ def generate_Ngrams(self, string: str): | |
| words = string.split(" ") | ||
| words = [self.start] * (self.n - 1) + words + [self.end] * (self.n - 1) | ||
|
|
||
| list_of_tup = [] | ||
|
|
||
| for i in range(len(words) + 1 - self.n): | ||
| list_of_tup.append((tuple(words[i + j] for j in range(self.n - 1)), words[i + self.n - 1])) | ||
|
|
||
| return list_of_tup | ||
| return [ | ||
| (tuple(words[i + j] for j in range(self.n - 1)), words[i + self.n - 1]) | ||
| for i in range(len(words) + 1 - self.n) | ||
| ] | ||
|
Comment on lines
-47
to
+52
Author
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. Function
|
||
|
|
||
| def backup(self): | ||
| os.makedirs("models", exist_ok=True) | ||
|
|
@@ -89,7 +89,7 @@ def get_word_prob(self, context: tuple, token: str): | |
| # return self.ngram_count[(context, token)] / context_freq | ||
|
|
||
| def calculate_freq(self, context: tuple): | ||
| freq = sum(freq for freq in self.context_options[context].values()) | ||
| freq = sum(self.context_options[context].values()) | ||
|
Author
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. Function
|
||
| self.context_freq_cache[self, context] = freq | ||
| return freq | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -30,5 +30,6 @@ def get_pin(url): | |
|
|
||
| time.sleep(5) | ||
|
|
||
| pin = driver.find_element(By.CSS_SELECTOR, "kbd > code").get_attribute("innerText") | ||
| return pin | ||
| return driver.find_element(By.CSS_SELECTOR, "kbd > code").get_attribute( | ||
| "innerText" | ||
| ) | ||
|
Comment on lines
-33
to
+35
Author
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. Function
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -54,8 +54,7 @@ def log_and_backup(): | |
|
|
||
| if __name__ == "__main__": | ||
| for i in signal.valid_signals(): | ||
| if (i == signal.SIGKILL or | ||
| i == signal.SIGSTOP): | ||
| if i in [signal.SIGKILL, signal.SIGSTOP]: | ||
|
Author
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. Lines
|
||
| continue | ||
| signal.signal(i, exit_gracefully) | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -73,7 +73,7 @@ def get_tweets(self, keyword: str) -> list[str]: | |
| :return: a list of tweets returned as strings | ||
| """ | ||
| search_param["query"] = keyword | ||
| to_return = dict() | ||
| to_return = {} | ||
|
Author
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. Function
|
||
| # noinspection PyBroadException | ||
| try: | ||
| to_return = requests.get(Twitter.__search_url, search_param, auth=self.bearer_oauth).json() | ||
|
|
||
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.
Function
NgramModel.__init__refactored with the following changes:merge-nested-ifs)This removes the following comments ( why? ):