/**
  * Modify the SPARQL pattern to allow querying using the original URI
  */
 function urisToEquivURIsInQuery()
 {
     $query_structure = $this->requestdata->query_parsed;
     //print_r($query_structure);
     $triple = $query_structure['query']['pattern']['patterns'][0]['patterns'][0];
     $s = $triple['s'];
     $p = $triple['p'];
     $o = $triple['o'];
     $s_type = $triple['s_type'];
     $p_type = $triple['p_type'];
     $o_type = $triple['o_type'];
     if ($s_type === 'uri') {
         $triple['s'] = 's';
         $triple['s_type'] = 'var';
         $newtriple = $this->createEquivURITriple($s, 's');
         // TODO: Shouldn't the new triple replace the old one, not just be added?
         $query_structure['query']['pattern']['patterns'][0]['patterns'][] = $newtriple;
     }
     if ($p_type === 'uri') {
         $triple['p'] = 'p';
         $triple['p_type'] = 'var';
         $newtriple = $this->createEquivURITriple($p, 'p', true);
         $query_structure['query']['pattern']['patterns'][0]['patterns'][] = $newtriple;
     }
     if ($o_type === 'uri') {
         $triple['o'] = 'o';
         $triple['o_type'] = 'var';
         $newtriple = $this->createEquivURITriple($o, 'o');
         $query_structure['query']['pattern']['patterns'][0]['patterns'][] = $newtriple;
     }
     // restore the first triple into its original location
     $query_structure['query']['pattern']['patterns'][0]['patterns'][0] = $triple;
     //print_r($query_structure);
     require_once __DIR__ . "/../bundle/ARC2_SPARQLSerializerPlugin.php";
     $sparqlserializer = new ARC2_SPARQLSerializerPlugin("<>", $this);
     $query = $sparqlserializer->toString($query_structure);
     $this->setQueryInPost($query);
 }
    /**
     * If option is so chosen, convert URIs in the query to
     * their corresponding "Original URIs" or "Equivalent URIs"
     */
    function convertURIsInQuery() {
        if ( $this->m_querybyoriguri ) {
            $this->convertOrigURIsToInternalURIsInQuery();
        } elseif ( $this->m_querybyequivuri ) {
            $query_structure = $this->m_query_parsed;
            $triple = $query_structure['query']['pattern']['patterns'][0]['patterns'][0];
            $s = $triple['s'];
            $p = $triple['p'];
            $o = $triple['o'];
            $s_type = $triple['s_type'];
            $p_type = $triple['p_type'];
            $o_type = $triple['o_type'];
            if ( $s_type === 'uri' ) {
                $triple['s'] = 's';
                $triple['s_type'] = 'var';
                $newtriple = $this->createEquivURITriple( $s, 's' );
                $query_structure['query']['pattern']['patterns'][0]['patterns'][] = $newtriple;
            }
            if ( $p_type === 'uri' ) {
                $triple['p'] = 'p';
                $triple['p_type'] = 'var';
                $newtriple = $this->createEquivURITriple( $p, 'p', true );
                $query_structure['query']['pattern']['patterns'][0]['patterns'][] = $newtriple;
            }
            if ( $o_type === 'uri' ) {
                $triple['o'] = 'o';
                $triple['o_type'] = 'var';
                $newtriple = $this->createEquivURITriple( $o, 'o' );
                $query_structure['query']['pattern']['patterns'][0]['patterns'][] = $newtriple;
            }
            // restore the first triple into its original location
            $query_structure['query']['pattern']['patterns'][0]['patterns'][0] = $triple;
            require_once( __DIR__ . "/bundle/ARC2_SPARQLSerializerPlugin.php" );
            $sparqlserializer = new ARC2_SPARQLSerializerPlugin();
            $query = $sparqlserializer->toString( $query_structure );

            $this->setQueryInPost( $query );
            # $this->convertEquivURIsToInternalURIsInQuery(); // TODO DEPRECATED
        }
    }