WikiCrawler/MediaWiki/WikimediaCategoryTree.cs
/// <summary>
/// Removes any categories from the list that are just less-specific versions of other categories.
/// </summary>
Removes any categories from the list that are just less-specific versions of other categories.
Removes any categories from the list that are just less - specific versions of other categories .
public void RemoveLessSpecific(ISet<string> categories)
		{
			foreach (string s in categories)
				AddToTree(s, 2);
			Queue<string> toCheck = new Queue<string>();
			HashSet<string> alreadyChecked = new HashSet<string>();
			foreach (string s in categories) toCheck.Enqueue(s);
			while (toCheck.Count > 0)
			{
				string checkCat = toCheck.Dequeue();
				if (!s_CategoriesByCategory.ContainsKey(checkCat)) continue;
				List<string> parents = s_CategoriesByCategory[checkCat];
				for (int c = 0; c < parents.Count; c++)
				{
					string cat = parents[c];
					cat = HttpUtility.UrlDecode(cat);
					if (!alreadyChecked.Contains(cat))
					{
						if (categories.Remove(cat))
						{
							Console.WriteLine("Removed less specific cat '" + cat + "'.");
						}
						toCheck.Enqueue(cat);
						alreadyChecked.Add(cat);
					}
				}
			}
		}
public void RemoveLessSpecific ( ISet < string > categories ) { foreach ( string s in categories ) AddToTree ( s , 2 ) ; Queue < string > toCheck = new Queue < string > ( ) ; HashSet < string > alreadyChecked = new HashSet < string > ( ) ; foreach ( string s in categories ) toCheck . Enqueue ( s ) ; while ( toCheck . Count > 0 ) { string checkCat = toCheck . Dequeue ( ) ; if ( ! s_CategoriesByCategory . ContainsKey ( checkCat ) ) continue ; List < string > parents = s_CategoriesByCategory [ checkCat ] ; for ( int c = 0 ; c < parents . Count ; c ++ ) { string cat = parents [ c ] ; cat = HttpUtility . UrlDecode ( cat ) ; if ( ! alreadyChecked . Contains ( cat ) ) { if ( categories . Remove ( cat ) ) { Console . WriteLine ( " " + cat + " " ) ; } toCheck . Enqueue ( cat ) ; alreadyChecked . Add ( cat ) ; } } } }
Removes any categories from the list that are just less-specific versions of other categories.
Removes any categories from the list that are just less - specific versions of other categories .
//queue this cat's parents, and remove them from the source list if they exist
categories
ISet<string>