Sourcery refactored main branch - #1
Conversation
| summary_list = [str(sentence) for sentence in summary] | ||
| result = ' '.join(summary_list) | ||
| return result | ||
| return ' '.join(summary_list) |
There was a problem hiding this comment.
Function sumy_summary refactored with the following changes:
- Inline variable that is immediately returned (
inline-immediately-returned-variable)
| estimatedTime = total_words/200.0 | ||
| return estimatedTime | ||
| return total_words/200.0 |
There was a problem hiding this comment.
Function readingTime refactored with the following changes:
- Inline variable that is immediately returned (
inline-immediately-returned-variable)
| fetched_text = ' '.join(map(lambda p:p.text,soup.find_all('p'))) | ||
| return fetched_text | ||
| return ' '.join(map(lambda p:p.text,soup.find_all('p'))) |
There was a problem hiding this comment.
Function get_text refactored with the following changes:
- Inline variable that is immediately returned (
inline-immediately-returned-variable)
| nouns = list() | ||
| nouns = [] | ||
| for word, tag in blob.tags: | ||
| if tag == 'NN': | ||
| nouns.append(word.lemmatize()) | ||
| len_of_words = len(nouns) | ||
| rand_words = random.sample(nouns,len(nouns)) | ||
| final_word = list() | ||
| for item in rand_words: | ||
| word = Word(item).pluralize() | ||
| final_word.append(word) | ||
| summary = final_word | ||
| end = time.time() | ||
| final_time = end-start | ||
| if tag == 'NN': | ||
| nouns.append(word.lemmatize()) | ||
| len_of_words = len(nouns) | ||
| rand_words = random.sample(nouns,len(nouns)) | ||
| final_word = [] | ||
| for item in rand_words: | ||
| word = Word(item).pluralize() | ||
| final_word.append(word) | ||
| summary = final_word | ||
| end = time.time() | ||
| final_time = end-start |
There was a problem hiding this comment.
Function analyse refactored with the following changes:
- Replace
list()with[][×2] (list-literal)
| summary_list = [str(sentence) for sentence in summary] | ||
| result = ' '.join(summary_list) | ||
| return result | ||
| return ' '.join(summary_list) |
There was a problem hiding this comment.
Function sumy_summary refactored with the following changes:
- Inline variable that is immediately returned (
inline-immediately-returned-variable)
| fetched_text = ' '.join(map(lambda p:p.text,soup.find_all('p'))) | ||
| return fetched_text | ||
| return ' '.join(map(lambda p:p.text,soup.find_all('p'))) |
There was a problem hiding this comment.
Function get_text refactored with the following changes:
- Inline variable that is immediately returned (
inline-immediately-returned-variable)
| nouns = list() | ||
| nouns = [] | ||
| for word, tag in blob.tags: | ||
| if tag == 'NN': | ||
| nouns.append(word.lemmatize()) | ||
| len_of_words = len(nouns) | ||
| rand_words = random.sample(nouns,len(nouns)) | ||
| final_word = list() | ||
| for item in rand_words: | ||
| word = Word(item).pluralize() | ||
| final_word.append(word) | ||
| summary = final_word | ||
| end = time.time() | ||
| final_time = end-start | ||
| if tag == 'NN': | ||
| nouns.append(word.lemmatize()) | ||
| len_of_words = len(nouns) | ||
| rand_words = random.sample(nouns,len(nouns)) | ||
| final_word = [] | ||
| for item in rand_words: | ||
| word = Word(item).pluralize() | ||
| final_word.append(word) | ||
| summary = final_word | ||
| end = time.time() | ||
| final_time = end-start |
There was a problem hiding this comment.
Function analyse refactored with the following changes:
- Replace
list()with[][×2] (list-literal)
| word_frequencies = {} | ||
| word_frequencies = {} | ||
| for word in nltk.word_tokenize(raw_text): | ||
| if word not in stopWords: | ||
| if word not in word_frequencies.keys(): | ||
| word_frequencies[word] = 1 | ||
| else: | ||
| word_frequencies[word] += 1 | ||
| if word not in stopWords: | ||
| if word in word_frequencies: | ||
| word_frequencies[word] += 1 | ||
|
|
||
| else: | ||
| word_frequencies[word] = 1 | ||
| maximum_frequncy = max(word_frequencies.values()) | ||
|
|
||
| for word in word_frequencies.keys(): | ||
| word_frequencies[word] = (word_frequencies[word]/maximum_frequncy) | ||
| for word in word_frequencies: | ||
| word_frequencies[word] = (word_frequencies[word]/maximum_frequncy) | ||
|
|
||
| sentence_list = nltk.sent_tokenize(raw_text) | ||
| sentence_scores = {} | ||
| sentence_scores = {} | ||
| for sent in sentence_list: | ||
| for word in nltk.word_tokenize(sent.lower()): | ||
| if word in word_frequencies.keys(): | ||
| if len(sent.split(' ')) < 30: | ||
| if sent not in sentence_scores.keys(): | ||
| sentence_scores[sent] = word_frequencies[word] | ||
| else: | ||
| sentence_scores[sent] += word_frequencies[word] | ||
| for word in nltk.word_tokenize(sent.lower()): | ||
| if word in word_frequencies: | ||
| if len(sent.split(' ')) < 30: | ||
| if sent in sentence_scores: | ||
| sentence_scores[sent] += word_frequencies[word] | ||
|
|
||
|
|
||
|
|
||
| else: | ||
| sentence_scores[sent] = word_frequencies[word] | ||
| summary_sentences = heapq.nlargest(7, sentence_scores, key=sentence_scores.get) | ||
|
|
||
| summary = ' '.join(summary_sentences) | ||
| return summary | ||
| return ' '.join(summary_sentences) |
There was a problem hiding this comment.
Function nltk_summarizer refactored with the following changes:
- Remove unnecessary call to keys() [×4] (
remove-dict-keys) - Swap positions of nested conditionals [×12] (
swap-nested-ifs) - Inline variable that is immediately returned (
inline-immediately-returned-variable) - Swap if/else branches [×2] (
swap-if-else-branches)
| word_frequencies = {} | ||
| word_frequencies = {} | ||
| for word in docx: | ||
| if word.text not in stopwords: | ||
| if word.text not in word_frequencies.keys(): | ||
| word_frequencies[word.text] = 1 | ||
| else: | ||
| if word.text in word_frequencies: | ||
| word_frequencies[word.text] += 1 | ||
|
|
||
|
|
||
| else: | ||
| word_frequencies[word.text] = 1 | ||
| maximum_frequncy = max(word_frequencies.values()) | ||
|
|
||
| for word in word_frequencies.keys(): | ||
| for word in word_frequencies: | ||
| word_frequencies[word] = (word_frequencies[word]/maximum_frequncy) | ||
| # Sentence Tokens | ||
| sentence_list = [ sentence for sentence in docx.sents ] | ||
| sentence_list = list(docx.sents) | ||
|
|
||
| # Sentence Scores | ||
| sentence_scores = {} | ||
| sentence_scores = {} | ||
| for sent in sentence_list: | ||
| for word in sent: | ||
| if word.text.lower() in word_frequencies.keys(): | ||
| if word.text.lower() in word_frequencies: | ||
| if len(sent.text.split(' ')) < 30: | ||
| if sent not in sentence_scores.keys(): | ||
| sentence_scores[sent] = word_frequencies[word.text.lower()] | ||
| else: | ||
| if sent in sentence_scores: | ||
| sentence_scores[sent] += word_frequencies[word.text.lower()] | ||
|
|
||
|
|
||
| else: | ||
| sentence_scores[sent] = word_frequencies[word.text.lower()] | ||
| summarized_sentences = nlargest(7, sentence_scores, key=sentence_scores.get) | ||
| final_sentences = [ w.text for w in summarized_sentences ] | ||
| summary = ' '.join(final_sentences) | ||
| return summary | ||
| return ' '.join(final_sentences) |
There was a problem hiding this comment.
Function text_summarizer refactored with the following changes:
- Remove unnecessary call to keys() [×4] (
remove-dict-keys) - Replace identity comprehension with call to collection constructor (
identity-comprehension) - Inline variable that is immediately returned (
inline-immediately-returned-variable) - Swap if/else branches [×2] (
swap-if-else-branches)
| lang = 'english' | ||
| summary_options = {} | ||
|
|
||
| if request.method == 'POST': | ||
| text = request.form.get('text') | ||
| if text: | ||
| lang = 'english' |
There was a problem hiding this comment.
Function summ refactored with the following changes:
- Move assignments closer to their usage (
move-assign)
Branch
mainrefactored by Sourcery.If you're happy with these changes, merge this Pull Request using the Squash and merge strategy.
See our documentation here.
Run Sourcery locally
Reduce the feedback loop during development by using the Sourcery editor plugin:
Review changes via command line
To manually merge these changes, make sure you're on the
mainbranch, then run:Help us improve this pull request!