-
Notifications
You must be signed in to change notification settings - Fork 14
Expand file tree
/
Copy pathrun.lua
More file actions
48 lines (41 loc) · 1.29 KB
/
run.lua
File metadata and controls
48 lines (41 loc) · 1.29 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
local senna = require 'senna'
local tokenizer = senna.Tokenizer()
local pos = senna.POS()
local chk = senna.CHK('BRK')
local ner = senna.NER('BRK')
local srl = senna.SRL('BRK')
-- just concatenate the SRL tags for each tokenized word
local function srltagsat(srltags, words, idx)
local txt = {}
table.insert(txt, string.format('%20s', srltags.verb[idx] and words[idx] or '-'))
for i=1,#srltags do
table.insert(txt, string.format('%10s', srltags[i][idx]))
end
return table.concat(txt)
end
for line in io.lines() do
local tokens = tokenizer:tokenize(line)
local words = tokens:words()
local postags = pos:forward(tokens)
local chktags = chk:forward(tokens, postags)
local nertags = ner:forward(tokens)
local srltags = srl:forward(tokens, postags)
for i=1,#postags do
local txt = {}
table.insert(txt, string.format('%20s', words[i]))
if pos then
table.insert(txt, string.format('%10s', postags[i]))
end
if chk then
table.insert(txt, string.format('%10s', chktags[i]))
end
if ner then
table.insert(txt, string.format('%10s', nertags[i]))
end
if srl then
table.insert(txt, string.format('%10s', srltagsat(srltags, words, i)))
end
print(table.concat(txt))
end
print()
end