Пример #1
0
        public void Apply(string text, string expected)
        {
            StandardTextFilter filter = new StandardTextFilter();
            StringBuilder      sb     = new StringBuilder(text);

            filter.Apply(sb);
            Assert.Equal(expected, sb.ToString());
        }
Пример #2
0
        /// <summary>
        /// Get all the key=value pairs (pins) exposed by the implementor.
        /// </summary>
        /// <remarks>
        /// For each entry, the pins emitted are (omitting duplicates):
        /// <list type="bullet">
        /// <item>
        /// <term>biblio.type</term>
        /// <description>The entry type ID.</description>
        /// </item>
        /// <item>
        /// <term>biblio.author</term>
        /// <description>The filtered last name of the author.</description>
        /// </item>
        /// <item>
        /// <term>biblio.title</term>
        /// <description>The filtered title.</description>
        /// </item>
        /// <item>
        /// <term>biblio.container</term>
        /// <description>The filtered container name.</description>
        /// </item>
        /// <item>
        /// <term>biblio.keyword</term>
        /// <description>The keyword.</description>
        /// </item>
        /// </list>
        /// Filtering implies preserving only letters, digits, whitespaces
        /// (normalized), and apostrophe. Letters are all lowercase and without
        /// any diacritics.
        /// </remarks>
        /// <param name="item">The optional item. The item with its parts
        /// can optionally be passed to this method for those parts requiring
        /// to access further data.</param>
        /// <returns>The pins.</returns>
        public override IEnumerable <DataPin> GetDataPins(IItem item = null)
        {
            // collect data from entries
            HashSet <string> typeIds    = new HashSet <string>();
            HashSet <string> authors    = new HashSet <string>();
            HashSet <string> titles     = new HashSet <string>();
            HashSet <string> containers = new HashSet <string>();
            HashSet <string> keywords   = new HashSet <string>();

            foreach (BibEntry entry in Entries)
            {
                // type
                if (entry.TypeId != null)
                {
                    typeIds.Add(entry.TypeId);
                }

                // authors (filtered last names)
                AddAuthors(entry.Authors, authors);
                AddAuthors(entry.Contributors, authors);

                // title (filtered)
                string title = StandardTextFilter.Apply(entry.Title);
                if (!string.IsNullOrEmpty(title))
                {
                    titles.Add(title);
                }

                // container (filtered)
                string container = StandardTextFilter.Apply(entry.Container);
                if (!string.IsNullOrEmpty(container))
                {
                    containers.Add(container);
                }

                // keywords
                if (entry.Keywords?.Length > 0)
                {
                    foreach (Keyword k in entry.Keywords)
                    {
                        keywords.Add(k.Value);
                    }
                }
            }

            // add pins
            List <DataPin> pins = new List <DataPin>();

            pins.AddRange(from s in typeIds select CreateDataPin("biblio.type", s));
            pins.AddRange(from s in authors select CreateDataPin("biblio.author", s));
            pins.AddRange(from s in titles select CreateDataPin("biblio.title", s));
            pins.AddRange(from s in containers select CreateDataPin("biblio.container", s));
            pins.AddRange(from s in keywords select CreateDataPin("biblio.keyword", s));

            return(pins);
        }
Пример #3
0
 private static void AddAuthors(IList <BibAuthor> authors,
                                HashSet <string> target)
 {
     if (authors?.Count > 0)
     {
         foreach (BibAuthor author in authors)
         {
             target.Add(StandardTextFilter.Apply(author.LastName));
         }
     }
 }
Пример #4
0
        /// <summary>
        /// Get all the pins exposed by the implementor.
        /// Pins: for each entry (avoiding duplicates): <c>fr.author</c>=author
        /// (filtered), <c>fr.work</c>=work (filtered), and optionally
        /// <c>fr.citation-uri</c>=citation URI and <c>fr.tag</c>=tag.
        /// </summary>
        /// <param name="item">The optional item. The item with its parts
        /// can optionally be passed to this method for those parts requiring
        /// to access further data.</param>
        /// <returns>Pins.</returns>
        public IEnumerable <DataPin> GetDataPins(IItem item = null)
        {
            List <DataPin>   pins      = new List <DataPin>();
            HashSet <string> authors   = new HashSet <string>();
            HashSet <string> works     = new HashSet <string>();
            HashSet <string> citations = new HashSet <string>();
            HashSet <string> tags      = new HashSet <string>();
            string           filtered;

            foreach (QuotationEntry entry in Entries)
            {
                if (!string.IsNullOrEmpty(entry.Author))
                {
                    filtered = StandardTextFilter.Apply(entry.Author);
                    if (filtered.Length > 0)
                    {
                        authors.Add(filtered);
                    }
                }
                if (!string.IsNullOrEmpty(entry.Work))
                {
                    filtered = StandardTextFilter.Apply(entry.Work);
                    if (filtered.Length > 0)
                    {
                        works.Add(filtered);
                    }
                }
                if (!string.IsNullOrEmpty(entry.CitationUri))
                {
                    citations.Add(entry.CitationUri);
                }
                if (!string.IsNullOrEmpty(entry.Tag))
                {
                    tags.Add(entry.Tag);
                }
            }

            // fr.author
            AddSetToPins(authors, PartBase.FR_PREFIX + "author", pins);

            // fr.work
            AddSetToPins(works, PartBase.FR_PREFIX + "work", pins);

            // fr.citation-uri
            AddSetToPins(citations, PartBase.FR_PREFIX + "citation-uri", pins);

            // fr.tag
            AddSetToPins(tags, PartBase.FR_PREFIX + "tag", pins);

            return(pins);
        }