public void TestCleanText() { Dictionary <string, string> StringsTable = new Dictionary <string, string>(); StringsTable.Add( key: "!\"#$%&'()=~|-^\\/,.<>;:@`{}[]*+The quick brown fox jumps over the lazy dog's!\"#$%&'()=~|-^\\/,.<>;:@`{}[]*+", value: "The quick brown fox jumps over the lazy dog's" ); StringsTable.Add( key: "The quick/slow, and the fast-stop and the second-best things we don't know about.", value: "The quick/slow and the fast-stop and the second-best things we don't know about" ); StringsTable.Add( key: "The markets opened at $100.00 today.", value: "The markets opened at $100.00 today" ); foreach (string StringKey in StringsTable.Keys) { string Cleaned = MacroscopeStringTools.CleanText(Text: StringKey); Assert.AreEqual(StringsTable[StringKey], Cleaned, string.Format("NOT VALID: {0}", Cleaned)); } }
/**************************************************************************/ public static string[] ReverseStringArray(string[] Input) { string[] Output = new string[Input.Length]; for (int i = 0; i < Input.Length; i++) { Output[i] = MacroscopeStringTools.ReverseString(Input[i]); } return(Output); }
/**************************************************************************/ public void SetAltText(string Text) { try { this.AltText = MacroscopeStringTools.CompactWhiteSpace(Text: Text); } catch (Exception ex) { this.DebugMsg(ex.Message); this.AltText = Text; } }
/**************************************************************************/ private void CallbackSearchCollectionTextBoxSearchKeyUp(object sender, KeyEventArgs e) { ToolStripTextBox SearchTextBox = ( ToolStripTextBox )sender; DebugMsg(string.Format("CallbackSearchCollectionTextBoxSearchKeyUp: {0}", "CALLED")); switch (e.KeyCode) { case Keys.Return: DebugMsg(string.Format("CallbackSearchCollectionTextBoxSearchKeyUp: {0}", "RETURN")); MacroscopeSearchIndex SearchIndex = this.JobMaster.GetDocCollection().GetSearchIndex(); string SearchText = MacroscopeStringTools.CleanHtmlText(Text: SearchTextBox.Text); if (SearchText.Length > 0) { List <MacroscopeDocument> DocList = null; SearchTextBox.Text = SearchText; DebugMsg(string.Format("CallbackSearchCollectionTextBoxSearchKeyUp sText: {0}", SearchText)); DocList = SearchIndex.ExecuteSearchForDocuments( MacroscopeSearchIndex.SearchMode.AND, SearchText.Split(' ') ); this.msDisplaySearchCollection.ClearData(); DebugMsg(string.Format("CallbackSearchCollectionTextBoxSearchKeyUp DocList: {0}", DocList.Count)); this.msDisplaySearchCollection.RefreshData(DocList); } break; case Keys.Escape: DebugMsg(string.Format("CallbackSearchCollectionTextBoxSearchKeyUp: {0}", "ESCAPE")); SearchTextBox.Text = ""; break; default: break; } }
/** Label Event Handlers **************************************************/ protected void CallbackTextBoxLabelTextChanged(object sender, EventArgs e) { TextBox TextBoxObject = ( TextBox )sender; bool IsValid = false; TextBoxObject.Text = MacroscopeStringTools.StripNewLines(Text: TextBoxObject.Text); IsValid = this.ValidateLabel(TextBoxObject: TextBoxObject, ShowErrorDialogue: false); if (IsValid) { TextBoxObject.ForeColor = Color.Green; } else { TextBoxObject.ForeColor = Color.Red; } }
/**************************************************************************/ //[Test] public void TestCleanTextWithHtmlDoc() { Dictionary <string, string> AssetDic = new Dictionary <string, string>(); AssetDic.Add( key: "StringToolsHtmlDoc001", value: "First Heading" ); foreach (string HtmlDocKey in this.HtmlDocs.Keys) { string Html = this.HtmlDocs[HtmlDocKey]; string Cleaned = MacroscopeStringTools.CleanText(Text: Html); DebugMsg(string.Format("HtmlDocKey: {0} :: Value: ||{1}||", HtmlDocKey, Cleaned)); //Assert.IsNotEmpty( ResultList, "WHOOPS!" ); //Assert.AreEqual( AssetDic[ HtmlDocKey ], ResultList[ 0 ].Value ); } }
/**************************************************************************/ public List <KeyValuePair <string, KEYWORD_STATUS> > AnalyzeKeywordPresence(MacroscopeDocument msDoc) { string Keywords = msDoc.GetKeywords().ToLower(); string BodyText = msDoc.GetDocumentTextCleaned().ToLower(); List <string> KeywordsList = new List <string>(); List <KeyValuePair <string, KEYWORD_STATUS> > KeywordPresence = new List <KeyValuePair <string, KEYWORD_STATUS> >(); bool KeywordsMetatagEmpty = false; foreach (string Keyword in Keywords.Split(',')) { string KeywordCleaned = MacroscopeStringTools.CleanWhiteSpace(Keyword); KeywordsList.Add(KeywordCleaned); KeywordsMetatagEmpty = true; } if (KeywordsMetatagEmpty) { foreach (string Keyword in KeywordsList) { string kw = this.GetPatternForLanguage(msDoc: msDoc, Keyword: Keyword); if (Regex.IsMatch(BodyText, kw)) { KeywordPresence.Add(new KeyValuePair <string, KEYWORD_STATUS>(Keyword, KEYWORD_STATUS.PRESENT_IN_BODY_TEXT)); } else { KeywordPresence.Add(new KeyValuePair <string, KEYWORD_STATUS>(Keyword, KEYWORD_STATUS.MISSING_IN_BODY_TEXT)); } } } else { KeywordPresence.Add(new KeyValuePair <string, KEYWORD_STATUS>("", KEYWORD_STATUS.KEYWORDS_METATAG_EMPTY)); } return(KeywordPresence); }
/**************************************************************************/ public List <KeyValuePair <string, KEYWORD_STATUS> > AnalyzeKeywordPresence(MacroscopeDocument msDoc) { string Keywords = msDoc.GetKeywords().ToLower(); string TitleText = msDoc.GetTitle().ToLower(); string DescriptionText = msDoc.GetDescription().ToLower(); string BodyText = msDoc.GetDocumentTextCleaned().ToLower(); List <string> KeywordsList = new List <string>(); List <KeyValuePair <string, KEYWORD_STATUS> > KeywordPresence = new List <KeyValuePair <string, KEYWORD_STATUS> >(); bool KeywordsMetatagFilled = false; foreach (string Keyword in Keywords.Split(',')) { string KeywordCleaned = MacroscopeStringTools.CleanWhiteSpace(Keyword); if (KeywordCleaned.Length > 0) { KeywordsList.Add(KeywordCleaned); KeywordsMetatagFilled = true; } } if (KeywordsMetatagFilled) { foreach (string Keyword in KeywordsList) { try { string kw = this.GetPatternForLanguage(msDoc: msDoc, Keyword: Keyword); if (Regex.IsMatch(TitleText, kw)) { KeywordPresence.Add(new KeyValuePair <string, KEYWORD_STATUS>(Keyword, KEYWORD_STATUS.PRESENT_IN_TITLE)); } else { KeywordPresence.Add(new KeyValuePair <string, KEYWORD_STATUS>(Keyword, KEYWORD_STATUS.MISSING_IN_TITLE)); } if (Regex.IsMatch(DescriptionText, kw)) { KeywordPresence.Add(new KeyValuePair <string, KEYWORD_STATUS>(Keyword, KEYWORD_STATUS.PRESENT_IN_DESCRIPTION)); } else { KeywordPresence.Add(new KeyValuePair <string, KEYWORD_STATUS>(Keyword, KEYWORD_STATUS.MISSING_IN_DESCRIPTION)); } if (Regex.IsMatch(BodyText, kw)) { KeywordPresence.Add(new KeyValuePair <string, KEYWORD_STATUS>(Keyword, KEYWORD_STATUS.PRESENT_IN_BODY)); } else { KeywordPresence.Add(new KeyValuePair <string, KEYWORD_STATUS>(Keyword, KEYWORD_STATUS.MISSING_IN_BODY)); } } catch (Exception ex) { this.DebugMsg(ex.Message); KeywordPresence.Add(new KeyValuePair <string, KEYWORD_STATUS>(Keyword, KEYWORD_STATUS.MALFORMED_KEYWORDS_METATAG)); } } } else { KeywordPresence.Add(new KeyValuePair <string, KEYWORD_STATUS>("", KEYWORD_STATUS.KEYWORDS_METATAG_EMPTY)); } return(KeywordPresence); }