Skip to content
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

Fix sentence scoring logic considering cases #167

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
43 changes: 26 additions & 17 deletions ipynb/Chapter 5 - Mining Web Pages.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -412,7 +412,7 @@
" if score > max_cluster_score:\n",
" max_cluster_score = score\n",
"\n",
" scores.append((sentence_idx, score))\n",
" scores.append((sentence_idx, max_cluster_score))\n",
"\n",
" return scores\n",
"\n",
Expand Down Expand Up @@ -569,22 +569,26 @@
" pos_tagged_tokens = [token for sent in pos_tagged_tokens for token in sent]\n",
"\n",
" all_entity_chunks = []\n",
" previous_pos = None\n",
" current_status = 'None-NN'\n",
Copy link
Owner

Choose a reason for hiding this comment

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

I apologize for taking so long to merge in this change. I'm just not totally sure where you're going with this second part of the diff where you are materializing current_status. Can you explain what's going on here?

" current_entity_chunk = []\n",
" for (token, pos) in pos_tagged_tokens:\n",
"\n",
" if pos == previous_pos and pos.startswith('NN'):\n",
" current_entity_chunk.append(token)\n",
" elif pos.startswith('NN'):\n",
" if current_entity_chunk != []:\n",
"\n",
" if pos.startswith('NN'):\n",
" if current_status == 'None-NN':\n",
" current_status = 'NN'\n",
" current_entity_chunk = [token]\n",
" else:\n",
" current_entity_chunk.append(token)\n",
" else:\n",
" if current_status == 'None-NN':\n",
" pass\n",
" else:\n",
" current_status = 'None-NN'\n",
" \n",
" # Note that current_entity_chunk could be a duplicate when appended,\n",
" # so frequency analysis again becomes a consideration\n",
"\n",
" all_entity_chunks.append((' '.join(current_entity_chunk), pos))\n",
" current_entity_chunk = [token]\n",
"\n",
" previous_pos = pos\n",
"\n",
" # Store the chunks as an index for the document\n",
" # and account for frequency while we're at it...\n",
Expand Down Expand Up @@ -633,20 +637,25 @@
" for sentence in pos_tagged_tokens:\n",
"\n",
" all_entity_chunks = []\n",
" previous_pos = None\n",
" current_status = 'None-NN'\n",
" current_entity_chunk = []\n",
"\n",
" for (token, pos) in sentence:\n",
"\n",
" if pos == previous_pos and pos.startswith('NN'):\n",
" current_entity_chunk.append(token)\n",
" elif pos.startswith('NN'):\n",
" if pos.startswith('NN'):\n",
" if current_status == 'None-NN':\n",
" current_status = 'NN'\n",
" current_entity_chunk = [token]\n",
" else:\n",
" current_entity_chunk.append(token)\n",
" else:\n",
" if current_status == 'None-NN':\n",
" pass\n",
" else:\n",
" current_status = 'None-NN'\n",
" if current_entity_chunk != []:\n",
" all_entity_chunks.append((' '.join(current_entity_chunk),\n",
" pos))\n",
" current_entity_chunk = [token]\n",
"\n",
" previous_pos = pos\n",
"\n",
" if len(all_entity_chunks) > 1:\n",
" entity_interactions.append(all_entity_chunks)\n",
Expand Down