public ProjectTextSearcher(StringSearcher searcher, List <IOccurence> items, FindTextSearchFlags searchFlags, ISolution solution)
 {
     _searcher    = searcher;
     _searchFlags = searchFlags;
     _items       = items;
     _solution    = solution;
 }
        public PossibilityAutoComplete(FdoCache cache, Mediator mediator, ICmPossibilityList list, Control control,
                                       string displayNameProperty, string displayWs)
        {
            m_cache               = cache;
            m_mediator            = mediator;
            m_control             = control;
            m_displayNameProperty = displayNameProperty;
            m_displayWs           = displayWs;

            m_listBox = new ComboListBox {
                DropDownStyle = ComboBoxStyle.DropDownList, ActivateOnShow = false
            };
            m_listBox.SelectedIndexChanged += HandleSelectedIndexChanged;
            m_listBox.SameItemSelected     += HandleSameItemSelected;
            m_listBox.StyleSheet            = FontHeightAdjuster.StyleSheetFromMediator(mediator);
            m_listBox.WritingSystemFactory  = cache.WritingSystemFactory;
            m_searcher      = new StringSearcher <ICmPossibility>(SearchType.Prefix, cache.ServiceLocator.WritingSystemManager);
            m_possibilities = new List <ICmPossibility>();
            var stack = new Stack <ICmPossibility>(list.PossibilitiesOS);

            while (stack.Count > 0)
            {
                ICmPossibility poss = stack.Pop();
                m_possibilities.Add(poss);
                foreach (ICmPossibility child in poss.SubPossibilitiesOS)
                {
                    stack.Push(child);
                }
            }

            m_control.KeyDown  += HandleKeyDown;
            m_control.KeyPress += HandleKeyPress;
        }
        public static IYamlDocument FindDocumentByAnchor([CanBeNull] this IYamlFile file, [CanBeNull] string anchor)
        {
            if (file == null || anchor == null)
            {
                return(null);
            }

            var searcher = new StringSearcher("&" + anchor, true);

            foreach (var document in file.DocumentsEnumerable)
            {
                // Don't open chameleons unless we have to
                // TODO: GetTextAsBuffer is not cheap - it will allocate a StringBuilder + string
                // But then, FindDocumentByAnchor is hopelessly naive
                if (searcher.Find(document.GetTextAsBuffer()) >= 0)
                {
                    // Note that this opens the Body chameleon
                    var properties = GetDocumentBlockNodeProperties(document.Body.BlockNode);
                    if (properties?.AnchorProperty?.Text?.CompareBufferText(anchor) == true)
                    {
                        return(document);
                    }
                }
            }

            return(null);
        }
예제 #4
0
		public PossibilityAutoComplete(FdoCache cache, Mediator mediator, ICmPossibilityList list, Control control,
			string displayNameProperty, string displayWs)
		{
			m_cache = cache;
			m_mediator = mediator;
			m_control = control;
			m_displayNameProperty = displayNameProperty;
			m_displayWs = displayWs;

			m_listBox = new ComboListBox {DropDownStyle = ComboBoxStyle.DropDownList, ActivateOnShow = false};
			m_listBox.SelectedIndexChanged += HandleSelectedIndexChanged;
			m_listBox.SameItemSelected += HandleSameItemSelected;
			m_listBox.StyleSheet = FontHeightAdjuster.StyleSheetFromMediator(mediator);
			m_listBox.WritingSystemFactory = cache.WritingSystemFactory;
			m_searcher = new StringSearcher<ICmPossibility>(SearchType.Prefix, cache.ServiceLocator.WritingSystemManager);
			m_possibilities = new List<ICmPossibility>();
			var stack = new Stack<ICmPossibility>(list.PossibilitiesOS);
			while (stack.Count > 0)
			{
				ICmPossibility poss = stack.Pop();
				m_possibilities.Add(poss);
				foreach (ICmPossibility child in poss.SubPossibilitiesOS)
					stack.Push(child);
			}

			m_control.KeyDown += HandleKeyDown;
			m_control.KeyPress += HandleKeyPress;
		}
예제 #5
0
        public static string Solve(int[] a, int[] b)
        {
            int n = a.Length;

            a = a.OrderBy(v => v).ToArray();
            b = b.OrderBy(v => v).ToArray();

            var sbA = new StringBuilder();
            var sbB = new StringBuilder();

            for (int i = 0; i < n - 1; i++)
            {
                sbA.Append(a[i + 1] - a[i]);
                sbB.Append(b[i + 1] - b[i]);
            }

            sbA.Append(360000 - a[n - 1] + a[0]);
            sbB.Append(360000 - b[n - 1] + b[0]);
            sbA.Append(sbA);

            a = null;
            b = null;

            var searcher = new StringSearcher(sbB.ToString().ToCharArray());
            return (searcher.Search(sbA.ToString().ToCharArray()) == -1 ? "impossible" : "possible");
        }
 public ProjectTextSearcher(StringSearcher searcher, List <IOccurence> items, FindTextSearchFlags searchFlags, DocumentManager documentManager, ISolution solution)
 {
     mySearcher        = searcher;
     mySearchFlags     = searchFlags;
     myItems           = items;
     myDocumentManager = documentManager;
     mySolution        = solution;
 }
예제 #7
0
        public void FindAppleSourCream()
        {
            string[] dataSource = { "dog donkey apple monkey sour", "this planet sour goat", "here is the sour cream" };
            string[] query      = { "apple", "sour cream" };

            bool finder = StringSearcher.StringArrayAndSearch(dataSource, query);

            Assert.IsTrue(finder);
        }
예제 #8
0
        private string ProcessInternal(string text, Nattrib attrib)
        {
            if (text == null)
            {
                throw new ArgumentNullException("text");
            }
            int openTagIndex;
            int closeTagIndex;
            int startIndex   = 0;
            var b            = new StringBuilder();
            var textSearcher = new StringSearcher(text, "<![CDATA[", "]]>");

            // 1. expand tag
            while (textSearcher.FindTextSpan(startIndex, "[[", "]]", out openTagIndex, out closeTagIndex))
            {
                b.Append(text.Substring(startIndex, openTagIndex - startIndex));
                startIndex = openTagIndex + 2;
                //
                string   tagKey;
                string[] args;
                //
                int openArgIndex;
                int closeArgIndex;
                if (((openArgIndex = textSearcher.IndexOf("{", startIndex, closeTagIndex - startIndex - 1)) > -1) && ((closeArgIndex = textSearcher.IndexOf("}", openArgIndex, closeTagIndex - openArgIndex - 1)) > -1))
                {
                    // has arguments
                    tagKey = text.Substring(startIndex, openArgIndex - startIndex).Trim();
                    string arg  = text.Substring(openArgIndex + 1, closeArgIndex - openArgIndex - 1);
                    string arg2 = text.Substring(closeArgIndex + 1, closeTagIndex - closeArgIndex - 2);
                    args = new[] { arg, arg2 };
                }
                else
                {
                    // tag only - no arguments
                    tagKey = text.Substring(startIndex, closeTagIndex - startIndex - 1).Trim();
                    args   = null;
                }
                //
                TextProcessBase tag;
                if ((tagKey.Length > 0) && ((tag = TextProcessBase.Get(tagKey)) != null))
                {
                    b.Append(tag.Process(args));
                }
                else
                {
                    b.Append(text.Substring(openTagIndex, closeTagIndex - openTagIndex + 2));
                }
                startIndex = closeTagIndex + 1;
            }
            b.Append(text.Substring(startIndex));
            return(b.ToString());
        }
예제 #9
0
		/// <summary>
		/// Initializes a new instance of the <see cref="SearchEngine"/> class.
		/// </summary>
		protected SearchEngine(FdoCache cache, SearchType type)
		{
			m_cache = cache;
			m_searcher = new StringSearcher<int>(type, m_cache.ServiceLocator.WritingSystemManager);
			m_thread = new ConsumerThread<int, SearchField[]>(HandleWork) { IsBackground = true };
			m_synchronizationContext = SynchronizationContext.Current;
			m_syncRoot = new object();
			m_indexObjPos = new Dictionary<Tuple<int, int>, int>();

			m_cache.DomainDataByFlid.AddNotification(this);

			m_thread.Start();
		}
예제 #10
0
        /// <summary>
        /// Initializes a new instance of the <see cref="SearchEngine"/> class.
        /// </summary>
        protected SearchEngine(FdoCache cache, SearchType type)
        {
            m_cache    = cache;
            m_searcher = new StringSearcher <int>(type, m_cache.ServiceLocator.WritingSystemManager);
            m_thread   = new ConsumerThread <int, SearchField[]>(HandleWork);
            m_synchronizationContext = SynchronizationContext.Current;
            m_syncRoot    = new object();
            m_indexObjPos = new Dictionary <Tuple <int, int>, int>();

            m_cache.DomainDataByFlid.AddNotification(this);

            m_thread.Start();
        }
        public bool IsRotatedString(string s1, string s2)
        {
            int length = s1.Length;

            if (length == s2.Length && length > 0)
            {
                StringSearcher searcher = new StringSearcher();
                string         s1s1     = s1 + s1;
                return(searcher.CountSubstringInstances(s2, s1s1) > 0);
            }

            return(false);
        }
        public void KMP_Search_String()
        {
            string stringW = "put";
            string stringS = "computer";

            char[] W = stringW.ToCharArray();
            char[] S = stringS.ToCharArray();

            StringSearcher ss = new StringSearcher(W);
            int            ix = ss.Search(S);

            Console.WriteLine("Location of W in S is " + ix);
        }
예제 #13
0
		public void PrefixSearchTest()
		{
			var searcher = new StringSearcher<int>(SearchType.Prefix, m_wsManager);
			searcher.Add(0, 0, m_tsf.MakeString("test", m_enWs));
			searcher.Add(1, 0, m_tsf.MakeString("Hello",  m_enWs));
			searcher.Add(2, 0, m_tsf.MakeString("c'est une phrase", m_frWs));
			searcher.Add(3, 0, m_tsf.MakeString("hello", m_enWs));
			searcher.Add(4, 0, m_tsf.MakeString("zebra", m_enWs));

			CheckSearch(searcher, m_tsf.MakeString("test", m_enWs), new[] {0});
			CheckSearch(searcher, m_tsf.MakeString("hel", m_enWs), new[] {1, 3});
			CheckSearch(searcher, m_tsf.MakeString("zebra", m_enWs), new[] { 4 });
			CheckSearch(searcher, m_tsf.MakeString("c'est", m_frWs), new[] {2});
			CheckNoResultsSearch(searcher, m_tsf.MakeString("zebras", m_enWs));
		}
예제 #14
0
        /// <summary>
        /// Initialize the control, creating the BrowseViewer among other things.
        /// </summary>
        /// <param name="cache">The cache.</param>
        /// <param name="stylesheet">The stylesheet.</param>
        /// <param name="mediator">The mediator.</param>
        /// <param name="configNode">The config node.</param>
        /// <param name="objs">The searchable objects.</param>
        /// <param name="type">The match type.</param>
        /// <param name="stringSelector">A function which generates, for an object we could match, a collection of SearchFields
        /// which indicate the string value and field that could be matched. It should NOT generate SearchFields with null
        /// or empty strings. (An earlier version of this class discarded them, but it is much more efficient never to make them.)</param>
        /// <param name="reversalWs">The reversal writing system.</param>
        public void Initialize(FdoCache cache, IVwStylesheet stylesheet, Mediator mediator, XmlNode configNode,
                               IEnumerable <ICmObject> objs, SearchType type, Func <ICmObject, IEnumerable <SearchField> > stringSelector,
                               IWritingSystem reversalWs)
        {
            CheckDisposed();

            m_cache          = cache;
            m_stylesheet     = stylesheet;
            m_mediator       = mediator;
            m_searchableObjs = objs.ToList();
            m_stringSelector = stringSelector;
            m_searcher       = new StringSearcher <ICmObject>(type, m_cache.ServiceLocator.WritingSystemManager);

            SuspendLayout();
            CreateBrowseViewer(configNode, reversalWs);
            ResumeLayout(false);
        }
        public bool IsRotatedString(string s1, string s2)
        {
            if (s1.Length != s2.Length)
            {
                return(false);
            }

            int index = 0;

            for (int i = 0; i < s2.Length; i++)
            {
                if (i == 0)
                {
                    for (int j = 0; j < s1.Length; j++)
                    {
                        if (s1[j] == s2[i])
                        {
                            index = j;
                            break;
                        }
                    }
                    return(false);
                }

                if (s1[index] != s2[i])
                {
                    if (s1[0] == s2[i])
                    {
                        StringSearcher searcher = new StringSearcher();
                        string         sub      = BuildTailingSubstring(s2, i);
                        return(searcher.CountSubstringInstances(s2, sub) > 0);
                    }
                    return(false);
                }

                index++;

                if (index > s1.Length)
                {
                    return(false);
                }
            }

            return(false);
        }
예제 #16
0
        private void btnSearch_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                GenericSearch.MainWindow dialog = new GenericSearch.MainWindow();
                if (dialog.ShowDialog() == true)
                {
                    recipeListBox.SelectedItem = null;
                    searchTerms = dialog.SearchTerms;
                    ClearFields();
                    //Take a list of recipes, and for each create an array of string from its fields (and ingredients), then search it using the searchTerms,
                    //if the result is true than add it to a List and set the recipes listbox datacontext to the new list.
                    List <Recipe> foundRecipes = new List <Recipe>();
                    foreach (Recipe r in context.Recipes)
                    {
                        string[] recipeFields = context.RecipeFields(r);
                        if (StringSearcher.StringArrayAndSearch(recipeFields, searchTerms))
                        {
                            foundRecipes.Add(r);
                        }
                    }

                    //If no recipes were found then inform user in the error lable.
                    if (foundRecipes.Count > 0)
                    {
                        recipeListBox.SelectedItem = null;
                        foundRecipes.Sort();
                        recipeListBox.DataContext = foundRecipes;
                    }
                    else
                    {
                        recipeListBox.DataContext = foundRecipes;
                        errorLabel.Content        = "No recipes were found matching your requirements.";
                    }
                }
            }
            catch (Exception ex)
            {
                var baseexception = ex.GetBaseException();
                errorLabel.Content = baseexception.Message;
            }
        }
    public override ICollection<IOccurence> Search(IProgressIndicator progressIndicator)
    {
      // Create and configure utility class, which will perform search
      var searcher = new StringSearcher(mySearchString, myCaseSensitive);

      // Fetch all projects for solution, start progress 
      ICollection<IProject> projects = Solution.GetAllProjects();
      progressIndicator.Start(projects.Count);
      var items = new List<IOccurence>();

      // visit each project and collect occurences
      var visitor = new ProjectTextSearcher(searcher, items, mySearchFlags, myDocumentManager, mySolution);
      foreach (IProject project in projects)
      {
        progressIndicator.CurrentItemText = string.Format("Scanning project '{0}'", project.Name);
        project.Accept(visitor);
        progressIndicator.Advance(1);
      }

      return items;
    }
예제 #18
0
        public void Find_Bug_in_KMP()
        {
            int mine = 0, theirs = 0, count = 0;
            string a = null, b = null;
            Random rand = new Random();
            while (mine == theirs && count < 10000)
            {
                a = rand.Next(1000000000, Int32.MaxValue).ToString();
                b = rand.Next(1000, 9999).ToString();

                var stringSearcher = new StringSearcher(b.ToCharArray());
                theirs = stringSearcher.Search(a.ToCharArray());
                mine = StringSearcher.Kmp(a, b);
                count++;
            }

            if (count != 10000)
            {
                Console.WriteLine(a);
                Console.WriteLine(b);
            }
        }
        public override ICollection <IOccurence> Search(IProgressIndicator progressIndicator)
        {
            // Create and configure utility class, which will perform search
            var searcher = new StringSearcher(mySearchString, myCaseSensitive);

            // Fetch all projects for solution, start progress
            ICollection <IProject> projects = Solution.GetAllProjects();

            progressIndicator.Start(projects.Count);
            var items = new List <IOccurence>();

            // visit each project and collect occurences
            var visitor = new ProjectTextSearcher(searcher, items, mySearchFlags, myDocumentManager, mySolution);

            foreach (IProject project in projects)
            {
                progressIndicator.CurrentItemText = string.Format("Scanning project '{0}'", project.Name);
                project.Accept(visitor);
                progressIndicator.Advance(1);
            }

            return(items);
        }
예제 #20
0
        public static void Test()
        {
            var testcase = StringSearchTestCase.New(50, 10, 100000);
            Stopwatch stopWatch = new Stopwatch();

            //searcher
            StringSearcher searcher = new StringSearcher();
            stopWatch.Start();
            testcase.TestDictionary.WithEach(x =>
            {
                searcher.Add(x, x);
            });
            stopWatch.Stop();
            Debug.WriteLine("searcher init elapsed ms {0}", stopWatch.ElapsedMilliseconds);

            stopWatch.Reset();
            stopWatch.Start();
            var searchermatches = searcher.FindMatches(testcase.TestSearchText);
            stopWatch.Stop();
            Debug.WriteLine("searcher elapsed ms {0}", stopWatch.ElapsedMilliseconds);
            Debug.WriteLine(
                string.Format("expected percent {0}.  found {1}", testcase.ExpectedPercentMatch, searchermatches.Count())
                );

            stopWatch.Reset();
            stopWatch.Start();
            //trie
            Trie trie = new Trie();
            testcase.TestDictionary.WithEach(x =>
            {
                trie.Add(x, x);
            });
            stopWatch.Stop();
            Debug.WriteLine("trie init elapsed ms {0}", stopWatch.ElapsedMilliseconds);

            stopWatch.Reset();
            stopWatch.Start();
            var matches = trie.FindMatches(testcase.TestSearchText);
            stopWatch.Stop();
            Debug.WriteLine("forwardonly elapsed ms {0}", stopWatch.ElapsedMilliseconds);
            Debug.WriteLine(
                string.Format("expected percent {0}.  found {1}", testcase.ExpectedPercentMatch, matches.Count())
                );

            stopWatch.Reset();
            stopWatch.Start();
            var matches1b = TrieLogic.FindMatchesUsingForwardOnlyCursor2(trie, testcase.TestSearchText);
            stopWatch.Stop();
            Debug.WriteLine("forwardonly2 elapsed ms {0}", stopWatch.ElapsedMilliseconds);
            Debug.WriteLine(
                string.Format("expected percent {0}.  found {1}", testcase.ExpectedPercentMatch, matches1b.Count())
                );

            stopWatch.Reset();
            stopWatch.Start();
            var matches2 = trie.HasPositionalSearch().FindMatches(testcase.TestSearchText);
            stopWatch.Stop();
            Debug.WriteLine("seekahead elapsed ms {0}", stopWatch.ElapsedMilliseconds);
            Debug.WriteLine(
                string.Format("expected percent {0}.  found {1}", testcase.ExpectedPercentMatch, matches2.Count())
                );

            stopWatch.Reset();
            stopWatch.Start();
            var matches3 = trie.HasPositionalSearch().NonOverlapping().FindMatches(testcase.TestSearchText);
            stopWatch.Stop();
            Debug.WriteLine("seekaheadnonoverlapped elapsed ms {0}", stopWatch.ElapsedMilliseconds);
            Debug.WriteLine(
                string.Format("expected percent {0}.  found {1}", testcase.ExpectedPercentMatch, matches3.Count())
                );

            stopWatch.Reset();
            stopWatch.Start();
            var matches4 = trie.HasPositionalSearch().Paralleling().FindMatches(testcase.TestSearchText);
            stopWatch.Stop();
            Debug.WriteLine("seekaheadparallel elapsed ms {0}", stopWatch.ElapsedMilliseconds);
            Debug.WriteLine(
                string.Format("expected percent {0}.  found {1}", testcase.ExpectedPercentMatch, matches4.Count())
                );

            //stopWatch.Reset();
            //stopWatch.Start();
            //InlineTrie inline_trie = new InlineTrie();
            //stopWatch.Start();
            //testcase.TestDictionary.WithEach(x =>
            //{
            //    inline_trie.Add(x, x);
            //});
            //stopWatch.Stop();
            //Debug.WriteLine("inline init elapsed ms {0}", stopWatch.ElapsedMilliseconds);
            //stopWatch.Reset();
            //stopWatch.Start();
            //var inline_matches = inline_trie.FindMatches(testcase.TestSearchText);
            //stopWatch.Stop();
            //Debug.WriteLine("inline elapsed ms {0}", stopWatch.ElapsedMilliseconds);
            //Debug.WriteLine(
            //    string.Format("expected percent {0}.  found {1}", testcase.ExpectedPercentMatch, inline_matches.Count)
            //    );

            ////trie
            //ITrie<string> gma_trie =  new PatriciaTrie<string>();
            //stopWatch.Start();
            //testcase.TestDictionary.WithEach(x =>
            //{
            //    gma_trie.Add(x, x);
            //});
            //stopWatch.Stop();
            //Debug.WriteLine("init elapsed ms {0}", stopWatch.ElapsedMilliseconds);

            //stopWatch.Reset();
            //stopWatch.Start();
            //var gma_matches = gma_trie.Retrieve(testcase.TestSearchText);
            //stopWatch.Stop();
            //Debug.WriteLine("elapsed ms {0}", stopWatch.ElapsedMilliseconds);
            //Debug.WriteLine(
            //    string.Format("expected percent {0}.  found {1}", testcase.ExpectedPercentMatch, gma_matches.Count())
            //    );
            //eeeksoft 
            stopWatch.Reset();
            stopWatch.Start();
            var eeeksoft_searcher = new Decoratid.Idioms.StringSearch.EeekSoft.StringSearch(testcase.TestDictionary.ToArray());
            stopWatch.Stop();
            Debug.WriteLine("eeeksoft init elapsed ms {0}", stopWatch.ElapsedMilliseconds);

            stopWatch.Reset();
            stopWatch.Start();
            var eeeksoft_matches = eeeksoft_searcher.FindAll(testcase.TestSearchText);
            stopWatch.Stop();
            Debug.WriteLine("eeeksoft elapsed ms {0}", stopWatch.ElapsedMilliseconds);
            Debug.WriteLine(
                string.Format("expected percent {0}.  found {1}", testcase.ExpectedPercentMatch, eeeksoft_matches.Length)
                );

            //pduniho
            //stopWatch.Reset();
            //stopWatch.Start();
            //var pduniho_graph = new Decoratid.Idioms.StringSearch.PDuniho.StateGraph<char, int>();
            //for (int istr = 0; istr < testcase.TestDictionary.Count; istr++)
            //{
            //    pduniho_graph.Add(testcase.TestDictionary[istr], istr);
            //}
            //stopWatch.Stop();
            //Debug.WriteLine("init elapsed ms {0}", stopWatch.ElapsedMilliseconds);

            //stopWatch.Reset();
            //stopWatch.Start();
            //var pduniho_matches = pduniho_graph.RgobjFromCollectionParallel(testcase.TestSearchText);
            //stopWatch.Stop();
            //Debug.WriteLine("elapsed ms {0}", stopWatch.ElapsedMilliseconds);
            //Debug.WriteLine(
            //    string.Format("expected percent {0}.  found {1}", testcase.ExpectedPercentMatch, pduniho_matches.Length)
            //    );

            //pnikiforovs
            stopWatch.Reset();
            stopWatch.Start();
            var pnikiforovs_trie = new Decoratid.Idioms.StringSearch.PNikiforovs.Trie();
            testcase.TestDictionary.WithEach(item =>
            {
                pnikiforovs_trie.Add(item);
            });
            pnikiforovs_trie.Build();
            stopWatch.Stop();
            Debug.WriteLine("pnikiforovs init elapsed ms {0}", stopWatch.ElapsedMilliseconds);

            stopWatch.Reset();
            stopWatch.Start();
            string[] pnikiforovs_matches = pnikiforovs_trie.Find(testcase.TestSearchText).ToArray();
            stopWatch.Stop();
            Debug.WriteLine("pnikiforovs elapsed ms {0}", stopWatch.ElapsedMilliseconds);
            Debug.WriteLine(
                string.Format("expected percent {0}.  found {1}", testcase.ExpectedPercentMatch, pnikiforovs_matches.Length)
                );
        }
 public ProjectTextSearcher(StringSearcher searcher, List<IOccurence> items, FindTextSearchFlags searchFlags, DocumentManager documentManager, ISolution solution)
 {
   mySearcher = searcher;
   mySearchFlags = searchFlags;
   myItems = items;
   myDocumentManager = documentManager;
   mySolution = solution;
 }
예제 #22
0
        public static IHierarchyReference GetReferenceBySearcher(IPsiSourceFile assetSourceFile, IBuffer assetDocumentBuffer, StringSearcher searcher)
        {
            var start = searcher.Find(assetDocumentBuffer, 0, assetDocumentBuffer.Length);

            if (start < 0)
            {
                return(null);
            }
            var end = ourBracketSearcher.Find(assetDocumentBuffer, start, assetDocumentBuffer.Length);

            if (end < 0)
            {
                return(null);
            }

            var buffer   = ProjectedBuffer.Create(assetDocumentBuffer, new TextRange(start, end + 1));
            var lexer    = new YamlLexer(buffer, false, false);
            var parser   = new YamlParser(lexer.ToCachingLexer());
            var document = parser.ParseDocument();

            return((document.Body.BlockNode as IBlockMappingNode)?.Entries.FirstOrDefault()?.Content.Value.ToHierarchyReference(assetSourceFile));
        }
예제 #23
0
		public void FullTextSearchTest()
		{
			var searcher = new StringSearcher<int>(SearchType.FullText, m_wsManager);
			searcher.Add(0, 0, m_tsf.MakeString("test", m_enWs));
			searcher.Add(1, 0, m_tsf.MakeString("c'est une phrase", m_frWs));
			ITsIncStrBldr tisb = m_tsf.GetIncBldr();
			tisb.SetIntPropValues((int)FwTextPropType.ktptWs, (int)FwTextPropVar.ktpvDefault, m_frWs);
			tisb.Append("C'est une sentence. ");
			tisb.SetIntPropValues((int)FwTextPropType.ktptWs, (int)FwTextPropVar.ktpvDefault, m_enWs);
			tisb.Append("We use it for testing purposes.");
			searcher.Add(2, 0, tisb.GetString());
			searcher.Add(3, 0, m_tsf.MakeString("Hello, how are you doing? I am doing fine. That is good to know.", m_enWs));

			CheckSearch(searcher, m_tsf.MakeString("test", m_enWs), new[] {0, 2});
			CheckSearch(searcher, m_tsf.MakeString("c'est une", m_frWs), new[] {1, 2});
			CheckSearch(searcher, m_tsf.MakeString("t", m_enWs), new[] {0, 2, 3});
			CheckSearch(searcher, m_tsf.MakeString("testing purpose", m_enWs), new[] {2});
		}
예제 #24
0
        public static void Main()
        {
            //string word = "xx";
            //string text = "xxx";

            var word = Console.ReadLine();
            var text = Console.ReadLine();

            char[] S = text.ToCharArray();

            var        prefix = "";
            BigInteger result = 0;

            for (int i = 0; i < word.Length; i++)
            {
                prefix += word[i];

                var suffix = "";

                for (int j = i; j < word.Length - 1; j++)
                {
                    suffix += word[j + 1];
                }

                char[] prefixCharArr = prefix.ToCharArray();
                char[] suffixCharArr = suffix.ToCharArray();


                StringSearcher prefixSearcher = new StringSearcher(prefixCharArr);

                int        prefixIndex = 0;
                BigInteger prefixCount = 0;
                do
                {
                    prefixIndex = prefixSearcher.Search(S, prefixIndex);

                    if (prefixIndex != -1)
                    {
                        prefixCount++;
                        //prefixIndex += prefix.Length;
                        prefixIndex++;
                    }
                } while (prefixIndex != -1);

                int        suffixIndex = 0;
                BigInteger suffixCount = 0;
                if (suffix != "")
                {
                    StringSearcher suffixSearcher = new StringSearcher(suffixCharArr);
                    do
                    {
                        suffixIndex = suffixSearcher.Search(S, suffixIndex);

                        if (suffixIndex != -1)
                        {
                            suffixCount++;
                            //suffixIndex += suffix.Length;
                            suffixIndex++;
                        }
                    } while (suffixIndex != -1);
                }
                else
                {
                    suffixCount = 1;
                }


                result += prefixCount * suffixCount;
            }

            Console.WriteLine(result);
        }
예제 #25
0
		private static void CheckNoResultsSearch(StringSearcher<int> searcher, ITsString tss)
		{
			Assert.AreEqual(0, searcher.Search(0, tss).Count());
		}
예제 #26
0
		private static void CheckSearch(StringSearcher<int> searcher, ITsString tss, int[] expectedResults)
		{
			Assert.AreEqual(expectedResults.Length, searcher.Search(0, tss).Intersect(expectedResults).Count());
		}