-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmp.cpp
More file actions
36 lines (33 loc) · 1.09 KB
/
mp.cpp
File metadata and controls
36 lines (33 loc) · 1.09 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
#include "mp.h"
extern Specs specs;
void em(JKArgs& args){
const string& src=args["src"];
const string& tgt=args["tgt"];
const string& out=args["o"];
const string& lex=args["lex"];
const string& lex_s2t=args["lex_s2t"];
const string& lex_t2s=args["lex_t2s"];
if(args.count("threshold"))specs.prune_threshold=stof(args["threshold"]);
if(args.count("prune"))specs.prune_method=stoi(args["prune"]);
bool knsmoothing=(args["kn"]=="true");
int round=5;
if(args.count("round"))round=stoi(args["round"]);
specs.max_phrase_length=args.count("maxlen")?stoi(args["maxlen"]):5;
MP1 mp1;
if(args.count("pt"))mp1.pt().read(args["pt"],args.count("reverse"));
CorpusCache cache;
mp1.init(src,tgt,lex_s2t,lex_t2s,cache);
if(lex!=""){
LexDic lex_s2t;
lex_s2t.read(lex);
mp1.pt().ibm1_scoring(lex_s2t);
}
else if(args["init"]=="frac")
mp1.pt().normalize_using_prob();
else
mp1.pt().normalize();
if(args.count("viterbi"))
mp1.viterbi(cache);
else
mp1.em(cache,round,out,knsmoothing);
}