}
}
double scale = 1.0;
int ngramStateID = 0;
DefaultSemiringParser parserEntropyP = new CrossEntropyOnHG(1, 0, scale, pFeatFunctions, pFeatFunctions);
DefaultSemiringParser parserEntropyQ = new CrossEntropyOnHG(1, 0, scale, qFeatFunctions, qFeatFunctions);
DefaultSemiringParser parserCrossentropyPQ = new CrossEntropyOnHG(1, 0, scale, pFeatFunctions, qFeatFunctions);
DiskHyperGraph diskHG = new DiskHyperGraph(symbolTbl, ngramStateID, true, null); //have model costs stored
diskHG.initRead(testItemsFile, testRulesFile, null);
for(int sent_id=0; sent_id < num_sents; sent_id ++){
System.out.println("#Process sentence " + sent_id);
HyperGraph testHG = diskHG.readHyperGraph();
//################setup the model: including estimation of variational model
//### step-1: run inside-outside
//note, inside and outside will use the transition_cost of each hyperedge, this cost is already linearly interpolated
TrivialInsideOutside insideOutsider = new TrivialInsideOutside();
insideOutsider.runInsideOutside(testHG, 0, 1, insideOutsideScalingFactor);//ADD_MODE=0=sum; LOG_SEMIRING=1;
//### step-2: model extraction based on the definition of Q
for(Map.Entry<VariationalNgramApproximator, FeatureTemplateBasedFF> entry : approximatorMap.entrySet()){
VariationalNgramApproximator approximator = entry.getKey();
FeatureTemplateBasedFF featureFunction = entry.getValue();
HashMap<String, Double> model = approximator.estimateModel(testHG, insideOutsider);
featureFunction.setModel(model);
}
//###############semiring parsing
parserEntropyP.insideEstimationOverHG(testHG);
parserEntropyQ.insideEstimationOverHG(testHG);
parserCrossentropyPQ.insideEstimationOverHG(testHG);
ExpectationSemiring pGoalSemiring = (ExpectationSemiring) parserEntropyP.getGoalSemiringMember(testHG);
ExpectationSemiring qGoalSemiring = (ExpectationSemiring) parserEntropyQ.getGoalSemiringMember(testHG);
ExpectationSemiring pqGoalSemiring = (ExpectationSemiring) parserCrossentropyPQ.getGoalSemiringMember(testHG);
pGoalSemiring.normalizeFactors();
pGoalSemiring.printInfor();
qGoalSemiring.normalizeFactors();
qGoalSemiring.printInfor();