<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<?vsp
--
--
--  $Id: description.vsp,v 1.1.2.24 2010/07/08 13:23:48 source Exp $
--
--  This file is part of the OpenLink Software Virtuoso Open-Source (VOS)
--  project.
--
--  Copyright (C) 1998-2009 OpenLink Software
--
--  This project 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; only version 2 of the License, dated June 1991.
--
--  This program 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 this program; if not, write to the Free Software Foundation, Inc.,
--  51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
--
--
   declare _S, odd_position any;
   declare page_resource_uri, proxy_iri, rdf_link, label, true_label, _subject any;
   declare white_page, arr, data, meta, h1, h2, inx, gr, host, refr, sid, inf, sas, langs, best_q any;
   declare urilookup integer;
   declare dbg_enable varchar;
   declare qry_str varchar;
   declare dbg_out any;
   declare inf_parm varchar;
  declare ses_parms varchar;
  declare all_langs, dset any;
  declare iri_type, iri_uri varchar;

   dbg_enable := get_keyword ('dbg', params);
   if (dbg_enable = '1') 
     {
        dbg_printf ('Enabling b3s session debug.\n');
        connection_set ('b3s_dbg', 1);
        dbg_out := string_output ();
     }
   else connection_set ('b3s_dbg',0);
     
  connection_set ('ns_ctr', 1); /* for unknown xmlns to print in RDFa */

  white_page := 1;
  sid := null;
  inf := '';
  iri_type := 'unknown';

  b3s_handle_ses (path, lines, params);
  sid := connection_get ('sid');

   b3s_parse_inf (sid, params);
   inf := b3s_render_inf_clause ();

  ses_parms := b3s_render_ses_params ();

  host := http_request_header (http_request_header (), 'X-Forwarded-Host', null, null);  
  if (host is null)
   host := http_request_header (http_request_header (), 'Host');  
   langs := http_request_header_full (lines, 'Accept-Language', 'en');
  all_langs := b3s_get_lang_acc (lines);
  dset := get_keyword ('lang', params, '');
  if (length (dset))
    all_langs := vector (dset, 1.0);
   gr := get_keyword ('g', params, '');

  b3s_dbg_out (dbg_out, 'sid     : ' || sid);
  b3s_dbg_out (dbg_out, 'gr      : ' || gr);

   arr := rfc1808_parse_uri (gr);

   if (arr[0] = '' and arr[1] = '' and arr[2] <> '')
     gr := 'http://' || gr;

   page_resource_uri := gr;
   page_resource_uri := replace (page_resource_uri, '%23', '#');
   
   _S := page_resource_uri; 
   proxy_iri := page_resource_uri;

  b3s_dbg_out (dbg_out, 'page_resource_uri: ' || page_resource_uri);

  if (get_keyword ('sp', params) = '1')
    {
      DB.DBA.EXEC_AS (sprintf ('sparql define input:storage "" define get:soft "soft" SELECT * from <%S> where { ?x ?y ?z . }', gr), 'SPARQL');
      DB.DBA.VT_INC_INDEX_DB_DBA_RDF_OBJ ();
    }

   odd_position := 0;
   set http_charset='utf-8';
   set isolation = 'uncommitted';
   http_header ('Cache-Control: no-cache, must-revalidate\r\nPragma: no-cache\r\n');
   label := ''; _subject := '';

   qry_str := sprintf ('sparql define input:inference "facets" select ?o (lang(?o)) where { <%S> virtrdf:label ?o }', _S);
   b3s_dbg_out (dbg_out, 'qry: ' || qry_str);

--dbg_obj_print (qry_str);

   exec (qry_str, null, null, vector (), 0, meta, data);

   label := b3s_label_get (data, langs);
   true_label := label;
  iri_type := b3s_type (_S, iri_uri);

   qry_str := sprintf ('sparql %s prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> prefix dc: <http://purl.org/dc/elements/1.1/> select ?o (lang(?o)) where { <%S> rdfs:comment ?o }', inf, _S);
--    dbg_obj_print (qry_str);

   b3s_dbg_out (dbg_out, 'qry: ' || qry_str);

   exec (qry_str, null, null, vector (), 0, meta, data);

   _subject := b3s_label_get (data, langs);

  rdf_link := sprintf ('/sparql?query=%U', sprintf ('%s DESCRIBE <%s>', b3s_render_inf_clause(), _S)); 

  declare __res_desc varchar;

  __res_desc := b3s_uri_curie(page_resource_uri);

  if (not length (label))
    label := page_resource_uri;
  --http_flush (1);
?>

<!-- header -->
<head>
    <base href="http://<?V host ?>/fct/rdfdesc/" />
    <title>About: <?vsp http (sprintf ('%s', label)); ?></title>
    <link rel="alternate" type="application/rdf+xml" href="<?=rdf_link?>" title="RDF" />

    <link rel="stylesheet" type="text/css" href="styles/default.css"  charset="utf-8" />
    <link rel="stylesheet" type="text/css" href="styles/highlighter.css" charset="utf-8" />
    <script type="text/javascript" >
      var featureList=["tab"];
    </script>
    <script type="text/javascript" src="/fct/oat/toolkit/loader.js"></script>
    <script type="text/javascript" src="s/description.js"></script>
</head>
  <body about="<?V page_resource_uri ?>">
    <div id="PG">
      <div id="HD">
    <?vsp fct_page_head (); ?>
    <ul id="main_menu">
      <?vsp if (sid is not null) { ?>
        <li><a href="<?= b3s_render_fct_link() ?>">Facets</a></li>
      <?vsp } ?>
      <li id="mnu_descr" class="sel"><a href="/describe/?uri=<?V _S ?><?V ses_parms ?>" class="sel">Description</a></li>
      <li id="mnu_usage">
        <a href="usage.vsp?g=<?U _S ?><?V ses_parms ?>">Usage Statistics</a>
      </li>
      <li id="mnu_settings"><a href="settings.vsp?g=<?U _S ?><?V ses_parms ?>">Settings</a>
        <div id="settings_popup" style="display: none">
          <ul>
            <li>
              <input id="sas_ckb" type="checkbox" <?= b3s_sas_selected() ?> onchange="javascript:sas_cb();"/> 
              <label for="sas_ckb">owl:sameAs</label>
            </li>
            <li>
              <label for="inf_sel">Inference Rule:</label>
              <select id="inf_sel" onchange="javascript:inf_cb();"><?vsp b3s_render_inf_opts (); ?></select><br/>
            </li>
          </ul>
        </div> <!-- settings-popup -->
      </li>
    </ul>
    </div> <!-- #HD -->
    <div id="MD">
        <div class="page_resource_info">
      <h2>About: <a href="<?= case when page_resource_uri like 'nodeID://%' then b3s_http_url (page_resource_uri) else page_resource_uri end ?>"><?vsp http (sprintf ('%s', label)); ?></a></h2>
      <div class="ds_inf_info"> 
	    An Entity of Type : <a href="<?V iri_uri ?>"><?V iri_type ?></a>, 
	    within Data Space : <a href="http://<?V host ?>"><?V host ?></a>
      </div>
        </div>
          <?vsp if (_subject <> '') { ?>
            <p class="subj_desc"><?vsp http (sprintf ('%s', _subject)); ?></p>
  <?vsp } else { ?>
  <p class="subj_delim"></p>
          <?vsp } ?>
<!--                <li><a href="/fct/facet.vsp?sid=<?V sid ?>&cmd=set_class&iri=<?V gr ?>">Choose <?V ''?> as Type</a></li>
                <li><a href="/fct/facet.vsp?sid=<?V sid ?>&cmd=open_property">Choose <?V ''?> as Property (p)</a></li>
                <li><a href="">Choose <?V ''?> as Value (o)</a></li> -->
<!-- proptable -->
      <table class="description">

<?vsp
      declare vis, printed int;
      declare all_lang any;
      declare curr_pred any;

      if (connection_get ('s_term') = 's')
        http ('<tr><th class="property">Properties</th><th class="value">Objects</th></tr>');
      else
        http ('<tr><th class="property">Attributes</th><th class="value">Values</th></tr>');

      all_lang := vector ('*', 1.0);
      qry_str := sprintf ('select "p" as PRED, "o" as OBJECT from (sparql %s select distinct ?p ?o where { <%S> ?p ?o }) sp order by 1', inf, _S);
      exec (qry_str, null, null, vector (), 0, null, null, h1); 
      curr_pred := '';
      while (0 = exec_next (h1, null, null, data))	
	{
           declare PRED, OBJECT any;
	   pred := data[0];  
           object := data[1];
	   if (not length (PRED))
	     goto nxt1;

	   if (curr_pred <> pred)
	     {
               if (curr_pred <> '') http ('</ul></td></tr>');
	       b3s_http_print_l (PRED, odd_position, 0, sid);
	       curr_pred := pred;
	     }
           vis := b3s_http_print_r (OBJECT, sid, PRED, true_label, 1, all_langs);
	   nxt1:;
	}
      exec_close (h1);
      if (curr_pred <> '') http ('</ul></td></tr>');

      qry_str := sprintf ('select "p" as PRED, "o" as OBJECT from (sparql %s select distinct ?p ?o where { ?o ?p <%S> }) sp order by 1', inf, _S);
      exec (qry_str, null, null, vector (), 0, null, null, h1); 
      inx := 0;	
      curr_pred := '';
      while (0 = exec_next (h1, null, null, data))	
	{
           declare PRED, OBJECT any;
	   PRED := data[0];  
	   OBJECT := data[1];
	   inx := inx + 1;
	   if (not length (PRED))
	     goto nxt2;
	   if (curr_pred <> pred)
		  {	
               if (curr_pred <> '') http ('</ul></td></tr>');
	       b3s_http_print_l (PRED, odd_position, 1, sid);
	       curr_pred := pred;
	     }
           vis := b3s_http_print_r (OBJECT, sid, PRED, true_label, 0, all_langs);
	   nxt2:;
	}
      exec_close (h1);
      if (curr_pred <> '') http ('</ul></td></tr>');
       if  (odd_position = 0)
	 {
	    http ('<tr><td colspan="2"><p>No further information is available.</p></td></tr>');
	 }
?>
      </table>
    </div> <!--  #MD -->
    <?vsp b3s_render_dbg_out (dbg_out); ?>
<!-- footer -->
    <div id="FT">
      <div id="ft_t">
        Explore alternative Linked Data Views &amp; Meshups using:
        <a href="http://linkeddata.uriburner.com/ode/?uri=<?vsp http_url (page_resource_uri); ?>">OpenLink Data Explorer</a> 
        &nbsp; &nbsp; Raw Data in:
        <a href="<?=rdf_link || sprintf ('&output=%U', 'text/rdf+n3') ?>">N3</a> |
        <a href="<?=rdf_link || sprintf ('&output=%U', 'application/rdf+xml') ?>">RDF/XML</a> |
        <a href="<?=rdf_link || sprintf ('&output=%U', 'application/rdf+json')?>">RDF/JSON</a>
        &nbsp; &nbsp;<a href="/fct/facet_doc.html">About</a>&nbsp; &nbsp;
      </div> <!-- #ft_t -->
      <div id="ft_b">
        <a href="http://linkeddata.org/"><img alt="This material is Open Knowledge" src="/fct/images/LoDLogo.gif" border="0"></a> &nbsp;
        <a href="http://dbpedia.org/sparql"><img alt="W3C Semantic Web Technology" src="/fct/images/sw-sparql-blue.png" border="0"></a>
        <a href="<?=rdf_link?>" title="RDF data"><img src="/fct/images/sw-rdf-blue.png" alt="[RDF Data]"></a>
        <a href="http://www.opendefinition.org/"><img alt="This material is Open Knowledge" src="/fct/images/od_80x15_red_green.png" border="0"></a>
	<a rel="license" href="http://creativecommons.org/licenses/by-sa/3.0/"><img alt="Creative Commons License" style="border-width:0" 
	    src="/fct/images/creativecommons.png" /></a><br />
	This work is licensed under a 
	<a rel="license" href="http://creativecommons.org/licenses/by-sa/3.0/">Creative Commons Attribution-Share Alike 3.0 Unported License</a>.<br />
	<?vsp fct_virt_info (); ?><br /> 
        Copyright &copy; 2010 OpenLink Software
      </div> <!-- #ft_b -->
    </div> <!-- #FT -->
    </div> <!-- #PG -->
 </body>
</html>
