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

Usernavigation - Check if table of contents #25

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Changes from 4 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
31 changes: 30 additions & 1 deletion api/models/heuristics/easeofnavigation.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,36 @@
from models.heuristic import Heuristic
from boilerpipe.extract import Extractor

# Formal 3
# Ensure ease of user navigation.
class EaseOfNavigation(Heuristic):
def score(self, eula):
return {'score': -1, 'max': 4, 'reason': 'Not implemented'}

if eula.html is not None:
# gets actual text since eula.text doesn't get everything
extractor = Extractor(extractor='KeepEverythingExtractor', html= eula.html)
text = extractor.getText()
else:
text = eula.text

# limit text to first 1000 characters
text_first_1000 = text[:1000]
tocscore = 0 # score for table of contents
reason = '' # reason
index_of_table = -1 # index of matching text

# text to look out for
tocindicators = ['TABLE OF CONTENTS', 'Table Of Contents']

# find index of indicator text
for ind in tocindicators:
if index_of_table < 0:
index_of_table = text_first_1000.find(ind)
else:
break

# Score of 4 if found, score of 0 if not
# TODO: additional scoring hyperlinked vs unlinked table
tocscore = 4 if index_of_table >= 0 else 0

return {'score': tocscore, 'max': 4, 'index': index_of_table}