Skip to content

Highlights Supported by Deciding Force Parser #163

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

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
53 changes: 48 additions & 5 deletions data/parse_document.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,11 +97,53 @@ def parse_article(raw_text, filename):
raise ArticleParseError("Only found Useless tuas!",
ArticleParseError.DUPLICATE_ERROR)

# Warning: brackets left over are usually bad news.
if '[' in clean_text or ']' in clean_text:
print "Unparsed brackets left in article:", article_number
# raise ArticleParseError("Brackets remain in clean text!",
# ArticleParseError.BRACKET_WARNING)
#Trace highlights
index = 0
highlight_open = False
highlights = []

while index < len(clean_text):

#Assume that highlights cannot have internal square brackets... throw error.
if (clean_text[index] == "[" and highlight_open):
raise Exception("Extra [ in " + filename + " article number " + article_number + "\n")

#Assume that right square bracket without its corresponding left square bracket is an error.
elif (clean_text[index] == "]" and not highlight_open):
raise Exception("Extra ] in " + filename + " article number " + article_number + "\n")

#Start of highlight.
elif clean_text[index] == "[":
highlight_open = True
start = index

#Close of highlight... Remove highlight from text.
elif clean_text[index] == "]" and highlight_open:
highlight = {'start': start, 'end': index, 'text': clean_text[start:index+1]}
clean_text = clean_text[0:start] + clean_text[index+1:]
index -= index+1 - start
highlights.append(highlight)
highlight_open = False
index += 1

#Find highlight offsets with new clean doc
offsets = []
for highlight in highlights:
text = highlight['text'][1:-1].strip()
text_length = len(text)

start_index = clean_text.find(text)
if start_index == -1:
raise Exception("Highlight '" + text + "' not recognized in " + filename + "\n")
end_index = start_index + text_length
offsets.append([start_index, end_index])

#Can I delete below the comments below?
#if '[' in clean_text or ']' in clean_text:
# print "Unparsed brackets left in article:", article_number
# raise ArticleParseError("Brackets remain in clean text!",
# ArticleParseError.BRACKET_WARNING)
#

# print out our data.
# TODO: store this somewhere.
Expand All @@ -115,6 +157,7 @@ def parse_article(raw_text, filename):
'periodical': periodical,
'periodical_code': periodical_code,
'filename': filename,
'highlight_offsets': offsets,
}
return {
'metadata': metadata,
Expand Down
3 changes: 3 additions & 0 deletions data/pybossa_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ class ImproperConfigForRemote(Exception):
class InvalidTaskRun(Exception):
pass

class DecidingForceParserError(Exception):
pass

@django_rq.job('task_exporter', timeout=60, result_ttl=24*3600)
def create_or_update_remote_project_worker(project_id,
debug_presenter=False,
Expand Down