Ejemplo n.º 1
0
        /// <summary>
        /// Finds the list of string that matches any of the patterns with the indices of each occurrence in sequence.
        /// </summary>
        /// <param name="patterns">List of patterns that needs to be searched in Sequence.</param>
        /// <param name="startIndex">Minimum index in Sequence at which match has to start.</param>
        /// <param name="ignoreCase">
        /// if true ignore character casing while match.
        /// <remarks>
        /// Note that symbols in Sequence are always Upper case.
        /// </remarks>
        /// </param>
        /// <returns></returns>
        public IDictionary <string, IList <int> > FindMatches(IList <string> patterns, int startIndex = 0, bool ignoreCase = true)
        {
            if (PatternFinder == null)
            {
                PatternFinder = new BoyerMoore();
            }

            return(PatternFinder.FindMatch(
                       this,
                       PatternConverter.GetInstanace(this.Alphabet).Convert(patterns).Values.SelectMany(pattern => pattern).ToList()));
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Returns an instance of PatternConverter
        /// </summary>
        public static IPatternConverter GetInstanace(IAlphabet alphabetSet)
        {
            IPatternConverter patternConverter = null;

            if (!_patternConverter.TryGetValue(alphabetSet, out patternConverter))
            {
                lock (_patternConverter)
                {
                    if (!_patternConverter.TryGetValue(alphabetSet, out patternConverter))
                    {
                        patternConverter = new PatternConverter(alphabetSet);
                        _patternConverter.Add(alphabetSet, patternConverter);
                    }
                }
            }

            return(patternConverter);
        }