//  Copyright 2008, 2009 DBIS Research Group at Humboldt-Universität zu Berlin
//
//  This file is part of Researchers Map.
//
//  Researchers Map is free software: you can redistribute it and/or modify
//  it under the terms of the GNU General Public License as published by
//  the Free Software Foundation, either version 3 of the License, or
//  (at your option) any later version.
//
//  Researchers Map is distributed in the hope that it will be useful,
//  but WITHOUT ANY WARRANTY; without even the implied warranty of
//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
//  GNU General Public License for more details.
//
//  You should have received a copy of the GNU General Public License
//  along with Researchers Map.  If not, see <http://www.gnu.org/licenses/>.

// File: queries.js
// Author: Hannes Mühleisen

// Queries all Positions for map
var mapquery = ' \
	PREFIX foaf: <http://xmlns.com/foaf/0.1/> \
	PREFIX contact: <http://www.w3.org/2000/10/swap/pim/contact#> \
	PREFIX geo: <http://www.w3.org/2003/01/geo/wgs84_pos#> \
	\
	SELECT DISTINCT ?prof ?name1 ?name2 ?lat ?long ?city ?street \
	WHERE { \
		?prof a <http://researchersmap.informatik.hu-berlin.de/data/dbprofs#DBProfessor> \
	\
		OPTIONAL { ?prof foaf:name ?name1 } \
		OPTIONAL { ?prof contact:fullName ?name2 } \
		FILTER ( BOUND(?name1) || BOUND(?name2) ) \
	\
		OPTIONAL { ?prof foaf:based_near [ geo:lat ?lat ; geo:long ?long ] } \
		OPTIONAL { ?prof contact:office [ contact:address \
			[ contact:street ?street ; contact:city ?city ] ] } \
		FILTER ( (BOUND(?lat) && BOUND(?long)) || BOUND(?street) ) \
		} \
	';
	
// Queries people with matching interests, DBFILTER gets replaced
var filterquery = '															\
	PREFIX foaf: <http://xmlns.com/foaf/0.1/>								\
	PREFIX contact: <http://www.w3.org/2000/10/swap/pim/contact#>			\
	PREFIX geo: <http://www.w3.org/2003/01/geo/wgs84_pos#>					\
																			\
	SELECT DISTINCT ?prof ?name1 ?name2 ?lat ?long ?city ?street						\
		WHERE {																\
			?prof a <http://researchersmap.informatik.hu-berlin.de/data/dbprofs#DBProfessor> ;	\
			       foaf:topic_interest ?i .									\
			FILTER (DBFILTER)												\
																			\
			OPTIONAL { ?prof foaf:name ?name1 }								\
			OPTIONAL { ?prof contact:fullName ?name2 }						\
			FILTER ( BOUND(?name1) || BOUND(?name2) )						\
																			\
			OPTIONAL { ?prof foaf:based_near [ geo:lat ?lat ; geo:long ?long ] }	\
			OPTIONAL { ?prof contact:office [ contact:address [ contact:street ?street ; \
			                                                    contact:city ?city ] ] } \
			FILTER ( (BOUND(?lat) && BOUND(?long)) || BOUND(?street) )		\
		}																	\
';

// Queries all research areas
var researchquery = '														\
	PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>					\
	PREFIX foaf: <http://xmlns.com/foaf/0.1/>								\
																			\
	SELECT DISTINCT ?i ?label WHERE {										\
 		?prof a <http://researchersmap.informatik.hu-berlin.de/data/dbprofs#DBProfessor> ;	\
       		foaf:topic_interest ?i .										\
       																		\
	 	OPTIONAL {															\
	   		?i rdfs:label ?label											\
	   		FILTER ( LANG(?label) = "en" || LANG(?label) = "" )				\
	 	}																	\
	}																		\
	ORDER BY ?label															\
';

// Queries for all data about a prof, DBPROF gets replaced
var alldataquery = ' \
	PREFIX owl:  <http://www.w3.org/2002/07/owl#> \
	PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> \
	\
	SELECT DISTINCT ?s ?p ?pLabel ?o WHERE { \
	  { \
	    { <DBPROF> ?p ?o } \
	    UNION \
	    { <DBPROF> owl:sameAs [ ?p ?o ] } \
	  } \
	  UNION \
	  { \
	    { ?s ?p <DBPROF> } \
	    UNION \
	    { <DBPROF> owl:sameAs ?sameProf . ?s ?p ?sameProf . } \
	  } \
	\
	  OPTIONAL { ?p rdfs:label ?pLabel } \
	} \
	ORDER BY ?pLabel \
';


// Queries all publications, DBPROF gets replaced
var pubquery = '															\
	PREFIX rdf:  <http://www.w3.org/1999/02/22-rdf-syntax-ns#>				\
	PREFIX owl:  <http://www.w3.org/2002/07/owl#>							\
	PREFIX foaf: <http://xmlns.com/foaf/0.1/>								\
	PREFIX swrc: <http://swrc.ontoware.org/ontology#>						\
	PREFIX dc:   <http://purl.org/dc/elements/1.1/>							\
	PREFIX dcterms: <http://purl.org/dc/terms/>								\
																			\
	SELECT DISTINCT ?title ?pub ?year										\
	WHERE {																	\
		<DBPROF> owl:sameAs ?sameProf .										\
		?pub foaf:maker ?sameProf ;											\
		     rdf:type ?pubType ;											\
		     dc:title ?title .												\
		 FILTER ( ?pubType = swrc:InProceedings 							\
		 	|| ?pubType = swrc:Book 										\
		 	|| ?pubType = swrc:Article )									\
		OPTIONAL { ?pub dcterms:issued ?year }								\
	}																		\
	ORDER BY DESC(?year)													\
';
