-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.py
executable file
·68 lines (56 loc) · 1.82 KB
/
test.py
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#!/usr/bin/ruby
import CRFPP
import sys
try:
# -v 3: access deep information like alpha,beta,prob
# -nN: enable nbest output. N should be >= 2
tagger = CRFPP.Tagger("-m ../model -v 3 -n2")
# clear internal context
tagger.clear()
# add context
tagger.add("Confidence NN")
tagger.add("in IN")
tagger.add("the DT")
tagger.add("pound NN")
tagger.add("is VBZ")
tagger.add("widely RB")
tagger.add("expected VBN")
tagger.add("to TO")
tagger.add("take VB")
tagger.add("another DT")
tagger.add("sharp JJ")
tagger.add("dive NN")
tagger.add("if IN")
tagger.add("trade NN")
tagger.add("figures NNS")
tagger.add("for IN")
tagger.add("September NNP")
print "column size: " , tagger.xsize()
print "token size: " , tagger.size()
print "tag size: " , tagger.ysize()
print "tagset information:"
ysize = tagger.ysize()
for i in range(0, ysize-1):
print "tag " , i , " " , tagger.yname(i)
# parse and change internal stated as 'parsed'
tagger.parse()
print "conditional prob=" , tagger.prob(), " log(Z)=" , tagger.Z()
size = tagger.size()
xsize = tagger.xsize()
for i in range(0, (size - 1)):
for j in range(0, (xsize-1)):
print tagger.x(i, j) , "\t",
print tagger.y2(i) , "\t",
print "Details",
for j in range(0, (ysize-1)):
print "\t" , tagger.yname(j) , "/prob=" , tagger.prob(i,j),"/alpha=" , tagger.alpha(i, j),"/beta=" , tagger.beta(i, j),
print "\n",
print "nbest outputs:"
for n in range(0, 9):
if (not tagger.next()):
continue
print "nbest n=" , n , "\tconditional prob=" , tagger.prob()
# you can access any information using tagger.y()...
print "Done"
except RuntimeError, e:
print "RuntimeError: ", e,