(* Get Wikipedia articles *) wikiEn[name_String] := ""; maintainWiki := ( Print["Getting Wikipedia data ..."]; textcondit = ((StringLength[#] > 10) &); (* English wiki *) lang = "en"; dirwiki = ToFileName[{dirdata, "wiki", lang}]; checkdir1[dirwiki]; Do[ title = ""; name1 = StringReplace[name, " " -> "_"]; url = "http://" <> lang <> ".wikipedia.org/wiki/" <> name1; file = ToFileName[dirwiki, htmlname[name] <> ".m"]; If[FileType[file] =!= File, filetemp = ToFileName[dirtemp, "wikilookup-" <> lang <> ".htm"]; If[FileType[filetemp] === File, DeleteFile[filetemp]]; {response, text} = urlsave[url, filetemp, textcondit]; Save[file, {response, text}]; ]; Get[file]; If[response[[2]] != 200, nPrint["Warning: URL = ", url, ": bad response: ", response[[2]]], title = StringCases[text, "
"]; content = Table[ par1 = StringReplace[par, RegularExpression["(?i)(?s)
" ~~ WhitespaceCharacter}]; content = Table[ par1 = StringReplace[par, {"
" -> "", "
" -> ""}]; par1 = stringtrim[par1]; par1, {par, content}]; content = Select[content, # =!= "" &]; If[content === {}, Print["Error: content==={}: ", name, " ", lang], wikitext1en[name] = wikitexten[name]]; ]], Print["Warning: file ", filedata, " not found."]; ]; ]; (* If[Head[title] =!= String, *) ]; (* If[response[[2]] != 200, *) (* First paragraph of Wiki *) wikipar = wikitext1en[name]; If[Head[wikipar] === List && wikipar =!= {}, wikiEn[name] = wikipar[[1]]], {name, namesListSort}]; (* MediaWiki's API *) (* Temporary suppress messages like: val::shdw: Symbol val appears in multiple contexts {ChannelFramework`Private`,Global`}; definitions in context ChannelFramework`Private` may shadow or be shadowed by other definitions. *) Off[General::shdw]; dirwikiproperties = ToFileName[{dirdata, "wiki", "properties"}]; checkdir1[dirwikiproperties]; wikipediaProperties = properties = {"ArticlePlaintext", "SummaryPlaintext", "LanguagesURLRules", "TitleTranslationRules"}; Do[ ClearAll[wikipediaData]; file = FileNameJoin[{dirwikiproperties, htmlname[name] <> ".m"}]; If[FileType[file] === File, Get[file], Do[ wikipediaData[name, property] = WikipediaData[name, property], {property, properties}]; Save[file, {properties, wikipediaData}]; ]; (* Currently, only languages-data are used *) a = wikipediaData[name, "LanguagesURLRules"]; b = wikipediaData[name, "TitleTranslationRules"]; wdata = {}; If[MatchQ[a, List[__]] && MatchQ[b, List[__]], a = Transpose[a /. Rule -> List]; b = Transpose[b /. Rule -> List]; langa = a[[1]]; langb = b[[1]]; If[langa === langb, wdata = {a[[1]], a[[2]], b[[2]]} // Transpose; wdata = Union[wdata, SameTest -> (#1[[3]] === #2[[3]] &)]; wdata = Select[wdata, #[[3]] =!= name &]; syns = nameSynonyms[name]; If[Head[syns] === List, wdata = Select[wdata, !MemberQ[syns, #[[3]]]&]], Print["Wikipedia-properties: Warning: ", name, ": mismatch of languages: ", {langa, langb}]]; ]; foreignNames[name] = If[wdata === {}, "", wd = Table[ {lang, link, fname} = wdat; lang <> ": link <> "\">" <> fname <> "", {wdat, wdata}]; StringRiffle[wd, ", "] <> "."], {name, namesListSort}]; On[General::shdw]; );