<?php
error_reporting(E_ALL);
ini_set('display_errors', 1);
require_once(dirname(__FILE__).'/lib/endpoint.php');

/***** Configuration Settings *****/
/*** ARC2 settings ***/
$config['arc'] = array(
    'remote_store_endpoint' => 'http://linguistic.linkeddata.es/sparql',
    'default-graph-uri' =>'http://linguistic.linkeddata.es/graph/terminesp/',
    'endpoint_features' => array(
        'select', 'construct', 'ask', 'describe', // allow read
        //'load', 'insert', 'delete',             // disallow update
        //'dump'                                  // disallow backup
    ),
    /*'endpoint_max_limit' => 2000,  optional */
    'passthrough_sparqlxml' => true
);

/*** end of ARC2 settings ***/

/*** Sample query settings ***/
/* add any number of these, will be listed above query form, or remove to
 * hide sample queries altogether
 */
$name = '"Give me available translations for the term "red" in Spanish"';
$query = <<<QUERY_END
# Query that retrieves all available translations for the term "red" in Spanish

PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX skos: <http://www.w3.org/2004/02/skos/core#>
PREFIX lemon: <http://www.lemon-model.net/lemon#>
PREFIX translation: <http://purl.org/net/translation#>
PREFIX tr_cat: <http://purl.org/net/translation-categories#>

SELECT DISTINCT ?translation ?tr_category 
                ?lex_entry_source ?wr_source 
                ?lexicon_source ?lex_entry_target 
                ?wr_target ?lexicon_target 
WHERE {
  
  # retrieve "red" term
  ?lex_entry_source rdf:type lemon:LexicalEntry .
  ?lexicon_source a lemon:Lexicon .
  ?lexicon_source lemon:entry ?lex_entry_source .
  ?lex_entry_source lemon:sense ?sense_source .
  ?sense_source lemon:reference ?concept .
  ?lex_entry_source lemon:form ?form_source .
  ?form_source lemon:writtenRep ?wr_source .
  ?form_source lemon:writtenRep "red"@es .  
  ?translation translation:translationSource ?sense_source .
  ?translation translation:translationCategory ?tr_category .
  
  # written representation of translation target
  ?translation translation:translationTarget ?tr_t_sense .
  ?lex_entry_target lemon:sense ?tr_t_sense .
  ?lexicon_target a lemon:Lexicon .
  ?lexicon_target lemon:entry ?lex_entry_target .
  ?lex_entry_target lemon:form ?form_target .
  ?form_target lemon:writtenRep ?wr_target
}
QUERY_END;
$config['sample_queries'][] = array('name' => $name, 'query' => $query);

$name = '"Into which languages has been the term "hueco" translated? Retrieve also the URI of the lexica that makes them available"';
$query = <<<QUERY_END
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX skos: <http://www.w3.org/2004/02/skos/core#>
PREFIX lemon: <http://www.lemon-model.net/lemon#>
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX skos: <http://www.w3.org/2004/02/skos/core#>
PREFIX lemon: <http://www.lemon-model.net/lemon#>
PREFIX translation: <http://purl.org/net/translation#>
PREFIX tr_cat: <http://purl.org/net/translation-categories#>

SELECT DISTINCT ?lang_target ?lexicon_target ?wr_target 
WHERE {
  
  # retrieve "hueco" term
  ?lex_entry_source rdf:type lemon:LexicalEntry .
  ?lexicon_source a lemon:Lexicon .
  ?lexicon_source lemon:entry ?lex_entry_source .
  ?lex_entry_source lemon:sense ?sense_source .
  ?sense_source lemon:reference ?concept .
  ?lex_entry_source lemon:form ?form_source .
  ?form_source lemon:writtenRep ?wr_source .
  ?form_source lemon:writtenRep "hueco"@es .  
  ?translation translation:translationSource ?sense_source .
  ?translation translation:translationCategory ?tr_category .
  
  # written representation of translations translations 
  ?translation translation:translationTarget ?tr_t_sense .
  ?lex_entry_target lemon:sense ?tr_t_sense .
  ?lexicon_target a lemon:Lexicon ;
  lemon:language ?lang_target .
  ?lexicon_target lemon:entry ?lex_entry_target .
  ?lex_entry_target lemon:form ?form_target .
  ?form_target lemon:writtenRep ?wr_target
}
QUERY_END;

$config['sample_queries'][] = array('name' => $name, 'query' => $query);
/*** End of sample query settings ***/

/*** Query form settings ***/
/* Text that will be show when 'Load Namespaces' button is pressed */
$config['prefixes'] = <<<PREFIXES_END
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX foaf: <http://xmlns.com/foaf/0.1/>
PREFIX dct: <http://purl.org/dc/terms/>
PREFIX geo: <http://www.w3.org/2003/01/geo/wgs84_pos#>
PREFIX owl: <http://www.w3.org/2002/07/owl#>

PREFIXES_END;

/* text that will be shown when page is first visited */
$config['default_query'] = <<<QUERY_END
# Query that retrieves the first 1000 translations in Terminesp

PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX skos: <http://www.w3.org/2004/02/skos/core#>
PREFIX lemon: <http://www.lemon-model.net/lemon#>
PREFIX translation: <http://purl.org/net/translation#>
PREFIX tr_cat: <http://purl.org/net/translation-categories#>

SELECT DISTINCT ?translation 
                ?lex_entry_source ?wr_source 
                ?lex_entry_target 
                ?wr_target 
WHERE {
  
  # retrieve all translations
  ?translation a translation:Translation ;
     translation:translationSource ?tr_source ;
     translation:translationTarget ?tr_target ;  
     translation:translationCategory ?tr_cat .
  # retrieve source information
  ?lex_entry_source lemon:sense ?tr_source .
  ?lex_entry_source lemon:form ?form_source .
  ?form_source lemon:writtenRep ?wr_source .
  
  # retrieve target information
  ?lex_entry_target lemon:sense ?tr_target .
  ?lex_entry_target lemon:form ?form_target .
  ?form_target lemon:writtenRep ?wr_target .

} limit 1000
QUERY_END;

/* Supported output formats (ARC2 should support all of these) */
$config['output_formats'] = array(
    'xml'       => 'SPARQL XML',
    'json'      => 'JSON',
    'plain'     => 'Plain',
    'php_ser'   => 'Serialized PHP',
    'turtle'    => 'Turtle',
    'rdfxml'    => 'RDF/XML',
    'infos'     => 'Query Structure',
    'htmltab'   => 'HTML Table',
    'tsv'       => 'Tab Separated Values (TSV)',
    'csv'       => 'Comma Separated Values (CSV)',
    'plain'     => 'Plain',
    'sqlite'    => 'SQLite database'
);
/*** End of query form settings ***/
/***** End of configuration settings *****/

$ep = ARC2::getStoreEndpoint($config['arc']);
$ep = StoreEndpoint::convert_endpoint($ep, $config);
$ep->go();

?>
