Skip to content

Commit

Permalink
Updated to allow lexClass Lua table instead of the cobj field
Browse files Browse the repository at this point in the history
  • Loading branch information
pakozm committed Jul 31, 2015
1 parent 8ab126f commit 4a7032f
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 4 deletions.
20 changes: 17 additions & 3 deletions packages/nnlm.corpora/binding/bind_nnlm_corpora.lua.cc
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,23 @@ IMPLEMENT_LUA_TABLE_BIND_SPECIALIZATION(NNLMCorpora);
//BIND_CONSTRUCTOR NNLMCorpora
{
const char *filename = lua_tostring(L,1);
LexClass *lex = LuaTable::convertTo<LexClass*>(L,2);
const char *unk = lua_tostring(L,3);
uint32_t unk_id=0;
LexClass *lex;
if (LuaTable::checkType<LexClass*>(L,2)) {
lex = LuaTable::convertTo<LexClass*>(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<LexClass*>(L,-1);
lua_pop(L,1);
}
const char *unk = luaL_optstring(L,3,"<unk>");
uint32_t unk_id = 0u;
if (!lex->getWordId(unk, unk_id)) {
LUABIND_FERROR1("Unable to locate word %s", unk);
}
Expand Down
2 changes: 1 addition & 1 deletion test/test.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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,"<unk>")
local corpora = nnlm.corpora(dir.."/sample.txt",lex)
local in_ds,out_ds = nnlm.dataset.both{
corpora = corpora,
order = 3, -- trigrams
Expand Down

0 comments on commit 4a7032f

Please sign in to comment.