Book Home

Contents
Preface


Overview
Data Representation
RDF and SPARQL API and SQL
SPARUL -- an Update Language For RDF Graphs
RDF Insert Methods in Virtuoso
Virtuoso Sponger
Dereferencable IRIs and RDF Linked Data
RDF Views -- Mapping Relational Data to RDF
Introduction Rationale Quad Map Patterns, Value and IRI Classes Simple Mapping Example -- Northwind RDF View Configuring RDF Storages Translation Of SPARQL Triple Patterns To Quad Map Patterns Describing Source Relational Tables Function-Based IRI Classes Connection Variabes in IRI Classes Lookup Optimization -- BIJECTION and RETURNS Options Join Optimization -- Declaring IRI Subclasses RDF Metadata Maintenance and Recovery Split RDF View RDF views and recursive FK relationships Enterprise Data Access & Integration Business Intelligence
RDF Inference in Virtuoso
Using Full Text Search in SPARQL
Virtuoso SPARQL Query Service
Business Intelligence Extensions for SPARQL
Debugging SPARQL queries
Virtuoso RDF Performance Tuning
RDF Store Benchmarks
SPARQL Implementation Details
Native RDF Storage Providers
SPARQL predicates usage

15.8. RDF Views -- Mapping Relational Data to RDF

RDF Views map relational data into RDF and allow customizing RDF representation of locally stored RDF data. To let SPARQL clients access relational data as well as physical RDF graphs in a single query, we introduce a declarative Meta Schema Language for mapping SQL Data to RDF Ontologies. As a result, all types of clients can efficiently access all data stored on the server. The mapping functionality dynamically generates RDF Data Sets for popular ontologies such as SIOC, SKOS, FOAF, and ATOM/OWL without disruption to the existing database infrastructure of Web 1.0 or Web 2.0 solutions. RDF views are also suitable for declaring custom representation for RDF triples, e.g. property tables, where one row holds many single-valued properties.

15.8.1. Introduction

The Virtuoso RDF Views meta schema is a built-in feature of Virtuoso's SPARQL to SQL translator. It recognizes triple patterns that refer to graphs for which an alternate representation is declared and translates these into SQL accordingly. The main purpose of this is evaluating SPARQL queries against existing relational databases. There exists previous work from many parties for rendering relational data as RDF and opening it to SPARQL access. We can mention D2RQ, SPASQL, Squirrel RDF, DBLP and others. The Virtuoso effort differs from these mainly in the following:


15.8.2. Rationale

Since most of the data that is of likely use for the emerging semantic web is stored in relational databases, the argument for exposing this to SPARQL access is clear. We note that historically, SQL access to relational data has essentially never been given to the public outside of the organization. If programmatic access to corporate IS has been available to partners or the public, it has been through dynamic web pages or more recently web services. There are reasons of performance, security, maintainability and so forth for this.

The culture of the emerging semantic web is however taking a different turn. Since RDF and OWL offer a mergeable and queryable model for heterogeneous data, it is more meaningful and maintainable to expose selected data for outside query than it would be with SQL. Advances in hardware make this also less of a performance issue than it would have been in the client-server database era.

In the context of Virtuoso, since Virtuoso is originally a virtual/federated database, incorporating SPARQL to relational mapping is an evident extension of the product's mission as a multi-protocol, multi-platform connector between information systems.


15.8.3. Quad Map Patterns, Value and IRI Classes

In the simplest sense, any relational schema can be rendered into RDF by converting all primary keys and foreign keys into IRI's, assigning a predicate IRI to each column, and an rdf:type predicate for each row linking it to a RDF class IRI corresponding to the table. Then a triple with the primary key IRI as subject, the column IRI as predicate and the column's value as object is considered to exist for each column that is neither part of a primary or foreign key.

Strictly equating a subject value to a row and each column to a predicate is often good but is too restrictive for the general case.

Thus in the most common case the RDF meta schema should consist of independent transformations; the domain of each transformation is a result-set of some SQL SELECT statement and range is a set of triples. The SELECT that produce the domain is quite simple: it does not use aggregate functions, joins and sorting, only inner joins and WHERE conditions. There is no need to support outer joins in the RDF meta schema because NULLs are usually bad inputs for functions that produce IRIs. In the rare cases when NULLs are OK for functions, outer joins can be encapsulated in SQL views. The range of mapping can be described by a SPARQL triple pattern: a pattern field is a variable if it depends on table columns, otherwise it is a constant. Values of variables in the pattern may have additional restrictions on datatypes, when datatypes of columns are known.

This common case of an RDF meta schema is implemented in Virtuoso, with one adjustment. Virtuoso stores quads, not triples, using the graph field (G) to indicate that a triple belongs to some particular application or resource. A SPARQL query may use quads from different graphs without large difference between G and the other three fields of a quad. E.g., variable ?g in expression GRAPH ?g {...} can be unbound. SPARQL has special syntax for "graph group patterns" that is convenient for sets of triple patterns with a common graph, but it also has shorthands for common subject and predicate, so the difference is no more than in syntax. There is only one feature that is specific for graphs but not for other fields: the SPARQL compiler can create restrictions on graphs according to FROM and FROM NAMED clauses.

Virtuoso RDF Views should offer the same flexibility with the graphs as SPARQL addressing physical triples. A transformation cannot always be identified by the graph used for ranges because graph may be composed from SQL data. The key element of the meta schema is a "quad map pattern". A simple quad map pattern fully defines one particular transformation from one set of relational columns into triples that match one SPARQL graph pattern. The main part of quad map pattern is four declarations of "quad map values", each declaration specifies how to calculate the value of the corresponding triple field from the SQL data. The pattern also lists boolean SQL expressions that should be used to filter out unwanted rows of source data (and to join multiple tables if source columns belong to different tables). There are also quad map patterns that group together similar quad patterns but do not specify any real transformation or even prevent unwanted transformations from being used, they are described in "Grouping Map Patterns" below.

Quad map values refer to schema elements of two further types: "IRI classes" and "literal classes".

15.8.3.1. IRI Classes

An IRI class declares that a column or set of columns gets converted into a IRI in a certain way. The conversion of this sort can be declared revertible (bijection) so an IRI can be parsed into original SQL values; this is useful when some equality of an IRI constant and a calculated IRI can be replaced with an equality of a parse result of a constant and an SQL column that is index criteria or simply faster. In addition, the SPARQL optimizer will eliminate redundant conversions if one IRI class is explicitly declared as a subclass of another. The most flexible declaration for conversion consists of specifying functions that assemble and disassemble from IRI into its constituent parts. This is overkill for typical conversions so it is possible to specify only one sprintf-style format string such that sprintf() SQL function will print an IRI using this format and sprintf_inverse() will be able to parse it back.

The use of sprintf_inverse() assumes that the format does not contain fragments like '%s%s' that make it impossible to separate parts of IRI from each other.

In the following, we shall map the Virtuoso users and user roles system tables into the SIOC ontology.

create iri class oplsioc:user_iri "http://myhost/sys/user?id=%d"
  (in uid integer not null) .
create iri class oplsioc:group_iri "http://myhost/sys/group?id=%d"
  (in gid integer not null) .
create iri class oplsioc:membership_iri
  "http://myhost/sys/membership?super=%d&sub=%d"
  (in super integer not null, in sub integer not null) .
create iri class oplsioc:dav_iri "http://myhost%s"
  (in path varchar) .

These IRI classes are used for mapping data from the DB.DBA.SYS_USERS and DB.DBA.SYS_ROLE_GRANTS system tables that are defined in Virtuoso as follows:

create table DB.DBA.SYS_USERS (
  U_ID                integer not null unique,
  U_NAME              char (128) not null primary key,
  U_IS_ROLE           integer default 0,
  U_FULL_NAME         char (128),
  U_E_MAIL            char (128) default ",
  U_ACCOUNT_DISABLED  integer default 1,
  U_DAV_ENABLE        integer default 0,
  U_SQL_ENABLE        integer default 1,
  U_HOME              varchar (128),
. . .
 );

Single record in DB.DBA.SYS_USERS corresponds to a plain user or a group (role). Users and roles are collectively named "grantees". Thus a role may be granted to another role or to a user account. A role grant may be direct (explicit) or assigned by recursion.

create table SYS_ROLE_GRANTS (
  GI_SUPER   integer,
  GI_SUB     integer,
  GI_DIRECT  integer default 1,
. . .
  primary key (GI_SUPER, GI_SUB, GI_DIRECT));

One IRI class usually corresponds to one ontology class, because similar things are usually called similarly. One may wish to use identifiers of ontology classes as identifiers of related IRI classes, to not remember double number of names, e.g. create IRI class mybank:XpressXfer for subjects that will have rdf:type property mybank:XpressXfer made by mapping. That is technically possible but proven to become inconvenient and misleading as application evolves. While RDF types tend to persist, IRI classes may change over time or same subject may get more than one name via more than one IRI class, say, for exports to different systems. It is found to be more convenient to compose names of IRI classes by adding some common prefixes or suffixes to RDF classes (or to table names), say, write create IRI class mybank:XpressXfer_iri.


15.8.3.2. Literal Classes

A "literal class" declares that a column or set of columns gets converted into a literal instead of an IRI. More precisely, the result of conversion can be IRI_ID so it represents an IRI, but in current version of Virtuoso this is supported only for some internal built-in literal classes, not for classes declared by the user. So for user-defined literal class the result of the conversion is an RDF literal even if it is a string representation of a valid IRI.

In any case, a literal class can be used only in quad map values of O fields, because Virtuoso does not support literal values as subjects.

A special case of literal class is the identity class that converts a value from varchar column into an untyped literal and value from column of any other SQL datatype into a typed literal with type from XMLSchema set, i.e. xsd:integer, xsd:dateTime and so on. Columns of types ANY and IRI_ID are not supported.

The SPARQL optimizer knows that RDF literal types are pairwise disjoint so literal classes that produce literals of different types are known to be pairwise disjoint. The optimizer will replace a join on two disjoint literal classes with an empty statement, to simplify the resulting query.


15.8.3.3. Simple Quad Map Patterns

The following declaration of quad map pattern is self-explanatory. The line for object uses identity literal class so there's no need to specify its name.

graph      <http://myhost/sys>
subject    oplsioc:user_iri (DB.DBA.SYS_USERS.U_ID)
predicate  foaf:email
object     DB.DBA.SYS_USERS.U_E_MAIL

The description language also supports SPARQL-style notation that contains less keywords and eliminates duplicate graphs, subjects and predicates. The following add two patterns with constant graph IRI <http://myhost/sys> and subjects are made from column DB.DBA.SYS_USERS.U_ID by oplsioc:user_iri.

graph <http://myhost/sys>
  {
    oplsioc:user_iri (DB.DBA.SYS_USERS.U_ID)
      a sioc:user ;
      oplsioc:name DB.DBA.SYS_USERS.U_FULL_NAME .
  }

15.8.3.4. Assigning Names To Quad Map Patterns

In real applications, quad map patterns should be named, for schema manipulation and keeping debug info readable. Thus it is much better to rewrite the previous example as

create virtrdf:SysUsers as graph <http://myhost/sys>
  {
    oplsioc:user_iri (DB.DBA.SYS_USERS.U_ID)
      a sioc:user
          as virtrdf:SysUserType-User;
      oplsioc:name DB.DBA.SYS_USERS.U_FULL_NAME
          as virtrdf:SysUsersFullName .
  }

Using these names, one may later write, say, drop quad map virtrdf:SysUserType-User.

One name, virtrdf:DefaultQuadMap is reserved. It is an internal quad map pattern used to access "native-form" quads from DB.DBA.RDF_QUAD:

create virtrdf:DefaultQuadMap as
graph rdfdf:default-iid-nonblank (DB.DBA.RDF_QUAD.G)
subject rdfdf:default-iid (DB.DBA.RDF_QUAD.S)
predicate rdfdf:default-iid-nonblank (DB.DBA.RDF_QUAD.P)
object rdfdf:default (DB.DBA.RDF_QUAD.O)

IRI classes from rdfdf:... namespace are also reserved.


15.8.3.5. Grouping Map Patterns

The previous example actually contains three map patterns, not two. The name virtrdf:SysUsers refers to a "group map pattern" that does not define any real transformation of relational data into RDF but helps organize quad map patterns into a tree. Group may contain both quad map patterns and other groups. A group can be manipulated as a whole, e.g. drop quad map virtrdf:SysUsers will remove all three map patterns.



15.8.4. Simple Mapping Example -- Northwind RDF View

Here is example of the basic Northwind RDF Views deployment. The sequence of operations is very common for adding SPARQL access to existing application.

There exist few important questions to answer. Who should have access to data behind RDF View? Should someone have access to other sorts of RDF data but not to the new View? What are applications that should be interoperable with the new RDF data source? Are there any applications that produce similar data but that data sould be kept apart from data made by view? How to ensure that deployment the view will not cause problems for other applications?

First of all, we decide whether the default web service endpoint should have access to the data in question. If it should then we have to grant SELECT priviledges to the account "SPARQL" that is used for the default endpoint; if it should not but some custom edpoint should then grant to the owner account of that account. Granting access is less trivial that it is usual. On one hand, those who can make SQL SELECT statements on application's tables can also make SPARQL queries on RDF View over that tables, because it makes SQL inside. On the other hand, those who do not intend to query that data at all may get unexpected "permission denied" errors on queries that worked fine before adding an RDF View. If SPARQL compiler can not prove that the query can not access data from the view then it will generate SQL code that will access tables behind the view. In some cases permission problems should be resolved by creating RDF View in a separate RDF storage. In this example, data are public:

use DB;

GRANT SELECT ON "Demo"."demo"."Products" TO "SPARQL";
GRANT SELECT ON "Demo"."demo"."Suppliers" TO "SPARQL";
GRANT SELECT ON "Demo"."demo"."Shippers" TO "SPARQL";
GRANT SELECT ON "Demo"."demo"."Categories" TO "SPARQL";
GRANT SELECT ON "Demo"."demo"."Customers" TO "SPARQL";
GRANT SELECT ON "Demo"."demo"."Employees" TO "SPARQL";
GRANT SELECT ON "Demo"."demo"."Orders" TO "SPARQL";
GRANT SELECT ON "Demo"."demo"."Order_Details" TO "SPARQL";
GRANT SELECT ON "Demo"."demo"."Countries" TO "SPARQL";
GRANT SELECT ON "Demo"."demo"."Provinces" TO "SPARQL";

Interoperability is the next question. The example is not interoperable with anything so in can provide data of any form, a real application will probably use some ontology from external source. Sometimes data should be converted from internal application's representation to something different (such as metric to imperial or ATT country code to two-character country id); sometimes composed IRIs should follow special rules; function-based IRI classes may help in that cases. As this is the first example, only plain format-string-based IRI classes are used.

We should also ensure that data generated by the new view will not be accidentally mixed with other data of the database. For that purpose the example will use a unique graph name that includes both application name and host name. In addition, the script will drop declarations that might remain from a previous run of the same script. The script is executed many times during the development so erasing previous version is worth writing. It will report an error if there's nothing to erase but it's better than unpredictable errors due to writing new declarations over existing ones.

Note:

Making graph name unique for every host is not needed if the application is supposed to be "local" and nobody will access more than one installation of the application. If this is the case, use some fixed graph IRI, not necessarily starting with hostname at all; this is much more convenient for querying because you don't have to calculate the graph name in each query. With fixed graph in use, it is still possible to clone the RDF View to map to a unique graph as soon as the application become "public" and requires merging data from many installations.

SPARQL drop quad map graph iri("http://^{URIQADefaultHost}^/Northwind")
;
SPARQL drop quad map virtrdf:NorthwindDemo
;
Note:

The ^{URIQADefaultHost}^ macro is replaced with the value of DefaultHost parameter of [URIQA] section of configuration file. The IRI is written as iri("http://^{URIQADefaultHost}^/Northwind"), not as <http://^{URIQADefaultHost}^/Northwind> because macro of this sort works only inside SPARQL string values.

Now it's safe to create IRI classes needed for the view. If these classes are used only in the view we define then it is safe to create all of them in a single statement. If some of them are used across multiple declarations then errors may occur. it is impossible to redefine an IRI class that is in use; the compiler will try to avoid reporting errors by checking whether the new declaration is identical to the existing one and by trying garbage collection in hope that the IRI class is used only in garbage, but errors may occur anyway. Thus it is better to declare "shared" IRI classes by individual statements and group together only "private" IRI classes of a view. If a "class redefinition" error occurs in the middle of a group then "undefined class" errors may occur after because the processing of the group was interrupted before rest of group was not executed. When in trouble, try DB.DBA.RDF_AUDIT_METADATA procedure.

SPARQL
create iri class northwind:Category "http://^{URIQADefaultHost}^/Northwind/Category/%d#this" (in category_id integer not null) .
create iri class northwind:Shipper "http://^{URIQADefaultHost}^/Northwind/Shipper/%d#this" (in shipper_id integer not null) .
create iri class northwind:Supplier "http://^{URIQADefaultHost}^/Northwind/Supplier/%d#this" (in supplier_id integer not null) .
create iri class northwind:Product   "http://^{URIQADefaultHost}^/Northwind/Product/%d#this" (in product_id integer not null) .
create iri class northwind:Customer "http://^{URIQADefaultHost}^/Northwind/Customer/%U#this" (in customer_id varchar not null) .
create iri class northwind:Employee "http://^{URIQADefaultHost}^/Northwind/Employee/%U%U%d#this" (in employee_firstname varchar not null, in employee_lastname varchar not null, in employee_id integer not null) .
create iri class northwind:Order "http://^{URIQADefaultHost}^/Northwind/Order/%d#this" (in order_id integer not null) .
create iri class northwind:CustomerContact "http://^{URIQADefaultHost}^/Northwind/CustomerContact/%U#this" (in customer_id varchar not null) .
create iri class northwind:OrderLine "http://^{URIQADefaultHost}^/Northwind/OrderLine/%d/%d#this" (in order_id integer not null, in product_id integer not null) .
create iri class northwind:Province "http://^{URIQADefaultHost}^/Northwind/Province/%U/%U#this" (in country_name varchar not null, in province_name varchar not null) .
create iri class northwind:Country "http://^{URIQADefaultHost}^/Northwind/Country/%U#this" (in country_name varchar not null) .
create iri class northwind:Flag "http://^{URIQADefaultHost}^%U#this" (in flag_path varchar not null) .
create iri class northwind:dbpedia_iri "http://dbpedia.org/resource/%U" (in uname varchar not null) .
create iri class northwind:EmployeePhoto "http://^{URIQADefaultHost}^/DAV/VAD/demo/sql/EMP%d#this" (in emp_id varchar not null) .
create iri class northwind:CategoryPhoto "http://^{URIQADefaultHost}^/DAV/VAD/demo/sql/CAT%d#this" (in category_id varchar not null) .
;

One IRI class per subject type; format strings begin with same host but different directory names so this will let the compiler to guess the type of subject by the text of IRI. Most of declarations are bijections and may get option (bijection) hint but these format strings are so simple that the compiler may understant it by itself. (northwind:Employee is not a bijection because sprintf_inverse will be unable to split the tail of IRI string and find the boundary between first and last name.)

The final operation is extending the default quad storage with new tree of quad map patterns.

SPARQL
prefix northwind: <http://demo.openlinksw.com/schemas/northwind#>
prefix oplsioc: <http://www.openlinksw.com/schemas/oplsioc#>
prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#>
prefix sioc: <http://rdfs.org/sioc/ns#>
prefix foaf: <http://xmlns.com/foaf/0.1/>
prefix owl: <http://www.w3.org/2002/07/owl#>
prefix wgs: <http://www.w3.org/2003/01/geo/wgs84_pos#>

alter quad storage virtrdf:DefaultQuadStorage
from Demo.demo.Products as products
from Demo.demo.Suppliers as suppliers
from Demo.demo.Shippers as shippers
from Demo.demo.Categories as categories
from Demo.demo.Customers as customers
from Demo.demo.Employees as employees
from Demo.demo.Orders as orders
from Demo.demo.Order_Details as order_lines
from Demo.demo.Countries as countries
from Demo.demo.Provinces as provinces
where (^{suppliers.}^.Country = ^{countries.}^.Name)
where (^{customers.}^.Country = ^{countries.}^.Name)
where (^{employees.}^.Country = ^{countries.}^.Name)
where (^{orders.}^.ShipCountry = ^{countries.}^.Name)
{
        create virtrdf:NorthwindDemo as graph iri ("http://^{URIQADefaultHost}^/Northwind") option (exclusive)
        {
                northwind:CustomerContact (customers.CustomerID)
                        a foaf:Person
                                as virtrdf:CustomerContact-foaf_Person .

                northwind:CustomerContact (customers.CustomerID)
                        a northwind:CustomerContact
                                as virtrdf:CustomerContact-CustomerContact;
                        foaf:name customers.ContactName
                                as virtrdf:CustomerContact-contact_name ;
                        foaf:phone customers.Phone
                                as virtrdf:CustomerContact-foaf_phone ;
                        northwind:is_contact_at northwind:Customer (customers.CustomerID)
                                as virtrdf:CustomerContact-is_contact_at ;
                        northwind:country northwind:Country (customers.Country)
                                as virtrdf:CustomerContact-country ;
                        rdfs:isDefinedBy northwind:customercontact_iri (customers.CustomerID) ;
                        rdfs:isDefinedBy northwind:CustomerContact (customers.CustomerID) .

                northwind:Country (customers.Country)
                        northwind:is_country_of
                northwind:CustomerContact (customers.CustomerID) as virtrdf:CustomerContact-is_country_of .

                northwind:Product (products.ProductID)
                        a northwind:Product
                                as virtrdf:Product-ProductID ;
                        northwind:has_category northwind:Category (products.CategoryID)
                                as virtrdf:Product-product_has_category ;
                        northwind:has_supplier northwind:Supplier (products.SupplierID)
                                as virtrdf:Product-product_has_supplier ;
                        northwind:productName products.ProductName
                                as virtrdf:Product-name_of_product ;
                        northwind:quantityPerUnit products.QuantityPerUnit
                                as virtrdf:Product-quantity_per_unit ;
                        northwind:unitPrice products.UnitPrice
                                as virtrdf:Product-unit_price ;
                        northwind:unitsInStock products.UnitsInStock
                                as virtrdf:Product-units_in_stock ;
                        northwind:unitsOnOrder products.UnitsOnOrder
                                as virtrdf:Product-units_on_order ;
                        northwind:reorderLevel products.ReorderLevel
                                as virtrdf:Product-reorder_level ;
                        northwind:discontinued products.Discontinued
                                as virtrdf:Product-discontinued ;
                        rdfs:isDefinedBy northwind:product_iri (products.ProductID) ;
                        rdfs:isDefinedBy northwind:Product (products.ProductID) .

                northwind:Category (products.CategoryID)
                        northwind:category_of northwind:Product (products.ProductID) as virtrdf:Product-category_of .

                northwind:Supplier (products.SupplierID)
                        northwind:supplier_of northwind:Product (products.ProductID) as virtrdf:Product-supplier_of .

                northwind:Supplier (suppliers.SupplierID)
                        a northwind:Supplier
                                as virtrdf:Supplier-SupplierID ;
                        northwind:companyName suppliers.CompanyName
                                as virtrdf:Supplier-company_name ;
                        northwind:contactName suppliers.ContactName
                                as virtrdf:Supplier-contact_name ;
                        northwind:contactTitle suppliers.ContactTitle
                                as virtrdf:Supplier-contact_title ;
                        northwind:address suppliers.Address
                                as virtrdf:Supplier-address ;
                        northwind:city suppliers.City
                                as virtrdf:Supplier-city ;
                        northwind:dbpedia_city northwind:dbpedia_iri(suppliers.City)
                                as virtrdf:Supplier-dbpediacity ;
                        northwind:region suppliers.Region
                                as virtrdf:Supplier-region ;
                        northwind:postalCode suppliers.PostalCode
                                as virtrdf:Supplier-postal_code ;
                        northwind:country northwind:Country(suppliers.Country)
                                as virtrdf:Supplier-country ;
                        northwind:phone suppliers.Phone
                                as virtrdf:Supplier-phone ;
                        northwind:fax suppliers.Fax
                                as virtrdf:Supplier-fax ;
                        northwind:homePage suppliers.HomePage
                                as virtrdf:Supplier-home_page ;
                        rdfs:isDefinedBy northwind:supplier_iri (suppliers.SupplierID) ;
                        rdfs:isDefinedBy northwind:Supplier (suppliers.SupplierID) .

                northwind:Country (suppliers.Country)
                        northwind:is_country_of
                northwind:Supplier (suppliers.SupplierID) as virtrdf:Supplier-is_country_of .

                northwind:Category (categories.CategoryID)
                        a northwind:Category
                                as virtrdf:Category-CategoryID ;
                        northwind:categoryName categories.CategoryName
                                as virtrdf:Category-home_page ;
                        northwind:description categories.Description
                                as virtrdf:Category-description ;
                        foaf:img northwind:CategoryPhoto(categories.CategoryID)
                                as virtrdf:Category-categories.CategoryPhoto ;
                        rdfs:isDefinedBy northwind:category_iri (categories.CategoryID) ;
                        rdfs:isDefinedBy northwind:Category (categories.CategoryID) .

                northwind:CategoryPhoto(categories.CategoryID)
                        a northwind:CategoryPhoto
                                as virtrdf:Category-categories.CategoryPhotoID ;
                        rdfs:isDefinedBy northwind:categoryphoto_iri (categories.CategoryID) ;
                        rdfs:isDefinedBy northwind:CategoryPhoto(categories.CategoryID) .

                northwind:Shipper (shippers.ShipperID)
                        a northwind:Shipper
                                as virtrdf:Shipper-ShipperID ;
                        northwind:companyName shippers.CompanyName
                                as virtrdf:Shipper-company_name ;
                        northwind:phone shippers.Phone
                                as virtrdf:Shipper-phone ;
                        rdfs:isDefinedBy northwind:shipper_iri (shippers.ShipperID) ;
                        rdfs:isDefinedBy northwind:Shipper (shippers.ShipperID) .

                northwind:Customer (customers.CustomerID)
                        a  northwind:Customer
                                as virtrdf:Customer-CustomerID2 ;
                        a  foaf:Organization
                                as virtrdf:Customer-CustomerID ;
                        foaf:name customers.CompanyName
                                as virtrdf:Customer-foaf_name ;
                        northwind:companyName customers.CompanyName
                                as virtrdf:Customer-company_name ;
                        northwind:has_contact northwind:CustomerContact (customers.CustomerID)
                                as virtrdf:Customer-contact ;
                        northwind:country northwind:Country (customers.Country)
                                as virtrdf:Customer-country ;
                        northwind:contactName customers.ContactName
                                as virtrdf:Customer-contact_name ;
                        northwind:contactTitle customers.ContactTitle
                                as virtrdf:Customer-contact_title ;
                        northwind:address customers.Address
                                as virtrdf:Customer-address ;
                        northwind:city customers.City
                                as virtrdf:Customer-city ;
                        northwind:dbpedia_city northwind:dbpedia_iri(customers.City)
                                as virtrdf:Customer-dbpediacity ;
                        northwind:region customers.Region
                                as virtrdf:Customer-region ;
                        northwind:PostalCode customers.PostalCode
                                as virtrdf:Customer-postal_code ;
                        foaf:phone customers.Phone
                                as virtrdf:Customer-foaf_phone ;
                        northwind:phone customers.Phone
                                as virtrdf:Customer-phone ;
                        northwind:fax customers.Fax
                                as virtrdf:Customer-fax ;
                        rdfs:isDefinedBy northwind:customer_iri (customers.CustomerID) ;
                        rdfs:isDefinedBy northwind:Customer (customers.CustomerID) .

                northwind:Country (customers.Country)
                        northwind:is_country_of
                northwind:Customer (customers.CustomerID) as virtrdf:Customer-is_country_of .

                northwind:Employee (employees.FirstName, employees.LastName, employees.EmployeeID)
                        a northwind:Employee
                                as virtrdf:Employee-EmployeeID2 ;
                        a foaf:Person
                                as virtrdf:Employee-EmployeeID ;
                        foaf:surname employees.LastName
                                as virtrdf:Employee-foaf_last_name ;
                        northwind:lastName employees.LastName
                                as virtrdf:Employee-last_name ;
                        foaf:firstName employees.FirstName
                                as virtrdf:Employee-foaf_first_name ;
                        northwind:firstName employees.FirstName
                                as virtrdf:Employee-first_name ;
                        foaf:title employees.Title
                                as virtrdf:Employee-title ;
                        northwind:titleOfCourtesy employees.TitleOfCourtesy
                                as virtrdf:Employee-title_of_courtesy ;
                        foaf:birthday employees.BirthDate
                                as virtrdf:Employee-foaf_birth_date ;
                        northwind:birthday employees.BirthDate
                                as virtrdf:Employee-birth_date ;
                        northwind:hireDate employees.HireDate
                                as virtrdf:Employee-hire_date ;
                        northwind:address employees.Address
                                as virtrdf:Employee-address ;
                        northwind:city employees.City
                                as virtrdf:Employee-city ;
                        northwind:dbpedia_city northwind:dbpedia_iri(employees.City)
                                as virtrdf:Employee-dbpediacity ;
                        northwind:region employees.Region
                                as virtrdf:Employee-region ;
                        northwind:postalCode employees.PostalCode
                                as virtrdf:Employee-postal_code ;
                        northwind:country northwind:Country(employees.Country)
                                as virtrdf:Employee-country ;
                        foaf:phone employees.HomePhone
                                as virtrdf:Employee-home_phone ;
                        northwind:extension employees.Extension
                                as virtrdf:Employee-extension ;
                        northwind:notes employees.Notes
                                as virtrdf:Employee-notes ;
                        northwind:reportsTo northwind:Employee(employees.FirstName, employees.LastName, employees.ReportsTo) where (^{employees.}^.ReportsTo = ^{employees.}^.EmployeeID)
                                as virtrdf:Employee-reports_to ;
                        foaf:img northwind:EmployeePhoto(employees.EmployeeID)
                                as virtrdf:Employee-employees.EmployeePhoto ;
                        rdfs:isDefinedBy northwind:employee_iri (employees.EmployeeID) ;
                        rdfs:isDefinedBy northwind:Employee (employees.FirstName, employees.LastName, employees.EmployeeID) .

                northwind:EmployeePhoto(employees.EmployeeID)
                        a northwind:EmployeePhoto
                                as virtrdf:Employee-employees.EmployeePhotoId ;
                        rdfs:isDefinedBy northwind:employeephoto_iri (employees.EmployeeID) ;
                        rdfs:isDefinedBy northwind:EmployeePhoto (employees.EmployeeID) .

                northwind:Employee (employees.FirstName, employees.LastName, orders.EmployeeID)
                        northwind:is_salesrep_of
                northwind:Order (orders.OrderID) where (^{orders.}^.EmployeeID = ^{employees.}^.EmployeeID) as virtrdf:Order-is_salesrep_of .

                northwind:Country (employees.Country)
                        northwind:is_country_of
                northwind:Employee (employees.FirstName, employees.LastName, employees.EmployeeID) as virtrdf:Employee-is_country_of .

                northwind:Order (orders.OrderID)
                        a northwind:Order
                                as virtrdf:Order-Order ;
                        northwind:has_customer northwind:Customer (orders.CustomerID)
                                as virtrdf:Order-order_has_customer ;
                        northwind:has_salesrep northwind:Employee (employees.FirstName, employees.LastName, orders.EmployeeID) where (^{orders.}^.EmployeeID = ^{employees.}^.EmployeeID)
                                as virtrdf:Customer-has_salesrep ;
                        northwind:has_employee northwind:Employee (employees.FirstName, employees.LastName, orders.EmployeeID) where (^{orders.}^.EmployeeID = ^{employees.}^.EmployeeID)
                                as virtrdf:Order-order_has_employee ;
                        northwind:orderDate orders.OrderDate
                                as virtrdf:Order-order_date ;
                        northwind:requiredDate orders.RequiredDate
                                as virtrdf:Order-required_date ;
                        northwind:shippedDate orders.ShippedDate
                                as virtrdf:Order-shipped_date ;
                        northwind:order_ship_via northwind:Shipper (orders.ShipVia)
                                as virtrdf:Order-order_ship_via ;
                        northwind:freight orders.Freight
                                as virtrdf:Order-freight ;
                        northwind:shipName orders.ShipName
                                as virtrdf:Order-ship_name ;
                        northwind:shipAddress orders.ShipAddress
                                as virtrdf:Order-ship_address ;
                        northwind:shipCity orders.ShipCity
                                as virtrdf:Order-ship_city ;
                        northwind:dbpedia_shipCity northwind:dbpedia_iri(orders.ShipCity)
                                as virtrdf:Order-dbpediaship_city ;
                        northwind:shipRegion orders.ShipRegion
                                as virtrdf:Order-ship_region ;
                        northwind:shipPostal_code orders.ShipPostalCode
                                as virtrdf:Order-ship_postal_code ;
                        northwind:shipCountry northwind:Country(orders.ShipCountry)
                                as virtrdf:ship_country ;
                        rdfs:isDefinedBy northwind:order_iri (orders.OrderID) ;
                        rdfs:isDefinedBy northwind:Order (orders.OrderID) .

                northwind:Country (orders.ShipCountry)
                        northwind:is_ship_country_of
                northwind:Order (orders.OrderID) as virtrdf:Order-is_country_of .

                northwind:Customer (orders.CustomerID)
                        northwind:has_order northwind:Order (orders.OrderID) as virtrdf:Order-has_order .

                northwind:Shipper (orders.ShipVia)
                        northwind:ship_order northwind:Order (orders.OrderID) as virtrdf:Order-ship_order .

                northwind:OrderLine (order_lines.OrderID, order_lines.ProductID)
                        a northwind:OrderLine
                                as virtrdf:OrderLine-OrderLines ;
                        northwind:has_order_id northwind:Order (order_lines.OrderID)
                                as virtrdf:order_lines_has_order_id ;
                        northwind:has_product_id northwind:Product (order_lines.ProductID)
                                as virtrdf:order_lines_has_product_id ;
                        northwind:unitPrice order_lines.UnitPrice
                                as virtrdf:OrderLine-unit_price ;
                        northwind:quantity order_lines.Quantity
                                as virtrdf:OrderLine-quantity ;
                        northwind:discount order_lines.Discount
                                as virtrdf:OrderLine-discount ;
                        rdfs:isDefinedBy northwind:orderline_iri (order_lines.OrderID, order_lines.ProductID) ;
                        rdfs:isDefinedBy northwind:OrderLine (order_lines.OrderID, order_lines.ProductID) .

                northwind:Order (orders.OrderID)
                        northwind:is_order_of
                northwind:OrderLine (order_lines.OrderID, order_lines.ProductID) where (^{orders.}^.OrderID = ^{order_lines.}^.OrderID) as virtrdf:Order-is_order_of .

                northwind:Product (products.ProductID)
                        northwind:is_product_of
                northwind:OrderLine (order_lines.OrderID, order_lines.ProductID) where (^{products.}^.ProductID = ^{order_lines.}^.ProductID) as virtrdf:Product-is_product_of .

                northwind:Country (countries.Name)
                        a northwind:Country
                                as virtrdf:Country-Type2 ;
                        a wgs:SpatialThing
                                as virtrdf:Country-Type ;
                        owl:sameAs northwind:dbpedia_iri (countries.Name) ;
                        northwind:name countries.Name
                                as virtrdf:Country-Name ;
                        northwind:code countries.Code
                                as virtrdf:Country-Code ;
                        northwind:smallFlagDAVResourceName countries.SmallFlagDAVResourceName
                                as virtrdf:Country-SmallFlagDAVResourceName ;
                        northwind:largeFlagDAVResourceName countries.LargeFlagDAVResourceName
                                as virtrdf:Country-LargeFlagDAVResourceName ;
                        northwind:smallFlagDAVResourceURI northwind:Flag(countries.SmallFlagDAVResourceURI)
                                as virtrdf:Country-SmallFlagDAVResourceURI ;
                        northwind:largeFlagDAVResourceURI northwind:Flag(countries.LargeFlagDAVResourceURI)
                                as virtrdf:Country-LargeFlagDAVResourceURI ;
                        wgs:lat countries.Lat
                                as virtrdf:Country-Lat ;
                        wgs:long countries.Lng
                                as virtrdf:Country-Lng ;
                        rdfs:isDefinedBy northwind:country_iri (countries.Name) ;
                        rdfs:isDefinedBy northwind:Country (countries.Name) .

                northwind:Country (countries.Name)
                        northwind:has_province
                northwind:Province (provinces.CountryCode, provinces.Province) where (^{provinces.}^.CountryCode = ^{countries.}^.Code) as virtrdf:Country-has_province .

                northwind:Province (provinces.CountryCode, provinces.Province)
                        a northwind:Province
                                as virtrdf:Province-Provinces ;
                        northwind:has_country_code provinces.CountryCode
                                as virtrdf:has_country_code ;
                        northwind:provinceName provinces.Province
                                as virtrdf:Province-ProvinceName ;
                        rdfs:isDefinedBy northwind:province_iri (provinces.CountryCode, provinces.Province) ;
                        rdfs:isDefinedBy northwind:Province (provinces.CountryCode, provinces.Province) .

                northwind:Province (provinces.CountryCode, provinces.Province)
                        northwind:is_province_of
                northwind:Country (countries.Name) where  (^{countries.}^.Code = ^{provinces.}^.CountryCode) as virtrdf:Province-country_of .
        }.
}.
;

The created RDF View is sufficient for querying relational data via SPARQL but not for accessing data by dereferencing IRIs of subjects. Making IRIs dereferenceable requires configuring HTTP server; that is explained in second part of the example.


15.8.5. Configuring RDF Storages

"Quad Storage" is a named set of quad map patterns. The declaration define input:storage storage-name states that a SPARQL query will be executed using only quad patterns of the given quad storage. Declarations of IRI classes, literal classes and quad patterns are shared between all quad storages of an RDF meta schema but every quad storage contains only a subset of all available quad patterns. Two quad storages are always defined:

Three statements for manipulating storages are

A map pattern can be created only as a part of create quad storage or alter quad storage statement, so initially it is used by exactly one storage. It can be imported to some other storage using directive create map-id using storage source-storage. E.g., declarations of many storages create virtrdf:DefaultQuadMap using storage virtrdf:DefaultQuadStorage.

Only a "top-level" quad map pattern (standalone or a whole group with descendants) can be imported, member of a group can not. The import directive also can not be a part of some group declaration.

The directive drop quad map map-name removes a map from one storage when it appears inside alter quad storage statement. Otherwise it removes the map from all storages. There exists garbage collection for quad map patterns, so any unused map is immediately deleted. A group is deleted with all its descendants.


15.8.6. Translation Of SPARQL Triple Patterns To Quad Map Patterns

When a SPARQL query is compiled into SQL using a quad storage, every triple pattern should become a subquery that retrieves data from relational tables. This subquery is an UNION ALL of joins generated from appropriate quad map patterns. The complete SQL query is composed from these basic subqueries. Thus the first operation of the SQL generation for a triple pattern is searching for quad map patterns that may in principle produce triples that match the triple pattern.

The more restrictions contained in the triple pattern the fewer quad map patterns will be used. A triple pattern graph ?g { ?s ?p ?o } is common enough to invoke all data transformations of the storage. A triple pattern graph <g> { ?s <p> <o> } will usually intersect with the range of only one quad map. Sometimes it is possible to prove that the storage can not contain any data that matches the given triple pattern, hence zero number of members of UNION ALL will result in constantly empty result-set.

The search for quad maps for a given pair of triple pattern and quad map storage is quite simple. The storage is treated as a tree of map patterns where quad map patterns are leafs, grouping patterns are inner nodes and the whole storage is also treated as a grouping pattern that specify no fields and contains all top-level map patterns of the storage.

The tree is traversed from the root, left to right, non-leaf vertex are checked before their children. The check of a vertex consists of up to four field checks, for G, S, P and O. Every field check compares the field definition in the vertex and the corresponding field in the triple pattern, G and G, S and S and so on. Note that a non-leaf vertex defines less than four of its fields, e.g., the root vertex does not define any of its fields and top-level graph map { ... } defines only graph. Checks are performed only for defined fields and return one of three values: "failed", "passed", "full match", according to the following rules:

Table: 15.8.6.1. Matching Triple Field and Vertex Field
Field of vertex Field in triple pattern Result
constant same constant full match
constant different constant failed
constant variable of same type passed
constant variable of different type failed
quad map value constant of same type full match
quad map value constant of different type failed
quad map value of type X variable, X or subtype of X full match
quad map value of type X variable, supertype of X passed
quad map value of type X variable, type does not intersect with X failed

If any of the checks fails, the vertex and all its children are excluded from the rest of processing. Otherwise, if all four fields are defined for the quad map pattern, the map is added to the list of matching map patterns. The difference between "passed" and "full match" is significant only if the map is declared with option (exclusive) If all performed checks return "full match" and option (exclusive) is set then the traverse of the tree is stopped as soon as all children of the vertex are traversed. The most typical use of this option is when the application developer is sure that all triples of a graph belong to his application and they come from his own quad map patterns, not from DB.DBA.RDF_QUAD. This is to prevent the SPARQL compiler from generating redundant subqueries accessing DB.DBA.RDF_QUAD. The declaration may look like

create quad storage <mystorage>
  {
    graph <mygraph> option (exclusive) { . . . }
    create virtrdf:DefaultQuadMap
      using storage virtrdf:DefaultQuadStorage .
  }

Exclusive patterns make the order of declarations important, because an exclusive declaration may "throw a shadow" on declarations after it. Consider a database that have a special table RDF_TYPE that caches all RDF types of all subjects in all graphs. Consider two declarations: all triples from graph <http://myhost/sys> and all triples with rdf:type predicate, both exclusive:

graph <http://myhost/sys> option (exclusive)
  {
    . . . # mapping of DB.DBA.SYS_USERS as in previous examples.
  }
graph rdfdf:default-iid-nonblank (DB.DBA.RDF_TYPE.G)
subject rdfdf:default-iid (DB.DBA.RDF_TYPE.S)
predicate rdf:type
object rdfdf:default (DB.DBA.RDF_TYPE.O)
option (exclusive)

The order of these declarations dictates that triple pattern

graph <http://myhost/sys> {?s rdf:type ?o}

is compiled using only quad map patterns of the graph declaration, ignoring second declaration (and of course ignoring default mapping rule, if any). An explicit option (order N) at the end of quad map pattern will tweak the priority. By default, order will grow from 1000 for the first declaration in the statement to 1999 for the last, explicit configuration is especially useful to make order persistent to alter storage statements.

The option (exclusive) trick is ugly, low-level and prone to cause compilation errors after altering storage declarations. When misused, it is as bad as "red cut" in PROLOG, but one must use this trick to build scalable storages.

The option (exclusive) helps the SPARQL compiler to prepare better SQL queries, but sometimes it is "too exclusive". For instance, if a grouping quad map pattern specify only quad map value for graph and no other fields then making it exclusive prohibits the use of all declarations of the storage after that one. Sometimes it is better to notify compiler that quads made by the given quad map pattern are supposed to be different from all quads made by declarations listed after the given one.

Consider an application that exports users' personal data as graphs whose IRIs looks like http://www.example.com/DAV/home/username/RDF/personal/; the application makes a query and a triple pattern is proven to be restrictive enough to filter out all quads that are not similar to quads generated by the given quad map pattern (say, the graph is constant http://www.example.com/DAV/home/JohnSmith/RDF/personal/). The application do not hope to find any quads that match the pattern but made by other applications, because graphs named like in the pattern are supposed to be solely for this single purpose; if, say, DB.DBA.RDF_QUAD occasionally contains some quads with graph equal to http://www.example.com/DAV/home/JohnSmith/RDF/personal/ then they can be ignored.

Under this circumstances, the quad map pattern may have option (soft exclusive). That grants a permission to the compiler to ignore rest of storage as soon as it is proven that the triple pattern can not access quads that does not match the pattern. So if that is proven then the pattern is exclusive and it makes the query faster; when unsure, the complier work like there is no option at all.

Note:

The option (exclusive) can be used as a security measure, option (soft exclusive) can not. Say, if an financial application exports its data as a single graph http://www.example.com/front-office/cash/ using exclusive then the query that explicitly refers to that graph will never access any quads written by the attacker into DB.DBA.RDF_QUAD using same graph IRI. The use of soft exclusive gives no such protection. From the compiler's perspective, the option (soft exclusive) is a hint that may be ignored, not an unambiguous order.

There is one exception from the rules described above. This exception is for virtrdf:DefaultQuadStorage only. If a graph variable of a quad map pattern is not bound and no source graph specified by FROM clauses then quad maps for specific constant graphs are ignored. In other words, if a default quad storage contains quad maps for specific graphs then the query in that storage should explicitly specify the graph in order to use a map for graph. This rule will not work if the default quad map is removed from the virtrdf:DefaultQuadStorage. This rule relates to the default storage itself, not to the containing patterns; copying some or all patterns into other storage will not reproduce there this special effect.


15.8.7. Describing Source Relational Tables

Quad map patterns of an application usually share a common set of source tables and quad map values of one pattern usually share either a single table or very small number of joined tables. Join and filtering conditions are also usually repeated in different patterns. It is not necessary to type table descriptions multiple times, they are declare once in the beginning of storage declaration statement and shared between all quad map declarations inside the statement. Names of aliases can be used instead of table names in quad map values.

from DB.DBA.SYS_USERS as user where (^{user.}^.U_IS_ROLE = 0)
from DB.DBA.SYS_USERS as group where (^{group.}^.U_IS_ROLE = 1)
from DB.DBA.SYS_USERS as account
from user as active_user
  where (^{active_user.}^.U_ACCOUNT_DISABLED = 0)
from DB.DBA.SYS_ROLE_GRANTS as grant
  where (^{grant.}^.GI_SUPER = ^{account.}^.U_ID)
  where (^{grant.}^.GI_SUB = ^{group.}^.U_ID)
  where (^{grant.}^.GI_SUPER = ^{user.}^.U_ID)

This declares five distinct aliases for two distinct tables, and six filtering conditions. Every condition is an SQL expression with placeholders where a reference to the table should be printed. The SPARQL compiler will not try to parse texts of these expressions (except dummy search for placeholders), so any logical expressions are acceptable. When a quad map pattern declaration refers to some aliases, the WHERE clause of the generated SQL code will contain a conjunction of all distinct texts of "relevant" conditions. A condition is relevant if every alias inside the condition is used in some quad map value of the map pattern, either directly or via clause like from user as active_user. (user is a "base alias" for active_user).

Consider a group of four declarations.

graph <http://myhost/sys>
  {
    oplsioc:user_iri (active_user.U_ID)
        a oplsioc:active-user .
    oplsioc:membership_iri (grant.GI_SUPER, grant.GI_SUB).
        oplsioc:is_direct
            grant.GI_DIRECT ;
        oplsioc:member-e-mail
            active_user.U_E_MAIL
               where (^{active_user.}^.U_E_MAIL like 'mailto:%').
    ldap:account-ref (account.U_NAME)
        ldap:belongs-to
            ldap:account-ref (group.U_NAME) option (using grant).
  }

The first declaration will extend <http://myhost/sys> graph with one imaginary triples { user a oplsioc:active-user } for every account record that is not a role and not disabled. The second declaration deals with membership records. A membership is a pair of a grantee ("super") and a granted role ("sub") stored as a row in DB.DBA.SYS_ROLE_GRANTS).

The second declaration states that every membership has oplsioc:is_direct property with value from GI_DIRECT column of that table (roles may be granted to other roles and users, so permissions are "direct" or "recursive").

The third declaration declares oplsioc:member-e-mail property of memberships. The value is a literal string from DB.DBA.SYS_USERS.U_E_MAIL, if the grantee is active (not disabled) and is not a role and its e-mail address starts with 'mailto:'. The join between DB.DBA.SYS_ROLE_GRANTS and DB.DBA.SYS_USERS is made by equality (GI_SUPER = U_ID) because the alias active_user in the declaration "inherits" all conditions specified for user. In addition, the SPARQL compiler will add one more condition to check if the U_E_MAIL is not null because the NULL value is not a valid object and it knows that U_E_MAIL is not declared as NOT NULL.

The last declaration contains an option clause. As usual, this indicates that the basic functionality is good for many tasks but not for all. In this declaration, the ldap:belongs-to property establishes a relation between grantee (subject) and a granted role (object). Both subject and object IRIs are based on account name, DB.DBA.SYS_USERS.U_NAME, so the quad map pattern contains two references to different aliases of DB.DBA.SYS_USERS but no alias for DB.DBA.SYS_ROLE_GRANTS. Hence the declaration could produce a triple for every row of the Cartesian product of the DB.DBA.SYS_USERS. To fix the problem, option (using alias-name) tells the compiler to process the alias-name as if it's used in some quad map value of the pattern.

It is an error to use an alias only in where clause of the quad map pattern but neither in values or in option (using alias-name). To detect more typos, an alias used in quad map values can not appear in option (using alias-name) clause.


15.8.8. Function-Based IRI Classes

Most of IRI classes can be declared by a sprintf format string, but sophisticated cases may require calculations, not only printing the string. create IRI class using function allows the application transform relational values to IRIs by any custom routines.

Let us extend the previous example about users and groups by a new class for grantees. Both users and groups are grantees and we have defined two IRI classes for them. Classes oplsioc:user_iri and oplsioc:group_iri work fine for quad maps of U_ID if and only if the value of U_IS_ROLE is accordingly restricted to FALSE or TRUE, otherwise one may occasionally generate, say, user IRI for a group. To create and parse IRIs that correspond to any U_IDs, two functions should be created:

create function DB.DBA.GRANTEE_URI (in id integer)
returns varchar
{
  declare isrole integer;
  isrole := coalesce ((select top 1 U_IS_ROLE
      from DB.DBA.SYS_USERS where U_ID = id ) );
  if (isrole is null)
    return NULL;
  else if (isrole)
    return sprintf ('http://%s/sys/group?id=%d', id);
  else
    return sprintf ('http://%s/sys/user?id=%d', id);
};
create function DB.DBA.GRANTEE_URI_INVERSE (in id_iri varchar)
returns integer
{
  declare parts any;
  parts := sprintf_inverse (id_iri,
      'http://myhost/sys/user?id=%d', 1 );
  if (parts is not null)
    {
      if (exists (select top 1 1 from DB.DBA.SYS_USERS
          where U_ID = parts[0] and not U_IS_ROLE ) )
        return parts[0];
    }
  parts := sprintf_inverse (id_iri,
      'http://myhost/sys/group?id=%d', 1 );
  if (parts is not null)
    {
      if (exists (select top 1 1 from DB.DBA.SYS_USERS
          where U_ID = parts[0] and U_IS_ROLE ) )
        return parts[0];
    }
  return NULL;
};

These functions may be more useful if the SPARQL web service endpoint is allowed to use them:

grant execute on DB.DBA.GRANTEE_URI to "SPARQL";
grant execute on DB.DBA.GRANTEE_URI_INVERSE to "SPARQL";

The next declaration creates an IRI class based on these two functions:

create iri class oplsioc:grantee_iri using
  function DB.DBA.GRANTEE_URI (in id integer)
    returns varchar,
  function DB.DBA.GRANTEE_URI_INVERSE (in id_iri varchar)
    returns integer .

In common case, IRI class declaration contains an N-array function that composes IRIs and N inverse functions that gets an IRI as an argument and extracts the Nth SQL value. IRI composing function should silently return NULL on incorrect arguments instead of error signal. Inverse functions should return NULL if the argument has an incorrect type or value.

It is possible to specify only composing function without any of inverse functions. However option (bijection) can not be used in that case, obviously.


15.8.9. Connection Variabes in IRI Classes

Writing function-based IRI class is overkill when the IRI can in principle be made by a sprintf_iri but the format should contain some context-specific data, such as host name used for the dynamic renaming of local IRIs. Format strings offer a special syntax for that cases. %{varname}U acts as %U but the function sprintf will take the value from client connection variable varname, not from list of arguments. Similarly, sprintf_inverse will not return fragment that match to %{varname}U in the vector of other fragments; instead it will get the value from connection environment and ensure that it matches the fragment of input; mismatch between printed and actual value of variable will means that the whole string do not match the format.

SPARQL optimizer knows about this formatting feature and sometimes it makes more deductions from occurence of %{varname}U than from occurence of plain %U, so this notation may be used in option ( returns ...) when appropriate. Of course, the optimizer has no access to the actual value of conection variabe because it may vary from run to run or may change between the compilation and the run, but the value is supposed to be persistent during any single query run so %{myvariable}U in one place is equal to %{myvariable}U in other.

Connection variables are set by connection_set and some of them have default values that are used if not overridden by application:

It is inconvenient to write different format strings for different cases. Two most common policies are different host names for default HTTP port of a publicly available service and different non-default ports for one or more host names of an intranet instalation; these two approaches are almost never used in a mix. So declaration of IRI classes may use shorthand ^{DynamicLocalFormat}^ in format strings that is expanded either to http://%{WSHost}U or to http://%{WSHostName}U:%{WSHostPort}U/..., depending on absence or presence of port number in the value of DefaultHost parameter of URIQA section of configuration file.

Note:

^{DynamicLocalFormat}^ is for IRI class declarations only and is not expanded in any other place, so it is useful sometimes to create an IRI class with empty argument list in order to get "almost constant" IRIs calculated without writing special procedures.


15.8.10. Lookup Optimization -- BIJECTION and RETURNS Options

There is one subtle problem with IRI class declarations. To get benefit from a relational index, SPARQL optimizer should compose equality between table column and some known SQL value, not between return value of IRI class and a known composed IRI. In addition, redundant calculations of IRIs takes time. To enable this optimization, an IRI class declaration should end with option (bijection) clause. For some simple format strings the compiler may recognize the bijection automatically but an explicit declaration is always a good idea.

Note:

See also: Wikipedia - Bijection. In mathematics, a bijection, or a bijective function is a function f from a set X to a set Y such that, for every y in Y, there is exactly one x in X such that f(x) = y.

Alternatively, f is bijective if it is a one-to-one correspondence between those sets; i.e., both one-to-one (injective) and onto (surjective).

The SPARQL compiler may produce big amounts of SQL code when the query contains equality of two calculated IRIs and these IRIs may come from many different IRI classes. It is possible to provide hints that will let the compiler check if two IRI classes form disjoint sets of possible IRI values. The more disjoint sets are found the less possible combinations remain so the resulting SQL query will contain fewer unions of joins. The SPARQL compiler can prove some properties of sprintf format strings. E.g., it can prove that set of all strings printed by "http://example.com/item%d" and the set of strings printed by "http://example.com/item%d/" are disjoint. It can prove some more complicated statements about unions and intersections of sets of strings. The IRI or literal class declaration may contain option (returns ...) clause that will specify one or more sprintf patterns that cover the set of generated values. Consider a better version of IRI class declaration listed above:

create iri class oplsioc:grantee_iri using
  function DB.DBA.GRANTEE_URI (in id integer)
    returns varchar,
  function DB.DBA.GRANTEE_URI_INVERSE (in id_iri varchar)
    returns integer
  option ( bijection,
    returns "http://myhost/sys/group?id=%d"
    union   "http://myhost/sys/user?id=%d" ) .

It is very important to keep IRI classes easily distinguishable by the text of IRI string and easy to parse.

In some cases option (returns ...) can be used for IRI classes that are declared using sprintf format, but actual data have more specific format. Consider a literal class declaration that is used to output strings and the application knows that all these strings are ISBN numbers:

create literal class example:isbn_ref "%s" (in isbn varchar not null)
  option ( bijection, returns "%u-%u-%u-%u" union "%u-%u-%u-X" )

Sometimes interoperability restrictions will force you to violate these rules but please try to follow them as often as possible.


15.8.11. Join Optimization -- Declaring IRI Subclasses

Additional problem appears when the equality is between two IRIs of two different IRI classes. Even if both of them are bijections, the compiler does not know if these IRI classes behave identically on the intersection of their domains. To let the optimizer know this fact, one IRI class can be explicitly declared as a subclass of another:

make oplsioc:user_iri subclass of oplsioc:grantee_iri .
make oplsioc:group_iri subclass of oplsioc:grantee_iri .

The SPARQL compiler can not check the validity of a subclass declaration. The developer should carefully test functions to ensure that transformations are really subclasses, as well as to ensure that functions of an IRI class declarations are really inverse to each other.

When declaring that a table's primary key is converted into a IRI according to one IRI class, one usually declares that all foreign keys referring to this class also get converted into an IRI as per this same class, or subclass of same class.

Subclasses can be declared for literal classes as well as for IRI classes, but this case is rare. The reason is that most of literals are made by identity literal classes that are disjoint to each other even if values may be equal in SQL sense, such as "2" of type xsd:integer and "2.0" of type xsd:double.


15.8.12. RDF Metadata Maintenance and Recovery

This section refers to checking and backing up RDF view and storage declarations only. The checks and backup/restore do not affect physical quads, relational schema or tables or data therein. For general backup and restore, see server administration. To detect and fix automatically most popular sorts of RDF metadata corruption use DB.DBA.RDF_AUDIT_METADATA. It is also possible to backup RDF data by DB.DBA.RDF_BACKUP_METADATA and restore the saved state later by using DB.DBA.RDF_RESTORE_METADATA. It is convenient to make a backup before any modification of quad storages, quad map patterns or IRI classes, especially during debugging new RDF Views.

Note:

In SQL, adding a new view can not break anything. This is because SQL lacks the ability of querying "everything" so data sources are always specified. This is not true for SPARQL, so please treat any metadata manipulation as potentially destructive operation. If an RDF storage is supposed to be used by more than one application then these applications should be tested together, not one after other, and they should be installed/upgraded on live database in the very same order as they were installed/upgraded on istrumental machine during testing. Always remember that these applications share RDF tables so they may interfere.


15.8.13. Split RDF View

RDF View can be created by two or more "sparql alter storage" statements. In each statement can be created one quad map that contains mappings for half or a third of all tables. Quad maps created should have distinct names but may mention same graph. The important fact is that if the RDF View in question is exclusive for a graph then only the last quad map should be exclusive but all previous should not have this option. This is because if a map is exclusive on a graph the rest of maps on that graph will be silently ignored.

The example below shows a sample part of the Virtuoso eCRM Views code, where the RDF view is split in two parts: with quad map virtrdf:ecrmDemo1 and with quad map virtrdf:ecrmDemo2:

SPARQL
prefix ecrm: <http://demo.openlinksw.com/schemas/ecrm#>
prefix oplsioc: <http://www.openlinksw.com/schemas/oplsioc#>
prefix sioc: <http://rdfs.org/sioc/ns#>
prefix foaf: <http://xmlns.com/foaf/0.1/>
prefix cal: <http://www.w3.org/2002/12/cal/ical#>
prefix geo: <http://www.w3.org/2003/01/geo/wgs84_pos#>
prefix product: <http://www.swop-project.eu/ontologies/pmo/product.owl#>
prefix owl: <http://www.w3.org/2002/07/owl#>
drop quad map virtrdf:ecrmDemo1 .
;

SPARQL
prefix ecrm: <http://demo.openlinksw.com/schemas/ecrm#>
prefix oplsioc: <http://www.openlinksw.com/schemas/oplsioc#>
prefix sioc: <http://rdfs.org/sioc/ns#>
prefix foaf: <http://xmlns.com/foaf/0.1/>
prefix cal: <http://www.w3.org/2002/12/cal/ical#>
prefix geo: <http://www.w3.org/2003/01/geo/wgs84_pos#>
prefix product: <http://www.swop-project.eu/ontologies/pmo/product.owl#>
prefix owl: <http://www.w3.org/2002/07/owl#>
drop quad map virtrdf:ecrmDemo2 .
;

...

SPARQL
prefix ecrm: <http://demo.openlinksw.com/schemas/ecrm#>
prefix oplsioc: <http://www.openlinksw.com/schemas/oplsioc#>
prefix sioc: <http://rdfs.org/sioc/ns#>
prefix foaf: <http://xmlns.com/foaf/0.1/>
prefix cal: <http://www.w3.org/2002/12/cal/ical#>
prefix geo: <http://www.w3.org/2003/01/geo/wgs84_pos#>
prefix product: <http://www.swop-project.eu/ontologies/pmo/product.owl#>
prefix owl: <http://www.w3.org/2002/07/owl#>
alter quad storage virtrdf:DefaultQuadStorage
from eCRM.DBA.SFA_SALES_QUOTA_VIEW2 as sales_quotas
from eCRM.DBA.SFA_COMPANIES_VIEW2 as companies
from eCRM.DBA.SFA_COMPANIES as companies_table text literal companies_table.DESCRIPTION of (companies.DESCRIPTION)
from eCRM.DBA.SFA_CONTACTS_VIEW2 as contacts
from eCRM.DBA.SFA_CONTACTS as contacts_table text literal contacts_table.NAME_FIRST of (contacts.NAME_FIRST)
from eCRM.DBA.SFA_EMPLOYMENTS_VIEW2 as employments
from eCRM.DBA.SFA_LEADS_VIEW2 as leads
from eCRM.DBA.SFA_LEADS as leads_table text literal leads_table.SUBJECT of (leads.SUBJECT)
from eCRM.DBA.SFA_OPPORTUNITIES_VIEW2 as opportunities
from eCRM.DBA.SFA_OPPORTUNITIES as opportunities_table text literal opportunities_table.OPPORTUNITY_NAME of (opportunities.OPPORTUNITY_NAME)
from eCRM.DBA.SFA_ACTIVITIES as activities
from eCRM.DBA.SFA_MAIL_MESSAGES as messages
from eCRM.DBA.SFA_DOCUMENTS_VIEW2 as documents
from eCRM.DBA.SFA_INFLUENCERS_VIEW2 as influencers
from eCRM.DBA.SFA_TEAMS_VIEW2 as teams
from eCRM.DBA.SFA_NOTES_VIEW2 as notes
from eCRM.DBA.SFA_NOTES as notes_table text literal notes_table.DESCRIPTION of (notes.DESCRIPTION)
from eCRM.DBA.SFA_COMPETITORS_VIEW2 as competitors
from eCRM.DBA.SFA_ISSUES_VIEW2 as issues
from eCRM.DBA.SFA_CUSTOM_FIELD_DEFS_VIEW2 as custom_field_defs
from eCRM.DBA.SFA_CUSTOM_FIELDS_VIEW2 as custom_fields
from eCRM.DBA.SFA_CASES_VIEW2 as cases
from eCRM.DBA.SFA_CASES as cases_table text literal cases_table.SUMMARY of (cases.SUMMARY)
from eCRM.DBA.SFA_ORDERS_VIEW2 as orders
from eCRM.DBA.SFA_ORDERS as orders_table text literal orders_table.EMAIL of (orders.EMAIL)
from eCRM.DBA.SFA_ORDER_ITEMS_VIEW2 as order_items
from eCRM.DBA.PM_CATEGORIES_VIEW2 as categories
from eCRM.DBA.PM_PRODUCT_ATTRIBUTE_DEFS_VIEW2 as product_attribute_defs
from eCRM.DBA.PM_PRODUCTS_VIEW2 as products
from eCRM.DBA.PM_PRODUCTS as products_table text literal products_table.DESCRIPTION of (products.DESCRIPTION)
from eCRM.DBA.PM_PRODUCT_ATTRIBUTES_VIEW2 as product_attributes
from eCRM.DBA.PM_CATALOGS_VIEW2 as catalogs
from eCRM.DBA.PM_CATALOG_PRODUCTS_VIEW2 as catalog_products
from eCRM.DBA.XSYS_MODULES as modules
from eCRM.DBA.XSYS_REGISTRY as registries
from eCRM.DBA.XSYS_ORGANIZATIONS_DATA as organizations_data
from eCRM.DBA.XSYS_MESSAGES as xsysmessages
from eCRM.DBA.XSYS_COUNTRIES_VIEW2 as countries
from eCRM.DBA.XSYS_PROVINCES_VIEW2 as provinces
from eCRM.DBA.XSYS_TIMEZONES as timezones
from eCRM.DBA.XSYS_MIME_TYPES as mimetypes
from eCRM.DBA.XSYS_MIME_EXTENSIONS as mimeexts
from eCRM.DBA.XSYS_CNAMES as cnames
from eCRM.DBA.XSYS_QUOTAS as quotas
from eCRM.DBA.XSYS_ROLES as roles
from eCRM.DBA.XSYS_ACCOUNTS as accounts
from eCRM.DBA.XSYS_USERDATA as userdatas
from eCRM.DBA.XSYS_GROUPDATA as groupdatas
from eCRM.DBA.XSYS_MEMBERS as members
from eCRM.DBA.XSYS_SESSIONS_DATA as sessionsdatas
from eCRM.DBA.XSYS_SESSION_DATA as sessiondatas
from eCRM.DBA.XSYS_LIST_MEMBERS_DEFS as list_members_defs
from eCRM.DBA.XSYS_CLASSES as classes
from eCRM.DBA.XSYS_ORG_CLASSES as org_classes
from eCRM.DBA.XSYS_CLASS_METHODS as class_methods
from eCRM.DBA.XSYS_CLASS_VIEWS as class_views
from eCRM.DBA.XSYS_ROLE_PRIVILEGES as role_priveleges
from eCRM.DBA.XSYS_USER_PRIVILEGES as user_priveleges
from eCRM.DBA.XSYS_HISTORY as history
from eCRM.DBA.XSYS_USERS as xsys_users
from eCRM.DBA.AP_PROCESSES_VIEW2 as ap_processes
from eCRM.DBA.AP_RULES_VIEW2 as ap_rules
from eCRM.DBA.AP_QUEUE as ap_queues
where (^{companies.}^.COUNTRY_NAME = ^{countries.}^.COUNTRY_NAME)
where (^{contacts.}^.COUNTRY_NAME = ^{countries.}^.COUNTRY_NAME)
where (^{leads.}^.COUNTRY_NAME = ^{countries.}^.COUNTRY_NAME)
where (^{products.}^.COUNTRY_NAME = ^{countries.}^.COUNTRY_NAME)
where (^{orders.}^.SHIP_COUNTRY_NAME = ^{countries.}^.COUNTRY_NAME)
where (^{leads_table.}^.FREETEXT_ID = ^{leads.}^.FREETEXT_ID)
where (^{contacts_table.}^.FREETEXT_ID = ^{contacts.}^.FREETEXT_ID)
where (^{companies_table.}^.FREETEXT_ID = ^{companies.}^.FREETEXT_ID)
where (^{opportunities_table.}^.FREETEXT_ID = ^{opportunities.}^.FREETEXT_ID)
where (^{cases_table.}^.FREETEXT_ID = ^{cases.}^.FREETEXT_ID)
where (^{notes_table.}^.FREETEXT_ID = ^{notes.}^.FREETEXT_ID)
where (^{orders_table.}^.FREETEXT_ID = ^{orders.}^.FREETEXT_ID)
where (^{products_table.}^.FREETEXT_ID = ^{products.}^.FREETEXT_ID)
{
        create virtrdf:ecrmDemo1 as graph iri ("http://^{URIQADefaultHost}^/ecrm") option (order 1501)
        {
            ecrm:Country (countries.COUNTRY_NAME)
                a ecrm:Country
                    as virtrdf:Country-Countrys2 ;
                a geo:SpatialThing
                    as virtrdf:Country-Countrys ;
                owl:sameAs ecrm:dbpedia_iri (countries.COUNTRY_NAME) ;
                ecrm:countryID countries.COUNTRY_ID
                        as virtrdf:Country-COUNTRY_ID ;
                ecrm:countryID3 countries.COUNTRY_ID3
                        as virtrdf:Country-COUNTRY_ID3 ;
                ecrm:isoCode countries.ISO_CODE
                        as virtrdf:Country-ISO_CODE ;
                ecrm:countryName countries.COUNTRY_NAME
                        as virtrdf:Country-COUNTRY_NAME .

            ecrm:Country (countries.COUNTRY_NAME)
                        ecrm:has_province
            ecrm:Province (provinces.COUNTRY_ID, provinces.PROVINCE_NAME) where
                        (^{provinces.}^.COUNTRY_ID = ^{countries.}^.COUNTRY_ID) as virtrdf:ecrmCountry-has_province .

...
  } .
} .
;
SPARQL
prefix ecrm: <http://demo.openlinksw.com/schemas/ecrm#>
prefix oplsioc: <http://www.openlinksw.com/schemas/oplsioc#>
prefix sioc: <http://rdfs.org/sioc/ns#>
prefix foaf: <http://xmlns.com/foaf/0.1/>
prefix geo: <http://www.w3.org/2003/01/geo/wgs84_pos#>
prefix cal: <http://www.w3.org/2002/12/cal/ical#>
prefix product: <http://www.swop-project.eu/ontologies/pmo/product.owl#>
prefix owl: <http://www.w3.org/2002/07/owl#>
alter quad storage virtrdf:DefaultQuadStorage
from eCRM.DBA.SFA_SALES_QUOTA_VIEW2 as sales_quotas
from eCRM.DBA.SFA_COMPANIES_VIEW2 as companies
from eCRM.DBA.SFA_COMPANIES as companies_table text literal companies_table.DESCRIPTION of (companies.DESCRIPTION)
from eCRM.DBA.SFA_CONTACTS_VIEW2 as contacts
from eCRM.DBA.SFA_CONTACTS as contacts_table text literal contacts_table.NAME_FIRST of (contacts.NAME_FIRST)
from eCRM.DBA.SFA_EMPLOYMENTS_VIEW2 as employments
from eCRM.DBA.SFA_LEADS_VIEW2 as leads
from eCRM.DBA.SFA_LEADS as leads_table text literal leads_table.SUBJECT of (leads.SUBJECT)
from eCRM.DBA.SFA_OPPORTUNITIES_VIEW2 as opportunities
from eCRM.DBA.SFA_OPPORTUNITIES as opportunities_table text literal opportunities_table.OPPORTUNITY_NAME of (opportunities.OPPORTUNITY_NAME)
from eCRM.DBA.SFA_ACTIVITIES as activities
from eCRM.DBA.SFA_MAIL_MESSAGES as messages
from eCRM.DBA.SFA_DOCUMENTS_VIEW2 as documents
from eCRM.DBA.SFA_INFLUENCERS_VIEW2 as influencers
from eCRM.DBA.SFA_TEAMS_VIEW2 as teams
from eCRM.DBA.SFA_NOTES_VIEW2 as notes
from eCRM.DBA.SFA_NOTES as notes_table text literal notes_table.DESCRIPTION of (notes.DESCRIPTION)
from eCRM.DBA.SFA_COMPETITORS_VIEW2 as competitors
from eCRM.DBA.SFA_ISSUES_VIEW2 as issues
from eCRM.DBA.SFA_CUSTOM_FIELD_DEFS_VIEW2 as custom_field_defs
from eCRM.DBA.SFA_CUSTOM_FIELDS_VIEW2 as custom_fields
from eCRM.DBA.SFA_CASES_VIEW2 as cases
from eCRM.DBA.SFA_CASES as cases_table text literal cases_table.SUMMARY of (cases.SUMMARY)
from eCRM.DBA.SFA_ORDERS_VIEW2 as orders
from eCRM.DBA.SFA_ORDERS as orders_table text literal orders_table.EMAIL of (orders.EMAIL)
from eCRM.DBA.SFA_ORDER_ITEMS_VIEW2 as order_items
from eCRM.DBA.PM_CATEGORIES_VIEW2 as categories
from eCRM.DBA.PM_PRODUCT_ATTRIBUTE_DEFS_VIEW2 as product_attribute_defs
from eCRM.DBA.PM_PRODUCTS_VIEW2 as products
from eCRM.DBA.PM_PRODUCTS as products_table text literal products_table.DESCRIPTION of (products.DESCRIPTION)
from eCRM.DBA.PM_PRODUCT_ATTRIBUTES_VIEW2 as product_attributes
from eCRM.DBA.PM_CATALOGS_VIEW2 as catalogs
from eCRM.DBA.PM_CATALOG_PRODUCTS_VIEW2 as catalog_products
from eCRM.DBA.XSYS_MODULES as modules
from eCRM.DBA.XSYS_REGISTRY as registries
from eCRM.DBA.XSYS_ORGANIZATIONS_DATA as organizations_data
from eCRM.DBA.XSYS_MESSAGES as xsysmessages
from eCRM.DBA.XSYS_COUNTRIES_VIEW2 as countries
from eCRM.DBA.XSYS_PROVINCES_VIEW2 as provinces
from eCRM.DBA.XSYS_TIMEZONES as timezones
from eCRM.DBA.XSYS_MIME_TYPES as mimetypes
from eCRM.DBA.XSYS_MIME_EXTENSIONS as mimeexts
from eCRM.DBA.XSYS_CNAMES as cnames
from eCRM.DBA.XSYS_QUOTAS as quotas
from eCRM.DBA.XSYS_ROLES as roles
from eCRM.DBA.XSYS_ACCOUNTS as accounts
from eCRM.DBA.XSYS_USERDATA as userdatas
from eCRM.DBA.XSYS_GROUPDATA as groupdatas
from eCRM.DBA.XSYS_MEMBERS as members
from eCRM.DBA.XSYS_SESSIONS_DATA as sessionsdatas
from eCRM.DBA.XSYS_SESSION_DATA as sessiondatas
from eCRM.DBA.XSYS_LIST_MEMBERS_DEFS as list_members_defs
from eCRM.DBA.XSYS_CLASSES as classes
from eCRM.DBA.XSYS_ORG_CLASSES as org_classes
from eCRM.DBA.XSYS_CLASS_METHODS as class_methods
from eCRM.DBA.XSYS_CLASS_VIEWS as class_views
from eCRM.DBA.XSYS_ROLE_PRIVILEGES as role_priveleges
from eCRM.DBA.XSYS_USER_PRIVILEGES as user_priveleges
from eCRM.DBA.XSYS_HISTORY as history
from eCRM.DBA.XSYS_USERS as xsys_users
from eCRM.DBA.AP_PROCESSES_VIEW2 as ap_processes
from eCRM.DBA.AP_RULES_VIEW2 as ap_rules
from eCRM.DBA.AP_QUEUE as ap_queues
where (^{companies.}^.COUNTRY_NAME = ^{countries.}^.COUNTRY_NAME)
where (^{contacts.}^.COUNTRY_NAME = ^{countries.}^.COUNTRY_NAME)
where (^{leads.}^.COUNTRY_NAME = ^{countries.}^.COUNTRY_NAME)
where (^{products.}^.COUNTRY_NAME = ^{countries.}^.COUNTRY_NAME)
where (^{orders.}^.SHIP_COUNTRY_NAME = ^{countries.}^.COUNTRY_NAME)
where (^{leads_table.}^.FREETEXT_ID = ^{leads.}^.FREETEXT_ID)
where (^{contacts_table.}^.FREETEXT_ID = ^{contacts.}^.FREETEXT_ID)
where (^{companies_table.}^.FREETEXT_ID = ^{companies.}^.FREETEXT_ID)
where (^{opportunities_table.}^.FREETEXT_ID = ^{opportunities.}^.FREETEXT_ID)
where (^{cases_table.}^.FREETEXT_ID = ^{cases.}^.FREETEXT_ID)
where (^{notes_table.}^.FREETEXT_ID = ^{notes.}^.FREETEXT_ID)
where (^{orders_table.}^.FREETEXT_ID = ^{orders.}^.FREETEXT_ID)
where (^{products_table.}^.FREETEXT_ID = ^{products.}^.FREETEXT_ID)
{
        create virtrdf:ecrmDemo2 as graph iri ("http://^{URIQADefaultHost}^/ecrm") option (exclusive, order 1502)
        {
            ecrm:Order (orders.ORG_ID, orders.ORDER_ID)
                a ecrm:Order
                    as virtrdf:Order-Orders ;
                ecrm:has_ecrm_organization ecrm:OrganizationsData(orders.ORG_ID, organizations_data.DNS_ZONE) where (^{orders.}^.ORG_ID = ^{organizations_data.}^.ORG_ID)
                        as virtrdf:Order-ORG_ID ;
                ecrm:owner ecrm:XSys_User(orders.ORG_ID, xsys_users.ACCOUNT_NAME, orders.OWNER_ID)
                        where (^{orders.}^.OWNER_ID = ^{xsys_users.}^.ACCOUNT_ID and ^{orders.}^.ORG_ID = ^{xsys_users.}^.ORG_ID)
                        as virtrdf:Order-OWNER_ID ;
                ecrm:FREETEXT_ID orders.FREETEXT_ID
                        as virtrdf:Order-FREETEXT_ID ;
                ecrm:has_company ecrm:Company(orders.COMPANY_NAME, orders.COMPANY_ID, orders.ORG_ID)
                        as virtrdf:Order-COMPANY_ID ;
                ecrm:companyName orders.COMPANY_NAME
                        as virtrdf:Order-COMPANY_NAME ;
                ecrm:has_contact ecrm:Contact(contacts.NAME_FIRST, contacts.NAME_MIDDLE, contacts.NAME_LAST, orders.CONTACT_ID, orders.ORG_ID)
                        where (^{orders.}^.CONTACT_ID = ^{contacts.}^.CONTACT_ID and ^{orders.}^.ORG_ID = ^{contacts.}^.ORG_ID)
                        as virtrdf:Order-CONTACT_ID ;
                ecrm:contactName orders.CONTACT_NAME
                        as virtrdf:Order-CONTACT_NAME ;
                ecrm:orderNo orders.ORDER_NO
                        as virtrdf:Order-ORDER_NO ;
                ecrm:shipFirstName orders.SHIP_FNAME
                        as virtrdf:Order-SHIP_FNAME ;
                ecrm:shipSecondName orders.SHIP_SNAME
                        as virtrdf:Order-SHIP_SNAME ;
                ecrm:phoneNumber orders.PHONE_NUMBER
                        as virtrdf:Order-PHONE_NUMBER ;
                ecrm:phoneExtension orders.PHONE_EXTENSION
                        as virtrdf:Order-PHONE_EXTENSION ;
                ecrm:email orders.EMAIL
                        as virtrdf:Order-EMAIL ;
                ecrm:shipCountry ecrm:Country(orders.SHIP_COUNTRY_NAME)
                        as virtrdf:Order-SHIP_COUNTRY_NAME ;
                ecrm:shipCountryCode ecrm:Country (countries.COUNTRY_NAME) where  (^{countries.}^.COUNTRY_NAME = ^{orders.}^.SHIP_COUNTRY_NAME)
                        as virtrdf:Order-SHIP_COUNTRY_CODE ;
                ecrm:shipProvince orders.SHIP_PROVINCE
                        as virtrdf:Order-SHIP_PROVINCE ;
                ecrm:shipCity orders.SHIP_CITY
                        as virtrdf:Order-SHIP_CITY ;
                ecrm:dbpedia_shipCity ecrm:dbpedia_iri (orders.SHIP_CITY)
                        as virtrdf:Order-SHIP_dbpedia_CITY ;
                ecrm:shipPostalCode orders.SHIP_POSTAL_CODE
                        as virtrdf:Order-SHIP_POSTAL_CODE ;
                ecrm:shipAddress1 orders.SHIP_ADDRESS1
                        as virtrdf:Order-SHIP_ADDRESS1 ;
                ecrm:shipAddress2 orders.SHIP_ADDRESS2
                        as virtrdf:Order-SHIP_ADDRESS2 ;
                ecrm:salesRep orders.SALESREP
                        as virtrdf:Order-SALESREP ;
                ecrm:orderDate orders.ORDER_DATE
                        as virtrdf:Order-ORDER_DATE ;
                ecrm:orderValue orders.ORDER_VALUE
                        as virtrdf:Order-ORDER_VALUE ;
                ecrm:refund orders.REFUND
                        as virtrdf:Order-REFUND ;
                ecrm:year orders.YEAR
                        as virtrdf:Order-YEAR ;
                ecrm:month orders.MONTH
                        as virtrdf:Order-MONTH ;
                ecrm:quarter orders.QUARTER
                        as virtrdf:Order-QUARTER ;
                ecrm:financialYear orders.FINANCIAL_YEAR
                        as virtrdf:Order-FINANCIAL_YEAR ;
                ecrm:CONTACT_REL_ID orders.CONTACT_REL_ID
                        as virtrdf:Order-CONTACT_REL_ID ;
                ecrm:COMPANY_REL_ID orders.COMPANY_REL_ID
                        as virtrdf:Order-COMPANY_REL_ID .

...
        } .
} .
;


15.8.14. RDF views and recursive FK relationships

Here is sample example of a script to include an additional table alias for a table:

alter quad storage virtrdf:DefaultQuadStorage
  :
  from isports_rdf.prs10_isports_rdf.VRef_Call      as Ref_Call_tbl
  from isports_rdf.prs10_isports_rdf.VRef_Call      as Ref_Call_tbl_1
  :
{
  :
  refcall:ref-call_iri (Ref_Call_tbl.Call_Num) a refcall:Ref-Call as
virtrdf:ref-call_pk ;
  :
  refcall:has_parent  refcall:ref-call_iri (Ref_Call_tbl_1.Call_Num)
where  ( ^{Ref_Call_tbl.}^.Parent    = ^{Ref_Call_tbl_1.}^.Call_Num )   as
virtrdf:Ref-Call_has_parent .

This demonstrates the way to self-join the table VRef_Call with itself. Like in SQL, are needed two different aliases for one table if you want to join it with itself.


15.8.15. Enterprise Data Access & Integration

15.8.15.1. Virtuoso's Northwind based Demo Database (Tutorials variant) to RDF

use DB;

DB.DBA.exec_no_error('UPDATE WS.WS.SYS_DAV_RES set RES_TYPE=\'image/jpeg\' where RES_FULL_PATH like \'/DAV/VAD/demo/sql/CAT%\'')
;

DB.DBA.exec_no_error('UPDATE WS.WS.SYS_DAV_RES set RES_TYPE=\'image/jpeg\' where RES_FULL_PATH like \'/DAV/VAD/demo/sql/EMP%\'')
;

GRANT SELECT ON "Demo"."demo"."Products" TO "SPARQL";
GRANT SELECT ON "Demo"."demo"."Suppliers" TO "SPARQL";
GRANT SELECT ON "Demo"."demo"."Shippers" TO "SPARQL";
GRANT SELECT ON "Demo"."demo"."Categories" TO "SPARQL";
GRANT SELECT ON "Demo"."demo"."Customers" TO "SPARQL";
GRANT SELECT ON "Demo"."demo"."Employees" TO "SPARQL";
GRANT SELECT ON "Demo"."demo"."Orders" TO "SPARQL";
GRANT SELECT ON "Demo"."demo"."Order_Details" TO "SPARQL";
GRANT SELECT ON "Demo"."demo"."Countries" TO "SPARQL";
GRANT SELECT ON "Demo"."demo"."Provinces" TO "SPARQL";

SPARQL
prefix tut_northwind: <http://demo.openlinksw.com/schemas/tutorial/northwind#>
prefix oplsioc: <http://www.openlinksw.com/schemas/oplsioc#>
prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#>
prefix sioc: <http://rdfs.org/sioc/ns#>
prefix foaf: <http://xmlns.com/foaf/0.1/>
prefix owl: <http://www.w3.org/2002/07/owl#>
prefix wgs: <http://www.w3.org/2003/01/geo/wgs84_pos#>
drop quad map graph iri("http://^{URIQADefaultHost}^/tutorial/Northwind") .
;

SPARQL
prefix tut_northwind: <http://demo.openlinksw.com/schemas/tutorial/northwind#>
prefix oplsioc: <http://www.openlinksw.com/schemas/oplsioc#>
prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#>
prefix sioc: <http://rdfs.org/sioc/ns#>
prefix foaf: <http://xmlns.com/foaf/0.1/>
prefix owl: <http://www.w3.org/2002/07/owl#>
prefix wgs: <http://www.w3.org/2003/01/geo/wgs84_pos#>
drop quad map virtrdf:TutorialNorthwindDemo .
;

create function DB.DBA.TUT_NORTHWIND_ID_TO_IRI(in _prefix varchar,in _id varchar)
{
  declare iri, uriqa_host any;
  uriqa_host := cfg_item_value(virtuoso_ini_path(), 'URIQA','DefaultHost');
  iri := 'http://' || uriqa_host || '/tutorial/Northwind/' || _prefix || '/' || _id || '#this';
  return sprintf ('http://%s/DAV/VAD/tutorial/rdfview/rd_v_1/RDFData/All/iid%%20(%d).rdf', uriqa_host, iri_id_num (iri_to_id (iri)));
}
;

create function DB.DBA.TUT_NORTHWIND_IRI_TO_ID(in _iri varchar)
{
    declare parts any;
    parts := sprintf_inverse (_iri, 'http://%s/DAV/VAD/tutorial/rdfview/rd_v_1/RDFData/All/iid (%d).rdf', 1 );
    if (parts is not null)
    {
        declare uriqa_host, iri any;
        uriqa_host := cfg_item_value(virtuoso_ini_path(), 'URIQA','DefaultHost');
        if (parts[0] = uriqa_host)
        {
            iri := id_to_iri(iri_id_from_num(parts[1]));
            parts := sprintf_inverse (iri, 'http://%s/tutorial/Northwind/%s/%s#this', 1 );
            if (parts[0] = uriqa_host)
            {
                return parts[2];
            }
        }
    }
    return NULL;
}
;

create function DB.DBA.TUT_CATEGORY_IRI (in _id integer) returns varchar
{
    return TUT_NORTHWIND_ID_TO_IRI('Category', cast(_id as varchar));
}
;

create function DB.DBA.TUT_CATEGORY_IRI_INVERSE (in _iri varchar) returns integer
{
    return atoi(DB.DBA.TUT_NORTHWIND_IRI_TO_ID(_iri));
};

create function DB.DBA.TUT_SHIPPER_IRI (in _id integer) returns varchar
{
    return TUT_NORTHWIND_ID_TO_IRI('Shipper', cast(_id as varchar));
}
;

create function DB.DBA.TUT_SHIPPER_IRI_INVERSE (in _iri varchar) returns integer
{
    return atoi(DB.DBA.TUT_NORTHWIND_IRI_TO_ID(_iri));
};

create function DB.DBA.TUT_SUPPLIER_IRI (in _id integer) returns varchar
{
    return TUT_NORTHWIND_ID_TO_IRI('Supplier', cast(_id as varchar));
}
;

create function DB.DBA.TUT_SUPPLIER_IRI_INVERSE (in _iri varchar) returns integer
{
    return atoi(DB.DBA.TUT_NORTHWIND_IRI_TO_ID(_iri));
};

create function DB.DBA.TUT_PRODUCT_IRI (in _id integer) returns varchar
{
    return TUT_NORTHWIND_ID_TO_IRI('Product', cast(_id as varchar));
}
;

create function DB.DBA.TUT_PRODUCT_IRI_INVERSE (in _iri varchar) returns integer
{
    return atoi(DB.DBA.TUT_NORTHWIND_IRI_TO_ID(_iri));
};

create function DB.DBA.TUT_CUSTOMER_IRI (in _id varchar) returns varchar
{
    return TUT_NORTHWIND_ID_TO_IRI('Customer', _id);
}
;

create function DB.DBA.TUT_CUSTOMER_IRI_INVERSE (in _iri varchar) returns varchar
{
    return DB.DBA.TUT_NORTHWIND_IRI_TO_ID(_iri);
};

create function DB.DBA.TUT_EMPLOYEE_IRI (in _id integer) returns varchar
{
    return TUT_NORTHWIND_ID_TO_IRI('Employee', cast(_id as varchar));
}
;

create function DB.DBA.TUT_EMPLOYEE_IRI_INVERSE (in _iri varchar) returns integer
{
    return atoi(DB.DBA.TUT_NORTHWIND_IRI_TO_ID(_iri));
};

create function DB.DBA.TUT_ORDER_IRI (in _id integer) returns varchar
{
    return TUT_NORTHWIND_ID_TO_IRI('Order', cast(_id as varchar));
}
;

create function DB.DBA.TUT_ORDER_IRI_INVERSE (in _iri varchar) returns integer
{
    return atoi(DB.DBA.TUT_NORTHWIND_IRI_TO_ID(_iri));
};

create function DB.DBA.TUT_CUSTOMERCONTACT_IRI (in _id integer) returns varchar
{
    return TUT_NORTHWIND_ID_TO_IRI('CustomerContact', cast(_id as varchar));
}
;

create function DB.DBA.TUT_CUSTOMERCONTACT_IRI_INVERSE (in _iri varchar) returns integer
{
    return atoi(DB.DBA.TUT_NORTHWIND_IRI_TO_ID(_iri));
};

create function DB.DBA.TUT_ORDERLINE_IRI (in _id1 integer, in _id2 integer) returns varchar
{
    return TUT_NORTHWIND_ID_TO_IRI('OrderLine', sprintf('%d/%d', _id1, _id2));
}
;

create function DB.DBA.TUT_ORDERLINE_IRI_INV_1 (in _iri varchar) returns integer
{
    return atoi(DB.DBA.TUT_NORTHWIND_IRI_TO_ID(_iri));
};

create function DB.DBA.TUT_ORDERLINE_IRI_INV_2 (in _iri varchar) returns integer
{
    return atoi(DB.DBA.TUT_NORTHWIND_IRI_TO_ID(_iri));
};


create function DB.DBA.TUT_PROVINCE_IRI (in _id1 varchar, in _id2 varchar) returns varchar
{
    return TUT_NORTHWIND_ID_TO_IRI('Province', sprintf('%s/%s', _id1, _id2));
}
;

create function DB.DBA.TUT_PROVINCE_IRI_INV_1 (in _iri varchar) returns varchar
{
    return DB.DBA.TUT_NORTHWIND_IRI_TO_ID(_iri);
};

create function DB.DBA.TUT_PROVINCE_IRI_INV_2 (in _iri varchar) returns varchar
{
    return DB.DBA.TUT_NORTHWIND_IRI_TO_ID(_iri);
};

create function DB.DBA.TUT_COUNTRY_IRI (in _id varchar) returns varchar
{
    return TUT_NORTHWIND_ID_TO_IRI('Country', _id);
}
;

create function DB.DBA.TUT_COUNTRY_IRI_INVERSE (in _iri varchar) returns varchar
{
    return DB.DBA.TUT_NORTHWIND_IRI_TO_ID(_iri);
};

create function DB.DBA.TUT_FLAG_IRI (in _id varchar) returns varchar
{
    return TUT_NORTHWIND_ID_TO_IRI('Flag', _id);
}
;

create function DB.DBA.TUT_FLAG_IRI_INVERSE (in _iri varchar) returns varchar
{
    return DB.DBA.TUT_NORTHWIND_IRI_TO_ID(_iri);
};

create function DB.DBA.TUT_EMPLOYEEPHOTO_IRI (in _id integer) returns varchar
{
    return TUT_NORTHWIND_ID_TO_IRI('EmployeePhoto', cast(_id as varchar));
}
;

create function DB.DBA.TUT_EMPLOYEEPHOTO_IRI_INVERSE (in _iri varchar) returns integer
{
    return atoi(DB.DBA.TUT_NORTHWIND_IRI_TO_ID(_iri));
};

create function DB.DBA.TUT_CATEGORYPHOTO_IRI (in _id integer) returns varchar
{
    return TUT_NORTHWIND_ID_TO_IRI('CategoryPhoto', cast(_id as varchar));
}
;

create function DB.DBA.TUT_CATEGORYPHOTO_IRI_INVERSE (in _iri varchar) returns integer
{
    return atoi(DB.DBA.TUT_NORTHWIND_IRI_TO_ID(_iri));
};

grant execute on DB.DBA.TUT_CATEGORY_IRI to "SPARQL";
grant execute on DB.DBA.TUT_CATEGORY_IRI_INVERSE to "SPARQL";
grant execute on DB.DBA.TUT_SHIPPER_IRI to "SPARQL";
grant execute on DB.DBA.TUT_SHIPPER_IRI_INVERSE to "SPARQL";
grant execute on DB.DBA.TUT_SUPPLIER_IRI to "SPARQL";
grant execute on DB.DBA.TUT_SUPPLIER_IRI_INVERSE to "SPARQL";
grant execute on DB.DBA.TUT_PRODUCT_IRI to "SPARQL";
grant execute on DB.DBA.TUT_PRODUCT_IRI_INVERSE to "SPARQL";
grant execute on DB.DBA.TUT_CUSTOMER_IRI to "SPARQL";
grant execute on DB.DBA.TUT_CUSTOMER_IRI_INVERSE to "SPARQL";
grant execute on DB.DBA.TUT_EMPLOYEE_IRI to "SPARQL";
grant execute on DB.DBA.TUT_EMPLOYEE_IRI_INVERSE to "SPARQL";
grant execute on DB.DBA.TUT_ORDER_IRI to "SPARQL";
grant execute on DB.DBA.TUT_ORDER_IRI_INVERSE to "SPARQL";
grant execute on DB.DBA.TUT_CUSTOMERCONTACT_IRI to "SPARQL";
grant execute on DB.DBA.TUT_CUSTOMERCONTACT_IRI_INVERSE to "SPARQL";
grant execute on DB.DBA.TUT_ORDERLINE_IRI to "SPARQL";
grant execute on DB.DBA.TUT_ORDERLINE_IRI_INV_1 to "SPARQL";
grant execute on DB.DBA.TUT_ORDERLINE_IRI_INV_2 to "SPARQL";
grant execute on DB.DBA.TUT_PROVINCE_IRI to "SPARQL";
grant execute on DB.DBA.TUT_PROVINCE_IRI_INV_1 to "SPARQL";
grant execute on DB.DBA.TUT_PROVINCE_IRI_INV_2 to "SPARQL";
grant execute on DB.DBA.TUT_COUNTRY_IRI to "SPARQL";
grant execute on DB.DBA.TUT_COUNTRY_IRI_INVERSE to "SPARQL";
grant execute on DB.DBA.TUT_FLAG_IRI to "SPARQL";
grant execute on DB.DBA.TUT_FLAG_IRI_INVERSE to "SPARQL";
grant execute on DB.DBA.TUT_EMPLOYEEPHOTO_IRI to "SPARQL";
grant execute on DB.DBA.TUT_EMPLOYEEPHOTO_IRI_INVERSE to "SPARQL";
grant execute on DB.DBA.TUT_CATEGORYPHOTO_IRI to "SPARQL";
grant execute on DB.DBA.TUT_CATEGORYPHOTO_IRI_INVERSE to "SPARQL";

SPARQL
prefix tut_northwind: <http://demo.openlinksw.com/schemas/tutorial/northwind#>
prefix oplsioc: <http://www.openlinksw.com/schemas/oplsioc#>
prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#>
prefix sioc: <http://rdfs.org/sioc/ns#>
prefix foaf: <http://xmlns.com/foaf/0.1/>
prefix owl: <http://www.w3.org/2002/07/owl#>
prefix wgs: <http://www.w3.org/2003/01/geo/wgs84_pos#>
create iri class tut_northwind:Category "http://^{URIQADefaultHost}^/tutorial/Northwind/Category/%d#this" (in category_id integer not null) .
create iri class tut_northwind:Shipper "http://^{URIQADefaultHost}^/tutorial/Northwind/Shipper/%d#this" (in shipper_id integer not null) .
create iri class tut_northwind:Supplier "http://^{URIQADefaultHost}^/tutorial/Northwind/Supplier/%d#this" (in supplier_id integer not null) .
create iri class tut_northwind:Product   "http://^{URIQADefaultHost}^/tutorial/Northwind/Product/%d#this" (in product_id integer not null) .
create iri class tut_northwind:Customer "http://^{URIQADefaultHost}^/tutorial/Northwind/Customer/%U#this" (in customer_id varchar not null) .
create iri class tut_northwind:Employee "http://^{URIQADefaultHost}^/tutorial/Northwind/Employee/%U%U%d#this" (in employee_firstname varchar not null, in employee_lastname varchar not null, in employee_id integer not null) .
create iri class tut_northwind:Order "http://^{URIQADefaultHost}^/tutorial/Northwind/Order/%d#this" (in order_id integer not null) .
create iri class tut_northwind:CustomerContact "http://^{URIQADefaultHost}^/tutorial/Northwind/CustomerContact/%U#this" (in customer_id varchar not null) .
create iri class tut_northwind:OrderLine "http://^{URIQADefaultHost}^/tutorial/Northwind/OrderLine/%d/%d#this" (in order_id integer not null, in product_id integer not null) .
create iri class tut_northwind:Province "http://^{URIQADefaultHost}^/tutorial/Northwind/Province/%U/%U#this" (in country_name varchar not null, in province_name varchar not null) .
create iri class tut_northwind:Country "http://^{URIQADefaultHost}^/tutorial/Northwind/Country/%U#this" (in country_name varchar not null) .
create iri class tut_northwind:Flag "http://^{URIQADefaultHost}^%U#this" (in flag_path varchar not null) .
create iri class tut_northwind:dbpedia_iri "http://dbpedia.org/resource/%U" (in uname varchar not null) .
create iri class tut_northwind:EmployeePhoto "http://^{URIQADefaultHost}^/DAV/VAD/demo/sql/EMP%d#this" (in emp_id varchar not null) .
create iri class tut_northwind:CategoryPhoto "http://^{URIQADefaultHost}^/DAV/VAD/demo/sql/CAT%d#this" (in category_id varchar not null) .
;

SPARQL
prefix tut_northwind: <http://demo.openlinksw.com/schemas/tutorial/northwind#>
prefix oplsioc: <http://www.openlinksw.com/schemas/oplsioc#>
prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#>
prefix sioc: <http://rdfs.org/sioc/ns#>
prefix foaf: <http://xmlns.com/foaf/0.1/>
prefix owl: <http://www.w3.org/2002/07/owl#>
prefix wgs: <http://www.w3.org/2003/01/geo/wgs84_pos#>
create iri class tut_northwind:customercontact_iri using
    function DB.DBA.TUT_CUSTOMERCONTACT_IRI (in customer_id varchar) returns varchar,
    function DB.DBA.TUT_CUSTOMERCONTACT_IRI_INVERSE (in customer_iri varchar) returns varchar.
create iri class tut_northwind:category_iri using
    function DB.DBA.TUT_CATEGORY_IRI (in customer_id integer) returns varchar,
    function DB.DBA.TUT_CATEGORY_IRI_INVERSE (in customer_iri varchar) returns integer.
create iri class tut_northwind:shipper_iri using
    function DB.DBA.TUT_SHIPPER_IRI (in customer_id integer) returns varchar,
    function DB.DBA.TUT_SHIPPER_IRI_INVERSE (in customer_iri varchar) returns integer.
create iri class tut_northwind:supplier_iri using
    function DB.DBA.TUT_SUPPLIER_IRI (in customer_id varchar) returns varchar,
    function DB.DBA.TUT_SUPPLIER_IRI_INVERSE (in customer_iri varchar) returns varchar.
create iri class tut_northwind:product_iri using
    function DB.DBA.TUT_PRODUCT_IRI (in customer_id integer) returns varchar,
    function DB.DBA.TUT_PRODUCT_IRI_INVERSE (in customer_iri varchar) returns integer.
create iri class tut_northwind:customer_iri using
    function DB.DBA.TUT_CUSTOMER_IRI (in customer_id varchar) returns varchar,
    function DB.DBA.TUT_CUSTOMER_IRI_INVERSE (in customer_iri varchar) returns varchar.
create iri class tut_northwind:employee_iri using
    function DB.DBA.TUT_EMPLOYEE_IRI (in customer_id integer) returns varchar,
    function DB.DBA.TUT_EMPLOYEE_IRI_INVERSE (in customer_iri varchar) returns integer.
create iri class tut_northwind:order_iri using
    function DB.DBA.TUT_ORDER_IRI (in customer_id integer) returns varchar,
    function DB.DBA.TUT_ORDER_IRI_INVERSE (in customer_iri varchar) returns integer.
create iri class tut_northwind:orderline_iri using
    function DB.DBA.TUT_ORDERLINE_IRI (in customer_id integer, in customer_id2 integer) returns varchar,
    function DB.DBA.TUT_ORDERLINE_IRI_INV_1 (in customer_iri varchar) returns integer,
    function DB.DBA.TUT_ORDERLINE_IRI_INV_2 (in customer_iri varchar) returns integer.
create iri class tut_northwind:province_iri using
    function DB.DBA.TUT_PROVINCE_IRI (in customer_id varchar, in customer_id2 varchar) returns varchar,
    function DB.DBA.TUT_PROVINCE_IRI_INV_1 (in customer_iri varchar) returns varchar,
    function DB.DBA.TUT_PROVINCE_IRI_INV_2 (in customer_iri varchar) returns varchar.
create iri class tut_northwind:country_iri using
    function DB.DBA.TUT_COUNTRY_IRI (in customer_id varchar) returns varchar,
    function DB.DBA.TUT_COUNTRY_IRI_INVERSE (in customer_iri varchar) returns varchar.
create iri class tut_northwind:employeephoto_iri using
    function DB.DBA.TUT_EMPLOYEEPHOTO_IRI (in customer_id integer) returns varchar,
    function DB.DBA.TUT_EMPLOYEEPHOTO_IRI_INVERSE (in customer_iri varchar) returns integer.
create iri class tut_northwind:categoryphoto_iri using
    function DB.DBA.TUT_CATEGORYPHOTO_IRI (in customer_id integer) returns varchar,
    function DB.DBA.TUT_CATEGORYPHOTO_IRI_INVERSE (in customer_iri varchar) returns integer.
create iri class tut_northwind:flag_iri using
    function DB.DBA.TUT_FLAG_IRI (in customer_id varchar) returns varchar,
    function DB.DBA.TUT_FLAG_IRI_INVERSE (in customer_iri varchar) returns varchar.
;

SPARQL
prefix tut_northwind: <http://demo.openlinksw.com/schemas/tutorial/northwind#>
prefix oplsioc: <http://www.openlinksw.com/schemas/oplsioc#>
prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#>
prefix sioc: <http://rdfs.org/sioc/ns#>
prefix foaf: <http://xmlns.com/foaf/0.1/>
prefix owl: <http://www.w3.org/2002/07/owl#>
prefix wgs: <http://www.w3.org/2003/01/geo/wgs84_pos#>
alter quad storage virtrdf:DefaultQuadStorage
from Demo.demo.Products as products
from Demo.demo.Suppliers as suppliers
from Demo.demo.Shippers as shippers
from Demo.demo.Categories as categories
from Demo.demo.Customers as customers
from Demo.demo.Employees as employees
from Demo.demo.Orders as orders
from Demo.demo.Order_Details as order_lines
from Demo.demo.Countries as countries
from Demo.demo.Provinces as provinces
where (^{suppliers.}^.Country = ^{countries.}^.Name)
where (^{customers.}^.Country = ^{countries.}^.Name)
where (^{employees.}^.Country = ^{countries.}^.Name)
where (^{orders.}^.ShipCountry = ^{countries.}^.Name)
{
        create virtrdf:TutorialNorthwindDemo as graph iri ("http://^{URIQADefaultHost}^/tutorial/Northwind") option (exclusive)
        {
                tut_northwind:CustomerContact (customers.CustomerID)
                        a foaf:Person
                                as virtrdf:tutCustomerContact-foaf_Person .

                tut_northwind:CustomerContact (customers.CustomerID)
                        a tut_northwind:CustomerContact
                                as virtrdf:tutCustomerContact-CustomerContact;
                        foaf:name customers.ContactName
                                as virtrdf:tutCustomerContact-contact_name ;
                        foaf:phone customers.Phone
                                as virtrdf:tutCustomerContact-foaf_phone ;
                        tut_northwind:is_contact_at tut_northwind:Customer (customers.CustomerID)
                                as virtrdf:tutCustomerContact-is_contact_at ;
                        tut_northwind:country tut_northwind:Country (customers.Country)
                                as virtrdf:tutCustomerContact-country ;
                        rdfs:isDefinedBy tut_northwind:customercontact_iri (customers.CustomerID) ;
                        rdfs:isDefinedBy tut_northwind:CustomerContact (customers.CustomerID) .

                tut_northwind:Country (customers.Country)
                        tut_northwind:is_country_of
                tut_northwind:CustomerContact (customers.CustomerID) as virtrdf:tutCustomerContact-is_country_of .

                tut_northwind:Product (products.ProductID)
                        a tut_northwind:Product
                                as virtrdf:tutProduct-ProductID ;
                        tut_northwind:has_category tut_northwind:Category (products.CategoryID)
                                as virtrdf:tutProduct-product_has_category ;
                        tut_northwind:has_supplier tut_northwind:Supplier (products.SupplierID)
                                as virtrdf:tutProduct-product_has_supplier ;
                        tut_northwind:productName products.ProductName
                                as virtrdf:tutProduct-name_of_product ;
                        tut_northwind:quantityPerUnit products.QuantityPerUnit
                                as virtrdf:tutProduct-quantity_per_unit ;
                        tut_northwind:unitPrice products.UnitPrice
                                as virtrdf:tutProduct-unit_price ;
                        tut_northwind:unitsInStock products.UnitsInStock
                                as virtrdf:tutProduct-units_in_stock ;
                        tut_northwind:unitsOnOrder products.UnitsOnOrder
                                as virtrdf:tutProduct-units_on_order ;
                        tut_northwind:reorderLevel products.ReorderLevel
                                as virtrdf:tutProduct-reorder_level ;
                        tut_northwind:discontinued products.Discontinued
                                as virtrdf:tutProduct-discontinued ;
                        rdfs:isDefinedBy tut_northwind:product_iri (products.ProductID) ;
                        rdfs:isDefinedBy tut_northwind:Product (products.ProductID).

                tut_northwind:Category (products.CategoryID)
                        tut_northwind:category_of tut_northwind:Product (products.ProductID) as virtrdf:tutProduct-category_of .

                tut_northwind:Supplier (products.SupplierID)
                        tut_northwind:supplier_of tut_northwind:Product (products.ProductID) as virtrdf:tutProduct-supplier_of .

                tut_northwind:Supplier (suppliers.SupplierID)
                        a tut_northwind:Supplier
                                as virtrdf:tutSupplier-SupplierID ;
                        tut_northwind:companyName suppliers.CompanyName
                                as virtrdf:tutSupplier-company_name ;
                        tut_northwind:contactName suppliers.ContactName
                                as virtrdf:tutSupplier-contact_name ;
                        tut_northwind:contactTitle suppliers.ContactTitle
                                as virtrdf:tutSupplier-contact_title ;
                        tut_northwind:address suppliers.Address
                                as virtrdf:tutSupplier-address ;
                        tut_northwind:city suppliers.City
                                as virtrdf:tutSupplier-city ;
                        tut_northwind:dbpedia_city tut_northwind:dbpedia_iri(suppliers.City)
                                as virtrdf:tutSupplier-dbpedia_city ;
                        tut_northwind:region suppliers.Region
                                as virtrdf:tutSupplier-region ;
                        tut_northwind:postalCode suppliers.PostalCode
                                as virtrdf:tutSupplier-postal_code ;
                        tut_northwind:country tut_northwind:Country(suppliers.Country)
                                as virtrdf:tutSupplier-country ;
                        tut_northwind:phone suppliers.Phone
                                as virtrdf:tutSupplier-phone ;
                        tut_northwind:fax suppliers.Fax
                                as virtrdf:tutSupplier-fax ;
                        tut_northwind:homePage suppliers.HomePage
                                as virtrdf:tutSupplier-home_page ;
                        rdfs:isDefinedBy tut_northwind:supplier_iri (suppliers.SupplierID) ;
                        rdfs:isDefinedBy tut_northwind:Supplier (suppliers.SupplierID).

                tut_northwind:Country (suppliers.Country)
                        tut_northwind:is_country_of
                tut_northwind:Supplier (suppliers.SupplierID) as virtrdf:tutSupplier-is_country_of .

                tut_northwind:Category (categories.CategoryID)
                        a tut_northwind:Category
                                as virtrdf:tutCategory-CategoryID ;
                        tut_northwind:categoryName categories.CategoryName
                                as virtrdf:tutCategory-home_page ;
                        tut_northwind:description categories.Description
                                as virtrdf:tutCategory-description ;
                        foaf:img tut_northwind:CategoryPhoto(categories.CategoryID)
                                as virtrdf:tutCategory-categories.CategoryPhoto ;
                        rdfs:isDefinedBy tut_northwind:category_iri (categories.CategoryID) ;
                        rdfs:isDefinedBy tut_northwind:Category (categories.CategoryID).

                tut_northwind:CategoryPhoto(categories.CategoryID)
                        a tut_northwind:CategoryPhoto
                                as virtrdf:tutCategory-categories.CategoryPhotoID ;
                        rdfs:isDefinedBy tut_northwind:categoryphoto_iri (categories.CategoryID) ;
                        rdfs:isDefinedBy tut_northwind:CategoryPhoto(categories.CategoryID).

                tut_northwind:Shipper (shippers.ShipperID)
                        a tut_northwind:Shipper
                                as virtrdf:tutShipper-ShipperID ;
                        tut_northwind:companyName shippers.CompanyName
                                as virtrdf:tutShipper-company_name ;
                        tut_northwind:phone shippers.Phone
                                as virtrdf:tutShipper-phone ;
                        rdfs:isDefinedBy tut_northwind:shipper_iri (shippers.ShipperID) ;
                        rdfs:isDefinedBy tut_northwind:Shipper (shippers.ShipperID).

                tut_northwind:Customer (customers.CustomerID)
                        a  tut_northwind:Customer
                                as virtrdf:tutCustomer-CustomerID2 ;
                        a  foaf:Organization
                                as virtrdf:tutCustomer-CustomerID ;
                        foaf:name customers.CompanyName
                                as virtrdf:tutCustomer-foaf_name ;
                        tut_northwind:companyName customers.CompanyName
                                as virtrdf:tutCustomer-company_name ;
                        tut_northwind:has_contact tut_northwind:CustomerContact (customers.CustomerID)
                                as virtrdf:tutCustomer-contact ;
                        tut_northwind:country tut_northwind:Country (customers.Country)
                                as virtrdf:tutCustomer-country ;
                        tut_northwind:contactName customers.ContactName
                                as virtrdf:tutCustomer-contact_name ;
                        tut_northwind:contactTitle customers.ContactTitle
                                as virtrdf:tutCustomer-contact_title ;
                        tut_northwind:address customers.Address
                                as virtrdf:tutCustomer-address ;
                        tut_northwind:city customers.City
                                as virtrdf:tutCustomer-city ;
                        tut_northwind:dbpedia_city tut_northwind:dbpedia_iri(customers.City)
                                as virtrdf:tutCustomer-dbpedia_city ;
                        tut_northwind:region customers.Region
                                as virtrdf:tutCustomer-region ;
                        tut_northwind:PostalCode customers.PostalCode
                                as virtrdf:tutCustomer-postal_code ;
                        foaf:phone customers.Phone
                                as virtrdf:tutCustomer-foaf_phone ;
                        tut_northwind:phone customers.Phone
                                as virtrdf:tutCustomer-phone ;
                        tut_northwind:fax customers.Fax
                                as virtrdf:tutCustomer-fax ;
                        rdfs:isDefinedBy tut_northwind:customer_iri (customers.CustomerID) ;
                        rdfs:isDefinedBy tut_northwind:Customer (customers.CustomerID).

                tut_northwind:Country (customers.Country)
                        tut_northwind:is_country_of
                tut_northwind:Customer (customers.CustomerID) as virtrdf:tutCustomer-is_country_of .

                tut_northwind:Employee (employees.FirstName, employees.LastName, employees.EmployeeID)
                        a tut_northwind:Employee
                                as virtrdf:tutEmployee-EmployeeID2 ;
                        a foaf:Person
                                as virtrdf:tutEmployee-EmployeeID ;
                        foaf:surname employees.LastName
                                as virtrdf:tutEmployee-foaf_last_name ;
                        tut_northwind:lastName employees.LastName
                                as virtrdf:tutEmployee-last_name ;
                        foaf:firstName employees.FirstName
                                as virtrdf:tutEmployee-foaf_first_name ;
                        tut_northwind:firstName employees.FirstName
                                as virtrdf:tutEmployee-first_name ;
                        foaf:title employees.Title
                                as virtrdf:tutEmployee-title ;
                        tut_northwind:titleOfCourtesy employees.TitleOfCourtesy
                                as virtrdf:tutEmployee-title_of_courtesy ;
                        foaf:birthday employees.BirthDate
                                as virtrdf:tutEmployee-foaf_birth_date ;
                        tut_northwind:birthday employees.BirthDate
                                as virtrdf:tutEmployee-birth_date ;
                        tut_northwind:hireDate employees.HireDate
                                as virtrdf:tutEmployee-hire_date ;
                        tut_northwind:address employees.Address
                                as virtrdf:tutEmployee-address ;
                        tut_northwind:city employees.City
                                as virtrdf:tutEmployee-city ;
                        tut_northwind:dbpedia_city tut_northwind:dbpedia_iri(employees.City)
                                as virtrdf:tutEmployee-dbpedia_city ;
                        tut_northwind:region employees.Region
                                as virtrdf:tutEmployee-region ;
                        tut_northwind:postalCode employees.PostalCode
                                as virtrdf:tutEmployee-postal_code ;
                        tut_northwind:country tut_northwind:Country (employees.Country)
                                as virtrdf:tutEmployee-country ;
                        foaf:phone employees.HomePhone
                                as virtrdf:tutEmployee-home_phone ;
                        tut_northwind:extension employees.Extension
                                as virtrdf:tutEmployee-extension ;
                        tut_northwind:notes employees.Notes
                                as virtrdf:tutEmployee-notes ;
                        tut_northwind:reportsTo tut_northwind:Employee(employees.FirstName, employees.LastName, employees.ReportsTo) where (^{employees.}^.ReportsTo = ^{employees.}^.EmployeeID)
                                as virtrdf:tutEmployee-reports_to ;
                        foaf:img tut_northwind:EmployeePhoto(employees.EmployeeID)
                                as virtrdf:tutEmployee-employees.EmployeePhoto ;
                        rdfs:isDefinedBy tut_northwind:employee_iri (employees.EmployeeID) ;
                        rdfs:isDefinedBy tut_northwind:Employee (employees.FirstName, employees.LastName, employees.EmployeeID).

                tut_northwind:EmployeePhoto(employees.EmployeeID)
                        a tut_northwind:EmployeePhoto
                                as virtrdf:tut_Employee-employees.EmployeePhotoId ;
                        rdfs:isDefinedBy tut_northwind:employeephoto_iri (employees.EmployeeID) ;
                        rdfs:isDefinedBy tut_northwind:EmployeePhoto (employees.EmployeeID).

                tut_northwind:Employee (employees.FirstName, employees.LastName, orders.EmployeeID)
                        tut_northwind:is_salesrep_of
                tut_northwind:Order (orders.OrderID) where (^{orders.}^.EmployeeID = ^{employees.}^.EmployeeID) as virtrdf:tutOrder-is_salesrep_of .

                tut_northwind:Country (employees.Country)
                        tut_northwind:is_country_of
                tut_northwind:Employee (employees.FirstName, employees.LastName, employees.EmployeeID) as virtrdf:tutEmployee-is_country_of .

                tut_northwind:Order (orders.OrderID)
                        a tut_northwind:Order
                                as virtrdf:tutOrder-Order ;
                        tut_northwind:has_customer tut_northwind:Customer (orders.CustomerID)
                                as virtrdf:tutOrder-order_has_customer ;
                        tut_northwind:has_salesrep tut_northwind:Employee (employees.FirstName, employees.LastName, orders.EmployeeID) where (^{orders.}^.EmployeeID = ^{employees.}^.EmployeeID)
                                as virtrdf:tutCustomer-has_salesrep ;
                        tut_northwind:has_employee tut_northwind:Employee (employees.FirstName, employees.LastName, orders.EmployeeID) where (^{orders.}^.EmployeeID = ^{employees.}^.EmployeeID)
                                as virtrdf:tutOrder-order_has_employee ;
                        tut_northwind:orderDate orders.OrderDate
                                as virtrdf:tutOrder-order_date ;
                        tut_northwind:requiredDate orders.RequiredDate
                                as virtrdf:tutOrder-required_date ;
                        tut_northwind:shippedDate orders.ShippedDate
                                as virtrdf:tutOrder-shipped_date ;
                        tut_northwind:order_ship_via tut_northwind:Shipper (orders.ShipVia)
                                as virtrdf:tutOrder-order_ship_via ;
                        tut_northwind:freight orders.Freight
                                as virtrdf:tutOrder-freight ;
                        tut_northwind:shipName orders.ShipName
                                as virtrdf:tutOrder-ship_name ;
                        tut_northwind:shipAddress orders.ShipAddress
                                as virtrdf:tutOrder-ship_address ;
                        tut_northwind:shipCity orders.ShipCity
                                as virtrdf:tutOrder-ship_city ;
                        tut_northwind:dbpedia_shipCity tut_northwind:dbpedia_iri(orders.ShipCity)
                                as virtrdf:tutOrder-ship_dbpedia_city ;
                        tut_northwind:shipRegion orders.ShipRegion
                                as virtrdf:tutOrder-ship_region ;
                        tut_northwind:shipPostal_code orders.ShipPostalCode
                                as virtrdf:tutOrder-ship_postal_code ;
                        tut_northwind:shipCountry tut_northwind:Country(orders.ShipCountry)
                                as virtrdf:tutship_country ;
                        rdfs:isDefinedBy tut_northwind:order_iri (orders.OrderID) ;
                        rdfs:isDefinedBy tut_northwind:Order (orders.OrderID).

                tut_northwind:Country (orders.ShipCountry)
                        tut_northwind:is_ship_country_of
                tut_northwind:Order (orders.OrderID) as virtrdf:tutOrder-is_country_of .

                tut_northwind:Customer (orders.CustomerID)
                        tut_northwind:has_order tut_northwind:Order (orders.OrderID) as virtrdf:tutOrder-has_order .

                tut_northwind:Shipper (orders.ShipVia)
                        tut_northwind:ship_order tut_northwind:Order (orders.OrderID) as virtrdf:tutOrder-ship_order .

                tut_northwind:OrderLine (order_lines.OrderID, order_lines.ProductID)
                        a tut_northwind:OrderLine
                                as virtrdf:tutOrderLine-OrderLines ;
                        tut_northwind:has_order_id tut_northwind:Order (order_lines.OrderID)
                                as virtrdf:tutorder_lines_has_order_id ;
                        tut_northwind:has_product_id tut_northwind:Product (order_lines.ProductID)
                                as virtrdf:tutorder_lines_has_product_id ;
                        tut_northwind:unitPrice order_lines.UnitPrice
                                as virtrdf:tutOrderLine-unit_price ;
                        tut_northwind:quantity order_lines.Quantity
                                as virtrdf:tutOrderLine-quantity ;
                        tut_northwind:discount order_lines.Discount
                                as virtrdf:tutOrderLine-discount ;
                        rdfs:isDefinedBy tut_northwind:orderline_iri (order_lines.OrderID, order_lines.ProductID) ;
                        rdfs:isDefinedBy tut_northwind:OrderLine (order_lines.OrderID, order_lines.ProductID).

                tut_northwind:Order (orders.OrderID)
                        tut_northwind:is_order_of
                tut_northwind:OrderLine (order_lines.OrderID, order_lines.ProductID) where (^{orders.}^.OrderID = ^{order_lines.}^.OrderID) as virtrdf:tutOrder-is_order_of .

                tut_northwind:Product (products.ProductID)
                        tut_northwind:is_product_of
                tut_northwind:OrderLine (order_lines.OrderID, order_lines.ProductID) where (^{products.}^.ProductID = ^{order_lines.}^.ProductID) as virtrdf:tutProduct-is_product_of .

                tut_northwind:Country (countries.Name)
                        a tut_northwind:Country
                                as virtrdf:tutCountry-Type2 ;
                        a wgs:SpatialThing
                                as virtrdf:tutCountry-Type ;
                        owl:sameAs tut_northwind:dbpedia_iri (countries.Name) ;
                        tut_northwind:name countries.Name
                                as virtrdf:tutCountry-Name ;
                        tut_northwind:code countries.Code
                                as virtrdf:tutCountry-Code ;
                        tut_northwind:smallFlagDAVResourceName countries.SmallFlagDAVResourceName
                                as virtrdf:tutCountry-SmallFlagDAVResourceName ;
                        tut_northwind:largeFlagDAVResourceName countries.LargeFlagDAVResourceName
                                as virtrdf:tutCountry-LargeFlagDAVResourceName ;
                        tut_northwind:smallFlagDAVResourceURI tut_northwind:Flag(countries.SmallFlagDAVResourceURI)
                                as virtrdf:tutCountry-SmallFlagDAVResourceURI ;
                        tut_northwind:largeFlagDAVResourceURI tut_northwind:Flag(countries.LargeFlagDAVResourceURI)
                                as virtrdf:tutCountry-LargeFlagDAVResourceURI ;
                        wgs:lat countries.Lat
                                as virtrdf:tutCountry-Lat ;
                        wgs:long countries.Lng
                                as virtrdf:tutCountry-Lng ;
                        rdfs:isDefinedBy tut_northwind:country_iri (countries.Name) ;
                        rdfs:isDefinedBy tut_northwind:Country (countries.Name).

                tut_northwind:Country (countries.Name)
                        tut_northwind:has_province
                tut_northwind:Province (provinces.CountryCode, provinces.Province) where (^{provinces.}^.CountryCode = ^{countries.}^.Code) as virtrdf:tutCountry-has_province .

                tut_northwind:Province (provinces.CountryCode, provinces.Province)
                        a tut_northwind:Province
                                as virtrdf:tutProvince-Provinces ;
                        tut_northwind:has_country_code provinces.CountryCode
                                as virtrdf:tuthas_country_code ;
                        tut_northwind:provinceName provinces.Province
                                as virtrdf:tutProvince-ProvinceName ;
                        rdfs:isDefinedBy tut_northwind:province_iri (provinces.CountryCode, provinces.Province) ;
                        rdfs:isDefinedBy tut_northwind:Province (provinces.CountryCode, provinces.Province).

                tut_northwind:Province (provinces.CountryCode, provinces.Province)
                        tut_northwind:is_province_of
                tut_northwind:Country (countries.Name) where  (^{countries.}^.Code = ^{provinces.}^.CountryCode) as virtrdf:tutProvince-country_of .
        } .
} .
;

delete from db.dba.url_rewrite_rule_list where urrl_list like 'tut_nw%';
delete from db.dba.url_rewrite_rule where urr_rule like 'tut_nw%';

create procedure DB.DBA.install_run ()
{
        declare file_text, uriqa varchar;
        uriqa := registry_get('URIQADefaultHost');
        file_text := (select blob_to_string (RES_CONTENT) from WS.WS.SYS_DAV_RES where RES_FULL_PATH='/DAV/VAD/tutorial/rdfview/rd_v_1/rd_v_1.isparql');
        file_text := replace(file_text, 'URIQA_MACRO', concat('http://', uriqa, '/tutorial/Northwind'));
        update WS.WS.SYS_DAV_RES set RES_CONTENT=file_text where RES_FULL_PATH='/DAV/VAD/tutorial/rdfview/rd_v_1/rd_v_1.isparql';
}
;

DB.DBA.install_run()
;

drop procedure DB.DBA.install_run
;

DB.DBA.URLREWRITE_CREATE_REGEX_RULE (
    'tut_nw_rule2',
    1,
    '(/[^#]*)',
    vector('path'),
    1,
    '/sparql?query=CONSTRUCT+{+%%3Chttp%%3A//^{URIQADefaultHost}^%U%%23this%%3E+%%3Fp+%%3Fo+}+FROM+%%3Chttp%%3A//^{URIQADefaultHost}^/tutorial/Northwind%%3E+WHERE+{+%%3Chttp%%3A//^{URIQADefaultHost}^%U%%23this%%3E+%%3Fp+%%3Fo+}&format=%U',
    vector('path', 'path', '*accept*'),
    null,
    '(text/rdf.n3)|(application/rdf.xml)',
    0,
    null
    );

DB.DBA.URLREWRITE_CREATE_REGEX_RULE (
    'tut_nw_rule1',
    1,
    '(/[^#]*)',
    vector('path'),
    1,
    '/rdfbrowser/index.html?uri=http%%3A//^{URIQADefaultHost}^%U%%23this',
    vector('path'),
    null,
    '(text/html)|(\\*/\\*)',
    0,
    303
    );

DB.DBA.URLREWRITE_CREATE_REGEX_RULE (
    'tut_nw_rule3',
    1,
    '(/[^#]*)/\x24',
    vector('path'),
    1,
    '%s',
    vector('path'),
    null,
    null,
    0,
    null
    );

create procedure DB.DBA.REMOVE_TUT_DEMO_RDF_DET()
{
  declare colid int;
  colid := DAV_SEARCH_ID('/DAV/VAD/tutorial/rdfview/rd_v_1/', 'C');
  if (colid < 0)
    return;
  update WS.WS.SYS_DAV_COL set COL_DET=null where COL_ID = colid;
}
;

DB.DBA.REMOVE_TUT_DEMO_RDF_DET();

drop procedure DB.DBA.REMOVE_TUT_DEMO_RDF_DET;

create procedure DB.DBA.TUT_NORTHWIND_MAKE_RDF_DET()
{
    declare uriqa_str varchar;
    uriqa_str := cfg_item_value(virtuoso_ini_path(), 'URIQA','DefaultHost');
    uriqa_str := 'http://' || uriqa_str || '/tutorial/Northwind';
    DB.DBA."RDFData_MAKE_DET_COL" ('/DAV/VAD/tutorial/rdfview/rd_v_1/RDFData/', uriqa_str, NULL);
    VHOST_REMOVE (lpath=>'/tutorial/Northwind/data/rdf');
    DB.DBA.VHOST_DEFINE (lpath=>'/tutorial/Northwind/data/rdf', ppath=>'/DAV/VAD/tutorial/rdfview/rd_v_1/RDFData/All/', is_dav=>1, vsp_user=>'dba');
}
;

DB.DBA.TUT_NORTHWIND_MAKE_RDF_DET();

drop procedure DB.DBA.TUT_NORTHWIND_MAKE_RDF_DET;

-- procedure to convert path to DET resource name
create procedure DB.DBA.TUT_NORTHWIND_DET_REF (in par varchar, in fmt varchar, in val varchar)
{
  declare res, iri any;
  declare uriqa_str varchar;
  uriqa_str := cfg_item_value(virtuoso_ini_path(), 'URIQA','DefaultHost');
  uriqa_str := 'http://' || uriqa_str || '/tutorial/Northwind';
  iri := uriqa_str || val;
  res := sprintf ('iid (%d).rdf', iri_id_num (iri_to_id (iri)));
  return sprintf (fmt, res);
}
;

DB.DBA.URLREWRITE_CREATE_REGEX_RULE ('tut_nw_rdf', 1,
    '/tutorial/Northwind/(.*)', vector('path'), 1,
    '/tutorial/Northwind/data/rdf/%U', vector('path'),
    'DB.DBA.TUT_NORTHWIND_DET_REF',
    'application/rdf.xml',
    2,
    303);

DB.DBA.URLREWRITE_CREATE_RULELIST (
    'tut_nw_rule_list1',
    1,
    vector (
                'tut_nw_rule1',
                'tut_nw_rule2',
                'tut_nw_rule3',
                'tut_nw_rdf'
          ));


VHOST_REMOVE (lpath=>'/tutorial/Northwind');
DB.DBA.VHOST_DEFINE (lpath=>'/tutorial/Northwind', ppath=>'/DAV/VAD/tutorial/rdfview/rd_v_1/', vsp_user=>'dba', is_dav=>1, def_page=>'sfront.vspx',
          is_brws=>0, opts=>vector ('url_rewrite', 'tut_nw_rule_list1'));

create procedure DB.DBA.LOAD_TUTNW_ONTOLOGY_FROM_DAV()
{
  declare content, urihost varchar;
  whenever not found goto endpoint;
  select cast (RES_CONTENT as varchar) into content from WS.WS.SYS_DAV_RES where RES_FULL_PATH = '/DAV/VAD/tutorial/rdfview/rd_v_1/rd_v_1.owl';
  if (content is null or content = '')
    goto endpoint;
  DB.DBA.RDF_LOAD_RDFXML (content, 'http://demo.openlinksw.com/schemas/tutorial/northwind#', 'http://demo.openlinksw.com/schemas/TutorialNorthwindOntology/1.0/');
  if (urihost = 'demo.openlinksw.com')
  {
    DB.DBA.VHOST_REMOVE (lpath=>'/schemas/tutorial/northwind#');
    DB.DBA.VHOST_DEFINE (lpath=>'/schemas/tutorial/northwind#', ppath=>'/DAV/VAD/tutorial/rdfview/rd_v_1/rd_v_1.owl', vsp_user=>'dba', is_dav=>1, is_brws=>0);
    DB.DBA.VHOST_REMOVE (lpath=>'/schemas/tutorial/northwind');
    DB.DBA.VHOST_DEFINE (lpath=>'/schemas/tutorial/northwind', ppath=>'/DAV/VAD/tutorial/rdfview/rd_v_1/rd_v_1.owl', vsp_user=>'dba', is_dav=>1, is_brws=>0);
  }
  endpoint:
  ;
}
;

DB.DBA.LOAD_TUTNW_ONTOLOGY_FROM_DAV()
;

drop procedure DB.DBA.LOAD_TUTNW_ONTOLOGY_FROM_DAV
;

create procedure DB.DBA.LOAD_TUTNW_ONTOLOGY_FROM_DAV2()
{
  declare urihost varchar;
  sparql base <http://demo.openlinksw.com/schemas/tutorial/northwind#> load bif:concat ("http://", bif:registry_get("URIQADefaultHost"), "/DAV/VAD/tutorial/rdfview/rd_v_1/rd_v_1.owl")
   into graph <http://demo.openlinksw.com/schemas/TutorialNorthwindOntology/1.0/>;
  urihost := cfg_item_value(virtuoso_ini_path(), 'URIQA','DefaultHost');
  if (urihost = 'demo.openlinksw.com')
  {
    DB.DBA.VHOST_REMOVE (lpath=>'/tutorial/northwind#');
    DB.DBA.VHOST_DEFINE (lpath=>'/tutorial/northwind#', ppath=>'/DAV/VAD/tutorial/rdfview/rd_v_1/rd_v_1.owl', vsp_user=>'dba', is_dav=>1, is_brws=>0);
  }
}
;

--DB.DBA.LOAD_TUTNW_ONTOLOGY_FROM_DAV2();

drop procedure DB.DBA.LOAD_TUTNW_ONTOLOGY_FROM_DAV2
;

DB.DBA.XML_SET_NS_DECL ('tut_northwind', 'http://demo.openlinksw.com/schemas/tutorial/northwind#', 2);

15.8.15.2. SQL Server's Northwind Demo Database

use DB;

DB.DBA.exec_stmt ('UPDATE WS.WS.SYS_DAV_RES set RES_TYPE=\'image/jpeg\' where RES_FULL_PATH like \'/DAV/VAD/demo/sql/CAT%\'', 0)
;

DB.DBA.exec_stmt ('UPDATE WS.WS.SYS_DAV_RES set RES_TYPE=\'image/jpeg\' where RES_FULL_PATH like \'/DAV/VAD/demo/sql/EMP%\'', 0)
;

GRANT SELECT ON "Demo"."demo"."Products" TO "SPARQL";
GRANT SELECT ON "Demo"."demo"."Suppliers" TO "SPARQL";
GRANT SELECT ON "Demo"."demo"."Shippers" TO "SPARQL";
GRANT SELECT ON "Demo"."demo"."Categories" TO "SPARQL";
GRANT SELECT ON "Demo"."demo"."Customers" TO "SPARQL";
GRANT SELECT ON "Demo"."demo"."Employees" TO "SPARQL";
GRANT SELECT ON "Demo"."demo"."Orders" TO "SPARQL";
GRANT SELECT ON "Demo"."demo"."Order_Details" TO "SPARQL";
GRANT SELECT ON "Demo"."demo"."Countries" TO "SPARQL";
GRANT SELECT ON "Demo"."demo"."Provinces" TO "SPARQL";


SPARQL drop quad map graph iri("http://^{URIQADefaultHost}^/Northwind") .
;

SPARQL drop quad map virtrdf:NorthwindDemo .
;

SPARQL
prefix northwind: <http://demo.openlinksw.com/schemas/northwind#>
drop iri class northwind:Category .
drop iri class northwind:CategoryDoc .
drop iri class northwind:Shipper .
drop iri class northwind:ShipperDoc .
drop iri class northwind:Supplier .
drop iri class northwind:SupplierDoc .
drop iri class northwind:Product .
drop iri class northwind:ProductDoc .
drop iri class northwind:Customer .
drop iri class northwind:CustomerDoc .
drop iri class northwind:Employee .
drop iri class northwind:EmployeeDoc .
drop iri class northwind:Order .
drop iri class northwind:OrderDoc .
drop iri class northwind:CustomerContact .
drop iri class northwind:CustomerContactDoc .
drop iri class northwind:OrderLine .
drop iri class northwind:OrderLineDoc .
drop iri class northwind:Province .
drop iri class northwind:ProvinceDoc .
drop iri class northwind:Country .
drop iri class northwind:CountryDoc .
drop iri class northwind:Flag .
drop iri class northwind:FlagDoc .
drop iri class northwind:dbpedia_iri2 .
drop iri class northwind:EmployeePhoto .
drop iri class northwind:CategoryPhoto .

drop iri class northwind:category_iri .
drop iri class northwind:categorydoc_iri .
drop iri class northwind:shipper_iri .
drop iri class northwind:shipperdoc_iri .
drop iri class northwind:supplier_iri .
drop iri class northwind:supplierdoc_iri .
drop iri class northwind:product_iri .
drop iri class northwind:productdoc_iri .
drop iri class northwind:customer_iri .
drop iri class northwind:customerdoc_iri .
drop iri class northwind:employee_iri .
drop iri class northwind:employeedoc_iri .
drop iri class northwind:order_iri .
drop iri class northwind:orderdoc_iri .
drop iri class northwind:customercontact_iri .
drop iri class northwind:customercontactdoc_iri .
drop iri class northwind:orderline_iri .
drop iri class northwind:orderlinedoc_iri .
drop iri class northwind:province_iri .
drop iri class northwind:provincedoc_iri .
drop iri class northwind:country_iri .
drop iri class northwind:countrydoc_iri .
drop iri class northwind:employeephoto_iri .
drop iri class northwind:categoryphoto_iri .
drop iri class northwind:flag_iri .
drop iri class northwind:flagdoc_iri .
;

SPARQL
prefix northwind: <http://demo.openlinksw.com/schemas/northwind#>

create iri class northwind:Category "http://^{URIQADefaultHost}^/Northwind/Category/%d#this" (in category_id integer not null) .
create iri class northwind:CategoryDoc "http://^{URIQADefaultHost}^/Northwind/Category/%d" (in category_id integer not null) .
create iri class northwind:Shipper "http://^{URIQADefaultHost}^/Northwind/Shipper/%d#this" (in shipper_id integer not null) .
create iri class northwind:ShipperDoc "http://^{URIQADefaultHost}^/Northwind/Shipper/%d" (in shipper_id integer not null) .
create iri class northwind:Supplier "http://^{URIQADefaultHost}^/Northwind/Supplier/%d#this" (in supplier_id integer not null) .
create iri class northwind:SupplierDoc "http://^{URIQADefaultHost}^/Northwind/Supplier/%d" (in supplier_id integer not null) .
create iri class northwind:Product   "http://^{URIQADefaultHost}^/Northwind/Product/%d#this" (in product_id integer not null) .
create iri class northwind:ProductDoc   "http://^{URIQADefaultHost}^/Northwind/Product/%d" (in product_id integer not null) .
create iri class northwind:Customer "http://^{URIQADefaultHost}^/Northwind/Customer/%U#this" (in customer_id varchar not null) .
create iri class northwind:CustomerDoc "http://^{URIQADefaultHost}^/Northwind/Customer/%U" (in customer_id varchar not null) .
create iri class northwind:Employee "http://^{URIQADefaultHost}^/Northwind/Employee/%U_%U_%d#this" (in employee_firstname varchar not null, in employee_lastname varchar not null, in employee_id integer not null) .
create iri class northwind:EmployeeDoc "http://^{URIQADefaultHost}^/Northwind/Employee/%U_%U_%d" (in employee_firstname varchar not null, in employee_lastname varchar not null, in employee_id integer not null) .
create iri class northwind:Order "http://^{URIQADefaultHost}^/Northwind/Order/%d#this" (in order_id integer not null) .
create iri class northwind:OrderDoc "http://^{URIQADefaultHost}^/Northwind/Order/%d" (in order_id integer not null) .
create iri class northwind:CustomerContact "http://^{URIQADefaultHost}^/Northwind/CustomerContact/%U#this" (in customer_id varchar not null) .
create iri class northwind:CustomerContactDoc "http://^{URIQADefaultHost}^/Northwind/CustomerContact/%U" (in customer_id varchar not null) .
create iri class northwind:OrderLine "http://^{URIQADefaultHost}^/Northwind/OrderLine/%d/%d#this" (in order_id integer not null, in product_id integer not null) .
create iri class northwind:OrderLineDoc "http://^{URIQADefaultHost}^/Northwind/OrderLine/%d/%d" (in order_id integer not null, in product_id integer not null) .
create iri class northwind:Province "http://^{URIQADefaultHost}^/Northwind/Province/%U/%U#this" (in country_name varchar not null, in province_name varchar not null) .
create iri class northwind:ProvinceDoc "http://^{URIQADefaultHost}^/Northwind/Province/%U/%U" (in country_name varchar not null, in province_name varchar not null) .
create iri class northwind:Country "http://^{URIQADefaultHost}^/Northwind/Country/%U#this" (in country_name varchar not null) .
create iri class northwind:CountryDoc "http://^{URIQADefaultHost}^/Northwind/Country/%U" (in country_name varchar not null) .
create iri class northwind:Flag "http://^{URIQADefaultHost}^%U#this" (in flag_path varchar not null) .
create iri class northwind:FlagDoc "http://^{URIQADefaultHost}^%U" (in flag_path varchar not null) .
create iri class northwind:dbpedia_iri2 "http://dbpedia.org/resource/%U" (in uname varchar not null) .
create iri class northwind:EmployeePhoto "http://^{URIQADefaultHost}^/DAV/VAD/demo/sql/EMP%d#this" (in emp_id varchar not null) .
create iri class northwind:CategoryPhoto "http://^{URIQADefaultHost}^/DAV/VAD/demo/sql/CAT%d#this" (in category_id varchar not null) .
create iri class northwind:Phone "tel:%s" (in phone_number varchar) .
create iri class northwind:Fax "fax:%s" (in fax_number varchar) .
;

SPARQL
prefix northwind: <http://demo.openlinksw.com/schemas/northwind#>
prefix oplsioc: <http://www.openlinksw.com/schemas/oplsioc#>
prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#>
prefix sioc: <http://rdfs.org/sioc/ns#>
prefix foaf: <http://xmlns.com/foaf/0.1/>
prefix owl: <http://www.w3.org/2002/07/owl#>
prefix wgs: <http://www.w3.org/2003/01/geo/wgs84_pos#>

alter quad storage virtrdf:DefaultQuadStorage
from Demo.demo.Products as products
from Demo.demo.Suppliers as suppliers
from Demo.demo.Shippers as shippers
from Demo.demo.Categories as categories
from Demo.demo.Customers as customers
from Demo.demo.Employees as employees
from Demo.demo.Orders as orders
from Demo.demo.Order_Details as order_lines
from Demo.demo.Countries as countries
from Demo.demo.Provinces as provinces
where (^{suppliers.}^.Country = ^{countries.}^.Name)
where (^{customers.}^.Country = ^{countries.}^.Name)
where (^{employees.}^.Country = ^{countries.}^.Name)
where (^{orders.}^.ShipCountry = ^{countries.}^.Name)
{
        create virtrdf:NorthwindDemo as graph iri ("http://^{URIQADefaultHost}^/Northwind") option (exclusive)
        {
                northwind:CustomerContact (customers.CustomerID)
                        a foaf:Person
                                as virtrdf:CustomerContact-foaf_Person .

                northwind:CustomerContact (customers.CustomerID)
                        a northwind:CustomerContact
                                as virtrdf:CustomerContact-CustomerContact;
                        foaf:name customers.ContactName
                                as virtrdf:CustomerContact-contact_name ;
                        foaf:phone northwind:Phone (customers.Phone)
                                as virtrdf:CustomerContact-foaf_phone ;
                        northwind:is_contact_at northwind:Customer (customers.CustomerID)
                                as virtrdf:CustomerContact-is_contact_at ;
                        northwind:country northwind:Country (customers.Country)
                                as virtrdf:CustomerContact-country ;
                        rdfs:isDefinedBy northwind: .

                northwind:CustomerContactDoc (customers.CustomerID)
                        a northwind:CustomerContactDoc
                                as virtrdf:CustomerContactDoc-CustomerID ;
                        a foaf:Document
                                as virtrdf:CustomerContactDoc-foaf_DocCustomerID ;
                        foaf:primaryTopic northwind:CustomerContact (customers.CustomerID)
                                as virtrdf:CustomerContactDoc-foaf_primarytopic ;
                        rdfs:isDefinedBy northwind: .

                northwind:Country (customers.Country)
                        northwind:is_country_of
                northwind:CustomerContact (customers.CustomerID) as virtrdf:CustomerContact-is_country_of .

                northwind:Product (products.ProductID)
                        a northwind:Product
                                as virtrdf:Product-ProductID ;
                        northwind:has_category northwind:Category (products.CategoryID)
                                as virtrdf:Product-product_has_category ;
                        northwind:has_supplier northwind:Supplier (products.SupplierID)
                                as virtrdf:Product-product_has_supplier ;
                        northwind:productName products.ProductName
                                as virtrdf:Product-name_of_product ;
                        northwind:quantityPerUnit products.QuantityPerUnit
                                as virtrdf:Product-quantity_per_unit ;
                        northwind:unitPrice products.UnitPrice
                                as virtrdf:Product-unit_price ;
                        northwind:unitsInStock products.UnitsInStock
                                as virtrdf:Product-units_in_stock ;
                        northwind:unitsOnOrder products.UnitsOnOrder
                                as virtrdf:Product-units_on_order ;
                        northwind:reorderLevel products.ReorderLevel
                                as virtrdf:Product-reorder_level ;
                        northwind:discontinued products.Discontinued
                                as virtrdf:Product-discontinued ;
                        rdfs:isDefinedBy northwind: .

                northwind:ProductDoc (products.ProductID)
                        a northwind:ProductDoc
                                as virtrdf:ProductDoc-ProductID ;
                        a foaf:Document
                                as virtrdf:ProductDoc-foaf_DocProductID ;
                        foaf:primaryTopic northwind:Product (products.ProductID)
                                as virtrdf:ProductDoc-foaf_primarytopic ;
                        rdfs:isDefinedBy northwind: .

                northwind:Category (products.CategoryID)
                        northwind:category_of northwind:Product (products.ProductID) as virtrdf:Product-category_of .

                northwind:Supplier (products.SupplierID)
                        northwind:supplier_of northwind:Product (products.ProductID) as virtrdf:Product-supplier_of .

                northwind:Supplier (suppliers.SupplierID)
                        a northwind:Supplier
                                as virtrdf:Supplier-SupplierID ;
                        northwind:companyName suppliers.CompanyName
                                as virtrdf:Supplier-company_name ;
                        northwind:contactName suppliers.ContactName
                                as virtrdf:Supplier-contact_name ;
                        northwind:contactTitle suppliers.ContactTitle
                                as virtrdf:Supplier-contact_title ;
                        northwind:address suppliers.Address
                                as virtrdf:Supplier-address ;
                        northwind:city northwind:dbpedia_iri2(suppliers.City)
                                as virtrdf:Supplier-dbpediacity ;
                        northwind:region suppliers.Region
                                as virtrdf:Supplier-region ;
                        northwind:postalCode suppliers.PostalCode
                                as virtrdf:Supplier-postal_code ;
                        northwind:country northwind:Country(suppliers.Country)
                                as virtrdf:Supplier-country ;
                        northwind:phone northwind:Phone (suppliers.Phone)
                                as virtrdf:Supplier-phone ;
                        northwind:fax northwind:Fax (suppliers.Fax)
                                as virtrdf:Supplier-fax ;
                        northwind:homePage suppliers.HomePage
                                as virtrdf:Supplier-home_page ;
                        rdfs:isDefinedBy northwind: .

                northwind:SupplierDoc (suppliers.SupplierID)
                        a northwind:SupplierDoc
                                as virtrdf:SupplierDoc-SupplierID ;
                        a foaf:Document
                                as virtrdf:SupplierDoc-foaf_DocSupplierID ;
                        foaf:primaryTopic northwind:Supplier (suppliers.SupplierID)
                                as virtrdf:SupplierDoc-foaf_primarytopic ;
                        rdfs:isDefinedBy northwind: .

                northwind:Country (suppliers.Country)
                        northwind:is_country_of
                northwind:Supplier (suppliers.SupplierID) as virtrdf:Supplier-is_country_of .

                northwind:Category (categories.CategoryID)
                        a northwind:Category
                                as virtrdf:Category-CategoryID ;
                        northwind:categoryName categories.CategoryName
                                as virtrdf:Category-home_page ;
                        northwind:description categories.Description
                                as virtrdf:Category-description ;
                        foaf:img northwind:CategoryPhoto(categories.CategoryID)
                                as virtrdf:Category-categories.CategoryPhoto ;
                        rdfs:isDefinedBy northwind: .

                northwind:CategoryDoc (categories.CategoryID)
                        a northwind:CategoryDoc
                                as virtrdf:CategoryDoc-CategoryID ;
                        a foaf:Document
                                as virtrdf:CategoryDoc-foaf_DocCategoryID ;
                        foaf:primaryTopic northwind:Category (categories.CategoryID)
                                as virtrdf:CategoryDoc-foaf_primarytopic ;
                        rdfs:isDefinedBy northwind: .

                northwind:CategoryPhoto(categories.CategoryID)
                        a northwind:CategoryPhoto
                                as virtrdf:Category-categories.CategoryPhotoID ;
                        rdfs:isDefinedBy northwind: .

                northwind:Shipper (shippers.ShipperID)
                        a northwind:Shipper
                                as virtrdf:Shipper-ShipperID ;
                        northwind:companyName shippers.CompanyName
                                as virtrdf:Shipper-company_name ;
                        northwind:phone northwind:Phone (shippers.Phone)
                                as virtrdf:Shipper-phone ;
                        rdfs:isDefinedBy northwind: .

                northwind:ShipperDoc (shippers.ShipperID)
                        a northwind:ShipperDoc
                                as virtrdf:ShipperDoc-ShipperID ;
                        a foaf:Document
                                as virtrdf:ShipperDoc-foaf_DocShipperID ;
                        foaf:primaryTopic northwind:Shipper (shippers.ShipperID)
                                as virtrdf:ShipperDoc-foaf_primarytopic ;
                        rdfs:isDefinedBy northwind: .

                northwind:Customer (customers.CustomerID)
                        a  northwind:Customer
                                as virtrdf:Customer-CustomerID2 ;
                        a  foaf:Organization
                                as virtrdf:Customer-CustomerID ;
                        foaf:name customers.CompanyName
                                as virtrdf:Customer-foaf_name ;
                        northwind:companyName customers.CompanyName
                                as virtrdf:Customer-company_name ;
                        northwind:has_contact northwind:CustomerContact (customers.CustomerID)
                                as virtrdf:Customer-contact ;
                        northwind:country northwind:Country (customers.Country)
                                as virtrdf:Customer-country ;
                        northwind:contactName customers.ContactName
                                as virtrdf:Customer-contact_name ;
                        northwind:contactTitle customers.ContactTitle
                                as virtrdf:Customer-contact_title ;
                        northwind:address customers.Address
                                as virtrdf:Customer-address ;
                        northwind:city northwind:dbpedia_iri2(customers.City)
                                as virtrdf:Customer-dbpediacity ;
                        northwind:region customers.Region
                                as virtrdf:Customer-region ;
                        northwind:PostalCode customers.PostalCode
                                as virtrdf:Customer-postal_code ;
                        foaf:phone northwind:Phone (customers.Phone)
                                as virtrdf:Customer-foaf_phone ;
                        northwind:phone northwind:Phone (customers.Phone)
                                as virtrdf:Customer-phone ;
                        northwind:fax northwind:Fax (customers.Fax)
                                as virtrdf:Customer-fax ;
                        rdfs:isDefinedBy northwind: .

                northwind:CustomerDoc (customers.CustomerID)
                        a  northwind:CustomerDoc
                                as virtrdf:CustomerDoc-CustomerID2 ;
                        a  foaf:Document
                                as virtrdf:CustomerDoc-CustomerID3 ;
                        foaf:primaryTopic northwind:Customer (customers.CustomerID)
                                as virtrdf:CustomerDoc-foaf_primarytopic ;
                        rdfs:isDefinedBy northwind: .

                northwind:Country (customers.Country)
                        northwind:is_country_of
                northwind:Customer (customers.CustomerID) as virtrdf:Customer-is_country_of .

                northwind:Employee (employees.FirstName, employees.LastName, employees.EmployeeID)
                        a northwind:Employee
                                as virtrdf:Employee-EmployeeID2 ;
                        a foaf:Person
                                as virtrdf:Employee-EmployeeID ;
                        foaf:surname employees.LastName
                                as virtrdf:Employee-foaf_last_name ;
                        northwind:lastName employees.LastName
                                as virtrdf:Employee-last_name ;
                        foaf:firstName employees.FirstName
                                as virtrdf:Employee-foaf_first_name ;
                        northwind:firstName employees.FirstName
                                as virtrdf:Employee-first_name ;
                        foaf:title employees.Title
                                as virtrdf:Employee-title ;
                        northwind:titleOfCourtesy employees.TitleOfCourtesy
                                as virtrdf:Employee-title_of_courtesy ;
                        foaf:birthday employees.BirthDate
                                as virtrdf:Employee-foaf_birth_date ;
                        northwind:birthday employees.BirthDate
                                as virtrdf:Employee-birth_date ;
                        northwind:hireDate employees.HireDate
                                as virtrdf:Employee-hire_date ;
                        northwind:address employees.Address
                                as virtrdf:Employee-address ;
                        northwind:city northwind:dbpedia_iri2(employees.City)
                                as virtrdf:Employee-dbpediacity ;
                        northwind:region employees.Region
                                as virtrdf:Employee-region ;
                        northwind:postalCode employees.PostalCode
                                as virtrdf:Employee-postal_code ;
                        northwind:country northwind:Country(employees.Country)
                                as virtrdf:Employee-country ;
                        foaf:phone employees.HomePhone
                                as virtrdf:Employee-home_phone ;
                        northwind:extension employees.Extension
                                as virtrdf:Employee-extension ;
                        northwind:notes employees.Notes
                                as virtrdf:Employee-notes ;
                        northwind:reportsTo northwind:Employee(employees.FirstName, employees.LastName, employees.ReportsTo) where (^{employees.}^.ReportsTo = ^{employees.}^.EmployeeID)
                                as virtrdf:Employee-reports_to ;
                        foaf:img northwind:EmployeePhoto(employees.EmployeeID)
                                as virtrdf:Employee-employees.EmployeePhoto ;
                        rdfs:isDefinedBy northwind: .

                northwind:EmployeeDoc (employees.FirstName, employees.LastName, employees.EmployeeID)
                        a  northwind:EmployeeDoc
                                as virtrdf:EmployeeDoc-EmployeeID2 ;
                        a  foaf:Document
                                as virtrdf:EmployeeDoc-EmployeeID3 ;
                        foaf:primaryTopic northwind:Employee (employees.FirstName, employees.LastName, employees.EmployeeID)
                                as virtrdf:EmployeeDoc-foaf_primarytopic ;
                        rdfs:isDefinedBy northwind: .

                northwind:EmployeePhoto(employees.EmployeeID)
                        a northwind:EmployeePhoto
                                as virtrdf:Employee-employees.EmployeePhotoId ;
                        rdfs:isDefinedBy northwind: .

                northwind:Employee (employees.FirstName, employees.LastName, orders.EmployeeID)
                        northwind:is_salesrep_of
                northwind:Order (orders.OrderID) where (^{orders.}^.EmployeeID = ^{employees.}^.EmployeeID) as virtrdf:Order-is_salesrep_of .

                northwind:Country (employees.Country)
                        northwind:is_country_of
                northwind:Employee (employees.FirstName, employees.LastName, employees.EmployeeID) as virtrdf:Employee-is_country_of .

                northwind:Order (orders.OrderID)
                        a northwind:Order
                                as virtrdf:Order-Order ;
                        northwind:has_customer northwind:Customer (orders.CustomerID)
                                as virtrdf:Order-order_has_customer ;
                        northwind:has_salesrep northwind:Employee (employees.FirstName, employees.LastName, orders.EmployeeID) where (^{orders.}^.EmployeeID = ^{employees.}^.EmployeeID)
                                as virtrdf:Customer-has_salesrep ;
                        northwind:has_employee northwind:Employee (employees.FirstName, employees.LastName, orders.EmployeeID) where (^{orders.}^.EmployeeID = ^{employees.}^.EmployeeID)
                                as virtrdf:Order-order_has_employee ;
                        northwind:orderDate orders.OrderDate
                                as virtrdf:Order-order_date ;
                        northwind:requiredDate orders.RequiredDate
                                as virtrdf:Order-required_date ;
                        northwind:shippedDate orders.ShippedDate
                                as virtrdf:Order-shipped_date ;
                        northwind:order_ship_via northwind:Shipper (orders.ShipVia)
                                as virtrdf:Order-order_ship_via ;
                        northwind:freight orders.Freight
                                as virtrdf:Order-freight ;
                        northwind:shipName orders.ShipName
                                as virtrdf:Order-ship_name ;
                        northwind:shipAddress orders.ShipAddress
                                as virtrdf:Order-ship_address ;
                        northwind:shipCity northwind:dbpedia_iri2(orders.ShipCity)
                                as virtrdf:Order-dbpediaship_city ;
                        northwind:shipRegion orders.ShipRegion
                                as virtrdf:Order-ship_region ;
                        northwind:shipPostal_code orders.ShipPostalCode
                                as virtrdf:Order-ship_postal_code ;
                        northwind:shipCountry northwind:Country(orders.ShipCountry)
                                as virtrdf:ship_country ;
                        rdfs:isDefinedBy northwind: .

                northwind:OrderDoc (orders.OrderID)
                        a  northwind:OrderDoc
                                as virtrdf:OrderDoc-OrderID2 ;
                        a  foaf:Document
                                as virtrdf:OrderDoc-OrderID3 ;
                        foaf:primaryTopic northwind:Order (orders.OrderID)
                                as virtrdf:OrderDoc-foaf_primarytopic ;
                        rdfs:isDefinedBy northwind: .

                northwind:Country (orders.ShipCountry)
                        northwind:is_ship_country_of
                northwind:Order (orders.OrderID) as virtrdf:Order-is_country_of .

                northwind:Customer (orders.CustomerID)
                        northwind:has_order northwind:Order (orders.OrderID) as virtrdf:Order-has_order .

                northwind:Shipper (orders.ShipVia)
                        northwind:ship_order northwind:Order (orders.OrderID) as virtrdf:Order-ship_order .

                northwind:OrderLine (order_lines.OrderID, order_lines.ProductID)
                        a northwind:OrderLine
                                as virtrdf:OrderLine-OrderLines ;
                        northwind:has_order_id northwind:Order (order_lines.OrderID)
                                as virtrdf:order_lines_has_order_id ;
                        northwind:has_product_id northwind:Product (order_lines.ProductID)
                                as virtrdf:order_lines_has_product_id ;
                        northwind:unitPrice order_lines.UnitPrice
                                as virtrdf:OrderLine-unit_price ;
                        northwind:quantity order_lines.Quantity
                                as virtrdf:OrderLine-quantity ;
                        northwind:discount order_lines.Discount
                                as virtrdf:OrderLine-discount ;
                        rdfs:isDefinedBy northwind: .

                northwind:OrderLineDoc (order_lines.OrderID, order_lines.ProductID)
                        a  northwind:OrderLineDoc
                                as virtrdf:OrderLineDoc-OrderLineID2 ;
                        a  foaf:Document
                                as virtrdf:OrderLineDoc-OrderLineID3 ;
                        foaf:primaryTopic northwind:OrderLine (order_lines.OrderID, order_lines.ProductID)
                                as virtrdf:OrderLineDoc-foaf_primarytopic ;
                        rdfs:isDefinedBy northwind: .

                northwind:Order (orders.OrderID)
                        northwind:is_order_of
                northwind:OrderLine (order_lines.OrderID, order_lines.ProductID) where (^{orders.}^.OrderID = ^{order_lines.}^.OrderID) as virtrdf:Order-is_order_of .

                northwind:Product (products.ProductID)
                        northwind:is_product_of
                northwind:OrderLine (order_lines.OrderID, order_lines.ProductID) where (^{products.}^.ProductID = ^{order_lines.}^.ProductID) as virtrdf:Product-is_product_of .

                northwind:Country (countries.Name)
                        a northwind:Country
                                as virtrdf:Country-Type2 ;
                        a wgs:SpatialThing
                                as virtrdf:Country-Type ;
                        owl:sameAs northwind:dbpedia_iri2 (countries.Name) ;
                        northwind:name countries.Name
                                as virtrdf:Country-Name ;
                        northwind:code countries.Code
                                as virtrdf:Country-Code ;
                        northwind:smallFlagDAVResourceName countries.SmallFlagDAVResourceName
                                as virtrdf:Country-SmallFlagDAVResourceName ;
                        northwind:largeFlagDAVResourceName countries.LargeFlagDAVResourceName
                                as virtrdf:Country-LargeFlagDAVResourceName ;
                        northwind:smallFlagDAVResourceURI northwind:Flag(countries.SmallFlagDAVResourceURI)
                                as virtrdf:Country-SmallFlagDAVResourceURI ;
                        northwind:largeFlagDAVResourceURI northwind:Flag(countries.LargeFlagDAVResourceURI)
                                as virtrdf:Country-LargeFlagDAVResourceURI ;
                        wgs:lat countries.Lat
                                as virtrdf:Country-Lat ;
                        wgs:long countries.Lng
                                as virtrdf:Country-Lng ;
                        rdfs:isDefinedBy northwind: .

                northwind:CountryDoc (countries.Name)
                        a  northwind:CountryDoc
                                as virtrdf:CountryDoc-CountryID2 ;
                        a  foaf:Document
                                as virtrdf:CountryDoc-CountryID3 ;
                        foaf:primaryTopic northwind:Country (countries.Name)
                                as virtrdf:CountryDoc-foaf_primarytopic ;
                        rdfs:isDefinedBy northwind: .

                northwind:Country (countries.Name)
                        northwind:has_province
                northwind:Province (provinces.CountryCode, provinces.Province) where (^{provinces.}^.CountryCode = ^{countries.}^.Code) as virtrdf:Country-has_province .

                northwind:Province (provinces.CountryCode, provinces.Province)
                        a northwind:Province
                                as virtrdf:Province-Provinces ;
                        owl:sameAs northwind:dbpedia_iri2 (provinces.Province) ;
                        northwind:has_country_code provinces.CountryCode
                                as virtrdf:has_country_code ;
                        northwind:provinceName provinces.Province
                                as virtrdf:Province-ProvinceName ;
                        rdfs:isDefinedBy northwind: .

                northwind:ProvinceDoc (provinces.CountryCode, provinces.Province)
                        a  northwind:ProvinceDoc
                                as virtrdf:ProvinceDoc-ProvinceID2 ;
                        a  foaf:Document
                                as virtrdf:ProvinceDoc-ProvinceID3 ;
                        foaf:primaryTopic northwind:Province (provinces.CountryCode, provinces.Province)
                                as virtrdf:ProvinceDoc-foaf_primarytopic ;
                        rdfs:isDefinedBy northwind: .

                northwind:Province (provinces.CountryCode, provinces.Province)
                        northwind:is_province_of
                northwind:Country (countries.Name) where  (^{countries.}^.Code = ^{provinces.}^.CountryCode) as virtrdf:Province-country_of .
        }.
}.
;

delete from DB.DBA.URL_REWRITE_RULE_LIST where urrl_list like 'demo_nw%';
delete from DB.DBA.URL_REWRITE_RULE where urr_rule like 'demo_nw%';

DB.DBA.URLREWRITE_CREATE_REGEX_RULE (
    'demo_nw_rule2',
    1,
    '(/[^#]*)',
    vector('path'),
    1,
    '/sparql?query=DESCRIBE+%%3Chttp%%3A//^{URIQADefaultHost}^%U%%23this%%3E+%%3Chttp%%3A//^{URIQADefaultHost}^%U%%3E+FROM+%%3Chttp%%3A//^{URIQADefaultHost}^/Northwind%%3E&format=%U',
    vector('path', 'path', '*accept*'),
    null,
    '(text/rdf.n3)|(application/rdf.xml)',
    0,
    null
    );

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

DB.DBA.URLREWRITE_CREATE_RULELIST (
    'demo_nw_rule_list1',
    1,
    vector (
                'demo_nw_rule1',
                'demo_nw_rule2'
          ));


VHOST_REMOVE (lpath=>'/Northwind');
DB.DBA.VHOST_DEFINE (lpath=>'/Northwind', ppath=>'/DAV/home/demo/', vsp_user=>'dba', is_dav=>1,
          is_brws=>0, opts=>vector ('url_rewrite', 'demo_nw_rule_list1'));

create procedure DB.DBA.LOAD_NW_ONTOLOGY_FROM_DAV()
{
  declare content1, urihost varchar;
  select cast (RES_CONTENT as varchar) into content1 from WS.WS.SYS_DAV_RES where RES_FULL_PATH = '/DAV/VAD/demo/sql/nw.owl';
  DB.DBA.RDF_LOAD_RDFXML (content1, 'http://demo.openlinksw.com/schemas/northwind#', 'http://demo.openlinksw.com/schemas/NorthwindOntology/1.0/');
  urihost := cfg_item_value(virtuoso_ini_path(), 'URIQA','DefaultHost');
  if (urihost = 'demo.openlinksw.com')
  {
    DB.DBA.VHOST_REMOVE (lpath=>'/schemas/northwind');
    DB.DBA.VHOST_DEFINE (lpath=>'/schemas/northwind', ppath=>'/DAV/VAD/demo/sql/nw.owl', vsp_user=>'dba', is_dav=>1, is_brws=>0);
    DB.DBA.VHOST_REMOVE (lpath=>'/schemas/northwind#');
    DB.DBA.VHOST_DEFINE (lpath=>'/schemas/northwind#', ppath=>'/DAV/VAD/demo/sql/nw.owl', vsp_user=>'dba', is_dav=>1, is_brws=>0);
  }
};

DB.DBA.LOAD_NW_ONTOLOGY_FROM_DAV();
drop procedure DB.DBA.LOAD_NW_ONTOLOGY_FROM_DAV;

DB.DBA.XML_SET_NS_DECL ('northwind', 'http://demo.openlinksw.com/schemas/northwind#', 2);

Basic Northwind Ontology

<?xml version="1.0" encoding="utf-8"?>
<!--
 -
 -
 -  This file is part of the OpenLink Software Virtuoso Open-Source (VOS)
 -  project.
 -
 -  Copyright (C) 1998-2007 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
 -
-->
<rdf:RDF xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#"
         xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
         xmlns:owl ="http://www.w3.org/2002/07/owl#"
         xmlns:virtrdf="http://www.openlinksw.com/schemas/virtrdf#"
         xml:base="http://demo.openlinksw.com/schemas/northwind#">
  <owl:Ontology rdf:about="http://demo.openlinksw.com/schemas/northwind#">
        <rdfs:label>Northwind</rdfs:label>
        <rdfs:comment>Northwind database classes and properties</rdfs:comment>
        <virtrdf:catName>Northwind</virtrdf:catName>
        <virtrdf:version>1.00</virtrdf:version>
  </owl:Ontology>

  <rdfs:Class rdf:ID="Product">
    <rdfs:label>Product</rdfs:label>
  </rdfs:Class>
  <rdf:Property rdf:ID="has_category">
    <rdfs:range rdf:resource="#Category"/>
    <rdfs:domain rdf:resource="#Product"/>
    <rdfs:cardinality>1</rdfs:cardinality>
    <rdfs:label>Category</rdfs:label>
  </rdf:Property>
  <rdf:Property rdf:ID="has_supplier">
    <rdfs:range rdf:resource="#Supplier"/>
    <rdfs:domain rdf:resource="#Product"/>
    <rdfs:cardinality>1</rdfs:cardinality>
    <rdfs:label>Supplier</rdfs:label>
  </rdf:Property>
  <rdf:Property rdf:ID="ProductName">
    <rdfs:range rdf:resource="http://www.w3.org/2001/XMLSchema#string"/>
    <rdfs:domain rdf:resource="#Product"/>
    <rdfs:cardinality>1</rdfs:cardinality>
    <rdfs:label>ProductName</rdfs:label>
  </rdf:Property>
  <rdf:Property rdf:ID="QuantityPerUnit">
    <rdfs:range rdf:resource="http://www.w3.org/2001/XMLSchema#string"/>
    <rdfs:domain rdf:resource="#Product"/>
    <rdfs:cardinality>1</rdfs:cardinality>
    <rdfs:label>QuantityPerUnit</rdfs:label>
  </rdf:Property>
  <rdf:Property rdf:ID="UnitPrice">
    <rdfs:range rdf:resource="http://www.w3.org/2001/XMLSchema#double"/>
    <rdfs:domain rdf:resource="#Product"/>
    <rdfs:domain rdf:resource="#OrderLine"/>
    <rdfs:cardinality>1</rdfs:cardinality>
    <rdfs:label>UnitPrice</rdfs:label>
  </rdf:Property>
  <rdf:Property rdf:ID="UnitsInStock">
    <rdfs:range rdf:resource="http://www.w3.org/2001/XMLSchema#integer"/>
    <rdfs:domain rdf:resource="#Product"/>
    <rdfs:cardinality>1</rdfs:cardinality>
    <rdfs:label>UnitsInStock</rdfs:label>
  </rdf:Property>
  <rdf:Property rdf:ID="UnitsOnOrder">
    <rdfs:range rdf:resource="http://www.w3.org/2001/XMLSchema#integer"/>
    <rdfs:domain rdf:resource="#Product"/>
    <rdfs:cardinality>1</rdfs:cardinality>
    <rdfs:label>UnitsOnOrder</rdfs:label>
  </rdf:Property>
  <rdf:Property rdf:ID="ReorderLevel">
    <rdfs:range rdf:resource="http://www.w3.org/2001/XMLSchema#integer"/>
    <rdfs:domain rdf:resource="#Product"/>
    <rdfs:cardinality>1</rdfs:cardinality>
    <rdfs:label>ReorderLevel</rdfs:label>
  </rdf:Property>
  <rdf:Property rdf:ID="Discontinued">
    <rdfs:range rdf:resource="http://www.w3.org/2001/XMLSchema#integer"/>
    <rdfs:domain rdf:resource="#Product"/>
    <rdfs:cardinality>1</rdfs:cardinality>
    <rdfs:label>Discontinued</rdfs:label>
  </rdf:Property>

  <rdfs:Class rdf:ID="Supplier">
    <rdfs:label>Supplier</rdfs:label>
  </rdfs:Class>
  <rdf:Property rdf:ID="CompanyName">
    <rdfs:range rdf:resource="http://www.w3.org/2001/XMLSchema#string"/>
    <rdfs:subPropertyOf rdf:resource="http://xmlns.com/foaf/0.1/name"/>
    <rdfs:domain rdf:resource="#Supplier"/>
    <rdfs:domain rdf:resource="#Shipper"/>
    <rdfs:domain rdf:resource="#Customer"/>
    <rdfs:cardinality>1</rdfs:cardinality>
    <rdfs:label>CompanyName</rdfs:label>
  </rdf:Property>
  <rdf:Property rdf:ID="ContactName">
    <rdfs:range rdf:resource="http://www.w3.org/2001/XMLSchema#string"/>
    <rdfs:subPropertyOf rdf:resource="http://xmlns.com/foaf/0.1/name"/>
    <rdfs:domain rdf:resource="#Supplier"/>
    <rdfs:domain rdf:resource="#Customer"/>
    <rdfs:domain rdf:resource="#CustomerContact"/>
    <rdfs:cardinality>1</rdfs:cardinality>
    <rdfs:label>ContactName</rdfs:label>
  </rdf:Property>
  <rdf:Property rdf:ID="ContactTitle">
    <rdfs:range rdf:resource="http://www.w3.org/2001/XMLSchema#string"/>
    <rdfs:subPropertyOf rdf:resource="http://xmlns.com/foaf/0.1/title"/>
    <rdfs:domain rdf:resource="#Supplier"/>
    <rdfs:domain rdf:resource="#Customer"/>
    <rdfs:cardinality>1</rdfs:cardinality>
    <rdfs:label>ContactTitle</rdfs:label>
  </rdf:Property>
  <rdf:Property rdf:ID="Address">
    <rdfs:range rdf:resource="http://www.w3.org/2001/XMLSchema#string"/>
    <rdfs:domain rdf:resource="#Supplier"/>
    <rdfs:domain rdf:resource="#Customer"/>
    <rdfs:domain rdf:resource="#Employee"/>
    <rdfs:cardinality>1</rdfs:cardinality>
    <rdfs:label>Address</rdfs:label>
  </rdf:Property>
  <rdf:Property rdf:ID="City">
    <rdfs:range rdf:resource="http://www.w3.org/2001/XMLSchema#string"/>
    <rdfs:domain rdf:resource="#Supplier"/>
    <rdfs:domain rdf:resource="#Customer"/>
    <rdfs:domain rdf:resource="#Employee"/>
    <rdfs:cardinality>1</rdfs:cardinality>
    <rdfs:label>City</rdfs:label>
  </rdf:Property>
  <rdf:Property rdf:ID="Region">
    <rdfs:range rdf:resource="http://www.w3.org/2001/XMLSchema#string"/>
    <rdfs:domain rdf:resource="#Supplier"/>
    <rdfs:domain rdf:resource="#Customer"/>
    <rdfs:domain rdf:resource="#Employee"/>
    <rdfs:cardinality>1</rdfs:cardinality>
    <rdfs:label>Region</rdfs:label>
  </rdf:Property>
  <rdf:Property rdf:ID="PostalCode">
    <rdfs:range rdf:resource="http://www.w3.org/2001/XMLSchema#string"/>
    <rdfs:domain rdf:resource="#Supplier"/>
    <rdfs:domain rdf:resource="#Customer"/>
    <rdfs:domain rdf:resource="#Employee"/>
    <rdfs:cardinality>1</rdfs:cardinality>
    <rdfs:label>PostalCode</rdfs:label>
  </rdf:Property>
  <rdf:Property rdf:ID="CountryName">
    <rdfs:range rdf:resource="#Country"/>
    <rdfs:domain rdf:resource="#Supplier"/>
    <rdfs:domain rdf:resource="#Customer"/>
    <rdfs:domain rdf:resource="#CustomerContact"/>
    <rdfs:domain rdf:resource="#Employee"/>
    <rdfs:cardinality>1</rdfs:cardinality>
    <rdfs:label>Country</rdfs:label>
  </rdf:Property>
  <rdf:Property rdf:ID="Phone">
    <rdfs:range rdf:resource="http://www.w3.org/2001/XMLSchema#string"/>
    <rdfs:subPropertyOf rdf:resource="http://xmlns.com/foaf/0.1/phone"/>
    <rdfs:domain rdf:resource="#Supplier"/>
    <rdfs:domain rdf:resource="#Shipper"/>
    <rdfs:domain rdf:resource="#Customer"/>
    <rdfs:domain rdf:resource="#CustomerContact"/>
    <rdfs:domain rdf:resource="#Employee"/>
    <rdfs:cardinality>1</rdfs:cardinality>
    <rdfs:label>Phone</rdfs:label>
  </rdf:Property>
  <rdf:Property rdf:ID="Fax">
    <rdfs:range rdf:resource="http://www.w3.org/2001/XMLSchema#string"/>
    <rdfs:domain rdf:resource="#Supplier"/>
    <rdfs:domain rdf:resource="#Customer"/>
    <rdfs:cardinality>1</rdfs:cardinality>
    <rdfs:label>Fax</rdfs:label>
  </rdf:Property>
  <rdf:Property rdf:ID="HomePage">
    <rdfs:range rdf:resource="http://www.w3.org/2001/XMLSchema#string"/>
    <rdfs:domain rdf:resource="#Supplier"/>
    <rdfs:cardinality>1</rdfs:cardinality>
    <rdfs:label>HomePage</rdfs:label>
  </rdf:Property>

  <rdfs:Class rdf:ID="Category">
    <rdfs:label>Category</rdfs:label>
  </rdfs:Class>
  <rdf:Property rdf:ID="CategoryName">
    <rdfs:range rdf:resource="http://www.w3.org/2001/XMLSchema#string"/>
    <rdfs:domain rdf:resource="#Category"/>
    <rdfs:cardinality>1</rdfs:cardinality>
    <rdfs:label>CategoryName</rdfs:label>
  </rdf:Property>
  <rdf:Property rdf:ID="Description">
    <rdfs:range rdf:resource="http://www.w3.org/2001/XMLSchema#string"/>
    <rdfs:domain rdf:resource="#Category"/>
    <rdfs:cardinality>1</rdfs:cardinality>
    <rdfs:label>Description</rdfs:label>
  </rdf:Property>

  <rdfs:Class rdf:ID="Shipper">
    <rdfs:label>Shipper</rdfs:label>
  </rdfs:Class>

  <rdfs:Class rdf:ID="CustomerContact">
    <rdfs:label>CustomerContact</rdfs:label>
    <rdfs:subClassOf rdf:resource="http://xmlns.com/foaf/0.1/Person"/>
  </rdfs:Class>

  <rdfs:Class rdf:ID="Customer">
    <rdfs:label>Customer</rdfs:label>
    <rdfs:subClassOf rdf:resource="http://xmlns.com/foaf/0.1/Organization"/>
  </rdfs:Class>

  <rdfs:Class rdf:ID="Employee">
    <rdfs:label>Employee</rdfs:label>
    <rdfs:subClassOf rdf:resource="http://xmlns.com/foaf/0.1/Person"/>
  </rdfs:Class>
  <rdf:Property rdf:ID="LastName">
    <rdfs:range rdf:resource="http://www.w3.org/2001/XMLSchema#string"/>
    <rdfs:subPropertyOf rdf:resource="http://xmlns.com/foaf/0.1/surname"/>
    <rdfs:domain rdf:resource="#Employee"/>
    <rdfs:cardinality>1</rdfs:cardinality>
    <rdfs:label>LastName</rdfs:label>
  </rdf:Property>
  <rdf:Property rdf:ID="FirstName">
    <rdfs:range rdf:resource="http://www.w3.org/2001/XMLSchema#string"/>
    <rdfs:subPropertyOf rdf:resource="http://xmlns.com/foaf/0.1/firstName"/>
    <rdfs:domain rdf:resource="#Employee"/>
    <rdfs:cardinality>1</rdfs:cardinality>
    <rdfs:label>FirstName</rdfs:label>
  </rdf:Property>
  <rdf:Property rdf:ID="Title">
    <rdfs:range rdf:resource="http://www.w3.org/2001/XMLSchema#string"/>
    <rdfs:subPropertyOf rdf:resource="http://xmlns.com/foaf/0.1/title"/>
    <rdfs:domain rdf:resource="#Employee"/>
    <rdfs:cardinality>1</rdfs:cardinality>
    <rdfs:label>Title</rdfs:label>
  </rdf:Property>
  <rdf:Property rdf:ID="TitleOfCourtesy">
    <rdfs:range rdf:resource="http://www.w3.org/2001/XMLSchema#string"/>
    <rdfs:domain rdf:resource="#Employee"/>
    <rdfs:cardinality>1</rdfs:cardinality>
    <rdfs:label>TitleOfCourtesy</rdfs:label>
  </rdf:Property>
  <rdf:Property rdf:ID="BirthDate">
    <rdfs:range rdf:resource="http://www.w3.org/2001/XMLSchema#string"/>
    <rdfs:subPropertyOf rdf:resource="http://xmlns.com/foaf/0.1/birthday"/>
    <rdfs:domain rdf:resource="#Employee"/>
    <rdfs:cardinality>1</rdfs:cardinality>
    <rdfs:label>BirthDate</rdfs:label>
  </rdf:Property>
  <rdf:Property rdf:ID="HireDate">
    <rdfs:range rdf:resource="http://www.w3.org/2001/XMLSchema#string"/>
    <rdfs:domain rdf:resource="#Employee"/>
    <rdfs:cardinality>1</rdfs:cardinality>
    <rdfs:label>HireDate</rdfs:label>
  </rdf:Property>
  <rdf:Property rdf:ID="Extension">
    <rdfs:range rdf:resource="http://www.w3.org/2001/XMLSchema#string"/>
    <rdfs:domain rdf:resource="#Employee"/>
    <rdfs:cardinality>1</rdfs:cardinality>
    <rdfs:label>Extension</rdfs:label>
  </rdf:Property>
  <rdf:Property rdf:ID="Notes">
    <rdfs:range rdf:resource="http://www.w3.org/2001/XMLSchema#string"/>
    <rdfs:domain rdf:resource="#Employee"/>
    <rdfs:cardinality>1</rdfs:cardinality>
    <rdfs:label>Notes</rdfs:label>
  </rdf:Property>
  <rdf:Property rdf:ID="ReportsTo">
    <rdfs:range rdf:resource="http://www.w3.org/2001/XMLSchema#integer"/>
    <rdfs:domain rdf:resource="#Employee"/>
    <rdfs:cardinality>1</rdfs:cardinality>
    <rdfs:label>ReportsTo</rdfs:label>
  </rdf:Property>

  <rdfs:Class rdf:ID="Order">
    <rdfs:label>Order</rdfs:label>
  </rdfs:Class>
  <rdf:Property rdf:ID="has_customer">
    <rdfs:range rdf:resource="#Customer"/>
    <rdfs:domain rdf:resource="#Order"/>
    <rdfs:cardinality>1</rdfs:cardinality>
    <rdfs:label>Customer</rdfs:label>
  </rdf:Property>
  <rdf:Property rdf:ID="has_employee">
    <rdfs:range rdf:resource="#Employee"/>
    <rdfs:domain rdf:resource="#Order"/>
    <rdfs:cardinality>1</rdfs:cardinality>
    <rdfs:label>Employee</rdfs:label>
  </rdf:Property>
  <rdf:Property rdf:ID="OrderDate">
    <rdfs:range rdf:resource="http://www.w3.org/2001/XMLSchema#string"/>
    <rdfs:domain rdf:resource="#Order"/>
    <rdfs:cardinality>1</rdfs:cardinality>
    <rdfs:label>OrderDate</rdfs:label>
  </rdf:Property>
  <rdf:Property rdf:ID="RequiredDate">
    <rdfs:range rdf:resource="http://www.w3.org/2001/XMLSchema#string"/>
    <rdfs:domain rdf:resource="#Order"/>
    <rdfs:cardinality>1</rdfs:cardinality>
    <rdfs:label>RequiredDate</rdfs:label>
  </rdf:Property>
  <rdf:Property rdf:ID="ShippedDate">
    <rdfs:range rdf:resource="http://www.w3.org/2001/XMLSchema#string"/>
    <rdfs:domain rdf:resource="#Order"/>
    <rdfs:cardinality>1</rdfs:cardinality>
    <rdfs:label>ShippedDate</rdfs:label>
  </rdf:Property>
  <rdf:Property rdf:ID="order_ship_via">
    <rdfs:range rdf:resource="#Shipper"/>
    <rdfs:domain rdf:resource="#Order"/>
    <rdfs:cardinality>1</rdfs:cardinality>
    <rdfs:label>Shipper</rdfs:label>
  </rdf:Property>
  <rdf:Property rdf:ID="Freight">
    <rdfs:range rdf:resource="http://www.w3.org/2001/XMLSchema#double"/>
    <rdfs:domain rdf:resource="#Order"/>
    <rdfs:cardinality>1</rdfs:cardinality>
    <rdfs:label>Freight</rdfs:label>
  </rdf:Property>
  <rdf:Property rdf:ID="ShipName">
    <rdfs:range rdf:resource="http://www.w3.org/2001/XMLSchema#string"/>
    <rdfs:domain rdf:resource="#Order"/>
    <rdfs:cardinality>1</rdfs:cardinality>
    <rdfs:label>ShipName</rdfs:label>
  </rdf:Property>
  <rdf:Property rdf:ID="ShipAddress">
    <rdfs:range rdf:resource="http://www.w3.org/2001/XMLSchema#string"/>
    <rdfs:domain rdf:resource="#Order"/>
    <rdfs:cardinality>1</rdfs:cardinality>
    <rdfs:label>ShipAddress</rdfs:label>
  </rdf:Property>
  <rdf:Property rdf:ID="ShipCity">
    <rdfs:range rdf:resource="http://www.w3.org/2001/XMLSchema#string"/>
    <rdfs:domain rdf:resource="#Order"/>
    <rdfs:cardinality>1</rdfs:cardinality>
    <rdfs:label>ShipCity</rdfs:label>
  </rdf:Property>
  <rdf:Property rdf:ID="ShipRegion">
    <rdfs:range rdf:resource="http://www.w3.org/2001/XMLSchema#string"/>
    <rdfs:domain rdf:resource="#Order"/>
    <rdfs:cardinality>1</rdfs:cardinality>
    <rdfs:label>ShipRegion</rdfs:label>
  </rdf:Property>
  <rdf:Property rdf:ID="ShipPostalCode">
    <rdfs:range rdf:resource="http://www.w3.org/2001/XMLSchema#string"/>
    <rdfs:domain rdf:resource="#Order"/>
    <rdfs:cardinality>1</rdfs:cardinality>
    <rdfs:label>ShipPostalCode</rdfs:label>
  </rdf:Property>
  <rdf:Property rdf:ID="ShipCountry">
    <rdfs:range rdf:resource="http://www.w3.org/2001/XMLSchema#string"/>
    <rdfs:domain rdf:resource="#Order"/>
    <rdfs:cardinality>1</rdfs:cardinality>
    <rdfs:label>ShipCountry</rdfs:label>
  </rdf:Property>

  <rdfs:Class rdf:ID="OrderLine">
    <rdfs:label>OrderLine</rdfs:label>
  </rdfs:Class>
  <rdf:Property rdf:ID="has_order_id">
    <rdfs:range rdf:resource="#Order"/>
    <rdfs:domain rdf:resource="#OrderLine"/>
    <rdfs:cardinality>1</rdfs:cardinality>
    <rdfs:label>Order</rdfs:label>
  </rdf:Property>
  <rdf:Property rdf:ID="has_product_id">
    <rdfs:range rdf:resource="#Product"/>
    <rdfs:domain rdf:resource="#OrderLine"/>
    <rdfs:cardinality>1</rdfs:cardinality>
    <rdfs:label>Product</rdfs:label>
  </rdf:Property>
  <rdf:Property rdf:ID="Quantity">
    <rdfs:range rdf:resource="http://www.w3.org/2001/XMLSchema#integer"/>
    <rdfs:domain rdf:resource="#OrderLine"/>
    <rdfs:cardinality>1</rdfs:cardinality>
    <rdfs:label>Quantity</rdfs:label>
  </rdf:Property>
  <rdf:Property rdf:ID="Discount">
    <rdfs:range rdf:resource="http://www.w3.org/2001/XMLSchema#double"/>
    <rdfs:domain rdf:resource="#OrderLine"/>
    <rdfs:cardinality>1</rdfs:cardinality>
    <rdfs:label>Discount</rdfs:label>
  </rdf:Property>

  <rdfs:Class rdf:ID="Country">
    <rdfs:label>Country</rdfs:label>
    <rdfs:subClassOf rdf:resource="http://www.w3.org/2003/01/geo/wgs84_pos#SpatialThing"/>
  </rdfs:Class>
  <rdf:Property rdf:ID="Name">
    <rdfs:range rdf:resource="http://www.w3.org/2001/XMLSchema#string"/>
    <rdfs:domain rdf:resource="#Country"/>
    <rdfs:cardinality>1</rdfs:cardinality>
    <rdfs:label>Name</rdfs:label>
  </rdf:Property>
  <rdf:Property rdf:ID="Code">
    <rdfs:range rdf:resource="http://www.w3.org/2001/XMLSchema#string"/>
    <rdfs:domain rdf:resource="#Country"/>
    <rdfs:cardinality>1</rdfs:cardinality>
    <rdfs:label>Code</rdfs:label>
  </rdf:Property>
  <rdf:Property rdf:ID="SmallFlagDAVResourceName">
    <rdfs:range rdf:resource="http://www.w3.org/2001/XMLSchema#string"/>
    <rdfs:domain rdf:resource="#Country"/>
    <rdfs:cardinality>1</rdfs:cardinality>
    <rdfs:label>SmallFlagDAVResourceName</rdfs:label>
  </rdf:Property>
  <rdf:Property rdf:ID="LargeFlagDAVResourceName">
    <rdfs:range rdf:resource="http://www.w3.org/2001/XMLSchema#string"/>
    <rdfs:domain rdf:resource="#Country"/>
    <rdfs:cardinality>1</rdfs:cardinality>
    <rdfs:label>LargeFlagDAVResourceName</rdfs:label>
  </rdf:Property>
  <rdf:Property rdf:ID="SmallFlagDAVResourceURI">
    <rdfs:range rdf:resource="http://www.w3.org/2001/XMLSchema#string"/>
    <rdfs:domain rdf:resource="#Country"/>
    <rdfs:cardinality>1</rdfs:cardinality>
    <rdfs:label>SmallFlagDAVResourceURI</rdfs:label>
  </rdf:Property>
  <rdf:Property rdf:ID="LargeFlagDAVResourceURI">
    <rdfs:range rdf:resource="http://www.w3.org/2001/XMLSchema#string"/>
    <rdfs:domain rdf:resource="#Country"/>
    <rdfs:cardinality>1</rdfs:cardinality>
    <rdfs:label>LargeFlagDAVResourceURI</rdfs:label>
  </rdf:Property>
  <rdf:Property rdf:ID="Lat">
    <rdfs:range rdf:resource="ttp://www.w3.org/2003/01/geo/wgs84_pos#lat"/>
    <rdfs:domain rdf:resource="#Country"/>
    <rdfs:cardinality>1</rdfs:cardinality>
    <rdfs:label>Lat</rdfs:label>
  </rdf:Property>
  <rdf:Property rdf:ID="Lng">
    <rdfs:range rdf:resource="ttp://www.w3.org/2003/01/geo/wgs84_pos#lng"/>
    <rdfs:domain rdf:resource="#Country"/>
    <rdfs:cardinality>1</rdfs:cardinality>
    <rdfs:label>Lng</rdfs:label>
  </rdf:Property>

  <rdfs:Class rdf:ID="Province">
    <rdfs:label>Province</rdfs:label>
  </rdfs:Class>
  <rdf:Property rdf:ID="has_country_code">
    <rdfs:range rdf:resource="#Country"/>
    <rdfs:domain rdf:resource="#Provinces"/>
    <rdfs:cardinality>1</rdfs:cardinality>
    <rdfs:label>Country Code</rdfs:label>
  </rdf:Property>
  <rdf:Property rdf:ID="ProvinceName">
    <rdfs:range rdf:resource="http://www.w3.org/2001/XMLSchema#string"/>
    <rdfs:domain rdf:resource="#Province"/>
    <rdfs:cardinality>1</rdfs:cardinality>
    <rdfs:label>ProvinceName</rdfs:label>
  </rdf:Property>

</rdf:RDF>

15.8.15.3. Oracle Demonstration 'HR' Database

Live links to a sample instance

Script to set up your own instance

-- Setup script for RDF views of Oracle 10 Human Resources Sample Database --

GRANT SELECT ON HR.orama.COUNTRIES TO "SPARQL", "SPARQL_UPDATE";
GRANT SELECT ON HR.orama.REGIONS TO "SPARQL", "SPARQL_UPDATE";
GRANT SELECT ON HR.orama.DEPARTMENTS TO "SPARQL", "SPARQL_UPDATE";
GRANT SELECT ON HR.orama.LOCATIONS TO "SPARQL", "SPARQL_UPDATE";
GRANT SELECT ON HR.orama.EMPLOYEES TO "SPARQL", "SPARQL_UPDATE";
GRANT SELECT ON HR.orama.JOBS TO "SPARQL", "SPARQL_UPDATE";
GRANT SELECT ON HR.orama.JOB_HISTORY TO "SPARQL", "SPARQL_UPDATE";

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

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

ttlp (
'
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .

@prefix hr: <http://localhost:8890/schemas/oraclehr/> .

hr:countries a rdfs:Class ;
	rdfs:isDefinedBy <http://localhost:8890/schemas/oraclehr> ;
	rdfs:label "COUNTRIES" ;
	rdfs:comment "Oracle HR COUNTRIES table" .

hr:country_id a rdf:Property ;
	rdfs:domain hr:countries ;
	rdfs:range xsd:string ;
	rdfs:label "COUNTRY ID" .

hr:country_name a rdf:Property ;
	rdfs:domain hr:countries ;
	rdfs:range xsd:string ;
	rdfs:label "COUNTRY NAME" .

hr:region_id a rdf:Property ;
	rdfs:domain hr:countries ;
	rdfs:range hr:regions ;
	rdfs:label "REGION ID" .

hr:regions a rdfs:Class ;
	rdfs:isDefinedBy <http://localhost:8890/schemas/oraclehr> ;
	rdfs:label "REGIONS" ;
	rdfs:comment "Oracle HR REGIONS table" .

hr:region_id a rdf:Property ;
	rdfs:domain hr:regions ;
	rdfs:range xsd:integer ;
        rdfs:label "REGION ID" .

hr:region_name a rdf:Property ;
	rdfs:domain hr:regions ;
	rdfs:range xsd:string ;
	rdfs:label "REGION NAME" .

hr:departments a rdfs:Class ;
	rdfs:isDefinedBy <http://localhost:8890/schemas/oraclehr> ;
	rdfs:label "DEPARTMENTS" ;
	rdfs:comment "Oracle HR DEPARTMENT table" .

hr:department_id a rdf:Property ;
	rdfs:domain hr:departments ;
	rdfs:range xsd:integer ;
	rdfs:label "DEPARTMENT ID" .

hr:department_name a rdf:Property ;
   	rdfs:domain hr:departments ;
	rdfs:range xsd:string ;
	rdfs:comment "DEPARTMENT NAME" .

hr:manager_id a rdf:Property ;
 	rdfs:domain hr:departments ;
	rdfs:range hr:employees ;
	rdfs:comment "MANAGER ID" .

hr:location_id a rdf:Property ;
	rdfs:domain hr:departments ;
	rdfs:range hr:locations ;
	rdfs:comment "LOCATION ID" .

hr:employees a rdfs:Class ;
	rdfs:isDefinedBy <http://localhost:8890/schemas/oraclehr> ;
	rdfs:label "employees" ;
	rdfs:comment "Oracle HR EMPLOYEES table" .

hr:employee_id a rdf:Property ;
	rdfs:domain hr:employees;
	rdfs:range xsd:integer ;
	rdfs:label "EMPLOYEE ID" .

hr:first_name a rdf:Property ;
	rdfs:domain hr:employees;
	rdfs:range xsd:string ;
	rdfs:label "FIRST NAME" .

hr:last_name a rdf:Property ;
	rdfs:domain hr:employees ;
	rdfs:range xsd:string ;
	rdfs:label "LAST NAME" .

hr:email a rdf:Property ;
	rdfs:domain hr:employees;
	rdfs:range xsd:string ;
	rdfs:label "EMAIL" .

hr:phone_number a rdf:Property ;
	rdfs:domain hr:employees ;
	rdfs:range xsd:string ;
	rdfs:label "PHONE NUMBER" .

hr:hire_date a rdf:Property ;
	rdfs:domain hr:employees ;
	rdfs:range xsd:date ;
	rdfs:label "HIRE DATE" .

hr:job_id a rdf:Property ;
	rdfs:domain hr:employees;
	rdfs:range hr:jobs ;
	rdfs:label "JOB ID" .

hr:salary a rdf:Property ;
	rdfs:domain hr:employees ;
	rdfs:range xsd:integer ;
	rdfs:label "SALARY" .

hr:commission_pct a rdf:Property ;
	rdfs:domain hr:employees ;
	rdfs:range xsd:integer ;
	rdfs:label "COMMISSION PCT" .

hr:manager_id a rdf:Property ;
	rdfs:domain hr:employees ;
	rdfs:range xsd:string ;
	rdfs:label "MANAGER ID" .

hr:department_id a rdf:Property ;
	rdfs:domain hr:employees ;
	rdfs:range hr:departments ;
	rdfs:label "DEPARTMENT ID" .

hr:jobs a rdfs:Class ;
	rdfs:isDefinedBy <http://localhost:8890/schemas/oraclehr> ;
	rdfs:label "JOBS" ;
	rdfs:comment "Oracle HR JOBS table" .

hr:job_id a rdf:Property ;

	rdfs:domain hr:jobs ;
	rdfs:range xsd:string ;
	rdfs:label "JOB ID" .

hr:job_title a rdf:Property ;
	rdfs:domain hr:jobs ;
	rdfs:range xsd:string ;
	rdfs:label "JOB TITLE" .

hr:min_salary a rdf:Property ;
	rdfs:domain hr:jobs ;
	rdfs:range xsd:number;
	rdfs:label "MIN SALARY" .

hr:max_salary a rdf:Property ;
	rdfs:domain hr:jobs ;
	rdfs:range xsd:number;
	rdfs:label "MAXSALARY" .

hr:job_history a rdfs:Class ;
	rdfs:isDefinedBy <http://localhost:8890/schemas/oraclehr> ;
	rdfs:label "JOB HISTORY" ;
	rdfs:comment "Oracle HR JOB HISTORY table" .

hr:employee_id a rdf:Property ;
	rdfs:domain hr:job_history ;
	rdfs:range hr:employees ;
	rdfs:label "EMPLOYEE ID" .

hr:start_date a rdf:Property ;
	rdfs:domain hr:job_history ;
	rdfs:range xsd:date ;
	rdfs:label "START DATE" .

hr:end_date a rdf:Property ;
	rdfs:domain hr:job_history ;
	rdfs:range xsd:date ;
	rdfs:label "END DATE" .

hr:job_id a rdf:Property ;
	rdfs:domain hr:job_history ;
	rdfs:range hr:jobs ;
	rdfs:label "JOB ID" .

hr:department_id a rdf:Property ;
	rdfs:domain hr:job_history ;
	rdfs:range hr:departments ;
	rdfs:label "DEPARTMENT ID" .

hr:locations a rdfs:Class ;
	rdfs:isDefinedBy <http://localhost:8890/schemas/oraclehr> ;
	rdfs:label "LOCATIONS" ;
	rdfs:comment "Oracle HR JOB LOCATIONS table" .

hr:location_id a rdf:Property ;
	rdfs:domain hr:locations ;
	rdfs:range xsd:number ;
	rdfs:label "LOCATION ID" .

hr:street_address a rdf:Property ;
	rdfs:domain hr:locations ;
	rdfs:range xsd:string ;
	rdfs:label "STREET ADDRESS" .

hr:postal_code a rdf:Property ;
	rdfs:domain hr:locations ;
	rdfs:range xsd:string ;
	rdfs:label "POSTAL CODE" .

hr:city a rdf:Property ;
	rdfs:domain hr:locations ;
	rdfs:range xsd:string ;
	rdfs:label "CITY" .

hr:state_province a rdf:Property ;
	rdfs:domain hr:locations ;
	rdfs:range xsd:string ;
	rdfs:label "STATE PROVINCE" .

hr:country_id a rdf:Property ;
	rdfs:domain hr:locations ;
	rdfs:range hr:countries ;
	rdfs:label "COUNTRY" .
', '', 'http://localhost:8890/schemas/oraclehr', 0);

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

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

create function DB.DBA.JOB_HISTORY (in EMPLOYEE_ID integer, in
START_DATE date) returns varchar
{
  return sprintf_or_null
('http://localhost:8890/oraclehr/job_history/%d_%s#this',
  EMPLOYEE_ID, cast (START_DATE as varchar) );
}
;

create function DB.DBA.JOB_HISTORY_INV_1 (in id varchar) returns integer
{
  return sprintf_inverse (id,
'http://localhost:8890/oraclehr/job_history/%d_%s#this',
2)[0];
}
;

create function DB.DBA.JOB_HISTORY_INV_2 (in id varchar) returns date
{
  declare exit handler for sqlstate '*' { return NULL; };
  return cast (sprintf_inverse (id,
'http://localhost:8890/oraclehr/job_history/%d_%s#this',
2)[1] as date);
}
;


GRANT EXECUTE ON DB.DBA.JOB_HISTORY TO "SPARQL", "SPARQL_UPDATE";
GRANT EXECUTE ON DB.DBA.JOB_HISTORY_URI_INV_1 TO "SPARQL", "SPARQL_UPDATE";
GRANT EXECUTE ON DB.DBA.JOB_HISTORY_URI_INV_2 TO "SPARQL", "SPARQL_UPDATE";

sparql


	create iri class <http://localhost:8890/schemas/oraclehr/countries_iri>
	"http://^{URIQADefaultHost}^/oraclehr/countries/%s#this"
    	(in COUNTRY_ID varchar not null) .

	create iri class <http://localhost:8890/schemas/oraclehr/regions_iri>
	"http://^{URIQADefaultHost}^/oraclehr/regions/%d#this"
	    (in REGION_ID integer not null) .

	create iri class <http://localhost:8890/schemas/oraclehr/departments_iri>
	"http://^{URIQADefaultHost}^/oraclehr/departments/%d#this"
	    (in DEPARTMENT_ID integer not null) .

	create iri class <http://localhost:8890/schemas/oraclehr/employees_iri>
	"http://^{URIQADefaultHost}^/oraclehr/employees/%d#this"
		(in EMPLOYEE_ID integer not null) .

	create iri class <http://localhost:8890/schemas/oraclehr/jobs_iri>
	"http://^{URIQADefaultHost}^/oraclehr/jobs/%s#this"
	    (in JOB_ID varchar not null) .

	create iri class <http://localhost:8890/schemas/oraclehr/job_history_iri>
		using function DB.DBA.JOB_HISTORY (in EMPLOYEE_ID integer not null, in
		START_DATE date not null) returns varchar not null,
		function DB.DBA.JOB_HISTORY_INV_1 (in id varchar) returns integer,
		function DB.DBA.JOB_HISTORY_INV_2 (in id varchar) returns date
		option (bijection, returns
		"http://localhost:8890/oraclehr/job_history/%d_%s#this") .

	create iri class <http://localhost:8890/schemas/oraclehr/locations_iri>
	"http://^{URIQADefaultHost}^/oraclehr/locations/%d#this"
	    (in LOCATION_ID integer not null) .
;

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

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

sparql

prefix hr: <http://localhost:8890/schemas/oraclehr/>

alter quad storage virtrdf:DefaultQuadStorage
  from HR.orama.COUNTRIES as countries_tbl
  from HR.orama.REGIONS as regions_tbl
  from HR.orama.DEPARTMENTS as departments_tbl
  from HR.orama.EMPLOYEES as employees_tbl
  from HR.orama.EMPLOYEES as employees_tbl_1		### alias required to represent recursive FK relationship (hr: has_manager ) below.
  from HR.orama.JOBS as jobs_tbl
  from HR.orama.JOB_HISTORY as job_history_tbl
  from HR.orama.LOCATIONS as locations_tbl
{
  create virtrdf:oraclehr as
      graph <http://localhost:8890/oraclehr>
  {
        hr:countries_iri(countries_tbl.COUNTRY_ID) a hr:countries  as virtrdf:countires_country_id ;
        hr:country_name countries_tbl.COUNTRY_NAME  as virtrdf:countries_country_name ;
        hr:region_id hr:regions_iri(regions_tbl.REGION_ID) where (^{countries_tbl.}^.REGION_ID = ^{regions_tbl.}^.REGION_ID)  as virtrdf:countries_region_id .

	hr:regions_iri(regions_tbl.REGION_ID) a hr:regions as virtrdf:regions_region_id ;
	hr:region_name regions_tbl.REGION_NAME  as virtrdf:regions_region_name .

	hr:departments_iri(departments_tbl.DEPARTMENT_ID) a hr:departments as virtrdf:departments_department_id ;
	hr:department_name departments_tbl.DEPARTMENT_NAME as virtrdf:departments_department_name ;
	hr:location_id hr:locations_iri(locations_tbl.LOCATION_ID) where (^{departments_tbl.}^.LOCATION_ID = ^{locations_tbl.}^.LOCATION_ID) as virtrdf:departments_location_id ;
	hr:manager_id hr:employees_iri(employees_tbl.EMPLOYEE_ID) where (^{departments_tbl.}^.MANAGER_ID = ^{employees_tbl.}^.EMPLOYEE_ID) as virtrdf:departments_manager_id .

	hr:employees_iri(employees_tbl.EMPLOYEE_ID) a hr:employees as virtrdf:employees_employee_id ;
	hr:department_id hr:departments_iri(departments_tbl.DEPARTMENT_ID) where (^{employees_tbl.}^.DEPARTMENT_ID = ^{departments_tbl.}^.DEPARTMENT_ID) as virtrdf:employees_department_id ;
	hr:job_id hr:jobs_iri(jobs_tbl.JOB_ID) where (^{employees_tbl.}^.JOB_ID = ^{jobs_tbl.}^.JOB_ID) as virtrdf:employees_job_id ;
	hr:manager_id employees_tbl.MANAGER_ID as virtrdf:employees_manager_id ;
	hr:commissin_pct employees_tbl.COMMISSION_PCT as virtrdf:employees_commission_pct ;
	hr:email employees_tbl.EMAIL as virtrdf:employees_email ;
	hr:first_name employees_tbl.FIRST_NAME as virtrdf:employees_first_name ;
	hr:hire_date employees_tbl.HIRE_DATE as virtrdf:employees_hire_date ;
	hr:last_name employees_tbl.LAST_NAME as virtrdf:employees_last_name ;
	hr:phone_number employees_tbl.PHONE_NUMBER as virtrdf:employees_phone_number ;
	hr:salary employees_tbl.SALARY as virtrdf:employees_salary ;
	hr:has_job_history hr:job_history_iri(job_history_tbl.EMPLOYEE_ID, job_history_tbl.START_DATE) where (^{employees_tbl.}^.EMPLOYEE_ID = ^{job_history_tbl.}^.EMPLOYEE_ID) as virtrdf:employees_has_job_history;
	hr:has_manager hr:employees_iri(employees_tbl_1.EMPLOYEE_ID) where (^{employees_tbl.}^.MANAGER_ID = ^{employees_tbl_1.}^.EMPLOYEE_ID) as virtrdf:employees_has_manager.

	hr:locations_iri(locations_tbl.LOCATION_ID) a hr:locations as virtrdf:locations_location_id ;
	hr:country_id hr:countries_iri(countries_tbl.COUNTRY_ID) where (^{locations_tbl.}^.COUNTRY_ID = ^{countries_tbl.}^.COUNTRY_ID) as virtrdf:locations_country_id ;
	hr:city locations_tbl.CITY as virtrdf:locations_city ;
	hr:postal_code locations_tbl.POSTAL_CODE as virtrdf:locations_postal_code ;
	hr:state_province locations_tbl.STATE_PROVINCE as virtrdf:locations_state_province ;
	hr:street_address locations_tbl.STREET_ADDRESS as virtrdf:locations_street_address .

	hr:jobs_iri(jobs_tbl.JOB_ID) a hr:jobs as virtrdf:jobs_job_id ;
	hr:job_title jobs_tbl.JOB_TITLE as virtrdf:jobs_job_title ;
	hr:max_salary jobs_tbl.MAX_SALARY as virtrdf:jobs_max_salary ;
	hr:min_salary jobs_tbl.MIN_SALARY as virtrdf:jobs_min_salary .

	hr:job_history_iri(job_history_tbl.EMPLOYEE_ID, job_history_tbl.START_DATE) a hr:job_history as virtrdf:job_history_pk ;
	hr:employee_id hr:employees_iri(employees_tbl.EMPLOYEE_ID) where (^{job_history_tbl.}^.EMPLOYEE_ID = ^{employees_tbl.}^.EMPLOYEE_ID) as virtrdf:job_history_employee_id ;
	hr:department_id hr:departments_iri(departments_tbl.DEPARTMENT_ID) where (^{job_history_tbl.}^.DEPARTMENT_ID = ^{departments_tbl.}^.DEPARTMENT_ID) as virtrdf:job_history_department_id ;
	hr:job_id hr:jobs_iri(jobs_tbl.JOB_ID) where (^{job_history_tbl.}^.JOB_ID = ^{jobs_tbl.}^.JOB_ID) as virtrdf:job_history_job_id ;
	hr:start_date job_history_tbl.START_DATE as virtrdf:job_history_start_date ;
	hr:end_date job_history_tbl.END_DATE as virtrdf:job_history_end_date .

  } .
} .
;

delete from db.dba.url_rewrite_rule_list where urrl_list like 'oraclehr_rule%';
delete from db.dba.url_rewrite_rule where urr_rule like 'oraclehr_rule%';

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


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

DB.DBA.URLREWRITE_CREATE_RULELIST (
    'oraclehr_rule_list1',
    1,
    vector (
  	 	'oraclehr_rule1',
  	 	'oraclehr_rule2'
	  ));

-- ensure a VD for the IRIs which begins with /
VHOST_REMOVE (lpath=>'/oraclehr');

VHOST_DEFINE (
	lpath=>'/oraclehr',
	ppath=>'/DAV/oraclehr/',
    	is_dav=>1,
	vsp_user=>'dba',
	is_brws=>0,
	opts=>vector ('url_rewrite', 'oraclehr_rule_list1')
	);

delete from db.dba.url_rewrite_rule_list where urrl_list like 'oracle_schemas_rule%';
delete from db.dba.url_rewrite_rule where urr_rule like 'oracle_schemas_rule%';

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

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

DB.DBA.URLREWRITE_CREATE_RULELIST (
    'oracle_schemas_rule_list1',
    1,
    vector (
  	 	'oracle_schemas_rule1',
  	 	'oracle_schemas_rule2'
	  ));

-- ensure a VD for the IRIs which begins with /
VHOST_REMOVE (lpath=>'/schema/oraclehr');

VHOST_DEFINE (
	lpath=>'/schemas/oraclehr',
	ppath=>'/DAV/schemas/oraclehr/',
    	is_dav=>1,
	vsp_user=>'dba',
	is_brws=>0,
	opts=>vector ('url_rewrite', 'oracle_schemas_rule_list1')
	);

DB.DBA.XML_SET_NS_DECL ('hr', 'http://^{URIQADefaultHost}^/schemas/oraclehr/', 2);

15.8.15.4. Oracle using the demonstration 'Human Resources' database

Live links to a sample instance

Script to set up your own instance

-- Setup script for RDF views of Oracle 10 Human Resources Sample Database --

GRANT SELECT ON HR.orama.COUNTRIES TO "SPARQL", "SPARQL_UPDATE";
GRANT SELECT ON HR.orama.REGIONS TO "SPARQL", "SPARQL_UPDATE";
GRANT SELECT ON HR.orama.DEPARTMENTS TO "SPARQL", "SPARQL_UPDATE";
GRANT SELECT ON HR.orama.LOCATIONS TO "SPARQL", "SPARQL_UPDATE";
GRANT SELECT ON HR.orama.EMPLOYEES TO "SPARQL", "SPARQL_UPDATE";
GRANT SELECT ON HR.orama.JOBS TO "SPARQL", "SPARQL_UPDATE";
GRANT SELECT ON HR.orama.JOB_HISTORY TO "SPARQL", "SPARQL_UPDATE";

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

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

ttlp (
'
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .

@prefix hr: <http://localhost:8890/schemas/oraclehr/> .

hr:countries a rdfs:Class ;
	rdfs:isDefinedBy <http://localhost:8890/schemas/oraclehr> ;
	rdfs:label "COUNTRIES" ;
	rdfs:comment "Oracle HR COUNTRIES table" .

hr:country_id a rdf:Property ;
	rdfs:domain hr:countries ;
	rdfs:range xsd:string ;
	rdfs:label "COUNTRY ID" .

hr:country_name a rdf:Property ;
	rdfs:domain hr:countries ;
	rdfs:range xsd:string ;
	rdfs:label "COUNTRY NAME" .

hr:region_id a rdf:Property ;
	rdfs:domain hr:countries ;
	rdfs:range hr:regions ;
	rdfs:label "REGION ID" .

hr:regions a rdfs:Class ;
	rdfs:isDefinedBy <http://localhost:8890/schemas/oraclehr> ;
	rdfs:label "REGIONS" ;
	rdfs:comment "Oracle HR REGIONS table" .

hr:region_id a rdf:Property ;
	rdfs:domain hr:regions ;
	rdfs:range xsd:integer ;
        rdfs:label "REGION ID" .

hr:region_name a rdf:Property ;
	rdfs:domain hr:regions ;
	rdfs:range xsd:string ;
	rdfs:label "REGION NAME" .

hr:departments a rdfs:Class ;
	rdfs:isDefinedBy <http://localhost:8890/schemas/oraclehr> ;
	rdfs:label "DEPARTMENTS" ;
	rdfs:comment "Oracle HR DEPARTMENT table" .

hr:department_id a rdf:Property ;
	rdfs:domain hr:departments ;
	rdfs:range xsd:integer ;
	rdfs:label "DEPARTMENT ID" .

hr:department_name a rdf:Property ;
   	rdfs:domain hr:departments ;
	rdfs:range xsd:string ;
	rdfs:comment "DEPARTMENT NAME" .

hr:manager_id a rdf:Property ;
 	rdfs:domain hr:departments ;
	rdfs:range hr:employees ;
	rdfs:comment "MANAGER ID" .

hr:location_id a rdf:Property ;
	rdfs:domain hr:departments ;
	rdfs:range hr:locations ;
	rdfs:comment "LOCATION ID" .

hr:employees a rdfs:Class ;
	rdfs:isDefinedBy <http://localhost:8890/schemas/oraclehr> ;
	rdfs:label "employees" ;
	rdfs:comment "Oracle HR EMPLOYEES table" .

hr:employee_id a rdf:Property ;
	rdfs:domain hr:employees;
	rdfs:range xsd:integer ;
	rdfs:label "EMPLOYEE ID" .

hr:first_name a rdf:Property ;
	rdfs:domain hr:employees;
	rdfs:range xsd:string ;
	rdfs:label "FIRST NAME" .

hr:last_name a rdf:Property ;
	rdfs:domain hr:employees ;
	rdfs:range xsd:string ;
	rdfs:label "LAST NAME" .

hr:email a rdf:Property ;
	rdfs:domain hr:employees;
	rdfs:range xsd:string ;
	rdfs:label "EMAIL" .

hr:phone_number a rdf:Property ;
	rdfs:domain hr:employees ;
	rdfs:range xsd:string ;
	rdfs:label "PHONE NUMBER" .

hr:hire_date a rdf:Property ;
	rdfs:domain hr:employees ;
	rdfs:range xsd:date ;
	rdfs:label "HIRE DATE" .

hr:job_id a rdf:Property ;
	rdfs:domain hr:employees;
	rdfs:range hr:jobs ;
	rdfs:label "JOB ID" .

hr:salary a rdf:Property ;
	rdfs:domain hr:employees ;
	rdfs:range xsd:integer ;
	rdfs:label "SALARY" .

hr:commission_pct a rdf:Property ;
	rdfs:domain hr:employees ;
	rdfs:range xsd:integer ;
	rdfs:label "COMMISSION PCT" .

hr:manager_id a rdf:Property ;
	rdfs:domain hr:employees ;
	rdfs:range xsd:string ;
	rdfs:label "MANAGER ID" .

hr:department_id a rdf:Property ;
	rdfs:domain hr:employees ;
	rdfs:range hr:departments ;
	rdfs:label "DEPARTMENT ID" .

hr:jobs a rdfs:Class ;
	rdfs:isDefinedBy <http://localhost:8890/schemas/oraclehr> ;
	rdfs:label "JOBS" ;
	rdfs:comment "Oracle HR JOBS table" .

hr:job_id a rdf:Property ;

	rdfs:domain hr:jobs ;
	rdfs:range xsd:string ;
	rdfs:label "JOB ID" .

hr:job_title a rdf:Property ;
	rdfs:domain hr:jobs ;
	rdfs:range xsd:string ;
	rdfs:label "JOB TITLE" .

hr:min_salary a rdf:Property ;
	rdfs:domain hr:jobs ;
	rdfs:range xsd:number;
	rdfs:label "MIN SALARY" .

hr:max_salary a rdf:Property ;
	rdfs:domain hr:jobs ;
	rdfs:range xsd:number;
	rdfs:label "MAXSALARY" .

hr:job_history a rdfs:Class ;
	rdfs:isDefinedBy <http://localhost:8890/schemas/oraclehr> ;
	rdfs:label "JOB HISTORY" ;
	rdfs:comment "Oracle HR JOB HISTORY table" .

hr:employee_id a rdf:Property ;
	rdfs:domain hr:job_history ;
	rdfs:range hr:employees ;
	rdfs:label "EMPLOYEE ID" .

hr:start_date a rdf:Property ;
	rdfs:domain hr:job_history ;
	rdfs:range xsd:date ;
	rdfs:label "START DATE" .

hr:end_date a rdf:Property ;
	rdfs:domain hr:job_history ;
	rdfs:range xsd:date ;
	rdfs:label "END DATE" .

hr:job_id a rdf:Property ;
	rdfs:domain hr:job_history ;
	rdfs:range hr:jobs ;
	rdfs:label "JOB ID" .

hr:department_id a rdf:Property ;
	rdfs:domain hr:job_history ;
	rdfs:range hr:departments ;
	rdfs:label "DEPARTMENT ID" .

hr:locations a rdfs:Class ;
	rdfs:isDefinedBy <http://localhost:8890/schemas/oraclehr> ;
	rdfs:label "LOCATIONS" ;
	rdfs:comment "Oracle HR JOB LOCATIONS table" .

hr:location_id a rdf:Property ;
	rdfs:domain hr:locations ;
	rdfs:range xsd:number ;
	rdfs:label "LOCATION ID" .

hr:street_address a rdf:Property ;
	rdfs:domain hr:locations ;
	rdfs:range xsd:string ;
	rdfs:label "STREET ADDRESS" .

hr:postal_code a rdf:Property ;
	rdfs:domain hr:locations ;
	rdfs:range xsd:string ;
	rdfs:label "POSTAL CODE" .

hr:city a rdf:Property ;
	rdfs:domain hr:locations ;
	rdfs:range xsd:string ;
	rdfs:label "CITY" .

hr:state_province a rdf:Property ;
	rdfs:domain hr:locations ;
	rdfs:range xsd:string ;
	rdfs:label "STATE PROVINCE" .

hr:country_id a rdf:Property ;
	rdfs:domain hr:locations ;
	rdfs:range hr:countries ;
	rdfs:label "COUNTRY" .
', '', 'http://localhost:8890/schemas/oraclehr', 0);

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

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

create function DB.DBA.JOB_HISTORY (in EMPLOYEE_ID integer, in
START_DATE date) returns varchar
{
  return sprintf_or_null
('http://localhost:8890/oraclehr/job_history/%d_%s#this',
  EMPLOYEE_ID, cast (START_DATE as varchar) );
}
;

create function DB.DBA.JOB_HISTORY_INV_1 (in id varchar) returns integer
{
  return sprintf_inverse (id,
'http://localhost:8890/oraclehr/job_history/%d_%s#this',
2)[0];
}
;

create function DB.DBA.JOB_HISTORY_INV_2 (in id varchar) returns date
{
  declare exit handler for sqlstate '*' { return NULL; };
  return cast (sprintf_inverse (id,
'http://localhost:8890/oraclehr/job_history/%d_%s#this',
2)[1] as date);
}
;


GRANT EXECUTE ON DB.DBA.JOB_HISTORY TO "SPARQL", "SPARQL_UPDATE";
GRANT EXECUTE ON DB.DBA.JOB_HISTORY_URI_INV_1 TO "SPARQL", "SPARQL_UPDATE";
GRANT EXECUTE ON DB.DBA.JOB_HISTORY_URI_INV_2 TO "SPARQL", "SPARQL_UPDATE";

sparql


	create iri class <http://localhost:8890/schemas/oraclehr/countries_iri>
	"http://^{URIQADefaultHost}^/oraclehr/countries/%s#this"
    	(in COUNTRY_ID varchar not null) .

	create iri class <http://localhost:8890/schemas/oraclehr/regions_iri>
	"http://^{URIQADefaultHost}^/oraclehr/regions/%d#this"
	    (in REGION_ID integer not null) .

	create iri class <http://localhost:8890/schemas/oraclehr/departments_iri>
	"http://^{URIQADefaultHost}^/oraclehr/departments/%d#this"
	    (in DEPARTMENT_ID integer not null) .

	create iri class <http://localhost:8890/schemas/oraclehr/employees_iri>
	"http://^{URIQADefaultHost}^/oraclehr/employees/%d#this"
		(in EMPLOYEE_ID integer not null) .

	create iri class <http://localhost:8890/schemas/oraclehr/jobs_iri>
	"http://^{URIQADefaultHost}^/oraclehr/jobs/%s#this"
	    (in JOB_ID varchar not null) .

	create iri class <http://localhost:8890/schemas/oraclehr/job_history_iri>
		using function DB.DBA.JOB_HISTORY (in EMPLOYEE_ID integer not null, in
		START_DATE date not null) returns varchar not null,
		function DB.DBA.JOB_HISTORY_INV_1 (in id varchar) returns integer,
		function DB.DBA.JOB_HISTORY_INV_2 (in id varchar) returns date
		option (bijection, returns
		"http://localhost:8890/oraclehr/job_history/%d_%s#this") .

	create iri class <http://localhost:8890/schemas/oraclehr/locations_iri>
	"http://^{URIQADefaultHost}^/oraclehr/locations/%d#this"
	    (in LOCATION_ID integer not null) .
;

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

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

sparql

prefix hr: <http://localhost:8890/schemas/oraclehr/>

alter quad storage virtrdf:DefaultQuadStorage
  from HR.orama.COUNTRIES as countries_tbl
  from HR.orama.REGIONS as regions_tbl
  from HR.orama.DEPARTMENTS as departments_tbl
  from HR.orama.EMPLOYEES as employees_tbl
  from HR.orama.EMPLOYEES as employees_tbl_1		### alias required to represent recursive FK relationship (hr: has_manager ) below.
  from HR.orama.JOBS as jobs_tbl
  from HR.orama.JOB_HISTORY as job_history_tbl
  from HR.orama.LOCATIONS as locations_tbl
{
  create virtrdf:oraclehr as
      graph <http://localhost:8890/oraclehr>
  {
        hr:countries_iri(countries_tbl.COUNTRY_ID) a hr:countries  as virtrdf:countires_country_id ;
        hr:country_name countries_tbl.COUNTRY_NAME  as virtrdf:countries_country_name ;
        hr:region_id hr:regions_iri(regions_tbl.REGION_ID) where (^{countries_tbl.}^.REGION_ID = ^{regions_tbl.}^.REGION_ID)  as virtrdf:countries_region_id .

	hr:regions_iri(regions_tbl.REGION_ID) a hr:regions as virtrdf:regions_region_id ;
	hr:region_name regions_tbl.REGION_NAME  as virtrdf:regions_region_name .

	hr:departments_iri(departments_tbl.DEPARTMENT_ID) a hr:departments as virtrdf:departments_department_id ;
	hr:department_name departments_tbl.DEPARTMENT_NAME as virtrdf:departments_department_name ;
	hr:location_id hr:locations_iri(locations_tbl.LOCATION_ID) where (^{departments_tbl.}^.LOCATION_ID = ^{locations_tbl.}^.LOCATION_ID) as virtrdf:departments_location_id ;
	hr:manager_id hr:employees_iri(employees_tbl.EMPLOYEE_ID) where (^{departments_tbl.}^.MANAGER_ID = ^{employees_tbl.}^.EMPLOYEE_ID) as virtrdf:departments_manager_id .

	hr:employees_iri(employees_tbl.EMPLOYEE_ID) a hr:employees as virtrdf:employees_employee_id ;
	hr:department_id hr:departments_iri(departments_tbl.DEPARTMENT_ID) where (^{employees_tbl.}^.DEPARTMENT_ID = ^{departments_tbl.}^.DEPARTMENT_ID) as virtrdf:employees_department_id ;
	hr:job_id hr:jobs_iri(jobs_tbl.JOB_ID) where (^{employees_tbl.}^.JOB_ID = ^{jobs_tbl.}^.JOB_ID) as virtrdf:employees_job_id ;
	hr:manager_id employees_tbl.MANAGER_ID as virtrdf:employees_manager_id ;
	hr:commissin_pct employees_tbl.COMMISSION_PCT as virtrdf:employees_commission_pct ;
	hr:email employees_tbl.EMAIL as virtrdf:employees_email ;
	hr:first_name employees_tbl.FIRST_NAME as virtrdf:employees_first_name ;
	hr:hire_date employees_tbl.HIRE_DATE as virtrdf:employees_hire_date ;
	hr:last_name employees_tbl.LAST_NAME as virtrdf:employees_last_name ;
	hr:phone_number employees_tbl.PHONE_NUMBER as virtrdf:employees_phone_number ;
	hr:salary employees_tbl.SALARY as virtrdf:employees_salary ;
	hr:has_job_history hr:job_history_iri(job_history_tbl.EMPLOYEE_ID, job_history_tbl.START_DATE) where (^{employees_tbl.}^.EMPLOYEE_ID = ^{job_history_tbl.}^.EMPLOYEE_ID) as virtrdf:employees_has_job_history;
	hr:has_manager hr:employees_iri(employees_tbl_1.EMPLOYEE_ID) where (^{employees_tbl.}^.MANAGER_ID = ^{employees_tbl_1.}^.EMPLOYEE_ID) as virtrdf:employees_has_manager.

	hr:locations_iri(locations_tbl.LOCATION_ID) a hr:locations as virtrdf:locations_location_id ;
	hr:country_id hr:countries_iri(countries_tbl.COUNTRY_ID) where (^{locations_tbl.}^.COUNTRY_ID = ^{countries_tbl.}^.COUNTRY_ID) as virtrdf:locations_country_id ;
	hr:city locations_tbl.CITY as virtrdf:locations_city ;
	hr:postal_code locations_tbl.POSTAL_CODE as virtrdf:locations_postal_code ;
	hr:state_province locations_tbl.STATE_PROVINCE as virtrdf:locations_state_province ;
	hr:street_address locations_tbl.STREET_ADDRESS as virtrdf:locations_street_address .

	hr:jobs_iri(jobs_tbl.JOB_ID) a hr:jobs as virtrdf:jobs_job_id ;
	hr:job_title jobs_tbl.JOB_TITLE as virtrdf:jobs_job_title ;
	hr:max_salary jobs_tbl.MAX_SALARY as virtrdf:jobs_max_salary ;
	hr:min_salary jobs_tbl.MIN_SALARY as virtrdf:jobs_min_salary .

	hr:job_history_iri(job_history_tbl.EMPLOYEE_ID, job_history_tbl.START_DATE) a hr:job_history as virtrdf:job_history_pk ;
	hr:employee_id hr:employees_iri(employees_tbl.EMPLOYEE_ID) where (^{job_history_tbl.}^.EMPLOYEE_ID = ^{employees_tbl.}^.EMPLOYEE_ID) as virtrdf:job_history_employee_id ;
	hr:department_id hr:departments_iri(departments_tbl.DEPARTMENT_ID) where (^{job_history_tbl.}^.DEPARTMENT_ID = ^{departments_tbl.}^.DEPARTMENT_ID) as virtrdf:job_history_department_id ;
	hr:job_id hr:jobs_iri(jobs_tbl.JOB_ID) where (^{job_history_tbl.}^.JOB_ID = ^{jobs_tbl.}^.JOB_ID) as virtrdf:job_history_job_id ;
	hr:start_date job_history_tbl.START_DATE as virtrdf:job_history_start_date ;
	hr:end_date job_history_tbl.END_DATE as virtrdf:job_history_end_date .

  } .
} .
;

delete from db.dba.url_rewrite_rule_list where urrl_list like 'oraclehr_rule%';
delete from db.dba.url_rewrite_rule where urr_rule like 'oraclehr_rule%';

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


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

DB.DBA.URLREWRITE_CREATE_RULELIST (
    'oraclehr_rule_list1',
    1,
    vector (
  	 	'oraclehr_rule1',
  	 	'oraclehr_rule2'
	  ));

-- ensure a VD for the IRIs which begins with /
VHOST_REMOVE (lpath=>'/oraclehr');

VHOST_DEFINE (
	lpath=>'/oraclehr',
	ppath=>'/DAV/oraclehr/',
    	is_dav=>1,
	vsp_user=>'dba',
	is_brws=>0,
	opts=>vector ('url_rewrite', 'oraclehr_rule_list1')
	);

delete from db.dba.url_rewrite_rule_list where urrl_list like 'oracle_schemas_rule%';
delete from db.dba.url_rewrite_rule where urr_rule like 'oracle_schemas_rule%';

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

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

DB.DBA.URLREWRITE_CREATE_RULELIST (
    'oracle_schemas_rule_list1',
    1,
    vector (
  	 	'oracle_schemas_rule1',
  	 	'oracle_schemas_rule2'
	  ));

-- ensure a VD for the IRIs which begins with /
VHOST_REMOVE (lpath=>'/schema/oraclehr');

VHOST_DEFINE (
	lpath=>'/schemas/oraclehr',
	ppath=>'/DAV/schemas/oraclehr/',
    	is_dav=>1,
	vsp_user=>'dba',
	is_brws=>0,
	opts=>vector ('url_rewrite', 'oracle_schemas_rule_list1')
	);

DB.DBA.XML_SET_NS_DECL ('hr', 'http://^{URIQADefaultHost}^/schemas/oraclehr/', 2);

15.8.15.5. DB2 using the demonstration 'Sample' database

Version defined using explicit host - localhost:8890

-- $Id: rdfandsparql.xml,v 1.150 2009/02/12 15:41:35 rtsekova Exp $
-- Setup script for RDF view of portions of DB2 SAMPLE database included
-- in DB2 Express Edition v9.5
--
-- The script assumes external DB2 tables are linked into Virtuoso using
-- local schema name db2sample.

DB..vd_remote_data_source ('db2ma-smpl', '', '<uid>','<pwd>);

ATTACH TABLE  "DB2ADMIN"."ACT"      PRIMARY KEY ("ACTNO")              AS "DB"."db2sample"."ACT"      FROM 'db2ma-smpl';
ATTACH TABLE  "DB2ADMIN"."DEPARTMENT"      PRIMARY KEY ("DEPTNO")              AS "DB"."db2sample"."DEPARTMENT"      FROM 'db2ma-smpl';
ATTACH TABLE  "DB2ADMIN"."EMPLOYEE"      PRIMARY KEY ("EMPNO")              AS "DB"."db2sample"."EMPLOYEE"      FROM 'db2ma-smpl';
ATTACH TABLE  "DB2ADMIN"."EMPPROJACT"      PRIMARY KEY ("EMPNO", "PROJNO", "ACTNO", "EMSTDATE")              AS "DB"."db2sample"."EMPPROJACT"      FROM 'db2ma-smpl';
ATTACH TABLE  "DB2ADMIN"."EMP_RESUME"      PRIMARY KEY ("EMPNO", "RESUME_FORMAT)              AS "DB"."db2sample"."EMP_RESUME"      FROM 'db2ma-smpl';
ATTACH TABLE  "DB2ADMIN"."PROJACT"      PRIMARY KEY ("PROJNO", "ACTNO", "ACSTDATE")              AS "DB"."db2sample"."PROJACT"      FROM 'db2ma-smpl';
ATTACH TABLE  "DB2ADMIN"."PROJECT"      PRIMARY KEY ("PROJNO")              AS "DB"."db2sample"."PROJECT"      FROM 'db2ma-smpl';

COMMIT WORK;

GRANT SELECT ON DB.db2sample.ACT TO "SPARQL", "SPARQL_UPDATE";
GRANT SELECT ON DB.db2sample.DEPARTMENT TO "SPARQL", "SPARQL_UPDATE";
GRANT SELECT ON DB.db2sample.EMPLOYEE TO "SPARQL", "SPARQL_UPDATE";
GRANT SELECT ON DB.db2sample.EMPPROJACT TO "SPARQL", "SPARQL_UPDATE";
GRANT SELECT ON DB.db2sample.EMP_RESUME TO "SPARQL", "SPARQL_UPDATE";
GRANT SELECT ON DB.db2sample.PROJACT TO "SPARQL", "SPARQL_UPDATE";
GRANT SELECT ON DB.db2sample.PROJECT TO "SPARQL", "SPARQL_UPDATE";

create function DB.DBA.PROJ_ACT_IRI (
  in proj_no varchar,
  in act_no integer,
  in ac_st_date date
  ) returns varchar
{
  declare _act_no, _datetime, _date any;
  _act_no := cast(act_no as varchar);
  _datetime := cast(ac_st_date as varchar);
  _date := left(_datetime, 10);
  return sprintf('http://localhost:8890/db2sample/proj_act/%s_%s_%s#this',
    proj_no, _act_no, _date);
};

create function
DB.DBA.PROJ_ACT_IRI_INV_1 (in proj_act_iri varchar) returns varchar
{
  declare exit handler for sqlstate '*' { return NULL; };
  declare parts any;
  parts := sprintf_inverse (proj_act_iri,
   'http://localhost:8890/db2sample/proj_act/%s_%s_%s#this', 1);
  if (parts is not null)
  {
    return parts[0];
  }
  return NULL;
};

create function
DB.DBA.PROJ_ACT_IRI_INV_2 (in proj_act_iri varchar) returns integer
{
  declare exit handler for sqlstate '*' { return NULL; };
  declare parts any;
  parts := sprintf_inverse (proj_act_iri,
   'http://localhost:8890/db2sample/proj_act/%s_%s_%s#this', 1);
  if (parts is not null)
  {
    return cast(parts[1] as integer);
  }
  return NULL;
};

create function
DB.DBA.PROJ_ACT_IRI_INV_3 (in proj_act_iri varchar) returns date
{
  declare exit handler for sqlstate '*' { return NULL; };
  declare parts any;
  parts := sprintf_inverse (proj_act_iri,
   'http://localhost:8890/db2sample/proj_act/%s_%s_%s#this', 1);
  if (parts is not null)
  {
    return cast(parts[2] as date);
  }
  return NULL;
};

create function DB.DBA.EMP_PROJ_ACT_IRI (
  in emp_no varchar,
  in proj_no varchar,
  in act_no integer,
  in emp_start_date date
  ) returns varchar
{
  declare _act_no, _datetime, _date any;
  _act_no := cast(act_no as varchar);
  _datetime := cast(emp_start_date as varchar);
  _date := left(_datetime, 10);
  return sprintf(
      'http://localhost:8890/db2sample/emp_proj_act/%s_%s_%s_%s#this',
    emp_no, proj_no, _act_no, _date);
};

create function
DB.DBA.EMP_PROJ_ACT_IRI_INV_1 (in emp_proj_act_iri varchar) returns varchar
{
  declare exit handler for sqlstate '*' { return NULL; };
  declare parts any;
  parts := sprintf_inverse (emp_proj_act_iri,
   'http://localhost:8890/db2sample/emp_proj_act/%s_%s_%s_%s#this', 1);
  if (parts is not null)
  {
    return parts[0];
  }
  return NULL;
};

create function
DB.DBA.EMP_PROJ_ACT_IRI_INV_2 (in emp_proj_act_iri varchar) returns varchar
{
  declare exit handler for sqlstate '*' { return NULL; };
  declare parts any;
  parts := sprintf_inverse (emp_proj_act_iri,
   'http://localhost:8890/db2sample/emp_proj_act/%s_%s_%s_%s#this', 1);
  if (parts is not null)
  {
    return parts[1];
  }
  return NULL;
};

create function
DB.DBA.EMP_PROJ_ACT_IRI_INV_3 (in emp_proj_act_iri varchar) returns integer
{
  declare exit handler for sqlstate '*' { return NULL; };
  declare parts any;
  parts := sprintf_inverse (emp_proj_act_iri,
   'http://localhost:8890/db2sample/emp_proj_act/%s_%s_%s_%s#this', 1);
  if (parts is not null)
  {
    return cast(parts[2] as integer);
  }
  return NULL;
};

create function
DB.DBA.EMP_PROJ_ACT_IRI_INV_4 (in emp_proj_act_iri varchar) returns date
{
  declare exit handler for sqlstate '*' { return NULL; };
  declare parts any;
  parts := sprintf_inverse (emp_proj_act_iri,
   'http://localhost:8890/db2sample/emp_proj_act/%s_%s_%s_%s#this', 1);
  if (parts is not null)
  {
    return cast(parts[3] as date);
  }
  return NULL;
};

grant execute on DB.DBA.PROJ_ACT_IRI to "SPARQL", "SPARQL_UPDATE";
grant execute on DB.DBA.PROJ_ACT_IRI_INV_1 to "SPARQL", "SPARQL_UPDATE";
grant execute on DB.DBA.PROJ_ACT_IRI_INV_2 to "SPARQL", "SPARQL_UPDATE";
grant execute on DB.DBA.PROJ_ACT_IRI_INV_3 to "SPARQL", "SPARQL_UPDATE";

grant execute on DB.DBA.EMP_PROJ_ACT_IRI to "SPARQL", "SPARQL_UPDATE";
grant execute on DB.DBA.EMP_PROJ_ACT_IRI_INV_1 to "SPARQL", "SPARQL_UPDATE";
grant execute on DB.DBA.EMP_PROJ_ACT_IRI_INV_2 to "SPARQL", "SPARQL_UPDATE";
grant execute on DB.DBA.EMP_PROJ_ACT_IRI_INV_3 to "SPARQL", "SPARQL_UPDATE";
grant execute on DB.DBA.EMP_PROJ_ACT_IRI_INV_4 to "SPARQL", "SPARQL_UPDATE";

sparql drop graph <http://localhost:8890/schemas/db2sample> ;
sparql drop graph <http://localhost:8890/db2sample> ;

sparql drop quad map virtrdf:db2sample ;

--------------------------
-- RDFS class definitions
ttlp (
'
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .

@prefix opl: <http://localhost:8890/schemas/db2sample/> .

opl:Act a rdfs:Class ;
	rdfs:isDefinedBy <http://localhost:8890/schemas/db2sample> ;
	rdfs:label "Act" ;
	rdfs:comment "Activity" .

# ACTNO SMALLINT PRIMARY KEY
opl:act_no a rdf:Property ;
	rdfs:domain opl:Act ;
	rdfs:range xsd:integer ;
	rdfs:label "Activity number" .

# ACTKWD VARCHAR(6)
opl:act_kwd a rdf:Property ;
	rdfs:domain opl:Act ;
	rdfs:range xsd:string ;
	rdfs:label "Activity keyword" .

# ACTDESC VARCHAR(20)
opl:act_desc a rdf:Property ;
	rdfs:domain opl:Act ;
	rdfs:range xsd:string ;
	rdfs:label "Activity description" .

#####
opl:Department a rdfs:Class ;
	rdfs:isDefinedBy <http://localhost:8890/schemas/db2sample> ;
	rdfs:label "Department" ;
	rdfs:comment "Department" .

# DEPTNO VARCHAR(3) PRIMARY KEY
opl:dept_no a rdf:Property ;
	rdfs:domain opl:Department ;
	rdfs:range xsd:string ;
	rdfs:label "Department number" .

# DEPTNAME VARCHAR(36)
opl:dept_name a rdf:Property ;
	rdfs:domain opl:Department ;
	rdfs:range xsd:string ;
	rdfs:label "Department name" .

# MGRNO CHAR(6)
opl:dept_manager a rdf:Property ;
	rdfs:domain opl:Department ;
	rdfs:range xsd:Employee ;
	rdfs:label "Department manager" .

# ADMRDEPT CHAR(3)
opl:supervising_dept a rdf:Property ;
	rdfs:domain opl:Department ;
	rdfs:range opl:Department ;
	rdfs:label "Department reported to" .

# LOCATION CHAR(6)
opl:location a rdf:Property ;
	rdfs:domain opl:Department ;
	rdfs:range xsd:string ;
	rdfs:label "Location" .

opl:employee_collection a rdf:Property ;
	rdfs:domain opl:Department ;
	rdfs:range opl:Employee ;
	rdfs:label "Department employees" .

opl:dept_project_collection a rdf:Property ;
	rdfs:domain opl:Department ;
	rdfs:range opl:Project ;
	rdfs:label "Department projects" .

#####
opl:Employee a rdfs:Class ;
	rdfs:isDefinedBy <http://localhost:8890/schemas/db2sample> ;
	rdfs:label "Employee" ;
	rdfs:comment "Employee" .

# EMPNO VARCHAR(6) PRIMARY KEY
opl:emp_no a rdf:Property ;
	rdfs:domain opl:Employee;
	rdfs:range xsd:string ;
	rdfs:label "Employee number" .

# FIRSTNME VARCHAR(12)
opl:first_name a rdf:Property ;
	rdfs:domain opl:Employee ;
	rdfs:range xsd:string ;
	rdfs:label "First name" .

# MIDINIT VARCHAR(1)
opl:middle_initial a rdf:Property ;
	rdfs:domain opl:Employee ;
	rdfs:range xsd:string ;
	rdfs:label "Middle initial" .

# LASTNAME VARCHAR(15)
opl:last_name a rdf:Property ;
	rdfs:domain opl:Employee ;
	rdfs:range xsd:string ;
	rdfs:label "Last name" .

# WORKDEPT VARCHAR(3)
opl:work_dept a rdf:Property ;
	rdfs:domain opl:Employee ;
	rdfs:range opl:Department ;
	rdfs:label "Work department" .

# PHONENO VARCHAR(4)
opl:phone_no a rdf:Property ;
	rdfs:domain opl:Employee ;
	rdfs:range xsd:string ;
	rdfs:label "Phone number" .

# HIREDATE DATE
opl:hire_date a rdf:Property ;
	rdfs:domain opl:Employee ;
	rdfs:range xsd:date;
	rdfs:label "Hire date" .

# JOB VARCHAR(8)
opl:job a rdf:Property ;
	rdfs:domain opl:Employee ;
	rdfs:range xsd:string ;
	rdfs:label "Job" .

# EDLEVEL SMALLINT
opl:education_level a rdf:Property ;
	rdfs:domain opl:Employee ;
	rdfs:range xsd:integer ;
	rdfs:label "Education level" .

# SEX VARCHAR(1)
opl:gender a rdf:Property ;
	rdfs:domain opl:Employee ;
	rdfs:range xsd:string ;
	rdfs:label "Gender" .

# BIRTHDATE DATE
opl:date_of_birth a rdf:Property ;
	rdfs:domain opl:Employee ;
	rdfs:range xsd:date ;
	rdfs:label "Date of birth" .

# SALARY DECIMAL(9,2)
opl:salary a rdf:Property ;
	rdfs:domain opl:Employee ;
	rdfs:range xsd:decimal ;
	rdfs:label "Salary" .

# BONUS DECIMAL(9,2)
opl:bonus a rdf:Property ;
	rdfs:domain opl:Employee ;
	rdfs:range xsd:decimal ;
	rdfs:label "Bonus" .

# COMM DECIMAL(9,2)
opl:commission a rdf:Property ;
	rdfs:domain opl:Employee ;
	rdfs:range xsd:decimal ;
	rdfs:label "Commission" .

opl:resume_collection a rdf:Property ;
	rdfs:domain opl:Employee ;
	rdfs:range opl:EmployeeResume ;
	rdfs:label "Employee resumes" .

opl:projects_responsible_for_collection a rdf:Property ;
	rdfs:domain opl:Employee ;
	rdfs:range opl:Project ;
	rdfs:label "reponsible for project" .

opl:activity_collection a rdf:Property ;
	rdfs:domain opl:Employee ;
	rdfs:range opl:EmpProjAct ;
	rdfs:label "project activities" .

#####
opl:EmpProjAct a rdfs:Class ;
	rdfs:isDefinedBy <http://localhost:8890/schemas/db2sample> ;
	rdfs:label "EmpProjAct" ;
	rdfs:comment "Employee project activity" .

# EMPNO VARCHAR(6) PRIMARY KEY
opl:epa_emp_no a rdf:Property ;
	rdfs:domain opl:EmpProjAct ;
	rdfs:range xsd:string ;
	rdfs:label "Employee number" .

# PROJNO VARCHAR(6) PRIMARY KEY
opl:epa_proj_no a rdf:Property ;
	rdfs:domain opl:EmpProjAct ;
	rdfs:range xsd:string ;
	rdfs:label "Project number" .

# ACTNO SMALLINT PRIMARY KEY
opl:epa_act_no a rdf:Property ;
	rdfs:domain opl:EmpProjAct ;
	rdfs:range xsd:string ;
	rdfs:label "Activity number" .

# EMSTDATE DATE PRIMARY KEY
opl:emp_start_date a rdf:Property ;
	rdfs:domain opl:EmpProjAct ;
	rdfs:range xsd:date ;
	rdfs:label "Employee activity start date" .

# EMPTIME DECIMAL(5,2)
opl:emp_time a rdf:Property ;
	rdfs:domain opl:EmpProjAct ;
	rdfs:range xsd:decimal ;
	rdfs:label "Employee time" .

# EMENDATE DATE PRIMARY KEY
opl:emp_end_date a rdf:Property ;
	rdfs:domain opl:EmpProjAct ;
	rdfs:range xsd:date ;
	rdfs:label "Employee activity end date" .

opl:assigned_to a rdf:Property ;
	rdfs:domain opl:EmpProjAct ;
	rdfs:range opl:Employee ;
	rdfs:label "Assigned to" .

opl:project_activity a rdf:Property ;
	rdfs:domain opl:EmpProjAct ;
	rdfs:range opl:ProjAct ;
	rdfs:label "Project activity" .

#####
opl:EmployeeResume a rdfs:Class ;
	rdfs:isDefinedBy <http://localhost:8890/schemas/db2sample> ;
	rdfs:label "EmployeeResume" ;
	rdfs:comment "Employee resume" .

# EMPNO VARCHAR(6) PRIMARY KEY
opl:er_emp_no a rdf:Property ;
	rdfs:domain opl:EmployeeResume ;
	rdfs:range xsd:string ;
	rdfs:label "Employee number" .

# RESUME_FORMAT VARCHAR(10) PRIMARY KEY
opl:resume_format a rdf:Property ;
	rdfs:domain opl:EmployeeResume ;
	rdfs:range xsd:string ;
	rdfs:label "Resume format" .

# RESUME VARCHAR(5120)
opl:resume a rdf:Property ;
	rdfs:domain opl:EmployeeResume ;
	rdfs:range xsd:string ;
	rdfs:label "Resume" .

opl:resume_of a rdf:Property ;
	rdfs:domain opl:EmployeeResume ;
	rdfs:range opl:Employee ;
	rdfs:label "Resume subject" .

#####
opl:ProjAct a rdfs:Class ;
	rdfs:isDefinedBy <http://localhost:8890/schemas/db2sample> ;
	rdfs:label "ProjAct" ;
	rdfs:comment "Project activity" .

# PROJNO VARCHAR(6) PRIMARY KEY
opl:pa_proj_no a rdf:Property ;
	rdfs:domain opl:ProjAct ;
	rdfs:range xsd:string ;
	rdfs:label "Project number" .

# ACTNO SMALLINT PRIMARY KEY
opl:pa_act_no a rdf:Property ;
	rdfs:domain opl:ProjAct ;
	rdfs:range xsd:string ;
	rdfs:label "Activity number" .

# ACSTDATE DATE PRIMARY KEY
opl:ac_st_date a rdf:Property ;
	rdfs:domain opl:ProjAct ;
	rdfs:range xsd:date ;
	rdfs:label "Activity start date" .

# ACSTAFF DECIMAL(5,2)
opl:ac_staff a rdf:Property ;
	rdfs:domain opl:ProjAct ;
	rdfs:range xsd:decimal ;
	rdfs:label "Acstaff" .

# ACENDATE DATE
opl:ac_en_date a rdf:Property ;
	rdfs:domain opl:ProjAct ;
	rdfs:range xsd:date ;
	rdfs:label "Activity end date" .

opl:project a rdf:Property ;
	rdfs:domain opl:ProjAct ;
	rdfs:range opl:Project ;
	rdfs:label "Project" .

opl:activity a rdf:Property ;
	rdfs:domain opl:ProjAct ;
	rdfs:range opl:Act ;
	rdfs:label "Activity" .

opl:employee_activity_collection a rdf:Property ;
	rdfs:domain opl:ProjAct ;
	rdfs:range opl:EmpProjAct ;
	rdfs:label "Employee activity collection" .

#####
opl:Project a rdfs:Class ;
	rdfs:isDefinedBy <http://localhost:8890/schemas/db2sample> ;
	rdfs:label "Project" ;
	rdfs:comment "Project" .

# PROJNO VARCHAR(6) PRIMARY KEY
opl:proj_no a rdf:Property ;
	rdfs:domain opl:Project ;
	rdfs:range xsd:string ;
	rdfs:label "Project number" .

# PROJNAME VARCHAR(24)
opl:proj_name a rdf:Property ;
	rdfs:domain opl:Project ;
	rdfs:range xsd:string ;
	rdfs:label "Project name" .

# DEPTNO CHAR(3)
opl:is_project_of_department a rdf:Property ;
	rdfs:domain opl:Project ;
	rdfs:range opl:Department ;
	rdfs:label "is project of department" .

# RESPEMP VARCHAR(6)
opl:resp_emp a rdf:Property ;
	rdfs:domain opl:Project ;
	rdfs:range opl:Employee ;
	rdfs:label "Employee responsible" .

# PRSTAFF DECIMAL(5,2)
opl:pr_staff a rdf:Property ;
	rdfs:domain opl:Project ;
	rdfs:range xsd:decimal ;
	rdfs:label "PrStaff" .

# PRSTDATE DATE
opl:pr_st_date a rdf:Property ;
	rdfs:domain opl:Project ;
	rdfs:range xsd:date ;
	rdfs:label "Project start date" .

# PRENDATE DATE
opl:pr_en_date a rdf:Property ;
	rdfs:domain opl:Project ;
	rdfs:range xsd:date ;
	rdfs:label "Project end date" .

# MAJPROJ VARCHAR(6)
opl:maj_proj a rdf:Property ;
	rdfs:domain opl:Project ;
	rdfs:range xsd:string ;
	rdfs:label "MajProj" .

opl:proj_activity_collection a rdf:Property ;
	rdfs:domain opl:Project ;
	rdfs:range opl:ProjAct ;
	rdfs:label "Project activities" .

', '', 'http://localhost:8890/schemas/db2sample', 0);

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

sparql
prefix opl: <http://localhost:8890/schemas/db2sample/>

create iri class
<http://localhost:8890/schemas/db2sample/act_iri>
	"http://localhost:8890/db2sample/act/%d#this"
	(
	 in act_no integer not null
	) .

create iri class
<http://localhost:8890/schemas/db2sample/department_iri>
	"http://localhost:8890/db2sample/department/%s#this"
	(
	 in dept_no varchar not null
	) .

create iri class
<http://localhost:8890/schemas/db2sample/employee_iri>
	"http://localhost:8890/db2sample/employee/%s#this"
	(
	 in emp_no varchar not null
	) .

create iri class opl:emp_proj_act_iri using
	function DB.DBA.EMP_PROJ_ACT_IRI (
	 	in emp_no varchar,
	 	in proj_no varchar,
	 	in act_no integer,
	 	in emp_start_date date
		) returns varchar,
	function DB.DBA.EMP_PROJ_ACT_IRI_INV_1 (in emp_proj_act_iri varchar)
		returns varchar ,
	function DB.DBA.EMP_PROJ_ACT_IRI_INV_2 (in emp_proj_act_iri varchar)
		returns varchar ,
	function DB.DBA.EMP_PROJ_ACT_IRI_INV_3 (in emp_proj_act_iri varchar)
		returns integer ,
	function DB.DBA.EMP_PROJ_ACT_IRI_INV_4 (in emp_proj_act_iri varchar)
		returns date
	option (bijection, returns
	  "http://localhost:8890/db2sample/emp_proj_act/%s_%s_%s_%s#this")
	.


create iri class
<http://localhost:8890/schemas/db2sample/employee_resume_iri>
	"http://localhost:8890/db2sample/employee_resume/%s_%s#this"
	(
	 in emp_no varchar not null,
	 in resume_format varchar not null
	) .

create iri class opl:proj_act_iri using
	function DB.DBA.PROJ_ACT_IRI (
		in proj_no varchar,
		in act_no integer,
		in ac_st_date date
		) returns varchar,
	function DB.DBA.PROJ_ACT_IRI_INV_1 (in proj_act_iri varchar)
		returns varchar ,
	function DB.DBA.PROJ_ACT_IRI_INV_2 (in proj_act_iri varchar)
		returns integer ,
	function DB.DBA.PROJ_ACT_IRI_INV_3 (in proj_act_iri varchar)
		returns date
	option (bijection, returns
		"http://localhost:8890/db2sample/proj_act/%s_%s_%s#this")
	.

create iri class
<http://localhost:8890/schemas/db2sample/project_iri>
	"http://localhost:8890/db2sample/project/%s#this"
	(
	 in proj_no varchar not null
	) .
;

sparql
prefix opl: <http://localhost:8890/schemas/db2sample/>

alter quad storage virtrdf:DefaultQuadStorage
from DB.db2sample.ACT as act_tbl
from DB.db2sample.DEPARTMENT as dept_tbl
from DB.db2sample.EMPLOYEE as emp_tbl
from DB.db2sample.EMPPROJACT as emp_proj_act_tbl
from DB.db2sample.EMP_RESUME as emp_resume_tbl
from DB.db2sample.PROJACT as proj_act_tbl
from DB.db2sample.PROJECT as project_tbl
{
	create virtrdf:db2sample as
		graph <http://localhost:8890/db2sample>
	{
	opl:act_iri(act_tbl.ACTNO) a opl:Act
		as virtrdf:act_id ;
	opl:act_no act_tbl.ACTNO
		as virtrdf:act_act_no ;
	opl:act_kwd act_tbl.ACTKWD
		as virtrdf:act_act_kwd ;
	opl:act_desc act_tbl.ACTDESC
		as virtrdf:act_act_desc .

	opl:department_iri(dept_tbl.DEPTNO) a opl:Department
		as virtrdf:dept_id ;
	opl:dept_no dept_tbl.DEPTNO
		as virtrdf:dept_dept_no ;
	opl:dept_name dept_tbl.DEPTNAME
		as virtrdf:dept_dept_name ;
	opl:dept_manager opl:employee_iri(dept_tbl.MGRNO)
		as virtrdf:dept_mgr_no ;
	opl:supervising_dept opl:department_iri(dept_tbl.ADMRDEPT)
		as virtrdf:dept_supervising_dept ;
	opl:location dept_tbl.LOCATION
		as virtrdf:dept_location ;
	opl:employee_collection opl:employee_iri(emp_tbl.EMPNO)
		where (^{emp_tbl.}^.WORKDEPT = ^{dept_tbl.}^.DEPTNO)
		as virtrdf:dept_employee_collection ;
	opl:dept_project_collection opl:project_iri(project_tbl.PROJNO)
		where (^{project_tbl.}^.DEPTNO = ^{dept_tbl.}^.DEPTNO)
		as virtrdf:dept_project_collection .

	opl:employee_iri(emp_tbl.EMPNO) a opl:Employee
		as virtrdf:employee_id ;
	opl:emp_no emp_tbl.EMPNO
		as virtrdf:employee_emp_no ;
	opl:first_name emp_tbl.FIRSTNME
		as virtrdf:employee_first_name ;
	opl:middle_initial emp_tbl.MIDINIT
		as virtrdf:employee_middle_initial ;
	opl:last_name emp_tbl.LASTNAME
		as virtrdf:employee_last_name ;
	opl:work_dept opl:department_iri(emp_tbl.WORKDEPT)
		as virtrdf:employee_work_dept ;
	opl:phone_no emp_tbl.PHONENO
		as virtrdf:employee_phone_no ;
	opl:hire_date emp_tbl.HIREDATE
		as virtrdf:employee_hire_date ;
	opl:job emp_tbl.JOB
		as virtrdf:employee_job ;
	opl:education_level emp_tbl.EDLEVEL
		as virtrdf:employee_education_level ;
	opl:gender emp_tbl.SEX
		as virtrdf:employee_gender ;
	opl:date_of_birth emp_tbl.BIRTHDATE
		as virtrdf:employee_date_of_birth ;
	opl:salary emp_tbl.SALARY
		as virtrdf:employee_salary ;
	opl:bonus emp_tbl.BONUS
		as virtrdf:employee_bonus ;
	opl:commission emp_tbl.COMM
		as virtrdf:employee_commission ;
	opl:resume_collection opl:employee_resume_iri(
		emp_resume_tbl.EMPNO,
		emp_resume_tbl.RESUME_FORMAT
		)
		where (^{emp_tbl.}^.EMPNO = ^{emp_resume_tbl.}^.EMPNO)
		as virtrdf:employee_resume_collection ;
	opl:projects_responsible_for_collection
 		opl:project_iri(project_tbl.PROJNO)
		where (^{project_tbl.}^.RESPEMP = ^{emp_tbl.}^.EMPNO)
		as virtrdf:employee_projects_responsible_for_collection ;
	opl:activity_collection opl:emp_proj_act_iri(
		emp_proj_act_tbl.EMPNO,
		emp_proj_act_tbl.PROJNO,
		emp_proj_act_tbl.ACTNO,
		emp_proj_act_tbl.EMSTDATE
		)
		where (^{emp_tbl.}^.EMPNO = ^{emp_proj_act_tbl.}^.EMPNO)
		as virtrdf:employee_activity_collection .

	opl:emp_proj_act_iri(
		emp_proj_act_tbl.EMPNO,
		emp_proj_act_tbl.PROJNO,
		emp_proj_act_tbl.ACTNO,
		emp_proj_act_tbl.EMSTDATE
		) a opl:EmpProjAct
		as virtrdf:empprojact_id ;
	opl:epa_emp_no emp_proj_act_tbl.EMPNO
		as virtrdf:empprojact_emp_no ;
	opl:epa_proj_no emp_proj_act_tbl.PROJNO
		as virtrdf:empprojact_proj_no ;
	opl:epa_act_no emp_proj_act_tbl.ACTNO
		as virtrdf:empprojact_act_no ;
	opl:emp_start_date emp_proj_act_tbl.EMSTDATE
		as virtrdf:empprojact_emp_start_date ;
	opl:emp_time emp_proj_act_tbl.EMPTIME
		as virtrdf:empprojact_emp_time ;
	opl:emp_end_date emp_proj_act_tbl.EMENDATE
		as virtrdf:empprojact_emp_end_date ;
	opl:assigned_to opl:employee_iri(emp_proj_act_tbl.EMPNO)
		as virtrdf:empprojact_assigned_to ;
	opl:project_activity opl:proj_act_iri(
		emp_proj_act_tbl.PROJNO,
		emp_proj_act_tbl.ACTNO,
		emp_proj_act_tbl.EMSTDATE
		)
		as virtrdf:empprojact_project_activity .

	opl:employee_resume_iri(
		emp_resume_tbl.EMPNO,
		emp_resume_tbl.RESUME_FORMAT
		) a opl:EmployeeResume
		as virtrdf:employee_resume_id ;
	opl:er_emp_no emp_resume_tbl.EMPNO
		as virtrdf:employee_resume_emp_no ;
	opl:resume_format emp_resume_tbl.RESUME_FORMAT
		as virtrdf:employee_resume_resume_format ;
	opl:resume emp_resume_tbl.RESUME
		as virtrdf:employee_resume_resume ;
	opl:resume_of opl:employee_iri(emp_resume_tbl.EMPNO)
		as virtrdf:employee_resume_resume_of .

	opl:proj_act_iri(
		proj_act_tbl.PROJNO,
		proj_act_tbl.ACTNO,
		proj_act_tbl.ACSTDATE
		) a opl:ProjAct
		as virtrdf:projact_id;
	opl:pa_proj_no proj_act_tbl.PROJNO
		as virtrdf:projact_proj_no ;
	opl:pa_act_no proj_act_tbl.ACTNO
		as virtrdf:projact_act_no ;
	opl:ac_st_date proj_act_tbl.ACSTDATE
		as virtrdf:projact_ac_st_date ;
	opl:ac_staff proj_act_tbl.ACSTAFF
		as virtrdf:projact_ac_staff ;
	opl:ac_en_date proj_act_tbl.ACENDATE
		as virtrdf:projact_ac_en_date ;
	opl:project opl:project_iri(proj_act_tbl.PROJNO)
		as virtrdf:projact_project ;
	opl:activity opl:act_iri(proj_act_tbl.ACTNO)
		as virtrdf:projact_activity ;
	opl:employee_activity_collection opl:emp_proj_act_iri(
		emp_proj_act_tbl.EMPNO,
		emp_proj_act_tbl.PROJNO,
		emp_proj_act_tbl.ACTNO,
		emp_proj_act_tbl.EMSTDATE
		)
		where (
		^{proj_act_tbl.}^.PROJNO = ^{emp_proj_act_tbl.}^.PROJNO AND
	        ^{proj_act_tbl.}^.ACTNO = ^{emp_proj_act_tbl.}^.ACTNO AND
	        ^{proj_act_tbl.}^.ACSTDATE = ^{emp_proj_act_tbl.}^.EMSTDATE
	        )
		as virtrdf:project_employee_activity_collection .

	opl:project_iri(project_tbl.PROJNO) a opl:Project
		as virtrdf:project_id ;
	opl:proj_no project_tbl.PROJNO
		as virtrdf:project_proj_no ;
	opl:proj_name project_tbl.PROJNAME
		as virtrdf:project_proj_name ;
	opl:is_project_of_department opl:department_iri(project_tbl.DEPTNO)
		as virtrdf:project_is_project_of_department ;
	opl:resp_emp opl:employee_iri(project_tbl.RESPEMP)
		as virtrdf:project_resp_emp ;
	opl:pr_staff project_tbl.PRSTAFF
		as virtrdf:project_pr_staff ;
	opl:pr_st_date project_tbl.PRSTDATE
		as virtrdf:project_pr_st_date ;
	opl:pr_en_date project_tbl.PRENDATE
		as virtrdf:project_pr_en_date ;
	opl:maj_proj project_tbl.MAJPROJ
		as virtrdf:project_maj_proj ;
	opl:proj_activity_collection opl:proj_act_iri(
		proj_act_tbl.PROJNO,
		proj_act_tbl.ACTNO,
		proj_act_tbl.ACSTDATE
		)
		where (^{project_tbl.}^.PROJNO = ^{proj_act_tbl.}^.PROJNO)
		as virtrdf:project_activity_collection .
	} .
} .
;

delete from db.dba.url_rewrite_rule_list where urrl_list like 'db2sample_rule%';
delete from db.dba.url_rewrite_rule where urr_rule like 'db2sample_rule%';

DB.DBA.URLREWRITE_CREATE_REGEX_RULE (
    'db2sample_rule1',
    1,
    '(/[^#]*)',
    vector('path'),
    1,
    '/about/html/http://localhost:8890%s',
    vector('path'),
    null,
    '(text/html)|(\\*/\\*)',
    0,
    303
    );

DB.DBA.URLREWRITE_CREATE_REGEX_RULE (
    'db2sample_rule2',
    1,
    '(/[^#]*)',
    vector('path'),
    1,
    '/sparql?query=DESCRIBE+%%3Chttp%%3A//localhost%%3A8890%U%%23this%%3E+%%3Chttp%%3A//localhost%%3A8890%U%%23this%%3E+FROM+%%3Chttp%%3A//localhost%%3A8890/db2sample%%3E&format=%U',

    vector('path','path','*accept*'),
    null,
    '(text/rdf.n3)|(application/rdf.xml)',
    0,
    null
    );

DB.DBA.URLREWRITE_CREATE_RULELIST (
    'db2sample_rule_list1',
    1,
    vector (
  	 	'db2sample_rule1',
  	 	'db2sample_rule2'
	  ));


-- ensure a VD for the IRIs which begins with /
VHOST_REMOVE (lpath=>'/db2sample');

VHOST_DEFINE (
	lpath=>'/db2sample',
	ppath=>'/DAV/db2sample/',
	vsp_user=>'dba',
    	is_dav=>1,
	is_brws=>0,
	opts=>vector ('url_rewrite', 'db2sample_rule_list1')
	);
delete from db.dba.url_rewrite_rule_list where urrl_list like 'db2sample_schema_rule%';
delete from db.dba.url_rewrite_rule where urr_rule like 'db2sample_schema_rule%';

DB.DBA.URLREWRITE_CREATE_REGEX_RULE (
    'db2sample_schema_rule1',
    1,
    '(/[^#]*)',
    vector('path'),
    1,
    '/about/html/http://localhost:8890%U',
    vector('path'),
    null,
    '(text/html)|(\\*/\\*)',
    0,
    303
    );

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

DB.DBA.URLREWRITE_CREATE_RULELIST (
    'db2sample_schema_rule_list1',
    1,
    vector (
  	 	'db2sample_schema_rule1',
  	 	'db2sample_schema_rule2'
	  ));


-- ensure a VD for the IRIs which begins with /
VHOST_REMOVE (lpath=>'/schemas/db2sample');

VHOST_DEFINE (
	lpath=>'/schemas/db2sample',
	ppath=>'/DAV/schemas_db2sample/',
	vsp_user=>'dba',
    	is_dav=>1,
	is_brws=>0,
	opts=>vector ('url_rewrite', 'db2sample_schema_rule_list1')
	);

15.8.15.6. Informix using demonstration 'Stores' database

DB..vd_remote_data_source ('inf10_stores_demo_rdf', '', '<uid>','<pwd>');

ATTACH TABLE  "informix"."call_type"  PRIMARY KEY ("call_code")                  AS "stores_demo_rdf"."inf10_stores_demo_rdf"."call_type"  FROM 'inf10_stores_demo_rdf';
ATTACH TABLE  "informix"."catalog"    PRIMARY KEY ("catalog_num")                AS "stores_demo_rdf"."inf10_stores_demo_rdf"."catalog"    FROM 'inf10_stores_demo_rdf';
ATTACH TABLE  "informix"."cust_calls" PRIMARY KEY ("customer_num", "call_dtime") AS "stores_demo_rdf"."inf10_stores_demo_rdf"."cust_calls" FROM 'inf10_stores_demo_rdf';
ATTACH TABLE  "informix"."customer"   PRIMARY KEY ("customer_num")               AS "stores_demo_rdf"."inf10_stores_demo_rdf"."customer"   FROM 'inf10_stores_demo_rdf';
ATTACH TABLE  "informix"."items"      PRIMARY KEY ("item_num", "order_num")      AS "stores_demo_rdf"."inf10_stores_demo_rdf"."items"      FROM 'inf10_stores_demo_rdf';
ATTACH TABLE  "informix"."manufact"   PRIMARY KEY ("manu_code")                  AS "stores_demo_rdf"."inf10_stores_demo_rdf"."manufact"   FROM 'inf10_stores_demo_rdf';
ATTACH TABLE  "informix"."msgs"       PRIMARY KEY ("lang", "number", "message")  AS "stores_demo_rdf"."inf10_stores_demo_rdf"."msgs"       FROM 'inf10_stores_demo_rdf';
ATTACH TABLE  "informix"."orders"     PRIMARY KEY ("order_num")                  AS "stores_demo_rdf"."inf10_stores_demo_rdf"."orders"     FROM 'inf10_stores_demo_rdf';
ATTACH TABLE  "informix"."state"      PRIMARY KEY ("code", "sname")              AS "stores_demo_rdf"."inf10_stores_demo_rdf"."state"      FROM 'inf10_stores_demo_rdf';
ATTACH TABLE  "informix"."stock"      PRIMARY KEY ("stock_num", "manu_code")     AS "stores_demo_rdf"."inf10_stores_demo_rdf"."stock"      FROM 'inf10_stores_demo_rdf';

COMMIT WORK;

GRANT SELECT ON stores_demo_rdf.inf10_stores_demo_rdf.items      TO "SPARQL", "SPARQL_UPDATE";
GRANT SELECT ON stores_demo_rdf.inf10_stores_demo_rdf.catalog    TO "SPARQL", "SPARQL_UPDATE";
GRANT SELECT ON stores_demo_rdf.inf10_stores_demo_rdf.msgs       TO "SPARQL", "SPARQL_UPDATE";
GRANT SELECT ON stores_demo_rdf.inf10_stores_demo_rdf.state      TO "SPARQL", "SPARQL_UPDATE";
GRANT SELECT ON stores_demo_rdf.inf10_stores_demo_rdf.orders     TO "SPARQL", "SPARQL_UPDATE";
GRANT SELECT ON stores_demo_rdf.inf10_stores_demo_rdf.stock      TO "SPARQL", "SPARQL_UPDATE";
GRANT SELECT ON stores_demo_rdf.inf10_stores_demo_rdf.customer   TO "SPARQL", "SPARQL_UPDATE";
GRANT SELECT ON stores_demo_rdf.inf10_stores_demo_rdf.call_type  TO "SPARQL", "SPARQL_UPDATE";
GRANT SELECT ON stores_demo_rdf.inf10_stores_demo_rdf.manufact   TO "SPARQL", "SPARQL_UPDATE";
GRANT SELECT ON stores_demo_rdf.inf10_stores_demo_rdf.cust_calls TO "SPARQL", "SPARQL_UPDATE";
GRANT SPARQL_UPDATE to "SPARQL";


create function DB.DBA.CUST_CALLS_IRI (in customer_num integer, in call_dtime datetime) returns varchar
{
	declare _call_dtime any;
	_call_dtime := cast(call_dtime as varchar);
	return sprintf('http://localhost:8890/informix/stores_demo/cust_calls/%d_%U#this', customer_num, _call_dtime);
};

create function DB.DBA.CUST_CALLS_IRI_INV_1 (in cust_calls_iri varchar) returns integer
{
	declare parts any;
	parts := sprintf_inverse(cust_calls_iri, 'http://localhost:8890/informix/stores_demo/cust_calls/%d_%U#this', 1);
	if(parts is not null)
	{
		return parts[0];
	}
	return NULL;
};

create function DB.DBA.CUST_CALLS_IRI_INV_2 (in cust_calls_iri varchar) returns datetime
{
	declare parts any;
	parts := sprintf_inverse(cust_calls_iri, 'http://localhost:8890/informix/stores_demo/cust_calls/%d_%U#this', 1);
	if(parts is not null)
	{
		return parts[1];
	}
	return NULL;
};


grant execute on DB.DBA.CUST_CALLS_IRI to "SPARQL", "SPARQL_UPDATE";
grant execute on DB.DBA.CUST_CALLS_IRI_INV_1 to "SPARQL", "SPARQL_UPDATE";
grant execute on DB.DBA.CUST_CALLS_IRI_INV_2 to "SPARQL", "SPARQL_UPDATE";


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

ttlp (
'
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .

@prefix items:   <http://localhost:8890/schemas/informix/stores_demo/items/> .
@prefix catalog: <http://localhost:8890/schemas/informix/stores_demo/catalog/> .
@prefix stock:   <http://localhost:8890/schemas/informix/stores_demo/stock/> .
@prefix msgs:    <http://localhost:8890/schemas/informix/stores_demo/msgs/> .
@prefix state:   <http://localhost:8890/schemas/informix/stores_demo/state/> .
@prefix orders:  <http://localhost:8890/schemas/informix/stores_demo/orders/> .
@prefix manuf:   <http://localhost:8890/schemas/informix/stores_demo/manufact/> .
@prefix cust:    <http://localhost:8890/schemas/informix/stores_demo/customer/> .
@prefix callt:   <http://localhost:8890/schemas/informix/stores_demo/call_type/> .
@prefix custc:   <http://localhost:8890/schemas/informix/stores_demo/cust_calls/> .



items:Items a rdfs:Class ;
	rdfs:label "Items" ;
	rdfs:comment "Informix SD items table" .

items:item_num a rdf:Property ;
	rdfs:domain items:Items ;
	rdfs:range xsd:integer ;
	rdfs:label "ITEM NUMBER" .

items:quantity a rdf:Property ;
	rdfs:domain items:Items ;
	rdfs:range xsd:integer ;
	rdfs:label "QUANTITY" .

items:total_price a rdf:Property ;
	rdfs:domain items:Items ;
	rdfs:range xsd:decimal ;
	rdfs:label "TOTAL PRICE" .

items:order_num_fk a rdf:Property ;
	rdfs:domain items:Items ;
	rdfs:range orders:Orders ;
	rdfs:label "ORDER NUMBER" .

items:stock_num_fk a rdf:Property ;
	rdfs:domain items:Items ;
	rdfs:range stock:Stock ;
	rdfs:label "STOCK NUMBER" .

items:manu_code_fk a rdf:Property ;
	rdfs:domain items:Items ;
	rdfs:range stock:Stock ;
	rdfs:label "MANUAL CODE" .



catalog:Catalog a rdfs:Class ;
	rdfs:label "Catalog" ;
	rdfs:comment "Informix SD catalog table" .

catalog:manu_code a rdf:Property ;
	rdfs:domain catalog:Catalog ;
	rdfs:range xsd:integer ;
	rdfs:label "MANUAL CODE" .

catalog:cat_descr a rdf:Property ;
	rdfs:domain catalog:Catalog ;
	rdfs:range xsd:string ;
	rdfs:label "CATALOG DESCRIPTION" .

catalog:cat_picture a rdf:Property ;
	rdfs:domain catalog:Catalog ;
	rdfs:range xsd:byte ;
	rdfs:label "CATALOG PICTURE" .

catalog:cat_advert a rdf:Property ;
	rdfs:domain catalog:Catalog ;
	rdfs:range xsd:string ;
	rdfs:label "CATALOG ADVERT" .

catalog:catalog_num_fk a rdf:Property ;
	rdfs:domain catalog:Catalog ;
	rdfs:range stock:Stock ;
	rdfs:label "CATALOG NUMBER" .

catalog:stock_num_fk a rdf:Property ;
	rdfs:domain catalog:Catalog ;
	rdfs:range stock:Stock ;
	rdfs:label "STOCK NUMBER" .



msgs:Msgs a rdfs:Class ;
	rdfs:label "Msgs" ;
	rdfs:comment "Informix SD msgs table" .

msgs:lang a rdf:Property ;
	rdfs:domain msgs:Msgs ;
	rdfs:range xsd:string ;
	rdfs:label "LANGUAGE" .

msgs:number a rdf:Property ;
	rdfs:domain msgs:Msgs ;
	rdfs:range xsd:integer ;
	rdfs:label "NUMBER" .

msgs:message a rdf:Property ;
	rdfs:domain msgs:Msgs ;
	rdfs:range xsd:string ;
	rdfs:label "MESSAGE" .



state:State a rdfs:Class ;
	rdfs:label "State" ;
	rdfs:comment "Informix SD state table" .

state:code a rdf:Property ;
	rdfs:domain state:State ;
	rdfs:range xsd:string ;
	rdfs:label "STATE CODE" .

state:sname a rdf:Property ;
	rdfs:domain state:State ;
	rdfs:range xsd:string ;
	rdfs:label "STATE NAME" .



orders:Orders a rdfs:Class ;
	rdfs:label "Orders" ;
	rdfs:comment "Informix SD orders table" .

orders:order_num a rdf:Property ;
	rdfs:domain orders:Orders ;
	rdfs:range xsd:integer ;
	rdfs:label "ORDER NUMBER" .

orders:order_date a rdf:Property ;
	rdfs:domain orders:Orders ;
	rdfs:range xsd:date ;
	rdfs:label "ORDER DATE" .

orders:ship_instruct a rdf:Property ;
	rdfs:domain orders:Orders ;
	rdfs:range xsd:string ;
	rdfs:label "SHIPPING INSTRUCTION" .

orders:backlog a rdf:Property ;
	rdfs:domain orders:Orders ;
	rdfs:range xsd:string ;
	rdfs:label "BACKLOG" .

orders:po_num a rdf:Property ;
	rdfs:domain orders:Orders ;
	rdfs:range xsd:string ;
	rdfs:label "PURCHASE ORDER NUMBER" .

orders:ship_date a rdf:Property ;
	rdfs:domain orders:Orders ;
	rdfs:range xsd:date ;
	rdfs:label "SHIPPING DATE" .

orders:ship_weight a rdf:Property ;
	rdfs:domain orders:Orders ;
	rdfs:range xsd:decimal ;
	rdfs:label "SHIPPING WEIGHT" .

orders:ship_charge a rdf:Property ;
	rdfs:domain orders:Orders ;
	rdfs:range xsd:decimal ;
	rdfs:label "SHIPPING CHARGE" .

orders:paid_date a rdf:Property ;
	rdfs:domain orders:Orders ;
	rdfs:range xsd:date ;
	rdfs:label "PAID DATE" .

orders:customer_num_fk a rdf:Property ;
	rdfs:domain orders:Orders ;
	rdfs:range cust:Customer ;
	rdfs:label "CUSTOMER NUMBER" .



stock:Stock a rdfs:Class ;
	rdfs:label "Stock" ;
	rdfs:comment "Informix SD stock table" .

stock:stock_num a rdf:Property ;
	rdfs:domain stock:Stock ;
	rdfs:range xsd:integer ;
	rdfs:label "STOCK NUMBER" .

stock:description a rdf:Property ;
	rdfs:domain stock:Stock ;
	rdfs:range xsd:string ;
	rdfs:label "DESCRIPTION" .

stock:unit_price a rdf:Property ;
	rdfs:domain stock:Stock ;
	rdfs:range xsd:decimal ;
	rdfs:label "UNIT PRICE" .

stock:unit a rdf:Property ;
	rdfs:domain stock:Stock ;
	rdfs:range xsd:string ;
	rdfs:label "UNIT" .

stock:unit_descr a rdf:Property ;
	rdfs:domain stock:Stock ;
	rdfs:range xsd:decimal ;
	rdfs:label "UNIT DESCRIPTION" .

stock:manu_code_fk a rdf:Property ;
	rdfs:domain stock:Stock ;
	rdfs:range manuf:Manufact ;
	rdfs:label "MANUAL CODE" .



cust:Customer a rdfs:Class ;
	rdfs:label "Customer" ;
	rdfs:comment "Informix SD customer table" .

cust:customer_num a rdf:Property ;
	rdfs:domain cust:Customer ;
	rdfs:range xsd:integer ;
	rdfs:label "CUSTOMER NUMBER" .

cust:fname a rdf:Property ;
	rdfs:domain cust:Customer ;
	rdfs:range xsd:string ;
	rdfs:label "FIRST NAME" .

cust:lname a rdf:Property ;
	rdfs:domain cust:Customer ;
	rdfs:range xsd:string ;
	rdfs:label "LAST NAME" .

cust:company a rdf:Property ;
	rdfs:domain cust:Customer ;
	rdfs:range xsd:string ;
	rdfs:label "COMPANY" .

cust:address1 a rdf:Property ;
	rdfs:domain cust:Customer ;
	rdfs:range xsd:string ;
	rdfs:label "ADDRESS1" .

cust:address2 a rdf:Property ;
	rdfs:domain cust:Customer ;
	rdfs:range xsd:string ;
	rdfs:label "ADDRESS2" .

cust:city a rdf:Property ;
	rdfs:domain cust:Customer ;
	rdfs:range xsd:string ;
	rdfs:label "CITY" .

cust:state a rdf:Property ;
	rdfs:domain cust:Customer ;
	rdfs:range xsd:string ;
	rdfs:label "STATE" .

cust:zipcode a rdf:Property ;
	rdfs:domain cust:Customer ;
	rdfs:range xsd:string ;
	rdfs:label "ZIP CODE" .

cust:phone a rdf:Property ;
	rdfs:domain cust:Customer ;
	rdfs:range xsd:string ;
	rdfs:label "PHONE NUMBER" .



callt:Call_type a rdfs:Class ;
	rdfs:label "Call_type" ;
	rdfs:comment "Informix SD call_type table" .

callt:call_code a rdf:Property ;
	rdfs:domain callt:Call_type ;
	rdfs:range xsd:string ;
	rdfs:label "CALL CODE" .

callt:code_descr a rdf:Property ;
	rdfs:domain callt:Call_type ;
	rdfs:range xsd:string ;
	rdfs:label "CODE DESCRIPTION" .



manuf:Manufact a rdfs:Class ;
	rdfs:label "Manufact" ;
	rdfs:comment "Informix SD manufact table" .

manuf:manu_code a rdf:Property ;
	rdfs:domain manuf:Manufact ;
	rdfs:range xsd:string ;
	rdfs:label "MANUFACTURE CODE" .

manuf:manu_name a rdf:Property ;
	rdfs:domain manuf:Manufact ;
	rdfs:range xsd:string ;
	rdfs:label "MANUFACTURE NAME" .

manuf:lead_time a rdf:Property ;
	rdfs:domain manuf:Manufact ;
	rdfs:range xsd:integer ;
	rdfs:label "LEAD TIME" .



custc:Cust_calls a rdfs:Class ;
	rdfs:label "Cust_calls" ;
	rdfs:comment "Informix SD cust_calls table" .

custc:call_dtime a rdf:Property ;
	rdfs:domain manuf:Cust_calls ;
	rdfs:range xsd:datetime ;
	rdfs:label "CALL TIME" .

custc:user_id a rdf:Property ;
	rdfs:domain manuf:Cust_calls ;
	rdfs:range xsd:string ;
	rdfs:label "USER ID" .

custc:call_descr a rdf:Property ;
	rdfs:domain manuf:Cust_calls ;
	rdfs:range xsd:string ;
	rdfs:label "CALL DESCRIPTION" .

custc:res_dtime a rdf:Property ;
	rdfs:domain manuf:Cust_calls ;
	rdfs:range xsd:datetime ;
	rdfs:label "RES TIME" .

custc:res_descr a rdf:Property ;
	rdfs:domain manuf:Cust_calls ;
	rdfs:range xsd:string ;
	rdfs:label "RES DESCRIPTION" .

custc:customer_num_fk a rdf:Property ;
	rdfs:domain manuf:Cust_calls ;
	rdfs:range cust:Customer ;
	rdfs:label "CUSTOMER NUM" .

custc:call_code_fk a rdf:Property ;
	rdfs:domain manuf:Cust_calls ;
	rdfs:range callt:Call_type ;
	rdfs:label "CALL CODE" .


', '', 'http://localhost:8890/schemas/informix/stores_demo', 0);



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




sparql

prefix items:   <http://localhost:8890/schemas/informix/stores_demo/items/>
prefix catalog: <http://localhost:8890/schemas/informix/stores_demo/catalog/>
prefix stock:   <http://localhost:8890/schemas/informix/stores_demo/stock/>
prefix msgs:    <http://localhost:8890/schemas/informix/stores_demo/msgs/>
prefix state:   <http://localhost:8890/schemas/informix/stores_demo/state/>
prefix orders:  <http://localhost:8890/schemas/informix/stores_demo/orders/>
prefix manuf:   <http://localhost:8890/schemas/informix/stores_demo/manufact/>
prefix cust:    <http://localhost:8890/schemas/informix/stores_demo/customer/>
prefix callt:   <http://localhost:8890/schemas/informix/stores_demo/call_type/>
prefix custc:   <http://localhost:8890/schemas/informix/stores_demo/cust_calls/>

create iri class items:items_iri
	"http://localhost:8890/informix/stores_demo/items/%d_%d#this"
	(in item_num integer not null, in order_num integer not null) .

create iri class catalog:catalog_iri
	"http://localhost:8890/informix/stores_demo/catalog/%d#this"
    	(in catalog_num integer not null) .

create iri class msgs:msgs_iri
	"http://localhost:8890/informix/stores_demo/msgs/%U_%d_%U#this"
    	(in _lang varchar not null, in number integer not null, in message varchar not null) .

create iri class state:state_iri
	"http://localhost:8890/informix/stores_demo/state/%U#this"
    	(in code varchar not null) .

create iri class orders:orders_iri
	"http://localhost:8890/informix/stores_demo/orders/%d#this"
    	(in order_num integer not null) .

create iri class stock:stock_iri
	"http://localhost:8890/informix/stores_demo/stock/%d_%U#this"
    	(in stock_num integer not null, in manu_code varchar not null) .

create iri class cust:customer_iri
	"http://localhost:8890/informix/stores_demo/customer/%d#this"
    	(in customer_num integer not null) .

create iri class callt:call_type_iri
	"http://localhost:8890/informix/stores_demo/call_type/%U#this"
    	(in call_code varchar not null) .

create iri class manuf:manufact_iri
	"http://localhost:8890/informix/stores_demo/manufact/%U#this"
    	(in manu_code varchar not null) .

create iri class custc:cust_calls_iri using
	function DB.DBA.CUST_CALLS_IRI (in customer_num integer, in call_dtime datetime) returns varchar,
	function DB.DBA.CUST_CALLS_IRI_INV_1 (in cust_calls_iri varchar) returns integer,
        function DB.DBA.CUST_CALLS_IRI_INV_2 (in cust_calls_iri varchar) returns datetime .
;







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

sparql

prefix items:   <http://localhost:8890/schemas/informix/stores_demo/items/>
prefix catalog: <http://localhost:8890/schemas/informix/stores_demo/catalog/>
prefix stock:   <http://localhost:8890/schemas/informix/stores_demo/stock/>
prefix msgs:    <http://localhost:8890/schemas/informix/stores_demo/msgs/>
prefix state:   <http://localhost:8890/schemas/informix/stores_demo/state/>
prefix orders:  <http://localhost:8890/schemas/informix/stores_demo/orders/>
prefix manuf:   <http://localhost:8890/schemas/informix/stores_demo/manufact/>
prefix cust:    <http://localhost:8890/schemas/informix/stores_demo/customer/>
prefix callt:   <http://localhost:8890/schemas/informix/stores_demo/call_type/>
prefix custc:   <http://localhost:8890/schemas/informix/stores_demo/cust_calls/>

alter quad storage virtrdf:DefaultQuadStorage
  from stores_demo_rdf.inf10_stores_demo_rdf.items      as items_tbl
  from stores_demo_rdf.inf10_stores_demo_rdf.catalog    as catalog_tbl
  from stores_demo_rdf.inf10_stores_demo_rdf.msgs       as msgs_tbl
  from stores_demo_rdf.inf10_stores_demo_rdf.state      as state_tbl
  from stores_demo_rdf.inf10_stores_demo_rdf.orders     as orders_tbl
  from stores_demo_rdf.inf10_stores_demo_rdf.stock      as stock_tbl
  from stores_demo_rdf.inf10_stores_demo_rdf.customer   as customer_tbl
  from stores_demo_rdf.inf10_stores_demo_rdf.call_type  as call_type_tbl
  from stores_demo_rdf.inf10_stores_demo_rdf.manufact   as manufact_tbl
  from stores_demo_rdf.inf10_stores_demo_rdf.cust_calls as cust_calls_tbl
{
  create virtrdf:informix_stores_demo as graph <http://localhost:8890/informix/stores_demo>
  {
    items:items_iri (items_tbl.item_num, items_tbl.order_num) a items:Items as virtrdf:items_pk ;
    items:item_num    items_tbl.item_num       as virtrdf:items_item_num ;
    items:order_num   items_tbl.order_num      as virtrdf:items_order_num ;
    items:stock_num   items_tbl.stock_num      as virtrdf:items_stock_num ;
    items:manu_code   items_tbl.manu_code      as virtrdf:items_manu_code ;
    items:quantity    items_tbl.quantity       as virtrdf:items_quantity ;
    items:total_price items_tbl.total_price    as virtrdf:items_total_price ;
    items:from_order  orders:orders_iri (orders_tbl.order_num) where (^{items_tbl.}^.order_num = ^{orders_tbl.}^.order_num) as virtrdf:Items-from_order ;
    items:has_stock   stock:stock_iri (stock_tbl.stock_num, stock_tbl.manu_code) where (^{items_tbl.}^.stock_num = ^{stock_tbl.}^.stock_num and ^{items_tbl.}^.manu_code = ^{stock_tbl.}^.manu_code)  as virtrdf:Item-has_stock .

    catalog:catalog_iri (catalog_tbl.catalog_num) a catalog:Catalog as virtrdf:catalog_num;
    catalog:stock_num   catalog_tbl.stock_num    as virtrdf:catalog_stock_num ;
    catalog:manu_code   catalog_tbl.manu_code    as virtrdf:catalog_manu_code ;
    catalog:cat_descr   catalog_tbl.cat_descr    as virtrdf:catalog_cat_descr ;
    catalog:cat_picture catalog_tbl.cat_picture  as virtrdf:catalog_cat_picture ;
    catalog:cat_advert  catalog_tbl.cat_advert   as virtrdf:catalog_cat_advert ;
    catalog:has_stock   stock:stock_iri (stock_tbl.stock_num, stock_tbl.manu_code) where (^{catalog_tbl.}^.stock_num = ^{stock_tbl.}^.stock_num and ^{catalog_tbl.}^.manu_code = ^{stock_tbl.}^.manu_code)  as virtrdf:Catalog-has_stock .

    msgs:msgs_iri (msgs_tbl.lang, msgs_tbl.number, msgs_tbl.message) a msgs:Msgs as virtrdf:msgs_pk ;
    msgs:lang     msgs_tbl.lang    as virtrdf:msgs_lang ;
    msgs:number   msgs_tbl.number  as virtrdf:msgs_number ;
    msgs:message  msgs_tbl.message as virtrdf:msgs_message .

    state:state_iri (state_tbl.code) a state:State as virtrdf:code ;
    state:code   state_tbl.code   as virtrdf:state_code ;
    state:sname  state_tbl.sname  as virtrdf:state_sname .

    orders:orders_iri (orders_tbl.order_num) a orders:Orders as virtrdf:order_num ;
    orders:order_num     orders_tbl.order_num     as virtrdf:orders_order_num ;
    orders:order_date    orders_tbl.order_date    as virtrdf:orders_order_date ;
    orders:customer_num  orders_tbl.customer_num  as virtrdf:orders_customer_num ;
    orders:ship_instruct orders_tbl.ship_instruct as virtrdf:orders_ship_instruct ;
    orders:backlog       orders_tbl.backlog       as virtrdf:orders_backlog ;
    orders:po_num        orders_tbl.po_num        as virtrdf:orders_po_num ;
    orders:ship_date     orders_tbl.ship_date     as virtrdf:orders_ship_date ;
    orders:ship_weight   orders_tbl.ship_weight   as virtrdf:orders_ship_weight ;
    orders:ship_charge   orders_tbl.ship_charge   as virtrdf:orders_ship_charge ;
    orders:paid_date     orders_tbl.paid_date     as virtrdf:orders_paid_date ;
    orders:has_customer cust:customer_iri (customer_tbl.customer_num) where (^{orders_tbl.}^.customer_num = ^{customer_tbl.}^.customer_num) as virtrdf:Orders-has_customer ;
    orders:has_item     items:items_iri (items_tbl.item_num, items_tbl.order_num) where (^{orders_tbl.}^.order_num = ^{items_tbl.}^.order_num) as virtrdf:Orders-has_item .

    stock:stock_iri (stock_tbl.stock_num, stock_tbl.manu_code) a stock:Stock as virtrdf:stock_pk ;
    stock:stock_num    stock_tbl.stock_num    as virtrdf:stock_stock_num ;
    stock:manu_code    stock_tbl.manu_code    as virtrdf:stock_manu_code ;
    stock:description  stock_tbl.description  as virtrdf:stock_description ;
    stock:unit_price   stock_tbl.unit_price   as virtrdf:stock_unit_price ;
    stock:unit         stock_tbl.unit         as virtrdf:stock_unit ;
    stock:unit_descr   stock_tbl.unit_descr   as virtrdf:stock_unit_descr ;
    stock:manufactured_by manuf:manufact_iri (manufact_tbl.manu_code) where (^{stock_tbl.}^.manu_code = ^{manufact_tbl.}^.manu_code) as virtrdf:Stock-manufactured_by ;
    stock:in_catalog  catalog:catalog_iri (catalog_tbl.catalog_num) where (^{stock_tbl.}^.stock_num = ^{catalog_tbl.}^.stock_num and ^{stock_tbl.}^.manu_code = ^{catalog_tbl.}^.manu_code) as virtrdf:Stock-in_catalog ;
    stock:in_item     items:items_iri (items_tbl.item_num, items_tbl.order_num) where (^{stock_tbl.}^.stock_num = ^{items_tbl.}^.stock_num and ^{stock_tbl.}^.manu_code = ^{items_tbl.}^.manu_code) as virtrdf:Stock-in_items .


    cust:customer_iri (customer_tbl.customer_num) a cust:Customer as virtrdf:customer_num ;
    cust:customer_num  customer_tbl.customer_num  as virtrdf:customer_customer_num ;
    cust:fname         customer_tbl.fname         as virtrdf:customer_fname ;
    cust:lname         customer_tbl.lname         as virtrdf:customer_lname ;
    cust:company       customer_tbl.company       as virtrdf:customer_company ;
    cust:address1      customer_tbl.address1      as virtrdf:customer_address1 ;
    cust:address2      customer_tbl.address2      as virtrdf:customer_address2 ;
    cust:city          customer_tbl.city          as virtrdf:customer_city ;
    cust:state         customer_tbl.state         as virtrdf:customer_state ;
    cust:zipcode       customer_tbl.zipcode       as virtrdf:customer_zipcode ;
    cust:phone         customer_tbl.phone         as virtrdf:customer_phone ;
    cust:placed_order orders:orders_iri (orders_tbl.order_num) where (^{customer_tbl.}^.customer_num = ^{orders_tbl.}^.customer_num) as virtrdf:Customer-placed_order ;
    cust:made_call    custc:cust_calls_iri (cust_calls_tbl.customer_num, cust_calls_tbl.call_dtime ) where (^{customer_tbl.}^.customer_num = ^{cust_calls_tbl.}^.customer_num) as virtrdf:Cust_calls-made_call .

    callt:call_type_iri (call_type_tbl.call_code) a callt:Call_type as virtrdf:call_code ;
    callt:call_code   call_type_tbl.call_code as virtrdf:call_type_call_code ;
    callt:code_descr  call_type_tbl.code_descr as virtrdf:call_type_code_descr ;
    callt:call_is_type  custc:cust_calls_iri (cust_calls_tbl.customer_num, cust_calls_tbl.call_dtime) where (^{call_type_tbl.}^.call_code = ^{cust_calls_tbl.}^.call_code) as virtrdf:Call_type-call_is_type .

    manuf:manufact_iri (manufact_tbl.manu_code) a manuf:Manufact as virtrdf:manu_code ;
    manuf:manu_code     manufact_tbl.manu_code   as virtrdf:manufact_tbl_manu_code ;
    manuf:manu_name     manufact_tbl.manu_name   as virtrdf:manufact_tbl_manu_name ;
    manuf:lead_time     manufact_tbl.lead_time   as virtrdf:manufact_tbl_lead_time ;
    manuf:manufactures stock:stock_iri (stock_tbl.stock_num, stock_tbl.manu_code) where (^{manufact_tbl.}^.manu_code = ^{stock_tbl.}^.manu_code) as virtrdf:Manufact-manufactures .

    custc:cust_calls_iri  (cust_calls_tbl.customer_num, cust_calls_tbl.call_dtime) a custc:Cust_calls as virtrdf:cust_calls_pk ;
    custc:user_id    cust_calls_tbl.user_id      as virtrdf:cust_calls_user_id ;
    custc:call_code  cust_calls_tbl.call_code    as virtrdf:cust_calls_call_code ;
    custc:call_descr cust_calls_tbl.call_descr   as virtrdf:cust_calls_call_descr ;
    custc:res_dtime  cust_calls_tbl.res_dtime    as virtrdf:cust_calls_res_dtime ;
    custc:res_descr  cust_calls_tbl.res_descr    as virtrdf:cust_calls_res_descr ;
    custc:made_by_customer cust:customer_iri   (customer_tbl.customer_num) where (^{cust_calls_tbl.}^.customer_num = ^{customer_tbl.}^.customer_num) as virtrdf:Cust_calls-made_by_customer ;
    custc:is_call_type     callt:call_type_iri (call_type_tbl.call_code)   where (^{cust_calls_tbl.}^.call_code    = ^{call_type_tbl.}^.call_code)   as virtrdf:Cust_calls-is_call_type .

  } .
} .
;

delete from db.dba.url_rewrite_rule_list where urrl_list like 'informix_sd_rule%';
delete from db.dba.url_rewrite_rule where urr_rule like 'informix_sd_rule%';

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


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

DB.DBA.URLREWRITE_CREATE_RULELIST (
    'informix_sd_rule_list1',
    1,
    vector (
  	 	'informix_sd_rule1',
  	 	'informix_sd_rule2'
	  ));

-- ensure a VD for the IRIs which begins with /
VHOST_REMOVE (lpath=>'/informix/stores_demo');

VHOST_DEFINE (
	lpath=>'/informix/stores_demo',
	ppath=>'/DAV/informix/stores_demo/',
    	is_dav=>1,
	vsp_user=>'dba',
	is_brws=>0,
	opts=>vector ('url_rewrite', 'informix_sd_rule_list1')
	);

delete from db.dba.url_rewrite_rule_list where urrl_list like 'informix_sd_schemas_rule%';
delete from db.dba.url_rewrite_rule where urr_rule like 'informix_sd_schemas_rule%';

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

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

DB.DBA.URLREWRITE_CREATE_RULELIST (
    'informix_sd_schemas_rule_list1',
    1,
    vector (
  	 	'informix_sd_schemas_rule1',
  	 	'informix_sd_schemas_rule2'
	  ));

-- ensure a VD for the IRIs which begins with /
VHOST_REMOVE (lpath=>'/schemas/informix/stores_demo');

VHOST_DEFINE (
	lpath=>'/schemas/informix/stores_demo',
	ppath=>'/DAV/schemas/informix/stores_demo/',
    	is_dav=>1,
	vsp_user=>'dba',
	is_brws=>0,
	opts=>vector ('url_rewrite', 'informix_sd_schemas_rule_list1')
	);

DB.DBA.XML_SET_NS_DECL ('items',   'http://^{URIQADefaultHost}^/schemas/informix/stores_demo/items/', 2);
DB.DBA.XML_SET_NS_DECL ('catalog', 'http://^{URIQADefaultHost}^/schemas/informix/stores_demo/catalog/', 2);
DB.DBA.XML_SET_NS_DECL ('stock',   'http://^{URIQADefaultHost}^/schemas/informix/stores_demo/stock/', 2);
DB.DBA.XML_SET_NS_DECL ('msgs',    'http://^{URIQADefaultHost}^/schemas/informix/stores_demo/msgs/', 2);
DB.DBA.XML_SET_NS_DECL ('state',   'http://^{URIQADefaultHost}^/schemas/informix/stores_demo/state/', 2);
DB.DBA.XML_SET_NS_DECL ('orders',  'http://^{URIQADefaultHost}^/schemas/informix/stores_demo/orders/', 2);
DB.DBA.XML_SET_NS_DECL ('manuf',   'http://^{URIQADefaultHost}^/schemas/informix/stores_demo/manufact/', 2);
DB.DBA.XML_SET_NS_DECL ('cust',    'http://^{URIQADefaultHost}^/schemas/informix/stores_demo/customer/', 2);
DB.DBA.XML_SET_NS_DECL ('callt',   'http://^{URIQADefaultHost}^/schemas/informix/stores_demo/call_type/', 2);
DB.DBA.XML_SET_NS_DECL ('custc',   'http://^{URIQADefaultHost}^/schemas/informix/stores_demo/cust_calls/', 2);

15.8.15.7. Ingres using demonstration 'Tutorial' database

-- Setup script for RDF views of Ingres R3 Tutorial Sample Database --

DB..vd_remote_data_source ('ingiima-tut', '', '<uid>','<pwd>');

ATTACH TABLE  "ingres"."book_list"      PRIMARY KEY ("book_no")              AS "TUT"."ingiima"."book_list"      FROM 'ingiima-tut';
ATTACH TABLE  "ingres"."book_orders"      PRIMARY KEY ("order_no")              AS "TUT"."ingiima"."book_orders"      FROM 'ingiima-tut';
ATTACH TABLE  "ingres"."cust_info"      PRIMARY KEY ("cust_no")              AS "TUT"."ingiima"."cust_info"      FROM 'ingiima-tut';
ATTACH TABLE  "ingres"."cust_orders"      PRIMARY KEY ("order_no")              AS "TUT"."ingiima"."cust_orders"      FROM 'ingiima-tut';

COMMIT WORK;

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

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

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

ttlp (
'
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .

@prefix tut: <http://localhost:8890/schemas/ingrestut/> .

tut:book_list a rdfs:Class ;
	rdfs:isDefinedBy <http://localhost:8890/schemas/ingrestut> ;
	rdfs:label "book_list" ;
	rdfs:comment "Ingres Tutorial Database book_list table" .

tut:book_no a rdf:Property ;
	rdfs:domain tut:book_list ;
	rdfs:range xsd:integer ;
	rdfs:label "Book No" .

tut:title a rdf:Property ;
	rdfs:domain tut:book_list ;
	rdfs:range xsd:string ;
	rdfs:label "Title" .

tut:author a rdf:Property ;
	rdfs:domain tut:book_list ;
	rdfs:range xsd:string ;
	rdfs:label "Author" .

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

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

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

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

tut:book_orders a rdfs:Class ;
	rdfs:isDefinedBy <http://localhost:8890/schemas/ingrestut> ;
	rdfs:label "Book Orders" ;
	rdfs:comment "Ingres Tutorial Database book_orders table" .

tut:order_no a rdf:Property ;
	rdfs:domain tut:book_orders ;
	rdfs:range xsd:integer ;
         rdfs:label "Order No" .

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

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

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

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

tut:cust_info a rdfs:Class ;
	rdfs:isDefinedBy <http://localhost:8890/schemas/ingrestut> ;
	rdfs:label "Customer Information" ;
	rdfs:comment "Ingres Tutorial Database cust_info table" .

tut:cust_no a rdf:Property ;
	rdfs:domain tut:cust_info ;
	rdfs:range xsd:integer ;
         rdfs:label "Customer No" .

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

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

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

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

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

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

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

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

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

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

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

tut:cust_orders a rdfs:Class ;
	rdfs:isDefinedBy <http://localhost:8890/schemas/ingrestut> ;
	rdfs:label "Customer Orders" ;
	rdfs:comment "Ingres Tutorial Database cust_orders table" .

tut:order_no a rdf:Property ;
	rdfs:domain tut:cust_orders ;
	rdfs:range tut:book_orders ;
         rdfs:label "Order No" .

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

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

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

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

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

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

sparql

	create iri class <http://localhost:8890/schemas/ingrestut/book_list_iri>
	"http://^{URIQADefaultHost}^/ingrestut/book_list/%d#this"
    	(in book_no integer not null) .

	create iri class <http://localhost:8890/schemas/ingrestut/book_orders_iri>
	"http://^{URIQADefaultHost}^/ingrestut/book_orders/%d_%d#this"
	 (in order_no integer not null, in book_no integer not null ) .

	create iri class <http://localhost:8890/schemas/ingrestut/cust_info_iri>
	"http://^{URIQADefaultHost}^/ingrestut/cust_info/%d#this"
    	(in cust_no integer not null) .

	create iri class <http://localhost:8890/schemas/ingrestut/cust_orders_iri>
	"http://^{URIQADefaultHost}^/ingrestut/cust_orders/%d#this"
    	(in order_no integer not null) .

	;

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

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

sparql

prefix tut:	<http://localhost:8890/schemas/ingrestut/>

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 <http://localhost:8890/ingrestut>
  {
        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 'ingrestut_rule%';
delete from db.dba.url_rewrite_rule where urr_rule like 'ingrestut_rule%';

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


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

DB.DBA.URLREWRITE_CREATE_RULELIST (
    'ingrestut_rule_list1',
    1,
    vector (
  	 	'ingrestut_rule1',
  	 	'ingrestut_rule2'
	  ));

-- ensure a VD for the IRIs which begins with /
VHOST_REMOVE (lpath=>'/ingrestut');

VHOST_DEFINE (
	lpath=>'/ingrestut',
	ppath=>'/DAV/ingrestut/',
    	is_dav=>1,
	vsp_user=>'dba',
	is_brws=>0,
	opts=>vector ('url_rewrite', 'ingrestut_rule_list1')
	);

delete from db.dba.url_rewrite_rule_list where urrl_list like 'ingres_schemas_rule%';
delete from db.dba.url_rewrite_rule where urr_rule like 'ingres_schemas_rule%';

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

DB.DBA.URLREWRITE_CREATE_REGEX_RULE (
    'ingres_schemas_rule2',
    1,
    '(/[^#]*)',
    vector('path'),
    1,
    '/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+}&format=%U',
    vector('path','path','*accept*'),
    null,
    '(text/rdf.n3)|(application/rdf.xml)',
    0,
    null
    );

DB.DBA.URLREWRITE_CREATE_RULELIST (
    'ingres_schemas_rule_list1',
    1,
    vector (
  	 	'ingres_schemas_rule1',
  	 	'ingres_schemas_rule2'
	  ));

-- ensure a VD for the IRIs which begins with /
VHOST_REMOVE (lpath=>'/schema/ingrestut');

VHOST_DEFINE (
	lpath=>'/schemas/ingrestut',
	ppath=>'/DAV/schemas/ingrestut/',
    	is_dav=>1,
	vsp_user=>'dba',
	is_brws=>0,
	opts=>vector ('url_rewrite', 'ingres_schemas_rule_list1')
	);

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

15.8.15.8. Sybase using demonstration 'pubs2' database

-- Setup script for RDF views of Sybase 15 PUBS2 Sample Database --

DB..vd_remote_data_source ('syb15ma-pubs2', '', '<uid>','<pwd>');

ATTACH TABLE  "pubs2.dbo.au_pix"  PRIMARY KEY ("au_id")                  AS "pubs2"."syb"."au_pix"  FROM 'syb15ma-pubs2';
ATTACH TABLE  "pubs2.dbo.authors"  PRIMARY KEY ("au_id")                  AS "pubs2"."syb"."authors"  FROM 'syb15ma-pubs2';
ATTACH TABLE  "pubs2.dbo.discounts"  PRIMARY KEY ("stor_id")                  AS "pubs2"."syb"."discounts"  FROM 'syb15ma-pubs2';
ATTACH TABLE  "pubs2.dbo.publishers"  PRIMARY KEY ("pub_id")                  AS "pubs2"."syb"."publishers"  FROM 'syb15ma-pubs2';
ATTACH TABLE  "pubs2.dbo.roysched"  PRIMARY KEY ("title_id")                  AS "pubs2"."syb"."roysched"  FROM 'syb15ma-pubs2';
ATTACH TABLE  "pubs2.dbo.sales"  PRIMARY KEY ("stor_id", "ord_num")                  AS "pubs2"."syb"."sales"  FROM 'syb15ma-pubs2';
ATTACH TABLE  "pubs2.dbo.salesdetail"  PRIMARY KEY ("stor_id", "ord_num", "title_id")                   AS "pubs2"."syb"."salesdetail"  FROM 'syb15ma-pubs2';
ATTACH TABLE  "pubs2.dbo.stores"  PRIMARY KEY ("stor_id")                  AS "pubs2"."syb"."stores"  FROM 'syb15ma-pubs2';
ATTACH TABLE  "pubs2.dbo.titleauthor"  PRIMARY KEY ("au_id", "title_id")                  AS "pubs2"."syb"."titleauthor"  FROM 'syb15ma-pubs2';
ATTACH TABLE  "pubs2.dbo.titles"  PRIMARY KEY ("title_id", "pub_id")                  AS "pubs2"."syb"."titles"  FROM 'syb15ma-pubs2';

COMMIT WORK;

GRANT SELECT ON pubs2.syb.au_pix TO "SPARQL", "SPARQL_UPDATE";
GRANT SELECT ON pubs2.syb.authors TO "SPARQL", "SPARQL_UPDATE";
GRANT SELECT ON pubs2.syb.discounts TO "SPARQL", "SPARQL_UPDATE";
GRANT SELECT ON pubs2.syb.publishers TO "SPARQL", "SPARQL_UPDATE";
GRANT SELECT ON pubs2.syb.roysched TO "SPARQL", "SPARQL_UPDATE";
GRANT SELECT ON pubs2.syb.sales TO "SPARQL", "SPARQL_UPDATE";
GRANT SELECT ON pubs2.syb.salesdetail TO "SPARQL", "SPARQL_UPDATE";
GRANT SELECT ON pubs2.syb.stores TO "SPARQL", "SPARQL_UPDATE";
GRANT SELECT ON pubs2.syb.titleauthor TO "SPARQL", "SPARQL_UPDATE";
GRANT SELECT ON pubs2.syb.titles TO "SPARQL", "SPARQL_UPDATE";

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

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

ttlp (
'
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .

@prefix syb: <http://localhost:8890/schemas/sybasepubs2/> .

syb:titles a rdfs:Class ;
	rdfs:isDefinedBy <http://localhost:8890/schemas/sybasepubs2> ;
	rdfs:label "titles" ;
	rdfs:comment "Sybase Pubs2 titles table" .

syb:title_id a rdf:Property ;
	rdfs:domain syb:titles ;
	rdfs:range xsd:string ;
	rdfs:label "title id" .

syb:title a rdf:Property ;
	rdfs:domain syb:titles ;
	rdfs:range xsd:string ;
	rdfs:label "title" .

syb:type a rdf:Property ;
	rdfs:domain syb:titles ;
	rdfs:range xsd:string ;
	rdfs:label "type" .

syb:pub_id a rdf:Property ;
	rdfs:domain syb:titles ;
	rdfs:range syb:publishers ;
	rdfs:label "pub_id" .

syb:advance a rdf:Property ;
	rdfs:domain syb:titles ;
	rdfs:range xsd:decimal ;
	rdfs:label "advance" .

syb:price a rdf:Property ;
	rdfs:domain syb:titles ;
	rdfs:range xsd:decimal ;
	rdfs:label "price" .

syb:total_sales a rdf:Property ;
	rdfs:domain syb:titles ;
	rdfs:range xsd:integer ;
	rdfs:label "total_sales" .

syb:notes a rdf:Property ;
	rdfs:domain syb:titles ;
	rdfs:range xsd:string ;
	rdfs:label "notes" .

syb:contract a rdf:Property ;
	rdfs:domain syb:titles ;
	rdfs:range xsd:integer ;
	rdfs:label "contract" .

syb:pubdate a rdf:Property ;
	rdfs:domain syb:titles ;
	rdfs:range xsd:dateTime ;
	rdfs:label "publish date" .

syb:authors a rdfs:Class ;
	rdfs:isDefinedBy <http://localhost:8890/schemas/sybasepubs2> ;
	rdfs:label "authors" ;
	rdfs:comment "Sybase Pubs2 authors table" .

syb:au_id a rdf:Property ;
	rdfs:domain syb:authors ;
	rdfs:range xsd:string ;
	rdfs:label "author id" .

syb:au_lname a rdf:Property ;
	rdfs:domain syb:authors ;
	rdfs:range xsd:string ;
	rdfs:label "author last name" .

syb:au_fname a rdf:Property ;
	rdfs:domain syb:authors ;
	rdfs:range xsd:string ;
	rdfs:label "author first name" .

syb:phone a rdf:Property ;
	rdfs:domain syb:authors ;
	rdfs:range xsd:string ;
	rdfs:label "phone number" .

syb:address a rdf:Property ;
	rdfs:domain syb:authors ;
	rdfs:range xsd:string ;
	rdfs:label "address" .

syb:city a rdf:Property ;
	rdfs:domain syb:authors ;
	rdfs:range xsd:string ;
	rdfs:label "city" .

syb:state a rdf:Property ;
	rdfs:domain syb:authors ;
	rdfs:range xsd:string ;
	rdfs:label "state" .

syb:country a rdf:Property ;
	rdfs:domain syb:authors ;
	rdfs:range xsd:string ;
	rdfs:label "country" .

syb:postalcode a rdf:Property ;
	rdfs:domain syb:authors ;
	rdfs:range xsd:string ;
	rdfs:label "postalcode" .

syb:stores a rdfs:Class ;
	rdfs:isDefinedBy <http://localhost:8890/schemas/sybasepubs2> ;
	rdfs:label "stores" ;
	rdfs:comment "Sybase Pubs2 stores table" .

syb:stor_id a rdf:Property ;
	rdfs:domain syb:stores ;
	rdfs:range xsd:string ;
	rdfs:label "store id" .

syb:stor_name a rdf:Property ;
	rdfs:domain syb:stores ;
	rdfs:range xsd:string ;
	rdfs:label "store name" .

syb:stor_address a rdf:Property ;
	rdfs:domain syb:stores ;
	rdfs:range xsd:string ;
	rdfs:label "store address" .

syb:city a rdf:Property ;
	rdfs:domain syb:stores ;
	rdfs:range xsd:string ;
	rdfs:label "city" .

syb:state a rdf:Property ;
	rdfs:domain syb:stores ;
	rdfs:range xsd:string ;
	rdfs:label "state" .

syb:country a rdf:Property ;
	rdfs:domain syb:stores ;
	rdfs:range xsd:string ;
	rdfs:label "country" .

syb:postalcode a rdf:Property ;
	rdfs:domain syb:stores ;
	rdfs:range xsd:string ;
	rdfs:label "postal code" .

syb:payterms a rdf:Property ;
	rdfs:domain syb:stores ;
	rdfs:range xsd:string ;
	rdfs:label "payment terms" .

syb:au_pix a rdfs:Class ;
	rdfs:isDefinedBy <http://localhost:8890/schemas/sybasepubs2> ;
	rdfs:label "authors pictures" ;
	rdfs:comment "Sybase Pubs2 au_pix table" .

syb:au_id a rdf:Property ;
	rdfs:domain syb:au_pix ;
	rdfs:range syb:authors ;
	rdfs:label "author id" .

syb:format_type a rdf:Property ;
	rdfs:domain syb:au_pix ;
	rdfs:range xsd:string ;
	rdfs:label "format type" .

syb:bytesize a rdf:Property ;
	rdfs:domain syb:au_pix ;
	rdfs:range xsd:integer ;
	rdfs:label "byte size" .

syb:pixwidth_hor a rdf:Property ;
	rdfs:domain syb:au_pix ;
	rdfs:range xsd:string ;
	rdfs:label "picture horizontal width" .

syb:pixwidth_vert a rdf:Property ;
	rdfs:domain syb:au_pix ;
	rdfs:range xsd:string ;
	rdfs:label "picture vertical width" .

syb:discounts a rdfs:Class ;
	rdfs:isDefinedBy <http://localhost:8890/schemas/sybasepubs2> ;
	rdfs:label "discounts" ;
	rdfs:comment "Sybase Pubs2 discount table" .

syb:discounttype a rdf:Property ;
	rdfs:domain syb:discounts ;
	rdfs:range xsd:string ;
	rdfs:label "discounttype" .

syb:stor_id a rdf:Property ;
	rdfs:domain syb:discounts ;
	rdfs:range syb:stores ;
	rdfs:label "store id" .

syb:lowqty a rdf:Property ;
	rdfs:domain syb:discounts ;
	rdfs:range xsd:integer ;
	rdfs:label "min quantity" .

syb:highqty a rdf:Property ;
	rdfs:domain syb:discounts ;
	rdfs:range xsd:integer ;
	rdfs:label "max quantity" .

syb:discount a rdf:Property ;
	rdfs:domain syb:discounts ;
	rdfs:range xsd:decimal ;
	rdfs:label "min quantity" .

syb:salesdetail a rdfs:Class ;
	rdfs:isDefinedBy <http://localhost:8890/schemas/sybasepubs2> ;
	rdfs:label "sales details" ;
	rdfs:comment "Sybase Pubs2 sales detail table" .

syb:store_id a rdf:Property ;
	rdfs:domain syb:salesdetail ;
	rdfs:range syb:stores ;
	rdfs:label "store id" .

syb:ord_num a rdf:Property ;
	rdfs:domain syb:salesdetail ;
	rdfs:range syb:sales ;
	rdfs:label "order number" .

syb:title_id a rdf:Property ;
	rdfs:domain syb:salesdetail ;
	rdfs:range syb:titles ;
	rdfs:label "title id" .

syb:qty a rdf:Property ;
	rdfs:domain syb:salesdetail ;
	rdfs:range xsd:integer ;
	rdfs:label "quantity" .

syb:discount a rdf:Property ;
	rdfs:domain syb:salesdetail ;
	rdfs:range xsd:decimal ;
	rdfs:label "discount" .

syb:publishers a rdfs:Class ;
	rdfs:isDefinedBy <http://localhost:8890/schemas/sybasepubs2> ;
	rdfs:label "Publishers" ;
	rdfs:comment "Sybase Pubs2 publishers table" .

syb:pub_id a rdf:Property ;
	rdfs:domain syb:publishers ;
	rdfs:range xsd:string ;
	rdfs:label "publisher id" .

syb:pub_name a rdf:Property ;
	rdfs:domain syb:publishers ;
	rdfs:range xsd:string ;
	rdfs:label "publisher name" .

syb:city a rdf:Property ;
	rdfs:domain syb:publishers ;
	rdfs:range xsd:string ;
	rdfs:label "city" .

syb:state a rdf:Property ;
	rdfs:domain syb:publishers ;
	rdfs:range xsd:string ;
	rdfs:label "state" .

syb:titleauthor a rdfs:Class ;
	rdfs:isDefinedBy <http://localhost:8890/schemas/sybasepubs2> ;
	rdfs:label "title author" ;
	rdfs:comment "Sybase Pubs2 titleauthor table" .

syb:au_id a rdf:Property ;
	rdfs:domain syb:titleauthor ;
	rdfs:range syb:authors ;
	rdfs:label "author id" .

syb:title_id a rdf:Property ;
	rdfs:domain syb:titleauthor ;
	rdfs:range syb:titles ;
	rdfs:label "title id" .

syb:au_ord a rdf:Property ;
	rdfs:domain syb:titleauthor ;
	rdfs:range xsd:integer ;
	rdfs:label "author order" .

syb:royaltyper a rdf:Property ;
	rdfs:domain syb:titleauthor ;
	rdfs:range xsd:integer ;
	rdfs:label "royalty per book" .

syb:roysched a rdfs:Class ;
	rdfs:isDefinedBy <http://localhost:8890/schemas/sybasepubs2> ;
	rdfs:label "Royalty Schedule" ;
	rdfs:comment "Sybase Pubs2 roysched table" .

syb:title_id a rdf:Property ;
	rdfs:domain syb:roysched ;
	rdfs:range syb:titles ;
	rdfs:label "title id" .

syb:lorange a rdf:Property ;
	rdfs:domain syb:roysched ;
	rdfs:range xsd:integer ;
	rdfs:label "low range" .

syb:hirange a rdf:Property ;
	rdfs:domain syb:roysched ;
	rdfs:range xsd:integer ;
	rdfs:label "high range" .

syb:royalty a rdf:Property ;
	rdfs:domain syb:roysched ;
	rdfs:range xsd:integer ;
	rdfs:label "royalty" .

syb:sales a rdfs:Class ;
	rdfs:isDefinedBy <http://localhost:8890/schemas/sybasepubs2> ;
	rdfs:label "Sales" ;
	rdfs:comment "Sybase Pubs2 sales table" .

syb:stor_id a rdf:Property ;
	rdfs:domain syb:sales ;
	rdfs:range xsd:string ;
	rdfs:label "store id" .

syb:ord_num a rdf:Property ;
	rdfs:domain syb:sales ;
	rdfs:range xsd:string ;
	rdfs:label "order number" .

syb:date a rdf:Property ;
	rdfs:domain syb:sales ;
	rdfs:range xsd:dateTime ;
	rdfs:label "date" .
', '', 'http://localhost:8890/schemas/sybasepubs2', 0);

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

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

sparql

	create iri class <http://localhost:8890/schemas/sybasepubs2/titles_iri>
	"http://^{URIQADefaultHost}^/sybasepubs2/titles/%s_%s#this"
    	(in title_id varchar not null, in title varchar not null) .

	create iri class <http://localhost:8890/schemas/sybasepubs2/authors_iri>
	"http://^{URIQADefaultHost}^/sybasepubs2/authors/%s#this"
    	(in au_id varchar not null) .

	create iri class <http://localhost:8890/schemas/sybasepubs2/stores_iri>
	"http://^{URIQADefaultHost}^/sybasepubs2/stores/%s#this"
    	(in stor_id varchar not null) .

	create iri class <http://localhost:8890/schemas/sybasepubs2/au_pix_iri>
	"http://^{URIQADefaultHost}^/sybasepubs2/au_pix/%s#this"
    	(in au_id varchar not null) .

	create iri class <http://localhost:8890/schemas/sybasepubs2/discounts_iri>
	"http://^{URIQADefaultHost}^/sybasepubs2/discounts/%s#this"
    	(in discounttype varchar not null) .

	create iri class <http://localhost:8890/schemas/sybasepubs2/salesdetail_iri>
	"http://^{URIQADefaultHost}^/sybasepubs2/salesdetail/%s_%s_%s#this"
    	(in stor_id varchar not null, in ord_num varchar not null, in title_id varchar not null) .

	create iri class <http://localhost:8890/schemas/sybasepubs2/publishers_iri>
	"http://^{URIQADefaultHost}^/sybasepubs2/publishers/%s#this"
    	(in pub_id varchar not null) .

	create iri class <http://localhost:8890/schemas/sybasepubs2/titleauthor_iri>
	"http://^{URIQADefaultHost}^/sybasepubs2/titleauthor/%s_%s#this"
    	(in au_id varchar not null, in title_id varchar not null) .

	create iri class <http://localhost:8890/schemas/sybasepubs2/roysched_iri>
	"http://^{URIQADefaultHost}^/sybasepubs2/roysched/%s#this"
    	(in title_id varchar not null) .

	create iri class <http://localhost:8890/schemas/sybasepubs2/sales_iri>
	"http://^{URIQADefaultHost}^/sybasepubs2/sales/%s_%s#this"
    	(in stor_id varchar not null, in ord_num varchar not null) .

;

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

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

sparql

prefix syb: <http://localhost:8890/schemas/sybasepubs2/>

alter quad storage virtrdf:DefaultQuadStorage
  from pubs2.syb.au_pix as au_pix_tbl
  from pubs2.syb.authors as authors_tbl
  from pubs2.syb.discounts as discounts_tbl
  from pubs2.syb.publishers as publishers_tbl
  from pubs2.syb.roysched as roysched_tbl
  from pubs2.syb.sales as sales_tbl
  from pubs2.syb.salesdetail as salesdetail_tbl
  from pubs2.syb.stores as stores_tbl
  from pubs2.syb.titleauthor as titleauthor_tbl
  from pubs2.syb.titles as titles_tbl
{
  create virtrdf:sybasepubs2 as
      graph <http://localhost:8890/sybasepubs2>
  {
	syb:au_pix_iri (au_pix_tbl.au_id) a syb:au_pix as virtrdf:au_pix_id;
	syb:au_id au_pix_tbl.au_id as virtrdf:au_pix_au_id;
	syb:format_type au_pix_tbl.format_type as virtrdf:au_pix_format_type;
	syb:bytesize au_pix_tbl.bytesize as virtrdf:au_pix_bytesize;
	syb:pixwidth_hor au_pix_tbl.pixwidth_hor as virtrdf:au_pix_pixwidth_hor;
	syb:pixwidth_vert au_pix_tbl.pixwidth_vert as virtrdf:au_pix_pixwidth_vert ;
       	syb:has_author syb:authors_iri(authors_tbl.au_id) where (^{authors_tbl.}^.au_id = ^{au_pix_tbl.}^.au_id) as virtrdf:au_pix_has_author .

        syb:authors_iri (authors_tbl.au_id) a syb:authors as virtrdf:authors_pk ;
	syb:au_id authors_tbl.au_id as virtrdf:authors_au_id;
       	syb:au_lname authors_tbl.au_lname as virtrdf:authors_au_lname;
       	syb:au_fname authors_tbl.au_fname as virtrdf:authors_au_fname;
       	syb:phone authors_tbl.phone  as virtrdf:authors_phone;
       	syb:address authors_tbl.address  as virtrdf:authors_address;
       	syb:city authors_tbl.city as virtrdf:authors_city;
       	syb:state authors_tbl.state  as virtrdf:authors_state;
       	syb:country authors_tbl.country as virtrdf:authors_country;
       	syb:postalcode authors_tbl.postalcode as virtrdf:authors_postalcode;
      	syb:has_title syb:titleauthor_iri(titleauthor_tbl.au_id, titleauthor_tbl.title_id) where (^{titleauthor_tbl.}^.au_id = ^{authors_tbl.}^.au_id) as virtrdf:authors_has_title;
      	syb:has_pix syb:au_pix_iri(au_pix_tbl.au_id) where (^{au_pix_tbl.}^.au_id = ^{authors_tbl.}^.au_id) as virtrdf:authors_has_pix .

	syb:discounts_iri (discounts_tbl.stor_id) a syb:discounts as virtrdf:discounts_pk;
	syb:discounttype discounts_tbl.discounttype as virtrdf:discounts_discounttype;
	syb:stor_id syb:stores_iri(stores_tbl.stor_id) where (^{stores_tbl.}^.stor_id = ^{stores_tbl.}^.stor_id) as virtrdf:discounts_stor_id;
	syb:lowqty discounts_tbl.lowqty as virtrdf:discounts_lowqty;
	syb:highqty discounts_tbl.highqty as virtrdf:discounts_highqty;
	syb:discount discounts_tbl.discount as virtrdf:discounts_discount .

	syb:publishers_iri (publishers_tbl.pub_id) a syb:publishers as virtrdf:publishers_pk;
	syb:pub_id syb:titles_iri(titles_tbl.title_id, titles_tbl.pub_id) where (^{titles_tbl.}^.pub_id = ^{titles_tbl.}^.pub_id) as virtrdf:publisherss_pub_id;
	syb:pub_name publishers_tbl.pub_name as virtrdf:publisherss_pub_name;
	syb:city publishers_tbl.city as virtrdf:publisherss_city;
	syb:state publishers_tbl.state as virtrdf:publisherss_state .

	syb:roysched_iri (roysched_tbl.title_id) a syb:roysched as virtrdf:roysched_pk;
       	syb:title_id syb:titleauthor_iri(titleauthor_tbl.au_id, titleauthor_tbl.title_id) where (^{titleauthor_tbl.}^.title_id = ^{roysched_tbl.}^.title_id) as virtrdf:roysched_title_id;
	syb:lorange roysched_tbl.lorange as virtrdf:roysched_lorange;
	syb:hirange roysched_tbl.hirange as virtrdf:roysched_hirange;
	syb:royalty roysched_tbl.royalty as virtrdf:roysched_royalty .

	syb:sales_iri (sales_tbl.stor_id, sales_tbl.ord_num) a syb:sales as virtrdf:sales_pk;
	syb:stor_id sales_tbl.stor_id as virtrdf:sales_stor_id;
	syb:ord_num sales_tbl.ord_num as virtrdf:sales_ord_num;
	syb:date sales_tbl.date as virtrdf:sales_date;
       	syb:has_salesdetail syb:salesdetail_iri(salesdetail_tbl.stor_id, salesdetail_tbl.ord_num, salesdetail_tbl.title_id) where (^{salesdetail_tbl.}^.stor_id = ^{sales_tbl.}^.stor_id and ^{salesdetail_tbl.}^.ord_num = ^{sales_tbl.}^.ord_num)  as virtrdf:sales_has_salesdetail;
       	syb:has_stores syb:stores_iri(stores_tbl.stor_id) where (^{stores_tbl.}^.stor_id = ^{sales_tbl.}^.stor_id)  as virtrdf:sales_has_stores .

	syb:salesdetail_iri (salesdetail_tbl.stor_id, salesdetail_tbl.ord_num, salesdetail_tbl.title_id) a syb:salesdetail as virtrdf:salesdetail_pk;
	syb:stor_id salesdetail_tbl.stor_id as virtrdf:salesdetail_stor_id;
	syb:ord_num salesdetail_tbl.ord_num as virtrdf:salesdetail_ord_num;
	syb:title_id salesdetail_tbl.title_id as virtrdf:salesdetail_title_id;
	syb:qty salesdetail_tbl.qty as virtrdf:salesdeail_qty;
	syb:discount salesdetail_tbl.discount as virtrdf:salesdetail_discount;
	syb:has_title  syb:titles_iri (titles_tbl.title_id, titles_tbl.pub_id) where (^{titles_tbl.}^.title_id = ^{salesdetail_tbl.}^.title_id) as virtrdf:salesdetail_has_title;
       	syb:has_sales syb:sales_iri(sales_tbl.stor_id, sales_tbl.ord_num) where (^{salesdetail_tbl.}^.stor_id = ^{sales_tbl.}^.stor_id and ^{salesdetail_tbl.}^.ord_num = ^{sales_tbl.}^.ord_num ) as virtrdf:salesdetail_has_sales .

	syb:stores_iri (stores_tbl.stor_id) a syb:stores as virtrdf:stores_pk;
       	syb:stor_id stores_tbl.stor_id as virtrdf:stores_stor_id;
	syb:stor_name stores_tbl.stor_name as virtrdf:stores_stor_name;
	syb:stor_address stores_tbl.stor_address as virtrdf:stores_stor_address;
	syb:city stores_tbl.city as virtrdf:stores_city;
	syb:state stores_tbl.state as virtrdf:stores_state;
	syb:country stores_tbl.country as virtrdf:stores_country;
	syb:postalcode stores_tbl.postalcode as virtrdf:stores_postalcode;
	syb:payterms stores_tbl.payterms as virtrdf:stores_payterms;
       	syb:has_sales syb:sales_iri(sales_tbl.stor_id, sales_tbl.ord_num) where (^{sales_tbl.}^.stor_id = ^{stores_tbl.}^.stor_id) as virtrdf:stores_has_sales .

	syb:titleauthor_iri (titleauthor_tbl.au_id, titleauthor_tbl.title_id) a syb:titleauthor as virtrdf:titleauthor_pk;
	syb:au_id titleauthor_tbl.au_id as virtrdf:titleauthor_au_id;
	syb:title_id titleauthor_tbl.title_id as virtrdf:titleauthor_title_id;
	syb:au_ord titleauthor_tbl.au_ord as virtrdf:titleauthor_au_ord;
	syb:royaltyper titleauthor_tbl.royaltyper as virtrdf:titleauthor_royaltyper;
	syb:has_author syb:authors_iri(authors_tbl.au_id) where (^{authors_tbl.}^.au_id = ^{titleauthor_tbl.}^.au_id) as virtrdf:titleauthor_has_author;
	syb:has_titles syb:titles_iri(titles_tbl.title_id, titles_tbl.pub_id) where (^{titles_tbl.}^.title_id = ^{titleauthor_tbl.}^.title_id) as virtrdf:titleauthor_has_titles .

	syb:titles_iri (titles_tbl.title_id, titles_tbl.pub_id) a syb:titles as virtrdf:titles_pk;
	syb:title_id titles_tbl.title_id as virtrdf:titles_title_idd;
	syb:title titles_tbl.title as virtrdf:titles_title;
	syb:type titles_tbl.type as virtrdf:titles_type;
	syb:pub_id titles_tbl.pub_id as virtrdf:titles_pub_id;
	syb:price titles_tbl.price as virtrdf:titles_price;
	syb:advance titles_tbl.advance as virtrdf:titles_advance;
	syb:total_sales titles_tbl.total_sales as virtrdf:titles_total_sales;
	syb:notes titles_tbl.notes as virtrdf:titles_notes;
	syb:pubdate titles_tbl.pubdate as virtrdf:titles_pubdate;
	syb:contract titles_tbl.contract as virtrdf:titles_contract;
       	syb:has_titleauthor syb:titleauthor_iri(titleauthor_tbl.au_id, titleauthor_tbl.title_id) where (^{titleauthor_tbl.}^.title_id = ^{titles_tbl.}^.title_id) as virtrdf:titles_has_titleauthor;
       	syb:has_salesdetail syb:salesdetail_iri (salesdetail_tbl.stor_id, salesdetail_tbl.ord_num, salesdetail_tbl.title_id) where (^{salesdetail_tbl.}^.title_id = ^{titles_tbl.}^.title_id) as virtrdf:titles_has_salesdetail .

  } .
} .
;

delete from db.dba.url_rewrite_rule_list where urrl_list like 'sybasepubs2_rule%';
delete from db.dba.url_rewrite_rule where urr_rule like 'sybasepubs2_rule%';

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


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

DB.DBA.URLREWRITE_CREATE_RULELIST (
    'sybasepubs2_rule_list1',
    1,
    vector (
  	 	'sybasepubs2_rule1',
  	 	'sybasepubs2_rule2'
	  ));

-- ensure a VD for the IRIs which begins with /
VHOST_REMOVE (lpath=>'/sybasepubs2');

VHOST_DEFINE (
	lpath=>'/sybasepubs2',
	ppath=>'/DAV/sybasepubs2/',
    	is_dav=>1,
	vsp_user=>'dba',
	is_brws=>0,
	opts=>vector ('url_rewrite', 'sybasepubs2_rule_list1')
	);

delete from db.dba.url_rewrite_rule_list where urrl_list like 'sybase_schemas_rule%';
delete from db.dba.url_rewrite_rule where urr_rule like 'sybase_schemas_rule%';

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

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

DB.DBA.URLREWRITE_CREATE_RULELIST (
    'sybase_schemas_rule_list1',
    1,
    vector (
  	 	'sybase_schemas_rule1',
  	 	'sybase_schemas_rule2'
	  ));

-- ensure a VD for the IRIs which begins with /
VHOST_REMOVE (lpath=>'/schema/sybasepubs2');

VHOST_DEFINE (
	lpath=>'/schemas/sybasepubs2',
	ppath=>'/DAV/schemas/sybasepubs2/',
    	is_dav=>1,
	vsp_user=>'dba',
	is_brws=>0,
	opts=>vector ('url_rewrite', 'sybase_schemas_rule_list1')
	);

DB.DBA.XML_SET_NS_DECL ('hr', 'http://^{URIQADefaultHost}^/schemas/sybasepubs2', 2);

15.8.15.9. Progress (SQL-89) using demonstratino 'iSports' database

ATTACH TABLE  "ISPORTS_RDF"."Customer" PRIMARY KEY ("Cust-Num")
AS "isports_rdf"."pro91_isports_rdf"."Customer"
FROM 'pro91_isports_rdf';

ATTACH TABLE  "ISPORTS_RDF"."Invoice" PRIMARY KEY ("Invoice-Num")
AS "isports_rdf"."pro91_isports_rdf"."Invoice"
FROM 'pro91_isports_rdf';

ATTACH TABLE  "ISPORTS_RDF"."Item" PRIMARY KEY ("Item-num")
AS "isports_rdf"."pro91_isports_rdf"."Item"
FROM 'pro91_isports_rdf';

ATTACH TABLE  "ISPORTS_RDF"."Local-Default" PRIMARY KEY ("Country")
AS "isports_rdf"."pro91_isports_rdf"."Local-Default"
FROM 'pro91_isports_rdf';

ATTACH TABLE  "ISPORTS_RDF"."Order" PRIMARY KEY ("Order-num")
AS "isports_rdf"."pro91_isports_rdf"."Order"
FROM 'pro91_isports_rdf';

ATTACH TABLE  "ISPORTS_RDF"."Order-Line"  PRIMARY KEY ("Order-num", "Line-num")
AS "isports_rdf"."pro91_isports_rdf"."Order-Line"
FROM 'pro91_isports_rdf';

ATTACH TABLE  "ISPORTS_RDF"."Ref-Call" PRIMARY KEY ("Call-Num")
AS "isports_rdf"."pro91_isports_rdf"."Ref-Call"
FROM 'pro91_isports_rdf';

ATTACH TABLE  "ISPORTS_RDF"."Salesrep" PRIMARY KEY ("Sales-Rep")
AS "isports_rdf"."pro91_isports_rdf"."Salesrep"
FROM 'pro91_isports_rdf';

ATTACH TABLE  "ISPORTS_RDF"."State" PRIMARY KEY ("State")
AS "isports_rdf"."pro91_isports_rdf"."State"
FROM 'pro91_isports_rdf';

COMMIT WORK;

GRANT SELECT ON isports_rdf.pro91_isports_rdf.Customer        TO "SPARQL", "SPARQL_UPDATE";
GRANT SELECT ON isports_rdf.pro91_isports_rdf."Order"         TO "SPARQL", "SPARQL_UPDATE";
GRANT SELECT ON isports_rdf.pro91_isports_rdf.Item            TO "SPARQL", "SPARQL_UPDATE";
GRANT SELECT ON isports_rdf.pro91_isports_rdf."Order-Line"    TO "SPARQL", "SPARQL_UPDATE";
GRANT SELECT ON isports_rdf.pro91_isports_rdf.Invoice         TO "SPARQL", "SPARQL_UPDATE";
GRANT SELECT ON isports_rdf.pro91_isports_rdf."Local-Default" TO "SPARQL", "SPARQL_UPDATE";
GRANT SELECT ON isports_rdf.pro91_isports_rdf."Ref-Call"      TO "SPARQL", "SPARQL_UPDATE";
GRANT SELECT ON isports_rdf.pro91_isports_rdf.Salesrep        TO "SPARQL", "SPARQL_UPDATE";
GRANT SELECT ON isports_rdf.pro91_isports_rdf.State           TO "SPARQL", "SPARQL_UPDATE";

GRANT SPARQL_UPDATE to "SPARQL";

CREATE VIEW isports_rdf.pro91_isports_rdf.VCustomer      AS SELECT "Cust-Num" AS Cust_Num, Name, Address, Address2, City, State, Country, Phone, Contact, "Sales-Rep" AS Sales_Rep, Comments, "Credit-Limit" AS Credit_Limit, Balance, Terms, Discount, "Postal-Code" AS Postal_Code FROM "isports_rdf"."pro91_isports_rdf"."Customer";
CREATE VIEW isports_rdf.pro91_isports_rdf.VOrder         AS SELECT "Order-num" AS Order_num, "Cust-Num" AS Cust_Num, "Order-Date" AS Order_Date, "Ship-Date" AS Ship_Date, "Promise-Date" AS Promise_Date, Carrier, Instructions, PO, Terms, "Sales-Rep" AS Sales_Rep FROM isports_rdf.pro91_isports_rdf."Order";
CREATE VIEW isports_rdf.pro91_isports_rdf.VItem          AS SELECT "Item-num" AS Item_num, "Item-Name" AS Item_Name, "Cat-Page" AS Cat_Page, Price, "Cat-Description" AS Cat_Description, "On-hand" AS On_hand, Allocated, "Re-Order" AS Re_Order, "On-Order" AS On_Order FROM isports_rdf.pro91_isports_rdf.Item;
CREATE VIEW isports_rdf.pro91_isports_rdf.VOrder_Line    AS SELECT "Order-num" AS Order_num, "Line-num" AS Line_num, "Item-num" AS Item_num, Price, Qty, Discount, "Extended-Price" AS Extended_Price, Backorder FROM isports_rdf.pro91_isports_rdf."Order-Line";
CREATE VIEW isports_rdf.pro91_isports_rdf.VInvoice       AS SELECT "Invoice-Num" AS Invoice_Num, "Cust-Num" AS Cust_Num, "Invoice-Date" AS Invoice_Date, Amount, "Total-Paid" AS Total_Paid, Adjustment, "Order-Num" AS Order_Num, "Ship-Charge" AS Ship_Charge FROM isports_rdf.pro91_isports_rdf.Invoice;
CREATE VIEW isports_rdf.pro91_isports_rdf.VLocal_Default AS SELECT Country, "Region1-Label" AS Region1_Label, "Region2-Label" AS Region2_Label, "Postal-Label" AS Postal_Label, "Postal-Format" AS Postal_Format, "Tel-Format" AS Tel_Format, "Date-Format" AS Date_Format, "Currency-Symbol" AS Currency_Symbol FROM isports_rdf.pro91_isports_rdf."Local-Default";
CREATE VIEW isports_rdf.pro91_isports_rdf.VRef_Call      AS SELECT "Call-Num" AS Call_Num, "Cust-Num" AS Cust_Num, "Call-Date" AS Call_Date, "Sales-Rep" AS Sales_Rep, Parent, Txt FROM isports_rdf.pro91_isports_rdf."Ref-Call";
CREATE VIEW isports_rdf.pro91_isports_rdf.VSalesrep      AS SELECT "Rep-Name" AS Rep_Name, Region, "Sales-Rep" AS Sales_Rep, "Month-Quota@1" AS Month_Quota_1, "Month-Quota@2" AS Month_Quota_2, "Month-Quota@3" AS Month_Quota_3, "Month-Quota@4" AS Month_Quota_4, "Month-Quota@5" AS Month_Quota_5, "Month-Quota@6" AS Month_Quota_6, "Month-Quota@7" AS Month_Quota_7, "Month-Quota@8" AS Month_Quota_8, "Month-Quota@9" AS Month_Quota_9, "Month-Quota@10" AS Month_Quota_10, "Month-Quota@11" AS Month_Quota_11, "Month-Quota@12" AS Month_Quota_12 FROM isports_rdf.pro91_isports_rdf.Salesrep;
CREATE VIEW isports_rdf.pro91_isports_rdf.VState         AS SELECT State, "State-Name" AS State_Name, Region FROM isports_rdf.pro91_isports_rdf.State;

GRANT SELECT ON isports_rdf.pro91_isports_rdf.VCustomer      TO "SPARQL", "SPARQL_UPDATE";
GRANT SELECT ON isports_rdf.pro91_isports_rdf.VOrder         TO "SPARQL", "SPARQL_UPDATE";
GRANT SELECT ON isports_rdf.pro91_isports_rdf.VItem          TO "SPARQL", "SPARQL_UPDATE";
GRANT SELECT ON isports_rdf.pro91_isports_rdf.VOrder_Line    TO "SPARQL", "SPARQL_UPDATE";
GRANT SELECT ON isports_rdf.pro91_isports_rdf.VInvoice       TO "SPARQL", "SPARQL_UPDATE";
GRANT SELECT ON isports_rdf.pro91_isports_rdf.VLocal_Default TO "SPARQL", "SPARQL_UPDATE";
GRANT SELECT ON isports_rdf.pro91_isports_rdf.VRef_Call      TO "SPARQL", "SPARQL_UPDATE";
GRANT SELECT ON isports_rdf.pro91_isports_rdf.VSalesrep      TO "SPARQL", "SPARQL_UPDATE";
GRANT SELECT ON isports_rdf.pro91_isports_rdf.VState         TO "SPARQL", "SPARQL_UPDATE";


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

ttlp (
'
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .

@prefix customer:     <http://localhost:8890/schemas/progress/isports/customer/> .
@prefix order:        <http://localhost:8890/schemas/progress/isports/order/> .
@prefix item:         <http://localhost:8890/schemas/progress/isports/item/> .
@prefix orderline:    <http://localhost:8890/schemas/progress/isports/order_line/> .
@prefix invoice:      <http://localhost:8890/schemas/progress/isports/invoice/> .
@prefix localdefault: <http://localhost:8890/schemas/progress/isports/local_default/> .
@prefix refcall:      <http://localhost:8890/schemas/progress/isports/ref_call/> .
@prefix salesrep:     <http://localhost:8890/schemas/progress/isports/salesrep/> .
@prefix state:        <http://localhost:8890/schemas/progress/isports/state/> .



customer:Customer a rdfs:Class ;
	rdfs:label "Customer" ;
	rdfs:comment "Progress isports Customer table" .

customer:Cust-Num a rdf:Property ;
	rdfs:domain customer:Customer ;
	rdfs:range xsd:integer ;
	rdfs:label "Cust-Num" .

customer:Name a rdf:Property ;
	rdfs:domain customer:Customer ;
	rdfs:range xsd:string ;
	rdfs:label "Name" .

customer:Address a rdf:Property ;
	rdfs:domain customer:Customer ;
	rdfs:range xsd:string ;
	rdfs:label "Address" .

customer:Address2 a rdf:Property ;
	rdfs:domain customer:Customer ;
	rdfs:range xsd:string ;
	rdfs:label "Address2" .

customer:City a rdf:Property ;
	rdfs:domain customer:Customer ;
	rdfs:range xsd:string ;
	rdfs:label "City" .

customer:State a rdf:Property ;
	rdfs:domain customer:Customer ;
	rdfs:range xsd:string ;
	rdfs:label "State" .

customer:Country a rdf:Property ;
	rdfs:domain customer:Customer ;
	rdfs:range xsd:string ;
	rdfs:label "Country" .

customer:Phone a rdf:Property ;
	rdfs:domain customer:Customer ;
	rdfs:range xsd:string ;
	rdfs:label "Phone" .

customer:Contact a rdf:Property ;
	rdfs:domain customer:Customer ;
	rdfs:range xsd:string ;
	rdfs:label "Contact" .

customer:Sales-Rep a rdf:Property ;
	rdfs:domain customer:Customer ;
	rdfs:range xsd:string ;
	rdfs:label "Sales-Rep" .

customer:Comments a rdf:Property ;
	rdfs:domain customer:Customer ;
	rdfs:range xsd:string ;
	rdfs:label "Comments" .

customer:Credit-Limit a rdf:Property ;
	rdfs:domain customer:Customer ;
	rdfs:range xsd:decimal ;
	rdfs:label "Credit-Limit" .

customer:Balance a rdf:Property ;
	rdfs:domain customer:Customer ;
	rdfs:range xsd:decimal ;
	rdfs:label "Balance" .

customer:Terms a rdf:Property ;
	rdfs:domain customer:Customer ;
	rdfs:range xsd:string ;
	rdfs:label "Terms" .

customer:Discount a rdf:Property ;
	rdfs:domain customer:Customer ;
	rdfs:range xsd:integer ;
	rdfs:label "Discount" .

customer:Postal-Code a rdf:Property ;
	rdfs:domain customer:Customer ;
	rdfs:range xsd:string ;
	rdfs:label "Postal-Code" .



order:Order a rdfs:Class ;
	rdfs:label "Order" ;
	rdfs:comment "Progress isports Order table" .

order:Order-num a rdf:Property ;
	rdfs:domain order:Order ;
	rdfs:range xsd:integer ;
	rdfs:label "Order-num" .

order:Cust-Num a rdf:Property ;
	rdfs:domain order:Order ;
	rdfs:range xsd:integer ;
	rdfs:label "Cust-Num" .

order:Order-Date a rdf:Property ;
	rdfs:domain order:Order ;
	rdfs:range xsd:date ;
	rdfs:label "Order-Date" .

order:Ship-Date a rdf:Property ;
	rdfs:domain order:Order ;
	rdfs:range xsd:date ;
	rdfs:label "Ship-Date" .

order:Promise-Date a rdf:Property ;
	rdfs:domain order:Order ;
	rdfs:range xsd:date ;
	rdfs:label "Promise-Date" .

order:Carrier a rdf:Property ;
	rdfs:domain order:Order ;
	rdfs:range xsd:string ;
	rdfs:label "Carrier" .

order:Instructions a rdf:Property ;
	rdfs:domain order:Order ;
	rdfs:range xsd:string ;
	rdfs:label "Instructions" .

order:PO a rdf:Property ;
	rdfs:domain order:Order ;
	rdfs:range xsd:string ;
	rdfs:label "PO" .

order:Terms a rdf:Property ;
	rdfs:domain order:Order ;
	rdfs:range xsd:string ;
	rdfs:label "Terms" .

order:Sales-Rep a rdf:Property ;
	rdfs:domain order:Order ;
	rdfs:range xsd:string ;
	rdfs:label "Sales-Rep" .



item:Item a rdfs:Class ;
	rdfs:label "Item" ;
	rdfs:comment "Progress isports Item table" .

item:Item-num a rdf:Property ;
	rdfs:domain item:Item ;
	rdfs:range xsd:integer ;
	rdfs:label "Item-num" .

item:Item-Name a rdf:Property ;
	rdfs:domain item:Item ;
	rdfs:range xsd:string ;
	rdfs:label "Item-Name" .

item:Cat-Page a rdf:Property ;
	rdfs:domain item:Item ;
	rdfs:range xsd:integer ;
	rdfs:label "Cat-Page" .

item:Price a rdf:Property ;
	rdfs:domain item:Item ;
	rdfs:range xsd:decimal ;
	rdfs:label "Price" .

item:Cat-Description a rdf:Property ;
	rdfs:domain item:Item ;
	rdfs:range xsd:string ;
	rdfs:label "Cat-Description" .

item:On-hand a rdf:Property ;
	rdfs:domain item:Item ;
	rdfs:range xsd:integer ;
	rdfs:label "On-hand" .

item:Allocated a rdf:Property ;
	rdfs:domain item:Item ;
	rdfs:range xsd:integer ;
	rdfs:label "Allocated" .

item:Re-Order a rdf:Property ;
	rdfs:domain item:Item ;
	rdfs:range xsd:integer ;
	rdfs:label "Re-Order" .

item:On-Order a rdf:Property ;
	rdfs:domain item:Item ;
	rdfs:range xsd:integer ;
	rdfs:label "On-Order" .



orderline:Order-Line a rdfs:Class ;
	rdfs:label "Order-Line" ;
	rdfs:comment "Progress isports Order-Line table" .

orderline:Order-num a rdf:Property ;
	rdfs:domain orderline:Order-Line ;
	rdfs:range xsd:integer ;
	rdfs:label "Order-num" .

orderline:Line-num a rdf:Property ;
	rdfs:domain orderline:Order-Line ;
	rdfs:range xsd:integer ;
	rdfs:label "Line-num" .

orderline:Item-num a rdf:Property ;
	rdfs:domain orderline:Order-Line ;
	rdfs:range xsd:integer ;
	rdfs:label "Item-num" .

orderline:Price a rdf:Property ;
	rdfs:domain orderline:Order-Line ;
	rdfs:range xsd:decimal ;
	rdfs:label "Price" .

orderline:Qty a rdf:Property ;
	rdfs:domain orderline:Order-Line ;
	rdfs:range xsd:integer ;
	rdfs:label "Qty" .

orderline:Discount a rdf:Property ;
	rdfs:domain orderline:Order-Line ;
	rdfs:range xsd:integer ;
	rdfs:label "Discount" .

orderline:Extended-Price a rdf:Property ;
	rdfs:domain orderline:Order-Line ;
	rdfs:range xsd:decimal ;
	rdfs:label "Extended-Price" .

orderline:Backorder a rdf:Property ;
	rdfs:domain orderline:Order-Line ;
	rdfs:range xsd:byte ;
	rdfs:label "Backorder" .



invoice:Invoice a rdfs:Class ;
	rdfs:label "Invoice" ;
	rdfs:comment "Progress isports Invoice table" .

invoice:Invoice-Num a rdf:Property ;
	rdfs:domain invoice:Invoice ;
	rdfs:range xsd:integer ;
	rdfs:label "Invoice-Num" .

invoice:Cust-Num a rdf:Property ;
	rdfs:domain invoice:Invoice ;
	rdfs:range xsd:integer ;
	rdfs:label "Cust-Num" .

invoice:Invoice-Date a rdf:Property ;
	rdfs:domain invoice:Invoice ;
	rdfs:range xsd:date ;
	rdfs:label "Invoice-Date" .

invoice:Amount a rdf:Property ;
	rdfs:domain invoice:Invoice ;
	rdfs:range xsd:decimal ;
	rdfs:label "Amount" .

invoice:Total-Paid a rdf:Property ;
	rdfs:domain invoice:Invoice ;
	rdfs:range xsd:decimal ;
	rdfs:label "Total-Paid" .

invoice:Adjustment a rdf:Property ;
	rdfs:domain invoice:Invoice ;
	rdfs:range xsd:decimal ;
	rdfs:label "Adjustmant" .

invoice:Order-Num a rdf:Property ;
	rdfs:domain invoice:Invoice ;
	rdfs:range xsd:integer ;
	rdfs:label "Order-Num" .

invoice:Ship-Charge a rdf:Property ;
	rdfs:domain invoice:Invoice ;
	rdfs:range xsd:decimal ;
	rdfs:label "Ship-Charge" .



localdefault:Local-Default a rdfs:Class ;
	rdfs:label "Local-Default" ;
	rdfs:comment "Progress isports Local-Default table" .

localdefault:Country a rdf:Property ;
	rdfs:domain localdefault:Local-Default ;
	rdfs:range xsd:string ;
	rdfs:label "Country" .

localdefault:Region1-Label a rdf:Property ;
	rdfs:domain localdefault:Local-Default ;
	rdfs:range xsd:string ;
	rdfs:label "Region1-Label" .

localdefault:Region2-Label a rdf:Property ;
	rdfs:domain localdefault:Local-Default ;
	rdfs:range xsd:string ;
	rdfs:label "Region2-Label" .

localdefault:Postal-Label a rdf:Property ;
	rdfs:domain localdefault:Local-Default ;
	rdfs:range xsd:string ;
	rdfs:label "Postal-Label" .

localdefault:Postal-Format a rdf:Property ;
	rdfs:domain localdefault:Local-Default ;
	rdfs:range xsd:string ;
	rdfs:label "Postal-Format" .

localdefault:Tel-Format a rdf:Property ;
	rdfs:domain localdefault:Local-Default ;
	rdfs:range xsd:string ;
	rdfs:label "Tel-Format" .

localdefault:Date-Format a rdf:Property ;
	rdfs:domain localdefault:Local-Default ;
	rdfs:range xsd:string ;
	rdfs:label "Date-Format" .

localdefault:Currency-Symbol a rdf:Property ;
	rdfs:domain localdefault:Local-Default ;
	rdfs:range xsd:string ;
	rdfs:label "Currency-Symbol" .



refcall:Ref-Call a rdfs:Class ;
	rdfs:label "Ref-Call" ;
	rdfs:comment "Progress isports Ref-Call table" .

refcall:Call-Num a rdf:Property ;
	rdfs:domain refcall:Ref-Call ;
	rdfs:range xsd:string ;
	rdfs:label "Call-Num" .

refcall:Cust-Num a rdf:Property ;
	rdfs:domain refcall:Ref-Call ;
	rdfs:range xsd:integer ;
	rdfs:label "Cust-Num" .

refcall:Call-Date a rdf:Property ;
	rdfs:domain refcall:Ref-Call ;
	rdfs:range xsd:date ;
	rdfs:label "Call-Date" .

refcall:Sales-Rep a rdf:Property ;
	rdfs:domain refcall:Ref-Call ;
	rdfs:range xsd:string ;
	rdfs:label "Sales-Rep" .

refcall:Parent a rdf:Property ;
	rdfs:domain refcall:Ref-Call ;
	rdfs:range xsd:string ;
	rdfs:label "Parent" .

refcall:Txt a rdf:Property ;
	rdfs:domain refcall:Ref-Call ;
	rdfs:range xsd:string ;
	rdfs:label "Txt" .



salesrep:Salesrep a rdfs:Class ;
	rdfs:label "Salesrep" ;
	rdfs:comment "Progress isports Salesrep table" .

salesrep:Sales-Rep a rdf:Property ;
	rdfs:domain salesrep:Salesrep ;
	rdfs:range xsd:string ;
	rdfs:label "Sales-Rep" .

salesrep:Rep-Name a rdf:Property ;
	rdfs:domain salesrep:Salesrep ;
	rdfs:range xsd:string ;
	rdfs:label "Rep-Name" .

salesrep:Region a rdf:Property ;
	rdfs:domain salesrep:Salesrep ;
	rdfs:range xsd:string ;
	rdfs:label "Region" .

salesrep:Month-Quota-1 a rdf:Property ;
	rdfs:domain salesrep:Salesrep ;
	rdfs:range xsd:string ;
	rdfs:label "Month-Quota@1" .

salesrep:Month-Quota-2 a rdf:Property ;
	rdfs:domain salesrep:Salesrep ;
	rdfs:range xsd:string ;
	rdfs:label "Month-Quota@2" .

salesrep:Month-Quota-3 a rdf:Property ;
	rdfs:domain salesrep:Salesrep ;
	rdfs:range xsd:string ;
	rdfs:label "Month-Quota@3" .

salesrep:Month-Quota-4 a rdf:Property ;
	rdfs:domain salesrep:Salesrep ;
	rdfs:range xsd:string ;
	rdfs:label "Month-Quota@4" .

salesrep:Month-Quota-5 a rdf:Property ;
	rdfs:domain salesrep:Salesrep ;
	rdfs:range xsd:string ;
	rdfs:label "Month-Quota@5" .

salesrep:Month-Quota-6 a rdf:Property ;
	rdfs:domain salesrep:Salesrep ;
	rdfs:range xsd:string ;
	rdfs:label "Month-Quota@6" .

salesrep:Month-Quota-7 a rdf:Property ;
	rdfs:domain salesrep:Salesrep ;
	rdfs:range xsd:string ;
	rdfs:label "Month-Quota@7" .

salesrep:Month-Quota-8 a rdf:Property ;
	rdfs:domain salesrep:Salesrep ;
	rdfs:range xsd:string ;
	rdfs:label "Month-Quota@8" .

salesrep:Month-Quota-9 a rdf:Property ;
	rdfs:domain salesrep:Salesrep ;
	rdfs:range xsd:string ;
	rdfs:label "Month-Quota@9" .

salesrep:Month-Quota-10 a rdf:Property ;
	rdfs:domain salesrep:Salesrep ;
	rdfs:range xsd:string ;
	rdfs:label "Month-Quota@10" .

salesrep:Month-Quota-11 a rdf:Property ;
	rdfs:domain salesrep:Salesrep ;
	rdfs:range xsd:string ;
	rdfs:label "Month-Quota@11" .

salesrep:Month-Quota-12 a rdf:Property ;
	rdfs:domain salesrep:Salesrep ;
	rdfs:range xsd:string ;
	rdfs:label "Month-Quota@12" .



state:State a rdfs:Class ;
	rdfs:label "State" ;
	rdfs:comment "Progress isports State table" .

state:State_ a rdf:Property ;
	rdfs:domain state:State ;
	rdfs:range xsd:string ;
	rdfs:label "State" .

state:State-Name a rdf:Property ;
	rdfs:domain state:State ;
	rdfs:range xsd:string ;
	rdfs:label "State-Name" .

state:Region a rdf:Property ;
	rdfs:domain state:State ;
	rdfs:range xsd:string ;
	rdfs:label "Region" .

', '', 'http://localhost:8890/schemas/progress/isports', 0);



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




sparql

prefix customer:     <http://localhost:8890/schemas/progress/isports/customer/>
prefix order:        <http://localhost:8890/schemas/progress/isports/order/>
prefix item:         <http://localhost:8890/schemas/progress/isports/item/>
prefix orderline:    <http://localhost:8890/schemas/progress/isports/order_line/>
prefix invoice:      <http://localhost:8890/schemas/progress/isports/invoice/>
prefix localdefault: <http://localhost:8890/schemas/progress/isports/local_default/>
prefix refcall:      <http://localhost:8890/schemas/progress/isports/ref_call/>
prefix salesrep:     <http://localhost:8890/schemas/progress/isports/salesrep/>
prefix state:        <http://localhost:8890/schemas/progress/isports/state/>

create iri class customer:customer_iri
	"http://localhost:8890/progress/isports/customer/%d#this"
	(in Cust_Num integer not null) .

create iri class order:order_iri
	"http://localhost:8890/progress/isports/order/%d#this"
	(in Order_Num integer not null) .

create iri class item:item_iri
	"http://localhost:8890/progress/isports/item/%d#this"
	(in Item_num integer not null) .

create iri class orderline:order-line_iri
	"http://localhost:8890/progress/isports/order-line/%d_%d#this"
	(in Order_num integer not null, in Line_num integer not null) .

create iri class invoice:invoice_iri
	"http://localhost:8890/progress/isports/invoice/%d#this"
	(in Invoice_Num integer not null) .

create iri class localdefault:local-default_iri
	"http://localhost:8890/progress/isports/local-default/%U#this"
	(in Country varchar not null) .

create iri class refcall:ref-call_iri
	"http://localhost:8890/progress/isports/ref-call/%U#this"
	(in Call_Num varchar not null) .

create iri class salesrep:salesrep_iri
	"http://localhost:8890/progress/isports/salesrep/%U#this"
	(in Sales_Rep varchar not null) .

create iri class state:state_iri
	"http://localhost:8890/progress/isports/state/%U#this"
	(in State varchar not null) .

;







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

sparql

prefix customer:     <http://localhost:8890/schemas/progress/isports/customer/>
prefix order:        <http://localhost:8890/schemas/progress/isports/order/>
prefix item:         <http://localhost:8890/schemas/progress/isports/item/>
prefix orderline:    <http://localhost:8890/schemas/progress/isports/order_line/>
prefix invoice:      <http://localhost:8890/schemas/progress/isports/invoice/>
prefix localdefault: <http://localhost:8890/schemas/progress/isports/local_default/>
prefix refcall:      <http://localhost:8890/schemas/progress/isports/ref_call/>
prefix salesrep:     <http://localhost:8890/schemas/progress/isports/salesrep/>
prefix state:        <http://localhost:8890/schemas/progress/isports/state/>

alter quad storage virtrdf:DefaultQuadStorage
  from isports_rdf.pro91_isports_rdf.VCustomer      as Customer_tbl
  from isports_rdf.pro91_isports_rdf.VOrder         as Order_tbl
  from isports_rdf.pro91_isports_rdf.VItem          as Item_tbl
  from isports_rdf.pro91_isports_rdf.VOrder_Line    as Order_Line_tbl
  from isports_rdf.pro91_isports_rdf.VInvoice       as Invoice_tbl
  from isports_rdf.pro91_isports_rdf.VRef_Call      as Ref_Call_tbl
  from isports_rdf.pro91_isports_rdf.VRef_Call      as Ref_Call_tbl_1
  from isports_rdf.pro91_isports_rdf.VLocal_Default as Local_Default_tbl
  from isports_rdf.pro91_isports_rdf.VSalesrep      as Salesrep_tbl
  from isports_rdf.pro91_isports_rdf.VState         as State_tbl
{
  create virtrdf:progress_isports as graph <http://localhost:8890/progress/isports>
  {
    customer:customer_iri (Customer_tbl.Cust_Num) a customer:Customer as virtrdf:customer_pk ;
    customer:Cust-Num     Customer_tbl.Cust_Num     as virtrdf:Customer_cust-num ;
    customer:Name         Customer_tbl.Name         as virtrdf:Customer_name ;
    customer:Address      Customer_tbl.Address      as virtrdf:Customer_address ;
    customer:Address2     Customer_tbl.Address2     as virtrdf:Customer_address2 ;
    customer:City         Customer_tbl.City         as virtrdf:Customer_city ;
    customer:State        Customer_tbl.State        as virtrdf:Customer_state ;
    customer:Country      Customer_tbl.Country      as virtrdf:Customer_country ;
    customer:Phone        Customer_tbl.Phone        as virtrdf:Customer_phone ;
    customer:Contact      Customer_tbl.Contact      as virtrdf:Customer_contact ;
    customer:Sales-Rep    Customer_tbl.Sales_Rep    as virtrdf:Customer_sales_rep ;
    customer:Comments     Customer_tbl.Comments     as virtrdf:Customer_comments ;
    customer:Credit-Limit Customer_tbl.Credit_Limit as virtrdf:Customer_credit-limit ;
    customer:Balance      Customer_tbl.Balance      as virtrdf:Customer_balance ;
    customer:Terms        Customer_tbl.Terms        as virtrdf:Customer_terms ;
    customer:Discount     Customer_tbl.Discount     as virtrdf:Customer_discount ;
    customer:Postal-Code  Customer_tbl.Postal_Code  as virtrdf:Customer_postal-code ;
    customer:from_state        state:state_iri (State_tbl.State)                           where ( ^{Customer_tbl.}^.State     = ^{State_tbl.}^.State )           as virtrdf:Customer_from_state ;
    customer:has_sales_rep     salesrep:salesrep_iri (Salesrep_tbl.Sales_Rep)              where ( ^{Customer_tbl.}^.Sales_Rep = ^{Salesrep_tbl.}^.Sales_Rep )    as virtrdf:Customer_has_sales_rep ;
    customer:has_local_default localdefault:local-default_iri (Local_Default_tbl.Country)  where ( ^{Customer_tbl.}^.Country   = ^{Local_Default_tbl.}^.Country ) as virtrdf:Customer_has_local_default ;
    customer:placed_order      order:order_iri (Order_tbl.Order_num)                       where ( ^{Customer_tbl.}^.Cust_Num  = ^{Order_tbl.}^.Cust_Num )        as virtrdf:Customer_placed_order ;
    customer:has_invoice       invoice:invoice_iri (Invoice_tbl.Invoice_Num)               where ( ^{Customer_tbl.}^.Cust_Num  = ^{Invoice_tbl.}^.Cust_Num )      as virtrdf:Customer_has_invoice ;
    customer:ref_call          refcall:ref-call_iri (Ref_Call_tbl.Call_Num)                where ( ^{Customer_tbl.}^.Cust_Num  = ^{Ref_Call_tbl.}^.Cust_Num )     as virtrdf:Customer_ref-call .

    order:order_iri (Order_tbl.Order_num) a order:Order as virtrdf:order_pk ;
    order:Order-num    Order_tbl.Order_num    as virtrdf:Order_order-num ;
    order:Cust-Num     Order_tbl.Cust_Num     as virtrdf:Order_cust_num ;
    order:Order-Date   Order_tbl.Order_Date   as virtrdf:Order_order-date ;
    order:Ship-Date    Order_tbl.Ship_Date    as virtrdf:Order_ship-date ;
    order:Promise-Date Order_tbl.Promise_Date as virtrdf:Order_promise-date ;
    order:Carrier      Order_tbl.Carrier      as virtrdf:Order_carrier ;
    order:Instructions Order_tbl.Instructions as virtrdf:Order_instructions ;
    order:PO           Order_tbl.PO           as virtrdf:Order_po ;
    order:Terms        Order_tbl.Terms        as virtrdf:Order_terms ;
    order:placed_by    customer:customer_iri (Customer_tbl.Cust_Num)                                 where ( ^{Order_tbl.}^.Cust_Num  = ^{Customer_tbl.}^.Cust_Num )    as virtrdf:Order_placed_by ;
    order:Sales-Rep    salesrep:salesrep_iri (Salesrep_tbl.Sales_Rep)                                where ( ^{Order_tbl.}^.Sales_Rep = ^{Salesrep_tbl.}^.Sales_Rep )   as virtrdf:Order_sales_rep ;
    order:invoiced_on  invoice:invoice_iri (Invoice_tbl.Invoice_Num)                                 where ( ^{Order_tbl.}^.Order_num = ^{Invoice_tbl.}^.Order_Num )    as virtrdf:Order_invoiced_on ;
    order:has_lines    orderline:order-line_iri (Order_Line_tbl.Order_num, Order_Line_tbl.Line_num)  where ( ^{Order_tbl.}^.Order_num = ^{Order_Line_tbl.}^.Order_num ) as virtrdf:Order_has_lines .

    item:item_iri (Item_tbl.Item_num) a item:Item as virtrdf:item_pk ;
    item:Item-num        Item_tbl.Item_num        as virtrdf:item_item-num ;
    item:Item-Name       Item_tbl.Item_Name       as virtrdf:Item_item-Name ;
    item:Cat-Page        Item_tbl.Cat_Page        as virtrdf:Item_cat-page ;
    item:Price           Item_tbl.Price           as virtrdf:Item_price ;
    item:Cat-Description Item_tbl.Cat_Description as virtrdf:Item_cat-description ;
    item:On-hand         Item_tbl.On_hand         as virtrdf:Item_on-hand ;
    item:Allocated       Item_tbl.Allocated       as virtrdf:Item_allocated ;
    item:Re-Order        Item_tbl.Re_Order        as virtrdf:Item_re-order ;
    item:On-Order        Item_tbl.On_Order        as virtrdf:Item_on-order ;
    item:order_line  orderline:order-line_iri (Order_Line_tbl.Order_num, Order_Line_tbl.Line_num)  where ( ^{Item_tbl.}^.Item_num  = ^{Order_Line_tbl.}^.Item_num )   as virtrdf:Item_order_line .

    orderline:order-line_iri (Order_Line_tbl.Order_num, Order_Line_tbl.Line_num) a orderline:Order-Line as virtrdf:order-line_pk ;
    orderline:Line-num       Order_Line_tbl.Line_num       as virtrdf:Order-Line_line-num ;
    orderline:Price          Order_Line_tbl.Price          as virtrdf:Order-Line_price ;
    orderline:Qty            Order_Line_tbl.Qty            as virtrdf:Order-Line_qty ;
    orderline:Discount       Order_Line_tbl.Discount       as virtrdf:Order-Line_discount ;
    orderline:Extended-Price Order_Line_tbl.Extended_Price as virtrdf:Order-Line_extended-price ;
    orderline:Backorder      Order_Line_tbl.Backorder      as virtrdf:Order-Line_backorder ;
    orderline:Order-num  order:order_iri (Order_tbl.Order_num)  where ( ^{Order_Line_tbl.}^.Order_num = ^{Order_tbl.}^.Order_num ) as virtrdf:Order_Line_order_num ;
    orderline:Item-num   item:item_iri (Item_tbl.Item_num)      where ( ^{Order_Line_tbl.}^.Item_num  = ^{Item_tbl.}^.Item_num )   as virtrdf:Order_Line_item_num .

    invoice:invoice_iri (Invoice_tbl.Invoice_Num) a invoice:Invoice as virtrdf:invoice_pk ;
    invoice:Invoice-Num  Invoice_tbl.Invoice_Num  as virtrdf:Invoice_invoice-num ;
    invoice:Cust-Num     Invoice_tbl.Cust_Num    as virtrdf:Invoice_cust_num ;
    invoice:Invoice-Date Invoice_tbl.Invoice_Date as virtrdf:Invoice_invoice-date ;
    invoice:Amount       Invoice_tbl.Amount       as virtrdf:Invoice_amount ;
    invoice:Total-Paid   Invoice_tbl.Total_Paid   as virtrdf:Invoice_total-paid ;
    invoice:Adjustment   Invoice_tbl.Adjustment   as virtrdf:Invoice_adjustment ;
    invoice:Order-Num    Invoice_tbl.Order_Num    as virtrdf:Invoice_order-num ;
    invoice:Ship-Charge  Invoice_tbl.Ship_Charge  as virtrdf:Invoice_ship-charge ;
    invoice:invoiced_to  customer:customer_iri (Customer_tbl.Cust_Num)  where ( ^{Invoice_tbl.}^.Cust_Num  = ^{Customer_tbl.}^.Cust_Num ) as virtrdf:Invoice_invoiced_to ;
    invoice:Order-Num    order:order_iri (Order_tbl.Order_num)          where ( ^{Invoice_tbl.}^.Order_Num = ^{Order_tbl.}^.Order_num )   as virtrdf:Invoice_order_num .

    localdefault:local-default_iri (Local_Default_tbl.Country) a localdefault:Local-Default as virtrdf:local-default_pk ;
    localdefault:Country         Local_Default_tbl.Country as virtrdf:local-default_country ;
    localdefault:Region1-Label   Local_Default_tbl.Region1_Label   as virtrdf:Local-Default_region1-label ;
    localdefault:Region2-Label   Local_Default_tbl.Region2_Label   as virtrdf:Local-Default_region2-label ;
    localdefault:Postal-Label    Local_Default_tbl.Postal_Label    as virtrdf:Local-Default_postal-label ;
    localdefault:Postal-Format   Local_Default_tbl.Postal_Format   as virtrdf:Local-Default_postal-format ;
    localdefault:Tel-Format      Local_Default_tbl.Tel_Format      as virtrdf:Local-Default_tel-format ;
    localdefault:Date-Format     Local_Default_tbl.Date_Format     as virtrdf:Local-Default_date-format ;
    localdefault:Currency-Symbol Local_Default_tbl.Currency_Symbol as virtrdf:Local-Default_currency-symbol ;
    localdefault:has_customer customer:customer_iri (Customer_tbl.Cust_Num) where ( ^{Local_Default_tbl.}^.Country = ^{Customer_tbl.}^.Country ) as virtrdf:Local-Default_has_customer .


    refcall:ref-call_iri (Ref_Call_tbl.Call_Num) a refcall:Ref-Call as virtrdf:ref-call_pk ;
    refcall:Call-Num   Ref_Call_tbl.Call_Num   as virtrdf:Ref-Call_call-num ;
    refcall:Cust-Num   Ref_Call_tbl.Cust_Num   as virtrdf:Ref-Call_cust-num ;
    refcall:Call-Date  Ref_Call_tbl.Call_Date  as virtrdf:Ref-Call_call-date ;
    refcall:Sales-Rep  Ref_Call_tbl.Sales_Rep  as virtrdf:Ref-sales-rep ;
    refcall:Parent     Ref_Call_tbl.Parent     as virtrdf:Ref-Call_parent ;
    refcall:Txt        Ref_Call_tbl.Txt        as virtrdf:Ref-Call_txt ;
    refcall:made_to     customer:customer_iri (Customer_tbl.Cust_Num)   where  ( ^{Ref_Call_tbl.}^.Cust_Num  = ^{Customer_tbl.}^.Cust_Num )   as virtrdf:Ref-Call_made_to ;
    refcall:made_by     salesrep:salesrep_iri (Salesrep_tbl.Sales_Rep)  where  ( ^{Ref_Call_tbl.}^.Sales_Rep = ^{Salesrep_tbl.}^.Sales_Rep )  as virtrdf:Ref-Call_made-by ;
    refcall:has_parent  refcall:ref-call_iri (Ref_Call_tbl_1.Call_Num)    where  ( ^{Ref_Call_tbl.}^.Parent    = ^{Ref_Call_tbl_1.}^.Call_Num )   as virtrdf:Ref-Call_has_parent .

    salesrep:salesrep_iri (Salesrep_tbl.Sales_Rep) a salesrep:Salesrep as virtrdf:salesrep_pk ;
    salesrep:Sales-Rep      Salesrep_tbl.Sales_Rep       as virtrdf:Salesrep_sales-rep ;
    salesrep:Region         Salesrep_tbl.Region          as virtrdf:Salesrep_region ;
    salesrep:Rep-Name       Salesrep_tbl.Rep_Name        as virtrdf:Salesrep_rep-name ;
    salesrep:Month-Quota-1  Salesrep_tbl.Month_Quota_1   as virtrdf:Salesrep_month-quota-1 ;
    salesrep:Month-Quota-2  Salesrep_tbl.Month_Quota_2   as virtrdf:Salesrep_month-quota-2 ;
    salesrep:Month-Quota-3  Salesrep_tbl.Month_Quota_3   as virtrdf:Salesrep_month-quota-3 ;
    salesrep:Month-Quota-4  Salesrep_tbl.Month_Quota_4   as virtrdf:Salesrep_month-quota-4 ;
    salesrep:Month-Quota-5  Salesrep_tbl.Month_Quota_5   as virtrdf:Salesrep_month-quota-5 ;
    salesrep:Month-Quota-6  Salesrep_tbl.Month_Quota_6   as virtrdf:Salesrep_month-quota-6 ;
    salesrep:Month-Quota-7  Salesrep_tbl.Month_Quota_7   as virtrdf:Salesrep_month-quota-7 ;
    salesrep:Month-Quota-8  Salesrep_tbl.Month_Quota_8   as virtrdf:Salesrep_month-quota-8 ;
    salesrep:Month-Quota-9  Salesrep_tbl.Month_Quota_9   as virtrdf:Salesrep_month-quota-9 ;
    salesrep:Month-Quota-10 Salesrep_tbl.Month_Quota_10  as virtrdf:Salesrep_month-quota-10 ;
    salesrep:Month-Quota-11 Salesrep_tbl.Month_Quota_11  as virtrdf:Salesrep_month-quota-11 ;
    salesrep:Month-Quota-12 Salesrep_tbl.Month_Quota_12  as virtrdf:Salesrep_month-quota-12 ;
    salesrep:is_sales_rep_for customer:customer_iri (Customer_tbl.Cust_Num) where ( ^{Salesrep_tbl.}^.Sales_Rep = ^{Customer_tbl.}^.Sales_Rep ) as virtrdf:Salesrep_is_sales_rep_for ;
    salesrep:has_order        order:order_iri (Order_tbl.Order_num)         where ( ^{Salesrep_tbl.}^.Sales_Rep = ^{Order_tbl.}^.Sales_Rep )    as virtrdf:Salesrep_has_order ;
    salesrep:manages_region   state:state_iri (State_tbl.State)             where ( ^{Salesrep_tbl.}^.Region    = ^{State_tbl.}^.Region )       as virtrdf:Salesrep_manages_region ;
    salesrep:made_call        refcall:ref-call_iri (Ref_Call_tbl.Call_Num)  where ( ^{Salesrep_tbl.}^.Sales_Rep = ^{Ref_Call_tbl.}^.Sales_Rep ) as virtrdf:Ref-Call_made_call .

    state:state_iri (State_tbl.State) a state:State as virtrdf:state_pk ;
    state:State_     State_tbl.State        as virtrdf:State_state ;
    state:State-Name State_tbl.State_Name   as virtrdf:State_state-name ;
    state:Region     State_tbl.Region       as virtrdf:State_region ;
    state:has_customer   customer:customer_iri (Customer_tbl.Cust_Num)   where ( ^{State_tbl.}^.State  = ^{Customer_tbl.}^.State )  as virtrdf:State_has_customer ;
    state:has_sales_rep  salesrep:salesrep_iri (Salesrep_tbl.Sales_Rep)  where ( ^{State_tbl.}^.Region = ^{Salesrep_tbl.}^.Region ) as virtrdf:State_has_sales_rep .


  } .
} .
;

delete from db.dba.url_rewrite_rule_list where urrl_list like 'progress_isports_rule%';
delete from db.dba.url_rewrite_rule where urr_rule like 'progress_isports_rule%';

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


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

DB.DBA.URLREWRITE_CREATE_RULELIST (
    'progress_isports_rule_list1',
    1,
    vector (
  	 	'progress_isports_rule1',
  	 	'progress_isports_rule2'
	  ));

-- ensure a VD for the IRIs which begins with /
VHOST_REMOVE (lpath=>'/progress/isports');

VHOST_DEFINE (
	lpath=>'/progress/isports',
	ppath=>'/DAV/progress/isports/',
    	is_dav=>1,
	vsp_user=>'dba',
	is_brws=>0,
	opts=>vector ('url_rewrite', 'progress_isports_rule_list1')
	);

delete from db.dba.url_rewrite_rule_list where urrl_list like 'progress_isports_schemas_rule%';
delete from db.dba.url_rewrite_rule where urr_rule like 'progress_isports_schemas_rule%';

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

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

DB.DBA.URLREWRITE_CREATE_RULELIST (
    'progress_isports_schemas_rule_list1',
    1,
    vector (
  	 	'progress_isports_schemas_rule1',
  	 	'progress_isports_schemas_rule2'
	  ));

-- ensure a VD for the IRIs which begins with /
VHOST_REMOVE (lpath=>'/schemas/progress/isports');

VHOST_DEFINE (
	lpath=>'/schemas/progress/isports',
	ppath=>'/DAV/schemas/progress/isports/',
    	is_dav=>1,
	vsp_user=>'dba',
	is_brws=>0,
	opts=>vector ('url_rewrite', 'progress_isports_schemas_rule_list1')
	);

DB.DBA.XML_SET_NS_DECL ('customer',     'http://^{URIQADefaultHost}^/schemas/progress/isports/customer/', 2);
DB.DBA.XML_SET_NS_DECL ('order',        'http://^{URIQADefaultHost}^/schemas/progress/isports/order/', 2);
DB.DBA.XML_SET_NS_DECL ('item',         'http://^{URIQADefaultHost}^/schemas/progress/isports/item/', 2);
DB.DBA.XML_SET_NS_DECL ('orderline',    'http://^{URIQADefaultHost}^/schemas/progress/isports/order_line/', 2);
DB.DBA.XML_SET_NS_DECL ('invoice',      'http://^{URIQADefaultHost}^/schemas/progress/isports/invoice/', 2);
DB.DBA.XML_SET_NS_DECL ('localdefault', 'http://^{URIQADefaultHost}^/schemas/progress/isports/local_default/', 2);
DB.DBA.XML_SET_NS_DECL ('refcall',      'http://^{URIQADefaultHost}^/schemas/progress/isports/ref_call/', 2);
DB.DBA.XML_SET_NS_DECL ('salesrep',     'http://^{URIQADefaultHost}^/schemas/progress/isports/salesrep/', 2);
DB.DBA.XML_SET_NS_DECL ('state',        'http://^{URIQADefaultHost}^/schemas/progress/isports/state/', 2);

15.8.15.10. Progress (SQL-92) using demonstratino 'iSports' database

ATTACH TABLE  "PUB"."Customer"      PRIMARY KEY ("Cust-Num")              AS "isports_rdf"."prs10_isports_rdf"."Customer"      FROM 'prs10_isports_rdf';
ATTACH TABLE  "PUB"."Invoice"       PRIMARY KEY ("Invoice-Num")           AS "isports_rdf"."prs10_isports_rdf"."Invoice"       FROM 'prs10_isports_rdf';
ATTACH TABLE  "PUB"."Item"          PRIMARY KEY ("Item-num")              AS "isports_rdf"."prs10_isports_rdf"."Item"          FROM 'prs10_isports_rdf';
ATTACH TABLE  "PUB"."Local-Default" PRIMARY KEY ("Country")               AS "isports_rdf"."prs10_isports_rdf"."Local-Default" FROM 'prs10_isports_rdf';
ATTACH TABLE  "PUB"."Order"         PRIMARY KEY ("Order-num")             AS "isports_rdf"."prs10_isports_rdf"."Order"         FROM 'prs10_isports_rdf';
ATTACH TABLE  "PUB"."Order-Line"    PRIMARY KEY ("Order-num", "Line-num") AS "isports_rdf"."prs10_isports_rdf"."Order-Line"    FROM 'prs10_isports_rdf';
ATTACH TABLE  "PUB"."Ref-Call"      PRIMARY KEY ("Call-Num")              AS "isports_rdf"."prs10_isports_rdf"."Ref-Call"      FROM 'prs10_isports_rdf';
ATTACH TABLE  "PUB"."Salesrep"      PRIMARY KEY ("Sales-Rep")             AS "isports_rdf"."prs10_isports_rdf"."Salesrep"      FROM 'prs10_isports_rdf';
ATTACH TABLE  "PUB"."State"         PRIMARY KEY ("State")                 AS "isports_rdf"."prs10_isports_rdf"."State"         FROM 'prs10_isports_rdf';

COMMIT WORK;

GRANT SELECT ON isports_rdf.prs10_isports_rdf.Customer        TO "SPARQL", "SPARQL_UPDATE";
GRANT SELECT ON isports_rdf.prs10_isports_rdf."Order"         TO "SPARQL", "SPARQL_UPDATE";
GRANT SELECT ON isports_rdf.prs10_isports_rdf.Item            TO "SPARQL", "SPARQL_UPDATE";
GRANT SELECT ON isports_rdf.prs10_isports_rdf."Order-Line"    TO "SPARQL", "SPARQL_UPDATE";
GRANT SELECT ON isports_rdf.prs10_isports_rdf.Invoice         TO "SPARQL", "SPARQL_UPDATE";
GRANT SELECT ON isports_rdf.prs10_isports_rdf."Local-Default" TO "SPARQL", "SPARQL_UPDATE";
GRANT SELECT ON isports_rdf.prs10_isports_rdf."Ref-Call"      TO "SPARQL", "SPARQL_UPDATE";
GRANT SELECT ON isports_rdf.prs10_isports_rdf.Salesrep        TO "SPARQL", "SPARQL_UPDATE";
GRANT SELECT ON isports_rdf.prs10_isports_rdf.State           TO "SPARQL", "SPARQL_UPDATE";

GRANT SPARQL_UPDATE to "SPARQL";


CREATE VIEW isports_rdf.prs10_isports_rdf.VCustomer      AS SELECT "Cust-Num" AS Cust_Num, Name, Address, Address2, City, State, Country, Phone, Contact, "Sales-Rep" AS Sales_Rep, Comments, "Credit-Limit" AS Credit_Limit, Balance, Terms, Discount, "Postal-Code" AS Postal_Code FROM isports_rdf.prs10_isports_rdf.Customer;
CREATE VIEW isports_rdf.prs10_isports_rdf.VOrder         AS SELECT "Order-num" AS Order_num, "Cust-Num" AS Cust_Num, "Order-Date" AS Order_Date, "Ship-Date" AS Ship_Date, "Promise-Date" AS Promise_Date, Carrier, Instructions, PO, Terms, "Sales-Rep" AS Sales_Rep FROM isports_rdf.prs10_isports_rdf."Order";
CREATE VIEW isports_rdf.prs10_isports_rdf.VItem          AS SELECT "Item-num" AS Item_num, "Item-Name" AS Item_Name, "Cat-Page" AS Cat_Page, Price, "Cat-Description" AS Cat_Description, "On-hand" AS On_hand, Allocated, "Re-Order" AS Re_Order, "On-Order" AS On_Order FROM isports_rdf.prs10_isports_rdf.Item;
CREATE VIEW isports_rdf.prs10_isports_rdf.VOrder_Line    AS SELECT "Order-num" AS Order_num, "Line-num" AS Line_num, "Item-num" AS Item_num, Price, Qty, Discount, "Extended-Price" AS Extended_Price, Backorder FROM isports_rdf.prs10_isports_rdf."Order-Line";
CREATE VIEW isports_rdf.prs10_isports_rdf.VInvoice       AS SELECT "Invoice-Num" AS Invoice_Num, "Cust-Num" AS Cust_Num, "Invoice-Date" AS Invoice_Date, Amount, "Total-Paid" AS Total_Paid, Adjustment, "Order-Num" AS Order_Num, "Ship-Charge" AS Ship_Charge FROM isports_rdf.prs10_isports_rdf.Invoice;
CREATE VIEW isports_rdf.prs10_isports_rdf.VLocal_Default AS SELECT Country, "Region1-Label" AS Region1_Label, "Region2-Label" AS Region2_Label, "Postal-Label" AS Postal_Label, "Postal-Format" AS Postal_Format, "Tel-Format" AS Tel_Format, "Date-Format" AS Date_Format, "Currency-Symbol" AS Currency_Symbol FROM isports_rdf.prs10_isports_rdf."Local-Default";
CREATE VIEW isports_rdf.prs10_isports_rdf.VRef_Call      AS SELECT "Call-Num" AS Call_Num, "Cust-Num" AS Cust_Num, "Call-Date" AS Call_Date, "Sales-Rep" AS Sales_Rep, Parent, Txt FROM isports_rdf.prs10_isports_rdf."Ref-Call";
CREATE VIEW isports_rdf.prs10_isports_rdf.VSalesrep      AS SELECT "Rep-Name" AS Rep_Name, Region, "Sales-Rep" AS Sales_Rep, "Month-Quota" AS Month_Quota FROM isports_rdf.prs10_isports_rdf.Salesrep;
CREATE VIEW isports_rdf.prs10_isports_rdf.VState         AS SELECT State, "State-Name" AS State_Name, Region FROM isports_rdf.prs10_isports_rdf.State;


GRANT SELECT ON isports_rdf.prs10_isports_rdf.VCustomer      TO "SPARQL", "SPARQL_UPDATE";
GRANT SELECT ON isports_rdf.prs10_isports_rdf.VOrder         TO "SPARQL", "SPARQL_UPDATE";
GRANT SELECT ON isports_rdf.prs10_isports_rdf.VItem          TO "SPARQL", "SPARQL_UPDATE";
GRANT SELECT ON isports_rdf.prs10_isports_rdf.VOrder_Line    TO "SPARQL", "SPARQL_UPDATE";
GRANT SELECT ON isports_rdf.prs10_isports_rdf.VInvoice       TO "SPARQL", "SPARQL_UPDATE";
GRANT SELECT ON isports_rdf.prs10_isports_rdf.VLocal_Default TO "SPARQL", "SPARQL_UPDATE";
GRANT SELECT ON isports_rdf.prs10_isports_rdf.VRef_Call      TO "SPARQL", "SPARQL_UPDATE";
GRANT SELECT ON isports_rdf.prs10_isports_rdf.VSalesrep      TO "SPARQL", "SPARQL_UPDATE";
GRANT SELECT ON isports_rdf.prs10_isports_rdf.VState         TO "SPARQL", "SPARQL_UPDATE";


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

ttlp (
'
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .

@prefix customer:     <http://localhost:8890/schemas/progress/isports/customer/> .
@prefix order:        <http://localhost:8890/schemas/progress/isports/order/> .
@prefix item:         <http://localhost:8890/schemas/progress/isports/item/> .
@prefix orderline:    <http://localhost:8890/schemas/progress/isports/order_line/> .
@prefix invoice:      <http://localhost:8890/schemas/progress/isports/invoice/> .
@prefix localdefault: <http://localhost:8890/schemas/progress/isports/local_default/> .
@prefix refcall:      <http://localhost:8890/schemas/progress/isports/ref_call/> .
@prefix salesrep:     <http://localhost:8890/schemas/progress/isports/salesrep/> .
@prefix state:        <http://localhost:8890/schemas/progress/isports/state/> .



customer:Customer a rdfs:Class ;
	rdfs:label "Customer" ;
	rdfs:comment "Progress isports Customer table" .

customer:Cust-Num a rdf:Property ;
	rdfs:domain customer:Customer ;
	rdfs:range xsd:integer ;
	rdfs:label "Cust-Num" .

customer:Name a rdf:Property ;
	rdfs:domain customer:Customer ;
	rdfs:range xsd:string ;
	rdfs:label "Name" .

customer:Address a rdf:Property ;
	rdfs:domain customer:Customer ;
	rdfs:range xsd:string ;
	rdfs:label "Address" .

customer:Address2 a rdf:Property ;
	rdfs:domain customer:Customer ;
	rdfs:range xsd:string ;
	rdfs:label "Address2" .

customer:City a rdf:Property ;
	rdfs:domain customer:Customer ;
	rdfs:range xsd:string ;
	rdfs:label "City" .

customer:State a rdf:Property ;
	rdfs:domain customer:Customer ;
	rdfs:range xsd:string ;
	rdfs:label "State" .

customer:Country a rdf:Property ;
	rdfs:domain customer:Customer ;
	rdfs:range xsd:string ;
	rdfs:label "Country" .

customer:Phone a rdf:Property ;
	rdfs:domain customer:Customer ;
	rdfs:range xsd:string ;
	rdfs:label "Phone" .

customer:Contact a rdf:Property ;
	rdfs:domain customer:Customer ;
	rdfs:range xsd:string ;
	rdfs:label "Contact" .

customer:Sales-Rep a rdf:Property ;
	rdfs:domain customer:Customer ;
	rdfs:range xsd:string ;
	rdfs:label "Sales-Rep" .

customer:Comments a rdf:Property ;
	rdfs:domain customer:Customer ;
	rdfs:range xsd:string ;
	rdfs:label "Comments" .

customer:Credit-Limit a rdf:Property ;
	rdfs:domain customer:Customer ;
	rdfs:range xsd:decimal ;
	rdfs:label "Credit-Limit" .

customer:Balance a rdf:Property ;
	rdfs:domain customer:Customer ;
	rdfs:range xsd:decimal ;
	rdfs:label "Balance" .

customer:Terms a rdf:Property ;
	rdfs:domain customer:Customer ;
	rdfs:range xsd:string ;
	rdfs:label "Terms" .

customer:Discount a rdf:Property ;
	rdfs:domain customer:Customer ;
	rdfs:range xsd:integer ;
	rdfs:label "Discount" .

customer:Postal-Code a rdf:Property ;
	rdfs:domain customer:Customer ;
	rdfs:range xsd:string ;
	rdfs:label "Postal-Code" .



order:Order a rdfs:Class ;
	rdfs:label "Order" ;
	rdfs:comment "Progress isports Order table" .

order:Order-num a rdf:Property ;
	rdfs:domain order:Order ;
	rdfs:range xsd:integer ;
	rdfs:label "Order-num" .

order:Cust-Num a rdf:Property ;
	rdfs:domain order:Order ;
	rdfs:range xsd:integer ;
	rdfs:label "Cust-Num" .

order:Order-Date a rdf:Property ;
	rdfs:domain order:Order ;
	rdfs:range xsd:date ;
	rdfs:label "Order-Date" .

order:Ship-Date a rdf:Property ;
	rdfs:domain order:Order ;
	rdfs:range xsd:date ;
	rdfs:label "Ship-Date" .

order:Promise-Date a rdf:Property ;
	rdfs:domain order:Order ;
	rdfs:range xsd:date ;
	rdfs:label "Promise-Date" .

order:Carrier a rdf:Property ;
	rdfs:domain order:Order ;
	rdfs:range xsd:string ;
	rdfs:label "Carrier" .

order:Instructions a rdf:Property ;
	rdfs:domain order:Order ;
	rdfs:range xsd:string ;
	rdfs:label "Instructions" .

order:PO a rdf:Property ;
	rdfs:domain order:Order ;
	rdfs:range xsd:string ;
	rdfs:label "PO" .

order:Terms a rdf:Property ;
	rdfs:domain order:Order ;
	rdfs:range xsd:string ;
	rdfs:label "Terms" .

order:Sales-Rep a rdf:Property ;
	rdfs:domain order:Order ;
	rdfs:range xsd:string ;
	rdfs:label "Sales-Rep" .



item:Item a rdfs:Class ;
	rdfs:label "Item" ;
	rdfs:comment "Progress isports Item table" .

item:Item-num a rdf:Property ;
	rdfs:domain item:Item ;
	rdfs:range xsd:integer ;
	rdfs:label "Item-num" .

item:Item-Name a rdf:Property ;
	rdfs:domain item:Item ;
	rdfs:range xsd:string ;
	rdfs:label "Item-Name" .

item:Cat-Page a rdf:Property ;
	rdfs:domain item:Item ;
	rdfs:range xsd:integer ;
	rdfs:label "Cat-Page" .

item:Price a rdf:Property ;
	rdfs:domain item:Item ;
	rdfs:range xsd:decimal ;
	rdfs:label "Price" .

item:Cat-Description a rdf:Property ;
	rdfs:domain item:Item ;
	rdfs:range xsd:string ;
	rdfs:label "Cat-Description" .

item:On-hand a rdf:Property ;
	rdfs:domain item:Item ;
	rdfs:range xsd:integer ;
	rdfs:label "On-hand" .

item:Allocated a rdf:Property ;
	rdfs:domain item:Item ;
	rdfs:range xsd:integer ;
	rdfs:label "Allocated" .

item:Re-Order a rdf:Property ;
	rdfs:domain item:Item ;
	rdfs:range xsd:integer ;
	rdfs:label "Re-Order" .

item:On-Order a rdf:Property ;
	rdfs:domain item:Item ;
	rdfs:range xsd:integer ;
	rdfs:label "On-Order" .



orderline:Order-Line a rdfs:Class ;
	rdfs:label "Order-Line" ;
	rdfs:comment "Progress isports Order-Line table" .

orderline:Order-num a rdf:Property ;
	rdfs:domain orderline:Order-Line ;
	rdfs:range xsd:integer ;
	rdfs:label "Order-num" .

orderline:Line-num a rdf:Property ;
	rdfs:domain orderline:Order-Line ;
	rdfs:range xsd:integer ;
	rdfs:label "Line-num" .

orderline:Item-num a rdf:Property ;
	rdfs:domain orderline:Order-Line ;
	rdfs:range xsd:integer ;
	rdfs:label "Item-num" .

orderline:Price a rdf:Property ;
	rdfs:domain orderline:Order-Line ;
	rdfs:range xsd:decimal ;
	rdfs:label "Price" .

orderline:Qty a rdf:Property ;
	rdfs:domain orderline:Order-Line ;
	rdfs:range xsd:integer ;
	rdfs:label "Qty" .

orderline:Discount a rdf:Property ;
	rdfs:domain orderline:Order-Line ;
	rdfs:range xsd:integer ;
	rdfs:label "Discount" .

orderline:Extended-Price a rdf:Property ;
	rdfs:domain orderline:Order-Line ;
	rdfs:range xsd:decimal ;
	rdfs:label "Extended-Price" .

orderline:Backorder a rdf:Property ;
	rdfs:domain orderline:Order-Line ;
	rdfs:range xsd:byte ;
	rdfs:label "Backorder" .



invoice:Invoice a rdfs:Class ;
	rdfs:label "Invoice" ;
	rdfs:comment "Progress isports Invoice table" .

invoice:Invoice-Num a rdf:Property ;
	rdfs:domain invoice:Invoice ;
	rdfs:range xsd:integer ;
	rdfs:label "Invoice-Num" .

invoice:Cust-Num a rdf:Property ;
	rdfs:domain invoice:Invoice ;
	rdfs:range xsd:integer ;
	rdfs:label "Cust-Num" .

invoice:Invoice-Date a rdf:Property ;
	rdfs:domain invoice:Invoice ;
	rdfs:range xsd:date ;
	rdfs:label "Invoice-Date" .

invoice:Amount a rdf:Property ;
	rdfs:domain invoice:Invoice ;
	rdfs:range xsd:decimal ;
	rdfs:label "Amount" .

invoice:Total-Paid a rdf:Property ;
	rdfs:domain invoice:Invoice ;
	rdfs:range xsd:decimal ;
	rdfs:label "Total-Paid" .

invoice:Adjustment a rdf:Property ;
	rdfs:domain invoice:Invoice ;
	rdfs:range xsd:decimal ;
	rdfs:label "Adjustmant" .

invoice:Order-Num a rdf:Property ;
	rdfs:domain invoice:Invoice ;
	rdfs:range xsd:integer ;
	rdfs:label "Order-Num" .

invoice:Ship-Charge a rdf:Property ;
	rdfs:domain invoice:Invoice ;
	rdfs:range xsd:decimal ;
	rdfs:label "Ship-Charge" .



localdefault:Local-Default a rdfs:Class ;
	rdfs:label "Local-Default" ;
	rdfs:comment "Progress isports Local-Default table" .

localdefault:Country a rdf:Property ;
	rdfs:domain localdefault:Local-Default ;
	rdfs:range xsd:string ;
	rdfs:label "Country" .

localdefault:Region1-Label a rdf:Property ;
	rdfs:domain localdefault:Local-Default ;
	rdfs:range xsd:string ;
	rdfs:label "Region1-Label" .

localdefault:Region2-Label a rdf:Property ;
	rdfs:domain localdefault:Local-Default ;
	rdfs:range xsd:string ;
	rdfs:label "Region2-Label" .

localdefault:Postal-Label a rdf:Property ;
	rdfs:domain localdefault:Local-Default ;
	rdfs:range xsd:string ;
	rdfs:label "Postal-Label" .

localdefault:Postal-Format a rdf:Property ;
	rdfs:domain localdefault:Local-Default ;
	rdfs:range xsd:string ;
	rdfs:label "Postal-Format" .

localdefault:Tel-Format a rdf:Property ;
	rdfs:domain localdefault:Local-Default ;
	rdfs:range xsd:string ;
	rdfs:label "Tel-Format" .

localdefault:Date-Format a rdf:Property ;
	rdfs:domain localdefault:Local-Default ;
	rdfs:range xsd:string ;
	rdfs:label "Date-Format" .

localdefault:Currency-Symbol a rdf:Property ;
	rdfs:domain localdefault:Local-Default ;
	rdfs:range xsd:string ;
	rdfs:label "Currency-Symbol" .



refcall:Ref-Call a rdfs:Class ;
	rdfs:label "Ref-Call" ;
	rdfs:comment "Progress isports Ref-Call table" .

refcall:Call-Num a rdf:Property ;
	rdfs:domain refcall:Ref-Call ;
	rdfs:range xsd:string ;
	rdfs:label "Call-Num" .

refcall:Cust-Num a rdf:Property ;
	rdfs:domain refcall:Ref-Call ;
	rdfs:range xsd:integer ;
	rdfs:label "Cust-Num" .

refcall:Call-Date a rdf:Property ;
	rdfs:domain refcall:Ref-Call ;
	rdfs:range xsd:date ;
	rdfs:label "Call-Date" .

refcall:Sales-Rep a rdf:Property ;
	rdfs:domain refcall:Ref-Call ;
	rdfs:range xsd:string ;
	rdfs:label "Sales-Rep" .

refcall:Parent a rdf:Property ;
	rdfs:domain refcall:Ref-Call ;
	rdfs:range xsd:string ;
	rdfs:label "Parent" .

refcall:Txt a rdf:Property ;
	rdfs:domain refcall:Ref-Call ;
	rdfs:range xsd:string ;
	rdfs:label "Txt" .



salesrep:Salesrep a rdfs:Class ;
	rdfs:label "Salesrep" ;
	rdfs:comment "Progress isports Salesrep table" .

salesrep:Sales-Rep a rdf:Property ;
	rdfs:domain salesrep:Salesrep ;
	rdfs:range xsd:string ;
	rdfs:label "Sales-Rep" .

salesrep:Rep-Name a rdf:Property ;
	rdfs:domain salesrep:Salesrep ;
	rdfs:range xsd:string ;
	rdfs:label "Rep-Name" .

salesrep:Region a rdf:Property ;
	rdfs:domain salesrep:Salesrep ;
	rdfs:range xsd:string ;
	rdfs:label "Region" .

salesrep:Month-Quota a rdf:Property ;
	rdfs:domain salesrep:Salesrep ;
	rdfs:range xsd:string ;
	rdfs:label "Month-Quota" .



state:State a rdfs:Class ;
	rdfs:label "State" ;
	rdfs:comment "Progress isports State table" .

state:State_ a rdf:Property ;
	rdfs:domain state:State ;
	rdfs:range xsd:string ;
	rdfs:label "State" .

state:State-Name a rdf:Property ;
	rdfs:domain state:State ;
	rdfs:range xsd:string ;
	rdfs:label "State-Name" .

state:Region a rdf:Property ;
	rdfs:domain state:State ;
	rdfs:range xsd:string ;
	rdfs:label "Region" .

', '', 'http://localhost:8890/schemas/progress/isports', 0);



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




sparql

prefix customer:     <http://localhost:8890/schemas/progress/isports/customer/>
prefix order:        <http://localhost:8890/schemas/progress/isports/order/>
prefix item:         <http://localhost:8890/schemas/progress/isports/item/>
prefix orderline:    <http://localhost:8890/schemas/progress/isports/order_line/>
prefix invoice:      <http://localhost:8890/schemas/progress/isports/invoice/>
prefix localdefault: <http://localhost:8890/schemas/progress/isports/local_default/>
prefix refcall:      <http://localhost:8890/schemas/progress/isports/ref_call/>
prefix salesrep:     <http://localhost:8890/schemas/progress/isports/salesrep/>
prefix state:        <http://localhost:8890/schemas/progress/isports/state/>

create iri class customer:customer_iri
	"http://localhost:8890/progress/isports/customer/%d#this"
	(in Cust_Num integer not null) .

create iri class order:order_iri
	"http://localhost:8890/progress/isports/order/%d#this"
	(in Order_Num integer not null) .

create iri class item:item_iri
	"http://localhost:8890/progress/isports/item/%d#this"
	(in Item_num integer not null) .

create iri class orderline:order-line_iri
	"http://localhost:8890/progress/isports/order-line/%d_%d#this"
	(in Order_num integer not null, in Line_num integer not null) .

create iri class invoice:invoice_iri
	"http://localhost:8890/progress/isports/invoice/%d#this"
	(in Invoice_Num integer not null) .

create iri class localdefault:local-default_iri
	"http://localhost:8890/progress/isports/local-default/%U#this"
	(in Country varchar not null) .

create iri class refcall:ref-call_iri
	"http://localhost:8890/progress/isports/ref-call/%U#this"
	(in Call_Num varchar not null) .

create iri class salesrep:salesrep_iri
	"http://localhost:8890/progress/isports/salesrep/%U#this"
	(in Sales_Rep varchar not null) .

create iri class state:state_iri
	"http://localhost:8890/progress/isports/state/%U#this"
	(in State varchar not null) .

;







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

sparql

prefix customer:     <http://localhost:8890/schemas/progress/isports/customer/>
prefix order:        <http://localhost:8890/schemas/progress/isports/order/>
prefix item:         <http://localhost:8890/schemas/progress/isports/item/>
prefix orderline:    <http://localhost:8890/schemas/progress/isports/order_line/>
prefix invoice:      <http://localhost:8890/schemas/progress/isports/invoice/>
prefix localdefault: <http://localhost:8890/schemas/progress/isports/local_default/>
prefix refcall:      <http://localhost:8890/schemas/progress/isports/ref_call/>
prefix salesrep:     <http://localhost:8890/schemas/progress/isports/salesrep/>
prefix state:        <http://localhost:8890/schemas/progress/isports/state/>

alter quad storage virtrdf:DefaultQuadStorage
  from isports_rdf.prs10_isports_rdf.VCustomer      as Customer_tbl
  from isports_rdf.prs10_isports_rdf.VOrder         as Order_tbl
  from isports_rdf.prs10_isports_rdf.VItem          as Item_tbl
  from isports_rdf.prs10_isports_rdf.VOrder_Line    as Order_Line_tbl
  from isports_rdf.prs10_isports_rdf.VInvoice       as Invoice_tbl
  from isports_rdf.prs10_isports_rdf.VRef_Call      as Ref_Call_tbl
  from isports_rdf.prs10_isports_rdf.VRef_Call      as Ref_Call_tbl_1  -- Additional Ref_Call_tbl_1 alias required to represent recursive FK relationship (refcall:has_parent) below.
  from isports_rdf.prs10_isports_rdf.VLocal_Default as Local_Default_tbl
  from isports_rdf.prs10_isports_rdf.VSalesrep      as Salesrep_tbl
  from isports_rdf.prs10_isports_rdf.VState         as State_tbl
{
  create virtrdf:progress_isports as graph <http://localhost:8890/progress/isports>
  {
    customer:customer_iri (Customer_tbl.Cust_Num) a customer:Customer as virtrdf:customer_pk ;
    customer:Cust-Num     Customer_tbl.Cust_Num     as virtrdf:Customer_cust-num ;
    customer:Name         Customer_tbl.Name         as virtrdf:Customer_name ;
    customer:Address      Customer_tbl.Address      as virtrdf:Customer_address ;
    customer:Address2     Customer_tbl.Address2     as virtrdf:Customer_address2 ;
    customer:City         Customer_tbl.City         as virtrdf:Customer_city ;
    customer:State        Customer_tbl.State        as virtrdf:Customer_state ;
    customer:Country      Customer_tbl.Country      as virtrdf:Customer_country ;
    customer:Phone        Customer_tbl.Phone        as virtrdf:Customer_phone ;
    customer:Contact      Customer_tbl.Contact      as virtrdf:Customer_contact ;
    customer:Sales-Rep    Customer_tbl.Sales_Rep    as virtrdf:Customer_sales_rep ;
    customer:Comments     Customer_tbl.Comments     as virtrdf:Customer_comments ;
    customer:Credit-Limit Customer_tbl.Credit_Limit as virtrdf:Customer_credit-limit ;
    customer:Balance      Customer_tbl.Balance      as virtrdf:Customer_balance ;
    customer:Terms        Customer_tbl.Terms        as virtrdf:Customer_terms ;
    customer:Discount     Customer_tbl.Discount     as virtrdf:Customer_discount ;
    customer:Postal-Code  Customer_tbl.Postal_Code  as virtrdf:Customer_postal-code ;
    customer:from_state        state:state_iri (State_tbl.State)                           where ( ^{Customer_tbl.}^.State     = ^{State_tbl.}^.State )           as virtrdf:Customer_from_state ;
    customer:has_sales_rep     salesrep:salesrep_iri (Salesrep_tbl.Sales_Rep)              where ( ^{Customer_tbl.}^.Sales_Rep = ^{Salesrep_tbl.}^.Sales_Rep )    as virtrdf:Customer_has_sales_rep ;
    customer:has_local_default localdefault:local-default_iri (Local_Default_tbl.Country)  where ( ^{Customer_tbl.}^.Country   = ^{Local_Default_tbl.}^.Country ) as virtrdf:Customer_has_local_default ;
    customer:placed_order      order:order_iri (Order_tbl.Order_num)                       where ( ^{Customer_tbl.}^.Cust_Num  = ^{Order_tbl.}^.Cust_Num )        as virtrdf:Customer_placed_order ;
    customer:has_invoice       invoice:invoice_iri (Invoice_tbl.Invoice_Num)               where ( ^{Customer_tbl.}^.Cust_Num  = ^{Invoice_tbl.}^.Cust_Num )      as virtrdf:Customer_has_invoice ;
    customer:ref_call          refcall:ref-call_iri (Ref_Call_tbl.Call_Num)                where ( ^{Customer_tbl.}^.Cust_Num  = ^{Ref_Call_tbl.}^.Cust_Num )     as virtrdf:Customer_ref-call .

    order:order_iri (Order_tbl.Order_num) a order:Order as virtrdf:order_pk ;
    order:Order-num    Order_tbl.Order_num    as virtrdf:Order_order-num ;
    order:Cust-Num     Order_tbl.Cust_Num     as virtrdf:Order_cust_num ;
    order:Order-Date   Order_tbl.Order_Date   as virtrdf:Order_order-date ;
    order:Ship-Date    Order_tbl.Ship_Date    as virtrdf:Order_ship-date ;
    order:Promise-Date Order_tbl.Promise_Date as virtrdf:Order_promise-date ;
    order:Carrier      Order_tbl.Carrier      as virtrdf:Order_carrier ;
    order:Instructions Order_tbl.Instructions as virtrdf:Order_instructions ;
    order:PO           Order_tbl.PO           as virtrdf:Order_po ;
    order:Terms        Order_tbl.Terms        as virtrdf:Order_terms ;
    order:placed_by    customer:customer_iri (Customer_tbl.Cust_Num)                                 where ( ^{Order_tbl.}^.Cust_Num  = ^{Customer_tbl.}^.Cust_Num )    as virtrdf:Order_placed_by ;
    order:Sales-Rep    salesrep:salesrep_iri (Salesrep_tbl.Sales_Rep)                                where ( ^{Order_tbl.}^.Sales_Rep = ^{Salesrep_tbl.}^.Sales_Rep )   as virtrdf:Order_sales_rep ;
    order:invoiced_on  invoice:invoice_iri (Invoice_tbl.Invoice_Num)                                 where ( ^{Order_tbl.}^.Order_num = ^{Invoice_tbl.}^.Order_Num )    as virtrdf:Order_invoiced_on ;
    order:has_lines    orderline:order-line_iri (Order_Line_tbl.Order_num, Order_Line_tbl.Line_num)  where ( ^{Order_tbl.}^.Order_num = ^{Order_Line_tbl.}^.Order_num ) as virtrdf:Order_has_lines .

    item:item_iri (Item_tbl.Item_num) a item:Item as virtrdf:item_pk ;
    item:Item-num        Item_tbl.Item_num        as virtrdf:item_item-num ;
    item:Item-Name       Item_tbl.Item_Name       as virtrdf:Item_item-Name ;
    item:Cat-Page        Item_tbl.Cat_Page        as virtrdf:Item_cat-page ;
    item:Price           Item_tbl.Price           as virtrdf:Item_price ;
    item:Cat-Description Item_tbl.Cat_Description as virtrdf:Item_cat-description ;
    item:On-hand         Item_tbl.On_hand         as virtrdf:Item_on-hand ;
    item:Allocated       Item_tbl.Allocated       as virtrdf:Item_allocated ;
    item:Re-Order        Item_tbl.Re_Order        as virtrdf:Item_re-order ;
    item:On-Order        Item_tbl.On_Order        as virtrdf:Item_on-order ;
    item:order_line  orderline:order-line_iri (Order_Line_tbl.Order_num, Order_Line_tbl.Line_num)  where ( ^{Item_tbl.}^.Item_num  = ^{Order_Line_tbl.}^.Item_num )   as virtrdf:Item_order_line .

    orderline:order-line_iri (Order_Line_tbl.Order_num, Order_Line_tbl.Line_num) a orderline:Order-Line as virtrdf:order-line_pk ;
    orderline:Line-num       Order_Line_tbl.Line_num       as virtrdf:Order-Line_line-num ;
    orderline:Price          Order_Line_tbl.Price          as virtrdf:Order-Line_price ;
    orderline:Qty            Order_Line_tbl.Qty            as virtrdf:Order-Line_qty ;
    orderline:Discount       Order_Line_tbl.Discount       as virtrdf:Order-Line_discount ;
    orderline:Extended-Price Order_Line_tbl.Extended_Price as virtrdf:Order-Line_extended-price ;
    orderline:Backorder      Order_Line_tbl.Backorder      as virtrdf:Order-Line_backorder ;
    orderline:Order-num  order:order_iri (Order_tbl.Order_num)  where ( ^{Order_Line_tbl.}^.Order_num = ^{Order_tbl.}^.Order_num ) as virtrdf:Order_Line_order_num ;
    orderline:Item-num   item:item_iri (Item_tbl.Item_num)      where ( ^{Order_Line_tbl.}^.Item_num  = ^{Item_tbl.}^.Item_num )   as virtrdf:Order_Line_item_num .

    invoice:invoice_iri (Invoice_tbl.Invoice_Num) a invoice:Invoice as virtrdf:invoice_pk ;
    invoice:Invoice-Num  Invoice_tbl.Invoice_Num  as virtrdf:Invoice_invoice-num ;
    invoice:Cust-Num     Invoice_tbl.Cust_Num    as virtrdf:Invoice_cust_num ;
    invoice:Invoice-Date Invoice_tbl.Invoice_Date as virtrdf:Invoice_invoice-date ;
    invoice:Amount       Invoice_tbl.Amount       as virtrdf:Invoice_amount ;
    invoice:Total-Paid   Invoice_tbl.Total_Paid   as virtrdf:Invoice_total-paid ;
    invoice:Adjustment   Invoice_tbl.Adjustment   as virtrdf:Invoice_adjustment ;
    invoice:Order-Num    Invoice_tbl.Order_Num    as virtrdf:Invoice_order-num ;
    invoice:Ship-Charge  Invoice_tbl.Ship_Charge  as virtrdf:Invoice_ship-charge ;
    invoice:invoiced_to  customer:customer_iri (Customer_tbl.Cust_Num)  where ( ^{Invoice_tbl.}^.Cust_Num  = ^{Customer_tbl.}^.Cust_Num ) as virtrdf:Invoice_invoiced_to ;
    invoice:Order-Num    order:order_iri (Order_tbl.Order_num)          where ( ^{Invoice_tbl.}^.Order_Num = ^{Order_tbl.}^.Order_num )   as virtrdf:Invoice_order_num .

    localdefault:local-default_iri (Local_Default_tbl.Country) a localdefault:Local-Default as virtrdf:local-default_pk ;
    localdefault:Country         Local_Default_tbl.Country as virtrdf:local-default_country ;
    localdefault:Region1-Label   Local_Default_tbl.Region1_Label   as virtrdf:Local-Default_region1-label ;
    localdefault:Region2-Label   Local_Default_tbl.Region2_Label   as virtrdf:Local-Default_region2-label ;
    localdefault:Postal-Label    Local_Default_tbl.Postal_Label    as virtrdf:Local-Default_postal-label ;
    localdefault:Postal-Format   Local_Default_tbl.Postal_Format   as virtrdf:Local-Default_postal-format ;
    localdefault:Tel-Format      Local_Default_tbl.Tel_Format      as virtrdf:Local-Default_tel-format ;
    localdefault:Date-Format     Local_Default_tbl.Date_Format     as virtrdf:Local-Default_date-format ;
    localdefault:Currency-Symbol Local_Default_tbl.Currency_Symbol as virtrdf:Local-Default_currency-symbol ;
    localdefault:has_customer customer:customer_iri (Customer_tbl.Cust_Num) where ( ^{Local_Default_tbl.}^.Country = ^{Customer_tbl.}^.Country ) as virtrdf:Local-Default_has_customer .

    refcall:ref-call_iri (Ref_Call_tbl.Call_Num) a refcall:Ref-Call as virtrdf:ref-call_pk ;
    refcall:Call-Num   Ref_Call_tbl.Call_Num   as virtrdf:Ref-Call_call-num ;
    refcall:Cust-Num   Ref_Call_tbl.Cust_Num   as virtrdf:Ref-Call_cust-num ;
    refcall:Call-Date  Ref_Call_tbl.Call_Date  as virtrdf:Ref-Call_call-date ;
    refcall:Sales-Rep  Ref_Call_tbl.Sales_Rep  as virtrdf:Ref-sales-rep ;
    refcall:Parent     Ref_Call_tbl.Parent     as virtrdf:Ref-Call_parent ;
    refcall:Txt        Ref_Call_tbl.Txt        as virtrdf:Ref-Call_txt ;
    refcall:made_to     customer:customer_iri (Customer_tbl.Cust_Num)   where  ( ^{Ref_Call_tbl.}^.Cust_Num  = ^{Customer_tbl.}^.Cust_Num )    as virtrdf:Ref-Call_made_to ;
    refcall:made_by     salesrep:salesrep_iri (Salesrep_tbl.Sales_Rep)  where  ( ^{Ref_Call_tbl.}^.Sales_Rep = ^{Salesrep_tbl.}^.Sales_Rep )   as virtrdf:Ref-Call_made-by ;
    refcall:has_parent  refcall:ref-call_iri (Ref_Call_tbl_1.Call_Num)  where  ( ^{Ref_Call_tbl.}^.Parent    = ^{Ref_Call_tbl_1.}^.Call_Num )  as virtrdf:Ref-Call_has_parent .

    salesrep:salesrep_iri (Salesrep_tbl.Sales_Rep) a salesrep:Salesrep as virtrdf:salesrep_pk ;
    salesrep:Sales-Rep   Salesrep_tbl.Sales_Rep   as virtrdf:Salesrep_sales-rep ;
    salesrep:Region      Salesrep_tbl.Region      as virtrdf:Salesrep_region ;
    salesrep:Rep-Name    Salesrep_tbl.Rep_Name    as virtrdf:Salesrep_rep-name ;
    salesrep:Month-Quota Salesrep_tbl.Month_Quota as virtrdf:Salesrep_month-quota ;
    salesrep:is_sales_rep_for customer:customer_iri (Customer_tbl.Cust_Num) where ( ^{Salesrep_tbl.}^.Sales_Rep = ^{Customer_tbl.}^.Sales_Rep ) as virtrdf:Salesrep_is_sales_rep_for ;
    salesrep:has_order        order:order_iri (Order_tbl.Order_num)         where ( ^{Salesrep_tbl.}^.Sales_Rep = ^{Order_tbl.}^.Sales_Rep )    as virtrdf:Salesrep_has_order ;
    salesrep:manages_region   state:state_iri (State_tbl.State)             where ( ^{Salesrep_tbl.}^.Region    = ^{State_tbl.}^.Region )       as virtrdf:Salesrep_manages_region ;
    salesrep:made_call        refcall:ref-call_iri (Ref_Call_tbl.Call_Num)  where ( ^{Salesrep_tbl.}^.Sales_Rep = ^{Ref_Call_tbl.}^.Sales_Rep ) as virtrdf:Ref-Call_made_call .

    state:state_iri (State_tbl.State) a state:State as virtrdf:state_pk ;
    state:State_     State_tbl.State        as virtrdf:State_state ;
    state:State-Name State_tbl.State_Name   as virtrdf:State_state-name ;
    state:Region     State_tbl.Region       as virtrdf:State_region ;
    state:has_customer   customer:customer_iri (Customer_tbl.Cust_Num)   where ( ^{State_tbl.}^.State  = ^{Customer_tbl.}^.State )  as virtrdf:State_has_customer ;
    state:has_sales_rep  salesrep:salesrep_iri (Salesrep_tbl.Sales_Rep)  where ( ^{State_tbl.}^.Region = ^{Salesrep_tbl.}^.Region ) as virtrdf:State_has_sales_rep .


  } .
} .
;


-- Setup re-write rules that enable de-referencing of RDF based descriptions of
-- iSports Entities

-- Cleanup old rules

delete from db.dba.url_rewrite_rule_list where urrl_list like 'progress_isports_rule%';
delete from db.dba.url_rewrite_rule where urr_rule like 'progress_isports_rule%';

-- Create rules for handling HTML representation of Entity (resource) description requests

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

-- Create rules for handling RDF based representations (N3 or RDF/XML) of Entity (resource) descriptions

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

DB.DBA.URLREWRITE_CREATE_RULELIST (
    'progress_isports_rule_list1',
    1,
    vector (
  	 	'progress_isports_rule1',
  	 	'progress_isports_rule2'
	  ));

-- Setup OWL ontology data space that describes iSports entities

-- Create Virtual Directory access point

VHOST_REMOVE (lpath=>'/progress/isports');

VHOST_DEFINE (
	lpath=>'/progress/isports',
	ppath=>'/DAV/progress/isports/',
    	is_dav=>1,
	vsp_user=>'dba',
	is_brws=>0,
	opts=>vector ('url_rewrite', 'progress_isports_rule_list1')
	);

delete from db.dba.url_rewrite_rule_list where urrl_list like 'progress_isports_schemas_rule%';
delete from db.dba.url_rewrite_rule where urr_rule like 'progress_isports_schemas_rule%';

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

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

DB.DBA.URLREWRITE_CREATE_RULELIST (
    'progress_isports_schemas_rule_list1',
    1,
    vector (
  	 	'progress_isports_schemas_rule1',
  	 	'progress_isports_schemas_rule2'
	  ));

-- ensure a VD for the IRIs which begins with /
VHOST_REMOVE (lpath=>'/schemas/progress/isports');

VHOST_DEFINE (
	lpath=>'/schemas/progress/isports',
	ppath=>'/DAV/schemas/progress/isports/',
    	is_dav=>1,
	vsp_user=>'dba',
	is_brws=>0,
	opts=>vector ('url_rewrite', 'progress_isports_schemas_rule_list1')
	);

DB.DBA.XML_SET_NS_DECL ('customer',     'http://^{URIQADefaultHost}^/schemas/progress/isports/customer/', 2);
DB.DBA.XML_SET_NS_DECL ('order',        'http://^{URIQADefaultHost}^/schemas/progress/isports/order/', 2);
DB.DBA.XML_SET_NS_DECL ('item',         'http://^{URIQADefaultHost}^/schemas/progress/isports/item/', 2);
DB.DBA.XML_SET_NS_DECL ('orderline',    'http://^{URIQADefaultHost}^/schemas/progress/isports/order_line/', 2);
DB.DBA.XML_SET_NS_DECL ('invoice',      'http://^{URIQADefaultHost}^/schemas/progress/isports/invoice/', 2);
DB.DBA.XML_SET_NS_DECL ('localdefault', 'http://^{URIQADefaultHost}^/schemas/progress/isports/local_default/', 2);
DB.DBA.XML_SET_NS_DECL ('refcall',      'http://^{URIQADefaultHost}^/schemas/progress/isports/ref_call/', 2);
DB.DBA.XML_SET_NS_DECL ('salesrep',     'http://^{URIQADefaultHost}^/schemas/progress/isports/salesrep/', 2);
DB.DBA.XML_SET_NS_DECL ('state',        'http://^{URIQADefaultHost}^/schemas/progress/isports/state/', 2);

15.8.15.11. BSBM to RDF

use DB;

CREATE TABLE DB.DBA.ProductFeature (
  nr integer primary key,
  label varchar(100) not null,
  comment varchar(1500) not null,
  publisher integer not null,
  publishDate date not null
)
;

grant select on DB.DBA.ProductFeature to public
;

CREATE TABLE DB.DBA.ProductType (
  nr integer primary key,
  label varchar(100) not null,
  comment varchar(1500) not null,
  parent integer,
  publisher integer not null,
  publishDate date not null
)
;

grant select on DB.DBA.ProductType to public
;

CREATE TABLE DB.DBA.Producer (
  nr integer primary key,
  label varchar(100) not null,
  comment varchar(1500) not null,
  homepage varchar(100) not null,
  country char(2) not null,
  publisher integer not null,
  publishDate date not null
)
;

grant select on DB.DBA.Producer to public
;
create index producer_homepage on DB.DBA.Producer (homepage)
;

CREATE TABLE DB.DBA.Product (
  nr integer primary key,
  label varchar(100) not null,
  comment varchar not null,
  producer integer not null,
  propertyNum1 integer,
  propertyNum2 integer,
  propertyNum3 integer,
  propertyNum4 integer,
  propertyNum5 integer,
  propertyNum6 integer,
  propertyTex1 varchar(200),
  propertyTex2 varchar(200),
  propertyTex3 varchar(200),
  propertyTex4 varchar(200),
  propertyTex5 varchar(200),
  propertyTex6 varchar(200),
  publisher integer not null,
  publishDate date not null
)
;

grant select on DB.DBA.Product to public
;

create index product_lbl on DB.DBA.Product (label)
;
create unique index product_producer_nr on DB.DBA.Product (producer, nr)
;
create index product_pn1 on DB.DBA.Product (propertyNum1)
;
create index product_pn2 on DB.DBA.Product (propertyNum2)
;
create index product_pn3 on DB.DBA.Product (propertyNum3)
;

create text index on DB.DBA.Product (label) with key nr
;

CREATE TABLE DB.DBA.ProductTypeProduct (
  product integer not null,
  productType integer not null,
  PRIMARY KEY (product, productType)
)
;

grant select on DB.DBA.ProductTypeProduct to public
;

create index ptype_inv on DB.DBA.ProductTypeProduct (productType, product)
;

CREATE TABLE DB.DBA.ProductFeatureProduct (
  product integer not null,
  productFeature integer not null,
  PRIMARY KEY (product, productFeature)
)
;

grant select on DB.DBA.ProductFeatureProduct to public
;

create index pfeature_inv on DB.DBA.ProductFeatureProduct (productFeature, product)
;

CREATE TABLE DB.DBA.Vendor (
  nr integer primary key,
  label varchar(100) not null,
  comment varchar not null,
  homepage varchar(100) not null,
  country char(2) not null,
  publisher integer not null,
  publishDate date not null
)
;

grant select on DB.DBA.Vendor to public
;

create index vendor_country on DB.DBA.Vendor (country)
;
create index vendor_homepage on DB.DBA.Vendor (homepage)
;

CREATE TABLE DB.DBA.Offer (
  nr integer primary key,
  product integer not null,
  producer integer,
  vendor integer not null,
  price double precision not null,
  validFrom date not null,
  validTo date not null,
  deliveryDays integer not null,
  offerWebpage varchar(100) not null,
  publisher integer not null,
  publishDate date not null
)
;

grant select on DB.DBA.Offer to public
;

create index offer_product on DB.DBA.Offer (product, deliveryDays)
;
create unique index offer_producer_product on DB.DBA.Offer (producer, product, nr)
;
create index offer_validto on DB.DBA.Offer (validTo)
;
create index offer_vendor_product on DB.DBA.Offer (vendor, product)
;
create index offer_webpage on DB.DBA.Offer (offerWebpage)
;

CREATE TABLE DB.DBA.Person (
  nr integer primary key,
  name varchar(30) not null,
  mbox_sha1sum char(40) not null,
  country char(2) not null,
  publisher integer not null,
  publishDate date not null
)
;

grant select on DB.DBA.Person to public
;

CREATE TABLE DB.DBA.Review (
  nr integer primary key,
  product integer not null,
  producer integer,
  person integer not null,
  reviewDate date not null,
  title varchar(200) not null,
  text long varchar not null,
  textlang char(2) not null,
  rating1 integer,
  rating2 integer,
  rating3 integer,
  rating4 integer,
  publisher integer not null,
  publishDate date not null
)
;

grant select on DB.DBA.Review to public
;

create unique index review_product on DB.DBA.Review (product, producer, nr)
;

create unique index review_producer_product on DB.DBA.Review (producer, product, nr)
;

create bitmap index review_textlang on DB.DBA.Review (textlang)
;

DB.DBA.XML_SET_NS_DECL ('foaf', 'http://xmlns.com/foaf/0.1/', 2)
;
DB.DBA.XML_SET_NS_DECL ('dc', 'http://purl.org/dc/elements/1.1/', 2)
;
DB.DBA.XML_SET_NS_DECL ('xsd', 'http://www.w3.org/2001/XMLSchema-datatypes/', 2)
;
DB.DBA.XML_SET_NS_DECL ('rev', 'http://purl.org/stuff/rev#', 2)
;
DB.DBA.XML_SET_NS_DECL ('bsbm', 'http://www4.wiwiss.fu-berlin.de/bizer/bsbm/v01/vocabulary/', 2)
;
DB.DBA.XML_SET_NS_DECL ('bsbm-inst', 'http://www4.wiwiss.fu-berlin.de/bizer/bsbm/v01/instances/', 2)
;

sparql drop quad map bsbm:SingleGraphView
;

sparql create iri class bsbm:ProductFeature-iri "http://www4.wiwiss.fu-berlin.de/bizer/bsbm/v01/instances/ProductFeature%d" (in nr integer not null)
;

sparql create iri class bsbm:ProductType-iri "http://www4.wiwiss.fu-berlin.de/bizer/bsbm/v01/instances/ProductType%d" (in nr integer not null)
;

sparql create iri class bsbm:Producer-iri "http://www4.wiwiss.fu-berlin.de/bizer/bsbm/v01/instances/dataFromProducer%d/Producer%d" (in nr_ integer not null, in nr integer not null)
;

sparql create iri class bsbm:Product-iri "http://www4.wiwiss.fu-berlin.de/bizer/bsbm/v01/instances/dataFromProducer%d/Product%d" (in producer integer not null, in nr integer not null)
;

sparql create iri class bsbm:Vendor-iri "http://www4.wiwiss.fu-berlin.de/bizer/bsbm/v01/instances/dataFromVendor%d/Vendor%d" (in nr_ integer not null, in nr integer not null)
;

sparql create iri class bsbm:Offer-iri "http://www4.wiwiss.fu-berlin.de/bizer/bsbm/v01/instances/dataFromVendor%d/Offer%d" (in vendor integer not null, in nr integer not null)
;

sparql create iri class bsbm:StdInst-iri "http://www4.wiwiss.fu-berlin.de/bizer/bsbm/v01/instances/StandardizationInstitution%d" (in publisher integer not null)
;

sparql create iri class bsbm:Person-iri "http://www4.wiwiss.fu-berlin.de/bizer/bsbm/v01/instances/dataFromRatingSite%d/Person%d" (in publisher integer not null, in nr integer not null)
;

sparql create iri class bsbm:Review-iri "http://www4.wiwiss.fu-berlin.de/bizer/bsbm/v01/instances/dataFromRatingSite%d/Review%d" (in site integer, in nr integer not null)
;

sparql create iri class bsbm:ISO3166-country-iri "http://downlode.org/rdf/iso-3166/countries#%s" (in code varchar not null)
;

sparql create iri class bsbm:homepage-iri "%s" (in homepage varchar not null) option (returns "http://%s")
;

sparql create iri class bsbm:RatingSite-iri "http://www4.wiwiss.fu-berlin.de/bizer/bsbm/v01/instances/dataFromRatingSite%d/RatingSite%d" (in nr_ integer not null, in nr integer not null)
;

sparql
alter quad storage virtrdf:DefaultQuadStorage
from DB.DBA.ProductFeature as pfeature
from DB.DBA.ProductType as ptype
from DB.DBA.Producer as producer
from DB.DBA.Product as product text literal product.label
from DB.DBA.ProductTypeProduct as ptypeproduct
from DB.DBA.ProductFeatureProduct as pfeatureproduct
from DB.DBA.Vendor as vendor
from DB.DBA.Offer as offer
from DB.DBA.Person as person
from DB.DBA.Review as review
where (^{product.}^.nr = ^{ptypeproduct.}^.product)
where (^{product.}^.nr = ^{pfeatureproduct.}^.product)
  {
    create bsbm:SingleGraphView as graph <BSBM> option (exclusive)
      {
	bsbm:Product-iri (product.producer, product.nr)
          a bsbm:Product ;
	  rdfs:label product.label ;
          rdfs:comment product.comment ;
          bsbm:producer bsbm:Producer-iri (product.producer, product.producer) ;
          bsbm:productPropertyTextual1 product.propertyTex1 ;
          bsbm:productPropertyTextual2 product.propertyTex2 ;
          bsbm:productPropertyTextual3 product.propertyTex3 ;
          bsbm:productPropertyTextual4 product.propertyTex4 ;
          bsbm:productPropertyTextual5 product.propertyTex5 ;
          bsbm:productPropertyTextual6 product.propertyTex6 ;
          bsbm:productPropertyNumeric1 product.propertyNum1 ;
          bsbm:productPropertyNumeric2 product.propertyNum2 ;
          bsbm:productPropertyNumeric3 product.propertyNum3 ;
          bsbm:productPropertyNumeric4 product.propertyNum4 ;
          bsbm:productPropertyNumeric5 product.propertyNum5 ;
          bsbm:productPropertyNumeric6 product.propertyNum6 ;
          rdf:type bsbm:ProductType-iri (ptypeproduct.productType) ;
          bsbm:productFeature bsbm:ProductFeature-iri (pfeatureproduct.productFeature) ;
          dc:publisher bsbm:Producer-iri (product.publisher, product.publisher) ;
          dc:date product.publishDate .

        bsbm:ProductType-iri (ptype.nr)
          a bsbm:ProductType ;
          rdfs:label ptype.label ;
          rdfs:comment ptype.comment ;
          rdfs:subClassOf bsbm:ProductType-iri (ptype.parent) ;
          dc:publisher bsbm:StdInst-iri (ptype.publisher) ;
          dc:date ptype.publishDate .

        bsbm:ProductFeature-iri (pfeature.nr)
          a bsbm:ProductFeature ;
          rdfs:label pfeature.label ;
          rdfs:comment pfeature.comment ;
          dc:publisher bsbm:StdInst-iri (pfeature.publisher) ;
          dc:date pfeature.publishDate .

        bsbm:Producer-iri (producer.nr, producer.nr)
          a bsbm:Producer ;
          rdfs:label producer.label ;
          rdfs:comment producer.comment ;
          foaf:homepage bsbm:homepage-iri (producer.homepage) ;
          bsbm:country bsbm:ISO3166-country-iri (producer.country) ;
          dc:publisher bsbm:Producer-iri (producer.nr, producer.nr) ;
          dc:date producer.publishDate .

        bsbm:Vendor-iri (vendor.nr, vendor.nr)
          a bsbm:Vendor ;
          rdfs:label vendor.label ;
          rdfs:comment vendor.comment ;
          foaf:homepage bsbm:homepage-iri (vendor.homepage) ;
          bsbm:country bsbm:ISO3166-country-iri (vendor.country) ;
          dc:publisher bsbm:Vendor-iri (vendor.publisher, vendor.publisher) ;
          dc:date vendor.publishDate .

        bsbm:Offer-iri (offer.vendor, offer.nr)
          a bsbm:Offer ;
          bsbm:product bsbm:Product-iri (offer.producer, offer.product) ;
          bsbm:vendor bsbm:Vendor-iri (offer.vendor, offer.vendor) ;
          bsbm:vendor bsbm:Vendor-iri (offer.vendor, offer.vendor) ;
          bsbm:price offer.price ;
          bsbm:validFrom offer.validFrom ;
          bsbm:validTo offer.validTo ;
          bsbm:deliveryDays offer.deliveryDays ;
          bsbm:offerWebpage bsbm:homepage-iri (offer.offerWebpage) ;
          dc:publisher bsbm:Vendor-iri (offer.publisher, offer.publisher) ;
          dc:date offer.publishDate .

        bsbm:Person-iri (person.publisher, person.nr)
          a foaf:Person ;
          foaf:name person.name ;
          foaf:mbox_sha1sum person.mbox_sha1sum ;
          bsbm:country bsbm:ISO3166-country-iri (person.country) ;
          dc:publisher bsbm:RatingSite-iri (person.publisher, person.publisher) ;
          dc:date person.publishDate .

        bsbm:Review-iri (review.publisher, review.nr)
          a rev:Review ;
          bsbm:reviewFor bsbm:Product-iri (review.producer, review.product) ;
          bsbm:producer bsbm:Producer-iri (review.producer, review.producer) ;
          rev:reviewer bsbm:Person-iri (review.publisher, review.person) ;
          bsbm:reviewDate review.reviewDate ;
          dc:title review.title ;
          rev:text review.text lang review.textlang ;
          bsbm:rating1 review.rating1 ;
          bsbm:rating2 review.rating2 ;
          bsbm:rating3 review.rating3 ;
          bsbm:rating4 review.rating4 ;
          dc:publisher bsbm:RatingSite-iri (review.publisher, review.publisher) ;
          dc:date review.publishDate .
      }
  }
;


15.8.16. Business Intelligence

15.8.16.1. TPCH to RDF

use DB;

GRANT SELECT ON TPCH.DBA.PARTSUPP  TO "SPARQL";
GRANT SELECT ON TPCH.DBA.SUPPLIER  TO "SPARQL";
GRANT SELECT ON TPCH.DBA.CUSTOMER  TO "SPARQL";
GRANT SELECT ON TPCH.DBA.HISTORY   TO "SPARQL";
GRANT SELECT ON TPCH.DBA.PART      TO "SPARQL";
GRANT SELECT ON TPCH.DBA.LINEITEM  TO "SPARQL";
GRANT SELECT ON TPCH.DBA.ORDERS    TO "SPARQL";
GRANT SELECT ON TPCH.DBA.NATION    TO "SPARQL";
GRANT SELECT ON TPCH.DBA.REGION    TO "SPARQL";

SPARQL
drop quad map virtrdf:TPCH
;

SPARQL
prefix tpch: <http://www.openlinksw.com/schemas/tpch#>
prefix oplsioc: <http://www.openlinksw.com/schemas/oplsioc#>
prefix sioc: <http://rdfs.org/sioc/ns#>
prefix foaf: <http://xmlns.com/foaf/0.1/>
create iri class tpch:customer "http://^{URIQADefaultHost}^/tpch/customer/%U%d#this" (in custname varchar, in c_custkey integer not null) option (bijection, deref) .
create iri class tpch:lineitem "http://^{URIQADefaultHost}^/tpch/lineitem/%d/%d#this" (in l_orderkey integer not null, in l_linenumber integer not null) option (bijection, deref) .
create iri class tpch:nation "http://^{URIQADefaultHost}^/tpch/nation/%U%d#this" (in name varchar, in l_nationkey integer not null) option (bijection, deref) .
create iri class tpch:order "http://^{URIQADefaultHost}^/tpch/order/%d#this" (in o_orderkey integer not null) option (bijection, deref) .
create iri class tpch:part "http://^{URIQADefaultHost}^/tpch/part/%U%d#this" (in p_partname varchar, in p_partkey integer not null) option (bijection, deref) .
create iri class tpch:partsupp "http://^{URIQADefaultHost}^/tpch/partsupp/%d/%d#this" (in ps_partkey integer not null, in ps_suppkey integer not null) option (bijection, deref) .
create iri class tpch:region "http://^{URIQADefaultHost}^/tpch/region/%U%d#this" (in name varchar, in r_regionkey integer not null) option (bijection, deref) .
create iri class tpch:supplier "http://^{URIQADefaultHost}^/tpch/supplier/%U%d#this" (in name varchar, in s_supplierkey integer not null) option (bijection, deref) .
;

SPARQL
prefix tpch: <http://www.openlinksw.com/schemas/tpch#>
prefix oplsioc: <http://www.openlinksw.com/schemas/oplsioc#>
prefix sioc: <http://rdfs.org/sioc/ns#>
prefix foaf: <http://xmlns.com/foaf/0.1/>
prefix wgs: <http://www.w3.org/2003/01/geo/wgs84_pos#>
alter quad storage virtrdf:DefaultQuadStorage
from TPCH.DBA.LINEITEM as lineitems
from TPCH.DBA.CUSTOMER as customers
from TPCH.DBA.NATION as nations
from TPCH.DBA.ORDERS as orders
from TPCH.DBA.PART as parts
from TPCH.DBA.PARTSUPP as partsupps
from TPCH.DBA.REGION as regions
from TPCH.DBA.SUPPLIER as suppliers
where (^{suppliers.}^.S_NATIONKEY = ^{nations.}^.N_NATIONKEY)
where (^{customers.}^.C_NATIONKEY = ^{nations.}^.N_NATIONKEY)
{
    create virtrdf:TPCH as graph iri ("http://^{URIQADefaultHost}^/tpch") option (exclusive)
    {
# Customers
        tpch:customer (customers.C_NAME, customers.C_CUSTKEY)
            a  tpch:customer
                as virtrdf:customer-tpch-type ;
            a  foaf:Organization
                as virtrdf:customer-foaf-type ;
            tpch:custkey customers.C_CUSTKEY
                as virtrdf:customer-c_custkey ;
            foaf:name customers.C_NAME
                as virtrdf:customer-foaf_name ;
            tpch:companyName customers.C_NAME
                as virtrdf:customer-c_name ;
            tpch:has_nation tpch:nation (nations.N_NAME, customers.C_NATIONKEY)
                as virtrdf:customer-c_nationkey ;
            tpch:address customers.C_ADDRESS
                as virtrdf:customer-c_address ;
            foaf:phone customers.C_PHONE
                as virtrdf:customer-foaf_phone ;
            tpch:phone customers.C_PHONE
                as virtrdf:customer-phone ;
            tpch:acctbal customers.C_ACCTBAL
                as virtrdf:customer-acctbal ;
            tpch:mktsegment customers.C_MKTSEGMENT
                as virtrdf:customer-c_mktsegment ;
            tpch:comment customers.C_COMMENT
                as virtrdf:customer-c_comment .

# Nations
        tpch:nation (nations.N_NAME, customers.C_NATIONKEY)
            tpch:nation_of tpch:customer (customers.C_NAME, customers.C_CUSTKEY)
            as virtrdf:customer-nation_of .

        tpch:lineitem (lineitems.L_ORDERKEY, lineitems.L_LINENUMBER)
            a tpch:lineitem
                as virtrdf:lineitem-lineitems ;
            tpch:has_order tpch:order (lineitems.L_ORDERKEY)
                as virtrdf:lineitem-l_orderkey ;
            tpch:has_part tpch:part (parts.P_NAME, lineitems.L_PARTKEY)
                where (^{parts.}^.P_PARTKEY = ^{lineitems.}^.L_PARTKEY)
                as virtrdf:lineitem-l_partkey ;
            tpch:has_supplier tpch:supplier (suppliers.S_NAME, lineitems.L_SUPPKEY)
                where (^{suppliers.}^.S_SUPPKEY = ^{lineitems.}^.L_SUPPKEY)
                as virtrdf:lineitem-l_suppkey ;
            tpch:linenumber lineitems.L_LINENUMBER
                as virtrdf:lineitem-l_linenumber ;
            tpch:linequantity lineitems.L_QUANTITY
                as virtrdf:lineitem-l_linequantity ;
            tpch:lineextendedprice lineitems.L_EXTENDEDPRICE
                as virtrdf:lineitem-l_lineextendedprice ;
            tpch:linediscount lineitems.L_DISCOUNT
                as virtrdf:lineitem-l_linediscount ;
            tpch:linetax lineitems.L_TAX
                as virtrdf:lineitem-l_linetax ;
            tpch:returnflag lineitems.L_RETURNFLAG
                as virtrdf:lineitem-l_returnflag ;
            tpch:linestatus lineitems.L_LINESTATUS
                as virtrdf:lineitem-l_linestatus ;
            tpch:shipdate lineitems.L_SHIPDATE
                as virtrdf:lineitem-l_shipdate ;
            tpch:commitdate lineitems.L_COMMITDATE
                as virtrdf:lineitem-l_commitdate ;
            tpch:receiptdate lineitems.L_RECEIPTDATE
                as virtrdf:lineitem-l_receiptdate ;
            tpch:shipinstruct lineitems.L_SHIPINSTRUCT
                as virtrdf:lineitem-l_shipinstruct ;
            tpch:shipmode lineitems.L_SHIPMODE
                as virtrdf:lineitem-l_shipmode ;
            tpch:comment lineitems.L_COMMENT
                as virtrdf:lineitem-l_comment .

        tpch:part (parts.P_NAME, lineitems.L_PARTKEY)
            tpch:part_of tpch:lineitem (lineitems.L_ORDERKEY, lineitems.L_LINENUMBER)
            where (^{parts.}^.P_PARTKEY = ^{lineitems.}^.L_PARTKEY)
            as virtrdf:lineitem-part_of .

        tpch:order (lineitems.L_ORDERKEY)
            tpch:order_of tpch:lineitem (lineitems.L_ORDERKEY, lineitems.L_LINENUMBER) as virtrdf:lineitem-order_of .

        tpch:supplier (suppliers.S_NAME, lineitems.L_SUPPKEY)
            tpch:supplier_of tpch:lineitem (lineitems.L_ORDERKEY, lineitems.L_LINENUMBER)
            where (^{suppliers.}^.S_SUPPKEY = ^{lineitems.}^.L_SUPPKEY)
            as virtrdf:lineitem-supplier_of .

# Nation
        tpch:nation (nations.N_NAME, nations.N_NATIONKEY)
            a tpch:nation
                as virtrdf:nation-nations ;
            tpch:name nations.N_NAME
                as virtrdf:nation-n_name ;
            tpch:has_region tpch:region (regions.R_NAME, nations.N_REGIONKEY)
                where (^{regions.}^.R_REGIONKEY = ^{nations.}^.N_REGIONKEY)
                as virtrdf:nation-n_regionkey ;
            tpch:comment nations.N_COMMENT
                as virtrdf:nation-n_comment .

        tpch:region (regions.R_NAME, nations.N_REGIONKEY)
            tpch:region_of tpch:nation (nations.N_NAME, nations.N_NATIONKEY)
            where (^{regions.}^.R_REGIONKEY = ^{nations.}^.N_REGIONKEY)
            as virtrdf:nation-region_of .

# Order
        tpch:order (orders.O_ORDERKEY)
            a tpch:order
                as virtrdf:order-orders ;
            tpch:orderkey orders.O_ORDERKEY
                as virtrdf:order-o_orderkey ;
            tpch:has_customer tpch:customer (customers.C_NAME, orders.O_CUSTKEY)
                where (^{orders.}^.O_CUSTKEY = ^{customers.}^.C_CUSTKEY)
                as virtrdf:order-o_custkey ;
            tpch:orderstatus orders.O_ORDERSTATUS
                as virtrdf:order-o_orderstatus ;
            tpch:ordertotalprice orders.O_TOTALPRICE
                as virtrdf:order-o_totalprice ;
            tpch:orderdate orders.O_ORDERDATE
                as virtrdf:order-o_orderdate ;
            tpch:orderpriority orders.O_ORDERPRIORITY
                as virtrdf:order-o_orderpriority ;
            tpch:clerk orders.O_CLERK
                as virtrdf:order-o_clerk ;
            tpch:shippriority orders.O_SHIPPRIORITY
                as virtrdf:order-o_shippriority ;
            tpch:comment orders.O_COMMENT
                as virtrdf:order-o_comment .

        tpch:customer (customers.C_CUSTKEY, orders.O_CUSTKEY)
            tpch:customer_of tpch:order (orders.O_ORDERKEY)
            where (^{orders.}^.O_CUSTKEY = ^{customers.}^.C_CUSTKEY)
            as virtrdf:order-customer_of .

# Part
        tpch:part (parts.P_NAME, parts.P_PARTKEY)
            a tpch:part
                as virtrdf:part-parts ;
            tpch:partkey parts.P_PARTKEY
                as virtrdf:part-p_partkey ;
            tpch:name parts.P_NAME
                as virtrdf:part-p_name ;
            tpch:mfgr parts.P_MFGR
                as virtrdf:part-p_mfgr ;
            tpch:brand parts.P_BRAND
                as virtrdf:part-p_brand ;
            tpch:type parts.P_TYPE
                as virtrdf:part-p_type ;
            tpch:size parts.P_SIZE
                as virtrdf:part-p_size ;
            tpch:container parts.P_CONTAINER
                as virtrdf:part-p_container ;
            tpch:comment parts.P_COMMENT
                as virtrdf:part-p_comment .

# Partsupp
        tpch:partsupp (partsupps.PS_PARTKEY, partsupps.PS_SUPPKEY)
            a tpch:partsupp
                as virtrdf:partsupp-partsupps ;
            tpch:has_part tpch:part (parts.P_NAME, partsupps.PS_PARTKEY)
                where (^{parts.}^.P_PARTKEY = ^{partsupps.}^.PS_PARTKEY)
                as virtrdf:partsupp-ps_partkey ;
            tpch:has_supplier tpch:supplier (suppliers.S_NAME, partsupps.PS_SUPPKEY)
                where (^{suppliers.}^.S_SUPPKEY = ^{partsupps.}^.PS_SUPPKEY)
                as virtrdf:partsupp-ps_suppkey ;
            tpch:availqty partsupps.PS_AVAILQTY
                as virtrdf:partsupp-ps_availqty ;
            tpch:supplycost partsupps.PS_SUPPLYCOST
                as virtrdf:partsupp-ps_supplycost ;
            tpch:comment partsupps.PS_COMMENT
                as virtrdf:partsupp-ps_comment .

        tpch:part (parts.P_NAME, partsupps.PS_PARTKEY)
            tpch:part_of tpch:partsupp (partsupps.PS_PARTKEY, partsupps.PS_SUPPKEY)
            where (^{parts.}^.P_PARTKEY = ^{partsupps.}^.PS_PARTKEY)
            as virtrdf:partsupp-part_of .

        tpch:supplier (suppliers.S_NAME, partsupps.PS_SUPPKEY)
            tpch:supplier_of tpch:partsupp (partsupps.PS_PARTKEY, partsupps.PS_SUPPKEY)
            where (^{suppliers.}^.S_SUPPKEY = ^{partsupps.}^.PS_SUPPKEY)
            as virtrdf:partsupp-supplier_of .

# Region
        tpch:region (regions.R_NAME, regions.R_REGIONKEY)
            a tpch:region
                as virtrdf:region-regions ;
            tpch:name regions.R_NAME
                as virtrdf:region-r_name ;
            tpch:comment regions.R_COMMENT
                as virtrdf:region-r_comment .

# Supplier
        tpch:supplier (suppliers.S_NAME, suppliers.S_SUPPKEY)
            a tpch:supplier
                as virtrdf:supplier-suppliers ;
            tpch:name suppliers.S_NAME
                as virtrdf:supplier-s_name ;
            tpch:address suppliers.S_ADDRESS
                as virtrdf:supplier-s_address ;
            tpch:has_nation tpch:nation (nations.N_NAME, suppliers.S_NATIONKEY)
                where (^{nations.}^.N_NATIONKEY = ^{suppliers.}^.S_NATIONKEY)
                as virtrdf:supplier-s_nationkey ;
            foaf:phone suppliers.S_PHONE
                as virtrdf:supplier-foaf_phone ;
            tpch:phone suppliers.S_PHONE
                as virtrdf:supplier-s_phone ;
            tpch:acctbal suppliers.S_ACCTBAL
                as virtrdf:supplier-s_acctbal ;
            tpch:comment suppliers.S_COMMENT
                as virtrdf:supplier-s_comment .

        tpch:nation (nations.N_NAME, suppliers.S_NATIONKEY)
            tpch:nation_of tpch:supplier (suppliers.S_NAME, suppliers.S_SUPPKEY)
            where (^{nations.}^.N_NATIONKEY = ^{suppliers.}^.S_NATIONKEY)
            as virtrdf:supplier-nation_of .
    } .
} .
;

delete from db.dba.url_rewrite_rule_list where urrl_list like 'tpch_rule%';
delete from db.dba.url_rewrite_rule where urr_rule like 'tpch_rule%';

DB.DBA.URLREWRITE_CREATE_REGEX_RULE (
    'tpch_rule2',
    1,
    '([^#]*)',
    vector('path'),
    1,
    '/sparql?query=CONSTRUCT+{+%%3Chttp%%3A//^{URIQADefaultHost}^%U%%23this%%3E+%%3Fp+%%3Fo+}+FROM+%%3Chttp%%3A//^{URIQADefaultHost}^/tpch%%3E+WHERE+{+%%3Chttp%%3A//^{URIQADefaultHost}^%U%%23this%%3E+%%3Fp+%%3Fo+}&format=%U',
    vector('path', 'path', '*accept*'),
    null,
    '(text/rdf.n3)|(application/rdf.xml)',
    0,
    null
    );


DB.DBA.URLREWRITE_CREATE_REGEX_RULE (
    'tpch_rule1',
    1,
    '([^#]*)',
    vector('path'),
    1,
    '/about/html/http://^{URIQADefaultHost}^%s%%23this',
    vector('path'),
    null,
    '(text/html)|(\\*/\\*)',
    0,
    303
    );

DB.DBA.URLREWRITE_CREATE_REGEX_RULE (
    'tpch_rule3',
    1,
    '(/[^#]*)/\x24',
    vector('path'),
    1,
    '%s',
    vector('path'),
    null,
    null,
    0,
    null
    );

create procedure DB.DBA.REMOVE_TPCH_RDF_DET()
{
  declare colid int;
  colid := DAV_SEARCH_ID('/DAV/home/demo/tpch', 'C');
  if (colid < 0)
    return;
  update WS.WS.SYS_DAV_COL set COL_DET=null where COL_ID = colid;
}
;

DB.DBA.REMOVE_TPCH_RDF_DET();

drop procedure DB.DBA.REMOVE_TPCH_RDF_DET;

create procedure DB.DBA.TPCH_MAKE_RDF_DET()
{
    declare uriqa_str varchar;
    uriqa_str := cfg_item_value(virtuoso_ini_path(), 'URIQA','DefaultHost');
    uriqa_str := 'http://' || uriqa_str || '/tpch';
    DB.DBA."RDFData_MAKE_DET_COL" ('/DAV/home/demo/tpch/RDFData/', uriqa_str, NULL);
    VHOST_REMOVE (lpath=>'/tpch/data/rdf');
    DB.DBA.VHOST_DEFINE (lpath=>'/tpch/data/rdf', ppath=>'/DAV/home/demo/tpch/RDFData/All/', is_dav=>1, vsp_user=>'dba');
}
;

DB.DBA.TPCH_MAKE_RDF_DET();

drop procedure DB.DBA.TPCH_MAKE_RDF_DET;

create procedure DB.DBA.TPCH_DET_REF (in par varchar, in fmt varchar, in val varchar)
{
  declare res, iri any;
  declare uriqa_str varchar;
  uriqa_str := cfg_item_value(virtuoso_ini_path(), 'URIQA','DefaultHost');
  uriqa_str := 'http://' || uriqa_str || '/tpch';
  iri := uriqa_str || val;
  res := sprintf ('iid (%d).rdf', iri_id_num (iri_to_id (iri)));
  return sprintf (fmt, res);
}
;

DB.DBA.URLREWRITE_CREATE_REGEX_RULE ('tpch_rdf', 1,
    '/tpch/(.*)', vector('path'), 1,
    '/tpch/data/rdf/%U', vector('path'),
    'DB.DBA.TPCH_DET_REF',
    'application/rdf.xml',
    2,
    303);

DB.DBA.URLREWRITE_CREATE_RULELIST (
    'tpch_rule_list1',
    1,
    vector (
                'tpch_rule1',
                'tpch_rule2',
                'tpch_rule3',
                'tpch_rdf'
          ));

DB.DBA.VHOST_REMOVE (lpath=>'/tpch');
DB.DBA.VHOST_DEFINE (lpath=>'/tpch', ppath=>'/DAV/home/demo/tpch/', vsp_user=>'dba', is_dav=>1,
          is_brws=>0, opts=>vector ('url_rewrite', 'tpch_rule_list1'));


DB.DBA.VHOST_REMOVE (lpath=>'/tpch/linkeddata');
DB.DBA.VHOST_DEFINE (lpath=>'/tpch/linkeddata', ppath=>'/DAV/home/demo/tpch/', vsp_user=>'dba', is_dav=>1,
          is_brws=>1);

15.8.16.2. TPCD to RDF

Please load ~\binsrc\dav\DET_RDFData.sql before loadding this script (tpc-d has no vad to do this automatic)

use DB;

create procedure DB.DBA.exec_no_error (in expr varchar) {
  declare state, message, meta, result any;
  exec(expr, state, message, vector(), 0, meta, result);
}
;

DB.DBA.exec_no_error('GRANT \"SPARQL_UPDATE\" TO \"SPARQL\"')
;
GRANT SELECT ON tpcd.DBA.partsupp  TO "SPARQL";
GRANT SELECT ON tpcd.DBA.supplier  TO "SPARQL";
GRANT SELECT ON tpcd.DBA.customer  TO "SPARQL";
GRANT SELECT ON tpcd.DBA.history   TO "SPARQL";
GRANT SELECT ON tpcd.DBA.part      TO "SPARQL";
GRANT SELECT ON tpcd.DBA.lineitem  TO "SPARQL";
GRANT SELECT ON tpcd.DBA.orders    TO "SPARQL";
GRANT SELECT ON tpcd.DBA.nation    TO "SPARQL";
GRANT SELECT ON tpcd.DBA.region    TO "SPARQL";

SPARQL
prefix tpcd: <http://demo.openlinksw.com/schemas/tpcd#>
prefix oplsioc: <http://www.openlinksw.com/schemas/oplsioc#>
prefix sioc: <http://rdfs.org/sioc/ns#>
prefix foaf: <http://xmlns.com/foaf/0.1/>
prefix wgs: <http://www.w3.org/2003/01/geo/wgs84_pos#>
drop quad map graph iri("http://^{URIQADefaultHost}^/tpcd") .
;

SPARQL
prefix tpcd: <http://demo.openlinksw.com/schemas/tpcd#>
prefix oplsioc: <http://www.openlinksw.com/schemas/oplsioc#>
prefix sioc: <http://rdfs.org/sioc/ns#>
prefix foaf: <http://xmlns.com/foaf/0.1/>
prefix wgs: <http://www.w3.org/2003/01/geo/wgs84_pos#>
drop quad map virtrdf:TpcdDemo .
;

SPARQL
prefix tpcd: <http://demo.openlinksw.com/schemas/tpcd#>
prefix oplsioc: <http://www.openlinksw.com/schemas/oplsioc#>
prefix sioc: <http://rdfs.org/sioc/ns#>
prefix foaf: <http://xmlns.com/foaf/0.1/>
prefix wgs: <http://www.w3.org/2003/01/geo/wgs84_pos#>
create iri class tpcd:customer "http://^{URIQADefaultHost}^/tpcd/customer/%d#this" (in c_custkey integer not null) .
create iri class tpcd:lineitem "http://^{URIQADefaultHost}^/tpcd/lineitem/%d/%d#this" (in l_orderkey integer not null, in l_linenumber integer not null) .
create iri class tpcd:nation "http://^{URIQADefaultHost}^/tpcd/nation/%d#this" (in l_nationkey integer not null) .
create iri class tpcd:order "http://^{URIQADefaultHost}^/tpcd/order/%d#this" (in o_orderkey integer not null) .
create iri class tpcd:part "http://^{URIQADefaultHost}^/tpcd/part/%d#this" (in p_partkey integer not null) .
create iri class tpcd:partsupp "http://^{URIQADefaultHost}^/tpcd/partsupp/%d/%d#this" (in ps_partkey integer not null, in ps_suppkey integer not null) .
create iri class tpcd:region "http://^{URIQADefaultHost}^/tpcd/region/%d#this" (in r_regionkey integer not null) .
create iri class tpcd:supplier "http://^{URIQADefaultHost}^/tpcd/supplier/%d#this" (in s_supplierkey integer not null) .
;

SPARQL
prefix tpcd: <http://demo.openlinksw.com/schemas/tpcd#>
prefix oplsioc: <http://www.openlinksw.com/schemas/oplsioc#>
prefix sioc: <http://rdfs.org/sioc/ns#>
prefix foaf: <http://xmlns.com/foaf/0.1/>
prefix wgs: <http://www.w3.org/2003/01/geo/wgs84_pos#>
alter quad storage virtrdf:DefaultQuadStorage
from tpcd.DBA.lineitem as lineitems
from tpcd.DBA.customer as customers
from tpcd.DBA.nation as nations
from tpcd.DBA.orders as orders
from tpcd.DBA.part as parts
from tpcd.DBA.partsupp as partsupps
from tpcd.DBA.region as regions
from tpcd.DBA.supplier as suppliers
where (^{suppliers.}^.s_nationkey = ^{nations.}^.n_nationkey)
where (^{customers.}^.c_nationkey = ^{nations.}^.n_nationkey)
{
    create virtrdf:TpcdDemo as graph iri ("http://^{URIQADefaultHost}^/tpcd") option (exclusive)
    {
        tpcd:customer (customers.c_custkey)
            a  tpcd:customer
                as virtrdf:tpcdcustomer-c_custkey2 ;
            a  foaf:Organization
                as virtrdf:tpcdcustomer-c_custkey ;
            foaf:name customers.c_name
                as virtrdf:tpcdcustomer-foaf_name ;
            tpcd:companyName customers.c_name
                as virtrdf:tpcdcustomer-c_name ;
            tpcd:has_nation tpcd:nation (customers.c_nationkey)
                as virtrdf:tpcdcustomer-c_nationkey ;
            tpcd:address customers.c_address
                as virtrdf:tpcdcustomer-c_address ;
            foaf:phone customers.c_phone
                as virtrdf:tpcdcustomer-foaf_phone ;
            tpcd:phone customers.c_phone
                as virtrdf:tpcdcustomer-phone ;
            tpcd:mktsegment customers.c_mktsegment
                as virtrdf:tpcdcustomer-c_mktsegment ;
            tpcd:comment customers.c_comment
                as virtrdf:tpcdcustomer-c_comment .

        tpcd:nation (customers.c_nationkey)
            tpcd:nation_of tpcd:customer (customers.c_custkey) as virtrdf:tpcdcustomer-nation_of .

        tpcd:lineitem (lineitems.l_orderkey, lineitems.l_linenumber)
            a tpcd:lineitem
                as virtrdf:tpcdlineitem-lineitems ;
            tpcd:has_order tpcd:order (lineitems.l_orderkey)
                as virtrdf:tpcdlineitem-l_orderkey ;
            tpcd:has_part tpcd:part (lineitems.l_partkey)
                as virtrdf:tpcdlineitem-l_partkey ;
            tpcd:has_supplier tpcd:supplier (lineitems.l_suppkey)
                as virtrdf:tpcdlineitem-l_suppkey ;
            tpcd:linenumber lineitems.l_linenumber
                as virtrdf:tpcdlineitem-l_linenumber ;
            tpcd:returnflag lineitems.l_returnflag
                as virtrdf:tpcdlineitem-l_returnflag ;
            tpcd:linestatus lineitems.l_linestatus
                as virtrdf:tpcdlineitem-l_linestatus ;
            tpcd:shipdate lineitems.l_shipdate
                as virtrdf:tpcdlineitem-l_shipdate ;
            tpcd:commitdate lineitems.l_commitdate
                as virtrdf:tpcdlineitem-l_commitdate ;
            tpcd:receiptdate lineitems.l_receiptdate
                as virtrdf:tpcdlineitem-l_receiptdate ;
            tpcd:shipinstruct lineitems.l_shipinstruct
                as virtrdf:tpcdlineitem-l_shipinstruct ;
            tpcd:shipmode lineitems.l_shipmode
                as virtrdf:tpcdlineitem-l_shipmode ;
            tpcd:comment lineitems.l_comment
                as virtrdf:tpcdlineitem-l_comment .

        tpcd:part (lineitems.l_partkey)
            tpcd:part_of tpcd:lineitem (lineitems.l_orderkey, lineitems.l_linenumber) as virtrdf:tpcdlineitem-part_of .

        tpcd:order (lineitems.l_orderkey)
            tpcd:order_of tpcd:lineitem (lineitems.l_orderkey, lineitems.l_linenumber) as virtrdf:tpcdlineitem-order_of .

        tpcd:supplier (lineitems.l_suppkey)
            tpcd:supplier_of tpcd:lineitem (lineitems.l_orderkey, lineitems.l_linenumber) as virtrdf:tpcdlineitem-supplier_of .

        tpcd:nation (nations.n_nationkey)
            a tpcd:nation
                as virtrdf:tpcdnation-nations ;
            tpcd:name nations.n_name
                as virtrdf:tpcdnation-n_name ;
            tpcd:has_region tpcd:region (nations.n_regionkey)
                as virtrdf:tpcdnation-n_regionkey ;
            tpcd:comment nations.n_comment
                as virtrdf:tpcdnation-n_comment .

        tpcd:region (nations.n_regionkey)
            tpcd:region_of tpcd:nation (nations.n_nationkey) as virtrdf:tpcdnation-region_of .

        tpcd:order (orders.o_orderkey)
            a tpcd:order
                as virtrdf:tpcdorder-orders ;
            tpcd:has_customer tpcd:customer (orders.o_custkey)
                as virtrdf:tpcdorder-o_custkey ;
            tpcd:orderstatus orders.o_orderstatus
                as virtrdf:tpcdorder-o_orderstatus ;
            tpcd:orderdate orders.o_orderdate
                as virtrdf:tpcdorder-o_orderdate ;
            tpcd:orderpriority orders.o_orderpriority
                as virtrdf:tpcdorder-o_orderpriority ;
            tpcd:clerk orders.o_clerk
                as virtrdf:tpcdorder-o_clerk ;
            tpcd:shippriority orders.o_shippriority
                as virtrdf:tpcdorder-o_shippriority ;
            tpcd:comment orders.o_comment
                as virtrdf:tpcdorder-o_comment .

        tpcd:customer (orders.o_custkey)
            tpcd:customer_of tpcd:order (orders.o_orderkey) as virtrdf:tpcdorder-customer_of .

        tpcd:part (parts.p_partkey)
            a tpcd:part
                as virtrdf:tpcdpart-parts ;
            tpcd:name parts.p_name
                as virtrdf:tpcdpart-p_name ;
            tpcd:mfgr parts.p_mfgr
                as virtrdf:tpcdpart-p_mfgr ;
            tpcd:brand parts.p_brand
                as virtrdf:tpcdpart-p_brand ;
            tpcd:type parts.p_type
                as virtrdf:tpcdpart-p_type ;
            tpcd:size parts.p_size
                as virtrdf:tpcdpart-p_size ;
            tpcd:container parts.p_container
                as virtrdf:tpcdpart-p_container ;
            tpcd:comment parts.p_comment
                as virtrdf:tpcdpart-p_comment .

        tpcd:partsupp (partsupps.ps_partkey, partsupps.ps_suppkey)
            a tpcd:partsupp
                as virtrdf:tpcdpartsupp-partsupps ;
            tpcd:has_part tpcd:part (partsupps.ps_partkey)
                as virtrdf:tpcdpartsupp-ps_partkey ;
            tpcd:has_supplier tpcd:supplier (partsupps.ps_suppkey)
                as virtrdf:tpcdpartsupp-ps_suppkey ;
            tpcd:availqty partsupps.ps_availqty
                as virtrdf:tpcdpartsupp-ps_availqty ;
            tpcd:comment partsupps.ps_comment
                as virtrdf:tpcdpartsupp-ps_comment .

        tpcd:part (partsupps.ps_partkey)
            tpcd:part_of tpcd:partsupp (partsupps.ps_partkey, partsupps.ps_suppkey) as virtrdf:tpcdpartsupp-part_of .

        tpcd:supplier (partsupps.ps_suppkey)
            tpcd:supplier_of tpcd:partsupp (partsupps.ps_partkey, partsupps.ps_suppkey) as virtrdf:tpcdpartsupp-supplier_of .

        tpcd:region (regions.r_regionkey)
            a tpcd:region
                as virtrdf:tpcdregion-regions ;
            tpcd:name regions.r_name
                as virtrdf:tpcdregion-r_name ;
            tpcd:comment regions.r_comment
                as virtrdf:tpcdregion-r_comment .

        tpcd:supplier (suppliers.s_suppkey)
            a tpcd:supplier
                as virtrdf:tpcdsupplier-suppliers ;
            tpcd:name suppliers.s_name
                as virtrdf:tpcdsupplier-s_name ;
            tpcd:address suppliers.s_address
                as virtrdf:tpcdsupplier-s_address ;
            tpcd:has_nation tpcd:nation (suppliers.s_nationkey)
                as virtrdf:tpcdsupplier-s_nationkey ;
            foaf:phone customers.c_phone
                as virtrdf:tpcdsupplier-foaf_phone ;
            tpcd:phone suppliers.s_phone
                as virtrdf:tpcdsupplier-s_phone ;
            tpcd:comment suppliers.s_comment
                as virtrdf:tpcdsupplier-s_comment .

        tpcd:nation (suppliers.s_nationkey)
            tpcd:nation_of tpcd:supplier (suppliers.s_suppkey) as virtrdf:tpcdsupplier-nation_of .
    } .
} .
;

create procedure tcpd_rdf_doc (in path varchar)
{
  declare r any;
  r := regexp_match ('[^/]*\x24', path);
  return r||'#this';
};

create procedure tcpd_html_doc (in path varchar)
{
  declare r any;
  r := regexp_match ('[^/]*#', path);
  return subseq (r, 0, length (r)-1);
};

DB.DBA.URLREWRITE_CREATE_REGEX_RULE (
    'tcpd_rule2',
    1,
    '(/[^#]*)',
    vector('path'),
    1,
    '/sparql?query=CONSTRUCT+{+%%3Chttp%%3A//^{URIQADefaultHost}^%U%%23this%%3E+%%3Fp+%%3Fo+}+FROM+%%3Chttp%%3A//^{URIQADefaultHost}^/tpcd%%3E+WHERE+{+%%3Chttp%%3A//^{URIQADefaultHost}^%U%%23this%%3E+%%3Fp+%%3Fo+}&format=%U',
    vector('path', 'path', '*accept*'),
    null,
    '(text/rdf.n3)|(application/rdf.xml)',
    0,
    null
    );

DB.DBA.URLREWRITE_CREATE_REGEX_RULE (
    'tcpd_rule1',
    1,
    '(/[^#]*)',
    vector('path'),
    1,
    '/rdfbrowser/index.html?uri=http%%3A//^{URIQADefaultHost}^%U%%23this',
    vector('path'),
    null,
    '(text/html)|(\\*/\\*)',
    0,
    303
    );

DB.DBA.URLREWRITE_CREATE_REGEX_RULE (
    'tcpd_rule3',
    1,
    '(/[^#]*)/\x24',
    vector('path'),
    1,
    '%s',
    vector('path'),
    null,
    null,
    0,
    null
    );

DB.DBA."RDFData_MAKE_DET_COL" ('/DAV/home/tpcd/RDFData/', 'http://^{URIQADefaultHost}^/tpcd', NULL);
VHOST_REMOVE (lpath=>'/tpcd/data/rdf');
DB.DBA.VHOST_DEFINE (lpath=>'/tpcd/data/rdf', ppath=>'/DAV/home/tpcd/RDFData/All/', is_dav=>1, vsp_user=>'dba');

-- procedure to convert path to DET resource name
create procedure DB.DBA.TPCD_DET_REF (in par varchar, in fmt varchar, in val varchar)
{
  declare res, iri any;
  iri := 'http://^{URIQADefaultHost}^/tpcd' || val;
  res := sprintf ('iid (%d).rdf', iri_id_num (iri_to_id (iri)));
  return sprintf (fmt, res);
}
;

DB.DBA.URLREWRITE_CREATE_REGEX_RULE ('tpcd_rdf', 1,
    '/tpcd/(.*)', vector('path'), 1,
    '/tpcd/data/rdf/%U', vector('path'),
    'DB.DBA.TPCD_DET_REF',
    'application/rdf.xml',
    2,
    303);

DB.DBA.URLREWRITE_CREATE_RULELIST (
    'tpcd_rule_list1',
    1,
    vector (
                'tcpd_rule1',
                'tcpd_rule2',
                'tcpd_rule3',
                'tpcd_rdf'
          ));


VHOST_REMOVE (lpath=>'/tpcd');
DB.DBA.VHOST_DEFINE (lpath=>'/tpcd', ppath=>'/DAV/home/', vsp_user=>'dba', is_dav=>1, def_page=>'sfront.vspx',
    is_brws=>0, opts=>vector ('url_rewrite', 'tpcd_rule_list1'));

DB.DBA.XML_SET_NS_DECL ('tpcd', 'http://demo.openlinksw.com/schemas/tpcd#', 2);

15.8.16.3. Thalia to RDF

use DB;

create procedure DB.DBA.SPARQL_THALIA_RUN (in txt varchar)
{
  declare REPORT, stat, msg, sqltext varchar;
  declare metas, rowset any;
  result_names (REPORT);
  sqltext := string_output_string (sparql_to_sql_text (txt));
  stat := '00000';
  msg := '';
  rowset := null;
  exec (sqltext, stat, msg, vector (), 1000, metas, rowset);
  --result ('STATE=' || stat || ': ' || msg);
  --if (rowset is not null)
  --  {
  --    foreach (any r in rowset) do
  --      result (r[0] || ': ' || r[1]);
  --  }
}
;

use thalia;

DB.DBA.exec_no_error('drop View thalia.Demo.asu_v');
create View thalia.Demo.asu_v as select left(Title,3) code,* from thalia.Demo.asu;
DB.DBA.exec_no_error('drop View thalia.Demo.gatech_v');
create View thalia.Demo.gatech_v as select *, Room||' '||Building Place from thalia.Demo.gatech;

use DB;

DB.DBA.exec_no_error('GRANT \"SPARQL_UPDATE\" TO \"SPARQL\"');
GRANT SELECT ON thalia.Demo.asu TO "SPARQL";
GRANT SELECT ON thalia.Demo.asu_v TO "SPARQL";
GRANT SELECT ON thalia.Demo.brown TO "SPARQL";
GRANT SELECT ON thalia.Demo.cmu TO "SPARQL";
GRANT SELECT ON thalia.Demo.gatech TO "SPARQL";
GRANT SELECT ON thalia.Demo.gatech_v TO "SPARQL";
GRANT SELECT ON thalia.Demo.toronto TO "SPARQL";
GRANT SELECT ON thalia.Demo.ucsd TO "SPARQL";
GRANT SELECT ON thalia.Demo.umd TO "SPARQL";


DB.DBA.SPARQL_THALIA_RUN('drop quad map graph iri("http://^{URIQADefaultHost}^/Thalia") .
')
;

DB.DBA.SPARQL_THALIA_RUN('drop quad map graph iri("http://^{URIQADefaultHost}^/thalia") .
');

DB.DBA.SPARQL_THALIA_RUN('drop quad map virtrdf:ThaliaDemo .
');


DB.DBA.SPARQL_THALIA_RUN('
prefix oplsioc: <http://www.openlinksw.com/schemas/oplsioc#>
prefix sioc: <http://rdfs.org/sioc/ns#>
prefix xsd: <http://www.w3.org/2001/XMLSchema#>
prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#>
prefix owl: <http://www.w3.org/2002/07/owl#>
prefix dc: <http://purl.org/dc/elements/1.1/>
prefix time: <http://www.w3.org/2006/time#>
prefix event: <http://purl.org/NET/c4dm/event.owl#>
prefix geo: <http://www.w3.org/2003/01/geo/wgs84_pos#>
prefix foaf: <http://xmlns.com/foaf/0.1/>
prefix skos: <http://www.w3.org/2004/02/skos/core#>
prefix th: <http://purl.org/ontology/thalia/1.0/>

create iri class th:Asu "http://^{URIQADefaultHost}^/thalia/asu/course/%U#this" (in code varchar not null) .
create iri class th:Brown "http://^{URIQADefaultHost}^/thalia/brown/course/%U#this" (in Code varchar not null) .
create iri class th:BrownInstructor "http://^{URIQADefaultHost}^/thalia/brown/instructor/%U#this" (in Code varchar not null) .
create iri class th:BrownLecture "http://^{URIQADefaultHost}^/thalia/brown/lecture/%U#this" (in Code varchar not null) .
create iri class th:BrownPlace "http://^{URIQADefaultHost}^/thalia/brown/place/%U#this" (in Code varchar not null) .

create iri class th:Cmu "http://^{URIQADefaultHost}^/thalia/cmu/course/%U/%U#this" (in Code varchar not null, in Sec varchar) .
create iri class th:CmuInstructor "http://^{URIQADefaultHost}^/thalia/cmu/instructor/%U/%U#this" (in Code varchar not null, in Sec varchar) .
create iri class th:CmuLecture "http://^{URIQADefaultHost}^/thalia/cmu/lecture/%U/%U#this" (in Code varchar not null, in Sec varchar) .
create iri class th:CmuPlace "http://^{URIQADefaultHost}^/thalia/cmu/place/%U/%U#this" (in Code varchar not null, in Sec varchar) .
create iri class th:CmuEventTime "http://^{URIQADefaultHost}^/thalia/cmu/eventtime/%U/%U#this" (in Code varchar not null, in Sec varchar) .
create iri class th:CmuDatetime "http://^{URIQADefaultHost}^/thalia/cmu/datetime/%U/%U#this" (in Code varchar not null, in Sec varchar) .

create iri class th:Gatech "http://^{URIQADefaultHost}^/thalia/gatech/course/%U/%d/%U#this" (in Department varchar, in Code integer, in Section varchar) .
create iri class th:GatechInstructor "http://^{URIQADefaultHost}^/thalia/gatech/instructor/%U/%d/%U#this" (in Department varchar, in Code integer, in Section varchar) .
create iri class th:GatechLecture "http://^{URIQADefaultHost}^/thalia/gatech/lecture/%U/%d/%U#this" (in Department varchar, in Code integer, in Section varchar) .
create iri class th:GatechEventTime "http://^{URIQADefaultHost}^/thalia/gatech/eventtime/%U/%d/%U#this" (in Department varchar, in Code integer, in Section varchar) .
create iri class th:GatechDatetime "http://^{URIQADefaultHost}^/thalia/gatech/datetime/%U/%d/%U#this" (in Department varchar, in Code integer, in Section varchar) .
create iri class th:GatechPlace "http://^{URIQADefaultHost}^/thalia/gatech/place/%U/%d/%U#this" (in Department varchar, in Code integer, in Section varchar) .

create iri class th:Toronto "http://^{URIQADefaultHost}^/thalia/toronto/course/%U#this" (in No_ varchar) .
create iri class th:TorontoInstructor "http://^{URIQADefaultHost}^/thalia/toronto/instructor/%U#this" (in No_ varchar) .
create iri class th:TorontoLecture "http://^{URIQADefaultHost}^/thalia/toronto/lecture/%U#this" (in No_ varchar) .
create iri class th:TorontoPlace "http://^{URIQADefaultHost}^/thalia/toronto/place/%U#this" (in No_ varchar) .

create iri class th:Ucsd "http://^{URIQADefaultHost}^/thalia/ucsd/course/%U#this" (in Number varchar) .
create iri class th:UcsdInstructor1 "http://^{URIQADefaultHost}^/thalia/ucsd/instructor1/%U#this" (in Number varchar) .
create iri class th:UcsdInstructor2 "http://^{URIQADefaultHost}^/thalia/ucsd/instructor2/%U#this" (in Number varchar) .
create iri class th:UcsdInstructor3 "http://^{URIQADefaultHost}^/thalia/ucsd/instructor3/%U#this" (in Number varchar) .

create iri class th:Umd "http://^{URIQADefaultHost}^/thalia/umd/course/%U#this" (in Code varchar) .
create iri class th:UmdLecture "http://^{URIQADefaultHost}^/thalia/umd/lecture/%U#this" (in Code varchar) .
create iri class th:UmdEventTime "http://^{URIQADefaultHost}^/thalia/umd/eventtime/%U#this" (in Code varchar) .
create iri class th:UmdDatetime "http://^{URIQADefaultHost}^/thalia/umd/datetime/%U#this" (in Code varchar) .
')
;


DB.DBA.RDF_AUDIT_METADATA (1, '*');

DB.DBA.SPARQL_THALIA_RUN('prefix oplsioc: <http://www.openlinksw.com/schemas/oplsioc#>
prefix sioc: <http://rdfs.org/sioc/ns#>
prefix xsd: <http://www.w3.org/2001/XMLSchema#>
prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#>
prefix owl: <http://www.w3.org/2002/07/owl#>
prefix dc: <http://purl.org/dc/elements/1.1/>
prefix time: <http://www.w3.org/2006/time#>
prefix event: <http://purl.org/NET/c4dm/event.owl#>
prefix geo: <http://www.w3.org/2003/01/geo/wgs84_pos#>
prefix foaf: <http://xmlns.com/foaf/0.1/>
prefix skos: <http://www.w3.org/2004/02/skos/core#>
prefix th: <http://purl.org/ontology/thalia/1.0/>
alter quad storage virtrdf:DefaultQuadStorage
from thalia.demo.asu_v as asus
from thalia.demo.brown as browns
from thalia.demo.cmu as cmus
from thalia.demo.gatech_v as gatechs
from thalia.demo.toronto as torontos
from thalia.demo.ucsd as ucsds
from thalia.demo.umd as umds
{
        create virtrdf:ThaliaDemo as graph iri ("http://^{URIQADefaultHost}^/thalia") option (exclusive)
        {
                th:Asu (asus.code)
                	a th:Course
                		as virtrdf:Asu-Course ;
                	dc:title asus.Title
                		as virtrdf:Asu-Title ;
                	dc:description asus.Description
                		as virtrdf:Asu-Description ;
                	rdfs:seeAlso asus.MoreInfoURL
                		as virtrdf:Asu-MoreInfoURL ;
                        th:forUniversity "http://purl.org/thalia/university/asu"
                        	as virtrdf:Asu-University ;
                        skos:subject "http://purl.org/subject/thalia/ComputerScience"
                        	as virtrdf:Asu-Subject
                        	.

                th:Brown (browns.Code)
                        a th:Course
                                as virtrdf:Brown-Course ;
                        dc:title browns.Title
                        	as virtrdf:Brown-Title ;
                        th:hasInstructor th:BrownInstructor (browns.Code)
                        	as virtrdf:Brown-hasInstructor ;
                        th:hasLecture th:BrownLecture(browns.Code)
                        	as virtrdf:Brown-hasLecture ;
                        th:forUniversity "http://purl.org/thalia/university/brown"
                        	as virtrdf:Brown-University ;
                        skos:subject "http://purl.org/subject/thalia/ComputerScience"
                        	as virtrdf:Brown-Subject
                        	.
                th:BrownInstructor (browns.Code)
                        a th:Instructor
                                as virtrdf:Brown-Instructor ;
                        dc:homepage browns.Instructor
                        	as virtrdf:Brown-Instructor-Homepage
                        	.
                th:BrownLecture (browns.Code)
                        a event:Event
                                as virtrdf:Brown-Lecture ;
                        event:place th:BrownPlace(browns.Code)
                        	as virtrdf:Brown-hasPlace
                        	.
                th:BrownPlace (browns.Code)
                        a geo:Point
                                as virtrdf:Brown-Place;
                        dc:title browns.Room
                        	as virtrdf:Brown-Room
                        	.

                th:Cmu (cmus.Code, cmus.Sec)
                	a th:Course
                		as virtrdf:Cmu-Course ;
                	dc:title cmus.CourseTitle
                		as virtrdf:Cmu-CourseTitle ;
                        th:hasInstructor th:CmuInstructor (cmus.Code, cmus.Sec)
                        	as virtrdf:Cmu-hasInstructor ;
                        th:hasLecture th:CmuLecture(cmus.Code, cmus.Sec)
                        	as virtrdf:Cmu-hasLecture ;
                        th:hasUnits cmus.Units
                        	as virtrdf:Cmu-hasUnits ;
                        th:forUniversity "http://purl.org/thalia/university/cmu"
                        	as virtrdf:Cmu-University ;
                        skos:subject "http://purl.org/subject/thalia/ComputerScience"
                        	as virtrdf:Cmu-Subject
                		.
		th:CmuInstructor (cmus.Code, cmus.Sec)
                        a th:Instructor
                                as virtrdf:Cmu-Instructor ;
                	foaf:name cmus.Lecturer
                		as virtrdf:Cmu-Lecturer
                        	.
		th:CmuLecture (cmus.Code, cmus.Sec)
                        a event:Event
                                as virtrdf:Cmu-Lecture ;
                        event:time th:CmuEventTime(cmus.Code, cmus.Sec)
                        	as virtrdf:Cmu-hasEventTime ;
                        event:place th:CmuPlace(cmus.Code, cmus.Sec)
                        	as virtrdf:Cmu-hasPlace
                        	.
		th:CmuPlace (cmus.Code, cmus.Sec)
                        a geo:Point
                                as virtrdf:Cmu-Place;
                        dc:title cmus.Room
                        	as virtrdf:Cmu-Room
                        	.
		th:CmuEventTime (cmus.Code, cmus.Sec)
                        a time:Interval
                                as virtrdf:Cmu-EventTime;
                        time:inDateTime th:CmuDatetime(cmus.Code, cmus.Sec)
                        	as virtrdf:Cmu-inDateTime
                        	.
		th:CmuDatetime (cmus.Code, cmus.Sec)
                        a time:DateTimeDescription
                                as virtrdf:Cmu-Datetime;
                	time:dayOfWeek cmus.Day_
                		as virtrdf:Cmu-Day ;
                	time:hour cmus.Time_
                		as virtrdf:Cmu-Time
                        	.

                th:Gatech (gatechs.Department, gatechs.Code, gatechs.Section)
                	a th:Course
                		as virtrdf:Gatech-Course ;
                	dc:title gatechs.Title
                		as virtrdf:Gatech-Title ;
                        th:hasInstructor th:GatechInstructor(gatechs.Department, gatechs.Code, gatechs.Section)
                        	as virtrdf:Gatech-hasInstructor ;
                	dc:description gatechs.Description
                		as virtrdf:Gatech-Description ;
                        th:hasLecture th:GatechLecture(gatechs.Department, gatechs.Code, gatechs.Section)
                        	as virtrdf:Gatech-hasLecture ;
                        th:forUniversity "http://purl.org/thalia/university/gatech"
                        	as virtrdf:Gatech-University ;
                        skos:subject "http://purl.org/subject/thalia/ComputerScience"
                        	as virtrdf:Gatech-Subject
                        	.
		th:GatechInstructor (gatechs.Department, gatechs.Code, gatechs.Section)
                        a th:Instructor
                                as virtrdf:Gatech-Instructor ;
                	foaf:name gatechs.Instructor
                		as virtrdf:Gatech-InstructorName
				.
		th:GatechLecture (gatechs.Department, gatechs.Code, gatechs.Section)
                        a event:Event
                                as virtrdf:Gatech-Lecture ;
                        event:time th:GatechEventTime(gatechs.Department, gatechs.Code, gatechs.Section)
                        	as virtrdf:Gatech-hasEventTime ;
                        event:place th:GatechPlace(gatechs.Department, gatechs.Code, gatechs.Section)
                        	as virtrdf:Gatech-hasPlace
				.
		th:GatechEventTime (gatechs.Department, gatechs.Code, gatechs.Section)
                        a time:Interval
                                as virtrdf:Gatech-EventTime ;
                        time:inDateTime th:GatechDatetime(gatechs.Department, gatechs.Code, gatechs.Section)
                        	as virtrdf:Gatech-inDateTime
				.
		th:GatechDatetime (gatechs.Department, gatechs.Code, gatechs.Section)
                        a time:DateTimeDescription
                                as virtrdf:Gatech-Datetime ;
                	time:dayOfWeek gatechs.Days
                		as virtrdf:Gatech-Days ;
                	time:hour gatechs.Time_
                		as virtrdf:Gatech-Time_
				.
		th:GatechPlace (gatechs.Department, gatechs.Code, gatechs.Section)
                        a geo:Point
                                as virtrdf:Gatech-Place ;
                        dc:title gatechs.Place
                        	as virtrdf:Gatech-RoomBuilding
				.

                th:Toronto (torontos.No_)
                        a th:Course
                                as virtrdf:Toronto-Course ;
                        dc:title torontos.title
                        	as virtrdf:Toronto-Title ;
                        dc:description torontos.text_
                        	as virtrdf:Toronto-Description ;
                        th:hasInstructor th:TorontoInstructor(torontos.No_)
                        	as virtrdf:Toronto-hasInstructor ;
                        th:hasLecture th:TorontoLecture(torontos.No_)
                        	as virtrdf:Toronto-hasLecture ;
                        rdfs:seeAlso torontos.coursewebsite
                        	as virtrdf:Toronto-CourseWebSite ;
                        th:hasPrerequisite torontos.prereq
                        	as virtrdf:Toronto-prereq ;
                        th:text torontos.text_
                        	as virtrdf:Toronto-text;
                        th:forUniversity "http://purl.org/thalia/university/toronto"
                        	as virtrdf:Toronto-University ;
                        skos:subject "http://purl.org/subject/thalia/ComputerScience"
                        	as virtrdf:Toronto-Subject
                        	.
		th:TorontoInstructor (torontos.No_)
                        a th:Instructor
                                as virtrdf:Toronto-Instructor ;
                        foaf:name torontos.instructorName
                        	as virtrdf:Toronto-InstructorName ;
                        foaf:mbox torontos.instructorEmail
                        	as virtrdf:Toronto-InstructorEmail
				.
		th:TorontoLecture (torontos.No_)
                        a event:Event
                                as virtrdf:Toronto-Lecture ;
                        event:place th:TorontoPlace(torontos.No_)
                        	as virtrdf:Toronto-hasPlace
				.
		th:TorontoPlace (torontos.No_)
                        a geo:Point
                                as virtrdf:Toronto-Place ;
                        dc:title torontos.location
                        	as virtrdf:Toronto-Location
				.

                th:Ucsd (ucsds.Number)
                        a th:Course
                                as virtrdf:Ucsd-Course ;
                        dc:title ucsds.Title
                        	as virtrdf:Ucsd-Title ;
                        th:hasInstructor1 th:UcsdInstructor1 (ucsds.Number)
                        	as virtrdf:Ucsd-hasInstructor1 ;
                        th:hasInstructor2 th:UcsdInstructor2 (ucsds.Number)
                        	as virtrdf:Ucsd-hasInstructor2 ;
                        th:hasInstructor3 th:UcsdInstructor3 (ucsds.Number)
                        	as virtrdf:Ucsd-hasInstructor3 ;
                        th:forUniversity "http://purl.org/thalia/university/ucsd"
                        	as virtrdf:Ucsd-University ;
                        skos:subject "http://purl.org/subject/thalia/ComputerScience"
                        	as virtrdf:Ucsd-Subject
                        	.
                th:UcsdInstructor1 (ucsds.Number)
                        a th:Instructor
                                as virtrdf:Ucsd-Instructor1 ;
                        foaf:name ucsds.Fall2003
                        	as virtrdf:Ucsd-Instructor-Fall2003
                        	.
                th:UcsdInstructor2 (ucsds.Number)
                        a th:Instructor
                                as virtrdf:Ucsd-Instructor2 ;
                        foaf:name ucsds.Winter2004
                        	as virtrdf:Ucsd-Instructor-Winter2004
                        	.
                th:UcsdInstructor3 (ucsds.Number)
                        a th:Instructor
                                as virtrdf:Ucsd-Instructor3 ;
                        foaf:name ucsds.Spring2004
                        	as virtrdf:Ucsd-Instructor-Spring2004
                        	.

                th:Umd (umds.Code)
                	a th:Course
                		as virtrdf:Umd-Course ;
                	dc:title umds.CourseName
                		as virtrdf:Umd-Title ;
                        th:hasSection th:SectionTitle
                        	as virtrdf:Umd-hasSection ;
                        th:hasLecture th:UmdLecture(umds.Code)
                        	as virtrdf:Umd-hasLecture ;
                        th:forUniversity "http://purl.org/thalia/university/umd"
                        	as virtrdf:Umd-University ;
                        skos:subject "http://purl.org/subject/thalia/ComputerScience"
                        	as virtrdf:Umd-Subject
                        	.
		th:UmdLecture (umds.Code)
                        a event:Event
                                as virtrdf:Umd-Lecture ;
                        event:time th:UmdEventTime(umds.Code)
                        	as virtrdf:Umd-hasEventTime
				.
		th:UmdEventTime (umds.Code)
                        a time:Interval
                                as virtrdf:Umd-EventTime ;
                        time:inDateTime th:UmdDatetime(umds.Code)
                        	as virtrdf:Umd-inDateTime
				.
		th:UmdDatetime (umds.Code)
                        a time:DateTimeDescription
                                as virtrdf:Umd-Datetime ;
                	time:hour umds.SectionTime
                		as virtrdf:Umd-SectionTime
				.
        }
}
')
;

DB.DBA.RDF_AUDIT_METADATA (1, '*');


create procedure tut_th_rdf_doc (in path varchar)
{
  declare r any;
  r := regexp_match ('[^/]*\x24', path);
  return r||'#this';
};

create procedure tut_th_html_doc (in path varchar)
{
  declare r any;
  r := regexp_match ('[^/]*#', path);
  return subseq (r, 0, length (r)-1);
};

DB.DBA.URLREWRITE_CREATE_REGEX_RULE (
    'tut_th_rule2',
    1,
    '(/[^#]*)\x24',
    vector('path'),
    1,
    '/sparql?query=CONSTRUCT+{+%%3Chttp%%3A//^{URIQADefaultHost}^%U%%23this%%3E+%%3Fp+%%3Fo+}+FROM+%%3Chttp%%3A//^{URIQADefaultHost}^/Thalia%%3E+WHERE+{+%%3Chttp%%3A//^{URIQADefaultHost}^%U%%23this%%3E+%%3Fp+%%3Fo+}&format=%U',
    vector('path', 'path', '*accept*'),
    null,
    '(text/rdf.n3)|(application/rdf.xml)',
    0,
    303
    );

DB.DBA.URLREWRITE_CREATE_REGEX_RULE (
    'tut_th_rule1',
    1,
    '(/[^#]*)\x24',
    vector('path'),
    1,
    '/isparql/execute.html?query=SELECT%%20%%3Fp%%20%%3Fo%%20FROM%%20%%3Chttp%%3A//^{URIQADefaultHost}^/Thalia%%3E%%20WHERE%%20{%%20%%3Chttp%%3A//^{URIQADefaultHost}^%U%%23this%%3E%%20%%3Fp%%20%%3Fo%%20}&endpoint=/sparql',
    vector('path'),
    null,
    '(text/html)|(\\*/\\*)',
    0,
    303
    );

DB.DBA.URLREWRITE_CREATE_RULELIST (
    'tut_th_rule_list1',
    1,
    vector (
                'tut_th_rule1',
                'tut_th_rule2'
          ));


DB.DBA.VHOST_REMOVE (lpath=>'/thalia');
DB.DBA.VHOST_DEFINE (lpath=>'/thalia', ppath=>'/DAV/Thalia/', is_dav=>1, vsp_user=>'dba', is_brws=>0, opts=>vector ('url_rewrite', 'tut_th_rule_list1'));

DB.DBA.XML_SET_NS_DECL ('th', 'http://purl.org/ontology/thalia/1.0/', 2);


    * Demo : Thalia test queries


#service:/sparql
#should-sponge:soft
PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX owl: <http://www.w3.org/2002/07/owl#>
PREFIX dc: <http://purl.org/dc/elements/1.1/>
PREFIX time: <http://www.w3.org/2006/time#>
PREFIX event: <http://purl.org/NET/c4dm/event.owl#>
PREFIX geo: <http://www.w3.org/2003/01/geo/wgs84_pos#>
PREFIX foaf: <http://xmlns.com/foaf/0.1/>
PREFIX skos: <http://www.w3.org/2004/02/skos/core#>
PREFIX th: <http://purl.org/ontology/thalia/1.0/>

SELECT distinct ?room
FROM <http://demo.openlinksw.com/thalia>
WHERE
  {
    ?course a th:Course;
              dc:title ?title;
	      th:hasLecture ?lecture.
    ?lecture event:place [dc:title ?room].
    FILTER regex(?title, "Software Engineering")
}


#service:/sparql
#should-sponge:soft
PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX owl: <http://www.w3.org/2002/07/owl#>
PREFIX dc: <http://purl.org/dc/elements/1.1/>
PREFIX time: <http://www.w3.org/2006/time#>
PREFIX event: <http://purl.org/NET/c4dm/event.owl#>
PREFIX geo: <http://www.w3.org/2003/01/geo/wgs84_pos#>
PREFIX foaf: <http://xmlns.com/foaf/0.1/>
PREFIX skos: <http://www.w3.org/2004/02/skos/core#>
PREFIX th: <http://purl.org/ontology/thalia/1.0/>

SELECT ?day, ?hour ?course
FROM <http://demo.openlinksw.com/thalia>
WHERE
  {
    ?course a th:Course;
    th:hasLecture [event:time ?time];
    dc:title ?title.
    ?time time:inDateTime [time:dayOfWeek ?day];
    time:inDateTime [time:hour ?hour].
    FILTER regex(?title, "Computer Networks")
  }



#service:/sparql
#should-sponge:soft

PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX owl: <http://www.w3.org/2002/07/owl#>
PREFIX dc: <http://purl.org/dc/elements/1.1/>
PREFIX time: <http://www.w3.org/2006/time#>
PREFIX event: <http://purl.org/NET/c4dm/event.owl#>
PREFIX geo: <http://www.w3.org/2003/01/geo/wgs84_pos#>
PREFIX foaf: <http://xmlns.com/foaf/0.1/>
PREFIX skos: <http://www.w3.org/2004/02/skos/core#>
PREFIX th: <http://purl.org/ontology/thalia/1.0/>

SELECT distinct ?course
FROM <http://demo.openlinksw.com/thalia>
WHERE
  {
    ?course a th:Course;
              dc:title ?Title;
              th:hasLecture ?lecture.
    ?lecture event:time [time:inDateTime ?dateTime].
    ?dateTime time:hour ?hour.
    FILTER regex(?Title, "Database System")
    FILTER regex(?hour, "1:30 - 2:50")
  }


#service:/sparql
#should-sponge:soft
PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX owl: <http://www.w3.org/2002/07/owl#>
PREFIX dc: <http://purl.org/dc/elements/1.1/>
PREFIX time: <http://www.w3.org/2006/time#>
PREFIX event: <http://purl.org/NET/c4dm/event.owl#>
PREFIX geo: <http://www.w3.org/2003/01/geo/wgs84_pos#>
PREFIX foaf: <http://xmlns.com/foaf/0.1/>
PREFIX skos: <http://www.w3.org/2004/02/skos/core#>
PREFIX th: <http://purl.org/ontology/thalia/1.0/>

SELECT distinct ?course ?instructor ?name
FROM <http://demo.openlinksw.com/thalia>
WHERE
  {
    ?course a th:Course;
              th:hasInstructor ?instructor.
    ?instructor foaf:name ?name.

  }


#service:/sparql
#should-sponge:soft
PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX owl: <http://www.w3.org/2002/07/owl#>
PREFIX dc: <http://purl.org/dc/elements/1.1/>
PREFIX time: <http://www.w3.org/2006/time#>
PREFIX event: <http://purl.org/NET/c4dm/event.owl#>
PREFIX geo: <http://www.w3.org/2003/01/geo/wgs84_pos#>
PREFIX foaf: <http://xmlns.com/foaf/0.1/>
PREFIX skos: <http://www.w3.org/2004/02/skos/core#>
PREFIX th: <http://purl.org/ontology/thalia/1.0/>

SELECT distinct ?instructor
FROM <http://demo.openlinksw.com/thalia>
WHERE
  {
    ?course a th:Course;
	      th:hasInstructor ?instructor;
	      dc:title  ?title.
    FILTER regex(?title, "Database")
  }


#service:/sparql
#should-sponge:soft
PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX owl: <http://www.w3.org/2002/07/owl#>
PREFIX dc: <http://purl.org/dc/elements/1.1/>
PREFIX time: <http://www.w3.org/2006/time#>
PREFIX event: <http://purl.org/NET/c4dm/event.owl#>
PREFIX geo: <http://www.w3.org/2003/01/geo/wgs84_pos#>
PREFIX foaf: <http://xmlns.com/foaf/0.1/>
PREFIX skos: <http://www.w3.org/2004/02/skos/core#>
PREFIX th: <http://purl.org/ontology/thalia/1.0/>

SELECT distinct ?instructor
FROM <http://demo.openlinksw.com/thalia>
WHERE
  {
    ?course a th:Course;
              dc:title ?title;
              th:hasInstructor ?instructor.
    FILTER regex(?title, "Software")
  }


#service:/sparql
#should-sponge:soft
PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX owl: <http://www.w3.org/2002/07/owl#>
PREFIX dc: <http://purl.org/dc/elements/1.1/>
PREFIX time: <http://www.w3.org/2006/time#>
PREFIX event: <http://purl.org/NET/c4dm/event.owl#>
PREFIX geo: <http://www.w3.org/2003/01/geo/wgs84_pos#>
PREFIX foaf: <http://xmlns.com/foaf/0.1/>
PREFIX skos: <http://www.w3.org/2004/02/skos/core#>
PREFIX th: <http://purl.org/ontology/thalia/1.0/>

SELECT DISTINCT ?course
FROM <http://demo.openlinksw.com/thalia>
WHERE
  {
    ?course a th:Course;
              dc:title ?title;
              th:forUniversity 'http://purl.org/thalia/university/umd'.
    FILTER regex(?title, "Data Structures")
  }


#service:/sparql
#should-sponge:soft
PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX owl: <http://www.w3.org/2002/07/owl#>
PREFIX dc: <http://purl.org/dc/elements/1.1/>
PREFIX time: <http://www.w3.org/2006/time#>
PREFIX event: <http://purl.org/NET/c4dm/event.owl#>
PREFIX geo: <http://www.w3.org/2003/01/geo/wgs84_pos#>
PREFIX foaf: <http://xmlns.com/foaf/0.1/>
PREFIX skos: <http://www.w3.org/2004/02/skos/core#>
PREFIX th: <http://purl.org/ontology/thalia/1.0/>

SELECT distinct ?course
FROM <http://demo.openlinksw.com/thalia>
WHERE
  {
    ?course a th:Course;
              dc:title ?Title;
              th:hasUnits ?credits.
    FILTER (xsd:integer(?credits) > 10)
    FILTER regex(?Title, "Database")
  }


#service:/sparql
#should-sponge:soft
PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX owl: <http://www.w3.org/2002/07/owl#>
PREFIX dc: <http://purl.org/dc/elements/1.1/>
PREFIX time: <http://www.w3.org/2006/time#>
PREFIX event: <http://purl.org/NET/c4dm/event.owl#>
PREFIX geo: <http://www.w3.org/2003/01/geo/wgs84_pos#>
PREFIX foaf: <http://xmlns.com/foaf/0.1/>
PREFIX skos: <http://www.w3.org/2004/02/skos/core#>
PREFIX th: <http://purl.org/ontology/thalia/1.0/>

SELECT distinct ?course
FORM <http://demo.openlinksw.com/thalia>
WHERE
  {
    ?course a th:Course;
              dc:title ?title;
              th:forUniversity 'http://purl.org/thalia/university/umd'.
    FILTER regex(?title, "Database")
  }


#service:/sparql
#should-sponge:soft
PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX owl: <http://www.w3.org/2002/07/owl#>
PREFIX dc: <http://purl.org/dc/elements/1.1/>
PREFIX time: <http://www.w3.org/2006/time#>
PREFIX event: <http://purl.org/NET/c4dm/event.owl#>
PREFIX geo: <http://www.w3.org/2003/01/geo/wgs84_pos#>
PREFIX foaf: <http://xmlns.com/foaf/0.1/>
PREFIX skos: <http://www.w3.org/2004/02/skos/core#>
PREFIX th: <http://purl.org/ontology/thalia/1.0/>

SELECT distinct ?course
FROM <http://demo.openlinksw.com/thalia>
WHERE
  {
    ?course a th:Course;
              dc:title ?Title;
              th:hasUnits ?credits.
    FILTER (xsd:integer(?credits) > 10)
    FILTER regex(?Title, "Database")
  }


#service:/sparql
#should-sponge:soft
PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX owl: <http://www.w3.org/2002/07/owl#>
PREFIX dc: <http://purl.org/dc/elements/1.1/>
PREFIX time: <http://www.w3.org/2006/time#>
PREFIX event: <http://purl.org/NET/c4dm/event.owl#>
PREFIX geo: <http://www.w3.org/2003/01/geo/wgs84_pos#>
PREFIX foaf: <http://xmlns.com/foaf/0.1/>
PREFIX skos: <http://www.w3.org/2004/02/skos/core#>
PREFIX th: <http://purl.org/ontology/thalia/1.0/>

SELECT distinct ?text_
FROM <http://demo.openlinksw.com/thalia>
WHERE
  {
    ?course a th:Course;
             dc:title ?title;
             th:text ?text_.
    FILTER regex(?title, "Verification")
  }


#service:/sparql
#should-sponge:soft
PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX owl: <http://www.w3.org/2002/07/owl#>
PREFIX dc: <http://purl.org/dc/elements/1.1/>
PREFIX time: <http://www.w3.org/2006/time#>
PREFIX event: <http://purl.org/NET/c4dm/event.owl#>
PREFIX geo: <http://www.w3.org/2003/01/geo/wgs84_pos#>
PREFIX foaf: <http://xmlns.com/foaf/0.1/>
PREFIX skos: <http://www.w3.org/2004/02/skos/core#>
PREFIX : <http://purl.org/ontology/thalia/1.0/>

SELECT distinct ?course
FROM <http://demo.openlinksw.com/thalia>
WHERE
  {
    ?course a th:Course;
              dc:description ?description;
              th:forUniversity 'http://purl.org/thalia/university/gatech'.
    FILTER regex(?description, "JR")
  }

15.8.16.4. Musicbrainz to RDF

The following code creates the Musicbrainz RDF Views Deployment and Demo Scripts:

create text index on ZITGIST.MO.artist ("name") with key id;
create text index on ZITGIST.MO.artistalias ("name") with key id;
create text index on ZITGIST.MO.album ("name") with key id;
create text index on ZITGIST.MO.track ("name") with key id;
vt_batch_update (fix_identifier_case ('ZITGIST.MO.artist'), 'ON', NULL);
vt_batch_update (fix_identifier_case ('ZITGIST.MO.artistalias'), 'ON', NULL);
vt_batch_update (fix_identifier_case ('ZITGIST.MO.album'), 'ON', NULL);
vt_batch_update (fix_identifier_case ('ZITGIST.MO.track'), 'ON', NULL);
VT_INC_INDEX_DB_MO_artist ();
VT_INC_INDEX_DB_MO_artistalias ();
VT_INC_INDEX_DB_MO_album ();
VT_INC_INDEX_DB_MO_track ();

Note: Making sure that the graphs and views are deleting to clean Virtuoso from the old definitions

sparql
drop quad storage virtrdf:MBZROOT.
;

sparql
prefix mbz: <http://musibrainz.org/schemas/mbz#>
drop literal class mbz:duration
;

sparql
prefix mbz: <http://musibrainz.org/schemas/mbz#>
drop literal class mbz:created.
drop literal class mbz:official_iri.
drop literal class mbz:bootleg_iri.
drop literal class mbz:promotion_iri.
drop literal class mbz:album_iri.
drop literal class mbz:single_iri.
drop literal class mbz:ep_iri.
drop literal class mbz:compilation_iri.
drop literal class mbz:soundtrack_iri.
drop literal class mbz:spokenword_iri.
drop literal class mbz:interview_iri.
drop literal class mbz:audiobook_iri.
drop literal class mbz:live_iri.
drop literal class mbz:remix_iri.
;

The following SPARQL query will fix an issue Virtuoso has with its JSO system. Perform this query for now, the issue should be fixed in a future release

sparql define input:storage ""
delete from graph (iri(bif:JSO_SYS_GRAPH NIL)) { ?s virtrdf:version ?o }
where { graph `iri(bif:JSO_SYS_GRAPH NIL)` {?s virtrdf:version ?o}};
SPARQL_RELOAD_QM_GRAPH();

Creation of IRIs classes.

sparql

prefix mbz: <http://musibrainz.org/schemas/mbz#>
prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
prefix dc: <http://purl.org/dc/elements/1.1/>
prefix bio: <http://vocab.org/bio/0.1/#>
prefix rel: <http://vocab.org/relationship/#>
prefix mo: <http://purl.org/ontology/mo/>
prefix timeline: <http://purl.org/NET/c4dm/timeline.owl#>
prefix event: <http://purl.org/NET/c4dm/event.owl#>
prefix foaf: <http://xmlns.com/foaf/0.1/>
prefix sim: <http://purl.org/ontology/sim/>

create iri class mbz:artist_iri  "http://zitgist.com/music/artist/%U" (in gid varchar not null) option (bijection) .
create iri class mbz:artist_birth_event_iri  "http://zitgist.com/music/artist/birth/%U" (in gid varchar not null) option (bijection) .
create iri class mbz:artist_death_event_iri  "http://zitgist.com/music/artist/death/%U" (in gid varchar not null) option (bijection) .
create iri class mbz:sim_link_iri  "http://zitgist.com/music/artist/simlink/%U" (in gid varchar not null) option (bijection) .

#create iri class mbz:band_iri  "http://zitgist.com/music/band/%U" (in gid varchar not null) option (bijection) .
#create iri class mbz:band_birth_event_iri  "http://zitgist.com/music/band/birth/%U" (in gid varchar not null) option (bijection) .
#create iri class mbz:band_death_event_iri  "http://zitgist.com/music/band/death/%U" (in gid varchar not null) option (bijection) .

create iri class mbz:record_iri  "http://zitgist.com/music/record/%U" (in gid varchar not null) option (bijection) .
create iri class mbz:performance_iri  "http://zitgist.com/music/performance/%U" (in gid varchar not null) option (bijection) .
create iri class mbz:composition_iri  "http://zitgist.com/music/composition/%U" (in gid varchar not null) option (bijection) .
create iri class mbz:musicalwork_iri  "http://zitgist.com/music/musicalwork/%U" (in gid varchar not null) option (bijection) .
create iri class mbz:sound_iri  "http://zitgist.com/music/sound/%U" (in gid varchar not null) option (bijection) .
create iri class mbz:recording_iri  "http://zitgist.com/music/recording/%U" (in gid varchar not null) option (bijection) .
create iri class mbz:signal_iri  "http://zitgist.com/music/signal/%U" (in gid varchar not null) option (bijection) .

create iri class mbz:track_iri  "http://zitgist.com/music/track/%U" (in gid varchar not null) option (bijection) .

create iri class mbz:image_iri  "http://ec1.images-amazon.com/images/P/%U.01.MZZZZZZZ.jpg" (in image varchar not null) option (bijection) .

create iri class mbz:amazon_asin_iri  "http://amazon.com/exec/obidos/ASIN/%U/searchcom07-20" (in gid varchar not null) option (bijection) .


create literal class mbz:created using
    function ZITGIST.MO.RECORD_CREATION_DATE (in datestring varchar) returns varchar,
    function ZITGIST.MO.RECORD_CREATION_DATE_INVERSE (in datestring varchar) returns varchar .

create iri class mbz:official_iri using
    function ZITGIST.MO.RECORD_ATTRIBUTE_OFFICIAL (in attributes varchar) returns varchar
    option (returns 'http://purl.org/ontology/mo/official') .

create iri class mbz:promotion_iri using
    function ZITGIST.MO.RECORD_ATTRIBUTE_PROMOTION (in attributes varchar) returns varchar
    option (returns 'http://purl.org/ontology/mo/promotion') .

create iri class mbz:bootleg_iri using
    function ZITGIST.MO.RECORD_ATTRIBUTE_BOOTLEG (in attributes varchar) returns varchar
    option (returns 'http://purl.org/ontology/mo/bootleg') .

create iri class mbz:album_iri using
    function ZITGIST.MO.RECORD_ATTRIBUTE_ALBUM (in attributes varchar) returns varchar
    option (returns 'http://purl.org/ontology/mo/album') .

create iri class mbz:single_iri using
    function ZITGIST.MO.RECORD_ATTRIBUTE_SINGLE (in attributes varchar) returns varchar
    option (returns 'http://purl.org/ontology/mo/single') .

create iri class mbz:ep_iri using
    function ZITGIST.MO.RECORD_ATTRIBUTE_EP (in attributes varchar) returns varchar
    option (returns 'http://purl.org/ontology/mo/ep') .

create iri class mbz:compilation_iri using
    function ZITGIST.MO.RECORD_ATTRIBUTE_COMPILATION (in attributes varchar) returns varchar
    option (returns 'http://purl.org/ontology/mo/compilation') .

create iri class mbz:soundtrack_iri using
    function ZITGIST.MO.RECORD_ATTRIBUTE_SOUNDTRACK (in attributes varchar) returns varchar
    option (returns 'http://purl.org/ontology/mo/soundtrack') .

create iri class mbz:spokenword_iri using
    function ZITGIST.MO.RECORD_ATTRIBUTE_SPOKENWORD (in attributes varchar) returns varchar
    option (returns 'http://purl.org/ontology/mo/spokenword') .

create iri class mbz:interview_iri using
    function ZITGIST.MO.RECORD_ATTRIBUTE_INTERVIEW (in attributes varchar) returns varchar
    option (returns 'http://purl.org/ontology/mo/interview') .

create iri class mbz:audiobook_iri using
    function ZITGIST.MO.RECORD_ATTRIBUTE_AUDIOBOOK (in attributes varchar) returns varchar
    option (returns 'http://purl.org/ontology/mo/audiobook') .

create iri class mbz:live_iri using
    function ZITGIST.MO.RECORD_ATTRIBUTE_LIVE (in attributes varchar) returns varchar
    option (returns 'http://purl.org/ontology/mo/live') .

create iri class mbz:remix_iri using
    function ZITGIST.MO.RECORD_ATTRIBUTE_REMIX (in attributes varchar) returns varchar
    option (returns 'http://purl.org/ontology/mo/remix') .

create iri class mbz:duration_iri  "http://zitgist.com/music/track/duration/%U" (in gid varchar not null) .

create literal class mbz:duration using
    function ZITGIST.MO.TRACK_DURATION (in duration integer) returns varchar ,
    function ZITGIST.MO.TRACK_DURATION_INVERSE (in durationXSD varchar) returns integer .

create iri class mbz:geoname_country_iri  "http://www.geonames.org/countries/#%U" (in country varchar not null) .

create iri class mbz:url_iri  "%s" (in url varchar not null) .
create iri class mbz:mbz_release_url_iri  "http://musicbrainz.org/release/%s.html" (in mbz_gid varchar not null) .
create iri class mbz:mbz_track_url_iri  "http://musicbrainz.org/track/%s.html" (in mbz_gid varchar not null) .
create iri class mbz:mbz_artist_url_iri  "http://musicbrainz.org/artist/%s.html" (in mbz_gid varchar not null) .
;

List of functions used to compute some IRI classes:

Note:These functions have been developed to handle some weird user cases of the Musicbrainz data model (like the Attritube column of the album table, etc).

create function ZITGIST.MO.TRACK_DURATION_INVERSE(in durationXSD varchar)
{
    return null;
};

create function ZITGIST.MO.TRACK_DURATION(in duration integer)
{
    declare minutes, seconds, milliseconds integer;

    minutes := ((duration / 1000) / 60);

    if(minutes >= 1)
    {
        minutes := cast(minutes as integer);
    }
    else
    {
        minutes := 0;
    }

    seconds := (duration / 1000) - (minutes * 60);

    if(seconds >= 1)
    {
        seconds := cast(seconds as integer);
    }

    milliseconds := duration - (seconds * 1000) - (minutes * 60000);

    return sprintf('PT%dM%dS', minutes, seconds);
}
;


create function ZITGIST.MO.RECORD_CREATION_DATE(in datestring varchar)
{
    return sprintf('%sT00:00:00Z', datestring);
};

create function ZITGIST.MO.RECORD_CREATION_DATE_INVERSE(in datestring varchar)
{
    declare pos integer;
    pos := locate('T00:00:00Z', datestring) - 1;
    return substring(datestring, 1, pos);
};


create function ZITGIST.MO.RECORD_ATTRIBUTE(in attribute integer, in attributes varchar)
{
    declare attributes_array any;

    attributes_array := split_and_decode(ltrim(rtrim(attributes, '}'), '{'), 0, '\0\0,');

    foreach(int attr in attributes_array) do
    {
        attr := cast(attr as integer);
        if(attr = attribute)
        {
            if(attr = 100) return 'http://purl.org/ontology/mo/official';
            if(attr = 101) return 'http://purl.org/ontology/mo/promotion';
            if(attr = 102) return 'http://purl.org/ontology/mo/bootleg';
            if(attr = 1)   return 'http://purl.org/ontology/mo/album';
            if(attr = 2)   return 'http://purl.org/ontology/mo/single';
            if(attr = 3)   return 'http://purl.org/ontology/mo/ep';
            if(attr = 4)   return 'http://purl.org/ontology/mo/compilation';
            if(attr = 5)   return 'http://purl.org/ontology/mo/soundtrack';
            if(attr = 6)   return 'http://purl.org/ontology/mo/spokenword';
            if(attr = 7)   return 'http://purl.org/ontology/mo/interview';
            if(attr = 8)   return 'http://purl.org/ontology/mo/audiobook';
            if(attr = 9)   return 'http://purl.org/ontology/mo/live';
            if(attr = 10)  return 'http://purl.org/ontology/mo/remix';
        }
    }
    return null;
}
;

create function ZITGIST.MO.RECORD_ATTRIBUTE_OFFICIAL(in attributes varchar)
{    return ZITGIST.MO.RECORD_ATTRIBUTE(100, attributes); }
;
create function ZITGIST.MO.RECORD_ATTRIBUTE_PROMOTION(in attributes varchar)
{    return ZITGIST.MO.RECORD_ATTRIBUTE(101, attributes);}
;
create function ZITGIST.MO.RECORD_ATTRIBUTE_BOOTLEG(in attributes varchar)
{    return ZITGIST.MO.RECORD_ATTRIBUTE(102, attributes);}
;
create function ZITGIST.MO.RECORD_ATTRIBUTE_ALBUM(in attributes varchar)
{    return ZITGIST.MO.RECORD_ATTRIBUTE(1, attributes);}
;
create function ZITGIST.MO.RECORD_ATTRIBUTE_SINGLE(in attributes varchar)
{    return ZITGIST.MO.RECORD_ATTRIBUTE(2, attributes);}
;
create function ZITGIST.MO.RECORD_ATTRIBUTE_EP(in attributes varchar)
{    return ZITGIST.MO.RECORD_ATTRIBUTE(3, attributes);}
;
create function ZITGIST.MO.RECORD_ATTRIBUTE_COMPILATION(in attributes varchar)
{    return ZITGIST.MO.RECORD_ATTRIBUTE(4, attributes);}
;
create function ZITGIST.MO.RECORD_ATTRIBUTE_SOUNDTRACK(in attributes varchar)
{    return ZITGIST.MO.RECORD_ATTRIBUTE(5, attributes);}
;
create function ZITGIST.MO.RECORD_ATTRIBUTE_SPOKENWORD(in attributes varchar)
{    return ZITGIST.MO.RECORD_ATTRIBUTE(6, attributes);}
;
create function ZITGIST.MO.RECORD_ATTRIBUTE_INTERVIEW(in attributes varchar)
{    return ZITGIST.MO.RECORD_ATTRIBUTE(7, attributes);}
;
create function ZITGIST.MO.RECORD_ATTRIBUTE_AUDIOBOOK(in attributes varchar)
{    return ZITGIST.MO.RECORD_ATTRIBUTE(8, attributes);}
;
create function ZITGIST.MO.RECORD_ATTRIBUTE_LIVE(in attributes varchar)
{    return ZITGIST.MO.RECORD_ATTRIBUTE(9, attributes);}
;
create function ZITGIST.MO.RECORD_ATTRIBUTE_REMIX(in attributes varchar)
{    return ZITGIST.MO.RECORD_ATTRIBUTE(10, attributes);}
;

Definition of the quad map patterns

This what creates the RDF triples from the musicbrainz relational database schema.

sparql
prefix mbz: <http://musibrainz.org/schemas/mbz#>
prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
prefix dc: <http://purl.org/dc/elements/1.1/>
prefix dcterms: <http://purl.org/dc/terms/>
prefix bio: <http://vocab.org/bio/0.1/#>
prefix rel: <http://vocab.org/relationship/#>
prefix mo: <http://purl.org/ontology/mo/>
prefix timeline: <http://purl.org/NET/c4dm/timeline.owl#>
prefix event: <http://purl.org/NET/c4dm/event.owl#>
prefix foaf: <http://xmlns.com/foaf/0.1/>
prefix sim: <http://purl.org/ontology/sim/>

create quad storage virtrdf:MBZROOT


#
# Defitions of the source tables from the mbz relational database and their joints.
#########

from ZITGIST.MO.track as track text literal name
from ZITGIST.MO.artist as track_artist
from ZITGIST.MO.puid as track_puid
from ZITGIST.MO.track as track_track
from ZITGIST.MO.url as track_url

from ZITGIST.MO.artist as track_artist_creator where (^{track.}^.artist = ^{track_artist_creator.}^.id)

from ZITGIST.MO.albumjoin as track_albumjoin where (^{track.}^.id = ^{track_albumjoin.}^.track)

from ZITGIST.MO.l_artist_track as l_artist_track2 where (^{track.}^.id = ^{l_artist_track2.}^.link1)
                                                      where (^{track_artist.}^.id = ^{l_artist_track2.}^.link0)


from ZITGIST.MO.puidjoin as puidjoin where (^{track.}^.id = ^{puidjoin.}^.track)
                                         where (^{puidjoin.}^.puid = ^{track_puid.}^.id)


from ZITGIST.MO.l_track_track as l_track_track where (^{track.}^.id = ^{l_track_track.}^.link0)
                                                   where (^{track_track.}^.id = ^{l_track_track.}^.link1)


from ZITGIST.MO.l_track_url as l_track_url where (^{track.}^.id = ^{l_track_url.}^.link0)
                                               where (^{track_url.}^.id = ^{l_track_url.}^.link1)



from ZITGIST.MO.album as album text literal name
from ZITGIST.MO.artist as album_artist
from ZITGIST.MO.album as album_album
from ZITGIST.MO.url as album_url
from ZITGIST.MO.country as album_release_country
from ZITGIST.MO.track as album_albumjoin_track

from ZITGIST.MO.artist as album_artist_creator where (^{album.}^.artist = ^{album_artist_creator.}^.id)

from ZITGIST.MO.album_amazon_asin as album_amazon_asin where (^{album.}^.id = ^{album_amazon_asin.}^.album)


from ZITGIST.MO.albumjoin as album_albumjoin where (^{album.}^.id = ^{album_albumjoin.}^.album)
                                                 where (^{album_albumjoin.}^.track = ^{album_albumj