Commit d8744a9d authored by Sacha's avatar Sacha Committed by SXibolet@2PITAU
Browse files

closed #9 and some other tweaks

parent ad67ee27
......@@ -131,9 +131,10 @@ def logout():
@application.route("/register_anon")
def register_anon():
u = session['username']
session.pop('username', None)
session.pop('user', None)
u = session.get('username')
if u is not None:
session.pop('username', None)
session.pop('user', None)
return redirect('/register')
@application.route("/account", methods=['GET', 'POST'])
......
......@@ -25,7 +25,7 @@ from twython.exceptions import TwythonAuthError
import tor_query
MAX_ATTEMPTS = 6
MAX_ATTEMPTS = 3
MAX_COMMENTARY = 500
TAG_RE = re.compile(r'<[^>]+>')
ARTICLE_SEARCH_BASE = 'https://api.nytimes.com/svc/search/v2/articlesearch.json?'
......@@ -106,12 +106,10 @@ class Article(object):
"""
def __init__(self, j, training=False):
self.lead = j['lead_paragraph']
self.abstract = j['abstract']
self.lead = j['snippet']
self.title = j['headline']['main']
self.source = j['source']
self.byline = j['byline']['original'] if (j['byline']) else None
self.abstract = self._no_html_ab()
self.url = j['web_url']
self.xlarge = 'https://www.nytimes.com/%s' % j['multimedia'][1]['url'] if len(j['multimedia']) > 1 else None
self.published = j['pub_date'][:10]
......@@ -135,9 +133,6 @@ class Article(object):
else:
return None
def _no_html_ab(self):
return BeautifulSoup(self.abstract or self.lead, 'html.parser').getText()
def _full_text(self, training):
"""NYT url --> full article text
"""
......@@ -179,9 +174,10 @@ def article_search(keyword, training=False):
response = tor_query.query('%s%s' % (ARTICLE_SEARCH_BASE, params))
# an Article will be None if it doesn't have body text (thus the partial)
# return an array of Article objects that have a body text
parsed_response = json.loads(response.read())['response']['docs']
return filter(partial(is_not, None),
map(lambda x: Article(x, training=training),
json.loads(response.read())['response']['docs']))
parsed_response))
def article_comments(url, offset=0, training=False):
......
`see spec here <https://sxibolet.github.io/docs.html>`__
\documentclass[a4paper,12pt]{article}
\begin{document}
\pagestyle{empty}
\begin{enumerate}
\item Switch to conditional probability for linguistic features:
Recall $p(X_{sent} = x_i) = \frac{P(x_i) \in C'_i}{\sum_{i=1}^{z} f(x_i) \in C'_i}$ is equivalent to the number of comments (tweets) with sentiment $x_i$ divided by the total number of comments. Therefore, $p(X_{caps} = x_i) = p(X_{sent} = x_i | C'_i \in Caps) = \frac{p(X_{sent} = x_i \cap C'_i \in Caps)}{p(C'_i \in Caps)}$ where $Caps$ is the set of comments that have capitalized terms. This works similarly for the extreme lexicon.
With SentiStrength, sentiment scores range from $-4$ to $4$ thus $z=9$.
\end{enumerate}
\end{document}
pdflatex fa15-report.tex
open fa15-report.pdf
This diff is collapsed.
......@@ -20,7 +20,7 @@
<footer>
<p>
<i><a href="https://sxibolet.2pitau.org/_static/pdf/big-data-2015.pdf" target=_blank>Hotspots of News Articles: Joint Mining of News Text &amp; Social Media to Discover Controversial Points in News</a></i>
<i><a href="https://graham.2pitau.org/_static/pdf/big-data-2015.pdf" target=_blank>Hotspots of News Articles: Joint Mining of News Text &amp; Social Media to Discover Controversial Points in News</a></i>
<br>
Ismini Lourentzou, Graham Dyer, Abhishek Sharma, ChengXiang Zhai &mdash; <tt>{lourent2, gdyer2, sharma51, czhai}@illinois.edu</tt> &mdash; University of Illinois, Urbana-Champaign.
<br>
......
......@@ -41,7 +41,7 @@
<hr>
Please login or <a href="register">register</a>.
</span>
<p><noscript><span style='font-family: Optima'>CONTROVERSY</span> <i>requires JavaScript. We&rsquo;re not doing anything fishy: the project is free (as in freedom) software, and you may view the source files here: <a href='https://github.com/sxibolet/controversy' target=_blank>https://github.com/sxibolet/controversy</a></i></noscript></p>
<p><noscript><span style='font-family: Optima'>CONTROVERSY</span> <i>requires JavaScript. We&rsquo;re not doing anything fishy: the project is free (as in freedom) software, and you may view the source files here: <a href='https://github.com/SXibolet/controversy' target=_blank>https://github.com/SXibolet/controversy</a></i></noscript></p>
<form style="display:none" method=POST>
{{ form.hidden_tag() }}
{{ form.email(value=username, type="email", class_="field", placeholder="email (username)", required="required") }}
......
......@@ -39,7 +39,7 @@
</ul>
<article ng-bind-html="highlight(article.full, article.sentences)"></article>
<p>
Copyright &copy; 2016, The New York Times Company {% endraw %} <img src="{{ url_for('static', filename='img/nytimes.png') }}" /> {% raw %}. All Rights Reserved. <a target=_blank href="{{ article.url }}">Article on nytimes.com</a>
Copyright &copy; 2017, The New York Times Company {% endraw %} <img src="{{ url_for('static', filename='img/nytimes.png') }}" /> {% raw %}. All Rights Reserved. <a target=_blank href="{{ article.url }}">Article on nytimes.com</a>
</p>
</main>
{% endraw %}
......@@ -23,7 +23,7 @@
<div class=article ng-class="{ 'most-controversial' : $first, 'least-controversial' : $last }">
<a href="#results/{{ $index }}" class=title ng-bind-html="($index+1) + '. ' + article.title"></a>
<img ng-show="article.xlarge" ng-src="{{ article.xlarge }}" />
<p ng-bind-html="article.abstract"></p>
<p ng-bind-html="article.lead"></p>
<p class=url>
<a href="#results/{{ $index }}">Read the full article {{ article.sentiment_entropy}}</a>
</p>
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment