Esempio n. 1
0
        public void Init()
        {
            humanFactory = new HumanFactory();
            var    requestor = WikiDataRequestor.Create();
            string response  = File.ReadAllText(TestFile);

            wikiDataResponse = requestor.ResultFromString(response);
        }
Esempio n. 2
0
        public Human FromWikiDataResponse(WikiDataResponse wikiDataResponse)
        {
            var entity = wikiDataResponse.entities.First().Value;

            Language label;

            if (entity.labels.TryGetValue("en", out label))
            {
                label = entity.labels.First().Value;
            }
            string labelValue = label.value;
            string birthName  = GetClaimValue(entity, WikiDataProperties.BirthName, "text");

            string[]         countryOfCitizenship = GetClaimValues(entity, WikiDataProperties.CountryOfCitizenship, "numeric-id").ToArray();
            string[]         occupation           = GetClaimValues(entity, WikiDataProperties.Occupation, "numeric-id").ToArray();
            NodaTime.Instant?dateOfBirth          = null;
            var dateOfBirthStr = GetClaimValue(entity, WikiDataProperties.DateOfBirth, "time");

            if (dateOfBirthStr != null)
            {
                dateOfBirth = dateOfBirthStr.AsDateTime();
            }
            NodaTime.Instant?dateOfDeath = null;
            var dateOfDeathStr           = GetClaimValue(entity, WikiDataProperties.DateOfDeath, "time");

            if (dateOfDeathStr != null)
            {
                dateOfDeath = dateOfDeathStr.AsDateTime();
            }

            string   url        = null;
            SiteLink enSiteLink = null;

            if (entity.sitelinks.TryGetValue("enwiki", out enSiteLink))
            {
                url = enSiteLink.url;
            }

            var human = new Human(labelValue, birthName, countryOfCitizenship, occupation, dateOfBirth, dateOfDeath, url);

            return(human);
        }