-- Cleanup 
-- Inference Basis: schema:SoftwareApplication owl:disjointWith oplprod:ProductRelease .

-- Named Graphs
SPARQL CLEAR GRAPH <urn:website:new2018:rules:def> ;
SPARQL CLEAR GRAPH <urn:website:new> ; 
SPARQL CLEAR GRAPH <urn:apps:releases> ;

-- Built-in Inference Rule 

DELETE FROM sys_rdf_schema 
WHERE rs_name = 'urn:website:new2018:rules';



-- Define the rules
SPARQL
PREFIX owl: <http://www.w3.org/2002/07/owl#>
PREFIX oplfeat: <http://www.openlinksw.com/ontology/features#>
PREFIX oplben:  <http://www.openlinksw.com/ontology/benefits#>
PREFIX oplsoft: <http://www.openlinksw.com/ontology/software#>
PREFIX oplprod: <http://www.openlinksw.com/ontology/products#>
PREFIX schema: <http://schema.org/>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX virtuoso: <http://data.openlinksw.com/oplweb/product/Virtuoso#>
PREFIX cs: <http://data.openlinksw.com/oplweb/product/column-store-cl#>
PREFIX rs: <http://data.openlinksw.com/oplweb/product/row-store-cl#>
PREFIX rsn: <http://data.openlinksw.com/oplweb/product/row-store-sn#>
PREFIX v70: <http://data.openlinksw.com/oplweb/product_release/VirtuosoRelease70x#>
PREFIX v80: <http://data.openlinksw.com/oplweb/product_release/VirtuosoRelease8x#>
PREFIX vrscloud: <http://Data.Openlinksw.com/Oplweb/Product_release/VirtuosoReleaseRowStoreClusterCloud64x#>
PREFIX vrscloudss: <http://data.openlinksw.com/oplweb/product_release/VirtuosoReleaseRowStoreSingle64x#>

INSERT DATA {
				GRAPH <urn:website:new2018:rules:def>
				{
					rdfs:subPropertyOf a owl:TransitiveProperty .
					rdfs:subClassOf a owl:TransitiveProperty .						
					oplprod:ProductRelease rdfs:subClassOf schema:SoftwareApplication .
					
				}
				
				GRAPH <urn:website:new> 
				   {
						# oplprod:ProductRelease rdfs:subClassOf schema:SoftwareApplication .
						
						cs:this a oplprod:ProductRelease .

						rs:this a oplprod:ProductRelease .
						rsn:this a oplprod:ProductRelease .
						v70:this a oplprod:ProductRelease .
						v80:this a oplprod:ProductRelease .
						vrscloud:this a oplprod:ProductRelease .
						vrscloudss:this a oplprod:ProductRelease .

						virtuoso:this
						a schema:SoftwareApplication ;
						oplprod:hasRelease cs:this, rs:this, rsn:this, v70:this, v80:this, vrscloud:this, vrscloudss:this .
				  }
				  
		};
		
COMMIT WORK;

SPARQL

PREFIX owl: <http://www.w3.org/2002/07/owl#>
PREFIX oplfeat: <http://www.openlinksw.com/ontology/features#>
PREFIX oplben:  <http://www.openlinksw.com/ontology/benefits#>
PREFIX oplsoft: <http://www.openlinksw.com/ontology/software#>
PREFIX oplprod: <http://www.openlinksw.com/ontology/products#>

INSERT 
	{ GRAPH <urn:apps:releases> 
		{
		  ?s a oplprod:ProductRelease ;
          	 oplfeat:hasFeature ?feat . 
		}
	}
WHERE
  {
  	SELECT ?s ?feat
	FROM <http://oplussol11.intranet.openlinksw.com:8890/DAV/home/thaynes/Public/NewWebsite/website-data-bootstrap2018.ttl>
	WHERE {
			?s a oplprod:ProductRelease ;
	           oplfeat:hasFeature ?feat . 
		  }

	} ;

COMMIT WORK ;

-- Ensuring there are no schema:SoftwareApplication instances 
-- as these are to be materialized via inference rule invocation

SPARQL

WITH <urn:apps:releases> 
DELETE { ?s a schema:SoftwareApplication . } ;

COMMIT WORK;


-- Rules Setup

RDFS_RULE_SET ('urn:website:new2018:rules', 'urn:website:new2018:rules:def') ;
COMMIT work;

-- Confirm Rule Creation
SELECT * FROM sys_rdf_schema 
WHERE rs_name = 'urn:website:new2018:rules';


-- Test Query 1

SPARQL
 
DEFINE input:inference 'urn:website:new2018:rules'

PREFIX owl: <http://www.w3.org/2002/07/owl#>
PREFIX oplfeat: <http://www.openlinksw.com/ontology/features#>
PREFIX oplben:  <http://www.openlinksw.com/ontology/benefits#>
PREFIX oplsoft: <http://www.openlinksw.com/ontology/software#>
PREFIX oplprod: <http://www.openlinksw.com/ontology/products#>

SELECT DISTINCT  COUNT(*) AS ?count
## SELECT DISTINCT  ?prod oplfeat:hasFeature ?feat
FROM <urn:website:new> 
FROM <urn:apps:releases> 
# FROM <http://oplussol11.intranet.openlinksw.com:8890/DAV/home/thaynes/Public/NewWebsite/website-data-bootstrap2018.ttl>
WHERE {
		?app a schema:SoftwareApplication . 
	  };

-- Test Query 2

SPARQL 
# DEFINE input:inference 'urn:website:new2018:rules'

PREFIX owl: <http://www.w3.org/2002/07/owl#>
PREFIX oplfeat: <http://www.openlinksw.com/ontology/features#>
PREFIX oplben:  <http://www.openlinksw.com/ontology/benefits#>
PREFIX oplsoft: <http://www.openlinksw.com/ontology/software#>
PREFIX oplprod: <http://www.openlinksw.com/ontology/products#>

SELECT DISTINCT  COUNT(*) AS ?count 
## SELECT DISTINCT  ?prod oplfeat:hasFeature ?feat
FROM <urn:website:new> 
FROM <urn:apps:releases> 
# FROM <http://oplussol11.intranet.openlinksw.com:8890/DAV/home/thaynes/Public/NewWebsite/website-data-bootstrap2018.ttl>
WHERE {
		?app a schema:SoftwareApplication . 
	  };


-- Test Query 3

SPARQL
 
DEFINE input:inference 'urn:website:new2018:rules'

PREFIX owl: <http://www.w3.org/2002/07/owl#>
PREFIX oplfeat: <http://www.openlinksw.com/ontology/features#>
PREFIX oplben:  <http://www.openlinksw.com/ontology/benefits#>
PREFIX oplsoft: <http://www.openlinksw.com/ontology/software#>
PREFIX oplprod: <http://www.openlinksw.com/ontology/products#>


## SELECT DISTINCT  COUNT(*) AS ?count
SELECT DISTINCT  ?app oplfeat:hasFeature as ?relation ?feat
FROM <urn:website:new> 
FROM <urn:apps:releases> 
# FROM <http://oplussol11.intranet.openlinksw.com:8890/DAV/home/thaynes/Public/NewWebsite/website-data-bootstrap2018.ttl>
WHERE {
		?app a schema:SoftwareApplication ;
		   oplfeat:hasFeature ?feat .
	  } ;


-- Test Query 4

SPARQL 

# DEFINE input:inference 'urn:website:new2018:rules'

PREFIX owl: <http://www.w3.org/2002/07/owl#>
PREFIX oplfeat: <http://www.openlinksw.com/ontology/features#>
PREFIX oplben:  <http://www.openlinksw.com/ontology/benefits#>
PREFIX oplsoft: <http://www.openlinksw.com/ontology/software#>
PREFIX oplprod: <http://www.openlinksw.com/ontology/products#>


## SELECT DISTINCT  COUNT(*) AS ?count
SELECT DISTINCT  ?app oplfeat:hasFeature as ?relation ?feat
FROM <urn:website:new> 
FROM <urn:apps:releases> 
# FROM <http://oplussol11.intranet.openlinksw.com:8890/DAV/home/thaynes/Public/NewWebsite/website-data-bootstrap2018.ttl>
WHERE {
		?app a schema:SoftwareApplication ;
		   oplfeat:hasFeature ?feat .
	  } ;


-- Test Query 5

SPARQL

DEFINE input:inference 'urn:website:new2018:rules'

PREFIX oplfeat: <http://www.openlinksw.com/ontology/features#>
PREFIX oplben:  <http://www.openlinksw.com/ontology/benefits#>
PREFIX oplsoft: <http://www.openlinksw.com/ontology/software#>
PREFIX oplprod: <http://www.openlinksw.com/ontology/products#>
PREFIX schema: <http://schema.org/>

SELECT sample(?app) as ?sample count(1) as ?count ?type
FROM <urn:website:new> 
FROM <urn:apps:releases> 
# FROM <http://oplussol11.intranet.openlinksw.com:8890/DAV/home/thaynes/Public/NewWebsite/website-data-bootstrap2018.ttl>
WHERE {
       ?app a ?type. 
       filter (?type in (schema:SoftwareApplication, oplprod:ProductRelease)) 
      }
GROUP BY ?type
ORDER BY desc(?count) ;


-- Test Query 6

SPARQL

# DEFINE input:inference 'urn:website:new2018:rules'

PREFIX oplfeat: <http://www.openlinksw.com/ontology/features#>
PREFIX oplben:  <http://www.openlinksw.com/ontology/benefits#>
PREFIX oplsoft: <http://www.openlinksw.com/ontology/software#>
PREFIX oplprod: <http://www.openlinksw.com/ontology/products#>
PREFIX schema: <http://schema.org/>

SELECT sample(?app) as ?sample count(1) as ?count ?type
FROM <urn:website:new> 
FROM <urn:apps:releases> 
# FROM <http://oplussol11.intranet.openlinksw.com:8890/DAV/home/thaynes/Public/NewWebsite/website-data-bootstrap2018.ttl>
WHERE {
       ?app a ?type. 
       filter (?type in (schema:SoftwareApplication, oplprod:ProductRelease)) 
      }
GROUP BY ?type
ORDER BY desc(?count) ;

