public virtual void  TestModifyOnUnmodifiable()
        {
            //System.Diagnostics.Debugger.Break();
            CharArraySet set = new CharArraySet(10, true);

            set.AddAll(TEST_STOP_WORDS);
            int size = set.Count;

            set = CharArraySet.UnmodifiableSet(set);

            Assert.AreEqual(size, set.Count, "Set size changed due to UnmodifiableSet call");
            System.String NOT_IN_SET = "SirGallahad";
            Assert.IsFalse(set.Contains(NOT_IN_SET), "Test String already exists in set");

            Assert.Throws <NotSupportedException>(() => set.Add(NOT_IN_SET.ToCharArray()), "Modified unmodifiable set");
            Assert.IsFalse(set.Contains(NOT_IN_SET), "Test String has been added to unmodifiable set");
            Assert.AreEqual(size, set.Count, "Size of unmodifiable set has changed");

            Assert.Throws <NotSupportedException>(() => set.Add(NOT_IN_SET), "Modified unmodifiable set");
            Assert.IsFalse(set.Contains(NOT_IN_SET), "Test String has been added to unmodifiable set");
            Assert.AreEqual(size, set.Count, "Size of unmodifiable set has changed");

            Assert.Throws <NotSupportedException>(() => set.Add(new System.Text.StringBuilder(NOT_IN_SET)), "Modified unmodifiable set");
            Assert.IsFalse(set.Contains(NOT_IN_SET), "Test String has been added to unmodifiable set");
            Assert.AreEqual(size, set.Count, "Size of unmodifiable set has changed");

            Assert.Throws <NotSupportedException>(() => set.Clear(), "Modified unmodifiable set");
            Assert.IsFalse(set.Contains(NOT_IN_SET), "Changed unmodifiable set");
            Assert.AreEqual(size, set.Count, "Size of unmodifiable set has changed");

            Assert.Throws <NotSupportedException>(() => set.Add((object)NOT_IN_SET), "Modified unmodifiable set");
            Assert.IsFalse(set.Contains(NOT_IN_SET), "Test String has been added to unmodifiable set");
            Assert.AreEqual(size, set.Count, "Size of unmodifiable set has changed");

            Assert.Throws <NotSupportedException>(() => set.RemoveAll(new List <string>(TEST_STOP_WORDS)), "Modified unmodifiable set");
            Assert.AreEqual(size, set.Count, "Size of unmodifiable set has changed");

            Assert.Throws <NotSupportedException>(() => set.RetainAll(new List <string>(new[] { NOT_IN_SET })), "Modified unmodifiable set");
            Assert.AreEqual(size, set.Count, "Size of unmodifiable set has changed");

            Assert.Throws <NotSupportedException>(() => set.AddAll(new List <string>(new[] { NOT_IN_SET })), "Modified unmodifiable set");
            Assert.IsFalse(set.Contains(NOT_IN_SET), "Test String has been added to unmodifiable set");

            for (int i = 0; i < TEST_STOP_WORDS.Length; i++)
            {
                Assert.IsTrue(set.Contains(TEST_STOP_WORDS[i]));
            }
        }
示例#2
0
        /// <summary> </summary>
        /// <param name="stopWords">An array of stopwords
        /// </param>
        /// <param name="ignoreCase">If true, all words are lower cased first.
        /// </param>
        /// <returns> a Set containing the words
        /// </returns>
        public static System.Collections.Hashtable MakeStopSet(System.String[] stopWords, bool ignoreCase)
        {
            CharArraySet stopSet = new CharArraySet(stopWords.Length, ignoreCase);

            stopSet.AddAll(new System.Collections.ArrayList(stopWords));
            return(stopSet);
        }
示例#3
0
        /// <summary> </summary>
        /// <param name="stopWords">A List of Strings representing the stopwords
        /// </param>
        /// <param name="ignoreCase">if true, all words are lower cased first
        /// </param>
        /// <returns> A Set containing the words
        /// </returns>
        public static System.Collections.Hashtable MakeStopSet(System.Collections.IList stopWords, bool ignoreCase)
        {
            CharArraySet stopSet = new CharArraySet(stopWords.Count, ignoreCase);

            stopSet.AddAll(stopWords);
            return(stopSet);
        }
        /// <summary></summary>
        /// <param name="stopWords">An array of stopwords</param>
        /// <param name="ignoreCase">If true, all words are lower cased first.</param>
        /// <returns> a Set containing the words</returns>
        public static ISet <string> MakeStopSet(string[] stopWords, bool ignoreCase)
        {
            var stopSet = new CharArraySet(stopWords.Length, ignoreCase);

            stopSet.AddAll(stopWords);
            return(stopSet);
        }
示例#5
0
 static StopAnalyzer()
 {
     {
         var stopWords = new System.String[]{"a", "an", "and", "are", "as", "at", "be", "but", "by", "for", "if", "in", "into", "is", "it", "no", "not", "of", "on", "or", "such", "that", "the", "their", "then", "there", "these", "they", "this", "to", "was", "will", "with"};
         var stopSet = new CharArraySet(stopWords.Length, false);
         stopSet.AddAll(stopWords);
         ENGLISH_STOP_WORDS_SET = CharArraySet.UnmodifiableSet(stopSet);
     }
 }
示例#6
0
 static StopAnalyzer()
 {
     {
         var stopWords = new System.String[] { "a", "an", "and", "are", "as", "at", "be", "but", "by", "for", "if", "in", "into", "is", "it", "no", "not", "of", "on", "or", "such", "that", "the", "their", "then", "there", "these", "they", "this", "to", "was", "will", "with" };
         var stopSet   = new CharArraySet(stopWords.Length, false);
         stopSet.AddAll(stopWords);
         ENGLISH_STOP_WORDS_SET = CharArraySet.UnmodifiableSet(stopSet);
     }
 }
        public virtual void  TestUnmodifiableSet()
        {
            CharArraySet set_Renamed = new CharArraySet(10, true);

            set_Renamed.AddAll(new List <string>(TEST_STOP_WORDS));
            int size = set_Renamed.Count;

            set_Renamed = CharArraySet.UnmodifiableSet(set_Renamed);
            Assert.AreEqual(size, set_Renamed.Count, "Set size changed due to UnmodifiableSet call");

            Assert.Throws <ArgumentNullException>(() => CharArraySet.UnmodifiableSet(null), "can not make null unmodifiable");
        }
        public virtual void  TestUnmodifiableSet()
        {
            CharArraySet set_Renamed = new CharArraySet(10, true);

            set_Renamed.AddAll(new System.Collections.ArrayList(TEST_STOP_WORDS));
            int size = set_Renamed.Count;

            set_Renamed = CharArraySet.UnmodifiableSet(set_Renamed);
            Assert.AreEqual(size, set_Renamed.Count, "Set size changed due to UnmodifiableSet call");

            try
            {
                CharArraySet.UnmodifiableSet(null);
                Assert.Fail("can not make null unmodifiable");
            }
            catch (System.NullReferenceException e)
            {
                // expected
            }
        }
        public virtual void  TestModifyOnUnmodifiable()
        {
            //System.Diagnostics.Debugger.Break();
            CharArraySet set_Renamed = new CharArraySet(10, true);

            set_Renamed.AddAll(TEST_STOP_WORDS);
            int size = set_Renamed.Count;

            set_Renamed = CharArraySet.UnmodifiableSet(set_Renamed);
            Assert.AreEqual(size, set_Renamed.Count, "Set size changed due to UnmodifiableSet call");
            System.String NOT_IN_SET = "SirGallahad";
            Assert.IsFalse(set_Renamed.Contains(NOT_IN_SET), "Test String already exists in set");

            try
            {
                set_Renamed.Add(NOT_IN_SET.ToCharArray());
                Assert.Fail("Modified unmodifiable set");
            }
            catch (System.NotSupportedException e)
            {
                // expected
                Assert.IsFalse(set_Renamed.Contains(NOT_IN_SET), "Test String has been added to unmodifiable set");
                Assert.AreEqual(size, set_Renamed.Count, "Size of unmodifiable set has changed");
            }

            try
            {
                set_Renamed.Add(NOT_IN_SET);
                Assert.Fail("Modified unmodifiable set");
            }
            catch (System.NotSupportedException e)
            {
                // expected
                Assert.IsFalse(set_Renamed.Contains(NOT_IN_SET), "Test String has been added to unmodifiable set");
                Assert.AreEqual(size, set_Renamed.Count, "Size of unmodifiable set has changed");
            }

            try
            {
                set_Renamed.Add(new System.Text.StringBuilder(NOT_IN_SET));
                Assert.Fail("Modified unmodifiable set");
            }
            catch (System.NotSupportedException e)
            {
                // expected
                Assert.IsFalse(set_Renamed.Contains(NOT_IN_SET), "Test String has been added to unmodifiable set");
                Assert.AreEqual(size, set_Renamed.Count, "Size of unmodifiable set has changed");
            }

            try
            {
                set_Renamed.Clear();
                Assert.Fail("Modified unmodifiable set");
            }
            catch (System.NotSupportedException e)
            {
                // expected
                Assert.IsFalse(set_Renamed.Contains(NOT_IN_SET), "Changed unmodifiable set");
                Assert.AreEqual(size, set_Renamed.Count, "Size of unmodifiable set has changed");
            }
            try
            {
                set_Renamed.Add((System.Object)NOT_IN_SET);
                Assert.Fail("Modified unmodifiable set");
            }
            catch (System.NotSupportedException e)
            {
                // expected
                Assert.IsFalse(set_Renamed.Contains(NOT_IN_SET), "Test String has been added to unmodifiable set");
                Assert.AreEqual(size, set_Renamed.Count, "Size of unmodifiable set has changed");
            }
            try
            {
                set_Renamed.RemoveAll(new System.Collections.ArrayList(TEST_STOP_WORDS));
                Assert.Fail("Modified unmodifiable set");
            }
            catch (System.NotSupportedException e)
            {
                // expected
                Assert.AreEqual(size, set_Renamed.Count, "Size of unmodifiable set has changed");
            }

            try
            {
                set_Renamed.RetainAll(new System.Collections.ArrayList(new System.String[] { NOT_IN_SET }));
                Assert.Fail("Modified unmodifiable set");
            }
            catch (System.NotSupportedException e)
            {
                // expected
                Assert.AreEqual(size, set_Renamed.Count, "Size of unmodifiable set has changed");
            }

            try
            {
                set_Renamed.AddAll(new System.Collections.ArrayList(new System.String[] { NOT_IN_SET }));
                Assert.Fail("Modified unmodifiable set");
            }
            catch (System.NotSupportedException e)
            {
                // expected
                Assert.IsFalse(set_Renamed.Contains(NOT_IN_SET), "Test String has been added to unmodifiable set");
            }

            for (int i = 0; i < TEST_STOP_WORDS.Length; i++)
            {
                Assert.IsTrue(set_Renamed.Contains(TEST_STOP_WORDS[i]));
            }
        }
示例#10
0
 /// <summary> </summary>
 /// <param name="stopWords">A List of Strings representing the stopwords
 /// </param>
 /// <param name="ignoreCase">if true, all words are lower cased first
 /// </param>
 /// <returns> A Set containing the words
 /// </returns>
 public static System.Collections.Hashtable MakeStopSet(System.Collections.IList stopWords, bool ignoreCase)
 {
     CharArraySet stopSet = new CharArraySet(stopWords.Count, ignoreCase);
     stopSet.AddAll(stopWords);
     return stopSet;
 }
示例#11
0
 /// <summary> </summary>
 /// <param name="stopWords">An array of stopwords
 /// </param>
 /// <param name="ignoreCase">If true, all words are lower cased first.  
 /// </param>
 /// <returns> a Set containing the words
 /// </returns>
 public static System.Collections.Hashtable MakeStopSet(System.String[] stopWords, bool ignoreCase)
 {
     CharArraySet stopSet = new CharArraySet(stopWords.Length, ignoreCase);
     stopSet.AddAll(new System.Collections.ArrayList(stopWords));
     return stopSet;
 }
		/// <summary></summary>
		/// <param name="stopWords">An array of stopwords</param>
		/// <param name="ignoreCase">If true, all words are lower cased first.</param>
		/// <returns> a Set containing the words</returns>
		public static ISet<string> MakeStopSet(string[] stopWords, bool ignoreCase)
		{
			var stopSet = new CharArraySet(stopWords.Length, ignoreCase);
		    stopSet.AddAll(stopWords);
			return stopSet;
		}
示例#13
0
        public virtual void  TestModifyOnUnmodifiable()
        {
            //System.Diagnostics.Debugger.Break();
            CharArraySet set = new CharArraySet(10, true);
            set.AddAll(TEST_STOP_WORDS);
            int size = set.Count;
            set = CharArraySet.UnmodifiableSet(set);

            Assert.AreEqual(size, set.Count, "Set size changed due to UnmodifiableSet call");
            System.String NOT_IN_SET = "SirGallahad";
            Assert.IsFalse(set.Contains(NOT_IN_SET), "Test String already exists in set");
            
            Assert.Throws<NotSupportedException>(() => set.Add(NOT_IN_SET.ToCharArray()), "Modified unmodifiable set");
            Assert.IsFalse(set.Contains(NOT_IN_SET), "Test String has been added to unmodifiable set");
            Assert.AreEqual(size, set.Count, "Size of unmodifiable set has changed");
            
            Assert.Throws<NotSupportedException>(() => set.Add(NOT_IN_SET), "Modified unmodifiable set");
            Assert.IsFalse(set.Contains(NOT_IN_SET), "Test String has been added to unmodifiable set");
            Assert.AreEqual(size, set.Count, "Size of unmodifiable set has changed");
            
            Assert.Throws<NotSupportedException>(() => set.Add(new System.Text.StringBuilder(NOT_IN_SET)), "Modified unmodifiable set");
            Assert.IsFalse(set.Contains(NOT_IN_SET), "Test String has been added to unmodifiable set");
            Assert.AreEqual(size, set.Count, "Size of unmodifiable set has changed");
            
            Assert.Throws<NotSupportedException>(() => set.Clear(), "Modified unmodifiable set");
            Assert.IsFalse(set.Contains(NOT_IN_SET), "Changed unmodifiable set");
            Assert.AreEqual(size, set.Count, "Size of unmodifiable set has changed");

            Assert.Throws<NotSupportedException>(() => set.Add((object)NOT_IN_SET), "Modified unmodifiable set");
            Assert.IsFalse(set.Contains(NOT_IN_SET), "Test String has been added to unmodifiable set");
            Assert.AreEqual(size, set.Count, "Size of unmodifiable set has changed");

            Assert.Throws<NotSupportedException>(() => set.RemoveAll(new List<string>(TEST_STOP_WORDS)), "Modified unmodifiable set");
            Assert.AreEqual(size, set.Count, "Size of unmodifiable set has changed");
            
            Assert.Throws<NotSupportedException>(() => set.RetainAll(new List<string>(new[] { NOT_IN_SET })), "Modified unmodifiable set");
            Assert.AreEqual(size, set.Count, "Size of unmodifiable set has changed");
            
            Assert.Throws<NotSupportedException>(() => set.AddAll(new List<string>(new[] { NOT_IN_SET })), "Modified unmodifiable set");
            Assert.IsFalse(set.Contains(NOT_IN_SET), "Test String has been added to unmodifiable set");
            
            for (int i = 0; i < TEST_STOP_WORDS.Length; i++)
            {
                Assert.IsTrue(set.Contains(TEST_STOP_WORDS[i]));
            }
        }
示例#14
0
 public virtual void  TestUnmodifiableSet()
 {
     CharArraySet set_Renamed = new CharArraySet(10, true);
     set_Renamed.AddAll(new List<string>(TEST_STOP_WORDS));
     int size = set_Renamed.Count;
     set_Renamed = CharArraySet.UnmodifiableSet(set_Renamed);
     Assert.AreEqual(size, set_Renamed.Count, "Set size changed due to UnmodifiableSet call");
     
     Assert.Throws<ArgumentNullException>(() => CharArraySet.UnmodifiableSet(null), "can not make null unmodifiable");
 }
示例#15
0
		public virtual void  TestUnmodifiableSet()
		{
			CharArraySet set_Renamed = new CharArraySet(10, true);
			set_Renamed.AddAll(new System.Collections.ArrayList(TEST_STOP_WORDS));
			int size = set_Renamed.Count;
			set_Renamed = CharArraySet.UnmodifiableSet(set_Renamed);
			Assert.AreEqual(size, set_Renamed.Count, "Set size changed due to UnmodifiableSet call");
			
			try
			{
				CharArraySet.UnmodifiableSet(null);
				Assert.Fail("can not make null unmodifiable");
			}
			catch (System.NullReferenceException e)
			{
				// expected
			}
		}
示例#16
0
		public virtual void  TestModifyOnUnmodifiable()
		{
            //System.Diagnostics.Debugger.Break();
            CharArraySet set_Renamed = new CharArraySet(10, true);
			set_Renamed.AddAll(TEST_STOP_WORDS);
			int size = set_Renamed.Count;
			set_Renamed = CharArraySet.UnmodifiableSet(set_Renamed);
			Assert.AreEqual(size, set_Renamed.Count, "Set size changed due to UnmodifiableSet call");
			System.String NOT_IN_SET = "SirGallahad";
			Assert.IsFalse(set_Renamed.Contains(NOT_IN_SET), "Test String already exists in set");
			
			try
			{
				set_Renamed.Add(NOT_IN_SET.ToCharArray());
				Assert.Fail("Modified unmodifiable set");
			}
			catch (System.NotSupportedException e)
			{
				// expected
				Assert.IsFalse(set_Renamed.Contains(NOT_IN_SET), "Test String has been added to unmodifiable set");
				Assert.AreEqual(size, set_Renamed.Count, "Size of unmodifiable set has changed");
			}
			
			try
			{
				set_Renamed.Add(NOT_IN_SET);
				Assert.Fail("Modified unmodifiable set");
			}
			catch (System.NotSupportedException e)
			{
				// expected
				Assert.IsFalse(set_Renamed.Contains(NOT_IN_SET), "Test String has been added to unmodifiable set");
				Assert.AreEqual(size, set_Renamed.Count, "Size of unmodifiable set has changed");
			}
			
			try
			{
				set_Renamed.Add(new System.Text.StringBuilder(NOT_IN_SET));
				Assert.Fail("Modified unmodifiable set");
			}
			catch (System.NotSupportedException e)
			{
				// expected
				Assert.IsFalse(set_Renamed.Contains(NOT_IN_SET), "Test String has been added to unmodifiable set");
				Assert.AreEqual(size, set_Renamed.Count, "Size of unmodifiable set has changed");
			}
			
			try
			{
				set_Renamed.Clear();
				Assert.Fail("Modified unmodifiable set");
			}
			catch (System.NotSupportedException e)
			{
				// expected
				Assert.IsFalse(set_Renamed.Contains(NOT_IN_SET), "Changed unmodifiable set");
				Assert.AreEqual(size, set_Renamed.Count, "Size of unmodifiable set has changed");
			}
			try
			{
				set_Renamed.Add((System.Object) NOT_IN_SET);
				Assert.Fail("Modified unmodifiable set");
			}
			catch (System.NotSupportedException e)
			{
				// expected
				Assert.IsFalse(set_Renamed.Contains(NOT_IN_SET), "Test String has been added to unmodifiable set");
				Assert.AreEqual(size, set_Renamed.Count, "Size of unmodifiable set has changed");
			}
			try
			{
				set_Renamed.RemoveAll(new System.Collections.ArrayList(TEST_STOP_WORDS));
				Assert.Fail("Modified unmodifiable set");
			}
			catch (System.NotSupportedException e)
			{
				// expected
				Assert.AreEqual(size, set_Renamed.Count, "Size of unmodifiable set has changed");
			}
			
			try
			{
                set_Renamed.RetainAll(new System.Collections.ArrayList(new System.String[] { NOT_IN_SET }));
				Assert.Fail("Modified unmodifiable set");
			}
			catch (System.NotSupportedException e)
			{
				// expected
				Assert.AreEqual(size, set_Renamed.Count, "Size of unmodifiable set has changed");
			}
			
			try
			{
				set_Renamed.AddAll(new System.Collections.ArrayList(new System.String[] { NOT_IN_SET }));
				Assert.Fail("Modified unmodifiable set");
			}
			catch (System.NotSupportedException e)
			{
				// expected
				Assert.IsFalse(set_Renamed.Contains(NOT_IN_SET), "Test String has been added to unmodifiable set");
			}
			
			for (int i = 0; i < TEST_STOP_WORDS.Length; i++)
			{
				Assert.IsTrue(set_Renamed.Contains(TEST_STOP_WORDS[i]));
			}
		}
示例#17
0
        private static ISet<string> GetStopWords()
        {
            int portalId;
            string cultureCode;

            var searchDoc = Thread.GetData(Thread.GetNamedDataSlot(Constants.TlsSearchInfo)) as SearchDocument;
            if (searchDoc == null)
            {
                portalId = 0; // default
                cultureCode = Thread.CurrentThread.CurrentCulture.Name;
            }
            else
            {
                portalId = searchDoc.PortalId;
                cultureCode = searchDoc.CultureCode;
                if (string.IsNullOrEmpty(cultureCode))
                {
                    var portalInfo = PortalController.Instance.GetPortal(portalId);
                    if (portalInfo != null)
                        cultureCode = portalInfo.DefaultLanguage;
                }
            }

            var stops = StopAnalyzer.ENGLISH_STOP_WORDS_SET;
            var searchStopWords = SearchHelper.Instance.GetSearchStopWords(portalId, cultureCode);

            if (searchStopWords != null && !string.IsNullOrEmpty(searchStopWords.StopWords))
            {
                //TODO Use cache from InternalSearchController
                var strArray = searchStopWords.StopWords.Split(',');
                var set = new CharArraySet(strArray.Length, false);
                set.AddAll(strArray);
                stops = CharArraySet.UnmodifiableSet(set);
            }

            return stops;
        }