Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 10 additions & 10 deletions NgramModel.py
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Comment on lines -24 to +28
Copy link
Author

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:

This removes the following comments ( why? ):

# Ask if they intend to overwrite existing pickle

self.context_options: dict[tuple, Counter[str]] = defaultdict(Counter)
# dict [context, Counter of possible tokens]
self.num_tweets = 0
Expand All @@ -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
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function NgramModel.generate_Ngrams refactored with the following changes:


def backup(self):
os.makedirs("models", exist_ok=True)
Expand Down Expand Up @@ -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())
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function NgramModel.calculate_freq refactored with the following changes:

self.context_freq_cache[self, context] = freq
return freq

Expand Down
5 changes: 3 additions & 2 deletions browser.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function get_pin refactored with the following changes:

3 changes: 1 addition & 2 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]:
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lines 57-58 refactored with the following changes:

continue
signal.signal(i, exit_gracefully)

Expand Down
2 changes: 1 addition & 1 deletion twitter.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {}
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function Twitter.get_tweets refactored with the following changes:

# noinspection PyBroadException
try:
to_return = requests.get(Twitter.__search_url, search_param, auth=self.bearer_oauth).json()
Expand Down