"f25d084969b67902b9ee5874c162d165" . . "---++Virtuoso Tutorial Linked Data Views Script to set up your own instance\n\n\nuse DB;\n\ncreate procedure DB.DBA.exec_no_error (in expr varchar)\n{\n declare state, message, meta, result any;\n exec(expr, state, message, vector(), 0, meta, result);\n}\n;\n\n--GRANT SPARQL_UPDATE TO \"SPARQL\";\nGRANT SELECT ON \"WS\".\"WS\".\"SYS_DAV_RES\" TO \"SPARQL\";\nGRANT SELECT ON \"WS\".\"WS\".\"SYS_DAV_COL\" TO \"SPARQL\";\nGRANT SELECT ON \"WS\".\"WS\".\"SYS_DAV_PROP\" TO \"SPARQL\";\nGRANT SELECT ON \"DB\".\"DBA\".\"SYS_USERS\" TO \"SPARQL\";\nGRANT SELECT ON \"DB\".\"DBA\".\"TUT_SEARCH\" TO \"SPARQL\";\n\ncreate function DB.DBA.TUT_ID_TO_IRI(in _prefix varchar,in _id varchar)\n{\n declare iri, uriqa_host any;\n uriqa_host := cfg_item_value(virtuoso_ini_path(), 'URIQA','DefaultHost');\n iri := 'http://' || uriqa_host || '/tutorial_view/' || _prefix || '/' || _id || '#this';\n return sprintf ('http://%s/DAV/home/tutorial_view/RDFData/All/iid%%20(%d).rdf', uriqa_host, iri_id_num (iri_to_id (iri)));\n}\n;\n\ncreate function DB.DBA.TUT_IRI_TO_ID(in _iri varchar)\n{\n declare parts any;\n parts := sprintf_inverse (_iri, 'http://%s/DAV/home/tutorial_view/RDFData/All/iid (%d).rdf', 1 );\n if (parts is not null)\n {\n declare uriqa_host, iri any;\n uriqa_host := cfg_item_value(virtuoso_ini_path(), 'URIQA','DefaultHost');\n if (parts[0] = uriqa_host)\n {\n iri := id_to_iri(iri_id_from_num(parts[1]));\n parts := sprintf_inverse (iri, 'http://%s/tutorial_view/%s/%s#this', 1 );\n if (parts[0] = uriqa_host)\n {\n return parts[2];\n }\n }\n }\n return NULL;\n}\n;\n\ncreate function DB.DBA.POST_IRI (in _id integer) returns varchar\n{\n return TUT_ID_TO_IRI('Post', cast(_id as varchar));\n}\n;\n\ncreate function DB.DBA.POST_IRI_INVERSE (in _iri varchar) returns integer\n{\n return atoi(DB.DBA.TUT_IRI_TO_ID(_iri));\n};\n\ncreate function DB.DBA.SECTION_IRI (in _id integer) returns varchar\n{\n return TUT_ID_TO_IRI('Section', cast(_id as varchar));\n}\n;\n\ncreate function DB.DBA.SECTION_IRI_INVERSE (in _iri varchar) returns integer\n{\n return atoi(DB.DBA.TUT_IRI_TO_ID(_iri));\n};\n\ngrant execute on DB.DBA.POST_IRI to \"SPARQL\";\ngrant execute on DB.DBA.POST_IRI_INVERSE to \"SPARQL\";\ngrant execute on DB.DBA.COL_IRI to \"SPARQL\";\ngrant execute on DB.DBA.COL_IRI_INVERSE to \"SPARQL\";\n\nSPARQL drop quad map graph iri(\"http://^{URIQADefaultHost}^/tutorial_view\") .\n;\n\nSPARQL drop quad map virtrdf:tutorial .\n;\n\nSPARQL\nprefix tutorial: \nprefix bibo: \nprefix oplsioc: \nprefix rdfs: \nprefix sioc: \nprefix foaf: \nprefix owl: \ncreate iri class tutorial:Post \"http://^{URIQADefaultHost}^/tutorial_view/Post/%d/%U#this\" (in post_id integer not null, in post_name varchar not null) .\ncreate iri class tutorial:Section \"http://^{URIQADefaultHost}^/tutorial_view/Section/%d/%U#this\" (in col_id integer not null, in col_name varchar not null) .\ncreate iri class tutorial:DocPath \"http://^{URIQADefaultHost}^%U#this\" (in prop_name varchar not null) .\n;\n\nSPARQL\nprefix tutorial: \nprefix bibo: \nprefix oplsioc: \nprefix rdfs: \nprefix sioc: \nprefix foaf: \nprefix owl: \ncreate iri class tutorial:post_iri using\n function DB.DBA.POST_IRI (in customer_id integer) returns varchar,\n function DB.DBA.POST_IRI_INVERSE (in customer_iri varchar) returns integer.\ncreate iri class tutorial:section_iri using\n function DB.DBA.SECTION_IRI (in customer_id integer) returns varchar,\n function DB.DBA.SECTION_IRI_INVERSE (in customer_iri varchar) returns integer.\n;\n\nSPARQL\nprefix tutorial: \nprefix bibo: \nprefix oplsioc: \nprefix rdfs: \nprefix sioc: \nprefix foaf: \nprefix owl: \nalter quad storage virtrdf:DefaultQuadStorage\nfrom WS.WS.SYS_DAV_RES as resources text literal RES_CONTENT\nfrom WS.WS.SYS_DAV_COL as collections\nfrom DB.DBA.SYS_USERS as users\nwhere (^{collections.}^.COL_ID = ^{resources.}^.RES_COL)\nwhere (^{resources.}^.RES_FULL_PATH LIKE '/DAV/VAD/tutorial/%')\nwhere (DB.DBA.DAV_SEARCH_PATH(^{collections.}^.COL_ID, 'c') LIKE '/DAV/VAD/tutorial/%')\n{\n create virtrdf:tutorial as graph iri (\"http://^{URIQADefaultHost}^/tutorial_view\") option (exclusive)\n {\n tutorial:Post (resources.RES_ID, resources.RES_NAME)\n a tutorial:Post\n as virtrdf:tutPost-RES_ID ;\n a foaf:Document\n as virtrdf:tutsiocPost-RES_ID;\n a bibo:Article\n as virtrdf:tutBiboPost-RES_ID ;\n foaf:primaryTopic tutorial:Post (resources.RES_ID, resources.RES_NAME) ;\n bibo:identifier resources.RES_NAME\n as virtrdf:tutPost-RES_NAME ;\n bibo:author users.U_NAME\n where (^{resources.}^.RES_OWNER = ^{users.}^.U_ID)\n as virtrdf:tutPost-RES_OWNER ;\n tutorial:belongs_to_section tutorial:Section(collections.COL_ID, collections.COL_NAME)\n where (^{resources.}^.RES_COL = ^{collections.}^.COL_ID)\n as virtrdf:tutPost-RES_COL ;\n sioc:content resources.RES_CONTENT\n as virtrdf:tutPost-RES_CONTENT ;\n sioc:description resources.RES_NAME\n as virtrdf:tutsiocPost-RES_NAME ;\n tutorial:type resources.RES_TYPE\n as virtrdf:tutPost-RES_TYPE ;\n bibo:presentedAt resources.RES_CR_TIME\n as virtrdf:tutPost-RES_CR_TIME ;\n bibo:url tutorial:DocPath(resources.RES_FULL_PATH)\n as virtrdf:tutPost-RES_FULL_PATH ;\n rdfs:isDefinedBy tutorial:post_iri (resources.RES_ID) ;\n rdfs:isDefinedBy tutorial:Post (resources.RES_ID, resources.RES_NAME) ;\n rdfs:seeAlso tutorial:Section(collections.COL_ID, collections.COL_NAME)\n where (^{resources.}^.RES_COL = ^{collections.}^.COL_ID)\n as virtrdf:tutPost-RES_COL2.\n\n tutorial:DocPath(resources.RES_FULL_PATH)\n a tutorial:DocPath\n as virtrdf:tutDocPath-RES_FULL_PATH .\n\n tutorial:Section (collections.COL_ID, collections.COL_NAME)\n a tutorial:Section\n as virtrdf:tutSection-COL_ID ;\n a sioc:Container\n as virtrdf:tutsiocSection-COL_ID ;\n a bibo:Collection\n as virtrdf:tutBiboSection-COL_ID ;\n bibo:identifier collections.COL_NAME\n as virtrdf:tutSection-COL_NAME ;\n bibo:author users.U_NAME\n where (^{collections.}^.COL_OWNER = ^{users.}^.U_ID)\n as virtrdf:tutSection-COL_OWNER ;\n rdfs:isDefinedBy tutorial:section_iri (collections.COL_ID) ;\n rdfs:isDefinedBy tutorial:Section (collections.COL_ID, collections.COL_NAME) .\n\n tutorial:Section (collections.COL_ID, collections.COL_NAME)\n sioc:is_container_of\n tutorial:Post(resources.RES_ID, resources.RES_NAME)\n where (^{resources.}^.RES_COL = ^{collections.}^.COL_ID)\n as virtrdf:tutsiocSection-COL_ID2 .\n\n } .\n} .\n;\n\ndelete from db.dba.url_rewrite_rule_list where urrl_list like 'tutorial_%';\ndelete from db.dba.url_rewrite_rule where urr_rule like 'tutorial_%';\n\ncreate procedure tutorial_rdf_doc (in path varchar)\n{\n declare r any;\n r := regexp_match ('[^/]*\\x24', path);\n return r||'#this';\n};\n\ncreate procedure tutorial_html_doc (in path varchar)\n{\n declare r any;\n r := regexp_match ('[^/]*#', path);\n return subseq (r, 0, length (r)-1);\n};\n\nDB.DBA.URLREWRITE_CREATE_REGEX_RULE (\n 'tutorial_rule2',\n 1,\n '(/[^#]*)',\n vector('path'),\n 1,\n '/sparql?query=CONSTRUCT+{+%%3Chttp%%3A//^{URIQADefaultHost}^%U%%23this%%3E+%%3Fp+%%3Fo+}+FROM+%%3Chttp%%3A//^{URIQADefaultHost}^/tutorial_view%%3E+WHERE+{+%%3Chttp%%3A//^{URIQADefaultHost}^%U%%23this%%3E+%%3Fp+%%3Fo+}&format=%U',\n vector('path', 'path', '*accept*'),\n null,\n '(text/rdf.n3)|(application/rdf.xml)',\n 0,\n null\n );\n\n--DB.DBA.URLREWRITE_CREATE_REGEX_RULE (\n-- 'tutorial_rule1',\n-- 1,\n-- '(/[^#]*)',\n-- vector('path'),\n-- 1,\n-- '/rdfbrowser/index.html?uri=http%%3A//^{URIQADefaultHost}^%U%%23this',\n-- vector('path'),\n-- null,\n-- '(text/html)|(\\\\*/\\\\*)',\n-- 0,\n-- 303\n-- );\n\nDB.DBA.exec_no_error('\nDB.DBA.URLREWRITE_DROP_RULELIST (\\'tutorial_rule_list1\\')\n');\n\nDB.DBA.exec_no_error('\nDB.DBA.URLREWRITE_DROP_RULE (\\'tutorial_rule1\\')\n');\n\n\nDB.DBA.URLREWRITE_CREATE_REGEX_RULE (\n 'tutorial_rule3',\n 1,\n '(/[^#]*)/\\x24',\n vector('path'),\n 1,\n '%s',\n vector('path'),\n null,\n null,\n 0,\n null\n );\n\ncreate procedure DB.DBA.REMOVE_TUT_RDF_DET()\n{\n declare colid int;\n colid := DAV_SEARCH_ID('/DAV/home/tutorial_view/', 'C');\n if (colid < 0)\n return;\n update WS.WS.SYS_DAV_COL set COL_DET=null where COL_ID = colid;\n}\n;\n\nDB.DBA.REMOVE_TUT_RDF_DET();\n\ndrop procedure DB.DBA.REMOVE_TUT_RDF_DET;\n\ncreate procedure DB.DBA.TUT_MAKE_RDF_DET()\n{\n declare uriqa_str varchar;\n uriqa_str := cfg_item_value(virtuoso_ini_path(), 'URIQA','DefaultHost');\n uriqa_str := 'http://' || uriqa_str || '/tutorial_view';\n DB.DBA.\"RDFData_MAKE_DET_COL\" ('/DAV/home/tutorial_view/RDFData/', uriqa_str, NULL);\n VHOST_REMOVE (lpath=>'/tutorial_view/data/rdf');\n DB.DBA.VHOST_DEFINE (lpath=>'/tutorial_view/data/rdf', ppath=>'/DAV/home/tutorial_view/RDFData/All/', is_dav=>1, vsp_user=>'dba');\n}\n;\n\nDB.DBA.TUT_MAKE_RDF_DET();\n\ndrop procedure DB.DBA.TUT_MAKE_RDF_DET;\n\n-- procedure to convert path to DET resource name\ncreate procedure DB.DBA.TUT_DET_REF (in par varchar, in fmt varchar, in val varchar)\n{\n declare res, iri any;\n declare uriqa_str varchar;\n uriqa_str := cfg_item_value(virtuoso_ini_path(), 'URIQA','DefaultHost');\n uriqa_str := 'http://' || uriqa_str || '/tutorial_view';\n iri := uriqa_str || val;\n res := sprintf ('iid (%d).rdf', iri_id_num (iri_to_id (iri)));\n return sprintf (fmt, res);\n}\n;\n\nDB.DBA.URLREWRITE_CREATE_REGEX_RULE ('tutorial_rdf', 1,\n '/tutorial_view/(.*)', vector('path'), 1,\n '/tutorial_view/data/rdf/%U', vector('path'),\n 'DB.DBA.TUT_DET_REF',\n 'application/rdf.xml',\n 2,\n 303);\n\nDB.DBA.URLREWRITE_CREATE_REGEX_RULE (\n 'tutorial_rule4',\n 1,\n '/schemas/tutorial#(.*)',\n vector('path'),\n 1,\n '/sparql?query=DESCRIBE%20%3Chttp%3A//demo.openlinksw.com/schemas/tutorial%23%U%3E%20FROM%20%3Chttp%3A//demo.openlinksw.com/schemas/TutOntology/1.0/%3E',\n vector('path'),\n null,\n '(text/rdf.n3)|(application/rdf.xml)',\n 0,\n null\n );\n\nDB.DBA.URLREWRITE_CREATE_RULELIST (\n 'tutorial_rule_list1',\n 1,\n vector (\n 'tutorial_rule2',\n 'tutorial_rule3',\n 'tutorial_rule4',\n 'tutorial_rdf'\n ));\n\n\nVHOST_REMOVE (lpath=>'/tutorial_view');\nDB.DBA.VHOST_DEFINE (lpath=>'/tutorial_view', ppath=>'/DAV/home/tutorial_view/', vsp_user=>'dba', is_dav=>1, def_page=>'sfront.vspx',\n is_brws=>0, opts=>vector ('url_rewrite', 'tutorial_rule_list1'));\n\ncreate procedure DB.DBA.LOAD_TUT_ONTOLOGY_FROM_DAV()\n{\n declare content1, urihost varchar;\n whenever not found goto none;\n select cast (RES_CONTENT as varchar) into content1 from WS.WS.SYS_DAV_RES where RES_FULL_PATH = '/DAV/VAD/tutorial/tutorial.owl';\n DB.DBA.RDF_LOAD_RDFXML (content1, 'http://demo.openlinksw.com/schemas/tutorial#', 'http://demo.openlinksw.com/schemas/TutOntology/1.0/');\n urihost := cfg_item_value(virtuoso_ini_path(), 'URIQA','DefaultHost');\n if (urihost = 'demo.openlinksw.com')\n {\n DB.DBA.VHOST_REMOVE (lpath=>'/schemas/tutorial');\n DB.DBA.VHOST_DEFINE (lpath=>'/schemas/tutorial', ppath=>'/DAV/VAD/tutorial/tutorial.owl', vsp_user=>'dba', is_dav=>1, is_brws=>0);\n DB.DBA.VHOST_REMOVE (lpath=>'/schemas/tutorial#');\n DB.DBA.VHOST_DEFINE (lpath=>'/schemas/tutorial#', ppath=>'/DAV/VAD/tutorial/tutorial.owl', vsp_user=>'dba', is_dav=>1, is_brws=>0);\n }\n none:\n ;\n};\n\nDB.DBA.LOAD_TUT_ONTOLOGY_FROM_DAV();\n\ndrop procedure DB.DBA.LOAD_TUT_ONTOLOGY_FROM_DAV;\n\ncreate procedure DB.DBA.LOAD_TUT_ONTOLOGY_FROM_DAV2()\n{\n declare urihost varchar;\n whenever not found goto none;\n sparql base load bif:concat (\"http://\", bif:registry_get(\"URIQADefaultHost\"), \"/DAV/VAD/tutorial/tutorial.owl\")\n into graph ;\n urihost := cfg_item_value(virtuoso_ini_path(), 'URIQA','DefaultHost');\n if (urihost = 'demo.openlinksw.com')\n {\n DB.DBA.VHOST_REMOVE (lpath=>'/schemas/tutorial');\n DB.DBA.VHOST_DEFINE (lpath=>'/schemas/tutorial', ppath=>'/DAV/VAD/tutorial/tutorial.owl', vsp_user=>'dba', is_dav=>1, is_brws=>0);\n DB.DBA.VHOST_REMOVE (lpath=>'/schemas/tutorial#');\n DB.DBA.VHOST_DEFINE (lpath=>'/schemas/tutorial#', ppath=>'/DAV/VAD/tutorial/tutorial.owl', vsp_user=>'dba', is_dav=>1, is_brws=>0);\n }\n none:\n ;\n};\n\n--DB.DBA.LOAD_TUT_ONTOLOGY_FROM_DAV2();\n\ndrop procedure DB.DBA.LOAD_TUT_ONTOLOGY_FROM_DAV2;\n\n\n---+++References\n\n * [[SIOCRefTutorial][Virtuoso Tutorials SIOC Reference]]" . . . . . . "2017-06-13T05:46:13Z" . "VirtRDFViewTutorialScript" . . "VirtRDFViewTutorialScript" . . "VirtRDFViewTutorialScript" . . . "2017-06-13T05:46:13.590106"^^ . . "2017-06-13T05:46:13.590106"^^ . . . . "2017-06-13T05:46:13Z" .