示例#1
0
def handle_statement(stmt, features=False):
    """handle the statement returning a dictionary to return to the client"""
    print(stmt)
    result = dict()
    result['bias'] = compute_bias(stmt)
    result['statement'] = stmt
    if features:
        features = extract_bias_features(stmt)
        result['features'] = features
    return result
def bias_score( text ):
    """
    Main function calling the bsdetector.
    :param sentence: Sentence, the bias should be calculated for.
    :return: a bias value between 0 and 3
    """
    #text = text + "a"
    sentences = nltk.sent_tokenize( text )
    total_bias = 0

    for sentence in sentences:
        if len( sentence ) < 2:
            total_bias = total_bias
        else:
            total_bias += bias.compute_bias( sentence )

    if len( sentences ) != 0:
        total_bias = total_bias/len( sentences )

    return total_bias
示例#3
0
def test_compute():
    from bsdetector import bias
    assert_statement("The cat sucks.")
    fpath = 'input.txt'
    bias.enumerate_sentences(fpath)
    bias.compute_bias('brexit.txt')
示例#4
0
def assert_statement(stat):
    from bsdetector import bias
    r = bias.compute_bias(stat)
    print(stat)
    print(r)
    return r