Skip to content

Ya vse. #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

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open

Ya vse. #1

wants to merge 4 commits into from

Conversation

vloooo
Copy link

@vloooo vloooo commented Dec 12, 2018

No description provided.

class JsonWriter:
@staticmethod
def write_json(name, jsn):
with open(name, 'w') as file: # serialization
Copy link
Contributor

Choose a reason for hiding this comment

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

This class is very good in terms of SRP, but this comment is redundant - the code is pretty self-documenting.


class CheckerForMeaning:
@staticmethod
def find_trash(clean_line, inf_dict):
Copy link
Contributor

Choose a reason for hiding this comment

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

The idea to mutate the data passed as an argument is as bad as mutating the internal state. That means, instead of doing

def find_trash(clean_line, inf_dict):
# ...
inf_dict['orphan_tokens'].append(i)
# ...

a much better strategy could be

def find_trash(clean_line):
# ...
    return clean_tokens, orphan_tokens

# somewhere higher the call stack
clean_tokens, orphan_tokens = find_trash
response["orphan_tokens"] = orphan_tokens

Don't ever mutate the data passes to your methods as an argument.

for i in clean_tokens: # check for meaning
if nltk.wsd.lesk(tokens, i) is None:
inf_dict['orphan_tokens'].append(i)
return inf_dict
Copy link
Contributor

Choose a reason for hiding this comment

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

If you absolutely have to mutate the data sent you as an argument, don't return this very data from your method - your method should either have an "out" parameter to mutate, or a return value, not both. Having both, you confuse a reader of your method.


result = {'records': []}

for i in data: # tweet handling
Copy link
Contributor

@vittorius vittorius Dec 19, 2018

Choose a reason for hiding this comment

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

i could be line for better readability.

def __init__(self, line):
self.line = line

def explore(self):
Copy link
Contributor

Choose a reason for hiding this comment

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

The responsibilities distribution between lines is done well enough.

Copy link
Contributor

Choose a reason for hiding this comment

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

And the idea to get parts of the response data and merge them in a single place is also a very good way to go. Just remove any mutations of the input data in your methods (see my comment above).

def find_urls(clean_line, raw_line, inf_dict):
""" find URL """
urls = re.findall('http[s]?://(?:[a-zA-Z]|[0-9]|[$-_@.&+]|[!*\(\),]|(?:%[0-9a-fA-F][0-9a-fA-F]))+', raw_line)
funk_for_clean = RemoverUnwantedWords.remove_words
Copy link
Contributor

Choose a reason for hiding this comment

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

  1. Unnecessary indirection.
  2. English: func instead of funk.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants