* */
HGNode addHyperEdgeInCell(
ComputeNodeResult result, Rule rule, int i, int j,
List<HGNode> ants, SourcePath srcPath, boolean noPrune
) {
HGNode res = null;
HashMap<Integer,DPState> dpStates = result.getDPStates();
double expectedTotalLogP = result.getExpectedTotalLogP(); // including outside estimation
double transitionLogP = result.getTransitionTotalLogP();
double finalizedTotalLogP = result.getFinalizedTotalLogP();
if(noPrune==false && beamPruner!=null && beamPruner.relativeThresholdPrune(expectedTotalLogP)){//the hyperedge should be pruned
this.chart.nPreprunedEdges++;
res = null;
}else{
HyperEdge dt = new HyperEdge(rule, finalizedTotalLogP, transitionLogP, ants, srcPath);
res = new HGNode(i, j, rule.getLHS(), dpStates, dt, expectedTotalLogP);
/** each node has a list of hyperedges,
* need to check whether the node is already exist,
* if yes, just add the hyperedges, this may change the best logP of the node
* */
HGNode oldNode = this.nodesSigTbl.get( res.getSignature() );
if (null != oldNode) { // have an item with same states, combine items
this.chart.nMerged++;
/** the position of oldItem in this.heapItems
* may change, basically, we should remove the
* oldItem, and re-insert it (linear time), this is too expense)
**/
if ( res.getPruneLogP() > oldNode.getPruneLogP() ) {//merget old to new: semiring plus
if(beamPruner!=null){
oldNode.setDead();// this.heapItems.remove(oldItem);
beamPruner.incrementDeadObjs();
}
res.addHyperedgesInNode(oldNode.hyperedges);
addNewNode(res, noPrune); //this will update the HashMap, so that the oldNode is destroyed
} else {//merge new to old, does not trigger pruningItems
oldNode.addHyperedgesInNode(res.hyperedges);
}
} else { // first time item
this.chart.nAdded++; // however, this item may not be used in the future due to pruning in the hyper-graph
addNewNode(res, noPrune);