changeset 6:290d859f036b

ID search
author dwinter
date Thu, 29 Dec 2011 15:20:37 +0100
parents cdc4c12262b1
children e0aca5ffc4df
files protege.properties src/de/mpiwg/itgroup/nimanager/persons/IDQueryString src/de/mpiwg/itgroup/nimanager/persons/IDQueryStringFull src/de/mpiwg/itgroup/nimanager/persons/IDQueryStringFull_tmp src/de/mpiwg/itgroup/nimanager/persons/PersonByIDService.java src/de/mpiwg/itgroup/nimanager/persons/PersonByNameService.java src/de/mpiwg/itgroup/nimanager/persons/SearchPersonsByIDNoParameterInfo.html src/de/mpiwg/itgroup/nimanager/persons/personQueryString src/de/mpiwg/itgroup/nimanager/persons/personQueryStringFull src/de/mpiwg/itgroup/nimanager/persons/personQueryStringFull_altern
diffstat 10 files changed, 693 insertions(+), 15 deletions(-) [+]
line wrap: on
line diff
--- a/protege.properties	Wed Dec 21 22:10:38 2011 +0100
+++ b/protege.properties	Thu Dec 29 15:20:37 2011 +0100
@@ -1,5 +1,5 @@
 #Protege Properties
-#Thu Jul 14 22:42:24 CEST 2011
+#Wed Dec 21 16:29:30 CET 2011
+history.projects.reopen=file\:/Users/dwinter/Documents/Projekte/ECHO-eSciDoc-MPDL/escidocMPIWG/NamedIdentityManager/examples/newspaper/newspaper.pprj,file\:/Users/dwinter/Documents/Projekte/ECHO-eSciDoc-MPDL/escidocMPIWG/NamedIdentityManager/examples/sqwrl/SQWRLExamples.pprj,file\:/Users/dwinter/Documents/Projekte/ECHO-eSciDoc-MPDL/escidocMPIWG/NamedIdentityManager/examples/pizza/pizza.owl.pprj
 SwitchableClassDefinitionType=edu.stanford.smi.protegex.owl.ui.cls.LogicClassDefinitionWidgetType
-history.projects.reopen=file\:/Users/dwinter/Documents/Projekte/ECHO-eSciDoc-MPDL/escidocMPIWG/NamedIdentityManager/examples/newspaper/newspaper.pprj,file\:/Users/dwinter/Documents/Projekte/ECHO-eSciDoc-MPDL/escidocMPIWG/NamedIdentityManager/examples/sqwrl/SQWRLExamples.pprj,file\:/Users/dwinter/Documents/Projekte/ECHO-eSciDoc-MPDL/escidocMPIWG/NamedIdentityManager/examples/pizza/pizza.owl.pprj
 OntURIBase=http\://www.owl-ontologies.com
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/de/mpiwg/itgroup/nimanager/persons/IDQueryString	Thu Dec 29 15:20:37 2011 +0100
@@ -0,0 +1,21 @@
+sparql
+
+select * 
+FROM <file://mpiwg_persons_dnb.rdf>  
+FROM <file://mpiwg_persons_2.rdf> 
+FROM <file:///GND.rdf> 
+FROM <http://identifiedNames>
+where {
+{?person <http://xmlns.com/foaf/0.1/name> "%s". 
+
+?ident <http://ontologies.mpiwg-berlin.mpg.de/authorities/namedIdentities/identifies_NamedEntity> ?person. 
+?gnd crm:P1_is_identified_by ?ident.
+
+optional {?person2 <http://www.w3.org/2002/07/owl#sameAs> ?person.
+?ident2 <http://ontologies.mpiwg-berlin.mpg.de/authorities/namedIdentities/identifies_NamedEntity> ?person2. 
+?objects crm:P1_is_identified_by ?ident2.}
+
+optional {?gnd <http://RDVocab.info/ElementsGr2/dateOfBirth> ?birthDate.}
+optional {?gnd <http://RDVocab.info/ElementsGr2/dateOfDeath> ?deathDate.} 
+}
+UNION {GRAPH <file://newpersonsFromProjects> {?person <http://xmlns.com/foaf/0.1/name> "%s"}}}
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/de/mpiwg/itgroup/nimanager/persons/IDQueryStringFull	Thu Dec 29 15:20:37 2011 +0100
@@ -0,0 +1,63 @@
+sparql
+
+select distinct * 
+FROM <file://mpiwg_persons_dnb.rdf>  
+FROM <file://mpiwg_persons_2.rdf> 
+FROM <file:///GND.rdf> 
+FROM <http://identifiedNames>
+where {{
+<%s> <http://xmlns.com/foaf/0.1/name> ?name. 
+
+{{?ident <http://ontologies.mpiwg-berlin.mpg.de/authorities/namedIdentities/identifies_NamedEntity> <%s>. 
+
+?gnd crm:P1_is_identified_by ?ident.} UNION {
+?person2 <http://www.w3.org/2002/07/owl#sameAs> <%s>.
+?ident2 <http://ontologies.mpiwg-berlin.mpg.de/authorities/namedIdentities/identifies_NamedEntity> ?person2. 
+?gnd crm:P1_is_identified_by ?ident2.
+}} 
+
+optional {?gnd <http://RDVocab.info/ElementsGr2/dateOfBirth> ?birthDate.}
+optional {?gnd <http://RDVocab.info/ElementsGr2/dateOfDeath> ?deathDate.} 
+
+optional { {?gnd <http://www.w3.org/2002/07/owl#sameAs> ?gndSame.}  UNION
+{?gndSame <http://www.w3.org/2002/07/owl#sameAs> ?gnd.}}
+}
+
+union
+ {
+?person <http://xmlns.com/foaf/0.1/name> ?name. 
+
+{{?ident <http://ontologies.mpiwg-berlin.mpg.de/authorities/namedIdentities/identifies_NamedEntity> ?person. 
+
+<%s> crm:P1_is_identified_by ?ident.} UNION {
+?person2 <http://www.w3.org/2002/07/owl#sameAs> ?person.
+?ident2 <http://ontologies.mpiwg-berlin.mpg.de/authorities/namedIdentities/identifies_NamedEntity> ?person2. 
+?gndSame crm:P1_is_identified_by ?ident2.
+}}
+
+optional {<%s> <http://RDVocab.info/ElementsGr2/dateOfBirth> ?birthDate.}
+optional {<%s> <http://RDVocab.info/ElementsGr2/dateOfDeath> ?deathDate.} 
+
+{ {<%s> <http://www.w3.org/2002/07/owl#sameAs> ?gndSame.}  UNION
+{?gndSame <http://www.w3.org/2002/07/owl#sameAs> 
+<%s>.}}
+}
+union 
+
+{
+?person <http://xmlns.com/foaf/0.1/name> ?name. 
+
+?ident <http://ontologies.mpiwg-berlin.mpg.de/authorities/namedIdentities/identifies_NamedEntity> ?person. 
+?gnd crm:P1_is_identified_by ?ident.
+?person2 <http://www.w3.org/2002/07/owl#sameAs> ?person.
+?ident2 <http://ontologies.mpiwg-berlin.mpg.de/authorities/namedIdentities/identifies_NamedEntity> ?person2. 
+<%s> crm:P1_is_identified_by ?ident2.
+
+
+optional {?gnd <http://RDVocab.info/ElementsGr2/dateOfBirth> ?birthDate.}
+optional {?gnd <http://RDVocab.info/ElementsGr2/dateOfDeath> ?deathDate.} 
+
+optional { {?gnd <http://www.w3.org/2002/07/owl#sameAs> ?gndSame.}  UNION
+{?gndSame <http://www.w3.org/2002/07/owl#sameAs> ?gnd.}}
+}
+}
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/de/mpiwg/itgroup/nimanager/persons/IDQueryStringFull_tmp	Thu Dec 29 15:20:37 2011 +0100
@@ -0,0 +1,63 @@
+sparql
+
+select distinct * 
+FROM <file://mpiwg_persons_dnb.rdf>  
+FROM <file://mpiwg_persons_2.rdf> 
+FROM <file:///GND.rdf> 
+FROM <http://identifiedNames>
+where {{
+<http://ontologies.mpiwg-berlin.mpg.de/authorities/namedIdentities/Person:581130> <http://xmlns.com/foaf/0.1/name> ?name. 
+
+{{?ident <http://ontologies.mpiwg-berlin.mpg.de/authorities/namedIdentities/identifies_NamedEntity> <http://ontologies.mpiwg-berlin.mpg.de/authorities/namedIdentities/Person:581130>. 
+
+?gnd crm:P1_is_identified_by ?ident.} UNION {
+?person2 <http://www.w3.org/2002/07/owl#sameAs> <http://ontologies.mpiwg-berlin.mpg.de/authorities/namedIdentities/Person:581130>.
+?ident2 <http://ontologies.mpiwg-berlin.mpg.de/authorities/namedIdentities/identifies_NamedEntity> ?person2. 
+?gnd crm:P1_is_identified_by ?ident2.
+}} 
+
+optional {?gnd <http://RDVocab.info/ElementsGr2/dateOfBirth> ?birthDate.}
+optional {?gnd <http://RDVocab.info/ElementsGr2/dateOfDeath> ?deathDate.} 
+
+optional { {?gnd <http://www.w3.org/2002/07/owl#sameAs> ?gndSame.}  UNION
+{?gndSame <http://www.w3.org/2002/07/owl#sameAs> ?gnd.}}
+}
+
+union
+ {
+?person <http://xmlns.com/foaf/0.1/name> ?name. 
+
+{{?ident <http://ontologies.mpiwg-berlin.mpg.de/authorities/namedIdentities/identifies_NamedEntity> ?person. 
+
+<http://d-nb.info/gnd/118529579> crm:P1_is_identified_by ?ident.} UNION {
+?person2 <http://www.w3.org/2002/07/owl#sameAs> ?person.
+?ident2 <http://ontologies.mpiwg-berlin.mpg.de/authorities/namedIdentities/identifies_NamedEntity> ?person2. 
+<http://d-nb.info/gnd/118529579> crm:P1_is_identified_by ?ident2.
+}}
+
+optional {<http://d-nb.info/gnd/118529579> <http://RDVocab.info/ElementsGr2/dateOfBirth> ?birthDate.}
+optional {<http://d-nb.info/gnd/118529579> <http://RDVocab.info/ElementsGr2/dateOfDeath> ?deathDate.} 
+
+optional { {<http://d-nb.info/gnd/118529579> <http://www.w3.org/2002/07/owl#sameAs> ?gndSame.}  UNION
+{?gndSame <http://www.w3.org/2002/07/owl#sameAs> 
+<http://d-nb.info/gnd/118529579>.}}
+}
+union 
+
+{
+?person <http://xmlns.com/foaf/0.1/name> ?name. 
+
+?ident <http://ontologies.mpiwg-berlin.mpg.de/authorities/namedIdentities/identifies_NamedEntity> ?person. 
+?gnd crm:P1_is_identified_by ?ident.
+?person2 <http://www.w3.org/2002/07/owl#sameAs> ?person.
+?ident2 <http://ontologies.mpiwg-berlin.mpg.de/authorities/namedIdentities/identifies_NamedEntity> ?person2. 
+<http://dbpedia.org/resource/Albert_Einstein> crm:P1_is_identified_by ?ident2.
+
+
+optional {?gnd <http://RDVocab.info/ElementsGr2/dateOfBirth> ?birthDate.}
+optional {?gnd <http://RDVocab.info/ElementsGr2/dateOfDeath> ?deathDate.} 
+
+optional { {?gnd <http://www.w3.org/2002/07/owl#sameAs> ?gndSame.}  UNION
+{?gndSame <http://www.w3.org/2002/07/owl#sameAs> ?gnd.}}
+}
+}
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/de/mpiwg/itgroup/nimanager/persons/PersonByIDService.java	Thu Dec 29 15:20:37 2011 +0100
@@ -0,0 +1,421 @@
+package de.mpiwg.itgroup.nimanager.persons;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.StringWriter;
+import java.io.UnsupportedEncodingException;
+import java.io.Writer;
+import java.net.URLDecoder;
+import java.sql.SQLException;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.commons.io.IOUtils;
+import org.apache.commons.lang.StringUtils;
+import org.apache.log4j.Logger;
+import org.json.JSONArray;
+import org.openrdf.model.Statement;
+import org.openrdf.repository.RepositoryException;
+import org.openrdf.repository.RepositoryResult;
+import org.restlet.Context;
+import org.restlet.data.ClientInfo;
+import org.restlet.data.Form;
+import org.restlet.data.MediaType;
+import org.restlet.data.Status;
+import org.restlet.engine.component.ChildContext;
+import org.restlet.ext.json.JsonRepresentation;
+import org.restlet.representation.Representation;
+import org.restlet.representation.StringRepresentation;
+import org.restlet.resource.Get;
+import org.restlet.resource.Options;
+import org.restlet.resource.ServerResource;
+
+import de.mpiwg.itgroup.triplestoremanager.exceptions.TripleStoreHandlerException;
+import de.mpiwg.itgroup.triplestoremanager.owl.TripleStoreHandler;
+
+import virtuoso.jdbc4.VirtuosoResultSet;
+
+
+public class PersonByIDService extends ServerResource {
+
+	private String VIRTUOSO_PW;
+	private String VIRTUOSO_USER;
+	private String virtuoso_server_url;
+	private String RELATION_FOR_NAME_SEARCH = "http://xmlns.com/foaf/0.1/name";
+	private String PERSONS_CONTEXT;
+	private TripleStoreHandler th;
+	private Logger logger=Logger.getRootLogger();
+	
+	public PersonByIDService() {
+		ChildContext context = (ChildContext)Context.getCurrent();
+		virtuoso_server_url = context.getParameters().getFirstValue("de.mpwig.itgroup.personSearch.virtuoso.url");
+		VIRTUOSO_PW = context.getParameters().getFirstValue("de.mpwig.itgroup.personSearch.virtuoso.pw");
+		VIRTUOSO_USER = context.getParameters().getFirstValue("de.mpwig.itgroup.personSearch.virtuoso.user");
+		PERSONS_CONTEXT = context.getParameters().getFirstValue("de.mpwig.itgroup.personSearch.virtuoso.personsGraphURI");
+		//th = TripleStoreHandler.getInstance("jdbc:virtuoso://virtuoso.mpiwg-berlin.mpg.de:1111", "dba", "dba");
+		try {
+			th = new TripleStoreHandler(virtuoso_server_url, VIRTUOSO_USER, VIRTUOSO_PW);
+		} catch (TripleStoreHandlerException e) {
+			// TODO Auto-generated catch block
+			e.printStackTrace();
+		}
+	}
+
+	@Options
+	public void doOptions(Representation entity) {
+		Form responseHeaders = (Form) getResponse().getAttributes().get(
+		"org.restlet.http.headers");
+		if (responseHeaders == null) {
+			responseHeaders = new Form();
+			getResponse().getAttributes().put("org.restlet.http.headers",
+					responseHeaders);
+		}
+		responseHeaders.add("Access-Control-Allow-Origin", "*");
+		responseHeaders.add("Access-Control-Allow-Methods", "POST,OPTIONS,GET");
+		responseHeaders.add("Access-Control-Allow-Headers", "Content-Type");
+		responseHeaders.add("Access-Control-Allow-Credentials", "false");
+		responseHeaders.add("Access-Control-Max-Age", "60");
+	}
+
+	public Representation getTest() {
+		return new StringRepresentation("TEST");
+	}
+
+	@Get("json")
+	public Representation getJson() {
+		Form responseHeaders = (Form) getResponse().getAttributes().get(
+		"org.restlet.http.headers");
+		if (responseHeaders == null) {
+			responseHeaders = new Form();
+			getResponse().getAttributes().put("org.restlet.http.headers",
+					responseHeaders);
+		}
+		responseHeaders.add("Access-Control-Allow-Origin", "*");
+
+		JSONArray resultsJsonArray = new JSONArray();
+		try {
+			String id = (String) getRequest().getAttributes().get("name");
+			id = URLDecoder.decode(id, "utf-8");
+
+			//InputStream is = getClass().getResourceAsStream("de/mpiwg/itgroup/nimanager/persons/personQueryString");
+			InputStream is = getClass().getResourceAsStream("IDQueryString");
+			Writer sw = new StringWriter();
+			IOUtils.copy(is, sw,"utf-8");
+
+			String queryPersonWPMD=String.format(sw.toString(), id,id);
+
+			java.sql.Statement smt = th.sqlCon.createStatement();
+
+
+			smt.execute(queryPersonWPMD);
+			VirtuosoResultSet rs = (VirtuosoResultSet) smt.getResultSet();
+			Map<String,String> resultMap = new HashMap<String, String>();
+			while(rs.next()){
+				if (rs.getString("person")!=null){
+					resultMap.put("person",rs.getString("person"));
+				}else  {
+					resultMap.put("person","");
+				}
+				if (rs.getString("objects")!=null){
+					resultMap.put("wikipedia",rs.getString("objects"));
+				} else  {
+					resultMap.put("wikipedia","");
+				}
+				if (rs.getString("gnd")!=null){
+					resultMap.put("gnd",rs.getString("gnd"));
+				} else  {
+					resultMap.put("gnd","");
+				}
+				if (rs.getString("birthDate")!=null){
+					resultMap.put("birthDate",rs.getString("birthDate"));
+				} else {
+					resultMap.put("birthDate","");
+				}
+				if (rs.getString("deathDate")!=null){
+					resultMap.put("deathDate",rs.getString("deathDate"));
+				} else {
+					resultMap.put("deathDate","");
+				}
+				resultMap.put("name",id);
+				resultsJsonArray.put(resultMap);
+			}
+
+			return new JsonRepresentation(resultsJsonArray);
+
+		} catch (UnsupportedEncodingException e) {
+			e.printStackTrace();
+			setStatus(Status.SERVER_ERROR_INTERNAL, "REPOSITORY ERROR");
+			return new JsonRepresentation(new JSONArray());
+
+		} catch (SQLException e) {
+
+			e.printStackTrace();
+			setStatus(Status.SERVER_ERROR_INTERNAL, "REPOSITORY SQL ERROR");
+			return new JsonRepresentation(new JSONArray());
+
+		} catch (IOException e) {
+			// TODO Auto-generated catch block
+			e.printStackTrace();
+			setStatus(Status.SERVER_ERROR_INTERNAL);
+			return new JsonRepresentation(new JSONArray());
+		}
+
+
+	}
+
+	@Get("xml")
+	public Representation getXML() {
+		List<MediaType> supported=new ArrayList<MediaType>();
+		supported.add(MediaType.APPLICATION_JSON);
+
+		ClientInfo ci = getRequest().getClientInfo();
+
+		if(ci==null){ //don't know why this can happen, but sometimes does
+			setStatus(Status.SERVER_ERROR_INTERNAL);
+			return null;
+		}
+		MediaType types = getRequest().getClientInfo().getPreferredMediaType(supported);
+		if (types.equals(MediaType.APPLICATION_JSON))
+			return getJson();
+
+		try {
+			String id = (String) getRequest().getAttributes().get("name");
+			id = URLDecoder.decode(id, "utf-8");
+			RepositoryResult<Statement> statements = th.getStatements(null,
+					th.createUri(RELATION_FOR_NAME_SEARCH),
+					th.createLiteral(id, "en"), PERSONS_CONTEXT);
+			String ret = "<results>";
+			while (statements.hasNext()) {
+				Statement statement = statements.next();
+				ret += "<result subj=\"" + statement.getSubject().stringValue()
+				+ "\"/>";
+			}
+			ret += "</results>";
+
+			return new StringRepresentation(ret, MediaType.TEXT_XML);
+
+		} catch (RepositoryException e) {
+
+			e.printStackTrace();
+			setStatus(Status.SERVER_ERROR_INTERNAL, "REPOSITORY ERROR");
+			return new StringRepresentation(
+					"<xml><error>Repository Error</error></xml>",
+					MediaType.TEXT_XML);
+		} catch (UnsupportedEncodingException e) {
+			e.printStackTrace();
+			setStatus(Status.SERVER_ERROR_INTERNAL, "REPOSITORY ERROR");
+			return new StringRepresentation(
+					"<xml><error>Unsupported encoding</error></xml>",
+					MediaType.TEXT_XML);
+		}
+	}
+
+	@Get("html")
+	public Representation getHTML() {
+
+		List<MediaType> supported=new ArrayList<MediaType>();
+		supported.add(MediaType.APPLICATION_JSON);
+
+		ClientInfo ci = getRequest().getClientInfo();
+
+		if(ci==null){ //don't know why this can happen, but sometimes does
+			setStatus(Status.SERVER_ERROR_INTERNAL);
+			return null;
+		}
+		MediaType types = ci.getPreferredMediaType(supported);
+		if (types!=null)
+			if (types.equals(MediaType.APPLICATION_JSON))
+				return getJson();
+
+		Form responseHeaders = (Form) getResponse().getAttributes().get(
+		"org.restlet.http.headers");
+		if (responseHeaders == null) {
+			responseHeaders = new Form();
+			getResponse().getAttributes().put("org.restlet.http.headers",
+					responseHeaders);
+		}
+		responseHeaders.add("Access-Control-Allow-Origin", "*");
+		try {
+			Form form = getRequest().getResourceRef().getQueryAsForm();
+			
+		
+			String id  =form.getValuesMap().get("id");
+			if (id==null)
+			{
+				InputStream is = getClass().getResourceAsStream("SearchPersonsByIDNoParameterInfo.html");
+				Writer sw = new StringWriter();
+				IOUtils.copy(is, sw,"utf-8");
+				return new StringRepresentation(sw.toString(),MediaType.TEXT_HTML);
+			}
+				
+			id = URLDecoder.decode(id, "utf-8");
+			id=StringUtils.stripEnd(id, null);
+			id=StringUtils.stripStart(id, null);
+			InputStream is = getClass().getResourceAsStream("IDQueryStringFull");
+			Writer sw = new StringWriter();
+			IOUtils.copy(is, sw,"utf-8");
+
+			String queryPersonWPMD=String.format(sw.toString(), id,id,id,id,id,id,id,id,id,id);
+			logger.debug("personIDservice getHTML:"+queryPersonWPMD);
+			java.sql.Statement smt = th.sqlCon.createStatement();
+
+
+			smt.execute(queryPersonWPMD);
+			VirtuosoResultSet rs = (VirtuosoResultSet) smt.getResultSet();
+			
+			
+			String person=id;
+			String bd="";
+			String dd="";
+			String name="";
+			String ret = "";
+			
+			List<String> alternateMPIWGAdresses = new ArrayList<String>();
+			
+			while(rs.next()){
+				
+				String personNew= rs.getString("person"); // setzte Geburtsdatum, falls noch nicht geschehen
+				if (personNew!=null){
+					person=personNew;
+				}
+				
+				String gnd= rs.getString("gnd");
+			
+				String bdNew= rs.getString("birthDate"); // setzte Geburtsdatum, falls noch nicht geschehen
+				if (bdNew!=null && bd.equals("")){
+					bd=bdNew;
+				}
+				String nameNew= rs.getString("name"); // setzte Geburtsdatum, falls noch nicht geschehen
+				if (nameNew!=null && name.equals("")){
+					name=nameNew;
+				}
+				String ddNew= rs.getString("deathDate");  // setzte Todesdatum, falls noch nicht geschehen
+				if (ddNew!=null && dd.equals("")){
+					dd=ddNew;
+				}
+				
+				String person2=rs.getString("person2"); // get alternative MPIWG ID
+				if (person2!=null){
+					alternateMPIWGAdresses.add(person2);
+				}
+				ret+=String.format("<li>external ID:<a href=\"%s\">%s </a></li>",gnd,gnd);
+				
+				String sameID = rs.getString("gndSame");
+				if (sameID!=null){
+					ret+=String.format("<li>external ID: <a href=\"%s\">%s </a></li>",sameID,sameID);
+				}
+			}
+
+			ret = "<html><body><div id=\"resultNames\">"+
+			String.format("<div>%s (%s-%s)</div>",name,bd,dd)+
+			String.format("<div>MPIWG ID:<a href=\"%s\">%s </a></div><ul>",person,person)+
+			ret+
+			"</ul>";
+			if(alternateMPIWGAdresses.size()>0){
+				ret+="<div><div>Alternative MPIWG addresses (don't use)</div><ul>";
+				for (String alt: alternateMPIWGAdresses){
+					ret+=String.format("<li><a href=\"%s\">%s </a></li>",alt,alt);
+				}
+				ret+="</ul></div>";
+			}
+			
+			ret+="</div></body></html>";
+
+			return new StringRepresentation(ret, MediaType.TEXT_HTML);
+
+		} catch (UnsupportedEncodingException e) {
+			e.printStackTrace();
+			setStatus(Status.SERVER_ERROR_INTERNAL, "REPOSITORY ERROR");
+			return new StringRepresentation(
+					"<xml><error>Unsupported encoding</error></xml>",
+					MediaType.TEXT_HTML);
+		} catch (SQLException e) {
+
+			e.printStackTrace();
+			setStatus(Status.SERVER_ERROR_INTERNAL, "REPOSITORY SQL ERROR");
+			return new StringRepresentation(
+					"<xml><error>REPOSITORY SQL ERROR</error></xml>",
+					MediaType.TEXT_HTML);
+		} catch (IOException e) {
+			e.printStackTrace();
+			setStatus(Status.SERVER_ERROR_INTERNAL);
+			return null;
+		}
+	}
+
+	public List<Map<String,String>> getMaps(String id){
+		ArrayList<Map<String, String>> retList = new ArrayList<Map<String,String>>();
+		try {
+
+
+			//InputStream is = getClass().getResourceAsStream("de/mpiwg/itgroup/nimanager/persons/personQueryString");
+			InputStream is = getClass().getResourceAsStream("IDQueryString");
+			Writer sw = new StringWriter();
+			IOUtils.copy(is, sw,"utf-8");
+
+			String queryPersonWPMD=String.format(sw.toString(), id,id);
+
+			java.sql.Statement smt = th.sqlCon.createStatement();
+
+
+			smt.execute(queryPersonWPMD);
+			VirtuosoResultSet rs = (VirtuosoResultSet) smt.getResultSet();
+			Map<String,String> resultMap = new HashMap<String, String>();
+			while(rs.next()){
+				if (rs.getString("person")!=null){
+					resultMap.put("person",rs.getString("person"));
+				}else  {
+					resultMap.put("person","");
+				}
+				if (rs.getString("objects")!=null){
+					resultMap.put("wikipedia",rs.getString("objects"));
+				} else  {
+					resultMap.put("wikipedia","");
+				}
+				if (rs.getString("gnd")!=null){
+					resultMap.put("gnd",rs.getString("gnd"));
+				} else  {
+					resultMap.put("gnd","");
+				}
+				if (rs.getString("birthDate")!=null){
+					resultMap.put("birthDate",rs.getString("birthDate"));
+				} else {
+					resultMap.put("birthDate","");
+				}
+				if (rs.getString("deathDate")!=null){
+					resultMap.put("deathDate",rs.getString("deathDate"));
+				} else {
+					resultMap.put("deathDate","");
+				}
+				resultMap.put("name",id);
+			retList.add(resultMap);	
+			}
+
+		return retList;
+
+		} catch (UnsupportedEncodingException e) {
+			e.printStackTrace();
+			
+			return null;
+
+		} catch (SQLException e) {
+
+			e.printStackTrace();
+			
+			return null;
+
+		} catch (IOException e) {
+			// TODO Auto-generated catch block
+			e.printStackTrace();
+			setStatus(Status.SERVER_ERROR_INTERNAL);
+			return null;
+		}
+
+
+	
+
+	}
+	
+}
--- a/src/de/mpiwg/itgroup/nimanager/persons/PersonByNameService.java	Wed Dec 21 22:10:38 2011 +0100
+++ b/src/de/mpiwg/itgroup/nimanager/persons/PersonByNameService.java	Thu Dec 29 15:20:37 2011 +0100
@@ -101,7 +101,7 @@
 			Writer sw = new StringWriter();
 			IOUtils.copy(is, sw,"utf-8");
 
-			String queryPersonWPMD=String.format(sw.toString(), id);
+			String queryPersonWPMD=String.format(sw.toString(), id,id);
 
 			java.sql.Statement smt = th.sqlCon.createStatement();
 
@@ -238,11 +238,11 @@
 			String id = (String) getRequest().getAttributes().get("name");
 			id = URLDecoder.decode(id, "utf-8");
 			
-			InputStream is = getClass().getResourceAsStream("personQueryString");
+			InputStream is = getClass().getResourceAsStream("personQueryStringFull");
 			Writer sw = new StringWriter();
 			IOUtils.copy(is, sw,"utf-8");
 
-			String queryPersonWPMD=String.format(sw.toString(), id);
+			String queryPersonWPMD=String.format(sw.toString(), id,id);
 
 			java.sql.Statement smt = th.sqlCon.createStatement();
 
@@ -250,18 +250,55 @@
 			smt.execute(queryPersonWPMD);
 			VirtuosoResultSet rs = (VirtuosoResultSet) smt.getResultSet();
 			
-			String ret = "<html><body><div id=\"resultNames\">";
+			
+			String person="";
+			String bd="";
+			String dd="";
+			
+			String ret = "";
+			
+			List<String> alternateMPIWGAdresses = new ArrayList<String>();
+			
 			while(rs.next()){
-				String person= rs.getString("person");
+				person= rs.getString("person");
 				String gnd= rs.getString("gnd");
-				String bd= rs.getString("birthDate");
-				String dd= rs.getString("deathDate");
-
-				ret+=String.format("<div><a href=\"%s\">%s (%s-%s)</a></div>",gnd,id,bd,dd);
-				ret+=String.format("<div><a href=\"%s\">%s </a></div>",person,person);
+				
+			
+				String bdNew= rs.getString("birthDate"); // setzte Geburtsdatum, falls noch nicht geschehen
+				if (bdNew!=null && bd.equals("")){
+					bd=bdNew;
+				}
+				String ddNew= rs.getString("deathDate");  // setzte Todesdatum, falls noch nicht geschehen
+				if (ddNew!=null && dd.equals("")){
+					dd=ddNew;
+				}
+				
+				String person2=rs.getString("person2"); // get alternative MPIWG ID
+				if (person2!=null){
+					alternateMPIWGAdresses.add(person2);
+				}
+				ret+=String.format("<li>external ID:<a href=\"%s\">%s </a></li>",gnd,gnd);
+				
+				String sameID = rs.getString("gndSame");
+				if (sameID!=null){
+					ret+=String.format("<li>external ID: <a href=\"%s\">%s </a></li>",sameID,sameID);
+				}
 			}
 
-			ret += "</div></body></html>";
+			ret = "<html><body><div id=\"resultNames\">"+
+			String.format("<div>%s (%s-%s)</div>",id,bd,dd)+
+			String.format("<div>MPIWG ID:<a href=\"%s\">%s </a></div><ul>",person,person)+
+			ret+
+			"</ul>";
+			if(alternateMPIWGAdresses.size()>0){
+				ret+="<div><div>Alternative MPIWG addresses (don't use)</div><ul>";
+				for (String alt: alternateMPIWGAdresses){
+					ret+=String.format("<li><a href=\"%s\">%s </a></li>",alt,alt);
+				}
+				ret+="</ul></div>";
+			}
+			
+			ret+="</div></body></html>";
 
 			return new StringRepresentation(ret, MediaType.TEXT_HTML);
 
@@ -295,7 +332,7 @@
 			Writer sw = new StringWriter();
 			IOUtils.copy(is, sw,"utf-8");
 
-			String queryPersonWPMD=String.format(sw.toString(), id);
+			String queryPersonWPMD=String.format(sw.toString(), id,id);
 
 			java.sql.Statement smt = th.sqlCon.createStatement();
 
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/de/mpiwg/itgroup/nimanager/persons/SearchPersonsByIDNoParameterInfo.html	Thu Dec 29 15:20:37 2011 +0100
@@ -0,0 +1,23 @@
+<html>
+<head>
+<title>
+NO ID given
+</title></head>
+<body>
+<h2>Search Person by ID</h2>
+<p>You have to supply a parameter <em>id</em>!</p>
+<p>This services searches the MPIWG authority server for id of person names. 
+<p>This can be either
+<ul>
+<li>an MPIWG internal ID e.g. http://ontologies.mpiwg-berlin.mpg.de/authorities/namedIdentities/Person:11195</li>
+<li>an ID from <a href="http://www.d-nb.de/standardisierung/normdateien/gnd.htm"> Gemeinsame Normdatei (GND) of the German National Libary</a> e.g. http://d-nb.info/gnd/118529579 </li>
+<li>an ID from <a href="http://viaf.org">VIAF: Virtual International Authority File</a> e.g. http://viaf.org/viaf/75121530</li>
+<li>an ID from <a href="http://http://dbpedia.org">DBPedia</a> e.g. http://dbpedia.org/resource/Albert_Einstein </li>
+</ul>
+</p>
+<p>Search:
+<form>id: <input type="text" size="100" name="id"/><input type="submit"/></form>
+</p>
+
+</body>
+</html>
\ No newline at end of file
--- a/src/de/mpiwg/itgroup/nimanager/persons/personQueryString	Wed Dec 21 22:10:38 2011 +0100
+++ b/src/de/mpiwg/itgroup/nimanager/persons/personQueryString	Thu Dec 29 15:20:37 2011 +0100
@@ -18,4 +18,4 @@
 optional {?gnd <http://RDVocab.info/ElementsGr2/dateOfBirth> ?birthDate.}
 optional {?gnd <http://RDVocab.info/ElementsGr2/dateOfDeath> ?deathDate.} 
 }
-UNION {GRAPH <file://newpersonsFromProjects> {?person <http://xmlns.com/foaf/0.1/name> "Einstein, Albert"}}}
\ No newline at end of file
+UNION {GRAPH <file://newpersonsFromProjects> {?person <http://xmlns.com/foaf/0.1/name> "%s"}}}
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/de/mpiwg/itgroup/nimanager/persons/personQueryStringFull	Thu Dec 29 15:20:37 2011 +0100
@@ -0,0 +1,24 @@
+sparql
+
+select distinct * 
+FROM <file://mpiwg_persons_dnb.rdf>  
+FROM <file://mpiwg_persons_2.rdf> 
+FROM <file:///GND.rdf> 
+FROM <http://identifiedNames>
+where {{
+?person <http://xmlns.com/foaf/0.1/name> "%s". 
+
+{{?ident <http://ontologies.mpiwg-berlin.mpg.de/authorities/namedIdentities/identifies_NamedEntity> ?person. ?gnd crm:P1_is_identified_by ?ident.} UNION {
+?person2 <http://www.w3.org/2002/07/owl#sameAs> ?person.
+?ident2 <http://ontologies.mpiwg-berlin.mpg.de/authorities/namedIdentities/identifies_NamedEntity> ?person2. 
+?gnd crm:P1_is_identified_by ?ident2.
+}}
+
+optional {?gnd <http://RDVocab.info/ElementsGr2/dateOfBirth> ?birthDate.}
+optional {?gnd <http://RDVocab.info/ElementsGr2/dateOfDeath> ?deathDate.} 
+
+optional { {?gnd <http://www.w3.org/2002/07/owl#sameAs> ?gndSame.}  UNION
+{?gndSame <http://www.w3.org/2002/07/owl#sameAs> ?gnd.}}
+}
+UNION {GRAPH <file://newpersonsFromProjects> {?person <http://xmlns.com/foaf/0.1/name> "%s"}}
+}
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/de/mpiwg/itgroup/nimanager/persons/personQueryStringFull_altern	Thu Dec 29 15:20:37 2011 +0100
@@ -0,0 +1,26 @@
+sparql
+
+select * 
+FROM <file://mpiwg_persons_dnb.rdf>  
+FROM <file://mpiwg_persons_2.rdf> 
+FROM <file:///GND.rdf> 
+FROM <http://identifiedNames>
+where {
+{?person <http://xmlns.com/foaf/0.1/name> "%s". 
+
+?ident <http://ontologies.mpiwg-berlin.mpg.de/authorities/namedIdentities/identifies_NamedEntity> ?person. 
+?gnd crm:P1_is_identified_by ?ident.
+
+optional {?person2 <http://www.w3.org/2002/07/owl#sameAs> ?person.
+?ident2 <http://ontologies.mpiwg-berlin.mpg.de/authorities/namedIdentities/identifies_NamedEntity> ?person2. 
+?objects crm:P1_is_identified_by ?ident2.}
+
+optional {?gnd <http://RDVocab.info/ElementsGr2/dateOfBirth> ?birthDate.}
+optional {?gnd <http://RDVocab.info/ElementsGr2/dateOfDeath> ?deathDate.} 
+
+{ {?gnd <http://www.w3.org/2002/07/owl#sameAs> ?gndSame.}  UNION
+{?gndSame <http://www.w3.org/2002/07/owl#sameAs> ?gnd.} UNION
+{?objects <http://www.w3.org/2002/07/owl#sameAs> ?gndSame.}  UNION
+{?gndSame <http://www.w3.org/2002/07/owl#sameAs> ?objects.}}
+}
+UNION {GRAPH <file://newpersonsFromProjects> {?person <http://xmlns.com/foaf/0.1/name> "%s"}}}
\ No newline at end of file