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


C# Monitor.OnWarning方法代码示例

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


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

示例1: TryParse

        /// <summary>
        /// Parses the specified sentence string.
        /// Converts the string representation of a sentence in a specified attributes and culture-specific
        /// format to its <see cref="AdSentence" /> equivalent. A return value indicates whether the
        /// conversion succeeded or failed.
        /// </summary>
        /// <param name="sentence">The sentence.</param>
        /// <param name="sentenceString">The sentence string.</param>
        /// <param name="para">The para.</param>
        /// <param name="isTitle">if set to <c>true</c> [is title].</param>
        /// <param name="isBox">if set to <c>true</c> [is box].</param>
        /// <param name="safeParse">if set to <c>true</c> the invalid sentences will be ignored.</param>
        /// <param name="monitor">The evaluation monitor. This value can be a <c>null</c> value.</param>
        /// <returns><c>true</c> if the <paramref name="sentenceString"/> parameter was converted successfully, <c>false</c> otherwise.</returns>
        /// <exception cref="System.IO.InvalidDataException">
        /// Something went wrong.
        /// </exception>
        /// <exception cref="System.InvalidOperationException">Should not happen!</exception>
        public static bool TryParse(
            out AdSentence sentence,
            string sentenceString,
            int para,
            bool isTitle,
            bool isBox,
            bool safeParse,
            Monitor monitor) {
            string text = null;
            string meta = null;
            var sent = new AdSentence();

            try {
                using (var reader = new StringReader(sentenceString)) {
                    // first line is <s ...>
                    var line = reader.ReadLine();

                    if (line == null) {
                        sentence = null;
                        return false;
                    }

                    var useSameTextAndMeta = false; // to handle cases where there are diff sug of parse (&&)

                    while (!line.StartsWith("SOURCE")) {
                        if (line.Equals("&&")) {
                            useSameTextAndMeta = true;
                            break;
                        }
                        line = reader.ReadLine();

                        if (line == null) {
                            sentence = null;
                            return false;
                        }
                    }

                    if (!useSameTextAndMeta) {
                        var metaFromSource = line.Substring(7);

                        line = reader.ReadLine();

                        if (line == null) {
                            sentence = null;
                            return false;
                        }

                        var start = line.IndexOf(" ", StringComparison.InvariantCulture);

                        text = FixPunctuation(line.Substring(start + 1).Trim());

                        if (start > 0) {
                            meta = line.Substring(0, start) + " p=" + para;
                            if (isTitle)
                                meta += " title";

                            if (isBox)
                                meta += " box";

                            meta += metaFromSource;
                        } 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();
                    }

//.........这里部分代码省略.........
开发者ID:knuppe,项目名称:SharpNL,代码行数:101,代码来源:AdSentenceParser.cs

示例2: TryParseElement

        /// <summary>
        /// Converts the specified string representation of a tree element to its <see cref="AdTreeElement"/> 
        /// equivalent and returns a value that indicates whether the conversion succeeded.
        /// </summary>
        /// <param name="element">
        /// When this method returns, contains the <see cref="AdTreeElement"/> value equivalent to the element 
        /// contained in <paramref name="line"/>, if the conversion succeeded, or <c>null</c> if the conversion 
        /// failed. The conversion fails if the <paramref name="line"/> parameter is null, is an empty string (""),
        /// or does not contain a valid string representation of a AdElement. This parameter is passed 
        /// uninitialized.
        /// </param>
        /// <param name="line">The string representation of the element.</param>
        /// <param name="safeParse">if set to <c>true</c> the invalid sentences will be ignored.</param>
        /// <param name="monitor">The evaluation monitor.</param>
        /// <returns><c>true</c> if the s parameter was converted successfully; otherwise, <c>false</c>.</returns>
        private static bool TryParseElement(out AdTreeElement element, string line, bool safeParse, Monitor monitor) {
            var m = nodePattern.Match(line);
            if (m.Success) {
                element = new AdNode {
                    Level = m.Groups[1].Length + 1,
                    SyntacticTag = m.Groups[2].Value
                };
                return true;
            }

            m = leafPattern.Match(line);
            if (m.Success) {
                element = new AdLeaf {
                    Level = m.Groups[1].Length + 1,
                    SyntacticTag = m.Groups[2].Value,
                    FunctionalTag = m.Groups[3].Value,
                    Lemma = m.Groups[4].Value,
                    SecondaryTag = m.Groups[5].Value,
                    MorphologicalTag = m.Groups[6].Value,
                    Lexeme = m.Groups[7].Value
                };
                return true;
            }

            m = punctuationPattern.Match(line);
            if (m.Success) {
                element = new AdLeaf {
                    Level = m.Groups[1].Length + 1,
                    Lexeme = m.Groups[2].Value
                };
                return true;
            }

            if (safeParse) {
                element = null;
                return false;
            }

            // Knuppe: The most bizarre cases I found, were invalid data (like HTML, inside the sentences)
            //         so I decided to implement the safeParse attribute, to ignore this junk...
            //
            //         I think any program should adapt to an error in a file. otherwise the files will never
            //         be fixed...                      

            // process the bizarre cases.
            if (line.Equals("_") || line.StartsWith("<lixo") || line.StartsWith("pause")) {
                element = null;
                return false;
            }

            if (line.StartsWith("=")) {
                m = bizarreLeafPattern.Match(line);
                if (m.Success) {
                    var leaf = new AdLeaf {
                        Level = m.Groups[1].Length + 1,
                        SyntacticTag = m.Groups[2].Value,
                        Lemma = m.Groups[3].Value,
                        MorphologicalTag = m.Groups[4].Value,
                        Lexeme = m.Groups[5].Value
                    };

                    if (!string.IsNullOrEmpty(leaf.Lemma) && leaf.Lemma.Length > 2) {
                        leaf.Lemma = leaf.Lemma.Substring(1);
                    }
                    element = leaf;
                    return true;
                }

                var level = line.LastIndexOf("=", StringComparison.InvariantCulture) + 1;
                if (level > 0 && level < line.Length - 2 && Regex.IsMatch(line.Substring(level + 1), "\\w.*?[\\.<>].*")) {
                    element = new AdLeaf {
                        Level = level + 1,
                        Lexeme = line.Substring(level + 1)
                    };
                    return true;
                }
            }

            if (monitor != null) {
                monitor.OnWarning("Couldn't parse leaf: " + line);
            }

            element = null;
            return false;
        }
开发者ID:knuppe,项目名称:SharpNL,代码行数:100,代码来源:AdSentenceParser.cs


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