Exemple #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");
                    }
                }
            }
        }
Exemple #2
0
        /// <summary>
        ///
        /// </summary>
        /// <see cref=""/>
        private void CatScanExample()
        {
            WikimediaAPI WD         = new WikimediaAPI("https://www.wikidata.org", User, Password);
            Entities     EntityList = new Entities();

            ListGenerator lg     = new ListGenerator();
            List <string> chunks = lg.CatScan("it", "wikipedia", "Film del 1930|Film del 1931", "", "Film", "", "", ListGenerator.ReturnType.Item);

            foreach (string list in chunks)
            {
                string strJson = WD.LoadWD(list);
                EntityList = new Entities();
                EntityList = JsonConvert.DeserializeObject <Entities>(strJson, new DatavalueConverter());
                // Do something with entity list
            }

            Console.Write(chunks.Count());
        }
Exemple #3
0
        /// <summary>
        /// Use of "Whats links here"  - Tested: OK
        /// </summary>
        private void WhatsLinkExample()
        {
            WikimediaAPI WD         = new WikimediaAPI("https://www.wikidata.org", User, Password);
            Entities     EntityList = new Entities();

            ListGenerator lg = new ListGenerator();

            string[] list = { "", "" };

            do
            {
                list = lg.WhatsLinskHereWDQ("Q877358", WD, list[0]);
                string strJson = WD.LoadWD(list[1]);
                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 + "wiki"].title;
                    }
                    Text += Environment.NewLine;
                }
                txtPageList.AppendText(Text);
                Text = "";
            } while (list[0] != "");
        }
Exemple #4
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 = "";
            }
        }
Exemple #5
0
        /// <summary>
        /// Use of Quick intersection - Tested: OK
        /// </summary>
        /// <see cref="http://tools.wmflabs.org/quick-intersection/index.php"/>

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

            ListGenerator lg     = new ListGenerator();
            List <string> chunks = lg.QuickIntersection("it", "Film del 1930", 0, false, ListGenerator.ReturnType.Item, 10);

            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 + "wiki"].title;
                    }
                    Text += Environment.NewLine;
                }
                txtPageList.AppendText(Text);
                Text = "";
            }
        }