本文整理汇总了C#中Parse.ExpandTopNode方法的典型用法代码示例。如果您正苦于以下问题:C# Parse.ExpandTopNode方法的具体用法?C# Parse.ExpandTopNode怎么用?C# Parse.ExpandTopNode使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Parse
的用法示例。
在下文中一共展示了Parse.ExpandTopNode方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: AdvanceParses
protected override Parse[] AdvanceParses(Parse p, double probMass) {
var q = 1 - probMass;
/** The index of the node which will be labeled in this iteration of advancing the parse. */
int advanceNodeIndex;
/** The node which will be labeled in this iteration of advancing the parse. */
Parse advanceNode = null;
var originalChildren = p.Children;
var children = CollapsePunctuation(originalChildren, punctSet);
var numNodes = children.Length;
if (numNodes == 0) {
return null;
}
if (numNodes == 1) {
//put sentence initial and final punct in top node
if (children[0].IsPosTag) {
return null;
}
p.ExpandTopNode(children[0]);
return new[] {p};
}
//determines which node needs to advanced.
for (advanceNodeIndex = 0; advanceNodeIndex < numNodes; advanceNodeIndex++) {
advanceNode = children[advanceNodeIndex];
if (!IsBuilt(advanceNode)) {
break;
}
}
if (advanceNode == null)
throw new InvalidOperationException("advanceNode is null.");
var originalZeroIndex = MapParseIndex(0, children, originalChildren);
var originalAdvanceIndex = MapParseIndex(advanceNodeIndex, children, originalChildren);
var newParsesList = new List<Parse>();
//call build model
buildModel.Eval(buildContextGenerator.GetContext(children, advanceNodeIndex), bProbs);
var doneProb = bProbs[doneIndex];
#if DEBUG
Debug("adi=" + advanceNodeIndex + " " + advanceNode.Type + "." + advanceNode.Label + " " + advanceNode + " choose build=" + (1 - doneProb) + " attach=" + doneProb);
#endif
if (1 - doneProb > q) {
double bprobSum = 0;
while (bprobSum < probMass) {
/** The largest un advanced labeling. */
var max = 0;
for (var pi = 1; pi < bProbs.Length; pi++) {
//for each build outcome
if (bProbs[pi] > bProbs[max]) {
max = pi;
}
}
if (bProbs[max].Equals(0d)) {
break;
}
var bprob = bProbs[max];
bProbs[max] = 0; //zero out so new max can be found
bprobSum += bprob;
var tag = buildModel.GetOutcome(max);
if (!tag.Equals(DONE)) {
var newParse1 = (Parse) p.Clone();
var newNode = new Parse(p.Text, advanceNode.Span, tag, bprob, advanceNode.Head);
newParse1.Insert(newNode);
newParse1.AddProbability(Math.Log(bprob));
newParsesList.Add(newParse1);
if (checkComplete) {
cProbs =
checkModel.Eval(checkContextGenerator.GetContext(newNode, children, advanceNodeIndex,
false));
#if DEBUG
Debug("building " + tag + " " + bprob + " c=" + cProbs[completeIndex]);
#endif
if (cProbs[completeIndex] > probMass) {
//just complete advances
SetComplete(newNode);
newParse1.AddProbability(Math.Log(cProbs[completeIndex]));
#if DEBUG
Debug("Only advancing complete node");
#endif
} else if (1 - cProbs[completeIndex] > probMass) {
//just incomplete advances
SetIncomplete(newNode);
newParse1.AddProbability(Math.Log(1 - cProbs[completeIndex]));
#if DEBUG
Debug("Only advancing incomplete node");
#endif
} else {
//both complete and incomplete advance
#if DEBUG
Debug("Advancing both complete and incomplete nodes");
#endif
SetComplete(newNode);
newParse1.AddProbability(Math.Log(cProbs[completeIndex]));
var newParse2 = (Parse) p.Clone();
var newNode2 = new Parse(p.Text, advanceNode.Span, tag, bprob, advanceNode.Head);
//.........这里部分代码省略.........