本文整理汇总了Python中afinn.Afinn.data_dir方法的典型用法代码示例。如果您正苦于以下问题:Python Afinn.data_dir方法的具体用法?Python Afinn.data_dir怎么用?Python Afinn.data_dir使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类afinn.Afinn
的用法示例。
在下文中一共展示了Afinn.data_dir方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_data
# 需要导入模块: from afinn import Afinn [as 别名]
# 或者: from afinn.Afinn import data_dir [as 别名]
def test_data():
"""Test data files for format."""
afinn = Afinn()
filenames = listdir(afinn.data_dir())
for filename in filenames:
if not filename.endswith('.txt'):
continue
full_filename = join(afinn.data_dir(), filename)
with io.open(full_filename, encoding='UTF-8') as fid:
for line in fid:
# There should be the phrase and the score
# and nothing more
assert len(line.split('\t')) == 2
# The score should be interpretable as an int
phrase, score = line.split('\t')
assert type(int(score)) == int
示例2: test_emoticon
# 需要导入模块: from afinn import Afinn [as 别名]
# 或者: from afinn.Afinn import data_dir [as 别名]
def test_emoticon():
afinn = Afinn()
afinn.setup_from_file(join(afinn.data_dir(), 'AFINN-emoticon-8.txt'),
with_word_boundary=False)
score = afinn.score(':-)')
assert score > 0
score = afinn.score('This is a :-) smiley')
assert score > 0
score = afinn.score('Just so XOXO.')
assert score > 0
示例3: test_emoticon_upper_case
# 需要导入模块: from afinn import Afinn [as 别名]
# 或者: from afinn.Afinn import data_dir [as 别名]
def test_emoticon_upper_case():
afinn = Afinn()
afinn.setup_from_file(join(afinn.data_dir(), 'AFINN-emoticon-8.txt'),
word_boundary=False)
score = afinn.score(':d')
assert score == 0
# TODO
score = afinn.score(':D')
# assert score > 0
score = afinn.score('It is so: :D')