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

Improve title cleaning #198

Open
wants to merge 9 commits into
base: develop
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
17 changes: 16 additions & 1 deletion goose/extractors/title.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,22 @@ def clean_title(self, title):
# rebuild the title
title = u" ".join(title_words).strip()

return title
# Check if clean was bad, then apply old clean method
title_pieces = tuple()
for splitter in TITLE_SPLITTERS:
if splitter in title:
title_pieces = title.split(splitter)
break

largest_text_length = 0
# find the largest title piece
for current in title_pieces:
current_len = len(current)
if current_len > largest_text_length:
largest_text_length = current_len
title = current

return title.strip().rstrip()

def get_title(self):
"""\
Expand Down
2 changes: 1 addition & 1 deletion tests/data/extractors/content/test_allnewlyrics1.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"PJ Morton",
"Stevie Wonder"
],
"title": "\u201cOnly One\u201d Lyrics : PJ Morton (Ft. Stevie Wonder)",
"title": "PJ Morton (Ft. Stevie Wonder)",
"meta_favicon": "",
"meta_lang": "en"
}
Expand Down
2 changes: 1 addition & 1 deletion tests/data/extractors/content/test_businessWeek1.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"final_url": "http://www.businessweek.com/magazine/content/10_34/b4192066630779.htm",
"meta_keywords": "Olivia Munn, Attack of the Show, Jon Stewart, Daily Show, G4",
"cleaned_text": "Six years ago, Olivia Munn arrived in Hollywood with fading ambitions of making it as a sports reporter and set about deploying",
"title": "Olivia Munn: Queen of the Uncool",
"title": "Queen of the Uncool",
"meta_favicon": "",
"meta_lang": "en"
}
Expand Down
2 changes: 1 addition & 1 deletion tests/data/extractors/content/test_cnn1.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"final_url": "http://www.cnn.com/2010/POLITICS/08/13/democrats.social.security/index.html",
"meta_keywords": "",
"cleaned_text": "Washington (CNN) -- Democrats pledged ",
"title": "Democrats to use Social Security against GOP this fall - CNN.com",
"title": "Democrats to use Social Security against GOP this fall",
"meta_favicon": "http://i.cdn.turner.com/cnn/.element/img/3.0/global/misc/apple-touch-icon.png",
"meta_lang": "en"
}
Expand Down