Ejemplo n.º 1
0
        public void TestToWhereExpression()
        {
            var properties = new HashSet <string> {
                "S1", "S2"
            };
            var keywords = new HashSet <string> {
                "A", "B"
            };

            var set = new HashSet <KeywordFilterTestClass>();

            set.Add(new KeywordFilterTestClass
            {
                S1 = "A",
                S2 = "hello world"
            });

            var expectedList = set;

            var filter = new KeywordFilter <KeywordFilterTestClass>(properties, keywords);

            var where = filter.ToWhereExpression();

            var results = set.Where(where.Compile()).ToList();

            CollectionAssert.AreEqual(expectedList.ToList(), results);
        }
Ejemplo n.º 2
0
        private void applyKeywordButton_Click(object sender, EventArgs e)
        {
            KeywordFilter.FilterMode filterMode = (KeywordFilter.FilterMode)Enum.Parse(typeof(KeywordFilter.FilterMode), this.filterModeComboBox.SelectedItem.ToString());
            KeywordFilter            filter     = new KeywordFilter(this.keywordComboBox.Text, filterMode, this.caseSensitiveCheckBox.Checked, this.columnComboBox.SelectedIndex);

            this.currentKeywordFilter = filter;
            if (filter.InputString == null || filter.InputString.Length == 0)
            {
                this.keywordComboBox.BackColor = System.Drawing.SystemColors.Window;
            }
            else
            {
                this.keywordComboBox.BackColor = Color.LightGreen;
                bool newKeyword = true;
                foreach (Object item in this.keywordComboBox.Items)
                {
                    if (this.keywordComboBox.Text.Equals(item))
                    {
                        newKeyword = false;
                        break;
                    }
                }
                if (newKeyword)
                {
                    this.keywordComboBox.Items.Add(this.keywordComboBox.Text);
                }
            }


            this.BeginUpdateListView?.Invoke(this, EventArgs.Empty);


            if (this.currentKeywordFilter == null || this.currentKeywordFilter.InputString == null || this.currentKeywordFilter.InputString.Length == 0)
            {
                this.ClearItemsCallback();
                this.AddItemRangeCallback(this.UnfilteredList.ToArray());
            }
            else
            {
                try {
                    List <T> itemList = new List <T>();
                    foreach (T item in this.UnfilteredList)
                    {
                        if (this.currentKeywordFilter == null || this.currentKeywordFilter.Matches(item))
                        {
                            itemList.Add(item);
                        }
                    }
                    this.ClearItemsCallback();
                    this.AddItemRangeCallback(itemList.ToArray());
                }
                catch (Exception keywordException) {
                    this.currentKeywordFilter      = null;
                    this.keywordComboBox.BackColor = System.Drawing.SystemColors.Window;
                    //this.AddItemRangeCallback(this.UnfilteredList.ToArray());
                    MessageBox.Show(this, keywordException.Message, "Invalid Keyword Filter");
                }
            }
            this.EndUpdateListView?.Invoke(this, EventArgs.Empty);
        }
Ejemplo n.º 3
0
        public void TestToWhereExpression_CaseInsensitivity()
        {
            var properties = new HashSet <string> {
                "S1", "S2"
            };
            var keywords = new HashSet <string> {
                "A", "b"
            };

            var list = new List <KeywordFilterTestClass>();

            list.Add(new KeywordFilterTestClass
            {
                S1 = "a world",
                S2 = null
            });

            list.Add(new KeywordFilterTestClass
            {
                S1 = null,
                S2 = "B hello"
            });

            var filter = new KeywordFilter <KeywordFilterTestClass>(properties, keywords);

            var where = filter.ToWhereExpression();

            var results = list.Where(where.Compile()).ToList();

            Assert.AreEqual(2, results.Count);
        }
Ejemplo n.º 4
0
 private static void PrepareKeywordFilter(KeywordFilter filter)
 {
     if (!string.IsNullOrEmpty(filter.Value))
     {
         filter.Value = StandardFilter.Apply(filter.Value, true);
     }
 }
Ejemplo n.º 5
0
        public void TestToWhereExpression_NullPropertyValues()
        {
            var properties = new HashSet <string> {
                "S1", "S2"
            };
            var keywords = new HashSet <string> {
                "A", "B"
            };

            var list = new List <KeywordFilterTestClass>();

            list.Add(new KeywordFilterTestClass
            {
                S1 = null,
                S2 = null
            });

            var filter = new KeywordFilter <KeywordFilterTestClass>(properties, keywords);

            var where = filter.ToWhereExpression();

            var results = list.Where(where.Compile()).ToList();

            Assert.AreEqual(0, results.Count);
        }
Ejemplo n.º 6
0
        public void KeywordFilterHalfWordCase()
        {
            var testFilter = new KeywordFilter(new string[] { "are" });

            var resultOut = testFilter.FilterInput("1448470905", "test1", "What about the area around backgate?");

            Assert.That(resultOut[0].Equals(""));
            Assert.That(resultOut[1].Equals(""));
            Assert.That(resultOut[2].Equals(""));
        }
Ejemplo n.º 7
0
        public void KeywordFilterPassCase()
        {
            var testFilter = new KeywordFilter(new string[] { "are" });

            var resultOut = testFilter.FilterInput("1448470905", "test1", "How are you today");

            Assert.That(resultOut[0].Equals("1448470905"));
            Assert.That(resultOut[1].Equals("test1"));
            Assert.That(resultOut[2].Equals("How are you today"));
        }
Ejemplo n.º 8
0
        /// <summary>
        /// 保存关键词
        /// </summary>
        /// <param name="filter"></param>
        /// <returns></returns>
        public static Boolean AddKeywords(KeywordFilter filter)
        {
            ExecuteObject obj = new ExecuteObject();

            obj.tableName = "t_filter";
            obj.cells.Add("关键词", filter.Keyword);
            obj.cells.Add("替换值", filter.ReplaceChar);
            obj.cmdtype = CmdType.INSERT;
            return(db.ExecuteCommand(obj));
        }
Ejemplo n.º 9
0
        public void NoKeywordsThrowsNoKeywordsException()
        {
            var keywordFilter = new KeywordFilter(new string[] { });

            var conversation = new Conversation("conversation", new List <Message>()
            {
                new Message(DateTimeOffset.FromUnixTimeSeconds(1448470901), "senderId", "content")
            });

            Assert.Throws(typeof(NoKeywordsException), () => { keywordFilter.Filter(conversation); });
        }
Ejemplo n.º 10
0
        /// <summary>
        /// 加载关键词代码
        /// </summary>
        /// <returns></returns>
        public static List <KeywordFilter> LoadKeywords()
        {
            List <KeywordFilter> list = new List <KeywordFilter>();
            IDataReader          dr   = db.ExecuteReader("SELECT * FROM [t_filter]");

            while (dr.Read())
            {
                KeywordFilter item = new KeywordFilter();
                item.Keyword     = Convert.ToString(dr["关键词"]);
                item.ReplaceChar = Convert.ToString(dr["替换值"]);
                list.Add(item);
            }
            dr.Close();
            return(list);
        }
Ejemplo n.º 11
0
        /// <summary>
        /// Gets the specified page of keywords.
        /// </summary>
        /// <param name="filter">The filter.</param>
        /// <returns>The page.</returns>
        public DataPage <Keyword> GetKeywords(KeywordFilter filter)
        {
            PrepareKeywordFilter(filter);

            using (var db = GetContext())
            {
                var keywords = db.Keywords.AsQueryable();

                if (!string.IsNullOrEmpty(filter.Language))
                {
                    keywords = keywords.Where(k => k.Language == filter.Language);
                }

                if (!string.IsNullOrEmpty(filter.Value))
                {
                    // filter value for keyword can be language:value
                    int i = filter.Value.IndexOf(':');
                    if (i == 3)
                    {
                        string l = filter.Value.Substring(0, 3);
                        keywords = keywords.Where(k => k.Language == l);
                        if (filter.Value.Length > 4)
                        {
                            string v = filter.Value.Substring(4);
                            keywords = keywords.Where(k => k.Valuex.Contains(v));
                        }
                    }
                    else
                    {
                        keywords = keywords.Where(k => k.Valuex.Contains(filter.Value));
                    }
                }

                int tot = keywords.Count();

                // sort and page
                keywords = keywords.OrderBy(k => k.Language)
                           .ThenBy(k => k.Value)
                           .ThenBy(k => k.Id);
                keywords = keywords.Skip(filter.GetSkipCount()).Take(filter.PageSize);

                return(new DataPage <Keyword>(
                           filter.PageNumber,
                           filter.PageSize,
                           tot,
                           (from k in keywords select EfHelper.GetKeyword(k)).ToList()));
            }
        }
        public void FilterTestKeyWord()
        {
            var messages   = new List <Message>();
            var messageOne = new Message(DateTimeOffset.FromUnixTimeSeconds(Convert.ToInt64("1448470901")), "stan", "i tested stringone");

            messages.Add(messageOne);
            var messageTwo = new Message(DateTimeOffset.FromUnixTimeSeconds(Convert.ToInt64("1448470901")), "bob", "i tested stringtwo");

            messages.Add(messageTwo);

            var conversation  = new Conversation("test", messages);
            var keywordFilter = new KeywordFilter("stringtwo");

            keywordFilter.ApplyFilter(conversation);

            var filteredMessages = conversation.messages.ToList();

            Assert.That(filteredMessages[0].content, Is.EqualTo("i tested stringtwo"));
        }
Ejemplo n.º 13
0
        public void FilteringKeywordFiltersKeyword()
        {
            var keywordsToTest = new string[] { "thanks" };

            var keywordFilter = new KeywordFilter(keywordsToTest);

            Assert.That(_dummyConversation.name, Is.EqualTo("Dummy Conversation"));

            var filteredConversation = keywordFilter.Filter(_dummyConversation);

            var filteredMessages = filteredConversation.messages.ToList();

            Assert.That(filteredMessages.Count == 2);

            Assert.That(filteredMessages[0].senderId, Is.EqualTo("MindLink"));
            Assert.That(filteredMessages[0].content, Is.EqualTo("Many thanks! The recruitment team will review your test submission and get back to you with feedback."));

            Assert.That(filteredMessages[1].senderId, Is.EqualTo("Patrick"));
            Assert.That(filteredMessages[1].content, Is.EqualTo("Okay thanks, working on it!"));
        }
Ejemplo n.º 14
0
        public void TestToWhereExpression_NotAStringProperty()
        {
            var properties = new HashSet <string> {
                "Id"
            };
            var keywords = new HashSet <string> {
                "1"
            };

            var list = new List <KeywordFilterTestClass>();

            list.Add(new KeywordFilterTestClass
            {
                Id = 1
            });

            var filter = new KeywordFilter <KeywordFilterTestClass>(properties, keywords);

            var where = filter.ToWhereExpression();
        }
Ejemplo n.º 15
0
        /// <summary>
        /// Exports the conversation at <paramref name="inputFilePath"/> as JSON to <paramref name="outputFilePath"/>.
        /// </summary>
        /// <param name="inputFilePath">
        /// The input file path.
        /// </param>
        /// <param name="outputFilePath">
        /// The output file path.
        /// </param>
        /// <exception cref="ArgumentException">
        /// Thrown when a path is invalid.
        /// </exception>
        /// <exception cref="Exception">
        /// Thrown when something bad happens.
        /// </exception>

        public void ExportConversation(ConversationExporterConfiguration exporterConfiguration)
        {
            var          filters    = new List <BaseFilter>();
            var          blacklists = new List <IBlacklist>();
            Conversation conversation;

            if (exporterConfiguration.filterByUser != null)
            {
                var userFilter = new UserFilter(new string[] { exporterConfiguration.filterByUser });
                filters.Add(userFilter);
            }

            if (exporterConfiguration.filterByKeyword != null)
            {
                var keywordFilter = new KeywordFilter(new string[] { exporterConfiguration.filterByKeyword });
                filters.Add(keywordFilter);
            }

            if (exporterConfiguration.blacklist != null)
            {
                var blacklistWords = exporterConfiguration.blacklist.Split(',');
                blacklists.Add(new KeywordBlacklist(blacklistWords, "*redacted*"));
            }

            if (exporterConfiguration.generateReport)
            {
                conversation = this.ReadConversation(exporterConfiguration.InputFilePath, filters.ToArray(), blacklists.ToArray(), true);
            }
            else
            {
                conversation = this.ReadConversation(exporterConfiguration.InputFilePath, filters.ToArray(), blacklists.ToArray());
            }

            this.WriteConversation(conversation, exporterConfiguration.OutputFilePath);

            Console.WriteLine("Conversation exported from '{0}' to '{1}'", exporterConfiguration.InputFilePath, exporterConfiguration.OutputFilePath);
        }
Ejemplo n.º 16
0
        public void NullConversationThrowsArgumentNullException()
        {
            var keywordFilter = new KeywordFilter(new string[] { "thanks" });

            Assert.Throws(typeof(ArgumentNullException), () => { keywordFilter.Filter(null); });
        }
Ejemplo n.º 17
0
 public List <Keyword> GetByFilter(KeywordFilter filter)
 {
     return(servicosDeKeywords.GetByFilter(filter.Descricao));
 }
Ejemplo n.º 18
0
 /// <include file='doc\AdRotator.uex' path='docs/doc[@for="AdRotator.MatchingAd"]/*' />
 /// <devdoc>
 ///   Used to determine if the advertisement meets current criteria. Does a comparison with
 ///   KeywordFilter if it is set.
 /// </devdoc>
 private bool MatchingAd(AdRec ad)
 {
     // do a lower case comparison
     return(KeywordFilter == string.Empty ||
            (KeywordFilter.ToLower(CultureInfo.InvariantCulture) == ad.keyword.ToLower(CultureInfo.InvariantCulture)));
 }