grant select on "csv"."crunchbase"."organizations" to SPARQL_SELECT;


SPARQL
prefix csv: <http://demo.openlinksw.com/schemas/csv/> 
create iri class csv:organizations "http://^{URIQADefaultHost}^/csv/organizations/crunchbase_uuid/%U#this" (in _crunchbase_uuid varchar not null) . ;


drop view "csv"."crunchbase"."csv__Total"; 
create view "csv"."crunchbase"."csv__Total" as select (cnt0*cnt1) AS cnt from 
 (select count(*) cnt0 from "csv"."crunchbase"."organizations") tb0, 
 (select count(*)+1 as cnt1 from DB.DBA.TABLE_COLS where "TABLE" = 'csv.crunchbase.organizations'  and "COLUMN" <> '_IDN') tb1
; 
grant select on "csv"."crunchbase"."csv__Total" to SPARQL_SELECT; 


SPARQL
prefix csv: <http://demo.openlinksw.com/schemas/csv/> 
prefix csv-stat: <http://demo.openlinksw.com/csv/stat#> 
prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> 
prefix void: <http://rdfs.org/ns/void#> 
prefix scovo: <http://purl.org/NET/scovo#> 
prefix aowl: <http://bblfish.net/work/atom-owl/2006-06-06/> 
alter quad storage virtrdf:DefaultQuadStorage 
 from "csv"."crunchbase"."organizations" as organizations_s
 { 
   create csv:qm-organizations as graph iri ("http://^{URIQADefaultHost}^/csv#")  
    { 
      # Maps from columns of "csv.crunchbase.organizations"
      csv:organizations (organizations_s."crunchbase_uuid")  a csv:organizations ;
      csv:crunchbase_uuid organizations_s."crunchbase_uuid" as csv:crunchbase-organizations-crunchbase_uuid ;
      csv:type organizations_s."type" as csv:crunchbase-organizations-type ;
      csv:primary_role organizations_s."primary_role" as csv:crunchbase-organizations-primary_role ;
      csv:name organizations_s."name" as csv:crunchbase-organizations-name ;
      csv:crunchbase_url organizations_s."crunchbase_url" as csv:crunchbase-organizations-crunchbase_url ;
      csv:homepage_domain organizations_s."homepage_domain" as csv:crunchbase-organizations-homepage_domain ;
      csv:homepage_url organizations_s."homepage_url" as csv:crunchbase-organizations-homepage_url ;
      csv:profile_image_url organizations_s."profile_image_url" as csv:crunchbase-organizations-profile_image_url ;
      csv:facebook_url organizations_s."facebook_url" as csv:crunchbase-organizations-facebook_url ;
      csv:twitter_url organizations_s."twitter_url" as csv:crunchbase-organizations-twitter_url ;
      csv:linkedin_url organizations_s."linkedin_url" as csv:crunchbase-organizations-linkedin_url ;
      csv:stock_symbol organizations_s."stock_symbol" as csv:crunchbase-organizations-stock_symbol ;
      csv:location_city organizations_s."location_city" as csv:crunchbase-organizations-location_city ;
      csv:location_region organizations_s."location_region" as csv:crunchbase-organizations-location_region ;
      csv:location_country_code organizations_s."location_country_code" as csv:crunchbase-organizations-location_country_code ;
      csv:short_description organizations_s."short_description" as csv:crunchbase-organizations-short_description .

    }
 }

;

SPARQL
prefix csv: <http://demo.openlinksw.com/schemas/csv/> 
prefix csv-stat: <http://demo.openlinksw.com/csv/stat#> 
prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> 
prefix void: <http://rdfs.org/ns/void#> 
prefix scovo: <http://purl.org/NET/scovo#> 
prefix aowl: <http://bblfish.net/work/atom-owl/2006-06-06/> 
alter quad storage virtrdf:DefaultQuadStorage 
 from "csv"."crunchbase"."organizationsCount" as organizationscount_s
 from "csv"."crunchbase"."csv__Total" as csv__total_s
 { 
   create csv:qm-VoidStatistics as graph iri ("http://^{URIQADefaultHost}^/csv#") option (exclusive) 
    { 
      # voID Statistics 
      csv-stat: a void:Dataset as csv:dataset-csv ; 
       void:sparqlEndpoint <http://demo.openlinksw.com/sparql> as csv:dataset-sparql-csv ; 
      void:statItem csv-stat:Stat . 
      csv-stat:Stat a scovo:Item ; 
       rdf:value csv__total_s.cnt as csv:stat-decl-csv ; 
       scovo:dimension void:numOfTriples . 

      csv-stat: void:statItem csv-stat:organizationsStat as csv:statitem-csv-organizations . 
      csv-stat:organizationsStat a scovo:Item as csv:statitem-decl-csv-organizations ; 
      rdf:value organizationscount_s.cnt as csv:statitem-cnt-csv-organizations ; 
      scovo:dimension void:numberOfResources as csv:statitem-type-1-csv-organizations ; 
      scovo:dimension csv:organizations as csv:statitem-type-2-csv-organizations .

    }
 }
;



-- Virtual directories for instance data
DB.DBA.URLREWRITE_CREATE_REGEX_RULE (
'csv_rule2',
1,
'(/[^#]*)',
vector('path'),
1,
'/sparql?query=DESCRIBE+%%3Chttp%%3A//^{URIQADefaultHost}^%U%%23this%%3E+FROM+%%3Chttp%%3A//^{URIQADefaultHost}^/csv%%23%%3E&format=%U',
vector('path', '*accept*'),
null,
'(text/rdf.n3)|(application/rdf.xml)|(text/n3)|(application/json)',
2,
null
);
DB.DBA.URLREWRITE_CREATE_REGEX_RULE (
'csv_rule4',
1,
'/csv/stat([^#]*)',
vector('path'),
1,
'/sparql?query=DESCRIBE+%%3Chttp%%3A//^{URIQADefaultHost}^/csv/stat%%23%%3E+%%3Fo+FROM+%%3Chttp%%3A//^{URIQADefaultHost}^/csv%%23%%3E+WHERE+{+%%3Chttp%%3A//^{URIQADefaultHost}^/csv/stat%%23%%3E+%%3Fp+%%3Fo+}&format=%U',
vector('*accept*'),
null,
'(text/rdf.n3)|(application/rdf.xml)|(text/n3)|(application/json)',
2,
null
);
DB.DBA.URLREWRITE_CREATE_REGEX_RULE (
'csv_rule6',
1,
'/csv/objects/([^#]*)',
vector('path'),
1,
'/sparql?query=DESCRIBE+%%3Chttp%%3A//^{URIQADefaultHost}^/csv/objects/%U%%3E+FROM+%%3Chttp%%3A//^{URIQADefaultHost}^/csv%%23%%3E&format=%U',
vector('path', '*accept*'),
null,
'(text/rdf.n3)|(application/rdf.xml)|(text/n3)|(application/json)',
2,
null
);
DB.DBA.URLREWRITE_CREATE_REGEX_RULE (
'csv_rule1',
1,
'([^#]*)',
vector('path'),
1,
'/describe/?url=http%%3A//^{URIQADefaultHost}^%U%%23this&graph=http%%3A//^{URIQADefaultHost}^/csv%%23&distinct=0',
vector('path'),
null,
null,
2,
303
);
DB.DBA.URLREWRITE_CREATE_REGEX_RULE (
'csv_rule7',
1,
'/csv/stat([^#]*)',
vector('path'),
1,
'/describe/?url=http%%3A//^{URIQADefaultHost}^/csv/stat%%23&graph=http%%3A//^{URIQADefaultHost}^/csv%%23',
vector('path'),
null,
null,
2,
303
);
DB.DBA.URLREWRITE_CREATE_REGEX_RULE (
'csv_rule5',
1,
'/csv/objects/(.*)',
vector('path'),
1,
'/services/rdf/object.binary?path=%%2Fcsv%%2Fobjects%%2F%U&accept=%U',
vector('path', '*accept*'),
null,
null,
2,
null
);
DB.DBA.URLREWRITE_CREATE_RULELIST ( 'csv_rule_list1', 1, vector ( 'csv_rule1', 'csv_rule7', 'csv_rule5', 'csv_rule2', 'csv_rule4', 'csv_rule6'));
DB.DBA.VHOST_REMOVE (lpath=>'/csv');
DB.DBA.VHOST_DEFINE (lpath=>'/csv', ppath=>'/', vsp_user=>'dba', is_dav=>0,
is_brws=>0, opts=>vector ('url_rewrite', 'csv_rule_list1')
);

-- Virtual directories for ontology
DB.DBA.URLREWRITE_CREATE_REGEX_RULE (
'csv_owl_rule2',
1,
'(/[^#]*)',
vector('path'),
1,
'/sparql?query=DESCRIBE+%%3Chttp%%3A//^{URIQADefaultHost}^%U%%3E+FROM+%%3Chttp%%3A//^{URIQADefaultHost}^/schemas/csv%%23%%3E&format=%U',
vector('path', '*accept*'),
null,
'(text/rdf.n3)|(application/rdf.xml)|(text/n3)|(application/json)',
2,
null
);
DB.DBA.URLREWRITE_CREATE_REGEX_RULE (
'csv_owl_rule1',
1,
'([^#]*)',
vector('path'),
1,
'/describe/?url=http://^{URIQADefaultHost}^%U',
vector('path'),
null,
null,
2,
303
);
DB.DBA.URLREWRITE_CREATE_RULELIST ( 'csv_owl_rule_list1', 1, vector ( 'csv_owl_rule1', 'csv_owl_rule2'));
DB.DBA.VHOST_REMOVE (lpath=>'/schemas/csv');
DB.DBA.VHOST_DEFINE (lpath=>'/schemas/csv', ppath=>'/', vsp_user=>'dba', is_dav=>0,
is_brws=>0, opts=>vector ('url_rewrite', 'csv_owl_rule_list1')
);