View difference between Paste ID: GcDfb6AL and J0A0VNaX
SHOW: | | - or go back to the newest paste.
1
local sounddict = {}
2-
local sounddict = {
2+
3-
    ["hi"] = "",
3+
for key, list in pairs(chatsounds.List) do
4-
    ["hi there"] = "",
4+
	for key, data in pairs(list) do
5-
    ["eat me"] = "",
5+
		sounddict[key] = ""
6-
    ["eat"] = "",
6+
	end
7-
    ["an eye for an eye"] = "",
7+
8-
    ["an eye for an apple or banana"] = "",
8+
9-
    ["orange"] = "",
9+
10-
    ["cactus"] = "",
10+
11-
    ["cactus please"] = "",
11+
12-
    ["no sir"] = "",
12+
13-
    ["for"] = "",
13+
14-
}
14+
15
        currnode[part] = currnode[part] or {}
16-
local testphraselist = {
16+
17-
    "",
17+
18-
    "hi",
18+
19-
    "say hi",
19+
20-
    "hi there",
20+
21-
    "oh hi there",
21+
22-
    "an eye for an eye for an eye for an apple or banana",
22+
23-
    "an eye for an apple or banana",
23+
24-
    "cactus orange no sir",
24+
25-
    "eat me hi",
25+
26-
}
26+
27
    local stack_eposlist = { [0] = 1 }
28
    local stack_nodelist = { [0] = soundtree }
29
    local complete, atend = false, false
30
    local backtrack = false
31
    repeat
32
        local spos = stack_eposlist[stack_i]
33
        local node = stack_nodelist[stack_i]
34
        stack_i = stack_i+1
35
        -- get next word
36
        --local word_s, word, word_e, mods = string.match(phrase, "()([a-z_]+)()(%p%d)*", spos, true)
37
        local word_s, word_e, mods = string.find(phrase, "([a-z_]+)", spos)
38
        if word_s then
39
            --print(stack_i..": "..string.sub(phrase, word_s, word_e))
40
            -- we have a next word
41
            local word = string.sub(phrase, word_s, word_e)
42
            local subnode = node[word] -- (you could do pattern matching here)
43
            if subnode then
44
                -- we have a pattern that matches this next word
45
                -- (could be first, middle or last word in pattern!)
46
                stack_eposlist[stack_i] = word_e+1
47
                stack_nodelist[stack_i] = subnode
48
                -- continue
49
            else
50
                -- there is no continuing pattern that matches this word
51
                if stack_i == 1 then
52
                    -- this is the first word or next unmatched word and no pattern starts with it
53
                    -- so jump to next word
54
                    stack_i = 0
55
                    stack_eposlist[0] = word_e+1
56
                else
57
                    -- we were matching a pattern, see what comes of it
58
                    -- (this word did not continue any pattern, so it's not considered)
59
                    backtrack = true
60
                end
61
            end
62
        else
63
            --print(stack_i..": END")
64
            -- there is no next word, check for patterns
65
            -- (last few words may be rechecked if there is no sound for their nodes)
66
            if stack_i == 1 then
67
                -- we weren't matching anything
68
                complete = true
69
            else    
70
                atend = true
71
                backtrack = true
72
            end    
73
        end
74
        if backtrack then
75
            -- find the longest pattern on the stack that has a sound associated
76
            for stack_j = stack_i-1, 1, -1 do
77
                -- work backwards through each word to see if it has a sound
78
                local node = stack_nodelist[stack_j]
79
                local soundfile = node[soundtree_filekey]
80
                if soundfile then
81
                    -- this word has a sound
82
                    table.insert(foundlist, soundfile)
83
                    -- TODO: handle mods here
84
                    
85
                    if stack_j == stack_i-1 and atend then
86
                        -- we consumed the last word
87
                        complete = true
88
                    else
89
                        -- start searching for new patterns
90
                        stack_i = 0
91
                        -- resume from word after longest pattern with a sound
92
                        stack_eposlist[0] = stack_eposlist[stack_j]
93
                    end
94
                    -- stop backtracking
95
                    break
96
                end
97
            end
98
            backtrack, atend = false, false
99
        end
100
    until complete
101
    
102
    return foundlist
103
end
104
105
PrintTable(stuff(soundtree, "how could one man have slipped through your forces fingers time and time again how is it possible this is not some agent provocateur or highly trained assassin we are discussing gordon freeman is a theoretical physicist who had hardly earned the distinction of his ph d at the time of the black mesa incident i have good reason to believe that in the intervening years he was in a state that precluded further development of covert skills the man you have consistently failed to slow let alone capture is by all standards simply that an ordinary man how can you have failed to apprehend"))