Example #1
0
def test_hydra_depths():
    hdr = Hydraseq('main')

    assert len(
        hdr.d_depths) == 0, "Initially a hydraseq should have no depth sets"
    st = "one two three four five six seven eight nine ten"
    hdr.insert(st)
    assert len(
        hdr.d_depths) == 10, "there should be one set per depht traversed"
    st_lst = st.split()
    for idx, set_item in hdr.d_depths.items():
        assert len(hdr.d_depths[idx]
                   ) == 1, "there should be one item in each depth level"
        assert next(node for node in hdr.d_depths[idx]).key == st_lst[
            idx - 1], "the nodes should be in depth order"

    hdr.look_ahead("one two three four five six seven eight nine")
    last_node = next(node for node in hdr.next_nodes)
    assert last_node.depth == 10

    hdr.insert("one two three four five six siete ocho nueve diez")
    hdr.insert("one two three four five six siete ocho nueve")
    last_node = next(node for node in hdr.next_nodes)
    assert last_node.depth == 10

    hdr.insert("one two three four five six siete")
    last_node = next(node for node in hdr.next_nodes)
    assert last_node.depth == 8
Example #2
0
def test_01_02_01_01_sequence():
    hdr = Hydraseq('main')

    hdr.insert([['a'], ['b'], ['d'], ['e']])
    hdr.insert([['a'], ['c'], ['d'], ['e']])
    check_active(hdr, 1, ['a c d e'], ['e'])
    check_next(hdr, 0, [], [])

    hdr.look_ahead([['a']])
    check_active(hdr, 1, ['a'], ['a'])
    check_next(hdr, 2, ['a b', 'a c'], ['b', 'c'])

    hdr.look_ahead([['a'], ['b', 'f']])
    check_active(hdr, 1, ['a b'], ['b'])
    check_next(hdr, 1, ['a b d'], ['d'])

    hdr.look_ahead([['a'], ['b', 'c'], ['d']])
    check_active(hdr, 2, ['a b d', 'a c d'], ['d'])
    check_next(hdr, 2, ['a b d e', 'a c d e'], ['e'])

    hdr.look_ahead([['a'], ['b'], ['d']])
    check_active(hdr, 1, ['a b d'], ['d'])
    check_next(hdr, 1, ['a b d e'], ['e'])

    hdr.look_ahead([['a'], ['b']])
    check_active(hdr, 1, ['a b'], ['b'])
    check_next(hdr, 1, ['a b d'], ['d'])
Example #3
0
def test_01_01_sequence():
    hdr = Hydraseq('main')

    hdr.insert([['a'], ['b']])
    check_active(hdr, 1, ['a b'], ['b'])
    check_next(hdr, 0, [], [])

    hdr.look_ahead([['a']])
    check_active(hdr, 1, ['a'], ['a'])
    check_next(hdr, 1, ['a b'], ['b'])
Example #4
0
def test_streaming():
    hdr = Hydraseq('streaming')

    hdr.insert("the quick brown fox")

    assert hdr.look_ahead("the quick").get_next_values() == ["brown"]

    hdr.reset()

    assert hdr.look_ahead("the").get_next_values() == ["quick"]
    assert hdr.hit("quick", None).get_next_values() == ["brown"]
Example #5
0
def test_self_insert():
    hdq = Hydraseq('_')
    hdq.self_insert(
        "Burger King wants people to download its app. So it's sending them to McDonald's for access to a one-cent Whopper."
    )
    assert len(hdq.columns) == 38
    assert sorted(
        hdq.look_ahead("Burger King wants").get_next_values()) == sorted(
            ['people', '_3'])
    assert sorted(
        hdq.look_ahead("Burger King wants").get_active_values()) == sorted(
            ['wants'])
Example #6
0
def test_cloning_hydra():
    hdr0 = Hydraseq('zero')

    hdr0.insert("the quick brown fox")

    hdr1 = Hydraseq('one', hdr0)

    assert hdr1.look_ahead("the quick").get_next_values() == ["brown"]

    hdr1.reset()

    assert hdr1.look_ahead("the").get_next_values() == ["quick"]
    assert hdr1.hit("quick", None).get_next_values() == ["brown"]
Example #7
0
def test_activate_node_pathway():
    hdr = Hydraseq('main')

    hdr.insert("a b c d e f LETTERS")
    hdr.insert("1 2 3 4 5 6 NUMBERS")
    hdr.insert("a1 2b b4 MIXED")

    hdr.activate_node_pathway('LETTERS')

    assert {node.key
            for node in hdr.path_nodes
            } == {"a", "b", "c", "d", "e", "f", "LETTERS"}
    assert hdr.look_ahead("a b c d").get_active_values() == ["d"]
    assert hdr.look_ahead("a b c d").get_next_values() == ["e"]
    assert {node.key
            for node in hdr.path_nodes
            } == {"a", "b", "c", "d", "e", "f", "LETTERS"}
    assert hdr.look_ahead("1 2 3 4").get_active_values() == []
    assert hdr.look_ahead("1 2 3 4").get_next_values() == []

    hdr.reset_node_pathway()
    assert {node.key for node in hdr.path_nodes} == set()
    assert hdr.look_ahead("a b c d").get_active_values() == ["d"]
    assert hdr.look_ahead("a b c d").get_next_values() == ["e"]
    assert {node.key for node in hdr.path_nodes} == set()
    assert hdr.look_ahead("1 2 3 4").get_active_values() == ["4"]
    assert hdr.look_ahead("1 2 3 4").get_next_values() == ["5"]
Example #8
0
def test_get_sequence_multiple():
    hds2 = Hydraseq('_')
    hds2.insert([['a'], ['B'], ['c']])
    hds2.insert([['a'], ['b'], ['c']])

    nxts = hds2.look_ahead([['a'], ['b', 'B']]).next_nodes
    assert sorted([str(nxt.get_sequence_nodes())
                   for nxt in nxts]) == ['[[a], [B]]', '[[a], [b]]']
Example #9
0
def test_get_sequence_nodes():
    hds = Hydraseq('_')
    hds.insert('a b c d e f g h i j')

    nxt = hds.look_ahead('a b c d e f g h i').next_nodes.pop()
    assert nxt.get_sequence() == 'a b c d e f g h i j'
    assert str(nxt.get_sequence_nodes()
               ) == '[[a], [b], [c], [d], [e], [f], [g], [h], [i]]'
Example #10
0
def test_active_synapses():
    hdr = Hydraseq('main')

    hdr.insert("a b c d e f")
    hdr.insert("1 2 3 4 5 6")

    assert hdr.look_ahead("a b c d e").get_active_values() == ['e']
    assert hdr.look_ahead("1 2 3 4 5").get_active_values() == ['5']

    hdr.set_active_synapses(['f'])

    assert hdr.look_ahead("a b c d e").get_active_values() == ['e']
    assert hdr.look_ahead("1 2 3 4 5").get_active_values() == []
    assert hdr.look_ahead("a b c d").get_active_values() == ['d']

    hdr.reset_active_synapses()

    assert hdr.look_ahead("a b c d e").get_active_values() == ['e']
    assert hdr.look_ahead("1 2 3 4 5").get_active_values() == ['5']
    assert hdr.look_ahead("a b c d").get_active_values() == ['d']
Example #11
0
def test_sentence():
    hdr = Hydraseq('main')

    hdr.insert("The quick brown fox jumped over the lazy dog")
    assert hdr.look_ahead("The quick brown").get_next_values() == ['fox']

    hdr.insert("The quick brown cat jumped over the lazy dog")
    assert hdr.look_ahead("The quick brown").get_next_values() == [
        'cat', 'fox'
    ]

    hdr.insert("The quick brown cat jumped over the lazy hound")
    assert hdr.look_ahead("The quick brown").get_next_values() == [
        'cat', 'fox'
    ]

    hdr.look_ahead([['The'], ['quick'], ['brown'], ['fox', 'cat']])
    check_active(hdr, 2, ['The quick brown cat', 'The quick brown fox'],
                 ['cat', 'fox'])
    check_next(hdr, 2,
               ['The quick brown cat jumped', 'The quick brown fox jumped'],
               ['jumped'])
Example #12
0
def test_compare():
    hq = Hydraseq('_')

    hq.insert('small large GROWING')
    hq.insert('large small SHRINKING')
    hq.insert('left right EAST')
    hq.insert('right left WEST')
    hq.insert('circle square SHAPER')
    hq.insert('square circle BLUNTER')

    hq.look_ahead([['small', 'left', 'circle'], ['small', 'right', 'circle']])
    assert hq.get_next_values() == ['EAST']

    hq.look_ahead([['small', 'left', 'square'], ['small', 'right', 'circle']])
    assert hq.get_next_values() == ['BLUNTER', 'EAST']

    hq.look_ahead([['small', 'left', 'circle'], ['large', 'right', 'circle']])
    assert hq.get_next_values() == ['EAST', 'GROWING']

    hq.look_ahead([['large', 'right', 'circle'], ['small', 'left', 'circle']])
    assert hq.get_next_values() == ['SHRINKING', 'WEST']
Example #13
0
def test_get_sequence_nodes_out_of_order():
    hds1 = Hydraseq('_')
    hds1.insert('C A B')

    nxt1 = hds1.look_ahead('C A').next_nodes.pop()
    assert nxt1.get_sequence() == 'C A B'