/// <summary> /// 提取版本号 /// </summary> /// <param name="result">盘古分词的结果</param> /// <param name="vWordNode">V 这个字符的第一个出现位置</param> /// <param name="lastNode">版本号的最后一个词</param> /// <param name="versionBeginPosition">版本号第一个词的起始位置</param> private void Pickup(SuperLinkedList<WordInfo> result, SuperLinkedListNode<WordInfo> vWordNode, SuperLinkedListNode<WordInfo> lastNode, int versionBeginPosition) { SuperLinkedListNode<WordInfo> node = vWordNode.Next; int lastPosition = lastNode.Value.Position + lastNode.Value.Word.Length; SuperLinkedListNode<WordInfo> end = lastNode.Next; while (node != end) { result.Remove(node); node = vWordNode.Next; } if (vWordNode.Value.Word == "V") { vWordNode.Value.Word = "v"; } string version = _Text.Substring(versionBeginPosition, lastPosition - versionBeginPosition); int dotPosition = 0; int dotCount = 0; WordInfo verWord = null; dotPosition = version.IndexOf('.', dotPosition); while (dotPosition > 0) { verWord = null; if (dotCount > 0) //第一个点之前的版本号不提取 { //提取前n个子版本号 verWord = new WordInfo(version.Substring(0, dotPosition), POS.POS_D_K, 0); verWord.Rank = 1; //这里设置子版本号的权重 verWord.Position = versionBeginPosition; verWord.WordType = WordType.None; } dotCount++; dotPosition = version.IndexOf('.', dotPosition + 1); if (verWord != null) { result.AddAfter(vWordNode, verWord); } } //提取完整版本号 verWord = new WordInfo(version, POS.POS_D_K, 0); verWord.Rank = 5; //这里设置完整版本号的权重 verWord.Position = versionBeginPosition; verWord.WordType = WordType.None; result.AddAfter(vWordNode, verWord); }
public void EqualityOperator() { WordInfo info1 = new WordInfo("word", 0, 0, WordLocation.Content); WordInfo info2 = new WordInfo("word", 0, 0, WordLocation.Content); WordInfo info3 = new WordInfo("word", 10, 1, WordLocation.Content); WordInfo info4 = new WordInfo("word", 10, 1, WordLocation.Title); WordInfo info5 = new WordInfo("word2", 0, 0, WordLocation.Content); Assert.IsTrue(info1 == info2, "info1 should equal info2"); Assert.IsFalse(info1 == info3, "info1 should not equal info3"); Assert.IsFalse(info3 == info4, "info3 should not equal info4"); Assert.IsFalse(info1 == null, "info1 should not equal null"); Assert.IsFalse(info1 == info5, "info1 should not equal info5"); }
public void Clear() { WordInfoCollection collection = new WordInfoCollection(); WordInfo mi1 = new WordInfo("continuous", 0, 0, WordLocation.Content); WordInfo mi2 = new WordInfo("taskbar", 21, 1, WordLocation.Content); collection.Add(mi1); collection.Add(mi2); Assert.AreEqual(2, collection.Count, "Wrong count (collection should contain 2 items)"); collection.Clear(); Assert.AreEqual(0, collection.Count, "Wrong count (collection should be empty)"); }
public void CompareTo() { WordInfo info1 = new WordInfo("word", 0, 0, WordLocation.Content); WordInfo info2 = new WordInfo("word", 0, 0, WordLocation.Content); WordInfo info3 = new WordInfo("word", 10, 1, WordLocation.Content); WordInfo info4 = new WordInfo("word", 10, 1, WordLocation.Title); WordInfo info5 = new WordInfo("word2", 0, 0, WordLocation.Content); Assert.AreEqual(0, info1.CompareTo(info2), "info1 should equal info2"); Assert.AreEqual(-3, info1.CompareTo(info3), "info1 should be smaller than info3"); Assert.AreEqual(2, info3.CompareTo(info4), "info3 should be greater than info4"); Assert.AreEqual(1, info1.CompareTo(null), "info1 should be greater than null"); Assert.AreEqual(-1, info1.CompareTo(info5), "info1 should be smaller than info5"); }
public void Tokenize() { string input = "Hello, there!"; WordInfo[] expectedOutput = new WordInfo[] { new WordInfo("Hello", 0, 0, WordLocation.Content), new WordInfo("there", 7, 1, WordLocation.Content) }; WordInfo[] output = Tools.Tokenize(input, WordLocation.Content); Assert.AreEqual(expectedOutput.Length, output.Length, "Wrong output length"); for(int i = 0; i < output.Length; i++) { Assert.AreEqual(expectedOutput[i].Text, output[i].Text, "Wrong word text at index " + i.ToString()); Assert.AreEqual(expectedOutput[i].FirstCharIndex, output[i].FirstCharIndex, "Wrong first char index at " + i.ToString()); Assert.AreEqual(expectedOutput[i].WordIndex, output[i].WordIndex, "Wrong word index at " + i.ToString()); } }
public void Equals() { WordInfo info1 = new WordInfo("word", 0, 0, WordLocation.Content); WordInfo info2 = new WordInfo("word", 0, 0, WordLocation.Content); WordInfo info3 = new WordInfo("word", 10, 1, WordLocation.Content); WordInfo info4 = new WordInfo("word", 10, 1, WordLocation.Title); WordInfo info5 = new WordInfo("word2", 0, 0, WordLocation.Content); Assert.IsTrue(info1.Equals(info2), "info1 should equal info2"); Assert.IsFalse(info1.Equals(info3), "info1 should not equal info3"); Assert.IsFalse(info3.Equals(info4), "info3 should not equal info4"); Assert.IsTrue(info1.Equals(info1), "info1 should equal itself"); Assert.IsFalse(info1.Equals(null), "info1 should not equal null"); Assert.IsFalse(info1.Equals("hello"), "info1 should not equal a string"); Assert.IsFalse(info1.Equals(info5), "info1 should not equal info5"); }
public void RemoveStopWords() { WordInfo[] input = new WordInfo[] { new WordInfo("I", 0, 0, WordLocation.Content), new WordInfo("like", 7, 1, WordLocation.Content), new WordInfo("the", 15, 2, WordLocation.Content), new WordInfo("cookies", 22, 3, WordLocation.Content) }; WordInfo[] expectedOutput = new WordInfo[] { new WordInfo("I", 0, 0, WordLocation.Content), new WordInfo("like", 7, 1, WordLocation.Content), new WordInfo("cookies", 22, 3, WordLocation.Content) }; WordInfo[] output = Tools.RemoveStopWords(input, new string[] { "the", "in", "of" }); Assert.AreEqual(expectedOutput.Length, output.Length, "Wrong output length"); for(int i = 0; i < output.Length; i++) { Assert.AreEqual(expectedOutput[i].Text, output[i].Text, "Wrong word text at index " + i.ToString()); Assert.AreEqual(expectedOutput[i].FirstCharIndex, output[i].FirstCharIndex, "Wrong word position at index " + i.ToString()); } }
public void RemoveStopWords() { WordInfo[] input = new WordInfo[] { new WordInfo("I", 0, 0, WordLocation.Content), new WordInfo("like", 7, 1, WordLocation.Content), new WordInfo("the", 15, 2, WordLocation.Content), new WordInfo("cookies", 22, 3, WordLocation.Content) }; WordInfo[] expectedOutput = new WordInfo[] { new WordInfo("I", 0, 0, WordLocation.Content), new WordInfo("like", 7, 1, WordLocation.Content), new WordInfo("cookies", 22, 3, WordLocation.Content) }; WordInfo[] output = Tools.RemoveStopWords(input, new string[] { "the", "in", "of" }); Assert.AreEqual(expectedOutput.Length, output.Length, "Wrong output length"); for (int i = 0; i < output.Length; i++) { Assert.AreEqual(expectedOutput[i].Text, output[i].Text, "Wrong word text at index " + i); Assert.AreEqual(expectedOutput[i].FirstCharIndex, output[i].FirstCharIndex, "Wrong word position at index " + i); } }
public void Tokenize_OneWordWithSplitChar() { string input = "todo."; WordInfo[] expectedOutput = new WordInfo[] { new WordInfo("todo", 0, 0, WordLocation.Content) }; WordInfo[] output = Tools.Tokenize(input, WordLocation.Content); Assert.AreEqual(expectedOutput.Length, output.Length, "Wrong output length"); for (int i = 0; i < output.Length; i++) { Assert.AreEqual(expectedOutput[i].Text, output[i].Text, "Wrong word text at index " + i); Assert.AreEqual(expectedOutput[i].FirstCharIndex, output[i].FirstCharIndex, "Wrong first char index at " + i); Assert.AreEqual(expectedOutput[i].WordIndex, output[i].WordIndex, "Wrong word index at " + i); } }
private void WordsDataGridAddingNewItem(object sender, AddingNewItemEventArgs e) { DataGrid dataGrid = sender as DataGrid; if (dataGrid == null) { return; } LanguageConfig nativeLang = App.CountriesConfig.FirstOrDefault(c => c.Alias.Contains("Rus")); LanguageConfig translatedLang = App.CountriesConfig.LastOrDefault(c => c.Alias.Contains("Eng")); if (_wordsList.Count > 0) { List <IGrouping <LanguageConfig, WordInfo> > nativeLangGrouping = _wordsList.GroupBy(w => w.NativeLang).ToList(); List <IGrouping <LanguageConfig, WordInfo> > translatedLangGrouping = _wordsList.GroupBy(w => w.TranslatedLang).ToList(); int nativeLangGroupingMaxElementsCount = nativeLangGrouping.Max(g => g.Count()); int translatedLangGroupingMaxElementsCount = translatedLangGrouping.Max(g => g.Count()); IGrouping <LanguageConfig, WordInfo> nativeLangusgeGroup = nativeLangGrouping.FirstOrDefault(tt => tt.Count() == nativeLangGroupingMaxElementsCount); IGrouping <LanguageConfig, WordInfo> translatedLangusgeGroup = translatedLangGrouping.FirstOrDefault(tt => tt.Count() == translatedLangGroupingMaxElementsCount); if (nativeLangusgeGroup != null) { nativeLang = nativeLangusgeGroup.Key; } if (translatedLangusgeGroup != null) { translatedLang = translatedLangusgeGroup.Key; } } WordInfo lastItem = _wordsList.LastOrDefault() ?? new WordInfo(); e.NewItem = new WordInfo { NativeLang = nativeLang, TranslatedLang = translatedLang, TwoWays = lastItem.TwoWays, Parent = lastItem.Parent, }; }
public void DetailWord(WordInfo info) { DetailPanel.SetActive(true); Debug.Log("Detail Word :" + info.data.Id); AudioManager.I.PlayWord(info.data.Id); MoreInfoPanel.SetActive(false); ScoreText.text = "Score: " + info.score; var output = ""; var splittedLetters = ArabicAlphabetHelper.SplitWordIntoLetters(info.data.Arabic); foreach (var letter in splittedLetters) { output += letter.GetChar() + " "; } output += "\n"; output += info.data.Arabic; //output += "\n"; //foreach (var letter in splittedLetters) { // output += letter.GetChar(); //} ArabicText.text = output; LL_Isolated.Init(new LL_WordData(info.data)); LL_Initial.gameObject.SetActive(false); LL_Final.gameObject.SetActive(false); if (info.data.Drawing != "") { var drawingChar = AppManager.I.Teacher.wordHelper.GetWordDrawing(info.data); Drawing.text = drawingChar; //LL_Medial.gameObject.SetActive(true); LL_Medial.Init(new LL_ImageData(info.data)); Debug.Log("Drawing: " + info.data.Drawing + " / " + ArabicAlphabetHelper.GetLetterFromUnicode(info.data.Drawing)); } else { Drawing.text = ""; LL_Medial.gameObject.SetActive(false); } }
/// <summary> /// Stores a document in the index. /// </summary> /// <param name="document">The document.</param> /// <param name="keywords">The document keywords, if any, an empty array or <c>null</c> otherwise.</param> /// <param name="content">The content of the document.</param> /// <param name="state">A state object that is passed to the IndexStorer SaveDate/DeleteData function.</param> /// <returns>The number of indexed words (including duplicates).</returns> /// <remarks>Indexing the content of the document is <b>O(n)</b>, /// where <b>n</b> is the total number of words in the document.</remarks> public int StoreDocument(IDocument document, string[] keywords, string content, object state) { if (document == null) { throw new ArgumentNullException("document"); } if (keywords == null) { keywords = new string[0]; } if (content == null) { throw new ArgumentNullException("content"); } RemoveDocument(document, state); keywords = ScrewTurn.Wiki.SearchEngine.Tools.CleanupKeywords(keywords); // Prepare content words WordInfo[] contentWords = document.Tokenize(content); contentWords = ScrewTurn.Wiki.SearchEngine.Tools.RemoveStopWords(contentWords, stopWords); // Prepare title words WordInfo[] titleWords = document.Tokenize(document.Title); titleWords = ScrewTurn.Wiki.SearchEngine.Tools.RemoveStopWords(titleWords, stopWords); for (int i = 0; i < titleWords.Length; i++) { titleWords[i] = new WordInfo(titleWords[i].Text, titleWords[i].FirstCharIndex, titleWords[i].WordIndex, WordLocation.Title); } // Prepare keywords WordInfo[] words = new WordInfo[keywords.Length]; int count = 0; for (int i = 0; i < words.Length; i++) { words[i] = new WordInfo(keywords[i], (ushort)count, (ushort)i, WordLocation.Keywords); count += 1 + keywords[i].Length; } return(connector.SaveDataForDocument(document, contentWords, titleWords, words, state)); }
public void DetailWord(WordInfo _currentWord) { currentWordInfo = _currentWord; DetailPanel.SetActive(true); HighlightWordItem(currentWordInfo.data.Id); PlayWord(); // empty spelling container foreach (Transform t in SpellingContainer.transform) { Destroy(t.gameObject); } var splittedLetters = ArabicAlphabetHelper.SplitWord(AppManager.I.DB, currentWordInfo.data, false, false); foreach (var letter in splittedLetters) { btnGO = Instantiate(SpellingLetterItemPrefab); btnGO.transform.SetParent(SpellingContainer.transform, false); btnGO.transform.SetAsFirstSibling(); btnGO.GetComponent <ItemSpellingLetter>().Init(letter.letter); } WordArabicText.text = currentWordInfo.data.Arabic; if (currentWordInfo.data.Drawing != "") { WordDrawingText.text = AppManager.I.VocabularyHelper.GetWordDrawing(currentWordInfo.data); if (currentWordInfo.data.Category == WordDataCategory.Color) { WordDrawingText.SetColor(GenericHelper.GetColorFromString(currentWordInfo.data.Value)); } } else { WordDrawingText.text = ""; } if (AppConfig.DebugLogEnabled) { Debug.Log("Detail Word(): " + currentWordInfo.data.Id); Debug.Log("word unicodes: " + ArabicAlphabetHelper.GetStringUnicodes(currentWordInfo.data.Arabic)); Debug.Log("word unicodes forms: " + ArabicAlphabetHelper.GetStringUnicodes(WordArabicText.RenderedText)); } //ScoreText.text = "Score: " + currentWord.score; }
public void DetailWord(WordInfo _currentWord) { currentWordInfo = _currentWord; DetailPanel_Inner.SetActive(true); HighlightWordItem(currentWordInfo.data.Id); PlayWord(); // empty spelling container foreach (Transform t in SpellingContainer.transform) { Destroy(t.gameObject); } var splittedLetters = LanguageSwitcher.I.GetHelper(LanguageUse.Learning).SplitWord(AppManager.I.DB, currentWordInfo.data, false, false); foreach (var letter in splittedLetters) { btnGO = Instantiate(SpellingLetterItemPrefab); btnGO.transform.SetParent(SpellingContainer.transform, false); if (LanguageSwitcher.I.IsLearningLanguageRTL()) { btnGO.transform.SetAsFirstSibling(); } btnGO.GetComponent <ItemSpellingLetter>().Init(letter.letter); } WordArabicText.text = currentWordInfo.data.Text; if (currentWordInfo.data.Drawing != "") { WordDrawingText.SetLetterData(new LL_ImageData(currentWordInfo.data)); } else { WordDrawingText.text = ""; } if (ApplicationConfig.I.DebugLogEnabled) { Debug.Log("Detail Word(): " + currentWordInfo.data.Id); Debug.Log("drawing code: " + currentWordInfo.data.Drawing); Debug.Log("word unicodes: " + LanguageSwitcher.I.GetHelper(LanguageUse.Learning).GetStringUnicodes(currentWordInfo.data.Text)); Debug.Log("word unicodes forms: " + LanguageSwitcher.I.GetHelper(LanguageUse.Learning).GetStringUnicodes(WordArabicText.RenderedText)); } //ScoreText.text = "Score: " + currentWord.score; }
public void RtlWordsInLtrContentTest() { var content = "This is a test content for use متن تستی راست به چپ in ltr content"; var ltrPara = new Paragraph(0); var ltrLine = ltrPara.AddLine(new Line(new Point(0, 0))); var offset = 0; var wordCounter = 0; foreach (var word in content.Split(" ")) { var wordInfo = new WordInfo(word, offset, WordType.Normal); wordInfo.Styles.SetDirection(Paragraph.IsRtl(word)); wordInfo.SetFormattedText(_arial, _fontSize, 1, _lineHeight); offset += word.Length; var space = new SpaceWord(offset++); space.Styles.SetDirection(wordInfo.Styles.IsRtl); space.SetFormattedText(_arial, _fontSize, 1, _lineHeight); ltrLine.AddWord(wordInfo); Assert.AreEqual(++wordCounter, ltrLine.Words.Count); ltrLine.AddWord(space); Assert.AreEqual(++wordCounter, ltrLine.Words.Count); } ltrLine.Build(false); for (var i = 0; i < ltrLine.Words.Count - 1; i++) { Debug.WriteLine($"Word {i}'th"); var word = ltrLine.Words[i]; var nextWord = ltrLine.Words[i + 1]; if (word.Styles.IsRtl && nextWord.Styles.IsRtl) // 0X <--2-- <--1-- NX { Assert.IsTrue(word.Area.X > nextWord.Area.X); } else if (word.Styles.IsLtr && nextWord.Styles.IsLtr) // 0X --1--> --2--> NX { Assert.IsTrue(word.Area.X < nextWord.Area.X); } else { Assert.IsTrue(word.Area.X < nextWord.Area.X); } } }
/// <summary> /// Spawn word and non verbal object /// </summary> /// <param name="sound">Wordinfo. Spawn as non verbal if sound.word equals ""</param> /// <param name="isNewObject">Will have authority if it is newly generated.</param> public void spawnSoundObject(WordInfo sound, bool isNewObject) { GameObject soundobj; if (string.IsNullOrEmpty(sound.word)) { soundobj = (GameObject)Instantiate(nonVerbalPrefab); } else { soundobj = (GameObject)Instantiate(wordPrefab); } soundobj.transform.position = sound.pos; soundobj.transform.rotation = sound.rot; SoundObjectActs soundscript = soundobj.GetComponent <SoundObjectActs> (); if (soundscript is WordActs) { ((WordActs)soundscript).m_wordstr = sound.word; ((WordActs)soundscript).m_scale = sound.scale; } soundscript.m_serverFileName = sound.clipfn; if (sound.looping) { soundscript.m_looping = true; soundscript.m_sequencer.playtriggers = sound.playerTriggers; soundscript.m_sequencer.loadedFromScene = true; if (sound.scrubs != null) { soundscript.m_sequencer.scrubs = sound.scrubs; } soundscript.m_sequencer.path = sound.path; } if (isNewObject) { soundscript.m_newSpawn = true; soundscript.m_creator = netId.Value; Debug.Log(connectionToClient.connectionId); NetworkServer.SpawnWithClientAuthority(soundobj, connectionToClient); } else { NetworkServer.Spawn(soundobj); } }
public void ContainsOccurrence() { WordInfoCollection collection = new WordInfoCollection(); WordInfo mi1 = new WordInfo("continuous", 7, 0, WordLocation.Content); collection.Add(mi1); Assert.IsTrue(collection.ContainsOccurrence("continuous", 7), "Collection should contain occurrence"); Assert.IsFalse(collection.ContainsOccurrence("continuous2", 7), "Collection should not contain occurrence"); Assert.IsFalse(collection.ContainsOccurrence("continuous", 6), "Collection should not contain occurrence"); Assert.IsFalse(collection.ContainsOccurrence("continuous", 8), "Collection should not contain occurrence"); Assert.IsFalse(collection.ContainsOccurrence("continuous2", 6), "Collection should not contain occurrence"); Assert.IsFalse(collection.ContainsOccurrence("continuous2", -1), "Contains should return false"); Assert.IsFalse(collection.ContainsOccurrence("", 7), "Contains should return false"); Assert.IsFalse(collection.ContainsOccurrence(null, 7), "Contains should return false"); }
public void Setup() { _maker = new XHtmlMaker(); _kanjiWithReading = new WordInfo { Text = "見世物", Reading = "ミセモノ", Translation = "Unreal" }; _kanjiWithoutReading = new WordInfo { Text = "見世物" }; _hiraganaWord = new WordInfo { Text = "すべて", Reading = "スベテ" }; _katakanaWord = new WordInfo { Text = "スベテ", Reading = "スベテ" }; _hiraganaWordWithDifferentPronunciation = new WordInfo { Text = "は", Reading = "ハ", Pronunciation = "ワ" }; }
public WordVM(WordInfo wordInfo, IKanjiProperties lang, IKanaProperties kanaProperties, IRelated related) { var s = wordInfo.RawWord; StringForm = s; codePoints.AddRange(s.AsCodePoints().Select(rawCp => { var cp = CodePoint.FromInt(rawCp); var vm = new CodePointVM( cp, related.FindRelated(cp).SelectMany(g => g), cp is Kanji k ? lang.LookupRadicalsByKanji(k).ValueOr(Enumerable.Empty <CodePoint>()) : Enumerable.Empty <CodePoint>(), cp is Kana kana ? kanaProperties.LookupRomaji(kana.ToString()) : null); return(vm); })); WordInfo = wordInfo; }
public WordInfo SearchWord(string text) { if (!ContainsWord(text)) { return(null); } ZType ztype = SearchZTypeOne(text); WordInfo info0 = null; if (ztype != null) { info0 = new WordInfo(text, WordKind.TypeName, ztype); } WordInfo info1 = IWordDictionaryHelper.EnumerableSearchWord(text, EnumTypes); WordInfo info2 = IWordDictionaryHelper.EnumerableSearchWord(text, ClassTypes); WordInfo newWord = WordInfo.Merge(info0, info1, info2); return(newWord); }
private SplitResult SplitOne(string src) { //Console.WriteLine("WordSegmenter.SplitOne: "+src); if (src.Length == 1) { WordInfo result = GetFromTree(src); if (result == null) { result = new WordInfo(src, WordKind.Unkown); } SplitResult splitResult = new SplitResult(); splitResult.UnSplitText = ""; splitResult.ResultWord = result; return(splitResult); } else { SplitResult splitResult = null; WordInfo result = null; int i = 0; for (; i < src.Length; i++) { string newsrc = src.Substring(i); //Console.WriteLine("WordSegmenter.SplitOne: " + newsrc); result = GetFromTree(newsrc); if (result != null) { splitResult = new SplitResult(); splitResult.UnSplitText = src.Substring(0, i); splitResult.ResultWord = result; return(splitResult); } } if (splitResult == null) { splitResult = new SplitResult(); splitResult.UnSplitText = src.Substring(0, src.Length - 1); WordInfo info = new WordInfo(src.Substring(src.Length - 1), WordKind.Unkown); splitResult.ResultWord = info; } return(splitResult); } }
private void AddWordsUsingLingualeo(object sender, RoutedEventArgs args) { long addedWordsCount = 0; IEnumerable <WordInfo> allWordsFromLingualeo = GetWordsListFromLingualeo(); foreach (WordInfo justAddedWord in allWordsFromLingualeo) { WordInfo existedWord = _wordsList.FirstOrDefault(w => w.NativeLang == justAddedWord.NativeLang && w.TranslatedLang == justAddedWord.TranslatedLang && w.NativeWord == justAddedWord.NativeWord && w.TranslatedWord == justAddedWord.TranslatedWord); if (existedWord != null) { continue; } _wordsList.Add(justAddedWord); addedWordsCount++; } MessageBox.Show(addedWordsCount + " new words successfully added.", addedWordsCount + " words added", MessageBoxButton.OK, MessageBoxImage.Information); }
public WordVM(WordInfo wordInfo, ILanguageService lang) { var s = wordInfo.RawWord; StringForm = s; codePoints.AddRange(s.AsCodePoints().Select(rawCp => { var cp = CodePoint.FromInt(rawCp); var vm = new CodePointVM( cp, lang.LookupRelatedCharacters(cp), cp is Kanji k ? lang.LookupRadicals(k).ValueOr(Enumerable.Empty <CodePoint>()) : Enumerable.Empty <CodePoint>(), cp is Kana kana ? lang.LookupRomaji(kana) : null); return(vm); })); WordInfo = wordInfo; }
[AuthFilter]//身份认证,不带token或者token错误会被拦截器拦截进不来这个接口 public IActionResult WordsUpLoad(WordDto body) { string token = _httpContext.HttpContext.Request.Headers["Authorization"]; AuthRedis.GetUserByToken(token, out UserInfo userInfo); using EFCoreContextWrite context = new EFCore.EFCoreContextWrite(); if (body.Eid == null) { int count = context.WordInfo.Where(x => x.PictureID == body.id).Count(); if (count > 0) { return(Ok(new ApiResponse(code: CodeAndMessage.已存在对应的资讯文档))); } WordInfo WordInfos = new WordInfo() { Id = SequenceID.GetSequenceID(), CreateTime = DateTime.Now, Disable = false, HtmlContent = body.HtmlContent, PictureID = body.id, LastModifiedTime = DateTime.Now, HtmlExplain = body.HtmlExplain, HtmlTitle = body.HtmlTitle, AttachedPath = body.AttachedPath }; context.Add(WordInfos); context.SaveChanges(); WordRedis.Del(); } else { var WordInfo = context.WordInfo.Single(x => x.Id == body.Eid); WordInfo.LastModifiedTime = DateTime.Now; WordInfo.HtmlContent = body.HtmlContent; WordInfo.HtmlExplain = body.HtmlExplain; WordInfo.HtmlTitle = body.HtmlTitle; WordInfo.AttachedPath = body.AttachedPath; context.SaveChanges(); WordRedis.Del(); } return(Ok(new ApiResponse())); }
/// <summary>Простое изменение слов</summary> static void test2() { Console.Write("{0, -55} | ", "Test 2 - простое изменение слов "); SaveResourceFile("test2_resoult", "test2_resoult.xml"); SaveResourceFile("source_empty_dic", "dic.xml"); Testing.Clear(); DB db = DB.GetInstance(); //Добавляем одно слово WordInfo info1 = new WordInfo(); info1.En = "testing..."; info1.Ru = "апробирование"; db.Push(info1); db.Commit(); //Изменяем слово WordInfo info2 = new WordInfo(); info2.Word = db.Words[0]; info2.Ru = "EnWord2"; info2.En = "EnWord1"; db.Push(info2); db.Commit(); int wrongIndex; if (!CompareFiles2("dic.xml", "test2_resoult.xml", out wrongIndex)) { Console.WriteLine("false (line " + wrongIndex + ")"); } else { Console.WriteLine("true"); } }
private string GetPartOfSpeechText(WordInfo info) { if (info != null) { if (info.flex == null && info.indent != null && info.nom != null) { info.flex = context.Flexes.FirstOrDefault(x => x.type == info.nom.type && x.flex == info.nom.reestr.Substring(info.nom.reestr.Length - info.indent.indent)); } if (info.flex != null) { Gr gr = context.Gr.FirstOrDefault(x => x.id == info.indent.gr_id); if (gr != null) { var grInfo = gr.GetType().GetProperty($"field{info.flex.field2 + 3}").GetValue(gr, null); return(grInfo.ToString()); } } } return(""); }
private WordInfo SplitOneChar(string src) { //string src = tok.GetText(); if (src.Length != 1) { throw new CompileException("SplitOneChar的内容'" + src + "'长度不为1"); } WordInfo word = GetFromTree(src); if (word != null) { return(word); } else { WordInfo info2 = new WordInfo(src, WordKind.Unkown); return(info2); } }
public void AfterSegment(SuperLinkedList <WordInfo> result) { SuperLinkedListNode <WordInfo> node = result.First; while (node != null) { if (node.Value.WordType == WordType.English) { int position = node.Value.Word.IndexOf("Nokia", 0, StringComparison.CurrentCultureIgnoreCase); if (position >= 0 && !node.Value.Word.Equals("Nokia", StringComparison.CurrentCultureIgnoreCase)) { WordInfo wordinfo = new WordInfo("Nokia", node.Value.Position + position, node.Value.Pos, node.Value.Frequency, node.Value.Rank, node.Value.WordType, node.Value.OriginalWordType); node = result.AddAfter(node, wordinfo); } } node = node.Next; } }
public void AfterSegment(SuperLinkedList<WordInfo> result) { SuperLinkedListNode<WordInfo> node = result.First; while (node != null) { if (node.Value.WordType == WordType.English) { int position = node.Value.Word.IndexOf("Nokia", 0, StringComparison.CurrentCultureIgnoreCase); if (position >= 0 && !node.Value.Word.Equals("Nokia", StringComparison.CurrentCultureIgnoreCase)) { WordInfo wordinfo = new WordInfo("Nokia", node.Value.Position + position, node.Value.Pos, node.Value.Frequency, node.Value.Rank, node.Value.WordType, node.Value.OriginalWordType); node = result.AddAfter(node, wordinfo); } } node = node.Next; } }
/// <summary> /// 获取特定字符串在整个字符串位置集合 /// </summary> /// <param name="wordInfo"></param> /// <returns></returns> private static List <int> GetStrIndexsFromAllText(WordInfo wordInfo) { List <int> subIndex = new List <int>(); try { if (wordInfo != null && !string.IsNullOrEmpty(wordInfo.AllText) && !string.IsNullOrEmpty(wordInfo.UnValidText)) { int ii = wordInfo.AllText.IndexOf(wordInfo.UnValidText); while (ii >= 0 && ii < wordInfo.AllText.Length) { subIndex.Add(ii); ii = wordInfo.AllText.IndexOf(wordInfo.UnValidText, ii + 1); } } } catch (Exception ex) { } return(subIndex); }
public void UpdateWordInfo(WordInfo word) { currentCharacter = 0; pinYinArray = word.Pinyin.Split(' '); characterArray = word.Content.Split(' '); AndroidUtil.Log( "拼音: " + GeneralUtils.printArray(pinYinArray) + "\n内容: " + GeneralUtils.printArray(characterArray) + "\n详细: " + word.detail); for (var i = 0; i < pinYinArray.Length; i++) { characterGrids[i].pinyin.text = pinYinArray[i]; characterGrids[i].content.text = ""; } currentPinYin.text = pinYinArray[0]; characterGrids[0].toggle.isOn = true; tipPinYin.text = infos[currentWord].Pinyin; tipDetail.text = "释义:" + infos[currentWord].Detail; }
/// <summary> /// 图片生成WORD、PDF文件 /// </summary> /// <returns></returns> public Dictionary <string, string> ImagesToWordPDF(string docname, string abspath, string FilePath, Dictionary <string, string> imgdic) { DateTime dt = DateTime.Now; if (!Directory.Exists(FilePath)) { Directory.CreateDirectory(FilePath); } string OriginalPathYear = FilePath + "\\" + dt.Year; if (!Directory.Exists(OriginalPathYear)) { Directory.CreateDirectory(OriginalPathYear); } string OriginalPathdate = OriginalPathYear + "\\" + dt.ToString("yyyyMMdd"); if (!Directory.Exists(OriginalPathdate)) { Directory.CreateDirectory(OriginalPathdate); } string wordtimeStr = dt.ToString("yyyyMMddHHmmssffff") + new Random().Next(10000, 99999); string wordfileName = docname + wordtimeStr + ".docx"; string wordPath = Path.Combine(OriginalPathdate, wordfileName); string pdftimeStr = dt.ToString("yyyyMMddHHmmssffff") + new Random().Next(10000, 99999); string pdffileName = docname + pdftimeStr + ".pdf"; string pdfPath = Path.Combine(OriginalPathdate, pdffileName); WordInfo info = new WordInfo(abspath, wordPath, pdfPath); info.AddPictures(imgdic); info.WordToPdf(); info.Dispose(); Dictionary <string, string> doc = new Dictionary <string, string>(); doc.Add("WordPath", dt.Year + "/" + dt.ToString("yyyyMMdd") + "/" + wordfileName); doc.Add("PDFPath", dt.Year + "/" + dt.ToString("yyyyMMdd") + "/" + pdffileName); return(doc); }
//I have to optimise this. public static List <WordInfo> GetSelectedWords(int startSelectionIndex, string selectedText, string fullText) { _selectedWords.Clear(); var charIndex = 0; var selectedSplitted = selectedText.Split(SplitPattern, StringSplitOptions.RemoveEmptyEntries); for (int i = 0; i < selectedSplitted.Length; i++) { for (int j = startSelectionIndex; j < startSelectionIndex + selectedText.Length; j++) { if (fullText[j].IsValidChar()) { charIndex = j; while (fullText.ElementAtOrDefault(j).IsValidChar()) { j++; } startSelectionIndex = j; break; } } var pair = GetWordIndexPair(fullText, charIndex); var info = new WordInfo() { GlobalCharIndex = charIndex, WordIndex = pair.Item1, Word = pair.Item2 }; _selectedWords.Add(info); } return(_selectedWords); }
public WordInfo SearchWord(string text) { List <WordInfo> words = new List <WordInfo>(); foreach (IWordDictionary dict in this) { WordInfo word = dict.SearchWord(text); if (word != null) { words.Add(word); } } if (words != null) { WordInfo newWord = WordInfo.Merge(words.ToArray()); return(newWord); } else { return(null); } }
{/// <summary> /// Создание документа /// </summary> /// <param name="info"></param> public static void CreateDoc(WordInfo info) { using (WordprocessingDocument wordDocument = WordprocessingDocument.Create(info.FileName, WordprocessingDocumentType.Document)) { MainDocumentPart mainPart = wordDocument.AddMainDocumentPart(); mainPart.Document = new Document(); Body docBody = mainPart.Document.AppendChild(new Body()); docBody.AppendChild(CreateParagraph(new WordParagraph { Texts = new List <string> { info.Title }, TextProperties = new WordParagraphProperties { Bold = true, Size = "24", JustificationValues = JustificationValues.Center } })); foreach (var component in info.Komlects) { docBody.AppendChild(CreateParagraph(new WordParagraph { Texts = new List <string> { component.KomlectName + " - " + component.Price.ToString() + " р." }, TextProperties = new WordParagraphProperties { Bold = true, Size = "24", JustificationValues = JustificationValues.Both } })); } docBody.AppendChild(CreateSectionProperties()); wordDocument.MainDocumentPart.Document.Save(); } }
private void imageButton_Click(object sender, EventArgs e) { Button senderButton = (Button)sender; int position = tblLayout.GetColumn(senderButton); WordInfo wordInfo = m_Settings.Words[position]; if (wordInfo.IsHidden) { wordInfo.IsHidden = false; if (wordInfo.IsBadWord) { //senderButton.BackgroundImage = GuessTheSong.Properties.Resources.Minus; senderButton.BackgroundImage = GuessTheSong.Properties.Resources.MinusTall; } else { //senderButton.BackgroundImage = GuessTheSong.Properties.Resources.Plus; senderButton.BackgroundImage = GuessTheSong.Properties.Resources.PlusTall; } senderButton.Text = wordInfo.Word; } ShowSongTextIfGuessed(); }
/// <summary> /// /// </summary> protected void GetAndCreateWords() { //string[] wordsFromXml = GameFunctions.GetTextXML(challengeTypeString, "WORDS", "word"); //string[] lettersFromXml = GameFunctions.GetTextXML(challengeTypeString, "LETTERS", "letter"); char[] lettersToFilter = challengeTypeString.ToCharArray(); string[] lettersToFilterString = new string[lettersToFilter.Length]; for (int i = 0; i < lettersToFilterString.Length; i++) { lettersToFilterString[i] = lettersToFilter[i].ToString(); } Debug.Log(lettersToFilterString[0]); //WordsWithLetters wordsWithLetters = GetWords(lettersToFilterString); //WordsWithLetters wordsWithLetters = GetWords2(lettersToFilterString, (int)gameManager.infoType[ChallengeType.ZCS].Difficulty); WordsWithLetters wordsWithLetters = GetWords2(lettersToFilterString, 10); string[] wordsToUse = wordsWithLetters.words; string[] lettersToUse = wordsWithLetters.letters; int auxInt = 0; wordObjects = new List <WordInfo>(); wordsInScreen = new Queue <WordInfo>(4); foreach (string s in wordsToUse) { WordInfo aux = Instantiate(wordPrefab).GetComponent <WordInfo>(); aux.Word = s; aux.Letter = lettersToUse[auxInt]; aux.GetComponent <TextMesh>().text = aux.Word; aux.gameObject.SetActive(false); wordObjects.Add(aux); auxInt++; } AddWordInScreen(); }
public static void SaveWord(EnglishWordSqliteHelper englishWordSource, EnglishWordSqliteHelper englishWordOutput, EnglishWordTranslationData wordData) { if (string.IsNullOrEmpty(wordData.Word)) { return; } //var transformToWordSaveInfo = TransformToWordSaveInfo(wordData); var previousWord = englishWordSource.GetWord(wordData.Word); WordInfo newWord = new WordInfo(); newWord.Word = wordData.Word; if (previousWord != null) { newWord.Pronounce = previousWord.Pronounce; newWord.PronounceFileName = previousWord.PronounceFileName; } else { newWord.Word = wordData.Word; } SetWordPronounceInfo(newWord, wordData); var newSemanticList = GetSemanticSaveInfos(wordData); if (newSemanticList.Count > 0) { newWord.Semantic = JsonConvert.SerializeObject(GetSemanticSaveInfos(wordData)); } newWord.Sentence = JsonConvert.SerializeObject(GetSentenceSaveInfos(wordData)); newWord.Phrase = JsonConvert.SerializeObject(GetPhraseSaveInfos(wordData)); newWord.Synonym = JsonConvert.SerializeObject(GetSynonymInfos(wordData)); newWord.Cognate = JsonConvert.SerializeObject(GetCognateInfos(wordData)); englishWordOutput.SaveWord(newWord); }
private SuperLinkedList<WordInfo> PreSegment(String text) { SuperLinkedList<WordInfo> result = GetInitSegment(text); SuperLinkedListNode<WordInfo> cur = result.First; while (cur != null) { if (_Options.IgnoreSpace) { if (cur.Value.WordType == WordType.Space) { SuperLinkedListNode<WordInfo> lst = cur; cur = cur.Next; result.Remove(lst); continue; } } switch (cur.Value.WordType) { case WordType.SimplifiedChinese: string inputText = cur.Value.Word; WordType originalWordType = WordType.SimplifiedChinese; if (_Options.TraditionalChineseEnabled) { string simplified = Microsoft.VisualBasic.Strings.StrConv(cur.Value.Word, Microsoft.VisualBasic.VbStrConv.SimplifiedChinese, 0); if (simplified != cur.Value.Word) { originalWordType = WordType.TraditionalChinese; inputText = simplified; } } PanGu.Framework.AppendList<Dict.PositionLength> pls = _WordDictionary.GetAllMatchs(inputText, _Options.ChineseNameIdentify); PanGu.Match.ChsFullTextMatch chsMatch = new PanGu.Match.ChsFullTextMatch(_WordDictionary); chsMatch.Options = _Options; chsMatch.Parameters = _Parameters; SuperLinkedList<WordInfo> chsMatchWords = chsMatch.Match(pls.Items, cur.Value.Word, pls.Count); SuperLinkedListNode<WordInfo> curChsMatch = chsMatchWords.First; while (curChsMatch != null) { WordInfo wi = curChsMatch.Value; wi.Position += cur.Value.Position; wi.OriginalWordType = originalWordType; wi.WordType = originalWordType; if (_Options.OutputSimplifiedTraditional) { if (_Options.TraditionalChineseEnabled) { string newWord; WordType wt; if (originalWordType == WordType.SimplifiedChinese) { newWord = Microsoft.VisualBasic.Strings.StrConv(wi.Word, Microsoft.VisualBasic.VbStrConv.TraditionalChinese, 0); wt = WordType.TraditionalChinese; } else { newWord = Microsoft.VisualBasic.Strings.StrConv(wi.Word, Microsoft.VisualBasic.VbStrConv.SimplifiedChinese, 0); wt = WordType.SimplifiedChinese; } if (newWord != wi.Word) { WordInfo newWordInfo = new WordInfo(wi); newWordInfo.Word = newWord; newWordInfo.OriginalWordType = originalWordType; newWordInfo.WordType = wt; newWordInfo.Rank = _Parameters.SimplifiedTraditionalRank; newWordInfo.Position = wi.Position; chsMatchWords.AddBefore(curChsMatch, newWordInfo); } } } curChsMatch = curChsMatch.Next; } SuperLinkedListNode<WordInfo> lst = result.AddAfter(cur, chsMatchWords); SuperLinkedListNode<WordInfo> removeItem = cur; cur = lst.Next; result.Remove(removeItem); break; case WordType.English: cur.Value.Rank = _Parameters.EnglishRank; List<string> output; cur.Value.Word = ConvertChineseCapitalToAsiic(cur.Value.Word); if (_Options.IgnoreCapital) { cur.Value.Word = cur.Value.Word.ToLower(); } if (_Options.EnglishSegment) { string lower = cur.Value.Word.ToLower(); if (lower != cur.Value.Word) { result.AddBefore(cur, new WordInfo(lower, cur.Value.Position, POS.POS_A_NX, 1, _Parameters.EnglishLowerRank, WordType.English, WordType.English)); } string stem = GetStem(lower); if (!string.IsNullOrEmpty(stem)) { if (lower != stem) { result.AddBefore(cur, new WordInfo(stem, cur.Value.Position, POS.POS_A_NX, 1, _Parameters.EnglishStemRank, WordType.English, WordType.English)); } } } if (_Options.MultiDimensionality) { if (Framework.Regex.GetMatchStrings(cur.Value.Word, PATTERNS, true, out output)) { int outputCount = 0; foreach (string str in output) { if (!string.IsNullOrEmpty(str)) { outputCount++; if (outputCount > 1) { break; } } } if (outputCount > 1) { int position = cur.Value.Position; foreach (string splitWord in output) { if (string.IsNullOrEmpty(splitWord)) { continue; } WordInfo wi; if (splitWord[0] >= '0' && splitWord[0] <= '9') { wi = new WordInfo(splitWord, POS.POS_A_M, 1); wi.Position = position; wi.Rank = _Parameters.NumericRank; wi.OriginalWordType = WordType.English; wi.WordType = WordType.Numeric; } else { wi = new WordInfo(splitWord, POS.POS_A_NX, 1); wi.Position = position; wi.Rank = _Parameters.EnglishRank; wi.OriginalWordType = WordType.English; wi.WordType = WordType.English; } result.AddBefore(cur, wi); position += splitWord.Length; } } } } if (!MergeEnglishSpecialWord(text, result, ref cur)) { cur = cur.Next; } break; case WordType.Numeric: cur.Value.Word = ConvertChineseCapitalToAsiic(cur.Value.Word); cur.Value.Rank = _Parameters.NumericRank; if (!MergeEnglishSpecialWord(text, result, ref cur)) { cur = cur.Next; } //cur = cur.Next; break; case WordType.Symbol: cur.Value.Rank = _Parameters.SymbolRank; cur = cur.Next; break; default: cur = cur.Next; break; } } return result; }
public void Contains_String() { WordInfoCollection collection = new WordInfoCollection(); WordInfo mi1 = new WordInfo("continuous", 0, 0, WordLocation.Content); collection.Add(mi1); Assert.IsTrue(collection.Contains("continuous"), "Collection should contain string"); Assert.IsFalse(collection.Contains("taskbar"), "Collection should not contain string"); Assert.IsFalse(collection.Contains(null as string), "Contains should return false"); Assert.IsFalse(collection.Contains(""), "Contains should return false"); }
public void Constructor_EmptyText() { WordInfo info = new WordInfo("", 0, 0, WordLocation.Content); }
public void Remove() { WordInfoCollection collection = new WordInfoCollection(); WordInfo mi1 = new WordInfo("goose", 1, 0, WordLocation.Content); WordInfo mi2 = new WordInfo("hello", 12, 0, WordLocation.Content); collection.Add(mi1); Assert.IsTrue(collection.Contains(mi1), "Collection should contain item"); Assert.IsFalse(collection.Contains(mi2), "Collection should not contain item"); Assert.IsFalse(collection.Contains(null as WordInfo), "Contains should return false"); }
public void UnderlineWord(Graphics g, WordInfo wi) { if(TextLength<=1) return; UnderlineWord(g, wi.start, wi.word.Length); }
public void Constructor_NullText() { WordInfo info = new WordInfo(null, 0, 0, WordLocation.Content); }
public void CopyTo_InvalidIndex_TooBig() { WordInfoCollection collection = new WordInfoCollection(); WordInfo[] results = new WordInfo[10]; collection.CopyTo(results, 10); }
public void CopyTo_NoSpaceAtIndex() { WordInfoCollection collection = new WordInfoCollection(); WordInfo mi1 = new WordInfo("home", 0, 0, WordLocation.Content); WordInfo mi2 = new WordInfo("taskbar", 100, 0, WordLocation.Content); collection.Add(mi1); collection.Add(mi2); WordInfo[] matches = new WordInfo[2]; collection.CopyTo(matches, 1); }
public void CopyTo_ArrayTooSmall() { WordInfoCollection collection = new WordInfoCollection(); WordInfo mi1 = new WordInfo("home", 0, 0, WordLocation.Content); WordInfo mi2 = new WordInfo("taskbar", 100, 0, WordLocation.Content); collection.Add(mi1); collection.Add(mi2); WordInfo[] matches = new WordInfo[1]; collection.CopyTo(matches, 0); }
public void CopyTo_InvalidIndex_Negative() { WordInfoCollection collection = new WordInfoCollection(); WordInfo[] results = new WordInfo[10]; collection.CopyTo(results, -1); }
public void CopyTo() { WordInfoCollection collection = new WordInfoCollection(); WordInfo mi1 = new WordInfo("continuous", 0, 0, WordLocation.Content); WordInfo mi2 = new WordInfo("goose", 34, 0, WordLocation.Content); collection.Add(mi1); collection.Add(mi2); WordInfo[] matches = new WordInfo[2]; collection.CopyTo(matches, 0); Assert.AreEqual(mi1, matches[0], "Wrong match item"); Assert.AreEqual(mi2, matches[1], "Wrong match item"); matches = new WordInfo[3]; collection.CopyTo(matches, 0); Assert.AreEqual(mi1, matches[0], "Wrong match item"); Assert.AreEqual(mi2, matches[1], "Wrong match item"); Assert.IsNull(matches[2], "Non-null item"); matches = new WordInfo[3]; collection.CopyTo(matches, 1); Assert.IsNull(matches[0], "Non-null item"); Assert.AreEqual(mi1, matches[1], "Wrong match item"); Assert.AreEqual(mi2, matches[2], "Wrong match item"); }
public void Contains_WordInfo() { WordInfoCollection collection = new WordInfoCollection(); WordInfo mi1 = new WordInfo("continuous", 0, 0, WordLocation.Content); WordInfo mi2 = new WordInfo("taskbar", 21, 0, WordLocation.Content); collection.Add(mi1); Assert.IsTrue(collection.Contains(mi1), "Collection should contain item"); Assert.IsFalse(collection.Contains(mi2), "Collection should not contain item"); Assert.IsFalse(collection.Contains(null as WordInfo), "Contains should return false"); }
/// <summary> /// Stores a document in the index. /// </summary> /// <param name="document">The document.</param> /// <param name="keywords">The document keywords, if any, an empty array or <c>null</c> otherwise.</param> /// <param name="content">The content of the document.</param> /// <param name="state">A state object that is passed to the IndexStorer SaveDate/DeleteData function.</param> /// <returns>The number of indexed words (including duplicates).</returns> /// <remarks>Indexing the content of the document is <b>O(n)</b>, /// where <b>n</b> is the total number of words in the document.</remarks> public int StoreDocument(IDocument document, string[] keywords, string content, object state) { if(document == null) throw new ArgumentNullException("document"); if(keywords == null) keywords = new string[0]; if(content == null) throw new ArgumentNullException("content"); RemoveDocument(document, state); keywords = ScrewTurn.Wiki.SearchEngine.Tools.CleanupKeywords(keywords); // Prepare content words WordInfo[] contentWords = document.Tokenize(content); contentWords = ScrewTurn.Wiki.SearchEngine.Tools.RemoveStopWords(contentWords, stopWords); // Prepare title words WordInfo[] titleWords = document.Tokenize(document.Title); titleWords = ScrewTurn.Wiki.SearchEngine.Tools.RemoveStopWords(titleWords, stopWords); for(int i = 0; i < titleWords.Length; i++) { titleWords[i] = new WordInfo(titleWords[i].Text, titleWords[i].FirstCharIndex, titleWords[i].WordIndex, WordLocation.Title); } // Prepare keywords WordInfo[] words = new WordInfo[keywords.Length]; int count = 0; for(int i = 0; i < words.Length; i++) { words[i] = new WordInfo(keywords[i], (ushort)count, (ushort)i, WordLocation.Keywords); count += 1 + keywords[i].Length; } return connector.SaveDataForDocument(document, contentWords, titleWords, words, state); }
private void OnIdle(object sender, EventArgs e) { if(_spellUpdateNeeded) { string str=Text; string []words=str.Split(new char[]{' ', ',' , '\'' , '.', ':', '-', '!', '?'}); ArrayList wrongWordList=new ArrayList(); int l=0; for(int i=0; i<str.Length; i++) { if(char.IsLetterOrDigit(str[i])) { l++; } else { if(l>0) { string word=str.Substring(i-l, l); if(word.Length>0 && _spell.TestWord(word)==false ) { WordInfo wi=new WordInfo(); wi.start=i-l; wi.word=word; wrongWordList.Add(wi); } } l=0; } } /* foreach(string word in words) { if(word.Length>0 && wrongWordList.Contains(word)==false && _spell.TestWord(word)==false ) { wrongWordList.Add(word); } }*/ WrongWord=wrongWordList; Invalidate(); } _spellUpdateNeeded=false; }
public void GetEnumerator() { WordInfoCollection collection = new WordInfoCollection(); WordInfo mi1 = new WordInfo("goose", 1, 0, WordLocation.Content); WordInfo mi2 = new WordInfo("hello", 12, 0, WordLocation.Content); collection.Add(mi2); collection.Add(mi1); int count = 0; foreach(WordInfo r in collection) { if(count == 0) Assert.AreEqual(mi1, r, "Wrong item at position 0"); if(count == 1) Assert.AreEqual(mi2, r, "Wrong item at position 1"); count++; } Assert.AreEqual(2, count, "Wrong count - enumerator does not work"); }
public WordInfo WordFromPos(Point pt) { int charpos=CharFromPos(pt); string str=Text; if(!char.IsLetterOrDigit(str[charpos])) return WordInfo.Zero; int start=charpos; int end=charpos; while(start>0 && char.IsLetterOrDigit(str[start-1])) { start--; } while(end<str.Length && char.IsLetterOrDigit(str[end])) { end++; } WordInfo wi=new WordInfo(); wi.word=str.Substring(start, end-start).Trim(); wi.start=start; return wi; }
public void Indexer() { WordInfoCollection collection = new WordInfoCollection(); WordInfo mi1 = new WordInfo("taskbar", 1, 0, WordLocation.Content); WordInfo mi2 = new WordInfo("goose", 12, 0, WordLocation.Content); collection.Add(mi2); collection.Add(mi1); Assert.AreEqual(mi1, collection[0], "Wrong item at position 0"); Assert.AreEqual(mi2, collection[1], "Wrong item at position 0"); }
/// <summary> /// Saves data for a new document. /// </summary> /// <param name="document">The document.</param> /// <param name="content">The content words.</param> /// <param name="title">The title words.</param> /// <param name="keywords">The keywords.</param> /// <param name="state">A state object passed from the index (can be <c>null</c> or a <see cref="T:DbTransaction" />).</param> /// <returns>The number of stored occurrences.</returns> private int SaveDataForDocument(IDocument document, WordInfo[] content, WordInfo[] title, WordInfo[] keywords, object state) { // 1. Insert document // 2. Insert all new words // 3. Load all word IDs // 4. Insert mappings // On error, return without rolling back if state != null, rollback otherwise // On completion, commit if state == null ICommandBuilder builder = GetCommandBuilder(); QueryBuilder queryBuilder = new QueryBuilder(builder); DbTransaction transaction = null; if(state != null) transaction = (DbTransaction)state; else { DbConnection connection = builder.GetConnection(connString); transaction = BeginTransaction(connection); } uint freeDocumentId = GetFreeElementId(IndexElementType.Documents, transaction); uint freeWordId = GetFreeElementId(IndexElementType.Words, transaction); // Insert the document string query = queryBuilder.InsertInto("IndexDocument", new string[] { "Id", "Name", "Title", "TypeTag", "DateTime" }, new string[] { "Id", "Name", "Title", "TypeTag", "DateTime" }); List<Parameter> parameters = new List<Parameter>(5); parameters.Add(new Parameter(ParameterType.Int32, "Id", (int)freeDocumentId)); parameters.Add(new Parameter(ParameterType.String, "Name", document.Name)); parameters.Add(new Parameter(ParameterType.String, "Title", document.Title)); parameters.Add(new Parameter(ParameterType.String, "TypeTag", document.TypeTag)); parameters.Add(new Parameter(ParameterType.DateTime, "DateTime", document.DateTime)); DbCommand command = builder.GetCommand(transaction, query, parameters); if(ExecuteNonQuery(command, false) != 1) { if(state == null) RollbackTransaction(transaction); return -1; } document.ID = freeDocumentId; List<WordInfo> allWords = new List<WordInfo>(content.Length + title.Length + keywords.Length); allWords.AddRange(content); allWords.AddRange(title); allWords.AddRange(keywords); List<WordInfo> existingWords = new List<WordInfo>(allWords.Count / 2); Dictionary<string, uint> wordIds = new Dictionary<string, uint>(1024); // Try to blindly insert all words (assumed to be lowercase and clean from diacritics) query = queryBuilder.InsertInto("IndexWord", new string[] { "Id", "Text" }, new string[] { "Id", "Text" }); parameters = new List<Parameter>(2); parameters.Add(new Parameter(ParameterType.Int32, "Id", 0)); parameters.Add(new Parameter(ParameterType.String, "Text", "")); foreach(WordInfo word in allWords) { parameters[0].Value = (int)freeWordId; parameters[1].Value = word.Text; command = builder.GetCommand(transaction, query, parameters); if(ExecuteNonQuery(command, false, false) == 1) { wordIds.Add(word.Text, freeWordId); freeWordId++; } else { existingWords.Add(word); } } // Load IDs of all existing words query = queryBuilder.SelectFrom("IndexWord", new string[] { "Id" }); query = queryBuilder.Where(query, "Text", WhereOperator.Equals, "Text"); parameters = new List<Parameter>(1); parameters.Add(new Parameter(ParameterType.String, "Text", "")); foreach(WordInfo word in existingWords) { parameters[0].Value = word.Text; command = builder.GetCommand(transaction, query, parameters); int id = ExecuteScalar<int>(command, -1, false); if(id == -1) { if(state == null) RollbackTransaction(transaction); return -1; } if(!wordIds.ContainsKey(word.Text)) { wordIds.Add(word.Text, (uint)id); } else if(wordIds[word.Text] != (uint)id) throw new InvalidOperationException("Word ID mismatch"); } // Insert all mappings query = queryBuilder.InsertInto("IndexWordMapping", new string[] { "Word", "Document", "FirstCharIndex", "WordIndex", "Location" }, new string[] { "Word", "Document", "FirstCharIndex", "WordIndex", "Location" }); parameters = new List<Parameter>(5); parameters.Add(new Parameter(ParameterType.Int32, "Word", 0)); parameters.Add(new Parameter(ParameterType.Int32, "Document", (int)freeDocumentId)); parameters.Add(new Parameter(ParameterType.Int16, "FirstCharIndex", 0)); parameters.Add(new Parameter(ParameterType.Int16, "WordIndex", 0)); parameters.Add(new Parameter(ParameterType.Byte, "Location", 0)); foreach(WordInfo word in allWords) { parameters[0].Value = (int)wordIds[word.Text]; parameters[1].Value = (int)freeDocumentId; parameters[2].Value = (short)word.FirstCharIndex; parameters[3].Value = (short)word.WordIndex; parameters[4].Value = word.Location.Location; command = builder.GetCommand(transaction, query, parameters); if(ExecuteNonQuery(command, false) != 1) { if(state == null) RollbackTransaction(transaction); return -1; } } if(state == null) CommitTransaction(transaction); return allWords.Count; }
private IEnumerable<WordInfo> Optimize(List<WordInfo> selection, int start, int end) { int maxRank = 0; WordInfo lst = null; for(int i = start; i < end; i++) { if (selection[i].Rank > maxRank) { maxRank = selection[i].Rank; } } int rankSum = 0; int endPosition = selection[start].GetEndPositon(); for (int i = start; i < end; i++) { if (endPosition < selection[i].GetEndPositon()) { endPosition = selection[i].GetEndPositon(); } if (selection[i].Rank == maxRank) { if (lst == null) { rankSum += (int)Math.Pow(3, selection[i].Rank); //yield return selection[i]; } else if (selection[i].Position >= lst.Position + lst.Word.Length) { rankSum += (int)Math.Pow(3, selection[i].Rank); //yield return selection[i]; } lst = selection[i]; } } WordInfo word = new WordInfo(); word.Position = selection[start].Position; word.Word = _Content.Substring(word.Position, endPosition - word.Position); word.Rank = rankSum == 0 ? (int)Math.Pow(3, maxRank) : rankSum; yield return word; }
private void BuildWordList(string s, int lineWidth) { Debug.Assert(!s.Contains("\n")); ArrayList<WordInfo> mWordListAL = new ArrayList<WordInfo>(); bool lookingForWs = false; WordInfo we = new WordInfo(); we.pos = 0; int spaces = 0; int totalLength = 0; for (int i = 0; i < s.Length; i++) { char ch = s[i]; if (lookingForWs && ch == ' ') { spaces++; if (we.pos != i) mWordListAL.Add(we); we = new WordInfo(); we.spacesBefore = spaces; we.pos = i + 1; lookingForWs = false; continue; } else if (ch != ' ') { lookingForWs = true; } we.length++; totalLength++; we.totalLength = totalLength; if (we.length == lineWidth) { mWordListAL.Add(we); we = new WordInfo(); we.spacesBefore = spaces; we.pos = i + 1; } } mWordListAL.Add(we); mWordList = mWordListAL.ToArray(); }
public void Constructor() { WordInfo info = new WordInfo("continuous", 2, 0, WordLocation.Content); Assert.AreEqual(2, info.FirstCharIndex, "Wrong start index"); Assert.AreEqual(10, info.Text.Length, "Wrong length"); }