text
stringlengths
0
828
n * spacing_horizontal + left,
layer_top - m * spacing_vertical
),
spacing_vertical / 4,
color = ""w"",
ec = ""k"",
zorder = 4
)
axes.add_artist(circle)
# edges
for n, (layer_size_a, layer_size_b) in enumerate(zip(
layer_sizes[:-1],
layer_sizes[1:]
)):
layer_top_a =\
spacing_vertical * (layer_size_a - 1) / 2 + (top + bottom) / 2
layer_top_b =\
spacing_vertical * (layer_size_b - 1) / 2 + (top + bottom) / 2
for m in xrange(layer_size_a):
for o in xrange(layer_size_b):
line = matplotlib.pyplot.Line2D(
[
n * spacing_horizontal + left,
(n + 1) * spacing_horizontal + left
],
[
layer_top_a - m * spacing_vertical,
layer_top_b - o * spacing_vertical
],
c = ""k""
)
axes.add_artist(line)"
4549,"def sentiment(
text = None,
confidence = False
):
""""""
This function accepts a string text input. It calculates the sentiment of
the text, ""pos"" or ""neg"". By default, it returns this calculated sentiment.
If selected, it returns a tuple of the calculated sentiment and the
classificaton confidence.
""""""
try:
words = text.split("" "")
# Remove empty strings.
words = [word for word in words if word]
features = word_features(words)
classification = classifier.classify(features)
confidence_classification = classifier.prob_classify(features).prob(classification)
except:
classification = None
confidence_classification = None
if confidence:
return (
classification,
confidence_classification
)
else:
return classification"
4550,"def usernames(
self
):
""""""
This function returns the list of unique usernames corresponding to the
tweets stored in self.
""""""
try:
return list(set([tweet.username for tweet in self]))
except:
log.error(""error -- possibly a problem with tweets stored"")"
4551,"def user_sentiments(
self,
username = None
):
""""""
This function returns a list of all sentiments of the tweets of a
specified user.
""""""
try:
return [tweet.sentiment for tweet in self if tweet.username == username]
except:
log.error(""error -- possibly no username specified"")
return None"
4552,"def user_sentiments_most_frequent(
self,
username = None,
single_most_frequent = True
):
""""""
This function returns the most frequent calculated sentiments expressed
in tweets of a specified user. By default, the single most frequent
sentiment is returned. All sentiments with their corresponding
frequencies can be returned also.
""""""
try:
sentiment_frequencies = collections.Counter(self.user_sentiments(
username = username
))
if single_most_frequent:
return sentiment_frequencies.most_common(1)[0][0]