Example #1
0
        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");
                    }
                }
            }
        }
Example #2
0
        /// <summary>
        /// Use of WikiDataQuery - Tested: OK
        /// </summary>
        /// <see cref="http://wdq.wmflabs.org/api_documentation.html"/>
        private void WDQExample()
        {
            string strWDQ = "claim[171:10630160]"; //This is the query

            WikimediaAPI WD         = new WikimediaAPI("https://www.wikidata.org", User, Password);
            Entities     EntityList = new Entities();

            ListGenerator lg     = new ListGenerator();
            List <string> chunks = lg.WDQ(strWDQ, 5);

            foreach (string list in chunks)
            {
                string strJson = WD.LoadWD(list);
                EntityList = new Entities();
                EntityList = JsonConvert.DeserializeObject <Entities>(strJson, new DatavalueConverter());

                // Show Label, Description and Sitelink
                string Text = "";
                string lang = "it";
                foreach (KeyValuePair <string, Entity> entity in EntityList.entities)
                {
                    Text += entity.Value.id;
                    if (entity.Value.labels != null && entity.Value.labels.ContainsKey(lang))
                    {
                        Text += " Label: " + entity.Value.labels[lang].value;
                    }
                    if (entity.Value.descriptions != null && entity.Value.descriptions.ContainsKey(lang))
                    {
                        Text += " Descriptions: " + entity.Value.descriptions[lang].value;
                    }
                    if (entity.Value.sitelinks != null && entity.Value.sitelinks.ContainsKey(lang + "wiki"))
                    {
                        Text += " Sitelink: " + entity.Value.sitelinks[lang].title;
                    }
                    Text += Environment.NewLine;
                }
                txtPageList.AppendText(Text);
                Text = "";
            }
        }