Exemple #1
0
        public override BaseResource[] TransformSource(XDocument doc)
        {
            Member   member = new Member();
            XElement seatIncumbencyElement = doc.Element(atom + "entry")
                                             .Element(atom + "content")
                                             .Element(m + "properties");

            ParliamentaryIncumbency incumbency = new ParliamentaryIncumbency();

            incumbency.ParliamentaryIncumbencyStartDate = seatIncumbencyElement.Element(d + "StartDate").GetDate();
            incumbency.ParliamentaryIncumbencyEndDate   = seatIncumbencyElement.Element(d + "EndDate").GetDate();
            string memberId  = seatIncumbencyElement.Element(d + "Member_Id").GetText();
            Uri    memberUri = IdRetrieval.GetSubject("memberMnisId", memberId, false, logger);

            if (memberUri == null)
            {
                logger.Warning($"No member found for {memberId}");
                return(null);
            }
            incumbency.ParliamentaryIncumbencyHasMember = new Member()
            {
                Id = memberUri
            };
            incumbency.CommonsSeatIncumbencyMnisId = seatIncumbencyElement.Element(d + "MemberConstituency_Id").GetText();
            ParliamentPeriod parliamentPeriod = generateSeatIncumbencyParliamentPeriod(incumbency.ParliamentaryIncumbencyStartDate.Value, incumbency.ParliamentaryIncumbencyEndDate);

            if (parliamentPeriod != null)
            {
                incumbency.SeatIncumbencyHasParliamentPeriod = new ParliamentPeriod[] { parliamentPeriod }
            }
            ;

            string constituencyId   = seatIncumbencyElement.Element(d + "Constituency_Id").GetText();
            string houseSeatCommand = @"
        construct {
            ?id a parl:HouseSeat.
        }
        where {
            ?id parl:houseSeatHasConstituencyGroup ?houseSeatHasConstituencyGroup.
            ?houseSeatHasConstituencyGroup parl:constituencyGroupMnisId @constituencyGroupMnisId.
        }";
            SparqlParameterizedString seatSparql = new SparqlParameterizedString(houseSeatCommand);

            seatSparql.Namespaces.AddNamespace("parl", new Uri(schemaNamespace));
            seatSparql.SetLiteral("constituencyGroupMnisId", constituencyId);
            Uri houseSeatUri = IdRetrieval.GetSubject(seatSparql.ToString(), false, logger);

            if (houseSeatUri != null)
            {
                incumbency.SeatIncumbencyHasHouseSeat = new HouseSeat()
                {
                    Id = houseSeatUri
                }
            }
            ;

            return(new BaseResource[] { incumbency });
        }
Exemple #2
0
        public override BaseResource[] TransformSource(JObject jsonResponse)
        {
            ParliamentPeriod parliamentPeriod = new ParliamentPeriod();
            Uri id = giveMeUri(jsonResponse, "TripleStoreId");

            if (id != null)
            {
                parliamentPeriod.Id = id;
            }
            else
            {
                return(null);
            }
            parliamentPeriod.ParliamentPeriodNumber = ((JValue)jsonResponse.SelectToken("parliamentPeriodNumber")).GetFloat();

            string startDate = ((JValue)jsonResponse.SelectToken("parliamentPeriodStartDate")).GetText();

            if (DateTimeOffset.TryParse(startDate, null as IFormatProvider, System.Globalization.DateTimeStyles.AssumeUniversal, out DateTimeOffset startD))
            {
                parliamentPeriod.ParliamentPeriodStartDate = startD;
            }
            else
            {
                logger.Warning($"Startdate with value {startDate} has wrong value.");
                return(null);
            }
            string endDate = ((JValue)jsonResponse.SelectToken("parliamentPeriodEndDate")).GetText();

            if ((string.IsNullOrWhiteSpace(endDate) == false) && (DateTimeOffset.TryParse(endDate, null as IFormatProvider, System.Globalization.DateTimeStyles.AssumeUniversal, out DateTimeOffset endD)))
            {
                parliamentPeriod.ParliamentPeriodEndDate = endD;
            }

            Uri previousId = giveMeUri(jsonResponse, "ImmediatelyPreviousParliamentPer");

            if (previousId != null)
            {
                parliamentPeriod.ParliamentPeriodHasImmediatelyPreviousParliamentPeriod = new ParliamentPeriod()
                {
                    Id = previousId
                }
            }
            ;
            Uri followingId = giveMeUri(jsonResponse, "ImmediatelyFollowingParliamentPe");

            if (followingId != null)
            {
                parliamentPeriod.ParliamentPeriodHasImmediatelyFollowingParliamentPeriod = new ParliamentPeriod[]
                {
                    new ParliamentPeriod()
                    {
                        Id = followingId
                    }
                }
            }
            ;

            WikidataThing wikidataThing = new WikidataThing();

            wikidataThing.Id = id;
            var wikidataId  = ((JValue)jsonResponse.SelectToken("parliamentPeriodWikidataId")).GetText();
            var wikidataUri = new Uri(new Uri("http://www.wikidata.org/entity/"), wikidataId);

            wikidataThing.WikidataThingHasEquivalentWikidataResource = new WikidataResource[]
            {
                new WikidataResource()
                {
                    Id = wikidataUri
                }
            };

            return(new BaseResource[] { parliamentPeriod, wikidataThing });
        }