当前位置: 首页>>代码示例>>C#>>正文


C# Parse.Clone方法代码示例

本文整理汇总了C#中Parse.Clone方法的典型用法代码示例。如果您正苦于以下问题:C# Parse.Clone方法的具体用法?C# Parse.Clone怎么用?C# Parse.Clone使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Parse的用法示例。


在下文中一共展示了Parse.Clone方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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);
//.........这里部分代码省略.........
开发者ID:lovethisgame,项目名称:SharpNL,代码行数:101,代码来源:Parser.cs

示例2: AdvanceTags

        /// <summary>
        /// Advances the parse by assigning it POS tags and returns multiple tag sequences.
        /// </summary>
        /// <param name="p">The parse to be tagged.</param>
        /// <returns>Parses with different POS-tag sequence assignments.</returns>
        /// <exception cref="System.InvalidOperationException">No tag sequence.</exception>
        protected Parse[] AdvanceTags(Parse p) {
            var children = p.Children;
            var words = new string[children.Length];
            for (int i = 0, il = children.Length; i < il; i++) {
                words[i] = children[i].CoveredText;
            }
            var ts = tagger.TopKSequences(words);

            if (ts.Length == 0)
                throw new InvalidOperationException("No tag sequence.");

            var newParses = new Parse[ts.Length];
            for (var i = 0; i < ts.Length; i++) {
                var tags = ts[i].Outcomes.ToArray();

                newParses[i] = (Parse) p.Clone(); //copies top level

                if (createDerivationString)
                    newParses[i].Derivation.Append(i).Append(".");

                for (var j = 0; j < words.Length; j++) {
                    var word = children[j];

                    //System.err.println("inserting tag "+tags[j]);

                    var prob = ts[i].Probabilities[j];
                    newParses[i].Insert(new Parse(word.Text, word.Span, tags[j], prob, j));
                    newParses[i].AddProbability(Math.Log(prob));
                    //newParses[i].show();
                }
            }
            return newParses;
        }
开发者ID:lovethisgame,项目名称:SharpNL,代码行数:39,代码来源:AbstractBottomUpParser.cs

示例3: AdvanceChunks

        /// <summary>
        /// Returns the top chunk sequences for the specified parse.
        /// </summary>
        /// <param name="p">A pos-tag assigned parse.</param>
        /// <param name="minChunkScore">A minimum score below which chunks should not be advanced.</param>
        /// <returns>The top chunk assignments to the specified parse.</returns>
        protected virtual Parse[] AdvanceChunks(Parse p, double minChunkScore) {
            // chunk
            var children = p.Children;
            var words = new string[children.Length];
            var pTags = new string[words.Length];
            //var probs = new double[words.Length];

            for (int i = 0, il = children.Length; i < il; i++) {
                words[i] = children[i].Head.CoveredText;
                pTags[i] = children[i].Type;
            }

            //System.err.println("adjusted mcs = "+(minChunkScore-p.getProb()));

            var cs = chunker.TopKSequences(words, pTags, minChunkScore - p.Probability);

            var newParses = new Parse[cs.Length];
            for (var si = 0; si < cs.Length; si++) {
                newParses[si] = (Parse) p.Clone(); //copies top level

                if (createDerivationString) 
                    newParses[si].Derivation.Append(si).Append(".");

                var tags = cs[si].Outcomes.ToArray();

                var start = -1;
                var end = 0;
                string type = null;

                for (var j = 0; j <= tags.Length; j++) {

                    if (j != tags.Length) {
                        newParses[si].AddProbability(Math.Log(cs[si].Probabilities[j]));
                    }
                    if (j != tags.Length && tags[j].StartsWith(CONT)) {
                        // if continue just update end chunking tag don't use contTypeMap
                        end = j;
                    } else {
                        //make previous constituent if it exists
                        if (type != null) {

                            var p1 = p.Children[start];
                            var p2 = p.Children[end];

                            var cons = new Parse[end - start + 1];
                            cons[0] = p1;
                            //cons[0].label="Start-"+type;
                            if (end - start != 0) {
                                cons[end - start] = p2;
                                //cons[end-start].label="Cont-"+type;
                                for (var ci = 1; ci < end - start; ci++) {
                                    cons[ci] = p.Children[ci + start];
                                    //cons[ci].label="Cont-"+type;
                                }
                            }
                            var chunk = new Parse(p1.Text, new Span(p1.Span.Start, p2.Span.End), type, 1, headRules.GetHead(cons, type)) {
                                    IsChunk = true
                                };

                            newParses[si].Insert(chunk);
                        }
                        if (j != tags.Length) {
                            // update for new constituent
                            if (tags[j].StartsWith(START)) {
                                // don't use startTypeMap these are chunk tags
                                type = tags[j].Substring(START.Length);
                                start = j;
                                end = j;
                            } else {
                                // other
                                type = null;
                            }
                        }
                    }
                }
            }
            return newParses;
        }
开发者ID:lovethisgame,项目名称:SharpNL,代码行数:84,代码来源:AbstractBottomUpParser.cs


注:本文中的Parse.Clone方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。