Example #1
0
        /// <summary>
        /// If its a new property, look up label on Wikidata and add to cache.
        /// </summary>
        /// <param name="qcode"></param>
        /// <returns></returns>
        private string LookupLabel(int qcode)
        {
            WikidataIO IO = new WikidataIO();

            IO.Action    = "wbgetentities";
            IO.Format    = "json";
            IO.Ids       = qcode;
            IO.Props     = "labels";
            IO.Languages = "en|en-gb|ro";
            WikidataFields Fields = new WikidataFields();

            Fields = IO.GetData();

            string Name = "";

            if (!Fields.Labels.TryGetValue("en-gb", out Name))
            {
                if (!Fields.Labels.TryGetValue("en", out Name))
                {
                    Fields.Labels.TryGetValue("en", out Name);
                }
            }

            //using (StreamWriter Sw = File.AppendText(LABELCACHE))
            //{
            //    Sw.WriteLine(qcode);
            //    Sw.WriteLine(Name);
            //}

            //_Cache.Add(qcode, Name);

            return(Name);
        }
Example #2
0
        /// <summary>If its a new property, look up label on Wikidata and add to cache.</summary>
        /// <param name="qcode"></param>
        /// <returns></returns>
        private string LookupLabel( int qcode )
        {
            var io = new WikidataIO {
                Action = "wbgetentities",
                Format = "json",
                Ids = qcode,
                Props = "labels",
                Languages = "en|en-gb|ro"
            };
            var fields = io.GetData();

            string name;
            if ( !fields.Labels.TryGetValue( "en-gb", out name ) ) {
                if ( !fields.Labels.TryGetValue( "en", out name ) ) {
                    fields.Labels.TryGetValue( "en", out name );
                }
            }

            using ( var sw = File.AppendText( this._labelcache ) ) {
                sw.WriteLine( qcode );
                sw.WriteLine( name );
            }

            this._cache[ qcode ] = name;

            return name;
        }
Example #3
0
        /// <summary>If its a new property, look up label on Wikidata and add to cache.</summary>
        /// <param name="qcode"></param>
        /// <returns></returns>
        private string LookupLabel(int qcode)
        {
            var io = new WikidataIO {
                Action    = "wbgetentities",
                Format    = "json",
                Ids       = qcode,
                Props     = "labels",
                Languages = "en|en-gb|ro"
            };
            var fields = io.GetData();

            string name;

            if (!fields.Labels.TryGetValue("en-gb", out name))
            {
                if (!fields.Labels.TryGetValue("en", out name))
                {
                    fields.Labels.TryGetValue("en", out name);
                }
            }

            using (var sw = File.AppendText(this._labelcache)) {
                sw.WriteLine(qcode);
                sw.WriteLine(name);
            }

            this._cache[qcode] = name;

            return(name);
        }
Example #4
0
        private static void Main(string[] args)
        {
            var qcode = 15818798;

            var wio = new WikidataIO {
                Action         = "wbgetentities",
                Format         = "json",
                Sites          = "",
                Ids            = qcode,
                Props          = "claims|descriptions|labels|sitelinks",
                Languages      = "",
                ClaimsRequired = new[] { "P31", "P27", "P21", "P569", "P570" }
            };

            var fields = wio.GetData();

            Console.WriteLine("-----Errors-----");
            var errors = new List <IErrorLog>(wio.GetErrors());

            foreach (var error in errors.Where(thisLog => thisLog != null).SelectMany(thisLog => thisLog.Errors))
            {
                Console.WriteLine(error.ToString());
            }

            if (fields == null)
            {
                return;
            }

            string thisName;

            if (!fields.Labels.TryGetValue("en-gb", out thisName))
            {
                fields.Labels.TryGetValue("en", out thisName);
            }

            string thisDescription;

            if (!fields.Description.TryGetValue("en-gb", out thisDescription))
            {
                fields.Description.TryGetValue("en", out thisDescription);
            }

            string thisWikipedia;

            fields.WikipediaLinks.TryGetValue("enwiki", out thisWikipedia);

            Console.WriteLine(thisName);
            Console.WriteLine(thisDescription);

            Console.WriteLine("====================");

            var wpio = new WikipediaIO {
                Action       = "query",
                Export       = "Yes",
                ExportNoWrap = "Yes",
                Format       = "xml",
                Redirects    = "yes",
                Titles       = thisWikipedia
            };

            if (wpio.GetData())
            {
                var templates  = wpio.TemplatesUsed;
                var categories = wpio.CategoriesUsed;

                Console.WriteLine(wpio.PageTitle);
                Console.WriteLine(templates.Count() + " templates");
                Console.WriteLine(categories.Count() + " categories");
            }

            var errors2 = new List <IErrorLog>(wpio.GetErrors());

            foreach (var error in errors2.Where(thisLog => thisLog != null).SelectMany(thisLog => thisLog.Errors))
            {
                Console.WriteLine(error.ToString());
            }

            Console.WriteLine("Press enter to exit.");
            Console.ReadLine();
        }
Example #5
0
//        SELECT DISTINCT ?ingredient ?ingredientLabel ?unii ?alias WHERE {
// ?ingredient wdt:P652 ?unii.
//           OPTIONAL { ?ingredient skos:altLabel ?alias FILTER (LANG (?alias) = "nl").}
// SERVICE wikibase:label {
//   bd:serviceParam wikibase:language "nl" .}
//}
        static void Main(string[] args)
        {
            int Qcode = 15818798;

            WikidataIO WIO = new WikidataIO();

            WIO.Action         = "wbgetentities";
            WIO.Format         = "json";
            WIO.Sites          = "";
            WIO.Ids            = Qcode;
            WIO.Props          = "claims|descriptions|labels|sitelinks";
            WIO.Languages      = "";
            WIO.ClaimsRequired = new string[5] {
                "P31", "P27", "P21", "P569", "P570"
            };

            WikidataFields Fields = WIO.GetData();

            //Console.WriteLine("-----Errors-----");
            List <ErrorLog> Errors = new List <ErrorLog>();

            Errors = WIO.GetErrors();

            foreach (ErrorLog thisLog in Errors)
            {
                if (thisLog != null)
                {
                    foreach (ErrorMessage Error in thisLog.Errors)
                    {
                        //Console.WriteLine(Error.ToString());
                    }
                }
            }


            if (Fields == null)
            {
                return;
            }

            string ThisName;

            if (!Fields.Labels.TryGetValue("en-gb", out ThisName))
            {
                Fields.Labels.TryGetValue("en", out ThisName);
            }

            string ThisDescription;

            if (!Fields.Description.TryGetValue("en-gb", out ThisDescription))
            {
                Fields.Description.TryGetValue("en", out ThisDescription);
            }

            string ThisWikipedia;

            Fields.WikipediaLinks.TryGetValue("enwiki", out ThisWikipedia);

            //Console.WriteLine(ThisName);
            //Console.WriteLine(ThisDescription);

            //Console.WriteLine("====================");


            WikipediaIO WPIO = new WikipediaIO();

            WPIO.Action       = "query";
            WPIO.Export       = "Yes";
            WPIO.ExportNoWrap = "Yes";
            WPIO.Format       = "xml";
            WPIO.Redirects    = "yes";
            WPIO.Titles       = ThisWikipedia;

            if (WPIO.GetData())
            {
                List <string[]> Templates  = WPIO.TemplatesUsed;
                List <string>   Categories = WPIO.CategoriesUsed;

                //Console.WriteLine(WPIO.PageTitle);
                //Console.WriteLine(Templates.Count().ToString() + " templates");
                //Console.WriteLine(Categories.Count().ToString() + " categories");
            }

            List <ErrorLog> Errors2 = new List <ErrorLog>();

            Errors2 = WPIO.GetErrors();

            foreach (ErrorLog thisLog in Errors2)
            {
                if (thisLog != null)
                {
                    foreach (ErrorMessage Error in thisLog.Errors)
                    {
                        //Console.WriteLine(Error.ToString());
                    }
                }
            }
        }
Example #6
0
        private static void Main( string[] args )
        {
            var qcode = 15818798;

            var wio = new WikidataIO {
                Action = "wbgetentities",
                Format = "json",
                Sites = "",
                Ids = qcode,
                Props = "claims|descriptions|labels|sitelinks",
                Languages = "",
                ClaimsRequired = new[] { "P31", "P27", "P21", "P569", "P570" }
            };

            var fields = wio.GetData();

            Console.WriteLine( "-----Errors-----" );
            var errors = new List<IErrorLog>( wio.GetErrors() );

            foreach ( var error in errors.Where( thisLog => thisLog != null ).SelectMany( thisLog => thisLog.Errors ) ) {
                Console.WriteLine( error.ToString() );
            }

            if ( fields == null ) {
                return;
            }

            string thisName;
            if ( !fields.Labels.TryGetValue( "en-gb", out thisName ) ) {
                fields.Labels.TryGetValue( "en", out thisName );
            }

            string thisDescription;
            if ( !fields.Description.TryGetValue( "en-gb", out thisDescription ) ) {
                fields.Description.TryGetValue( "en", out thisDescription );
            }

            string thisWikipedia;
            fields.WikipediaLinks.TryGetValue( "enwiki", out thisWikipedia );

            Console.WriteLine( thisName );
            Console.WriteLine( thisDescription );

            Console.WriteLine( "====================" );

            var wpio = new WikipediaIO {
                Action = "query",
                Export = "Yes",
                ExportNoWrap = "Yes",
                Format = "xml",
                Redirects = "yes",
                Titles = thisWikipedia
            };

            if ( wpio.GetData() ) {
                var templates = wpio.TemplatesUsed;
                var categories = wpio.CategoriesUsed;

                Console.WriteLine( wpio.PageTitle );
                Console.WriteLine( templates.Count() + " templates" );
                Console.WriteLine( categories.Count() + " categories" );
            }

            var errors2 = new List<IErrorLog>( wpio.GetErrors() );

            foreach ( var error in errors2.Where( thisLog => thisLog != null ).SelectMany( thisLog => thisLog.Errors ) ) {
                Console.WriteLine( error.ToString() );
            }

            Console.WriteLine( "Press enter to exit." );
            Console.ReadLine();
        }