Пример #1
0
def test_rank_negative_entities(capsys):
    reader = [
        ('{"avg_sentiment": -12.0, ' '"name": "Patrick Macnee", "sentiment": -12.0}'),
        ('{"avg_sentiment": 5.0, ' '"name": "Paul Rudd", "sentiment": 5.0}'),
        ('{"avg_sentiment": -5.0, ' '"name": "Martha Plimpton", "sentiment": -5.0}'),
        ('{"avg_sentiment": 7.0, ' '"name": "Lucy (2014 film)", "sentiment": 7.0}'),
    ]

    main.rank_entities(reader, "neg", topn=1, reverse_bool=True)
    out, err = capsys.readouterr()

    expected = '{"avg_sentiment": -5.0, ' '"name": "Martha Plimpton", "sentiment": -5.0}'

    expected = "".join(sorted(expected))
    out = "".join(sorted(out.strip()))
    assert out == expected
Пример #2
0
def test_rank_positive_entities(capsys):
    reader = [('{"avg_sentiment": -12.0, '
               '"name": "Patrick Macnee", "sentiment": -12.0}'),
              ('{"avg_sentiment": 5.0, '
               '"name": "Paul Rudd", "sentiment": 5.0}'),
              ('{"avg_sentiment": -5.0, '
               '"name": "Martha Plimpton", "sentiment": -5.0}'),
              ('{"avg_sentiment": 7.0, '
               '"name": "Lucy (2014 film)", "sentiment": 7.0}')]

    main.rank_entities(reader, 'pos', topn=1, reverse_bool=False)
    out, err = capsys.readouterr()

    expected = ('{"avg_sentiment": 5.0, '
                '"name": "Paul Rudd", "sentiment": 5.0}')

    expected = ''.join(sorted(expected))
    out = ''.join(sorted(out.strip()))
    assert out == expected