Skip to content

Sourcery refactored main branch - #1

Open
sourcery-ai[bot] wants to merge 1 commit into
mainfrom
sourcery/main
Open

Sourcery refactored main branch#1
sourcery-ai[bot] wants to merge 1 commit into
mainfrom
sourcery/main

Conversation

@sourcery-ai

@sourcery-ai sourcery-ai Bot commented Jun 23, 2023

Copy link
Copy Markdown

Branch main refactored 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 main branch, then run:

git fetch origin sourcery/main
git merge --ff-only FETCH_HEAD
git reset HEAD^

Help us improve this pull request!

@sourcery-ai
sourcery-ai Bot requested a review from Aptronymist June 23, 2023 05:15
Comment thread app.py
summary_list = [str(sentence) for sentence in summary]
result = ' '.join(summary_list)
return result
return ' '.join(summary_list)

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Function sumy_summary refactored with the following changes:

Comment thread app.py
Comment on lines -44 to +43
estimatedTime = total_words/200.0
return estimatedTime
return total_words/200.0

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Function readingTime refactored with the following changes:

Comment thread app.py
Comment on lines -51 to +49
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')))

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Function get_text refactored with the following changes:

Comment thread app.py
Comment on lines -120 to +129
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

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Function analyse refactored with the following changes:

Comment thread main.py
summary_list = [str(sentence) for sentence in summary]
result = ' '.join(summary_list)
return result
return ' '.join(summary_list)

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Function sumy_summary refactored with the following changes:

Comment thread main.py
Comment on lines -48 to +46
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')))

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Function get_text refactored with the following changes:

Comment thread main.py
Comment on lines -117 to +126
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

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Function analyse refactored with the following changes:

Comment thread nltk_summarization.py
Comment on lines -8 to +36
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)

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Function nltk_summarizer refactored with the following changes:

Comment thread spacy_summarization.py
Comment on lines -15 to +45
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)

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Function text_summarizer refactored with the following changes:

Comment thread archive/app.py
Comment on lines -15 to +20
lang = 'english'
summary_options = {}

if request.method == 'POST':
text = request.form.get('text')
if text:
lang = 'english'

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Function summ refactored with the following changes:

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.

0 participants