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


C# Monitor.OnException方法代码示例

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


在下文中一共展示了Monitor.OnException方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: TryParse


//.........这里部分代码省略.........
                        } else {
                            // rare case were there is no space between id and the sentence.

                            if (monitor != null)
                                monitor.OnWarning("A sentence was skipped due a possible integrity loss.");

                            // The OpenNLP uses previous meta, but its better to just ignore the sentence
                            // since the previous meta its not related to the current.

                            sentence = null;
                            return false;                           
                        }
                    }
                    sent.Text = text;
                    sent.Metadata = meta;

                    // skip lines starting with ###
                    line = reader.ReadLine();
                    while (line != null && line.StartsWith("###")) {
                        line = reader.ReadLine();
                    }

                    var nodeStack = new List<AdNode>();

                    sent.Root = new AdNode {
                        SyntacticTag = "ROOT",
                        Level = 0
                    };

                    nodeStack.Add(sent.Root);

                    while (!string.IsNullOrEmpty(line) && !line.StartsWith("</s>") && !line.Equals("&&")) {
                        AdTreeElement element;

                        if (TryParseElement(out element, line, safeParse, monitor)) {
                            // The idea here is to keep a stack of nodes that are candidates for
                            // parenting the following elements (nodes and leafs).

                            // 1) When we get a new element, we check its level and remove from
                            // the top of the stack nodes that are brothers or nephews.
                            while (nodeStack.Count != 0 && element.Level > 0 &&
                                   element.Level <= nodeStack[nodeStack.Count - 1].Level) {
                                nodeStack.RemoveAt(nodeStack.Count - 1); // pop
                            }

                            if (element.IsLeaf) {
                                // 2b) There are parent candidates.
                                // look for the node with the correct level

                                if (element.Level == 0) {
                                    nodeStack[0].Elements.Add(element);
                                } else {
                                    var peek = nodeStack[nodeStack.Count - 1];
                                    var index = nodeStack.Count - 1;
                                    AdNode parent = null;
                                    while (parent == null) {
                                        if (peek.Level < element.Level) {
                                            parent = peek;
                                            break;
                                        }
                                        index--;
                                        if (index > -1) {
                                            peek = nodeStack[index];
                                        } else {
                                            parent = nodeStack[0];
                                        }
                                    }
                                    parent.AddElement(element);
                                }
                            } else {
                                // 3) Check if the element that is at the top of the stack is this
                                // node parent, if yes add it as a son

                                if (nodeStack.Count != 0 && nodeStack[nodeStack.Count - 1].Level < element.Level) {
                                    nodeStack[nodeStack.Count - 1].AddElement(element);
                                } else {
                                    throw new InvalidOperationException("Should not happen!");
                                }

                                nodeStack.Add((AdNode) element);
                            }
                        } else if (safeParse) {
                            // invalid element, so we skip this sentence...
                            sentence = null;
                            return false;
                        }
                        line = reader.ReadLine();
                    }
                }
            } catch (Exception ex) {
                if (monitor != null)
                    monitor.OnException(new InvalidDataException("Something went wrong during the AdSentence parse.", ex));

                sentence = null;
                return false;
            }

            sentence = sent;
            return true;
        }
开发者ID:knuppe,项目名称:SharpNL,代码行数:101,代码来源:AdSentenceParser.cs


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