<docbook><section><title>VirtRDFViewsIngresTutDbScript</title><bridgehead class="http://www.w3.org/1999/xhtml:h2">Ingres R3 Tutorial Linked Data Views Script to set up your own instance</bridgehead>
<programlisting>
-- Setup script for Linked Data Views of Ingres R3 Tutorial Sample Database --

GRANT SELECT ON TUT.ingiima.book_list TO &quot;SPARQL&quot;, &quot;SPARQL_UPDATE&quot;;
GRANT SELECT ON TUT.ingiima.book_orders TO &quot;SPARQL&quot;, &quot;SPARQL_UPDATE&quot;;
GRANT SELECT ON TUT.ingiima.cust_info TO &quot;SPARQL&quot;, &quot;SPARQL_UPDATE&quot;;
GRANT SELECT ON TUT.ingiima.cust_orders TO &quot;SPARQL&quot;, &quot;SPARQL_UPDATE&quot;;

-------------------------------------------------------------------

-------- Create rdfs:Class definitions ----------------------------

ttlp (
&#39;
@prefix rdf: &lt;http://www.w3.org/1999/02/22-rdf-syntax-ns#&gt; .
@prefix rdfs: &lt;http://www.w3.org/2000/01/rdf-schema#&gt; .
@prefix xsd: &lt;http://www.w3.org/2001/XMLSchema#&gt; .

@prefix tut: &lt;http://localhost:8890/schemas/ingrestut/&gt; .

tut:book_list a rdfs:Class ;
	rdfs:isDefinedBy &lt;http://localhost:8890/schemas/ingrestut&gt; ;
	rdfs:label &quot;book_list&quot; ;
	rdfs:comment &quot;Ingres Tutorial Database book_list table&quot; .
	
tut:book_no a rdf:Property ;
	rdfs:domain tut:book_list ;
	rdfs:range xsd:integer ;
	rdfs:label &quot;Book No&quot; .
	
tut:title a rdf:Property ;
	rdfs:domain tut:book_list ;
	rdfs:range xsd:string ;
	rdfs:label &quot;Title&quot; .
	
tut:author a rdf:Property ;
	rdfs:domain tut:book_list ;
	rdfs:range xsd:string ;
	rdfs:label &quot;Author&quot; .

tut:price a rdf:Property ;
	rdfs:domain tut:book_list ;
	rdfs:range xsd:money;
	rdfs:label &quot;Price&quot; .

tut:category a rdf:Property ;
	rdfs:domain tut:book_list ;
	rdfs:range xsd:string ;
	rdfs:label &quot;Category&quot; .

tut:stock a rdf:Property ;
	rdfs:domain tut:book_list ;
	rdfs:range xsd:integer ;
	rdfs:label &quot;Stock&quot; .

tut:dist_no a rdf:Property ;
	rdfs:domain tut:book_list ;
	rdfs:range xsd:integer ;
	rdfs:label &quot;Dist No&quot; .

tut:book_orders a rdfs:Class ;
	rdfs:isDefinedBy &lt;http://localhost:8890/schemas/ingrestut&gt; ;
	rdfs:label &quot;Book Orders&quot; ;
	rdfs:comment &quot;Ingres Tutorial Database book_orders table&quot; .
	
tut:order_no a rdf:Property ;
	rdfs:domain tut:book_orders ;
	rdfs:range xsd:integer ;
         rdfs:label &quot;Order No&quot; .

tut:book_no_no a rdf:Property ;
	rdfs:domain tut:book_orders ;
	rdfs:range tut:book_list ;
         rdfs:label &quot;Book No&quot; .

tut:sale_price a rdf:Property ;
	rdfs:domain tut:book_orders ;
	rdfs:range xsd:money ;
         rdfs:label &quot;Sale Price&quot; .

tut:quantity a rdf:Property ;
	rdfs:domain tut:book_orders ;
	rdfs:range xsd:integer ;
         rdfs:label &quot;Quantity&quot; .

tut:extension a rdf:Property ;
	rdfs:domain tut:book_orders ;
	rdfs:range xsd:money ;
         rdfs:label &quot;Extension&quot; .

tut:cust_info a rdfs:Class ;
	rdfs:isDefinedBy &lt;http://localhost:8890/schemas/ingrestut&gt; ;
	rdfs:label &quot;Customer Information&quot; ;
	rdfs:comment &quot;Ingres Tutorial Database cust_info table&quot; .
	
tut:cust_no a rdf:Property ;
	rdfs:domain tut:cust_info ;
	rdfs:range xsd:integer ;
         rdfs:label &quot;Customer No&quot; .

tut:name a rdf:Property ;
	rdfs:domain tut:cust_info ;
	rdfs:range xsd:string ;
         rdfs:label &quot;Name&quot; .

tut:company a rdf:Property ;
	rdfs:domain tut:cust_info ;
	rdfs:range xsd:string ;
         rdfs:label &quot;Company&quot; .

tut:street a rdf:Property ;
	rdfs:domain tut:cust_info ;
	rdfs:range xsd:string;
         rdfs:label &quot;Street&quot; .

tut:city a rdf:Property ;
	rdfs:domain tut:cust_info ;
	rdfs:range xsd:string;
         rdfs:label &quot;City&quot; .

tut:state a rdf:Property ;
	rdfs:domain tut:cust_info ;
	rdfs:range xsd:string;
         rdfs:label &quot;State&quot; .

tut:city a rdf:Property ;
	rdfs:domain tut:cust_info ;
	rdfs:range xsd:string;
         rdfs:label &quot;City&quot; .

tut:state a rdf:Property ;
	rdfs:domain tut:cust_info ;
	rdfs:range xsd:string;
         rdfs:label &quot;State&quot; .

tut:zip a rdf:Property ;
	rdfs:domain tut:cust_info ;
	rdfs:range xsd:string;
         rdfs:label &quot;Zip Code&quot; .

tut:card_no a rdf:Property ;
	rdfs:domain tut:cust_info ;
	rdfs:range xsd:string;
         rdfs:label &quot;Card No&quot; .

tut:exp_date a rdf:Property ;
	rdfs:domain tut:cust_info ;
	rdfs:range xsd:date;
         rdfs:label &quot;Expire Date&quot; .

tut:ship_to a rdf:Property ;
	rdfs:domain tut:cust_info ;
	rdfs:range xsd:string;
         rdfs:label &quot;Ship To&quot; .

tut:cust_orders a rdfs:Class ;
	rdfs:isDefinedBy &lt;http://localhost:8890/schemas/ingrestut&gt; ;
	rdfs:label &quot;Customer Orders&quot; ;
	rdfs:comment &quot;Ingres Tutorial Database cust_orders table&quot; .
	
tut:order_no a rdf:Property ;
	rdfs:domain tut:cust_orders ;
	rdfs:range tut:book_orders ;
         rdfs:label &quot;Order No&quot; .

tut:book_no a rdf:Property ;
	rdfs:domain tut:cust_orders ;
	rdfs:range tut:cust_info ;
         rdfs:label &quot;Book No&quot; .

tut:order_date a rdf:Property ;
	rdfs:domain tut:cust_orders ;
	rdfs:range xsd:date ;
         rdfs:label &quot;Order Date&quot; .

tut:status a rdf:Property ;
	rdfs:domain tut:cust_orders ;
	rdfs:range xsd:string ;
         rdfs:label &quot;Status&quot; .

tut:order_total a rdf:Property ;
	rdfs:domain tut:cust_orders ;
	rdfs:range xsd:money ;
         rdfs:label &quot;Order Total&quot; .
&#39;, &#39;&#39;, &#39;http://localhost:8890/schemas/ingrestut&#39;, 0);

---------------------------------------------------------------

----------- Create IRI Classes -------------

sparql

	create iri class &lt;http://localhost:8890/schemas/ingrestut/book_list_iri&gt; 
	&quot;http://^{URIQADefaultHost}^/ingrestut/book_list/%d#this&quot;
    	(in book_no integer not null) .

	create iri class &lt;http://localhost:8890/schemas/ingrestut/book_orders_iri&gt;
	&quot;http://^{URIQADefaultHost}^/ingrestut/book_orders/%d_%d#this&quot;
	 (in order_no integer not null, in book_no integer not null ) .

	create iri class &lt;http://localhost:8890/schemas/ingrestut/cust_info_iri&gt; 
	&quot;http://^{URIQADefaultHost}^/ingrestut/cust_info/%d#this&quot;
    	(in cust_no integer not null) .

	create iri class &lt;http://localhost:8890/schemas/ingrestut/cust_orders_iri&gt; 
	&quot;http://^{URIQADefaultHost}^/ingrestut/cust_orders/%d#this&quot;
    	(in order_no integer not null) .

	;

--------------------------------------------------------------------

------------- Create Quad Store ------------------------------------

sparql

prefix tut:	&lt;http://localhost:8890/schemas/ingrestut/&gt;

alter quad storage virtrdf:DefaultQuadStorage             
  from TUT.ingiima.book_list as book_list_tbl 
  from TUT.ingiima.book_orders as book_orders_tbl
  from TUT.ingiima.cust_info as cust_info_tbl
  from TUT.ingiima.cust_orders as cust_orders_tbl
{
  create virtrdf:ingrestut as 
      graph &lt;http://localhost:8890/ingrestut&gt;
  {
        tut:book_list_iri(book_list_tbl.book_no) a tut:book_list 
               as virtrdf:book_list_book_no ;
        tut:title book_list_tbl.title
	     as virtrdf:book_list_title;
        tut:author book_list_tbl.author
              as virtrdf:book_list_author;
        tut:price book_list_tbl.price
              as virtrdf:book_list_price;
        tut:category book_list_tbl.category
              as virtrdf:book_list_category;
        tut:stock book_list_tbl.stock
              as virtrdf:book_list_stock;
        tut:dist_no book_list_tbl.dist_no
              as virtrdf:book_list_dist_no .

	tut:book_orders_iri(book_orders_tbl.order_no, book_orders_tbl.book_no) a tut:book_orders
		as virtrdf:book_orders_pk;
	tut:order_no book_orders_tbl.order_no
		as virtrdf:book_orders_order_no;
	tut:book_no tut:book_list_iri(book_list_tbl.book_no)
		where(^{book_orders_tbl.}^.book_no = ^{book_list_tbl.}^.book_no)
		as virtrdf:book_orders_book_no;
	tut:sale_price book_orders_tbl.sale_price
		as virtrdf:book_orders_sale_price;
	tut:quantity book_orders_tbl.quantity
		as virtrdf:book_orders_quantity;
	tut:extension book_orders_tbl.extension
		as virtrdf:book_orders_extension .

 	tut:cust_info_iri(cust_info_tbl.cust_no) a tut:cust_info
		as virtrdf:cust_info_cust_no;
	tut:name cust_info_tbl.name
		as virtrdf:cust_info_name;
	tut:company cust_info_tbl.company
		as virtrdf:cust_info_company;
	tut:street cust_info_tbl.street
		as virtrdf:cust_info_street;
	tut:city cust_info_tbl.city
		as virtrdf:cust_info_city;
	tut:state cust_info_tbl.state
		as virtrdf:cust_info_state;
	tut:zip cust_info_tbl.zip
		as virtrdf:cust_info_zip;
	tut:card_no cust_info_tbl.card_no
		as virtrdf:cust_info_card_no;
	tut:exp_date cust_info_tbl.exp_date
		as virtrdf:cust_info_exp_date;
	tut:ship_to cust_info_tbl.ship_to
		as virtrdf:cust_info_ship_to .

 	tut:cust_orders_iri(cust_orders_tbl.order_no) a tut:cust_orders
		as virtrdf:cust_orders_order_no;

	tut:cust_no tut:cust_info_iri(cust_info_tbl.cust_no)
		where (^{cust_orders_tbl.}^.cust_no = ^{cust_info_tbl.}^.cust_no)
		as virtrdf:cust_orders_cust_no;
	tut:order_date cust_orders_tbl.order_date
		as virtrdf:cust_orders_order_date;
	tut:status cust_orders_tbl.status
		as virtrdf:cust_orders_status;
	tut:order_total cust_orders_tbl.order_total
		as virtrdf:cust_orders_order_total   .
  } .
} .
;

delete from db.dba.url_rewrite_rule_list where urrl_list like &#39;ingrestut_rule%&#39;;
delete from db.dba.url_rewrite_rule where urr_rule like &#39;ingrestut_rule%&#39;;

DB.DBA.URLREWRITE_CREATE_REGEX_RULE (
    &#39;ingrestut_rule1&#39;,
    1,
    &#39;(/[^#]*)&#39;,
    vector(&#39;path&#39;),
    1,
    &#39;/about/html/http/^{URIQADefaultHost}^%s&#39;,
    vector(&#39;path&#39;),
    null,
    &#39;(text/html)|(\\*/\\*)&#39;,
    0,
    303
    );


DB.DBA.URLREWRITE_CREATE_REGEX_RULE (
    &#39;ingrestut_rule2&#39;,
    1,
    &#39;(/[^#]*)&#39;,
    vector(&#39;path&#39;),
    1,
    &#39;/sparql?query=DESCRIBE+%%3Chttp%%3A//localhost%%3A8890%U%%23this%%3E+%%3Chttp%%3A//localhost%%3A8890%U%%23this%%3E+FROM+%%3Chttp%%3A//localhost%%3A8890/ingrestut%%3E&amp;format=%U&#39;,
    vector(&#39;path&#39;, &#39;path&#39;, &#39;*accept*&#39;),
    null,
    &#39;(text/rdf.n3)|(application/rdf.xml)&#39;,
    0,
    null
    );

DB.DBA.URLREWRITE_CREATE_RULELIST (
    &#39;ingrestut_rule_list1&#39;,
    1,
    vector (
  	 	&#39;ingrestut_rule1&#39;,
  	 	&#39;ingrestut_rule2&#39;
	  ));

-- ensure a VD for the IRIs which begins with /
VHOST_REMOVE (lpath=&gt;&#39;/ingrestut&#39;);

VHOST_DEFINE (
	lpath=&gt;&#39;/ingrestut&#39;,  
	ppath=&gt;&#39;/DAV/ingrestut/&#39;, 
    	is_dav=&gt;1, 
	vsp_user=&gt;&#39;dba&#39;, 
	is_brws=&gt;0, 
	opts=&gt;vector (&#39;url_rewrite&#39;, &#39;ingrestut_rule_list1&#39;) 
	);

delete from db.dba.url_rewrite_rule_list where urrl_list like &#39;ingres_schemas_rule%&#39;;
delete from db.dba.url_rewrite_rule where urr_rule like &#39;ingres_schemas_rule%&#39;;

DB.DBA.URLREWRITE_CREATE_REGEX_RULE (
    &#39;ingres_schemas_rule1&#39;,
    1,
    &#39;(/[^#]*)&#39;,
    vector(&#39;path&#39;),
    1,
    &#39;/about/html/http/^{URIQADefaultHost}^%s&#39;,
    vector(&#39;path&#39;),
    null,
    &#39;(text/html)|(\\*/\\*)&#39;,
    0,
    303
    );

DB.DBA.URLREWRITE_CREATE_REGEX_RULE (
    &#39;ingres_schemas_rule2&#39;,
    1,
    &#39;(/[^#]*)&#39;,
    vector(&#39;path&#39;),
    1,
    &#39;/sparql?query=CONSTRUCT+{+%%3Chttp%%3A//localhost%%3A8890%U%%3E+%%3Fp+%%3Fo+}%%0D%%0AFROM+%%3Chttp%%3A//localhost%%3A8890/schemas/ingrestut%%3E+%%0D%%0AWHERE+{+%%3Chttp%%3A//localhost%%3A8890%U%%3E+%%3Fp+%%3Fo+}&amp;format=%U&#39;,
    vector(&#39;path&#39;,&#39;path&#39;,&#39;*accept*&#39;),
    null,
    &#39;(text/rdf.n3)|(application/rdf.xml)&#39;,
    0,
    null
    );

DB.DBA.URLREWRITE_CREATE_RULELIST (
    &#39;ingres_schemas_rule_list1&#39;,
    1,
    vector (
  	 	&#39;ingres_schemas_rule1&#39;,
  	 	&#39;ingres_schemas_rule2&#39;
	  ));

-- ensure a VD for the IRIs which begins with /
VHOST_REMOVE (lpath=&gt;&#39;/schema/ingrestut&#39;);

VHOST_DEFINE (
	lpath=&gt;&#39;/schemas/ingrestut&#39;,  
	ppath=&gt;&#39;/DAV/schemas/ingrestut/&#39;, 
    	is_dav=&gt;1, 
	vsp_user=&gt;&#39;dba&#39;, 
	is_brws=&gt;0, 
	opts=&gt;vector (&#39;url_rewrite&#39;, &#39;ingres_schemas_rule_list1&#39;) 
	);

DB.DBA.XML_SET_NS_DECL (&#39;tut&#39;, &#39;http://^{URIQADefaultHost}^/schemas/ingrestut/&#39;, 2);

</programlisting></section></docbook>