Exemplo n.º 1
0
def test_example_features():
    vw_ex = vw(quiet=True)
    ex = vw_ex.example("1 |a two features |b more features here")
    ns = pyvw.namespace_id(ex, 1)
    assert ex.get_feature_id(ns, "a") == 127530
    ex.push_hashed_feature(ns, 1122)
    ex.push_features("x", [("c", 1.0), "d"])
    ex.push_feature(ns, 11000)
    assert ex.num_features_in("x") == 2
    assert ex.sum_feat_sq(ns) == 5.0
    ns2 = pyvw.namespace_id(ex, 2)
    ex.push_namespace(ns2)
    assert ex.pop_namespace()
Exemplo n.º 2
0
def test_example_features():
    vw_ex = vw(quiet=True)
    ex = vw_ex.example('1 |a two features |b more features here')
    ns = pyvw.namespace_id(ex, 1)
    assert ex.get_feature_id(ns, 'a') == 127530
    ex.push_hashed_feature(ns, 1122)
    ex.push_features('x', [('c', 1.), 'd'])
    ex.push_feature(ns, 11000)
    assert ex.num_features_in('x') == 2
    assert ex.sum_feat_sq(ns) == 5.0
    ns2 = pyvw.namespace_id(ex, 2)
    ex.push_namespace(ns2)
    assert ex.pop_namespace()
Exemplo n.º 3
0
def test_namespace_id():
    vw_ex = vw(quiet=True)
    ex = vw_ex.example("1 |a two features |b more features here")
    nm1 = pyvw.namespace_id(ex, 0)
    nm2 = pyvw.namespace_id(ex, 1)
    nm3 = pyvw.namespace_id(ex, 2)
    assert nm1.id == 0
    assert nm1.ord_ns == 97
    assert nm1.ns == "a"
    assert nm2.id == 1
    assert nm2.ord_ns == 98
    assert nm2.ns == "b"
    assert nm3.id == 2
    assert nm3.ord_ns == 128
    assert nm3.ns == "\x80"  # Represents string of ord_ns
Exemplo n.º 4
0
def test_example_namespace_id():
    vw_ex = vw(quiet=True)
    ex = vw_ex.example("1 |a two features |b more features here")
    ns = pyvw.namespace_id(ex, 1)
    assert isinstance(ex.get_ns(1), pyvw.namespace_id)
    assert isinstance(ex[2], pyvw.example_namespace)
    assert ex.setup_done is True
    assert ex.num_features_in(ns) == 3
Exemplo n.º 5
0
def test_example_namespace():
    vw_ex = vw(quiet=True)
    ex = vw_ex.example('1 |a two features |b more features here')
    ns_id = pyvw.namespace_id(ex, 1)
    ex_nm = pyvw.example_namespace(ex, ns_id, ns_hash=vw_ex.hash_space(ns_id.ns))
    assert isinstance(ex_nm.ex, pyvw.example)
    assert isinstance(ex_nm.ns, pyvw.namespace_id)
    assert ex_nm.ns_hash == 2514386435
    assert ex_nm.num_features_in() == 3
    assert ex_nm[2] == (11617, 1.0) # represents (feature, value)
    iter_obj =  ex_nm.iter_features()
    for i in range(ex_nm.num_features_in()):
        assert ex_nm[i] == next(iter_obj)
    assert ex_nm.pop_feature()
    ex_nm.push_features(ns_id, ['c', 'd'])
    assert ex_nm.num_features_in() == 4