Exemplo n.º 1
0
def test_task1_api3():
    '''
    Test whether entity multiplicity is handled properly
    '''
    tweets = [{'entities': {'dogs': [{'type': 'poodle'}, {'type': 'poodle'}]}}]
    assert (find_top_k_entities(tweets, ("dogs", "type"),
                                1) == [('poodle', 2)])
Exemplo n.º 2
0
def test_task1_api0():
    '''
    Test whether keys and subkeys are handled properly in find_top_k_entities
    '''

    tweets = [{'entities': {'dogs': [{'type': 'poodle'}]}}]
    assert (find_top_k_entities(tweets, ("dogs", "type"),
                                1) == [('poodle', 1)])
Exemplo n.º 3
0
def test_task1_api1():
    '''
    Test whether upper and lower case is handled properly
    '''
    tweets = [{
        'entities': {
            'dogs': [{
                'type': 'poodle'
            }]
        }
    }, {
        'entities': {
            'dogs': [{
                'type': 'Poodle'
            }]
        }
    }]
    assert (find_top_k_entities(tweets, ("dogs", "type"),
                                1) == [('poodle', 2)])
Exemplo n.º 4
0
def test_task1_api4():
    '''
    Test whether functionality works
    '''
    tweets = [{
        'entities': {
            'hashtags': [{
                'text': '#abc'
            }]
        }
    }, {
        'entities': {
            'hashtags': [{
                'text': '#bcd'
            }]
        }
    }, {
        'entities': {
            'hashtags': [{
                'text': '#bad'
            }]
        }
    }, {
        'entities': {
            'hashtags': [{
                'text': '#bcd'
            }]
        }
    }, {
        'entities': {
            'hashtags': [{
                'text': '#abc'
            }]
        }
    }]

    assert (find_top_k_entities(tweets, ("hashtags", "text"),
                                2) == [('#abc', 2), ('#bcd', 2)])
Exemplo n.º 5
0
def test_find_top_k_entities(params):
    '''
    test code for find_to_k_entities
    '''
    # fix the type of "entity_type"
    params["entity_type"] = tuple(params["entity_type"])

    # fix the type of expected
    params["expected"] = [tuple(t) for t in params["expected"]]

    recreate_msg = setup_tweets(params)

    call_str = "  analyze.find_top_k_entities(tweets, {}, {})"
    recreate_msg += call_str.format(params["entity_type"], params["k"])

    try:
        actual = analyze.find_top_k_entities(params["tweets"],
                                             params["entity_type"],
                                             params["k"])
    except Exception as e:
        msg = str(e) + "\n" + recreate_msg
        pytest.fail(msg)

    compare_tuple_lists(actual, params, recreate_msg)