public void TestShiftingIndex(int index, TextIndex.IndexState state, int shifting, int actualIndex, TextIndex.IndexState actualState) { var textIndex = new TextIndex(index, state); var actualTextIndex = new TextIndex(actualIndex, actualState); Assert.AreEqual(TextIndexUtils.ShiftingIndex(textIndex, shifting), actualTextIndex); }
}//登录 public object GetIndex(int?page) { var models = new List <TextIndex>(); List <BlogModel.BlogText> TextList = repository.GetTextsAll(); foreach (var item in TextList) { var temp = new TextIndex { TextID = item.TextID, CommitCount = repository.GetCommitsByTextID(item.TextID).Count(), Text = item.Text, FirstView = item.FirstView }; if (item.CategoryName == null) { item.CategoryName = "未分类"; } temp.CategoryName = item.CategoryName; temp.TextTitle = item.TextTitle; temp.TextChangeDate = item.TextChangeDate; temp.Hot = item.Hot; models.Add(temp); } models.Reverse(); int pageSize = 10;//每页显示的文章数 int pageNumber = (page ?? 1); return(models.ToPagedList(pageNumber, pageSize)); }//首页,page实现分页
public void ClearID(int ID, bool unindex, bool setBackCursor) { TextIndex index = GetIndex(ID); OverwriteOrAppend(index._index, new string(' ', index._length)); if (unindex) { indices.Remove(index); } int rememberConsoleLeft = System.Console.CursorLeft; int rememberConsoleTop = System.Console.CursorTop; Coords seekedCoords = TextIndexToConsoleCoords(index._index); System.Console.SetCursorPosition(seekedCoords.x, seekedCoords.y); System.Console.Write(new string(' ', index._length)); if (setBackCursor) { System.Console.SetCursorPosition(rememberConsoleLeft, rememberConsoleTop); } else { System.Console.SetCursorPosition(seekedCoords.x, seekedCoords.y); } }
public List <TextIndex> SearchBlogBycate(string categroyname) { var blog = repository.GetTextsAll(); var search_list = new List <TextIndex>(); if (!string.IsNullOrEmpty(categroyname)) { var c_blogs = blog.Where(m => m.CategoryName.Equals(categroyname)).ToList(); foreach (var item in c_blogs) { if (item.CategoryName == null) { item.CategoryName = "未分类"; } var temp = new TextIndex { TextID = item.TextID, CommitCount = repository.GetCommitsByTextID(item.TextID).Count(), Text = item.Text, TextTitle = item.TextTitle, CategoryName = item.CategoryName, TextChangeDate = item.TextChangeDate, FirstView = item.FirstView, Hot = item.Hot }; search_list.Add(temp); } } return(search_list); }
protected virtual TextIndex GetNextIndex(TextIndex currentIndex) { var nextIndex = TextIndexUtils.ToStringIndex(currentIndex); var nextState = TextIndexUtils.ReverseState(currentIndex.State); return(new TextIndex(nextIndex, nextState)); }
public bool AddTimeTagByPosition(Lyric lyric, TextIndex index) { if (!beatmap.HitObjects.Contains(lyric)) { return(false); } var timeTags = lyric.TimeTags.ToList(); var targetTimeTag = timeTags.FirstOrDefault(x => x.Index >= index) ?? timeTags.LastOrDefault(); if (targetTimeTag == null) { return(false); } changeHandler?.BeginChange(); var insertIndex = timeTags.IndexOf(targetTimeTag); timeTags.Insert(insertIndex, new TimeTag(index)); lyric.TimeTags = timeTags.ToArray(); changeHandler?.EndChange(); return(false); }
public ActionResult MIndex(int?page) //移动端主页 { var currentLoginUser = Session["loginuser"] == null ? null : (User)Session["loginuser"]; ViewBag.currentLoginInfo = currentLoginUser; var models = new List <TextIndex>(); var TextList = new List <TextList>(); TextList = db.TextLists.ToList(); foreach (var item in TextList) { var temp = new TextIndex { TextID = item.TextID, CommitCount = db.CommitLists.Count(c => c.TextID == item.TextID), Text = item.Text, FirstView = item.FirstView }; if (item.CategoryName == null) { item.CategoryName = "未分类"; } temp.CategoryName = item.CategoryName; temp.TextTitle = item.TextTitle; temp.TextChangeDate = item.TextChangeDate; temp.Hot = item.Hot; models.Add(temp); } models.Reverse(); int pageSize = 4; //每页显示的文章数 int pageNumber = (page ?? 1); return(View(models.ToPagedList(pageNumber, pageSize))); }
public List <TextIndex> SearchBlog(string searchthing)//搜索博文 { var blog = repository.GetTextsAll(); var search_list = new List <TextIndex>(); if (!string.IsNullOrEmpty(searchthing)) { var s_blogs = blog.Where(m => m.TextTitle.Contains(searchthing) || m.Text.Contains(searchthing)).ToList(); foreach (var item in s_blogs) { var temp = new TextIndex(); temp.TextID = item.TextID; temp.CommitCount = repository.GetCommitsByTextID(item.TextID).Count(); temp.Text = item.Text; if (item.CategoryName == null) { item.CategoryName = "未分类"; } temp.CategoryName = item.CategoryName; temp.FirstView = item.FirstView; temp.TextTitle = item.TextTitle.Replace(searchthing, "<font color='red'>" + searchthing + "</font>"); temp.TextChangeDate = item.TextChangeDate; temp.Hot = item.Hot; search_list.Add(temp); } } return(search_list); }
public void AddsItems() { var idx = new TextIndex("test", new RamMnemonic()); idx.Add("123"); Assert.True(idx.Has("123")); }
public ActionResult CategroyBlog(string categroyname) { var currentLoginUser = Session["loginuser"] == null ? null : (User)Session["loginuser"]; ViewBag.currentLoginInfo = currentLoginUser; var blog = from m in db.TextLists select m; //搜索 var search_list = new List <TextIndex>(); if (!string.IsNullOrEmpty(categroyname)) { var c_blogs = blog.Where(m => m.CategoryName.Equals(categroyname)).ToList(); foreach (var item in c_blogs) { var temp = new TextIndex(); temp.TextID = item.TextID; temp.CommitCount = db.CommitLists.Count(c => c.TextID == item.TextID); temp.Text = item.Text; temp.TextTitle = item.TextTitle; if (item.CategoryName == null) { item.CategoryName = "未分类"; } temp.CategoryName = item.CategoryName; temp.TextChangeDate = item.TextChangeDate; temp.FirstView = item.FirstView; temp.Hot = item.Hot; search_list.Add(temp); } ViewBag.searchRes = search_list; } return(View(search_list)); }
public ActionResult SearchResult(string searchthing) { var currentLoginUser = Session["loginuser"] == null ? null : (User)Session["loginuser"]; ViewBag.searching = searchthing; ViewBag.currentLoginInfo = currentLoginUser; var blog = from m in db.TextLists select m; //搜索 var search_list = new List <TextIndex>(); if (!string.IsNullOrEmpty(searchthing)) { var s_blogs = blog.Where(m => m.TextTitle.Contains(searchthing) || m.Text.Contains(searchthing)).ToList(); foreach (var item in s_blogs) { var temp = new TextIndex(); temp.TextID = item.TextID; temp.CommitCount = db.CommitLists.Count(c => c.TextID == item.TextID); temp.Text = item.Text; if (item.CategoryName == null) { item.CategoryName = "未分类"; } temp.CategoryName = item.CategoryName; temp.FirstView = item.FirstView; temp.TextTitle = item.TextTitle.Replace(searchthing, "<font color='red'>" + searchthing + "</font>"); temp.TextChangeDate = item.TextChangeDate; temp.Hot = item.Hot; search_list.Add(temp); } ViewBag.searchRes = search_list; } return(View(search_list)); }
/// <summary> /// Display string with position format /// </summary> /// <example> /// 3 /// 4(end) /// </example> /// <param name="textIndex"></param> /// <returns></returns> public static string PositionFormattedString(TextIndex textIndex) { var index = textIndex.Index; var state = textIndex.State == TextIndex.IndexState.End ? "(end)" : ""; return($"{index}{state}"); }
public void RemovesFromIndex() { var idx = new TextIndex("test", new RamMnemonic()); idx.Add("123"); idx.Remove("123"); Assert.False(idx.Has("123")); }
public TextIndex <T> CreateIndex(IEnumerable <Phrase <T> > phrases) { var index = new TextIndex <T>(); LoadPhrasesIntoTheIndex(phrases, index); return(index); }
public void RemovesXmls() { var mem = new RamMnemonic(); var idx = new TextIndex("test", mem); idx.Add("123").Xocument("xunit-test").Modify(new Directives().Xpath("/xunit-test").Add("content").Set("boo")); idx.Remove("123"); Assert.DoesNotContain($"test/123/xunit-test", mem.Contents().Knowledge()); }
public void RejectsUnknownSingleItem() { var mem = new RamMnemonic(); var idx = new TextIndex("test", mem); Assert.Throws <ArgumentException>(() => idx.Comb("123") ); }
public static int ToStringIndex(TextIndex index) { if (index.State == TextIndex.IndexState.Start) { return(index.Index); } return(index.Index + 1); }
public static bool OutOfRange(TextIndex index, string lyric) { if (string.IsNullOrEmpty(lyric)) { return(true); } return(index.Index < 0 || index.Index >= lyric.Length); }
public void RemovesCells() { var mem = new RamMnemonic(); var idx = new TextIndex("test", mem); idx.Add("123").Cell("xunit-test").Update(new InputOf("content")); idx.Remove("123"); Assert.DoesNotContain($"test/123/xunit-test", mem.Contents().Knowledge()); }
public override TextIndexList Ranges(string text) { TextIndexList ranges = new TextIndexList(); TextIndex t = new TextIndex(Start, Length); ranges.Add(t); return(ranges); }
/// <summary> /// Search for and process all object blocks in the file. /// </summary> /// <returns></returns> private IEnumerable <Block> ProcessBlocks() { // process found block strings foreach (Match match in RegexBlock.Matches(Text)) { yield return(new Block(this, TextIndex.Skip(match.Index).Take(match.Length).ToList(), Text.LineFromPosition(match.Index), match.Value)); } }
private void LoadPhrasesIntoTheIndex(IEnumerable <Phrase <T> > phrases, TextIndex <T> index) { var row = 0; foreach (var phrase in phrases) { AddPhrase(index, phrase); row++; FireRowInsertedEvent(row); } }
public override TimeTagIndexCaretPosition MoveToFirst() { var lyric = Lyrics.FirstOrDefault(l => !string.IsNullOrEmpty(l.Text)); if (lyric == null) { return(null); } var index = new TextIndex(); return(new TimeTagIndexCaretPosition(lyric, index)); }
public override TimeTagIndexCaretPosition MoveToLast() { var lyric = Lyrics.LastOrDefault(l => !string.IsNullOrEmpty(l.Text)); if (lyric == null) { return(null); } var textLength = lyric?.Text.Length ?? 0; var index = new TextIndex(textLength - 1, TextIndex.IndexState.End); return(new TimeTagIndexCaretPosition(lyric, index)); }
public List <WordReference <T> > SearchTheIndex(TextIndex <T> index, string frontString) { var binarySearcher = new BinarySearch <T>((str1, str2) => str2.StartsWith(str1) ? 0 : str1.CompareTo(str2)); var words = binarySearcher.Search(index, frontString); var results = new List <WordReference <T> >(); foreach (var word in words) { results.AddRange(index[word]); } return(results); }
[TestCase(0, TextIndex.IndexState.Start, 3, 1, null)] // test switch value. public void TestClamp(int index, TextIndex.IndexState state, int minIndex, int maxIndex, int?actualIndex) { var textIndex = new TextIndex(index, state); if (actualIndex != null) { var actualTextIndex = new TextIndex(actualIndex.Value, state); Assert.AreEqual(TextIndexUtils.Clamp(textIndex, minIndex, maxIndex), actualTextIndex); } else { Assert.Throws <ArgumentException>(() => TextIndexUtils.Clamp(textIndex, minIndex, maxIndex)); } }
public void CachesItems() { var mem = new RamMnemonic(); var idx = new TextIndex("test", mem); idx.Add("123"); new MemorizedXocument( $"test/hq/catalog.xml", mem ).Modify( new Directives().Xpath("/catalog/*").Remove() ); Assert.True(idx.Has("123")); }
public void IsThreadSafe() { var idx = new TextIndex("test", new RamMnemonic()); Parallel.For(0, 100, i => { idx.Add(i.ToString()); idx.List().ToArray(); }); Assert.Equal( 100, idx.List().Count ); }
// 1) Load Table // 2) Add items to index // 3) Save Index public void CreateIndex(string Name, string Directory, IDataReader reader, CultureInfo culture, string keyField, string textField) { int row = 0; TextIndex index = new TextIndex(Name, culture); index.IndexFolder = Directory; index.Initialize(); while (reader.Read()) { int key = (int)reader[keyField]; string text = (string)reader[textField]; index.AddPhrase(key, text); row++; if (OnRowInserted != null) OnRowInserted(row); } index.SaveIndex(); }
private List <WordReference <T> > GetTheSearchResultsForThisWord(TextIndex <T> textIndex, Synonym word) { var resultsForThisWord = textIndexSearcher.SearchTheIndex(textIndex, word.OriginalWord); foreach (var suggestedWord in word.SuggestedWords) { if (suggestedWord == word.OriginalWord) { continue; } var subResults = GetTheSearchResultsForTheSynonyms(textIndex, suggestedWord); resultsForThisWord.AddRange(subResults); } return(resultsForThisWord); }
public static PreparedDecorationCollection Merge(PreparedDecorationCollection previous, PreparedDecorationCollection current, TextDelta td) { if (previous.mDecorations.Count == 0) { current.mDifferenceRange = current.Bounds(); return(current); } if (AreDecorationsSame(previous, current)) { PreparedDecorationCollection merged = new PreparedDecorationCollection(); TextIndexList differenceRanges = new TextIndexList(); for (int i = 0; i < previous.Count; i++) { TextIndexList previousIndex = previous.Index(i); TextIndexList currentIndex = current.Index(i); TextIndex differenceRange = currentIndex.RangeDifferentFrom(previousIndex); if (differenceRange != null && differenceRange.Length > 0) { differenceRanges.Add(differenceRange); } } differenceRanges.Add(td.TextIndex); merged.mDifferenceRange = differenceRanges.Bounds; TextIndex activeArea = differenceRanges.Bounds; if (activeArea != null) { for (int i = 0; i < previous.Count; i++) { TextIndexList currentIndex = current.Index(i); TextIndexList projected = currentIndex.Projection(activeArea); if (projected.IndexLengthUpperBound() > 0)// Are there and textindexes in projected that have a length > 0 { merged.Add(current.Decoration(i), projected); } } } return(merged); } else { current.mAreDecorationsChanged = true; return(current); } }
/// <remarks>This method assumes a reader lock has already been acquired before calling this method</remarks> private static TextIndex GetTextIndex(string catalog, CultureInfo culture) { string indexKey = catalog + culture.ToString(); if (Indexes.Keys.Contains(indexKey)) return Indexes[indexKey]; else { // Load the index! TextIndex index = new TextIndex(catalog, culture); index.IndexFolder = DatabasePath; index.Initialize(); index.LoadIndex(); LockCookie lc = readerLock.UpgradeToWriterLock(1000 * 60); // 60 seconds! Indexes.Add(indexKey, index); readerLock.DowngradeFromWriterLock(ref lc); return index; } }