-
Notifications
You must be signed in to change notification settings - Fork 14
Expand file tree
/
Copy pathchk.lua
More file actions
50 lines (44 loc) · 1.32 KB
/
chk.lua
File metadata and controls
50 lines (44 loc) · 1.32 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
local ffi = require 'ffi'
local senna = require 'senna.env'
local C = senna.C
local CHK = {}
local mt = {__index=CHK}
function CHK.new(hashtype)
hashtype = hashtype or 'IOBES'
local self = {}
self.hash = senna.Hash(senna.path, "hash/chk.lst")
if hashtype == 'IOBES' then
elseif hashtype == 'IOB' then
self.hash:IOBES2IOB()
elseif hashtype == 'BRK' then
self.hash:IOBES2BRK()
else
error('hashtype must be IOBES, IOB or BRK')
end
self.c = C.SENNA_CHK_new(senna.path, "data/chk.dat")
ffi.gc(self.c, C.SENNA_CHK_free)
setmetatable(self, mt)
return self
end
function CHK:forward(tokens, pos_labels)
assert(pos_labels, 'POS tags expected')
local chk_labels = C.SENNA_CHK_forward(self.c,
tokens.c.word_idx,
tokens.c.caps_idx,
pos_labels.__raw,
tokens.c.n)
local tags = {__raw=chk_labels}
for i=0,tokens.c.n-1 do
tags[i+1] = self.hash:key(chk_labels[i])
end
return tags
end
senna.CHK = {}
setmetatable(senna.CHK,
{__call=
function(self, ...)
return CHK.new(...)
end,
__index=CHK,
__newindex=CHK})
return CHK