WikiCrawler/Utility/CategoryTranslation.cs
/// <summary>
/// Look for the specified categories. Return the actual categories used.
/// </summary>
Look for the specified categories. Return the actual categories used.
Look for the specified categories . Return the actual categories used .
public static MediaWiki.Article[] TryFetchCategories(MediaWiki.Api api, IList<string> cats)
		{
			for (int i = 0; i < cats.Count; i++)
			{
				cats[i] = MediaWiki.WikiUtils.GetCategoryCategory(cats[i]);
			}
			List<string> requestCats = new List<string>();
			foreach (string inCat in cats)
			{
				if (!s_extantCategories.ContainsKey(inCat))
				{
					requestCats.Add(inCat);
				}
			}
			MediaWiki.Article[] arts = GetCategories(api, requestCats);
			for (int i = 0; i < arts.Length; i++)
			{
				if (arts[i] != null && !arts[i].missing)
				{
					arts[i] = ProcessCategoryRedirects(api, arts[i]);
					s_extantCategories.Add(requestCats[i], arts[i]);
				}
				else
				{
					s_extantCategories.Add(requestCats[i], null);
				}
			}
			MediaWiki.Article[] resultArts = new MediaWiki.Article[cats.Count];
			for (int i = 0; i < cats.Count; i++)
			{
				resultArts[i] = s_extantCategories[cats[i]];
				if (resultArts[i] != null && resultArts[i].missing) resultArts[i] = null;
			}
			return resultArts;
		}
public static MediaWiki . Article [ ] TryFetchCategories ( MediaWiki . Api api , IList < string > cats ) { for ( int i = 0 ; i < cats . Count ; i ++ ) { cats [ i ] = MediaWiki . WikiUtils . GetCategoryCategory ( cats [ i ] ) ; } List < string > requestCats = new List < string > ( ) ; foreach ( string inCat in cats ) { if ( ! s_extantCategories . ContainsKey ( inCat ) ) { requestCats . Add ( inCat ) ; } } MediaWiki . Article [ ] arts = GetCategories ( api , requestCats ) ; for ( int i = 0 ; i < arts . Length ; i ++ ) { if ( arts [ i ] != null && ! arts [ i ] . missing ) { arts [ i ] = ProcessCategoryRedirects ( api , arts [ i ] ) ; s_extantCategories . Add ( requestCats [ i ] , arts [ i ] ) ; } else { s_extantCategories . Add ( requestCats [ i ] , null ) ; } } MediaWiki . Article [ ] resultArts = new MediaWiki . Article [ cats . Count ] ; for ( int i = 0 ; i < cats . Count ; i ++ ) { resultArts [ i ] = s_extantCategories [ cats [ i ] ] ; if ( resultArts [ i ] != null && resultArts [ i ] . missing ) resultArts [ i ] = null ; } return resultArts ; }
Look for the specified categories.
Look for the specified categories .
// preprocess names // don't request cats we already know about // request and map cats // collect the full list (previously- and freshly-mapped ones)
api
MediaWiki.Api
cats
IList<string>