Mercurial > hg > NamedIdentityManager
comparison src/de/mpiwg/itgroup/nimanager/persons/PersonByNameService.java @ 2:e3ecb88314a5
minor bugs
ontologies added
author | dwinter |
---|---|
date | Fri, 02 Dec 2011 08:37:03 +0100 |
parents | 1384a0d382fa |
children | f986e74583eb |
comparison
equal
deleted
inserted
replaced
1:b8333fab0d95 | 2:e3ecb88314a5 |
---|---|
1 package de.mpiwg.itgroup.nimanager.persons; | 1 package de.mpiwg.itgroup.nimanager.persons; |
2 | 2 |
3 import java.io.UnsupportedEncodingException; | 3 import java.io.UnsupportedEncodingException; |
4 import java.net.URLDecoder; | 4 import java.net.URLDecoder; |
5 import java.net.URLEncoder; | |
6 import java.sql.ResultSet; | |
7 import java.sql.SQLException; | 5 import java.sql.SQLException; |
8 import java.util.ArrayList; | 6 import java.util.ArrayList; |
9 import java.util.HashMap; | 7 import java.util.HashMap; |
10 import java.util.List; | 8 import java.util.List; |
11 import java.util.Map; | 9 import java.util.Map; |
13 import org.json.JSONArray; | 11 import org.json.JSONArray; |
14 import org.openrdf.model.Statement; | 12 import org.openrdf.model.Statement; |
15 import org.openrdf.repository.RepositoryException; | 13 import org.openrdf.repository.RepositoryException; |
16 import org.openrdf.repository.RepositoryResult; | 14 import org.openrdf.repository.RepositoryResult; |
17 import org.restlet.Context; | 15 import org.restlet.Context; |
16 import org.restlet.data.ClientInfo; | |
18 import org.restlet.data.Form; | 17 import org.restlet.data.Form; |
19 import org.restlet.data.MediaType; | 18 import org.restlet.data.MediaType; |
20 import org.restlet.data.Status; | 19 import org.restlet.data.Status; |
21 import org.restlet.engine.component.ChildContext; | 20 import org.restlet.engine.component.ChildContext; |
22 import org.restlet.ext.json.JsonRepresentation; | 21 import org.restlet.ext.json.JsonRepresentation; |
25 import org.restlet.resource.Get; | 24 import org.restlet.resource.Get; |
26 import org.restlet.resource.Options; | 25 import org.restlet.resource.Options; |
27 import org.restlet.resource.ServerResource; | 26 import org.restlet.resource.ServerResource; |
28 | 27 |
29 import virtuoso.jdbc4.VirtuosoResultSet; | 28 import virtuoso.jdbc4.VirtuosoResultSet; |
30 | |
31 import de.mpiwg.itgroup.nimanager.exceptions.TripleStoreHandlerException; | 29 import de.mpiwg.itgroup.nimanager.exceptions.TripleStoreHandlerException; |
32 import de.mpiwg.itgroup.nimanager.owl.TripleStoreHandler; | 30 import de.mpiwg.itgroup.nimanager.owl.TripleStoreHandler; |
33 | 31 |
34 public class PersonByNameService extends ServerResource { | 32 public class PersonByNameService extends ServerResource { |
35 | 33 |
89 JSONArray resultsJsonArray = new JSONArray(); | 87 JSONArray resultsJsonArray = new JSONArray(); |
90 try { | 88 try { |
91 String id = (String) getRequest().getAttributes().get("name"); | 89 String id = (String) getRequest().getAttributes().get("name"); |
92 id = URLDecoder.decode(id, "utf-8"); | 90 id = URLDecoder.decode(id, "utf-8"); |
93 String queryPersonWPMD="sparql select DISTINCT * "+ | 91 String queryPersonWPMD="sparql select DISTINCT * "+ |
94 "FROM <file://mpiwg_persons.rdf>"+ | 92 "FROM <"+PERSONS_CONTEXT+"> "+ |
95 "FROM <file://newpersonsFromProjects>"+ | 93 "FROM <file://newpersonsFromProjects>"+ |
96 " FROM <file://personendataWikipedia>"+ | 94 " FROM <file://personendataWikipedia>"+ |
97 " where { " + | 95 " where { " + |
98 "{GRAPH <file://mpiwg_persons.rdf>" + | 96 "{GRAPH <"+PERSONS_CONTEXT+">" + |
99 "{"+ | 97 "{"+ |
100 "?person <"+RELATION_FOR_NAME_SEARCH+"> \""+id+"\"@en."+ | 98 "?person <"+RELATION_FOR_NAME_SEARCH+"> \""+id+"\"@en."+ |
101 " ?ident <http://ontologies.mpiwg-berlin.mpg.de/authorities/namedIdentities/identifies_NamedEntity> ?person."+ | 99 " ?ident <http://ontologies.mpiwg-berlin.mpg.de/authorities/namedIdentities/identifies_NamedEntity> ?person."+ |
102 " OPTIONAL {?wikipedia crm:P1_is_identified_by ?ident.}"+ | 100 " OPTIONAL {?wikipedia crm:P1_is_identified_by ?ident.}"+ |
103 " OPTIONAL {?wikipedia <http://dbpedia.org/ontology/birthDate> ?birthDate.}"+ | 101 " OPTIONAL {?wikipedia <http://dbpedia.org/ontology/birthDate> ?birthDate.}"+ |
160 | 158 |
161 @Get("xml") | 159 @Get("xml") |
162 public Representation getXML() { | 160 public Representation getXML() { |
163 List<MediaType> supported=new ArrayList<MediaType>(); | 161 List<MediaType> supported=new ArrayList<MediaType>(); |
164 supported.add(MediaType.APPLICATION_JSON); | 162 supported.add(MediaType.APPLICATION_JSON); |
165 | 163 |
164 ClientInfo ci = getRequest().getClientInfo(); | |
165 | |
166 if(ci==null){ //don't know why this can happen, but sometimes does | |
167 setStatus(Status.SERVER_ERROR_INTERNAL); | |
168 return null; | |
169 } | |
166 MediaType types = getRequest().getClientInfo().getPreferredMediaType(supported); | 170 MediaType types = getRequest().getClientInfo().getPreferredMediaType(supported); |
167 if (types.equals(MediaType.APPLICATION_JSON)) | 171 if (types.equals(MediaType.APPLICATION_JSON)) |
168 return getJson(); | 172 return getJson(); |
169 | 173 |
170 try { | 174 try { |
203 public Representation getHTML() { | 207 public Representation getHTML() { |
204 | 208 |
205 List<MediaType> supported=new ArrayList<MediaType>(); | 209 List<MediaType> supported=new ArrayList<MediaType>(); |
206 supported.add(MediaType.APPLICATION_JSON); | 210 supported.add(MediaType.APPLICATION_JSON); |
207 | 211 |
208 MediaType types = getRequest().getClientInfo().getPreferredMediaType(supported); | 212 ClientInfo ci = getRequest().getClientInfo(); |
209 if (types.equals(MediaType.APPLICATION_JSON)) | 213 |
210 return getJson(); | 214 if(ci==null){ //don't know why this can happen, but sometimes does |
215 setStatus(Status.SERVER_ERROR_INTERNAL); | |
216 return null; | |
217 } | |
218 MediaType types = ci.getPreferredMediaType(supported); | |
219 if (types!=null) | |
220 if (types.equals(MediaType.APPLICATION_JSON)) | |
221 return getJson(); | |
211 | 222 |
212 Form responseHeaders = (Form) getResponse().getAttributes().get( | 223 Form responseHeaders = (Form) getResponse().getAttributes().get( |
213 "org.restlet.http.headers"); | 224 "org.restlet.http.headers"); |
214 if (responseHeaders == null) { | 225 if (responseHeaders == null) { |
215 responseHeaders = new Form(); | 226 responseHeaders = new Form(); |
223 // RepositoryResult<Statement> statements = th.getStatements(null, | 234 // RepositoryResult<Statement> statements = th.getStatements(null, |
224 // th.createUri(RELATION_FOR_NAME_SEARCH), | 235 // th.createUri(RELATION_FOR_NAME_SEARCH), |
225 // th.createLiteral(id, "en"), PERSONS_CONTEXT); | 236 // th.createLiteral(id, "en"), PERSONS_CONTEXT); |
226 String ret = "<html><body><div id=\"resultNames\">"; | 237 String ret = "<html><body><div id=\"resultNames\">"; |
227 String queryPersonWPMD="sparql select * "+ | 238 String queryPersonWPMD="sparql select * "+ |
228 "FROM <file://mpiwg_persons.rdf>"+ | 239 "FROM <"+PERSONS_CONTEXT+"> "+ |
229 " FROM <file://personendataWikipedia>"+ | 240 " FROM <file://personendataWikipedia>"+ |
230 " where { "+ | 241 " where { "+ |
231 " ?person <"+RELATION_FOR_NAME_SEARCH+"> \""+id+"\"@en."+ | 242 " ?person <"+RELATION_FOR_NAME_SEARCH+"> \""+id+"\"@en."+ |
232 " ?ident <http://ontologies.mpiwg-berlin.mpg.de/authorities/namedIdentities/identifies_NamedEntity> ?person."+ | 243 " ?ident <http://ontologies.mpiwg-berlin.mpg.de/authorities/namedIdentities/identifies_NamedEntity> ?person."+ |
233 " ?wikipedia crm:P1_is_identified_by ?ident."+ | 244 " ?wikipedia crm:P1_is_identified_by ?ident."+ |