コード例 #1
0
        private string BuildItemDescription(XElement item)
        {
            XElement prepared = XElement.Parse(
                item.ToString(SaveOptions.DisableFormatting),
                LoadOptions.PreserveWhitespace);

            // ensure there is a space before gc/sns
            foreach (XElement gcOrSns in prepared.Descendants()
                     .Where(e => e.Name.LocalName == "gc" || e.Name.LocalName == "sns")
                     .ToList())
            {
                gcOrSns.AddBeforeSelf(" ");
            }

            // remove any element beginning with _ (_bm etc),
            // or containing only $ (there is a deplorable habit of
            // inserting empty elements with this placeholder)
            foreach (XElement meta in prepared.Descendants()
                     .Where(e =>
                            e.Name.LocalName.StartsWith("_", StringComparison.Ordinal) ||
                            (!e.HasElements && e.Value.Trim() == "$"))
                     .ToList())
            {
                meta.Remove();
            }

            // extract text and normalize its spaces
            string xml = prepared.ToString(SaveOptions.DisableFormatting);
            string txt = _tagRegex.Replace(xml, "");

            txt = _wsRegex.Replace(txt, " ");

            // cut the result
            return(TextCutter.Cut(txt, _textCutterOptions));
        }
コード例 #2
0
        private string ReduceLabel(string label)
        {
            if (label.Length <= _options.MaxLength)
            {
                return(label);
            }

            // extract tail
            string tail = "";
            Match  m    = _tailRegex.Match(label);

            if (m.Success)
            {
                tail = m.Groups[1].Value;
                int tailLen = tail.Length;
                tail = TextCutter.Cut(tail, _options);
                if (tail.Length < tailLen)
                {
                    tail += tail[1] == '[' ? ']' : ')';
                }

                label = label.Substring(0, m.Index);
            }

            string head = TextCutter.Cut(label, _options);

            return(head + (tail.Length > 0? (" " + tail) : ""));
        }
コード例 #3
0
        /// <summary>
        /// Returns a <see cref="System.String" /> that represents this instance.
        /// </summary>
        /// <returns>
        /// A <see cref="System.String" /> that represents this instance.
        /// </returns>
        public override string ToString()
        {
            StringBuilder sb = new StringBuilder("[WordEtymology] ");

            // lineages
            if (Lineages != null)
            {
                Lineage best = Lineages.OrderBy(l => l.Rank).FirstOrDefault();
                if (best != null)
                {
                    sb.Append(best);
                }
                if (Lineages.Count > 1)
                {
                    sb.Append(" (other ").Append(Lineages.Count - 1).Append(")");
                }
            }

            // date
            if (Date != null)
            {
                sb.Append(" (").Append(Date).Append(")");
            }

            // discussion
            if (!string.IsNullOrEmpty(Discussion))
            {
                sb.Append(TextCutter.Cut(Discussion, _options));
            }

            return(sb.ToString());
        }