sdmswitch/sdm/data/nls-cloud-sdm/script/RequestTransformer.lua
2023-10-11 04:39:21 +00:00

44 lines
1.2 KiB
Lua
Executable File
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

function grammarTransformer(grammar)
-- see : https://www.runoob.com/lua/lua-tables.html
--print("c++ call lua function parse")
mytable = {}
--mytable["SPEECH_URL"] = "custom:ws://11.164.63.252:8101/ws/v1"
--print("mytable 索引为 1 的元素是 ", mytable[1])
--print("mytable 索引为 wow 的元素是 ", mytable["wow"])
return mytable
end
function split(str, reps)
local resultStrList = {}
string.gsub(str, '[^'..reps..']+', function (w)
table.insert(resultStrList, w)
end)
return resultStrList
end
function vendorParamsTransformer(vendorParams)
-- vendorParams = k1=v1;k2=v2;k3=v3
-- 将verndorParam按需拆分为key:value对并可在此处进行相应修改
--print("input : ", vendorParams)
mytable = {}
local list = split(vendorParams, ";")
for _, s in ipairs(list) do
print(s)
local pos = string.find(s, '=')
if pos then
local key = string.sub(s, 0, pos - 1)
local value = string.sub(s, pos + 1)
--print("key = ", key, ", value = ", value)
mytable[key] = value
end
end
--mytable["SPEECH_VOCAB_ID"] = "11111"
return mytable
end