/// <summary> /// Check if content clean of bad words /// </summary> /// <param name="Content"></param> /// <returns>True if content is allowed under policy</returns> public bool isContentAllowed(string Content, BlockPhraseScope scope, out string reason) { string phraseContext = ""; var phrase = findBlockingPhrase(Content, scope, out phraseContext); if (phrase == null) { reason = "content allowed, no phrase found in scope " + scope; return(true); } else { reason = "content blocked because scope <*" + scope + "*> equal phrase <*" + phrase.ToString() + "*>, context: " + phraseContext; return(false); } }
/// <summary> /// Find the phrase that the content is blocked from using. /// </summary> /// <param name="Content">string chunk</param> /// <returns>Null if no phrase rule is applicabalbe (allowed)</returns> public PhraseFilter findBlockingPhrase(string Content, BlockPhraseScope scope, out string context) { PhraseFilter result = null; List <string> Words = getWords(Content); context = ""; for (int i = 0; i < BlockedPhrases.Count && (result == null); i++) { if ( // Any of the scope is ALL scope == BlockPhraseScope.ANY || BlockedPhrases[i].Scope == BlockPhraseScope.ANY // Scopes are equal: || BlockedPhrases[i].Scope == scope ) { switch (BlockedPhrases[i].Type) { case BlockPhraseType.CONTAIN: case BlockPhraseType.REGEX: if (checkPhraseFoundSimple(Content, BlockedPhrases[i], out context)) { result = BlockedPhrases[i]; } break; case BlockPhraseType.EXACTWORD: case BlockPhraseType.WORDCONTAINING: if (checkPhraseFoundWord(Words, BlockedPhrases[i], out context)) { result = BlockedPhrases[i]; } break; } } } return(result); }