private void CompleteExample() { //Wikidata query string strWDQ = "CLAIM[31:24862] AND CLAIM[57] AND BETWEEN[577,+00000001908-00-00T00:00:00Z,+00000001908-12-31T00:00:00Z]"; ListGenerator lg = new ListGenerator(); List <string> chunks = lg.WDQ(strWDQ, 50); //Connection to Wikipedia WikimediaAPI WP = new WikimediaAPI("https://it.wikipedia.org", User, Password); Pages PageList = new Pages(); //Connection to Wikidata WikimediaAPI WD = new WikimediaAPI("https://www.wikidata.org", User, Password); Entities EntityList = new Entities(); Dictionary <string, string> Labels = new Dictionary <string, string>(); foreach (string list in chunks) { // Load all the entity of the chunk string strJson = WD.LoadWD(list); EntityList = new Entities(); EntityList = JsonConvert.DeserializeObject <Entities>(strJson, new DatavalueConverter()); foreach (KeyValuePair <string, Entity> entity in EntityList.entities) { if (entity.Value.sitelinks.ContainsKey("itwiki")) { // Load Wikipage string Pages = WP.LoadWP(entity.Value.sitelinks["itwiki"].title); PageList = JsonConvert.DeserializeObject <Pages>(Pages, new DatavalueConverter()); //Director from template string director = Utility.GetTemplateParameter(PageList.query.FirstPageText, "film", "Regista").Replace("[", "").Replace("]", ""); Labels = new Dictionary <string, string>(); if (director == "") { Labels.Add("en", "1908 short movie"); } else { Labels.Add("en", "1908 short movie directed by " + director); } // Update Wikidata WD.EditEntity(entity.Value.id, null, Labels, null, null, null, "BOT: Update en label"); } } } }
/// <summary> /// Add Label, description, alias, sitelink, claim with qualifier and reference, all datatype. /// </summary> private void EditExample() { string list = "Q938"; WikimediaAPI WD = new WikimediaAPI("https://test.wikidata.org", User, Password); string strJson = WD.LoadWD(list, WikimediaAPI.LoadTypeWD.All); Entities itemList = new Entities(); itemList = JsonConvert.DeserializeObject <Entities>(strJson, new DatavalueConverter()); Entity item = itemList.entities["Q938"]; List <Datavalue> dvList = item.PropertyValue("P245"); WD.SetBadge("Q89", "itwiki", "Q608"); // Edit entity Dictionary <string, string> Labels = new Dictionary <string, string>(); Dictionary <string, string> Descriptions = new Dictionary <string, string>(); Dictionary <string, string> Sitelinks = new Dictionary <string, string>(); Dictionary <string, List <string> > Aliases = new Dictionary <string, List <string> >(); List <Claim> Claims = new List <Claim>(); // To add one or more Label Labels.Add("it", "Label1 IT"); Labels.Add("en", "Label1 EN"); // To add one or more Description Descriptions.Add("it", "Description1 IT"); Descriptions.Add("en", "Description1 EN"); // To add one or more Sitelink Sitelinks.Add("itwiki", "Sandbox"); Sitelinks.Add("enwiki", "Sandbox (computer security)"); // To add one or more Alias List <string> itAlias = new List <string>(); itAlias.Add("Alias1 IT"); itAlias.Add("Alias2 IT"); Aliases.Add("it", itAlias); List <string> enAlias = new List <string>(); enAlias.Add("Alias1 EN"); enAlias.Add("Alias2 EN"); Aliases.Add("en", enAlias); // To add one or more Claim with qualifiers and references Claim claim = new Claim(); claim.mainsnak.property = "P40"; Datavalue dv = new Datavalue(); dv = Utility.CreateDataValue("Stringa", Utility.typeData.String); // for string claim.mainsnak.datavalue = dv; Claims.Add(claim); claim = new Claim(); claim.mainsnak.property = "P40"; dv = Utility.CreateDataValue("Stringa2", Utility.typeData.String); // for string claim.mainsnak.datavalue = dv; Claims.Add(claim); claim = new Claim(); claim.mainsnak.property = "P37"; dv = Utility.CreateDataValue("Q77", Utility.typeData.Item); // for item claim.mainsnak.datavalue = dv; Claims.Add(claim); claim = new Claim(); claim.mainsnak.property = "P285"; dv = Utility.CreateDataValue("it|testo", Utility.typeData.Monolingual); // for monolingual claim.mainsnak.datavalue = dv; Claims.Add(claim); claim = new Claim(); claim.mainsnak.property = "P268"; dv = Utility.CreateDataValue("+00000002013-01-01T00:00:00Z|0|0|0|11", Utility.typeData.Time); // for time claim.mainsnak.datavalue = dv; Claims.Add(claim); claim = new Claim(); claim.mainsnak.property = "P253"; dv = Utility.CreateDataValue("8.10|9.12|0", Utility.typeData.Coordinate); // for coordinate claim.mainsnak.datavalue = dv; Claims.Add(claim); claim = new Claim(); claim.mainsnak.property = "P245"; dv = Utility.CreateDataValue("+10|1|+10|+10", Utility.typeData.Quantity); // for quantity claim.mainsnak.datavalue = dv; Claims.Add(claim); // To add one or more reference List <Reference> refs = new List <Reference>(); Reference reference = new Reference(); List <Snak> snaks = new List <Snak>(); Snak snak = new Snak(); dv = Utility.CreateDataValue("StringaFonte1", Utility.typeData.String); // for string snak.datavalue = dv; snaks.Add(snak); snak = new Snak(); dv = Utility.CreateDataValue("StringaFonte2", Utility.typeData.String); // for string snak.datavalue = dv; snaks.Add(snak); reference.snaks.Add("P40", snaks); refs.Add(reference); //Another ref reference = new Reference(); snaks = new List <Snak>(); snak = new Snak(); dv = Utility.CreateDataValue("it|testo", Utility.typeData.Monolingual); // for monolingual snak.datavalue = dv; snaks.Add(snak); reference.snaks.Add("P285", snaks); refs.Add(reference); claim.references = refs; //To add One or more qualifiers Dictionary <string, List <Qualifier> > qualifiers = new Dictionary <string, List <Qualifier> >(); List <Qualifier> QualList = new List <Qualifier>(); Qualifier qualifier = new Qualifier(); dv = Utility.CreateDataValue("it|testo1", Utility.typeData.Monolingual); // for monolingual qualifier.datavalue = dv; QualList.Add(qualifier); qualifier = new Qualifier(); dv = Utility.CreateDataValue("it|testo2", Utility.typeData.Monolingual); // for monolingual qualifier.datavalue = dv; QualList.Add(qualifier); qualifiers.Add("P285", QualList); QualList = new List <Qualifier>(); qualifier = new Qualifier(); dv = Utility.CreateDataValue("StringaQualificatore", Utility.typeData.String); // for string qualifier.datavalue = dv; QualList.Add(qualifier); qualifiers.Add("P40", QualList); claim.qualifiers = qualifiers; Claims.Add(claim); WD.EditEntity(item.title, Sitelinks, null, Descriptions, Aliases, Claims, "BOT:Test"); }