FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

intersection query for relevant_pages and corresp test by bionascu · Pull Request #402 · aimacode/aima-python · GitHub

Repository navigation

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .py  (2) All 1 file type selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
19 changes: 11 additions & 8 deletions nlp.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -293,14 +293,17 @@ def expand_pages( pages ):
return expanded

def relevant_pages(query):
"""Relevant pages are pages that contain the query in its entireity.
If a page's content contains the query it is returned by the function."""
relevant = {}
print("pagesContent in function: ", pagesContent)
for addr, page in pagesIndex.items():
if query.lower() in pagesContent[addr].lower():
relevant[addr] = page
return relevant
"""Relevant pages are pages that contain all of the query words. They are obtained by
intersecting the hit lists of the query words."""
intersection = set()
query_words = query.split()
for query_word in query_words:
hit_list = set()
for addr in pagesIndex:
if query_word.lower() in pagesContent[addr].lower():
hit_list.add(addr)
intersection = hit_list if not intersection else intersection.intersection(hit_list)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

This would lead to problems when the intersection is an empty set. When the set becomes empty it is replaced by hit_list instead of staying empty. I've fixed this and the merge conflict in #509 .

return {addr: pagesIndex[addr] for addr in intersection}

def normalize( pages ):
"""From the pseudocode: Normalize divides each page's score by the sum of
Expand Down
10 changes: 7 additions & 3 deletions tests/test_nlp.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def test_lexicon():
href="https://google.com.au"
< href="/wiki/TestThing" > href="/wiki/TestBoy"
href="/wiki/TestLiving" href="/wiki/TestMan" >"""
testHTML2 = "Nothing"
testHTML2 = "a mom and a dad"

pA = Page("A", 1, 6, ["B", "C", "E"], ["D"])
pB = Page("B", 2, 5, ["E"], ["A", "C", "D"])
Expand Down Expand Up @@ -87,9 +87,13 @@ def test_expand_pages():


def test_relevant_pages():
pages = relevant_pages("male")
assert all((x in pages.keys()) for x in ['A', 'C', 'E'])
pages = relevant_pages("his dad")
assert all((x in pages) for x in ['A', 'C', 'E'])
assert all((x not in pages) for x in ['B', 'D', 'F'])
pages = relevant_pages("mom and dad")
assert all((x in pages) for x in ['A', 'B', 'C', 'D', 'E', 'F'])
pages = relevant_pages("philosophy")
assert all((x not in pages) for x in ['A', 'B', 'C', 'D', 'E', 'F'])


def test_normalize():
Expand Down

Back | FazBrowse Home | New Git URL