forked from habeanf/yap
-
Notifications
You must be signed in to change notification settings - Fork 21
/
genunamlemmas.go
143 lines (124 loc) · 4.01 KB
/
genunamlemmas.go
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
package app
import (
"yap/nlp/format/lattice"
"yap/nlp/format/raw"
// "yap/nlp/format/mapping"
"yap/nlp/parser/disambig"
nlp "yap/nlp/types"
"fmt"
"log"
"os"
"github.com/gonuts/commander"
"github.com/gonuts/flag"
)
func GenUnAmbLemmasConfigOut() {
log.Println("Configuration")
log.Printf("Parameter Func:\t%v", paramFuncName)
log.Println()
log.Println("Data")
log.Printf("Raw Input:\t\t\t%s", inRawFile)
if !VerifyExists(tLatDis) {
return
}
log.Printf("Disamb. lattice file:\t%s", tLatDis)
if !VerifyExists(tLatDis) {
return
}
log.Printf("Ambig. lattice file:\t%s", tLatAmb)
if !VerifyExists(tLatAmb) {
return
}
}
func GetUnAmbLemmas(conf *disambig.MDConfig, pf nlp.MDParam) nlp.DisAmbMorphs {
return conf.Lattices.FindGoldDisAmbMorphs(conf.Mappings, pf)
}
func GetUnAmbLemmasCorpus(goldSequences []*disambig.MDConfig, rawSents []nlp.BasicSentence, pf nlp.MDParam) {
f, _ := os.Create(outMap)
defer f.Close()
prefix := log.Prefix()
for i, goldSeq := range goldSequences {
log.SetPrefix(fmt.Sprintf("%v graph# %v ", prefix, i))
result := GetUnAmbLemmas(goldSeq, pf)
for _, ambLemma := range result {
fmt.Fprintf(f, "%v,%v,%v,%v,%v\n", i, ambLemma.Token, ambLemma.GoldMorph, ambLemma.Lemma, ambLemma.CPOS)
}
}
log.SetPrefix(prefix)
}
func GenUnAmbLemmas(cmd *commander.Command, args []string) error {
paramFunc, exists := nlp.MDParams[paramFuncName]
if !exists {
log.Fatalln("Param Func", paramFuncName, "does not exist")
}
REQUIRED_FLAGS := []string{"d", "l"}
VerifyFlags(cmd, REQUIRED_FLAGS)
// RegisterTypes()
GenLemmasConfigOut()
if allOut {
log.Println()
// start processing - setup enumerations
log.Println("Setup enumerations")
}
SetupMDEnum()
if allOut {
log.Println("Amb. Lat:\tReading ambiguous lattices from", tLatAmb)
}
lAmb, lAmbE := lattice.ReadFile(tLatAmb, limit)
if lAmbE != nil {
log.Println(lAmbE)
return lAmbE
}
if allOut {
log.Println("Amb. Lat:\tRead", len(lAmb), "ambiguous lattices")
log.Println("Amb. Lat:\tConverting lattice format to internal structure")
}
goldAmbLat := lattice.Lattice2SentenceCorpus(lAmb, EWord, EPOS, EWPOS, EMorphProp, EMHost, EMSuffix)
// goldAmbLat = Limit(goldAmbLat, 1)
if allOut {
log.Println("Dis. Lat.:\tReading disambiguated lattices from", tLatDis)
}
lDis, lDisE := lattice.ReadFile(tLatDis, limit)
if lDisE != nil {
log.Println(lDisE)
return lDisE
}
if allOut {
log.Println("Dis. Lat.:\tRead", len(lDis), "disambiguated lattices")
log.Println("Dis. Lat.:\tConverting lattice format to internal structure")
}
goldDisLat := lattice.Lattice2SentenceCorpus(lDis, EWord, EPOS, EWPOS, EMorphProp, EMHost, EMSuffix)
// goldDisLat = Limit(goldDisLat, 1)
if allOut {
log.Println("Combining train files into gold morph graphs with original lattices")
}
combined := genLemmasInstances(goldDisLat, goldAmbLat)
rawSents, err := raw.ReadFile(inRawFile, limit)
if err != nil {
panic(fmt.Sprintf("Failed reading raw file - %v", err))
}
if allOut {
log.Println("Read", len(rawSents), "raw sentences")
log.Println("Getting lemmas for", len(combined), "sentences")
}
GetUnAmbLemmasCorpus(combined, rawSents, paramFunc)
return nil
}
func GenUnAmbLemmasCmd() *commander.Command {
cmd := &commander.Command{
Run: GenUnAmbLemmas,
UsageLine: "unamblemmas <file options> [arguments]",
Short: "gets unambiguous lemmas in the hebrew tb for gold paths",
Long: `
gets unambiguous lemmas in the hebrew tb for gold paths
$ ./yap unamblemmas -d <disamb. lat> -l <amb. lat> [-p <param func>] [options]
`,
Flag: *flag.NewFlagSet("unamblemmas", flag.ExitOnError),
}
cmd.Flag.StringVar(&tLatDis, "d", "", "Disambiguated Lattices File")
cmd.Flag.StringVar(&tLatAmb, "l", "", "Ambiguous Lattices File")
cmd.Flag.StringVar(&inRawFile, "r", "", "Input raw (tokenized) file")
cmd.Flag.StringVar(&outMap, "om", "", "Output Mapping File")
cmd.Flag.StringVar(¶mFuncName, "p", "Funcs_Main_POS_Both_Prop", "Param Func types: ["+nlp.AllParamFuncNames+"]")
cmd.Flag.IntVar(&limit, "limit", 0, "limit training set")
return cmd
}