Skip to content

Commit

Permalink
bugfix: When one sentence is entered per paragraph no error occurs
Browse files Browse the repository at this point in the history
When someone included a paragraph with just one sentence,
there was a bug because the variable cluster_next was not
defined. I therefore calculated the current cluster within
the else statement.
  • Loading branch information
ch-bu committed Aug 26, 2017
1 parent 7d6779f commit 0fdd594
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions web/cohapp/coherenceanalyzer/analyzerenglish.py
Original file line number Diff line number Diff line change
Expand Up @@ -379,19 +379,29 @@ def _get_html_string(self, node_list, word_cluster_index, paragraphs, visword_to
html_string = html_string + '⇔ ' if cluster_changed else html_string
# Append last sentence
else:
# Get text of last sentence
sentence = sent.text

# Get cluster numbers of all words
indexes_last_sentence = [word_cluster_index[node]
for node in node_list if tokenized_sentences[index].text.find(visword_to_word[node][0]) != -1]

# Get the most common cluster
most_common_cluster_last_sentence = Counter(indexes_last_sentence).most_common(1)

# Extract the number of the most common cluster
cluster_last_sentence = most_common_cluster_last_sentence[0][0]

# Loop over every word we have
for node in node_list:
# The word is in the current cluster
if word_cluster_index[node] == cluster_next:

if word_cluster_index[node] == cluster_last_sentence:
# Loop over every possible word for word in visualization
for real_word in list(set(visword_to_word[node.lower()])):
# Change to span element
sentence = sentence.replace(real_word,
'<span class="cluster-' +
str(cluster_next) + '">' +
str(cluster_last_sentence) + '">' +
real_word + '</span>')

html_string += sentence
Expand Down

0 comments on commit 0fdd594

Please sign in to comment.