public static TurnFirstToUpper ( string input ) : string | ||
input | string | |
return | string |
/// <summary> /// Returns Category key from article name e.g. "David Smith" returns "Smith, David". /// special case: "John Doe, Jr." turns into "Doe, Jonn Jr." /// http://en.wikipedia.org/wiki/Wikipedia:Categorization_of_people /// </summary> public static string MakeHumanCatKey(string Name) { Name = RemoveNamespaceString(Regex.Replace(RemoveDiacritics(Name), @"\(.*?\)$", "").Replace("'", "").Trim()).Trim(); string origName = Name; if (!Name.Contains(" ") || Variables.LangCode == LangCodeEnum.uk) { return(origName); } // ukwiki uses "Lastname Firstname Patronymic" convention, nothing more is needed string suffix = ""; int pos = Name.IndexOf(','); // ruwiki has "Lastname, Firstname Patronymic" convention if (pos >= 0 && Variables.LangCode != LangCodeEnum.ru) { suffix = Name.Substring(pos + 1).Trim(); Name = Name.Substring(0, pos).Trim(); } int intLast = Name.LastIndexOf(" ") + 1; string lastName = Name.Substring(intLast).Trim(); Name = Name.Remove(intLast).Trim(); if (IsRomanNumber(lastName)) { if (Name.Contains(" ")) { suffix += lastName; intLast = Name.LastIndexOf(" ") + 1; lastName = Name.Substring(intLast); Name = Name.Remove(intLast).Trim(); } else { //if (Suffix != "") { // We have something like "Peter" "II" "King of Spain" (first/last/suffix), so return what we started with // OR We have "Fred" "II", we don't want to return "II, Fred" so we must return "Fred II" return(origName); } } lastName = Tools.TurnFirstToUpper(lastName.ToLower()); Name = (lastName + ", " + Name + ", " + suffix).Trim(" ,".ToCharArray()); return(Name); }
/// <summary> /// returns /// </summary> /// <param name="title"></param> /// <returns></returns> public static string CanonicalizeTitle(string title) { // visible parts of links may contain crap we shouldn't modify, such as // refs and external links if (title.Contains("[") || title.Contains("{")) { return(title); } string s = Parsers.CanonicalizeTitle(title); if (Variables.UnderscoredTitles.Contains(Tools.TurnFirstToUpper(s))) { return(System.Web.HttpUtility.UrlDecode(title.Replace("+", "%2B")) .Trim(new char[] { '_' })); } return(s); }
// Covered by: NamespaceTests.Determine /// <summary> /// Deduces the namespace number from the input article title. /// </summary> public static int Determine(string articleTitle) { articleTitle = ColonSpace.Replace(articleTitle.Replace("%3A", ":"), ":"); /* if there is a spacing modifying character at the start of the articletitle it will mean the article full name will never contain "Namespace:" * as the colon and modifier will combine to some other Unicode character, so remove any such modifier characters to allow correct derivation */ articleTitle = SpacingModifierLetters.Replace(articleTitle, @"'"); if (!articleTitle.Contains(":")) { return(0); } articleTitle = Tools.TurnFirstToUpper(Tools.WikiDecode(articleTitle)); foreach (KeyValuePair <int, string> k in Variables.Namespaces) { if (articleTitle.StartsWith(k.Value)) { return(articleTitle.Length >= k.Value.Length ? k.Key : 0); } } foreach (KeyValuePair <int, List <string> > k in Variables.NamespaceAliases) { foreach (string s in k.Value) { if (articleTitle.StartsWith(s)) { return(articleTitle.Length >= s.Length ? k.Key : 0); } } } foreach (KeyValuePair <int, string> k in Variables.CanonicalNamespaces) { if (articleTitle.StartsWith(k.Value)) { return(articleTitle.Length >= k.Value.Length ? k.Key : 0); } } return(0); }
// Covered by: NamespaceTests.Determine /// <summary> /// Deduces the namespace number from the input article title. /// </summary> public static int Determine(string articleTitle) { articleTitle = Tools.TurnFirstToUpper(Regex.Replace(articleTitle, @"\s*:\s*", ":")); articleTitle = Tools.WikiDecode(articleTitle); if (!articleTitle.Contains(":")) { return(0); } foreach (KeyValuePair <int, string> k in Variables.Namespaces) { if (articleTitle.StartsWith(k.Value)) { return(articleTitle.Length >= k.Value.Length ? k.Key : 0); } } foreach (KeyValuePair <int, List <string> > k in Variables.NamespaceAliases) { foreach (string s in k.Value) { if (articleTitle.StartsWith(s)) { return(articleTitle.Length >= s.Length ? k.Key : 0); } } } foreach (KeyValuePair <int, string> k in Variables.CanonicalNamespaces) { if (articleTitle.StartsWith(k.Value)) { return(articleTitle.Length >= k.Value.Length ? k.Key : 0); } } return(0); }