From 4a7032fd0a6b76118ed29fe5a7208025ed931d0e Mon Sep 17 00:00:00 2001 From: Paco Zamora Martinez Date: Fri, 31 Jul 2015 23:18:24 +0200 Subject: [PATCH] Updated to allow lexClass Lua table instead of the cobj field --- .../binding/bind_nnlm_corpora.lua.cc | 20 ++++++++++++++++--- test/test.lua | 2 +- 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/packages/nnlm.corpora/binding/bind_nnlm_corpora.lua.cc b/packages/nnlm.corpora/binding/bind_nnlm_corpora.lua.cc index 576f313..b88f531 100644 --- a/packages/nnlm.corpora/binding/bind_nnlm_corpora.lua.cc +++ b/packages/nnlm.corpora/binding/bind_nnlm_corpora.lua.cc @@ -20,9 +20,23 @@ IMPLEMENT_LUA_TABLE_BIND_SPECIALIZATION(NNLMCorpora); //BIND_CONSTRUCTOR NNLMCorpora { const char *filename = lua_tostring(L,1); - LexClass *lex = LuaTable::convertTo(L,2); - const char *unk = lua_tostring(L,3); - uint32_t unk_id=0; + LexClass *lex; + if (LuaTable::checkType(L,2)) { + lex = LuaTable::convertTo(L,2); + } + else { + if (!lua_istable(L,2)) { + LUABIND_ERROR("Expecting lexClass object as second argument"); + } + lua_getfield(L,2,"cobj"); + if (lua_isnil(L,-1)) { + LUABIND_ERROR("Expecting lexClass object as second argument"); + } + lex = LuaTable::convertTo(L,-1); + lua_pop(L,1); + } + const char *unk = luaL_optstring(L,3,""); + uint32_t unk_id = 0u; if (!lex->getWordId(unk, unk_id)) { LUABIND_FERROR1("Unable to locate word %s", unk); } diff --git a/test/test.lua b/test/test.lua index e122897..64dc2bd 100644 --- a/test/test.lua +++ b/test/test.lua @@ -3,7 +3,7 @@ require "nnlmutils" local dir = arg[0]:dirname() local lex = lexClass.load(io.open(dir.."/voc.398")) -local corpora = nnlm.corpora(dir.."/sample.txt",lex.cobj,"") +local corpora = nnlm.corpora(dir.."/sample.txt",lex) local in_ds,out_ds = nnlm.dataset.both{ corpora = corpora, order = 3, -- trigrams