/// <summary> /// Gets all information avalible for the person with the given URI /// </summary> /// <param name="librisId">Unique URI from Libris</param> /// <returns>a Person object filld with data from Libris</returns> public Person GetPerson(String librisId) { SparqlRemoteEndpoint endpoint = new SparqlRemoteEndpoint(new Uri(URI)); SparqlResultSet results = endpoint.QueryWithResultSet( " PREFIX foaf: <http://xmlns.com/foaf/0.1/> " + " PREFIX date: <http://dbpedia.org/property/> " + " PREFIX links: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> " + " select ?name ?birth ?death ?links where{<" + librisId + "> foaf:name ?name." + "OPTIONAL {<" + librisId + "> date:birthYear ?birth." + "}OPTIONAL {<" + librisId + "> date:deathYear ?death." + " }}"); Person person = new Person(); foreach (SparqlResult result in results) { if (result.Value("name") != null) { person.Name = result.Value("name").ToString(); } if (result.Value("birth") != null) { person.BirthYear = result.Value("birth").ToString(); } if (result.Value("death") != null) { person.DeathYear = result.Value("death").ToString(); } } person.URI = librisId; person.AddListOfExternalEntitie(GetListOfBooksAbout(librisId)); person.AddListOfExternalEntitie(GetListOfBooksBy(librisId)); return person; }
/// <summary> /// Gets information about a person given the URI /// </summary> /// <param name="uri">The Unique URI for a person</param> /// <returns>a person object with data added</returns> public Person GetPersonByURI(String uri) { Person person = new Person(); //Endast för test Gunnar Asplund person.URI = "http://kulturarvsdata.se/raa/bbrp/21600000003542"; SparqlRemoteEndpoint endpoint = new SparqlRemoteEndpoint(new Uri(URI)); SparqlResultSet results = endpoint.QueryWithResultSet( "prefix ksamsok: <http://kulturarvsdata.se/ksamsok#>" + "prefix wiki: <http://kulturarvsdata.se/ugc#>" + "PREFIX foaf: <http://xmlns.com/foaf/0.1/>" + "select ?name ?wikiLink ?image ?born ?death" + "where{" + "<" + uri + "> foaf:fullName ?name." + "optional{<" + uri + "> wiki:sameAsWikipedia ?wikiLink}" + "optional{<" + uri + "> ksamsok:isVisualizedBy ?image}" + "}"); person.URI = uri; foreach (SparqlResult result in results) { if (result.Value("name") != null) { person.Name = result.Value("name").ToString(); } if (result.Value("wikiLink") != null) { person.WikipediaLink = result.Value("wikiLink").ToString(); } if (result.Value("image") != null) { person.SetImageUrl(result.Value("image").ToString()); } person = GetBirthAndDeathYear(person); } person.AddListOfExternalEntitie(GetListOfHouses(person.URI)); return person; }
/// <summary> /// Gets a list of person objects where the name matches the param /// </summary> /// <param name="fullName">Name of the person</param> /// <returns>A list with all persons with the given name</returns> public List<Person> GetPersons(String fullName) { SparqlRemoteEndpoint endpoint = new SparqlRemoteEndpoint(new Uri(URI)); SparqlResultSet results = endpoint.QueryWithResultSet( "PREFIX date: <http://dbpedia.org/property/> " + "PREFIX foaf: <http://xmlns.com/foaf/0.1/> " + "select ?a ?birth ?death where{" + "?a foaf:name" + "'" + fullName + "'" + ". " + "OPTIONAL {" + "?a date:birthYear ?birth." + "}OPTIONAL {" + "?a date:deathYear ?death." + "}}"); List<Person> listOfPersons = new List<Person>(); foreach (SparqlResult result in results) { Person person = new Person { Name = fullName }; if (result.Value("a") != null) { person.URI = result.Value("a").ToString(); } if (result.Value("birth") != null) { person.BirthYear = result.Value("birth").ToString(); } if (result.Value("death") != null) { person.DeathYear = result.Value("death").ToString(); } person.AddListOfExternalEntitie(GetListOfBooksAbout(person.URI)); person.AddListOfExternalEntitie(GetListOfBooksBy(person.URI)); listOfPersons.Add(person); } return listOfPersons; }