Graph Developers Guide Rdf Graph
Graph Developers Guide Rdf Graph
23c
F46994-03
July 2023
Oracle Database Graph Developer's Guide for RDF Graph, 23c
F46994-03
Contributors: Melliyal Annamalai , Maitreyee Chaliha, Chuck Murray, Eugene Inseok Chong, Souri Das, Joao
Paiva, Matt Perry, Jags Srinivasan, Seema Sundara, Zhe (Alan) Wu, Aravind Yalamanchi
This software and related documentation are provided under a license agreement containing restrictions on
use and disclosure and are protected by intellectual property laws. Except as expressly permitted in your
license agreement or allowed by law, you may not use, copy, reproduce, translate, broadcast, modify, license,
transmit, distribute, exhibit, perform, publish, or display any part, in any form, or by any means. Reverse
engineering, disassembly, or decompilation of this software, unless required by law for interoperability, is
prohibited.
The information contained herein is subject to change without notice and is not warranted to be error-free. If
you find any errors, please report them to us in writing.
If this is software, software documentation, data (as defined in the Federal Acquisition Regulation), or related
documentation that is delivered to the U.S. Government or anyone licensing it on behalf of the U.S.
Government, then the following notice is applicable:
U.S. GOVERNMENT END USERS: Oracle programs (including any operating system, integrated software,
any programs embedded, installed, or activated on delivered hardware, and modifications of such programs)
and Oracle computer documentation or other Oracle data delivered to or accessed by U.S. Government end
users are "commercial computer software," "commercial computer software documentation," or "limited rights
data" pursuant to the applicable Federal Acquisition Regulation and agency-specific supplemental
regulations. As such, the use, reproduction, duplication, release, display, disclosure, modification, preparation
of derivative works, and/or adaptation of i) Oracle programs (including any operating system, integrated
software, any programs embedded, installed, or activated on delivered hardware, and modifications of such
programs), ii) Oracle computer documentation and/or iii) other Oracle data, is subject to the rights and
limitations specified in the license contained in the applicable contract. The terms governing the U.S.
Government's use of Oracle cloud services are defined by the applicable contract for such services. No other
rights are granted to the U.S. Government.
This software or hardware is developed for general use in a variety of information management applications.
It is not developed or intended for use in any inherently dangerous applications, including applications that
may create a risk of personal injury. If you use this software or hardware in dangerous applications, then you
shall be responsible to take all appropriate fail-safe, backup, redundancy, and other measures to ensure its
safe use. Oracle Corporation and its affiliates disclaim any liability for any damages caused by use of this
software or hardware in dangerous applications.
Oracle®, Java, and MySQL are registered trademarks of Oracle and/or its affiliates. Other names may be
trademarks of their respective owners.
Intel and Intel Inside are trademarks or registered trademarks of Intel Corporation. All SPARC trademarks are
used under license and are trademarks or registered trademarks of SPARC International, Inc. AMD, Epyc,
and the AMD logo are trademarks or registered trademarks of Advanced Micro Devices. UNIX is a registered
trademark of The Open Group.
This software or hardware and documentation may provide access to or information about content, products,
and services from third parties. Oracle Corporation and its affiliates are not responsible for and expressly
disclaim all warranties of any kind with respect to third-party content, products, and services unless otherwise
set forth in an applicable agreement between you and Oracle. Oracle Corporation and its affiliates will not be
responsible for any loss, costs, or damages incurred due to your access to or use of third-party content,
products, or services, except as set forth in an applicable agreement between you and Oracle.
Contents
Preface
Audience xxvii
Documentation Accessibility xxvii
Related Documents xxviii
Conventions xxviii
iii
1.3.3 Statements 1-14
1.3.3.1 Triple Uniqueness and Data Types for Literals 1-16
1.3.4 Subjects and Objects 1-17
1.3.5 Blank Nodes 1-17
1.3.6 Properties 1-17
1.3.7 Inferencing: Rules and Rulebases 1-17
1.3.8 Entailments (Rules Indexes) 1-20
1.3.9 Virtual Models 1-21
1.3.10 Named Graphs 1-25
1.3.10.1 Data Formats Related to Named Graph Support 1-25
1.3.11 Semantic Data Security Considerations 1-26
1.3.12 RDF Privilege Considerations 1-27
1.4 Semantic Metadata Tables and Views 1-27
1.5 Semantic Data Types, Constructors, and Methods 1-28
1.5.1 Constructors for Inserting Triples 1-30
1.6 Using the SEM_MATCH Table Function to Query Semantic Data 1-31
1.6.1 Performing Queries with Incomplete or Invalid Entailments 1-39
1.6.2 Graph Patterns: Support for Curly Brace Syntax, and OPTIONAL, FILTER,
UNION, and GRAPH Keywords 1-40
1.6.2.1 GRAPH Keyword Support 1-49
1.6.3 Graph Patterns: Support for SPARQL ASK Syntax 1-50
1.6.4 Graph Patterns: Support for SPARQL CONSTRUCT Syntax 1-51
1.6.4.1 Typical SPARQL CONSTRUCT Workflow 1-55
1.6.5 Graph Patterns: Support for SPARQL DESCRIBE Syntax 1-56
1.6.6 Graph Patterns: Support for SPARQL SELECT Syntax 1-58
1.6.7 Graph Patterns: Support for SPARQL 1.1 Constructs 1-62
1.6.7.1 Expressions in the SELECT Clause 1-62
1.6.7.2 Subqueries 1-63
1.6.7.3 Grouping and Aggregation 1-64
1.6.7.4 Negation 1-67
1.6.7.5 Value Assignment 1-68
1.6.7.6 Property Paths 1-71
1.6.8 Graph Patterns: Support for SPARQL 1.1 Federated Query 1-74
1.6.8.1 Privileges Required to Execute Federated SPARQL Queries 1-74
1.6.8.2 SPARQL SERVICE Join Push Down 1-75
1.6.8.3 SPARQL SERVICE SILENT 1-76
1.6.8.4 Using a Proxy Server with SPARQL SERVICE 1-76
1.6.8.5 Accessing SPARQL Endpoints with HTTP Basic Authentication 1-77
1.6.9 Inline Query Optimizer Hints 1-77
1.6.10 Full-Text Search 1-79
1.6.11 Spatial Support 1-82
iv
1.6.11.1 OGC GeoSPARQL Support 1-83
1.6.11.2 Representing Spatial Data in RDF 1-83
1.6.11.3 Validating Geometries 1-86
1.6.11.4 Indexing Spatial Data 1-86
1.6.11.5 Querying Spatial Data 1-89
1.6.11.6 Using Long Literals with GeoSPARQL Queries 1-89
1.6.12 Flashback Query Support 1-91
1.6.13 Speeding up Query Execution with SPM Auxiliary Tables 1-92
1.6.13.1 Single-Valued Property Tables 1-92
1.6.13.2 Multi-Valued Property Tables 1-93
1.6.13.3 Property Chain Tables 1-94
1.6.13.4 Creating SPM Tables 1-95
1.6.13.5 Including Lexical Values in SPM Auxiliary Tables 1-105
1.6.13.6 Creating Secondary Indexes on SPM Auxiliary Tables 1-117
1.6.13.7 Performing DML Operations on Models with SPM Auxiliary Tables 1-129
1.6.13.8 Performing Bulk Load Operations on Models with SPM Auxiliary Tables 1-129
1.6.13.9 Gathering Statistics on SPM Auxiliary Tables 1-129
1.6.13.10 SPARQL Query Options for SPM Auxiliary Tables 1-130
1.6.13.11 Special Considerations when Using SPM Auxiliary Tables 1-130
1.6.14 Best Practices for Query Performance 1-131
1.6.14.1 FILTER Constructs Involving xsd:dateTime, xsd:date, and xsd:time 1-131
1.6.14.2 Indexes for FILTER Constructs Involving Typed Literals 1-132
1.6.14.3 FILTER Constructs Involving Relational Expressions 1-132
1.6.14.4 Optimizer Statistics and Dynamic Sampling 1-132
1.6.14.5 Multi-Partition Queries 1-133
1.6.14.6 Compression on Systems with OLTP Index Compression 1-133
1.6.14.7 Unbounded Property Path Expressions 1-133
1.6.14.8 Nested Loop Pushdown for Property Paths 1-134
1.6.14.9 Grouping and Aggregation 1-135
1.6.14.10 Use of Bind Variables to Reduce Compilation Time 1-135
1.6.14.11 Non-Null Expression Hints 1-137
1.6.14.12 Automatic JOIN Hints 1-138
1.6.14.13 Semantic Network Indexes 1-138
1.6.14.14 Using RDF with Oracle Database In-Memory 1-139
1.6.14.15 Using Language Tags in FILTER Expressions 1-139
1.6.14.16 Type Casting for More Efficient FILTER Evaluation 1-140
1.6.14.17 Spatial Indexing for GeoSPARQL Queries 1-140
1.6.15 Special Considerations When Using SEM_MATCH 1-140
1.7 Using the SEM_APIS.SPARQL_TO_SQL Function to Query Semantic Data 1-142
1.7.1 Using Bind Variables with SEM_APIS.SPARQL_TO_SQL 1-143
1.7.2 SEM_MATCH and SEM_APIS.SPARQL_TO_SQL Compared 1-146
v
1.8 Using the SEM_APIS.GET_SQL Function and SEM_SQL SQL Macro to Query
Semantic Data 1-147
1.9 Loading and Exporting Semantic Data 1-154
1.9.1 Bulk Loading Semantic Data Using a Staging Table 1-155
1.9.1.1 Loading the Staging Table 1-156
1.9.1.2 Recording Event Traces During Bulk Loading 1-158
1.9.2 Loading Semantic Data Using INSERT Statements 1-158
1.9.2.1 Loading Data into Named Graphs Using INSERT Statements 1-159
1.9.3 Exporting Semantic Data 1-159
1.9.3.1 Retrieving Semantic Data from an Application Table 1-159
1.9.3.2 Retrieving Semantic Data from an RDF Model 1-160
1.9.3.3 Removing Model and Graph Information from Retrieved Blank Node
Identifiers 1-161
1.9.4 Exporting or Importing a Semantic Network Using Oracle Data Pump 1-162
1.9.5 Moving, Restoring, and Appending a Semantic Network 1-162
1.9.6 Purging Unused Values 1-167
1.10 Using Semantic Network Indexes 1-167
1.10.1 SEM_NETWORK_INDEX_INFO View 1-169
1.11 Using Data Type Indexes 1-169
1.12 Managing Statistics for Semantic Models and the Semantic Network 1-171
1.12.1 Saving Statistics at a Model Level 1-172
1.12.2 Restoring Statistics at a Model Level 1-173
1.12.3 Saving Statistics at the Network Level 1-173
1.12.4 Dropping Extended Statistics at the Network Level 1-174
1.12.5 Restoring Statistics at the Network Level 1-174
1.12.6 Setting Statistics at a Model Level 1-174
1.12.7 Deleting Statistics at a Model Level 1-174
1.13 Support for SPARQL Update Operations on a Semantic Model 1-175
1.13.1 Tuning the Performance of SPARQL Update Operations 1-185
1.13.2 Transaction Management with SPARQL Update Operations 1-186
1.13.2.1 Transaction Isolation Levels 1-189
1.13.3 Support for Bulk Operations 1-190
1.13.3.1 Materialization of Intermediate Data (STREAMING=F) 1-190
1.13.3.2 Using SEM_APIS.BULK_LOAD_FROM_STAGING_TABLE 1-190
1.13.3.3 Using Delete as Insert (DEL_AS_INS=T) 1-191
1.13.4 Setting UPDATE_MODEL Options at the Session Level 1-192
1.13.5 Load Operations: Special Considerations for SPARQL Update 1-192
1.13.6 Long Literals: Special Considerations for SPARQL Update 1-193
1.13.7 Blank Nodes: Special Considerations for SPARQL Update 1-193
1.14 RDF Support for Oracle Database In-Memory 1-195
1.14.1 Enabling Oracle Database In-Memory for RDF 1-195
1.14.2 Using In-Memory Virtual Columns with RDF 1-196
vi
1.14.3 Using Invisible Indexes with Oracle Database In-Memory 1-197
1.15 RDF Support for Materialized Join Views 1-197
1.16 RDF Support in Oracle SQL Developer 1-198
1.17 Enhanced RDF ORDER BY Query Processing 1-199
1.18 Applying Oracle Machine Learning Algorithms to RDF Data 1-199
1.19 Semantic Data Examples (PL/SQL and Java) 1-200
1.19.1 Example: Journal Article Information 1-200
1.19.2 Example: Family Information 1-202
1.20 Software Naming Changes Since Release 11.1 1-206
1.21 For More Information About RDF Semantic Graph 1-207
1.22 Required Migration of Pre-12.2 Semantic Data 1-207
1.23 Oracle RDF Graph Features that Support Accessibility 1-208
3 OWL Concepts
3.1 Ontologies 3-1
3.1.1 Example: Disease Ontology 3-1
3.1.2 Supported OWL Subsets 3-3
3.2 Using OWL Inferencing 3-5
3.2.1 Creating a Simple OWL Ontology 3-6
3.2.2 Performing Native OWL inferencing 3-6
3.2.3 Performing OWL and User-Defined Rules Inferencing 3-7
3.2.4 Generating OWL inferencing Proofs 3-8
3.2.5 Validating OWL Models and Entailments 3-10
3.2.6 Using SEM_APIS.CREATE_ENTAILMENT for RDFS Inference 3-11
3.2.7 Enhancing Inference Performance 3-11
3.2.8 Optimizing owl:sameAs Inference 3-12
3.2.8.1 Querying owl:sameAs Consolidated Inference Graphs 3-13
3.2.9 Performing Incremental Inference 3-14
3.2.10 Using Parallel Inference 3-15
3.2.11 Using Named Graph Based Inferencing (Global and Local) 3-16
3.2.11.1 Named Graph Based Global Inference (NGGI) 3-16
3.2.11.2 Named Graph Based Local Inference (NGLI) 3-17
vii
3.2.11.3 Using NGGI and NGLI Together 3-19
3.2.12 Performing Selective Inferencing (Advanced Information) 3-19
3.3 Using Semantic Operators to Query Relational Data 3-20
3.3.1 Using the SEM_RELATED Operator 3-21
3.3.2 Using the SEM_DISTANCE Ancillary Operator 3-22
3.3.2.1 Computation of Distance Information 3-23
3.3.3 Creating a Semantic Index of Type MDSYS.SEM_INDEXTYPE 3-24
3.3.4 Using SEM_RELATED and SEM_DISTANCE When the Indexed Column Is
Not the First Parameter 3-25
3.3.5 Using URIPREFIX When Values Are Not Stored as URIs 3-26
viii
5.14 Passing Extractor-Specific Parameters in CREATE INDEX and ALTER INDEX 5-17
5.15 Performing Document-Centric Inference 5-17
5.16 Metadata Views for Semantic Indexing 5-18
5.16.1 MDSYS.RDFCTX_POLICIES View 5-19
5.16.2 RDFCTX_INDEX_POLICIES View 5-19
5.16.3 RDFCTX_INDEX_EXCEPTIONS View 5-20
5.17 Default Style Sheet for GATE Extractor Output 5-20
ix
7.8.3 User-Defined Functions 7-24
7.9 SPARQL Update Support 7-27
7.10 Analytical Functions for RDF Data 7-29
7.10.1 Generating Contextual Information about a Path in a Graph 7-34
7.11 Support for Server-Side APIs 7-35
7.11.1 Virtual Models Support 7-36
7.11.2 Connection Pooling Support 7-37
7.11.3 Semantic Model PL/SQL Interfaces 7-38
7.11.4 Inference Options 7-39
7.11.5 PelletInfGraph Class Support Deprecated 7-41
7.12 Bulk Loading Using RDF Semantic Graph Support for Apache Jena 7-42
7.12.1 Using prepareBulk in Parallel (Multithreaded) Mode 7-44
7.12.2 Handling Illegal Syntax During Data Loading 7-47
7.13 Automatic Variable Renaming 7-48
7.14 JavaScript Object Notation (JSON) Format Support 7-48
7.15 Other Recommendations and Guidelines 7-51
7.15.1 BOUND or !BOUND Instead of EXISTS or NOT EXISTS 7-51
7.15.2 SPARQL 1.1 SELECT Expressions 7-51
7.15.3 Syntax Involving Bnodes (Blank Nodes) 7-51
7.15.4 Limit in the SERVICE Clause 7-52
7.15.5 OracleGraphWrapperForOntModel Class for Better Performance 7-52
7.16 Example Queries Using RDF Semantic Graph Support for Apache Jena 7-54
7.16.1 Test.java: Query Family Relationships 7-55
7.16.2 Test6.java: Load OWL Ontology and Perform OWLPrime inference 7-56
7.16.3 Test7.java: Bulk Load OWL Ontology and Perform OWLPrime inference 7-58
7.16.4 Test8.java: SPARQL OPTIONAL Query 7-59
7.16.5 Test9.java: SPARQL Query with LIMIT and OFFSET 7-60
7.16.6 Test10.java: SPARQL Query with TIMEOUT and DOP 7-62
7.16.7 Test11.java: Query Involving Named Graphs 7-63
7.16.8 Test12.java: SPARQL ASK Query 7-64
7.16.9 Test13.java: SPARQL DESCRIBE Query 7-65
7.16.10 Test14.java: SPARQL CONSTRUCT Query 7-66
7.16.11 Test15.java: Query Multiple Models and Specify "Allow Duplicates" 7-67
7.16.12 Test16.java: SPARQL Update 7-69
7.16.13 Test17.java: SPARQL Query with ARQ Built-In Functions 7-69
7.16.14 Test18.java: SELECT Cast Query 7-70
7.16.15 Test19.java: Instantiate Oracle Database Using OracleConnection 7-72
7.16.16 Test20.java: Oracle Database Connection Pooling 7-73
7.17 SPARQL Gateway and Semantic Data 7-74
7.17.1 SPARQL Gateway Features and Benefits Overview 7-74
7.17.2 Installing and Configuring SPARQL Gateway 7-75
x
7.17.2.1 Download the RDF Semantic Graph Support for Apache Jena .zip File
(if Not Already Done) 7-75
7.17.2.2 Deploy SPARQL Gateway in WebLogic Server 7-76
7.17.2.3 Modify Proxy Settings, if Necessary 7-76
7.17.2.4 Configure the OracleSGDS Data Source, if Necessary 7-76
7.17.2.5 Add and Configure the SparqlGatewayAdminGroup Group, if Desired 7-77
7.17.3 Using SPARQL Gateway with Semantic Data 7-77
7.17.3.1 Storing SPARQL Queries and XSL Transformations 7-78
7.17.3.2 Specifying a Timeout Value 7-79
7.17.3.3 Specifying Best Effort Query Execution 7-80
7.17.3.4 Specifying a Content Type Other Than text/xml 7-80
7.17.4 Customizing the Default XSLT File 7-81
7.17.5 Using the SPARQL Gateway Java API 7-81
7.17.6 Using the SPARQL Gateway Graphical Web Interface 7-84
7.17.6.1 Main Page (index.html) 7-84
7.17.6.2 Navigation and Browsing Page (browse.jsp) 7-86
7.17.6.3 XSLT Management Page (xslt.jsp) 7-88
7.17.6.4 SPARQL Management Page (sparql.jsp) 7-89
7.17.7 Using SPARQL Gateway as an XML Data Source to OBIEE 7-90
7.18 Deploying Fuseki in Apache Tomcat 7-93
7.19 ORARDFLDR Utility for Bulk Loading RDF Data 7-94
7.19.1 Using ORARDFLDR with Oracle Autonomous Database 7-95
xi
8.5.3.2 SPARQL_TO_SQL (SEM_MATCH) Options 8-21
8.5.4 Special Considerations for SPARQL Query Support 8-22
8.6 SPARQL Update Execution Model 8-22
8.6.1 Transaction Management for SPARQL Update 8-23
8.6.2 Additions to the SPARQL Syntax to Support Other Features 8-23
8.6.2.1 UPDATE_MODEL Options 8-23
8.6.2.2 UPDATE_MODEL Match Options 8-24
8.6.3 Special Considerations for SPARQL Update Support 8-24
8.7 Efficiently Loading RDF Data 8-25
8.8 Best Practices for Oracle RDF Graph Adapter for Eclipse RDF4J 8-26
8.9 Blank Nodes Support in Oracle RDF Graph Adapter for Eclipse RDF4J 8-27
8.10 Unsupported Features in Oracle RDF Graph Adapter for Eclipse RDF4J 8-28
8.11 Example Queries Using Oracle RDF Graph Adapter for Eclipse RDF4J 8-28
8.11.1 Example 1: Basic Operations 8-30
8.11.2 Example 2: Add a Data File in TRIG Format 8-32
8.11.3 Example 3: Simple Query 8-34
8.11.4 Example 4: Simple Bulk Load 8-36
8.11.5 Example 5: Bulk Load RDF/XML 8-39
8.11.6 Example 6: SPARQL Ask Query 8-41
8.11.7 Example 7: SPARQL CONSTRUCT Query 8-43
8.11.8 Example 8: Named Graph Query 8-45
8.11.9 Example 9: Get COUNT of Matches 8-48
8.11.10 Example 10: Specify Bind Variable for Constant in Query Pattern 8-50
8.11.11 Example 11: SPARQL Update 8-53
8.11.12 Example 12: Oracle Hint 8-57
8.11.13 Example 13: Using JDBC Bind Values 8-60
8.11.14 Example 14: Simple Inference 8-63
8.11.15 Example 15: Simple Virtual Model 8-66
xii
9.1.3.6 Example 6: Calling a Web Service 9-25
9.2 User-Defined Functions and Aggregates 9-28
9.2.1 Data Types for User-Defined Functions and Aggregates 9-28
9.2.2 API Support for User-Defined Functions 9-29
9.2.2.1 PL/SQL Function Implementation 9-29
9.2.2.2 Invoking User-Defined Functions from a SPARQL Query Pattern 9-30
9.2.2.3 User-Defined Function Examples 9-30
9.2.3 API Support for User-Defined Aggregates 9-32
9.2.3.1 ODCIAggregate Interface 9-32
9.2.3.2 Invoking User-Defined Aggregates 9-33
9.2.3.3 User-Defined Aggregate Examples 9-33
xiii
13 RDF Graph Server and Query UI Concepts
13.1 Data Sources 13-1
13.1.1 Oracle Data Sources 13-1
13.1.2 Endpoint URL Data Sources 13-3
13.2 RDF Datasets 13-4
13.3 REST Services 13-4
xiv
14.4 Accessibility 14-51
xv
15.36 SEM_APIS.DISABLE_CHANGE_TRACKING 15-63
15.37 SEM_APIS.DISABLE_INC_INFERENCE 15-64
15.38 SEM_APIS.DISABLE_INMEMORY 15-65
15.39 SEM_APIS.DISABLE_INMEMORY_FOR_ENT 15-65
15.40 SEM_APIS.DISABLE_INMEMORY_FOR_MODEL 15-66
15.41 SEM_APIS.DISABLE_NETWORK_SHARING 15-67
15.42 SEM_APIS.DROP_DATATYPE_INDEX 15-67
15.43 SEM_APIS.DROP_ENTAILMENT 15-68
15.44 SEM_APIS.DROP_MATERIALIZED_VIEW 15-69
15.45 SEM_APIS.DROP_MV_BITMAP_INDEX 15-70
15.46 SEM_APIS.DROP_PG_RDFVIEW 15-71
15.47 SEM_APIS.DROP_PG_RDFVIEW_INDEXES 15-72
15.48 SEM_APIS.DROP_RDFVIEW_MODEL 15-73
15.49 SEM_APIS.DROP_RULEBASE 15-73
15.50 SEM_APIS.DROP_SEM_INDEX 15-74
15.51 SEM_APIS.DROP_SEM_MODEL 15-75
15.52 SEM_APIS.DROP_SEM_NETWORK 15-76
15.53 SEM_APIS.DROP_SEM_SQL 15-77
15.54 SEM_APIS.DROP_SPARQL_UPDATE_TABLES 15-77
15.55 SEM_APIS.DROP_SPM_TAB 15-78
15.56 SEM_APIS.DROP_USER_INFERENCE_OBJS 15-80
15.57 SEM_APIS.DROP_VIRTUAL_MODEL 15-81
15.58 SEM_APIS.ENABLE_CHANGE_TRACKING 15-81
15.59 SEM_APIS.ENABLE_INC_INFERENCE 15-82
15.60 SEM_APIS.ENABLE_INMEMORY 15-83
15.61 SEM_APIS.ENABLE_INMEMORY_FOR_ENT 15-84
15.62 SEM_APIS.ENABLE_INMEMORY_FOR_MODEL 15-85
15.63 SEM_APIS.ENABLE_NETWORK_SHARING 15-86
15.64 SEM_APIS.ESCAPE_CLOB_TERM 15-86
15.65 SEM_APIS.ESCAPE_CLOB_VALUE 15-87
15.66 SEM_APIS.ESCAPE_RDF_TERM 15-88
15.67 SEM_APIS.ESCAPE_RDF_VALUE 15-89
15.68 SEM_APIS.EXPORT_ENTAILMENT_STATS 15-89
15.69 SEM_APIS.EXPORT_MODEL_STATS 15-90
15.70 SEM_APIS.EXPORT_RDFVIEW_MODEL 15-91
15.71 SEM_APIS.GATHER_SPM_INFO 15-92
15.72 SEM_APIS.GET_CHANGE_TRACKING_INFO 15-93
15.73 SEM_APIS.GET_INC_INF_INFO 15-95
15.74 SEM_APIS.GET_MODEL_ID 15-96
15.75 SEM_APIS.GET_MODEL_NAME 15-96
15.76 SEM_APIS.GET_PLAN_COST 15-97
xvi
15.77 SEM_APIS.GET_SQL 15-98
15.78 SEM_APIS.GET_TRIPLE_ID 15-99
15.79 SEM_APIS.GETV$DATETIMETZVAL 15-100
15.80 SEM_APIS.GETV$DATETZVAL 15-101
15.81 SEM_APIS.GETV$GEOMETRYVAL 15-102
15.82 SEM_APIS.GETV$NUMERICVAL 15-103
15.83 SEM_APIS.GETV$STRINGVAL 15-104
15.84 SEM_APIS.GETV$TIMETZVAL 15-105
15.85 SEM_APIS.GRANT_MODEL_ACCESS_PRIV 15-106
15.86 SEM_APIS.GRANT_MODEL_ACCESS_PRIVS 15-107
15.87 SEM_APIS.GRANT_NETWORK_ACCESS_PRIVS 15-109
15.88 SEM_APIS.GRANT_NETWORK_SHARING_PRIVS 15-110
15.89 SEM_APIS.IMPORT_ENTAILMENT_STATS 15-110
15.90 SEM_APIS.IMPORT_MODEL_STATS 15-111
15.91 SEM_APIS.IS_TRIPLE 15-112
15.92 SEM_APIS.LOAD_INTO_STAGING_TABLE 15-113
15.93 SEM_APIS.LOOKUP_ENTAILMENT 15-114
15.94 SEM_APIS.MERGE_MODELS 15-115
15.95 SEM_APIS.MIGRATE_DATA_TO_CURRENT 15-117
15.96 SEM_APIS.MIGRATE_DATA_TO_STORAGE_V2 15-118
15.97 SEM_APIS.MOVE_SEM_NETWORK_DATA 15-119
15.98 SEM_APIS.PRIVILEGE_ON_APP_TABLES 15-120
15.99 SEM_APIS.PURGE_UNUSED_VALUES 15-121
15.100 SEM_APIS.REFRESH_MATERIALIZED_VIEW 15-122
15.101 SEM_APIS.REFRESH_SEM_NETWORK_INDEX_INFO 15-123
15.102 SEM_APIS.REMOVE_DUPLICATES 15-123
15.103 SEM_APIS.RENAME_ENTAILMENT 15-125
15.104 SEM_APIS.RENAME_MODEL 15-126
15.105 SEM_APIS.RES2VID 15-126
15.106 SEM_APIS.RESTORE_SEM_NETWORK_DATA 15-127
15.107 SEM_APIS.REVOKE_MODEL_ACCESS_PRIV 15-129
15.108 SEM_APIS.REVOKE_MODEL_ACCESS_PRIVS 15-130
15.109 SEM_APIS.REVOKE_NETWORK_ACCESS_PRIVS 15-132
15.110 SEM_APIS.REVOKE_NETWORK_SHARING_PRIVS 15-133
15.111 SEM_APIS.SEM_SQL_COMPILE 15-133
15.112 SEM_APIS.SET_ENTAILMENT_STATS 15-134
15.113 SEM_APIS.SET_MODEL_STATS 15-135
15.114 SEM_APIS.SPARQL_TO_SQL 15-136
15.115 SEM_APIS.SWAP_NAMES 15-137
15.116 SEM_APIS.TRUNCATE_SEM_MODEL 15-138
15.117 SEM_APIS.UNESCAPE_CLOB_TERM 15-139
xvii
15.118 SEM_APIS.UNESCAPE_CLOB_VALUE 15-139
15.119 SEM_APIS.UNESCAPE_RDF_TERM 15-140
15.120 SEM_APIS.UNESCAPE_RDF_VALUE 15-141
15.121 SEM_APIS.UPDATE_MODEL 15-142
15.122 SEM_APIS.VALIDATE_ENTAILMENT 15-144
15.123 SEM_APIS.VALIDATE_GEOMETRIES 15-145
15.124 SEM_APIS.VALIDATE_MODEL 15-148
15.125 SEM_APIS.VALUE_NAME_PREFIX 15-149
15.126 SEM_APIS.VALUE_NAME_SUFFIX 15-150
xviii
19.8 SEM_RDFSA.SET_RESOURCE_LABEL 19-10
19.9 SEM_RDFSA.SET_RULE_LABEL 19-12
Part IV Appendixes
xix
B.1.22 ogcf:geometryN B-21
B.1.23 ogcf:geometryType B-22
B.1.24 ogcf:getSRID B-23
B.1.25 ogcf:intersection B-24
B.1.26 ogcf:is3D B-25
B.1.27 ogcf:isEmpty B-26
B.1.28 ogcf:isMeasured B-26
B.1.29 ogcf:isSimple B-27
B.1.30 ogcf:length B-28
B.1.31 ogcf:maxX B-29
B.1.32 ogcf:maxY B-30
B.1.33 ogcf:maxZ B-31
B.1.34 ogcf:metricArea B-31
B.1.35 ogcf:metricBuffer B-32
B.1.36 ogcf:metricLength B-33
B.1.37 ogcf:metricPerimeter B-34
B.1.38 ogcf:minX B-35
B.1.39 ogcf:minY B-36
B.1.40 ogcf:minZ B-36
B.1.41 ogcf:numGeometries B-37
B.1.42 ogcf:perimeter B-38
B.1.43 ogcf:relate B-39
B.1.44 ogcf:sfContains B-40
B.1.45 ogcf:sfCrosses B-41
B.1.46 ogcf:sfDisjoint B-43
B.1.47 ogcf:sfEquals B-44
B.1.48 ogcf:sfIntersects B-45
B.1.49 ogcf:sfOverlaps B-46
B.1.50 ogcf:sfTouches B-47
B.1.51 ogcf:sfWithin B-48
B.1.52 ogcf:spatialDimension B-49
B.1.53 ogcf:symDifference B-50
B.1.54 ogcf:transform B-51
B.1.55 ogcf:union B-52
B.2 Oracle-Specific Functions for Spatial Support B-53
B.2.1 orageo:aggrCentroid B-53
B.2.2 orageo:aggrConvexHull B-54
B.2.3 orageo:aggrMBR B-55
B.2.4 orageo:aggrUnion B-56
B.2.5 orageo:area B-56
B.2.6 orageo:buffer B-57
xx
B.2.7 orageo:centroid B-58
B.2.8 orageo:convexHull B-59
B.2.9 orageo:difference B-60
B.2.10 orageo:distance B-61
B.2.11 orageo:getSRID B-62
B.2.12 orageo:intersection B-62
B.2.13 orageo:length B-63
B.2.14 orageo:mbr B-64
B.2.15 orageo:nearestNeighbor B-65
B.2.16 orageo:relate B-66
B.2.17 orageo:sdoDistJoin B-68
B.2.18 orageo:sdoJoin B-69
B.2.19 orageo:union B-70
B.2.20 orageo:withinDistance B-71
B.2.21 orageo:xor B-72
Glossary
Index
xxi
List of Figures
1-1 Oracle Semantic Capabilities 1-3
1-2 Inferencing 1-18
1-3 Family Tree for RDF Example 1-202
2-1 Running SPARQL Query in RDF Graph Query UI 2-6
3-1 Disease Ontology Example 3-2
7-1 Visual Representation of Analytical Function Output 7-35
7-2 Graphical Interface Main Page (index.html) 7-85
7-3 SPARQL Query Main Page Response 7-86
7-4 Graphical Interface Navigation and Browsing Page (browse.jsp) 7-87
7-5 Browsing and Navigation Page: Response 7-87
7-6 Query and Response from Clicking URI Link 7-88
7-7 XSLT Management Page 7-89
7-8 SPARQL Management Page 7-90
7-9 Import Metadata - Select Data Source 7-91
7-10 Import Metadata - Select Metadata Types 7-92
7-11 Import Metadata - Select Metadata Objects 7-93
8-1 Data Source Repository in RDF4J Workbench 8-9
8-2 RDF4J Workbench Repository 8-14
8-3 RDF4J Workbench New Repository 8-15
8-4 Create New Repository in RDF4J Workbench 8-15
8-5 Summary of New Repository in RDF4J Workbench 8-16
11-1 Equivalent Property Graph and RDF Representations of the Same Graph 11-3
12-1 RDF Graph Server and Query UI 12-1
14-1 Oracle Graph Webapps deployment 14-1
14-2 User Roles for RDF Graph Query 14-2
14-3 WebLogic Server Administration Console 14-3
14-4 Creating new user groups in WebLogic Server 14-3
14-5 Created User Groups in WebLogic Server 14-3
14-6 Create new users in WebLogic Server 14-4
14-7 New RDF and Guest users 14-4
14-8 RDF User 14-5
14-9 RDF Guest User 14-6
14-10 Query UI Main Page 14-7
14-11 Data Sources Page 14-8
14-12 Creating a JDBC URL Data Source 14-9
xxii
14-13 Create Container Data Source 14-10
14-14 Generic Data Source 14-10
14-15 JDBC Data Source and JNDI 14-11
14-16 Create JDBC Data Source 14-11
14-17 Validate connection 14-12
14-18 Create JDBC Data Source 14-12
14-19 Cloud Wallet 14-13
14-20 Wallet Data Source from cloud zip 14-14
14-21 DBpedia Data Source 14-16
14-22 Apache Jena Fuseki Data Source 14-17
14-23 RDF Data Page 14-17
14-24 RDF Network 14-18
14-25 RDF Semantic Network Actions 14-18
14-26 RDF Import Data Actions 14-19
14-27 SPARQL Query Cache Manager 14-20
14-28 Manage SPARQL Query Cache 14-20
14-29 RDF Objects for Oracle Data Source 14-21
14-30 RDF Objects from capabilities 14-21
14-31 Default RDF Object 14-21
14-32 RDF Navigator - Context Menu 14-22
14-33 Data Source Published Datasets Navigator 14-22
14-34 SPARQL Query Page 14-23
14-35 SQL EXPLAIN PLAN for SPARQL Translation 14-24
14-36 Map Visualization for GeoSPARQL Data Types in a SPARQL Query 14-24
14-37 Publish Menu 14-25
14-38 Publish RDF Model 14-26
14-39 GET URL Endpoint 14-26
14-40 Open an RDF Dataset Definition 14-27
14-41 RDF Dataset Definition 14-28
14-42 Public Web Page 14-29
14-43 Opening a Published Dataset on the Public Page 14-29
14-44 Auxiliary tables Menu 14-30
14-45 Predicates Table 14-31
14-46 Predicate List 14-31
14-47 Creating an Auxiliary Table 14-32
14-48 List of Auxiliary Tables 14-32
14-49 Viewing the Predicate Information for an SPM table 14-33
xxiii
14-50 Viewing the Secondary Indexes 14-33
14-51 Creating a Secondary Index 14-34
14-52 Dropping an SPM Table 14-35
14-53 Advanced Graph View Components 14-35
14-54 Visualize Menu 14-36
14-55 Query Selector 14-37
14-56 Advanced Graph View 14-37
14-57 Expanding a Node 14-38
14-58 Viewing Node Values 14-39
14-59 Expanding an Edge Predicate 14-39
14-60 Circular Layout Graph 14-40
14-61 Create Graph View Option 14-41
14-62 RDF Classes 14-42
14-63 Sample Graph Definition 14-42
14-64 Action Menu Options 14-42
14-65 Graph Visualization for RDF Database Views 14-43
14-66 Create Views 14-43
14-67 RDF Database Graph Views 14-44
14-68 Creating a Vertex View 14-44
14-69 Vertex View Definitions 14-45
14-70 Edge Views 14-45
14-71 Edge View Definition 14-46
14-72 General SPARQL Parameters 14-48
14-73 General JDBC Parameters 14-49
14-74 General File Upload Parameters 14-49
14-75 Proxy JSON Configuration File 14-50
14-76 Logging JSON Configuration File 14-50
14-77 Disabled Accessibility 14-51
14-78 Enabled Accessibility 14-51
14-79 Disabled Graph View 14-51
C-1 RDF Semantic Graph Setup C-2
C-2 Apply RDF Semantic Graph Setup C-3
C-3 Create Semantic Network C-5
xxiv
List of Tables
1-1 network_owner and network_name Parameters 1-7
1-2 SEM_MODEL$ View Columns 1-13
1-3 SEMM_model-name View Columns 1-13
1-4 RDF_VALUE$ Table Columns 1-14
1-5 SEMR_rulebase-name View Columns 1-19
1-6 SEM_RULEBASE_INFO View Columns 1-19
1-7 SEM_RULES_INDEX_INFO View Columns 1-21
1-8 SEM_RULES_INDEX_DATASETS View Columns 1-21
1-9 SEM_MODEL$ View Column Explanations for Virtual Models 1-23
1-10 SEM_VMODEL_INFO View Columns 1-23
1-11 SEM_VMODEL_DATASETS View Columns 1-24
1-12 Semantic Metadata Tables and Views 1-27
1-13 Built-in Functions Available for FILTER Clause 1-40
1-14 Oracle-Specific Query Functions 1-45
1-15 SEM_MATCH graphs and named_graphs Values, and Resulting Dataset Configurations 1-49
1-16 Built-in Aggregates 1-64
1-17 Property Path Syntax Constructs 1-71
1-18 Single-Valued Table Columns 1-93
1-19 Multi-Valued Table Columns 1-94
1-20 Property Chain Table Columns 1-94
1-21 Predicate Information Table Columns 1-95
1-22 Lexical Values Columns in MVN, PCN and SVP Tables 1-106
1-23 SEM_APIS.CREATE_INDEX_ON_SPM_TAB Procedure Parameters 1-117
1-24 SEM_NETWORK_INDEX_INFO View Columns (Partial List) 1-169
1-25 Data Types for Data Type Indexing 1-170
1-26 SEM_DTYPE_INDEX_INFO View Columns 1-171
1-27 Semantic Technology Software Objects: Old and New Names 1-207
3-1 PATIENTS Table Example Data 3-2
3-2 RDFS/OWL Vocabulary Constructs Included in Each Supported Rulebase 3-4
3-3 SEMC_entailment_name View Columns 3-13
5-1 MDSYS.RDFCTX_POLICIES View Columns 5-19
5-2 MDSYS.RDFCTX_INDEX_POLICIES View Columns 5-19
5-3 MDSYS.RDFCTX_INDEX_EXCEPTIONS View Columns 5-20
7-1 Functions and Return Values for my_strlen Example 7-24
xxv
7-2 PL/SQL Subprograms and Corresponding RDF Semantic Graph support for Apache
Jena Java Class and Methods 7-38
8-1 Commands to create a Semantic Network 8-4
13-1 External Data source Parameters 13-3
15-1 Inferencing Keywords for inf_components_in Parameter 15-36
15-2 SEM_RDFSA Package Constants for label_gen Parameter 15-40
19-1 SEM_RDFSA Package Constants for rdfsa_options Parameter 19-2
C-1 RDF Semantic Graph Setup Specific To SQL Developer and Oracle DB Version C-2
C-2 Recommended Semantic Network Type C-4
C-3 Release Specific Instructions to Create a Semantic Network C-5
xxvi
Preface
Oracle Spatial and Graph RDF Semantic Graph Developer's Guide provides usage and
reference information about Oracle Database Enterprise Edition support for semantic
technologies, including storage, inference, and query capabilities for data and ontologies
based on Resource Description Framework (RDF), RDF Schema (RDFS), and Web Ontology
Language (OWL). The RDF Semantic Graph feature is licensed with the Oracle Spatial and
Graph option to Oracle Database Enterprise Edition, and it requires the Oracle Partitioning
option to Oracle Database Enterprise Edition.
Note:
You must perform certain actions and meet prerequisites before you can use any
types, synonyms, or PL/SQL packages related to RDF Semantic Graph support.
These actions and prerequisites are explained in Enabling RDF Semantic Graph
Support.
• Audience
• Documentation Accessibility
• Related Documents
• Conventions
Audience
This guide is intended for those who need to use semantic technology to store, manage, and
query semantic data in the database.
You should be familiar with at least the main concepts and techniques for the Resource
Description Framework (RDF) and the Web Ontology Language (OWL).
Documentation Accessibility
For information about Oracle's commitment to accessibility, visit the Oracle Accessibility
Program website at http://www.oracle.com/pls/topic/lookup?ctx=acc&id=docacc.
xxvii
Preface
Related Documents
For an excellent explanation of RDF concepts, see the World Wide Web Consortium
(W3C) RDF Primer at http://www.w3.org/TR/rdf-primer/.
For information about OWL, see the OWL Web Ontology Language Reference at
http://www.w3.org/TR/owl-ref/.
Conventions
The following text conventions are used in this document:
Convention Meaning
boldface Boldface type indicates graphical user interface elements associated
with an action, or terms defined in text or the glossary.
italic Italic type indicates book titles, emphasis, or placeholder variables for
which you supply particular values.
monospace Monospace type indicates commands within a paragraph, URLs, code
in examples, text that appears on the screen, or text that you enter.
xxviii
Changes in This Release for This Guide
This topic contains the following.
• Changes in Oracle Database Release 23c
• Changes in Oracle Database Release 21c
• Changes in Oracle Database Release 19c
• Changes in Oracle Database Release 18.1
xxix
Changes in This Release for This Guide
EXEC SEM_APIS.MIGRATE_DATA_TO_CURRENT;
For each schema-private semantic network, you must run the following as the network
owner:
EXEC
SEM_APIS.MIGRATE_DATA_TO_CURRENT(network_owner=>'<NETWORK_OWNER>',
network_name=>'<NETWORK_NAME>');
xxx
Changes in This Release for This Guide
recommended that you migrate existing semantic networks to unescaped storage form.
Existing semantic networks using escaped storage form can be migrated to unescaped
storage form with the SEM_APIS.MIGRATE_DATA_TO_STORAGE_V2 procedure. Existing
applications should not be affected by any changes in network storage form. Such changes
only affect internal operations of RDF Knowledge Graph.
xxxi
Changes in This Release for This Guide
xxxii
Changes in This Release for This Guide
xxxiii
Changes in This Release for This Guide
xxxiv
How to Use This Book
This book is organized into three parts:
• Part I provides conceptual and usage information about RDF Semantic Graph.
• Part II provides information about using RDF Graph Server and Query UI.
• Part III provides reference information about RDF Semantic Graph subprograms.
All supplementary information is provided in Appendixes and specialized terms are defined in
the Glossary.
However, the following summary provides an outline of some of the main ideas in the book
that will help you to develop an understanding of RDF semantic graph support in Oracle
Database and how to store, load, query, infer and visualize RDF data.
Learn About Oracle RDF Graph Get Started With Oracle RDF Graph
What's New In Oracle RDF Graph Additional Oracle RDF Graph Features
Speeding up Query Execution with SPM RDF Semantic Graph Support for Apache
Auxiliary Tables Jena
RDF Semantic Graph Support for Eclipse RDF Integration with Property Graph Data
RDF4J
RDF Support in SQL Developer
RDF Graph Server and Query UI
xxxv
How to Use This Book
xxxvi
Part I
Conceptual and Usage Information
Part I provides conceptual and usage information about RDF Semantic Graph.
This part contains the following chapters:
• RDF Graph Overview
Oracle Graph support for semantic technologies consists mainly of Resource Description
Framework (RDF) and a subset of the Web Ontology Language (OWL). These
capabilities are referred to as the RDF Graph feature of Oracle Graph.
• Quick Start for Using Semantic Data
This section provides the steps to help you get started on working with semantic data in
an Oracle Database.
• OWL Concepts
You should understand key concepts related to the support for a subset of the Web
Ontology Language (OWL).
• Simple Knowledge Organization System (SKOS) Support
You can perform inferencing based on a core subset of the Simple Knowledge
Organization System (SKOS) data model, which is especially useful for representing
thesauri, classification schemes, taxonomies, and other types of controlled vocabulary.
• Semantic Indexing for Documents
Information extractors locate and extract meaningful information from unstructured
documents. The ability to search for documents based on this extracted information is a
significant improvement over the keyword-based searches supported by the full-text
search engines.
• Fine-Grained Access Control for RDF Data
The default control of access to the Oracle Database semantic data store is at the model
level: the owner of a model can grant select, delete, and insert privileges on the model to
other users by granting appropriate privileges on the view named
RDFM_<model_name>. However, for applications with stringent security requirements,
you can enforce a fine-grained access control mechanism by using the Oracle Label
Security option of Oracle Database.
• RDF Semantic Graph Support for Apache Jena
RDF Semantic Graph support for Apache Jena (also referred to here as support for
Apache Jena) provides a Java-based interface to Oracle Graph RDF Semantic Graph by
implementing the well-known Jena Graph, Model, and DatasetGraph APIs.
• RDF Semantic Graph Support for Eclipse RDF4J
Oracle RDF Graph Adapter for Eclipse RDF4J utilizes the popular Eclipse RDF4J
framework to provide Java developers support to use the RDF Semantic Graph feature of
Oracle Database.
• User-Defined Inferencing and Querying
RDF Semantic Graph extension architectures enable the addition of user-defined
capabilities.
• RDF Views: Relational Data as RDF
You can create and use RDF views over relational data in RDF Semantic Graph.
• RDF Integration with Property Graph Data Stored in Oracle Database
The property graph data model is supported in Oracle Graph. Oracle Graph
provides built-in support for RDF views of property graph data stored in Oracle
Database.
1
RDF Graph Overview
Oracle Graph support for semantic technologies consists mainly of Resource Description
Framework (RDF) and a subset of the Web Ontology Language (OWL). These capabilities
are referred to as the RDF Graph feature of Oracle Graph.
The RDF Graph feature enables you to create one or more semantic networks in an Oracle
database. Each network contains semantic data (also referred to as RDF data).
This chapter assumes that you are familiar with the major concepts associated with RDF and
OWL, such as {subject, predicate, object} triples, {subject, predicate, object, graph} quads,
URIs, blank nodes, plain and typed literals, and ontologies. It does not explain these
concepts in detail, but focuses instead on how the concepts are implemented in Oracle.
• For an excellent explanation of RDF concepts, see the World Wide Web Consortium
(W3C) RDF Primer at http://www.w3.org/TR/rdf-primer/.
• For information about OWL, see the OWL Web Ontology Language Reference at
http://www.w3.org/TR/owl-ref/.
The PL/SQL subprograms for working with semantic data are in the SEM_APIS package,
which is documented in SEM_APIS Package Subprograms.
The RDF and OWL support are features of Oracle Graph, which must be installed for these
features to be used. However, the use of RDF and OWL is not restricted to spatial data.
Note:
If you have any semantic data created using an Oracle Database release before
12.2, see Required Migration of Pre-12.2 Semantic Data.
For information about OWL concepts and the Oracle Database support for OWL capabilities,
see OWL Concepts .
Note:
Before performing any operations described in this guide, you must enable RDF
Graph support in the database and meet other prerequisites, as explained in
Enabling RDF Semantic Graph Support.
1-1
Chapter 1
1-2
Chapter 1
Introduction to Oracle Semantic Technologies Support
enterprise data
(relational)
Enterprise
query of
data
Database
QUERY
Query RDF/OWL
RDF/OWL
ontologies
data and
ontologies
data and
User-defined
Load & DML
Incremental
INFER
Bulk Load
STORE
RDF/S
OWL subset
As shown in Figure 1-1, the database contains semantic data and ontologies (RDF/OWL
models), as well as traditional relational data. To load semantic data, bulk loading is the most
efficient approach, although you can load data incrementally using transactional INSERT
statements.
1-3
Chapter 1
Semantic Data Modeling
Note:
If you want to use existing semantic data from a release before Oracle
Database 11.1, the data must be upgraded as described in Enabling RDF
Semantic Graph Support.
You can query semantic data and ontologies, and you can also perform ontology-
assisted queries of semantic and traditional relational data to find semantic
relationships. To perform ontology-assisted queries, use the SEM_RELATED operator,
which is described in Using Semantic Operators to Query Relational Data.
You can expand the power of queries on semantic data by using inferencing, which
uses rules in rulebases. Inferencing enables you to make logical deductions based on
the data and the rules. For information about using rules and rulebases for inferencing,
see Inferencing: Rules and Rulebases.
1-4
Chapter 1
Semantic Data in the Database
1-5
Chapter 1
Semantic Data in the Database
the single character 'ñ' instead of the ASCII escape sequence '\u00F1'). This
unescaped storage form reduces storage costs and increases query performance.
The network storage form can be specified in the options parameter of the
SEM_APIS.CREATE_SEM_NETWORK procedure at network creation time.
Unescaped storage form is the default in version 21c and later. Existing semantic
networks can be migrated using the SEM_APIS.MIGRATE_DATA_TO_STORAGE_V2
procedure.. Existing applications should not be affected by any changes in network
storage form.
A semantic network can be created in and owned by either the MDSYS schema or a
regular database user schema:
• If a network is created in the MDSYS schema, it is an unnamed semantic network
available to the entire database.
Having a single unnamed network was the only scenario available before Oracle
Database Release 19c. That usage is still supported, but discouraged, for
networks created starting with Release 19c.
• Regardless of the presence or absence of a network in the MDSYS schema in a
database, you can create or one more semantic networks in one or more regular
database user schemas. Each such network is called a schema-private semantic
network.
The use of schema-private networks is encouraged.
You can have both an MDSYS-owned network and one or more schema-private
networks in a single database or pluggable database.
An existing MDSYS-owned semantic network can be migrated to a shared schema-
private semantic network by using the SEM_APIS.MOVE_SEM_NETWORK_DATA
and SEM_APIS.APPEND_SEM_NETWORK_DATA procedures. See Moving,
Restoring, and Appending a Semantic Network for details.
• Schema-Private Semantic Networks
• Types of Semantic Network Users
• Naming Conventions for Semantic Network Objects
• RDF_PARAMETER Table in Semantic Networks
• Migrating from MDSYS to Schema-Private Semantic Networks
• Sharing Schema-Private Semantic Networks
• Migrating from Escaped to Unescaped Storage Form
1-6
Chapter 1
Semantic Data in the Database
Schema-private semantic networks provide better isolation because database objects are
not shared among multiple database users by default. However, after granting
appropriate privileges, a network owner may share his or her schema-private semantic
network with other users.
• Regular users can perform administration operations on their own networks, for example,
index creation or network-wide statistics gathering.
The network owner can perform administration operations on the network without
needing DBA privileges. (By contrast, with an MDSYS-owned network, DBA privileges
are required to perform administration operations.)
Several schema-private semantic networks can coexist in a single database, PDB, or
even schema, which allows custom data type indexing schemes for different sets of RDF
data. For example, NETWORK1 can have only a spatial data type index while
NETWORK2 has only a text data type index.
Most SEM_APIS package subprograms now have network_owner and network_name
parameters to support schema-private semantic networks. Schema-private semantic
networks are identified by the two-element combination of network owner and network name,
which is specified in the last two parameters of the SEM_APIS.CREATE_SEM_NETWORK
call that created the network.
The following table describes the usage of the network_owner and network_name parameters
in subprograms that include them.
1-7
Chapter 1
Semantic Data in the Database
In many examples in this book, the name RDFUSER is given as a sample network
user name. There is nothing special about that name string; it could be the name
of any database user such as SCOTT, ANNA, or MARKETING.
For a schema-private network, the network owner is initially the only network user.
(However, other database users can be granted privileges on the network, thus
making them additional potential network users.)
1-8
Chapter 1
Semantic Data in the Database
Note:
Having the above access capabilities for a network allows a user to access only the
dictionary and metadata tables for the network. Models and entailments not owned
by the user are not accessible unless the network owner or the owner of the
individual models use the SEM_APIS.GRANT_MODEL_ACCESS_PRIV or
SEM_APIS.GRANT_MODEL_ACCESS_PRIVS subprogram to grant appropriate
privilege(s) for individual models or entailments in the network to the user.
Example 1-1 Sharing a Network and Granting Query Only Privilege to Another User
The following example shares a network named NET1, owned by user RDFUSER.
RDFUSER grants query-only access on NET1 with user RDFQ.
-- As RDFUSER, grant query only network access privilege for NET1 to RDFQ
EXECUTE
SEM_APIS.GRANT_NETWORK_ACCESS_PRIVS(network_owner=>'RDFUSER',network_name=>'N
ET1',network_user=>'RDFQ', options=>' QUERY_ONLY=T ');
1-9
Chapter 1
Semantic Data in the Database
-- Check metadata
SELECT *
FROM rdfuser.net1#sem_model$;
Example 1-2 Sharing a Network and Granting Read and Write Privileges to
Another User
The following example shares a network named NET1, owned by user RDFUSER,
with user RDFUSER2. Also RDFUSER grants query-only access on NET1 with user
RDFUSER3.
1-10
Chapter 1
Semantic Data in the Database
SEM_APIS.ENABLE_NETWORK_SHARING(network_owner=>'RDFUSER',network_name=>'NET1'
);
-- Check metadata
SELECT *
FROM rdfuser.net1#sem_model$;
-- As RDFUSER2, allow RDFUSER3 to select and query a model that RDFUSER2 owns
CONNECT rdfuser2/<password>
EXECUTE
SEM_APIS.GRANT_MODEL_ACCESS_PRIVS('M2','RDFUSER3',sys.odcivarchar2list('SELEC
T','QUERY'),network_owner=>'RDFUSER',network_name=>'NET1');
1-11
Chapter 1
Semantic Data in the Database
1-12
Chapter 1
Semantic Data in the Database
way that the application table can in MDSYS networks. However, there is one exception:
SEM_APIS.TRUNCATE_SEM_MODEL should be used instead of a SQL TRUNCATE
operation on RDFT_<model_name>. The model owner is given SELECT, INSERT,
UPDATE, and DELETE privileges WITH GRANT OPTION on RDFT_<model_name>.
The SEM_MODEL$ view contains information about all models defined in a semantic
network. When you create a model using the SEM_APIS.CREATE_SEM_MODEL procedure,
you specify a name for the model, as well as a table and column to hold references to the
semantic data, and the system automatically generates a model ID.
Oracle maintains the SEM_MODEL$ view automatically when you create and drop models.
Users should never modify this view directly. For example, do not use SQL INSERT,
UPDATE, or DELETE statements with this view.
The SEM_MODEL$ view contains the columns shown in Table 1-2.
When you create a model, a view for the triples associated with the model is also created
under the network owner’s schema. This view has a name in the format SEMM_model-name,
and it is visible only to the owner of the model and to users with suitable privileges. Each
SEMM_model-name view contains a row for each triple (stored as a link in a network), and it
has the columns shown in Table 1-3.
1-13
Chapter 1
Semantic Data in the Database
Note:
In Table 1-3, for columns P_VALUE_ID, START_NODE_ID, END_NODE_ID,
CANON_END_NODE_ID, and G_ID, the actual ID values are computed from
the corresponding lexical values. However, a lexical value may not always
map to the same ID value.
1.3.3 Statements
The RDF_VALUE$ table contains information about the subjects, properties, and
objects used to represent RDF statements. It uniquely stores the text values (URIs or
literals) for these three pieces of information, using a separate row for each part of
each triple.
Oracle maintains the RDF_VALUE$ table automatically. Users should never modify
this view directly. For example, do not use SQL INSERT, UPDATE, or DELETE
statements with this view.
The RDF_VALUE$ table contains the columns shown in Table 1-4.
1-14
Chapter 1
Semantic Data in the Database
1-15
Chapter 1
Semantic Data in the Database
Note:
Although duplicate triples and quads are not stored in the underlying table
partition for the RDFM_<model> view, it is possible to have duplicate rows in
an application table. For example, if a triple is inserted multiple times into an
application table, it will appear once in the RDFM_<model> view, but will
occupy multiple rows in the application table.
Value-based matching of lexical forms is supported for the following data types:
• STRING: plain literal, xsd:string and some of its XML Schema subtypes
• NUMERIC: xsd:decimal and its XML Schema subtypes, xsd:float, and xsd:double.
(Support is not provided for float/double INF, -INF, and NaN values.)
• DATETIME: xsd:datetime, with support for time zone. (Without time zone there are
still multiple representations for a single value, for example,
"2004-02-18T15:12:54" and "2004-02-18T15:12:54.0000".)
• DATE: xsd:date, with or without time zone
• OTHER: Everything else. (No attempt is made to match different representations).
1-16
Chapter 1
Semantic Data in the Database
Canonicalization is performed when the time zone is present for literals of type xsd:time and
xsd:dateTime.
The following namespace definition is used: xmlns:xsd="http://www.w3.org/2001/
XMLSchema"
The first occurrence of a long literal in the RDF_VALUE$ table is taken as the canonical form
and given the VALUE_TYPE value of CPLL, CPLL@, or CTLL as appropriate; that is, a C for
canonical is prefixed to the actual value type. If a long literal with the same canonical form
(but a different lexical representation) as a previously inserted long literal is inserted into the
RDF_VALUE$ table, the VALUE_TYPE value assigned to the new insertion is PLL, PLL@, or
TLL as appropriate.
Canonically equivalent text values having different lexical representations are thus stored in
the RDF_VALUE$ table; however, canonically equivalent triples are not stored in the
database.
1.3.6 Properties
Properties are mapped to links that have their start node and end node as subjects and
objects, respectively. Therefore, a link represents a complete triple.
When a triple is inserted into a model, the subject, property, and object text values are
checked to see if they already exist in the database. If they already exist (due to previous
statements in other models), no new entries are made; if they do not exist, three new rows
are inserted into the RDF_VALUE$ table (described in Statements).
1-17
Chapter 1
Semantic Data in the Database
Figure 1-2 shows triple sets being inferred from model data and the application of rules
in one or more rulebases. In this illustration, the database can have any number of
semantic models, rulebases, and inferred triple sets, and an inferred triple set can be
derived using rules in one or more rulebases.
Rulebase 1 Rulebase 2 . .
Inferred
Model 1
Triple Set 1
Inferred
. . .
Model 2
Triple Set 2
. .
A rule is an object that can be applied to draw inferences from semantic data. A rule is
identified by a name and consists of:
• An IF side pattern for the antecedents
• A THEN side pattern for the consequents
For example, the rule that a chairperson of a conference is also a reviewer of the
conference could be represented as follows:
('chairpersonRule', -- rule name
'(?r :ChairPersonOf ?c)', -- IF side pattern
NULL, -- filter condition
'(?r :ReviewerOf ?c)', -- THEN side pattern
SEM_ALIASES (SEM_ALIAS('', 'http://some.org/test/'))
)
For best performance, use a single-triple pattern on the THEN side of the rule. If a rule
has multiple triple patterns on the THEN side, you can easily break it into multiple
rules, each with a single-triple pattern, on the THEN side.
A rulebase is an object that contains rules. The following Oracle-supplied rulebases
are provided:
• RDFS
• RDF (a subset of RDFS)
• OWLSIF (empty)
• RDFS++ (empty)
• OWL2EL (empty)
• OWL2RL (empty)
• OWLPrime (empty)
• SKOSCORE (empty)
The RDFS and RDF rulebases are created when you call the
SEM_APIS.CREATE_SEM_NETWORK procedure to add RDF support to the
1-18
Chapter 1
Semantic Data in the Database
database. The RDFS rulebase implements the RDFS entailment rules, as described in the
World Wide Web Consortium (W3C) RDF Semantics document at http://www.w3.org/TR/
rdf-mt/. The RDF rulebase represents the RDF entailment rules, which are a subset of the
RDFS entailment rules. You can see the contents of these rulebases by examining the
SEMR_RDFS and SEMR_RDF views.
You can also create user-defined rulebases using the SEM_APIS.CREATE_RULEBASE
procedure. User-defined rulebases enable you to provide additional specialized inferencing
capabilities.
For each rulebase, a table is created to hold rules in the rulebase, along with a view with a
name in the format SEMR_rulebase-name (for example, SEMR_FAMILY_RB for a rulebase
named FAMILY_RB). You must use this view to insert, delete, and modify rules in the rulebase.
Each SEMR_rulebase-name view has the columns shown in Table 1-5.
Information about all rulebases is maintained in the SEM_RULEBASE_INFO view, which has
the columns shown in Table 1-6 and one row for each rulebase.
1-19
Chapter 1
Semantic Data in the Database
Note that the kind of grandparent rule shown in Example 1-3 can be implemented
using the OWL 2 property chain construct. For information about property chain
handling, see Property Chain Handling.
Example 1-4 Using Rulebases for Inferencing
You can specify one or more rulebases when calling the SEM_MATCH table function
(described in Using the SEM_MATCH Table Function to Query Semantic Data), to
control the behavior of queries against semantic data. Example 1-4 refers to the
family_rb rulebase and to the grandParentOf relationship created in Example 1-3, to
find all grandfathers (grandparents who are male) and their grandchildren. (This
example is an excerpt from Example 1-124 in Example: Family Information.)
-- Select all grandfathers and their grandchildren from the family model.
-- Use inferencing from both the RDFS and family_rb rulebases.
SELECT x$rdfterm grandfather, y$rdfterm grandchild
FROM TABLE(SEM_MATCH(
'PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX : <http://www.example.org/family/>
SELECT ?x ?y
WHERE {?x :grandParentOf ?y . ?x rdf:type :Male}',
SEM_Models('family'),
SEM_Rulebases('RDFS','family_rb'),
null, null, null,
' PLUS_RDFT=VC ',
null, null,
'RDFUSER', 'NET1'));
For information about support for native OWL inferencing, see Using OWL Inferencing.
1-20
Chapter 1
Semantic Data in the Database
Information about all database objects, such as models and rulebases, related to entailments
is maintained in the SEM_RULES_INDEX_DATASETS view. This view has the columns
shown in Table 1-8 and one row for each unique combination of values of all the columns.
Example 1-5 creates an entailment named family_rb_rix_family, using the family model
and the RDFS and family_rb rulebases. (This example is an excerpt from Example 1-124 in
Example: Family Information.)
Example 1-5 Creating an Entailment
BEGIN
SEM_APIS.CREATE_ENTAILMENT(
'rdfs_rix_family',
SEM_Models('family'),
SEM_Rulebases('RDFS','family_rb'),
network_owner=>'RDFUSER', network_name=>'NET1');
END;
/
1-21
Chapter 1
Semantic Data in the Database
Queries against a single model can more effectively use partition pruning and are able
to use local optimizer statistics for the single-model's partition, compared to queries
against a virtual model. Queries against a virtual model use global optimizer statistics
for the entire semantic network, which can be less accurate than local, model-level
statistics. Hence, where possible you must combine the datasets that are queried
together into a single model.
Besides using virtual models for development, you can also use them if you need to
access data across multiple RDF models in a single query, and also need to keep the
individual models separate for other queries. However, if possible, you must combine
the datasets that are queried together into a single model.
Using a virtual model, during the development phase of a project, provides the
following benefits:
• It can simplify management of access privileges for semantic data. For example,
assume that you have created three semantic models and one entailment based
on the three models and the OWLPrime rulebase. Without a virtual model, you
must individually grant and revoke access privileges for each model and the
entailment. However, if you create a virtual model that contains the three models
and the entailment, you will only need to grant and revoke access privileges for the
single virtual model.
• It can facilitate rapid updates to semantic models. For example, assume that
virtual model VM1 contains model M1 and entailment R1 (that is, VM1 = M1
UNION ALL R1), and assume that semantic model M1_UPD is a copy of M1 that
has been updated with additional triples and that R1_UPD is an entailment created
for M1_UPD. Now, to have user queries over VM1 go to the updated model and
entailment, you can redefine virtual model VM1 (that is, VM1 = M1_UPD UNION
ALL R1_UPD).
• It can simplify query specification because querying a virtual model is equivalent to
querying multiple models in a SEM_MATCH query. For example, assume that
models m1, m2, and m3 already exist, and that an entailment has been created for
m1, m2 ,and m3 using the OWLPrime rulebase. You could create a virtual model
vm1 as follows:
EXECUTE sem_apis.create_virtual_model('vm1', sem_models('m1', 'm2', 'm3'),
sem_rulebases('OWLPRIME'),
network_owner=>'RDFUSER',
network_name=>'NET1');
To query the virtual model, use the virtual model name as if it were a model in a
SEM_MATCH query. For example, the following query on the virtual model:
SELECT * FROM TABLE (sem_match('{…}', sem_models('vm1'), null, …));
A SEM_MATCH query over a virtual model will query either the SEMV or SEMU
view (SEMU by default and SEMV if the 'ALLOW_DUP=T' option is specified)
rather than querying the UNION or UNION ALL of each model and entailment. For
information about these views and options, see the reference section for the
SEM_APIS.CREATE_VIRTUAL_MODEL procedure.
Virtual models use views (described later in this section) and add some metadata
entries, but do not significantly increase system storage requirements.
1-22
Chapter 1
Semantic Data in the Database
Information about all virtual models is maintained in the SEM_VMODEL_INFO view, which
has the columns shown in Table 1-10 and one row for each virtual model.
1-23
Chapter 1
Semantic Data in the Database
Information about all objects (models, rulebases, and entailments) related to virtual
models is maintained in the SEM_VMODEL_DATASETS view. This view has the
columns shown in Table 1-11 and one row for each unique combination of values of all
the columns.
1-24
Chapter 1
Semantic Data in the Database
This support is provided by extending an RDF triple consisting of the traditional subject,
predicate, and object, to include an additional component to represent a graph name. The
extended RDF triple, despite having four components, will continue to be referred to as an
RDF triple in this document. In addition, the following terms are sometimes used:
• N-Triple is a format that does not allow extended triples. Thus, n-triples can include only
triples with three components.
• N-Quad is a format that allows both "regular" triples (three components) and extended
triples (four components, including the graph name). For more information, see http://
www.w3.org/TR/2013/NOTE-n-quads-20130409/.
To load a file containing extended triples (possibly mixed with regular triples) into an
Oracle database, the input file must be in N-Quad format.
The graph name component of an RDF triple must either be null or a URI. If it is null, the RDF
triple is said to belong to a default graph; otherwise it is said to belong to a named graph
whose name is designated by the URI.
Additionally, to support named graphs in SDO_RDF_TRIPLE_S object type (described in
Semantic Data Types_ Constructors_ and Methods), a new syntax is provided for specifying
a model-graph, that is, a combination of model and graph (if any) together, and the
RDF_M_ID attribute holds the identifier for a model-graph: a combination of model ID and
value ID for the graph (if any). The name of a model-graph is specified as model_name, and
if a graph is present, followed by the colon (:) separator character and the graph name
(which must be a URI and enclosed within angle brackets < >).
For example, in a medical data set the named graph component for each RDF triple might be
a URI based on patient identifier, so there could be as many named graphs as there are
unique patients, with each named graph consisting of data for a specific patient.
For information about performing specific operations with named graphs, see the following:
• Using constructors and methods: Semantic Data Types_ Constructors_ and Methods
• Loading: Loading N-Quad Format Data into a Staging Table Using an External Table and
Loading Data into Named Graphs Using INSERT Statements
• Querying: GRAPH Keyword Support and Expressions in the SELECT Clause
• Inferencing: Using Named Graph Based Inferencing (Global and Local)
• Data Formats Related to Named Graph Support
1-25
Chapter 1
Semantic Data in the Database
# Default graph
{
<http://my.com/John> dc:publisher <http://publisher/Xyz> .
}
# A named graph
<http://my.com/John> {
<http://my.com/John> foaf:name "John Doe" .
}
When loading the TriG file from Example 1-7 into a DatasetGraphOracleSem object (for
example, using Example 7-12 in Bulk Loading Using RDF Semantic Graph Support for
Apache Jena, but replacing the constant "N-QUADS" with "TRIG"), the triples in the
default graph will be loaded into Oracle Database as triples with null graph names, and
the triples in the named graphs will be loaded into Oracle Database with the
designated graph names.
Example 1-8 N-QUADS Format Representation
N-QUADS format is a simple extension of the existing N-TRIPLES format by adding an
optional fourth column (graph name or context). Example 1-8 shows the N-QUADS
format representation of the TriG file from Example 1-7.
<http://my.com/John> <http://purl.org/dc/elements/1.1/publisher> <http://
publisher/Xyz> .
<http://my.com/John> <http://xmlns.com/foaf/0.1/name> "John Doe" <http://my.com/
John>
1-26
Chapter 1
Semantic Metadata Tables and Views
• The creator of the base table corresponding to a model can grant privileges to other
users.
• To perform data manipulation language (DML) operations on a rulebase, a user must
have the appropriate privileges on the corresponding database view.
• The creator of a model can grant SELECT privileges on the corresponding database view
to other users.
• A user can query only those models for which that user has SELECT privileges to the
corresponding database views.
• Only the creator of a model or a rulebase can drop it.
1-27
Chapter 1
Semantic Data Types, Constructors, and Methods
Note:
Blank nodes are always reused within an RDF model and cannot be reused
across models
1-28
Chapter 1
Semantic Data Types, Constructors, and Methods
The SDO_RDF_TRIPLE_S type has the following methods that retrieve the name of the RDF
model (or model-graph), or a part (subject, property, or object) of a triple:
GET_MODEL(
NETWORK_OWNER VARCHAR2 DEFAULT NULL,
NETWORK_NAME VARCHAR2 DEFAULT NULL) RETURNS VARCHAR2
GET_SUBJECT(
NETWORK_OWNER VARCHAR2 DEFAULT NULL,
NETWORK_NAME VARCHAR2 DEFAULT NULL) RETURNS VARCHAR2
GET_PROPERTY(
NETWORK_OWNER VARCHAR2 DEFAULT NULL,
NETWORK_NAME VARCHAR2 DEFAULT NULL) RETURNS VARCHAR2
GET_OBJECT(
NETWORK_OWNER VARCHAR2 DEFAULT NULL,
NETWORK_NAME VARCHAR2 DEFAULT NULL) RETURNS CLOB
GET_OBJ_VALUE(
NETWORK_OWNER VARCHAR2 DEFAULT NULL,
NETWORK_NAME VARCHAR2 DEFAULT NULL) RETURNS VARCHAR2
SUBJECT
--------------------------------------------------------------------------------
<http://nature.example.com/Article1>
SUBJECT
--------------------------------------------------------------------------------
PROPERTY
--------------------------------------------------------------------------------
OBJECT
--------------------------------------------------------------------------------
<http://nature.example.com/Article1>
<http://purl.org/dc/elements/1.1/title>
"All about XYZ"
<http://nature.example.com/Article1>
<http://purl.org/dc/elements/1.1/creator>
"Jane Smith"
<http://nature.example.com/Article1>
<http://purl.org/dc/terms/references>
1-29
Chapter 1
Semantic Data Types, Constructors, and Methods
<http://nature.example.com/Article2>
<http://nature.example.com/Article1>
<http://purl.org/dc/terms/references>
<http://nature.example.com/Article3
OBJECT
--------------------------------------------------------------------------------
"All about XYZ"
"Jane Smith"
<http://nature.example.com/Article2>
<http://nature.example.com/Article3>
SUBJECT
--------------------------------------------------------------------------------
PROPERTY
--------------------------------------------------------------------------------
OBJECT
--------------------------------------------------------------------------------
<http://nature.example.com/Article1>
<http://purl.org/dc/elements/1.1/creator>
"Jane Smith"
SDO_RDF_TRIPLE_S (
model_name VARCHAR2, -- Model name
subject VARCHAR2, -- Subject
property VARCHAR2, -- Property
object CLOB, -- Object
network_owner VARCHAR2 DEFAULT NULL,
1-30
Chapter 1
Using the SEM_MATCH Table Function to Query Semantic Data
Example 1-10 uses the first constructor format to insert several triples.
Example 1-10 SDO_RDF_TRIPLE_S Constructor to Insert Triples
INSERT INTO RDFUSER.NET1#RDFT_ARTICLES VALUES (
SDO_RDF_TRIPLE_S ('articles','<http://nature.example.com/Article1>',
'<http://purl.org/dc/elements/1.1/creator>',
'"Jane Smith"',
'RDFUSER',
'NET1'));
The query and models attributes are required. The other attributes are optional (that is, each
can be a null value).
The query attribute is a string literal (or concatenation of string literals) with one or more triple
patterns, usually containing variables. (The query attribute cannot be a bind variable or an
expression involving a bind variable.) A triple pattern is a triple of atoms followed by a period.
Each atom can be a variable (for example, ?x), a qualified name (for example, rdf:type) that
1-31
Chapter 1
Using the SEM_MATCH Table Function to Query Semantic Data
is expanded based on the default namespaces and the value of the aliases attribute,
or a full URI (for example, <http://www.example.org/family/Male>). In addition, the
third atom can be a numeric literal (for example, 3.14), a plain literal (for example,
"Herman"), a language-tagged plain literal (for example, "Herman"@en), or a typed
literal (for example, "123"^^xsd:int).
For example, the following query attribute specifies three triple patterns to find
grandfathers (that is, grandparents who are also male) and the height of each of their
grandchildren:
'SELECT * WHERE { ?x :grandParentOf ?y . ?x rdf:type :Male . ?y :height ?h }'
The models attribute identifies the model or models to use. Its data type is
SEM_MODELS, which has the following definition: TABLE OF VARCHAR2(25). If you are
querying a virtual model, specify only the name of the virtual model and no other
models. (Virtual models are explained in Virtual Models.)
The rulebases attribute identifies one or more rulebases whose rules are to be applied
to the query. Its data type is SDO_RDF_RULEBASES, which has the following
definition: TABLE OF VARCHAR2(25). If you are querying a virtual model, this attribute
must be null.
The aliases attribute identifies one or more namespaces, in addition to the default
namespaces, to be used for expansion of qualified names in the query pattern. Its data
type is SEM_ALIASES, which has the following definition: TABLE OF SEM_ALIAS, where
each SEM_ALIAS element identifies a namespace ID and namespace value. The
SEM_ALIAS data type has the following definition: (namespace_id VARCHAR2(30),
namespace_val VARCHAR2(4000))
You can override any of these defaults by specifying the namespace_id value and a
different namespace_val value in the aliases attribute.
The filter attribute identifies any additional selection criteria. If this attribute is not
null, it should be a string in the form of a WHERE clause without the WHERE keyword. For
example: '(h >= ''6'')' to limit the result to cases where the height of the
grandfather's grandchild is 6 or greater (using the example of triple patterns earlier in
this section).
1-32
Chapter 1
Using the SEM_MATCH Table Function to Query Semantic Data
Note:
Instead of using the filter attribute, you are encouraged to use the FILTER
keyword inside your query pattern whenever possible (as explained in Graph
Patterns: Support for Curly Brace Syntax_ and OPTIONAL_ FILTER_ UNION_ and
GRAPH Keywords). Using the FILTER keyword is likely to give better performance
because of internal optimizations. The filter argument, however, can be useful if
you require SQL constructs that cannot be expressed with the FILTER keyword.
The index_status attribute lets you query semantic data even when the relevant entailment
does not have a valid status. (If you are querying a virtual model, this attribute refers to the
entailment associated with the virtual model.) If this attribute is null, the query returns an error
if the entailment does not have a valid status. If this attribute is not null, it must be the string
INCOMPLETE or INVALID. For an explanation of query behavior with different index_status
values, see Performing Queries with Incomplete or Invalid Entailments.
The options attribute identifies options that can affect the results of queries. Options are
expressed as keyword-value pairs. The following options are supported:
• ALL_AJ_HASH, ALL_AJ_MERGE, and ALL_BGP_NL are global query optimizer hints that specify
that all anti joins for NOT EXISTS and MINUS operations should use the specified join
type.
• ALL_BGP_HASH and ALL_BGP_NL are global query optimizer hints that specify that all inter-
BGP joins (for example. the join between the root BGP and an OPTIONAL BGP) should
use the specified join type. (BGP stands for basic graph pattern. From the W3C SPARQL
Query Language for RDF Recommendation: "SPARQL graph pattern matching is defined
in terms of combining the results from matching basic graph patterns. A sequence of
triple patterns interrupted by a filter comprises a single basic graph pattern. Any graph
pattern terminates a basic graph pattern."
The BGP_JOIN(USE_NL) and BGP_JOIN(USE_HASH) HINT0 query optimizer hints can be
used to control the join type with finer granularity.
Example 1-17 shows the ALL_BGP_HASH option used in a SEM_MATCH query.
• AUTO_HINTS=T automatically detects and generates USE_HASH hints for unselective
SPARQL queries.
• ALL_LINK_HASH and ALL_LINK_NL are global query optimizer hints that specify the join
type for all RDF_LINK$ joins (that is, all joins between triple patterns within a BGP).
ALL_LINK_HASH and ALL_LINK_NL can also be used within a HINT0 query optimizer hint
for finer granularity.
• ALL_MAX_PP_DEPTH(n) is a global query optimizer hint that sets the maximum depth to
use when evaluating * and + property path operators. The default value is 10. The
MAX_PP_DEPTH(n) HINT0 hint can be used to specify maximum depth with finer
granularity.
• ALL_NO_MERGE is a global query optimizer hint that adds NO_MERGE to each subquery in the
generated SQL for a SPARQL query.This hint is used to ensure that a selective subquery
in a SPARQL query is not merged with the other parts of the SPARQL query.
• ALL_ORDERED is a global query optimizer hint that specifies that the triple patterns in each
BGP in the query should be evaluated in order.
Example 1-17 shows the ALL_ORDERED option used in a SEM_MATCH query.
1-33
Chapter 1
Using the SEM_MATCH Table Function to Query Semantic Data
• ALL_USE_PP_HASH and ALL_USE_PP_NL are global query optimizer hints that specify
the join type to use when evaluating property path expressions. The USE_PP_HASH
and USE_PP_NL HINT0 hints can be used for specifying join type with finer
granularity.
• ALLOW_DUP=T generates an underlying SQL statement that performs a "union all"
instead of a union of the semantic models and inferred data (if applicable). This
option may introduce more rows (duplicate triples) in the result set, and you may
need to adjust the application logic accordingly. If you do not specify this option,
duplicate triples are automatically removed across all the models and inferred data
to maintain the set semantics of merged RDF graphs; however, removing
duplicate triples increases query processing time. In general, specifying
'ALLOW_DUP=T' improves performance significantly when multiple semantic models
are involved in a SEM_MATCH query.
If you are querying a virtual model, specifying ALLOW_DUP=T causes the
SEMV_vm_name view to be queried; otherwise, the SEMU_vm_name view is
queried.
• ALLOW_PP_DUP=T allows duplicate results for + and * property path queries.
Allowing duplicate results may return the first result rows faster.
• AS_OF [SCN, <SCN_VALUE>] , where <SCN_VALUE> is a valid system change
number, indicates that Flashback Query should be used to query the state of the
semantic network as of the specified SCN.
• AS_OF [TIMESTAMP, <TIMESTAMP_VALUE>] , where <TIMESTAMP_VALUE> is a
valid timestamp string with format 'YYYY/MM/DD HH24:MI:SS.FF', indicates that
Flashback Query should be used to query the state of the semantic network as of
the specified timestamp.
• CLOB_AGG_SUPPORT=T enables support for CLOB values for the following
aggregates: MIN, MAX, GROUP_CONCAT, SAMPLE. Note that enabling CLOB
support incurs a significant performance penalty.
• CLOB_EXP_SUPPORT=T enables support for CLOB values for some built-in SPARQL
functions. Note that enabling CLOB support incurs a significant performance
penalty.
• CONSTRUCT_STRICT=T eliminates invalid RDF triples from the result of SPARQL
CONSTRUCT or SPARQL DESCRIBE syntax queries. RDF triples with literals in
the subject position or literals or blank nodes in the predicate position are
considered invalid.
• CONSTRUCT_UNIQUE=T eliminates duplicate RDF triples from the result of SPARQL
CONSTRUCT or SPARQL DESCRIBE syntax queries.
• DISABLE_IM_VIRTUAL_COL specifies that the query compiler should not use in-
memory virtual columns.
• DISABLE_MVIEW specifies that the query compiler should not use materialized
views.
• DISABLE_NULL_EXPR_JOIN specifies that the query compiler should assume that all
SELECT expressions produce non-null output.
• DISABLE_SAMEAS_BLOOM specifies that the query compiler should not use a Bloom
filter when owl:sameAs triples are joined. (For detailed information, see the
explanation of Bloom filters in Oracle Database SQL Tuning Guide.)
1-34
Chapter 1
Using the SEM_MATCH Table Function to Query Semantic Data
1-35
Chapter 1
Using the SEM_MATCH Table Function to Query Semantic Data
• PLUS_RDFT=VC can be used with SPARQL SELECT syntax (see Expressions in the
SELECT Clause) to additionally return a var$RDFTERM VARCHAR2(4000)
column for each projected query variable. The value for this column is equivalent
to the result of SEM_APIS.COMPOSE_RDF_TERM(var, var$RDFVTYP,
var$RDFLTYP, var$RDFLANG). When using this option, the return columns for
each variable var will be var, var$RDFVID, var$_PREFIX, var$_SUFFIX,
var$RDFVTYP, var$RDFCLOB, var$RDFLTYP, var$RDFLANG, and
var$RDFTERM.
• PROJ_EXACT_VALUES=T disables canonicalization of values returned from functions
and of constant values used in value assignment statements. Such values are
canonicalized by default.
• SERVICE_CLOB=F sets the column values of var$RDFCLOB to null instead of saving
values when calling the service. If CLOB data is not needed in your application,
performance can be improved by using this option to skip CLOB processing.
• SERVICE_ESCAPE=F disables character escaping for RDF literal values returned by
SPARQL SERVICE calls. RDF literal values are escaped by default. If character
escaping is not relevant for your application, performance can be improved by
disabling character escaping.
• SERVICE_JPDWN=T is a query optimizer hint for using nested loop join in SPARQL
SERVICE. Example 1-73 shows the SERVICE_JPDWN=T option used in a
SEM_MATCH query.
• SERVICE_PROXY=<proxy-string> sets a proxy address to be used when
performing http connections. The given proxy-string will be used in SERVICE
queries. Example 1-76 shows a SEM_MATCH query including a proxy address.
• STRICT_AGG_CARD=T uses SPARQL semantics (one null row) instead of SQL
semantics (zero rows) for aggregate queries with graph patterns that fail to match.
This option incurs a slight performance penalty.
• STRICT_DEFAULT=T restricts the default graph to unnamed triples when no dataset
information is specified.
The graphs attribute specifies the set of named graphs from which to construct the
default graph for a SEM_MACH query. Its data type is SEM_GRAPHS, which has the
following definition: TABLE OF VARCHAR2(4000). The default value for this attribute is
NULL. When graphs is NULL, the "union all" of all graphs in the set of query models is
used as the default graph.
The named_graphs attribute specifies the set of named graphs that can be matched by
a GRAPH clause. Its data type is SEM_GRAPHS, which has the following definition:
TABLE OF VARCHAR2(4000). The default value for this attribute is NULL. When
named_graphs is NULL, all named graphs in the set of query models can be matched
by a GRAPH clause.
The network_owner attribute specifies the schema that owns the semantic network
that contains the RDF model or virtual model specified in the models attribute. This
attribute should be non-null to query a schema-private semantic network. A NULL value
for network_owner implies the MDSYS-owned semantic network
The network_name attribute specifies the name of the semantic network that contains
the RDF model or virtual model specified in the models attribute. This attribute should
be non-null to query a schema-private semantic network. A NULL value for
network_name implies the unnamed MDSYS-owned semantic network.
1-36
Chapter 1
Using the SEM_MATCH Table Function to Query Semantic Data
The SEM_MATCH table function returns an object of type ANYDATASET, with elements that
depend on the input variables. In the following explanations, var represents the name of a
variable used in the query. For each variable var, the result elements have the following
attributes: var, var$RDFVID, var$_PREFIX, var$_SUFFIX, var$RDFVTYP, var$RDFCLOB,
var$RDFLTYP, and var$RDFLANG.
In such cases, var has the lexical value bound to the variable, var$RDFVID has the
VALUE_ID of the value bound to the variable, var$_PREFIX and var$_SUFFIX are the prefix
and suffix of the value bound to the variable, var$RDFVTYP indicates the type of value
bound to the variable (URI, LIT [literal], or BLN [blank node]), var$RDFCLOB has the lexical
value bound to the variable if the value is a long literal, var$RDFLTYP indicates the type of
literal bound if a literal is bound, and var$RDFLANG has the language tag of the bound literal
if a literal with language tag is bound. var$RDFCLOB is of type CLOB, while all other
attributes are of type VARCHAR2.
For a literal value or a blank node, its prefix is the value itself and its suffix is null. For a URI
value, its prefix is the left portion of the value up to and including the rightmost occurrence of
any of the three characters / (slash), # (pound), or : (colon), and its suffix is the remaining
portion of the value to the right. For example, the prefix and suffix for the URI value http://
www.example.org/family/grandParentOf are http://www.example.org/family/ and
grandParentOf, respectively.
Along with columns for variable values, a SEM_MATCH query that uses SPARQL SELECT
syntax returns one additional NUMBER column, SEM$ROWNUM, which can be used to
ensure the correct result ordering for queries that involve a SPARQL ORDER BY clause.
A SEM_MATCH query that uses SPARQL ASK syntax returns the columns ASK,
ASK$RDFVID, ASK$_PREFIX, ASK$_SUFFIX, ASK$RDFVTYP, ASK$RDFCLOB,
ASK$RDFLTYP, ASK$RDFLANG, and SEM$ROWNUM. This is equivalent to a SPARQL
SELECT syntax query that projects a single ?ask variable.
1-37
Chapter 1
Using the SEM_MATCH Table Function to Query Semantic Data
As shown in Example 1-14, the search pattern for the SEM_MATCH table function is
specified using SPARQL syntax where the variable starts with the question-mark
character (?). In this example, the variable ?r must match to the same term, and thus it
must be a subclass of both Proteins and Complexes.
1-38
Chapter 1
Using the SEM_MATCH Table Function to Query Semantic Data
1-39
Chapter 1
Using the SEM_MATCH Table Function to Query Semantic Data
Function Description
ABS(RDF term) Returns the absolute value of term. If term is
a non-numerical value, returns null.
BNODE(literal) or BNODE() Constructs a blank node that is distinct from all
blank nodes in the dataset of the query, and
those created by this function in other queries.
The form with no arguments results in a
distinct blank node in every call. The form with
a simple literal results in distinct blank nodes
for different simple literals, and the same blank
node for calls with the same simple literal.
BOUND(variable) BOUND(x) returns true if x is bound (that is,
non-null) in the result, false otherwise.
CEIL(RDF term) Returns the closest number with no fractional
part which is not less than term. If term is a
non-numerical value, returns null.
COALESCE(term list) Returns the first element on the argument list
that is evaluated without raising an error.
Unbound variables raise an error if evaluated.
Returns null if there are no valid elements in
the term list.
CONCAT(term list) Returns an xsd:String value resulting of the
concatenation of the string values in the term
list.
CONTAINS(literal, match) Returns true if the string match is found
anywhere in literal. It returns false
otherwise.
1-40
Chapter 1
Using the SEM_MATCH Table Function to Query Semantic Data
Function Description
DATATYPE(literal) DATATYPE(x) returns a URI representing the
datatype of x.
DAY(argument) Returns an integer corresponding to the day
part of argument. If the argument is not a
dateTime or date data type, it returns a null
value.
ENCODE_FOR_URI(literal) Returns a string where the reserved
characters in literal are escaped and
converted to its percent-encode form.
EXISTS(pattern) Returns true if the pattern matches the query
data set, using the current bindings in the
containing group graph pattern and the current
active graph. If there are no matches, it returns
false.
FLOOR(RDF term) Returns the closest number with no fractional
part which is less than term. If term is a non-
numerical value, returns null.
HOURS(argument) Returns an integer corresponding to the hours
part of argument. If the argument is not a
dateTime or date data type, it returns a null
value.
IF(condition , expression1, expression2) Evaluates the condition and obtains the
effective Boolean value. If true, the first
expression is evaluated and its value returned.
If false, the second expression is used. If the
condition raises an error, the error is passed
as the result of the IF statement.
IRI(RDF term) Returns an IRI resolving the string
representation of argument term. If there is a
base IRI defined in the query, the IR is resolve
against it, and the result must result in an
absolute IRI.
isBLANK(RDF term) isBLANK(x) returns true if x is a blank node,
false otherwise.
isIRI(RDF term) isIRI(x) returns true if x is an IRI, false
otherwise.
isLITERAL(RDF term) isLiteral(x) returns true if x is a literal, false
otherwise.
IsNUMERIC(RDF term) Returns true if term is a numeric value,
false otherwise.
isURI(RDF term) isURI(x) returns true if x is a URI, false
otherwise.
LANG(literal) LANG(x) returns a plain literal serializing the
language tag of x.
LANGMATCHES(literal, literal) LANGMATCHES(x, y) returns true if
language tag x matches language range y,
false otherwise.
1-41
Chapter 1
Using the SEM_MATCH Table Function to Query Semantic Data
Function Description
LCASE(literal) Returns a string where each character in literal
is converted to its lowercase correspondent.
MD5(literal) Returns the checksum for literal,
corresponding to the MD5 hash function.
Note:
Starting from
Oracle Database
21c Release, the
use of MD5
algorithm is
deprecated. As
this function will
be desupported
in a future
release, it is
recommended to
replace MD5 with
one of the SHA
hash functions.
1-42
Chapter 1
Using the SEM_MATCH Table Function to Query Semantic Data
Function Description
REGEX(string, pattern, flags) REGEX(x,y,z) returns true if x matches the
regular expression y using the options given in
z, false otherwise. Available options: 's' –
dot all mode ('.' matches any character
including the newline character); 'm' –
multiline mode ('^' matches the beginning of
any line and '$' matches the end of any line);
'i' – case insensitive mode; 'x' – remove
whitespace characters from the regular
expression before matching.
REPLACE(string, pattern, replacement) Returns a string where each match of the
regular expression pattern in string is
replaced by replacement. For more
information about the regular expressions
supported, see the Oracle Regular Expression
Support appendix in Oracle Database SQL
Language Reference.
REPLACE(string, pattern, replacement, flags) Returns a string where each match of the
regular expression pattern in string is
replaced by replacement. Available options:
's' – dot all mode ('.' matches any
character including the newline character); 'm'
– multiline mode ('^' matches the beginning
of any line and '$' matches the end of any
line); 'i' – case insensitive mode; 'x' –
remove whitespace characters from the
regular expression before matching.
For more information about the regular
expressions supported, see the Oracle
Regular Expression Support appendix in
Oracle Database SQL Language Reference.
ROUND(RDF term) Returns the closest number with no fractional
part to term. If two values exist, the value
closer to positive infinite is returned. If term is
a non-numerical value, returns null.
sameTerm(RDF term, RDF term) sameTerm(x, y) returns true if x and y are the
same RDF term, false otherwise.
SECONDS(argument) Returns an integer corresponding to the
seconds part of argument. If the argument is
not a dateTime or date data type, it returns a
null value.
SHA1(literal) Returns the checksum for literal,
corresponding to the SHA1 hash function.
SHA256(literal) Returns the checksum for literal,
corresponding to the SHA256 hash function.
SHA384(literal) Returns the checksum for literal,
corresponding to the SHA384 hash function.
SHA512(literal) Returns the checksum for literal,
corresponding to the SHA512 hash function.
1-43
Chapter 1
Using the SEM_MATCH Table Function to Query Semantic Data
Function Description
STR(RDF term) STR(x) returns a plain literal of the string
representation of x (that is, what would be
stored in the VALUE_NAME column of
MDSYS.RDF_VALUE$ enclosed within double
quotes).
STRAFTER(literal, literal) StrAfter (x,y) returns the portion of the string
corresponding to substring that precedes in x
the first match of y, and the end of x. If y
cannot be matched inside x, the empty string
is returned.
STRBEFORE(literal, literal) StrBefore (x,y) returns the portion of the string
corresponding to the start of x and the first
match of y. If y cannot be matched inside x,
the empty string is returned.
STRDT(string, datatype) Construct a literal term composed by the
string lexical form and the datatype passed
as arguments. datatype must be a URI;
otherwise, the function returns a null value.
STRENDS(literal, match) Returns true if the string literal ends with
the string match. It returns false otherwise.
STRLANG (string, languageTag) Constructs a string composed by the string
lexical form and language tag passed as
arguments.
STRLEN(literal) Returns the length of the lexical form of the
literal.
STRSTARTS(literal, match) Returns true if the string literal starts with
the string match. It returns false otherwise.
STRUUID() Returns a string containing the scheme
section of a new UUID.
SUBSTR(term, startPos) Returns the string corresponding to the portion
of term that starts at startPos and continues
until term ends. The index of the first character
is 1.
SUBSTR(term, startPos, length) Returns the string corresponding to the portion
of term that starts at startPos and continues
for length characters. The index of the first
character is 1.
term IN (term list) The expression x IN(term list) returns true if x
can be found in any of the values in
termlist. Returns false if not found. Zero-
length lists are legal. An error is raised if any of
the values in termlist raises an error and x
is not found.
1-44
Chapter 1
Using the SEM_MATCH Table Function to Query Semantic Data
Function Description
term NOT IN (term list) The expression x NOT IN(term list) returns
false if x can be found in any of the values in
term list. Returns true if not found. Zero-
length lists are legal. An error is raised if any of
the values in term list raises an error and x is
not found.
TIMEZONE(argument) Returns the time zones section of argument
as an xsd:dayTimeDuration value. If the
argument is not a dateTime or date data
type, it returns a null value.
TZ(argument) Returns an integer corresponding to the time
zone part of argument. If the argument is not
a dateTime or date data type, it returns a null
value.
UCASE(literal) Returns a string where each character in
literal is converted to its uppercase
correspondent.
URI(RDF term) (Synonym for IRI(RDF term)
UUID() Returns a URI with a new Universal Unique
Identifier. The value and the version
correspond to the PL/SQL function sys_guid
().
YEAR(argument) Returns an integer corresponding to the year
part of argument.
See also the descriptions of the built-in functions defined in the SPARQL query language
specification (http://www.w3.org/TR/sparql11-query/), to better understand the built-in
functions available in SEM_MATCH.
In addition, Oracle provides some proprietary query functions that take advantage of Oracle
Database features and help improve query performance. The following table lists these
Oracle-specific query functions. Note that the built-in namespace prefix orardf expands to
<http://xmlns.oracle.com/rdf/>.
Function Description
orardf:like(RDF term, pattern) Returns true if the given term matches with the given like pattern,
false otherwise. See Full-Text Search for more information.
orardf:sameCanonTerm(RDF Returns true if two terms represent the same canonical RDF term,
term, RDF term) false otherwise. Allows a VALUE_ID-based comparison, which is
more efficient than sameTerm(?x, ?y) or (?x = ?y).
orardf:textContains(RDF term, Returns true if the given term matches with the given Oracle Text
pattern) search pattern, false otherwise. See Full-Text Search for more
information.
orardf:textScore(invocation id) Returns the score of an orardf:textContains match. See Full-Text
Search for more information.
1-45
Chapter 1
Using the SEM_MATCH Table Function to Query Semantic Data
Function Description
(Spatial built-in functions) (See Spatial Support.)
The following XML Schema casting functions are available for use in FILTER clauses.
These functions take an RDF term as input and return a new RDF term of the desired
type or raise an error if the term cannot be cast to the desired type. Details of type
casting can be found in Section 17.1 of the XPath query specification: http://
www.w3.org/TR/xpath-functions/#casting-from-primitive-to-primitive. These
functions use the XML Namespace xsd : http://www.w3.org/2001/XMLSchema#.
1-46
Chapter 1
Using the SEM_MATCH Table Function to Query Semantic Data
SELECT x, y, game
FROM TABLE(SEM_MATCH(
'{?x :grandParentOf ?y . ?x rdf:type :Male .
OPTIONAL{?x :plays ?game}
}',
SEM_Models('family'),
SEM_Rulebases('RDFS','family_rb'),
SEM_ALIASES(SEM_ALIAS('','http://www.example.org/family/')),
null,
null,
'HINT0={LEADING(t0 t1) USE_NL(?x ?y)}',
null,
null,
'RDFUSER', 'NET1'));
1-47
Chapter 1
Using the SEM_MATCH Table Function to Query Semantic Data
Example 1-21 Curly Brace Syntax and FILTER with REGEX and STR Built-In
Constructs
Example 1-21 uses the REGEX built-in function to select all grandfathers who have an
Oracle email address. Note that backslash (\) characters in the regular expression
pattern must be escaped in the query string; for example, \\. produces the following
pattern: \.
SELECT x, y, z
FROM TABLE(SEM_MATCH(
'{?x :grandParentOf ?y . ?x rdf:type :Male . ?x :email ?z
FILTER (REGEX(STR(?z), "@oracle\\.com$"))}',
SEM_Models('family'),
SEM_Rulebases('RDFS','family_rb'),
SEM_ALIASES(SEM_ALIAS('','http://www.example.org/family/')),
null, null, ' ', null, null,
'RDFUSER', 'NET1'));
1-48
Chapter 1
Using the SEM_MATCH Table Function to Query Semantic Data
Example 1-22 Curly Brace Syntax and UNION and FILTER Constructs
Example 1-22 uses the UNION construct to modify Example 1-20, so that grandfathers are
returned only if they are residents of NY or CA or own property in NY or CA, or if both
conditions are true (they reside in and own property in NY or CA).
SELECT x, y
FROM TABLE(SEM_MATCH(
'{?x :grandParentOf ?y . ?x rdf:type :Male
{{?x :residentOf ?z} UNION {?x :ownsPropertyIn ?z}}
FILTER (?z = "NY" || ?z = "CA")}',
SEM_Models('family'),
SEM_Rulebases('RDFS','family_rb'),
SEM_ALIASES(SEM_ALIAS('','http://www.example.org/family/')),
null, null, ' ', null, null,
'RDFUSER', 'NET1'));
Table 1-15 SEM_MATCH graphs and named_graphs Values, and Resulting Dataset
Configurations
See also the W3C SPARQL specification for more information on RDF data sets and the
GRAPH construct, specifically: http://www.w3.org/TR/rdf-sparql-query/#rdfDataset
1-49
Chapter 1
Using the SEM_MATCH Table Function to Query Semantic Data
1-50
Chapter 1
Using the SEM_MATCH Table Function to Query Semantic Data
ASK$RDFLANG, SEM$ROWNUM. Note that these columns are the same as a SPARQL
SELECT syntax query that projects a single ?ask variable.
SPARQL ASK queries will generally give better performance than an equivalent SPARQL
SELECT syntax query because the ASK query does not have to retrieve lexical values for
query variables, and query execution can stop after a single result has been found.
SPARQL ASK queries use the same syntax as SPARQL SELECT queries, but the topmost
SELECT clause must be replaced with the keyword ASK.
Example 1-26 SPARQL ASK
Example 1-26 shows a SPARQL ASK query that determines whether or not any cameras are
for sale with more than 10 megapixels that cost less than 50 dollars.
SELECT ask
FROM TABLE(SEM_MATCH(
'PREFIX : <http://www.example.org/electronics/>
ASK
WHERE
{?x :price ?p .
?x :megapixels ?m .
FILTER (?p < 50 && ?m > 10)
}',
SEM_Models('electronics'),
null, null, null, ' ', null, null,
'RDFUSER', 'NET1'));
See also the W3C SPARQL specification for more information on SPARQL ASK queries,
specifically: http://www.w3.org/TR/sparql11-query/#ask
1-51
Chapter 1
Using the SEM_MATCH Table Function to Query Semantic Data
PRED$RDFLTYP
PRED$RDFLANG
PRED$RDFTERM
PRED$RDFCLBT
OBJ
OBJ$RDFVID
OBJ$_PREFIX
OBJ$_SUFFIX
OBJ$RDFVTYP
OBJ$RDFCLOB
OBJ$RDFLTYP
OBJ$RDFLANG
OBJ$RDFTERM
OBJ$RDFCLBT
SEM$ROWNUM
The overall SEM_MATCH CONSTRUCT query in Example 1-27 would then return the
following rows, which correspond to six RDF triples (two for each result row of the
query pattern).
1-52
Chapter 1
Using the SEM_MATCH Table Function to Query Semantic Data
There are two SEM_MATCH query options that influence the behavior of SPARQL
CONSTRUCT: CONSTRUCT_UNIQUE=T and CONSTRUCT_STRICT=T. Using the
CONSTRUCT_UNIQUE=T query option ensures that only unique RDF triples are returned from the
CONSTRUCT query. Using the CONSTRUCT_STRICT=T query option ensures that only valid
RDF triples are returned from the CONSTRUCT query. Valid RDF triples are those that have
(1) a URI or blank node in the subject position, (2) a URI in the predicate position, and (3) a
URI, blank node or RDF literal in the object position. Both of these query options are turned
off by default for improved query performance.
Example 1-27 SPARQL CONSTRUCT
Example 1-27 shows a SPARQL CONSTRUCT query that builds an RDF graph of employee
names using the foaf vocabulary.
SELECT subj$rdfterm, pred$rdfterm, obj$rdfterm
FROM TABLE(SEM_MATCH(
'PREFIX ent: <http://www.example.org/enterprise/>
PREFIX foaf: <http://xmlns.com/foaf/0.1/>
CONSTRUCT
{?e foaf:givenName ?fname .
?e foaf:familyName ?lname
}
WHERE
{?e ent:fname ?fname .
?e ent:lname ?lname
}',
SEM_Models('enterprise'),
SEM_Rulebases('RDFS'),
null, null, null, ' ', null, null,
'RDFUSER', 'NET1'));
1-53
Chapter 1
Using the SEM_MATCH Table Function to Query Semantic Data
SEM_Models('enterprise'),
SEM_Rulebases('RDFS'),
null, null, null, ' ', null, null,
'RDFUSER', 'NET1'));
1-54
Chapter 1
Using the SEM_MATCH Table Function to Query Semantic Data
1-55
Chapter 1
Using the SEM_MATCH Table Function to Query Semantic Data
See also the W3C SPARQL specification for more information on SPARQL
CONSTRUCT queries, specifically: http://www.w3.org/TR/sparql11-query/
#construct
Like CONSTRUCT queries, DESCRIBE queries return an RDF graph instead of result
bindings. Each DESCRIBE query, therefore, returns the same columns as a
CONSTRUCT query (see Graph Patterns: Support for SPARQL CONSTRUCT Syntax
for a listing of return columns).
SPARQL DESCRIBE queries use the same syntax as SPARQL SELECT queries,
except the topmost SELECT clause is replaced with a DESCRIBE clause. A
1-56
Chapter 1
Using the SEM_MATCH Table Function to Query Semantic Data
1-57
Chapter 1
Using the SEM_MATCH Table Function to Query Semantic Data
11. Limit
See also the W3C SPARQL specification for more information on SPARQL BASE,
PREFIX, SELECT, SELECT DISTINCT, FROM, FROM NAMED, WHERE, ORDER BY,
LIMIT, and OFFSET constructs, specifically: http://www.w3.org/TR/sparql11-query/
1-58
Chapter 1
Using the SEM_MATCH Table Function to Query Semantic Data
1-59
Chapter 1
Using the SEM_MATCH Table Function to Query Semantic Data
Example 1-40 RDF Dataset Specification Using FROM and FROM NAMED
SPARQL FROM and FROM NAMED are used to specify the RDF dataset for a query.
FROM clauses are used to specify the set of graphs that make up the default graph,
and FROM NAMED clauses are used to specify the set of graphs that make up the set
of named graphs. Example 1-40 uses FROM and FROM NAMED to select email
addresses and friend of relationships from the union of the <http://
www.friends.com/friends> and <http://www.contacts.com/contacts> graphs and
grandparent information from the <http://www.example.org/family/Smith> and
<http://www.example.org/family/Jones> graphs.
SELECT x, y, z, email
FROM TABLE(SEM_MATCH(
'PREFIX : <http://www.example.org/family/>
PREFIX foaf: <http://xmlns.com/foaf/0.1/>
PREFIX friends: <http://www.friends.com/>
PREFIX contacts: <http://www.contacts.com/>
SELECT *
FROM friends:friends
FROM contacts:contacts
FROM NAMED :Smith
FROM NAMED :Jones
WHERE
{?x foaf:frendOf ?y .
?x :email ?email .
GRAPH ?g {
?x :grandParentOf ?z }
}',
SEM_Models('family'),
SEM_Rulebases('RDFS','family_rb'),
null, null, null, ' ', null, null,
'RDFUSER', 'NET1'));
1-60
Chapter 1
Using the SEM_MATCH Table Function to Query Semantic Data
1-61
Chapter 1
Using the SEM_MATCH Table Function to Query Semantic Data
{?x <http://www.example.org/employee> ?p .
?p <http://www.example.org/employee/name> ?employee .
?p <http://www.example.org/employee/position> ?pos .
?pos <http://www.example.org/positions/name> ?position
}',
SEM_Models('enterprise'),
null,
null, null, null, ' ', null, null,
'RDFUSER', 'NET1'))
ORDER BY 1,2;
1-62
Chapter 1
Using the SEM_MATCH Table Function to Query Semantic Data
1.6.7.2 Subqueries
Subqueries are allowed with SPARQL SELECT syntax. That is, fully-specified SPARQL
SELECT queries may be embedded within other SPARQL SELECT queries. Subqueries
have many uses, for example, limiting the number of results from a subcomponent of a query.
Example 1-48 SPARQL SELECT Subquery
Example 1-48 uses a subquery to find the manufacturer that makes the cheapest camera and
then finds all other cameras made by this manufacturer.
SELECT *
FROM TABLE(SEM_MATCH(
'PREFIX : <http://www.example.org/electronics/>
SELECT ?c1
WHERE {?c1 rdf:type :Camera .
?c1 :manufacturer ?m .
{
SELECT ?m
WHERE {?c2 rdf:Type :Camera .
?c2 :price ?p .
?c2 :manufacturer ?m .
1-63
Chapter 1
Using the SEM_MATCH Table Function to Query Semantic Data
}
ORDER BY ASC(?p)
LIMIT 1
}
}',
SEM_Models('electronics'),
SEM_Rulebases('RDFS'),
null, null, null, ' ', null, null,
'RDFUSER', 'NET1'));
Subqueries are logically evaluated first, and the results are projected up to the outer
query. Note that only variables projected in the subquery's SELECT clause are visible
to the outer query.
Aggregate Description
AVG(expression) Returns the numeric average of expression over the values
within a group.
COUNT(* | expression) Counts the number of times expression has a bound, non-error
value within a group; asterisk (*) counts the number of results
within a group.
GROUP_CONCAT(expressi Performs string concatenation of expression over the values
on [; SEPARATOR = within a group. If provided, an optional separator string will be
"STRING"]) placed between each value.
MAX(expression) Returns the maximum value of expression within a group based
on the ordering defined by SPARQL ORDER BY.
MIN(expression) Returns the minimum value of expression within a group based
on the ordering defined by SPARQL ORDER BY.
SAMPLE(expression) Returns expression evaluated for a single arbitrary value from a
group.
SUM(expression) Calculates the numeric sum of expression over the values within
a group.
1-64
Chapter 1
Using the SEM_MATCH Table Function to Query Semantic Data
SELECT *
FROM TABLE(SEM_MATCH(
'PREFIX : <http://www.example.org/electronics/>
SELECT ?cType
WHERE
{?x rdf:type :Camera .
?x :cameraType ?cType .
}
GROUP BY ?cType',
SEM_Models('electronics'),
SEM_Rulebases('RDFS'),
null, null, null, ' ', null, null,
'RDFUSER', 'NET1'));
A grouping query partitions the query results into a collection of groups based on a grouping
expression (?cType in Example 1-49) such that each result within a group has the same
values for the grouping expression. The final result of the grouping operation will include one
row for each group.
Example 1-50 Complex Grouping Expression
A grouping expression consists of a sequence of one or more of the following: a variable, an
expression, or a value assignment of the form (<expression> as <alias>). Example 1-50
shows a grouping query that uses one of each type of component in the grouping expression.
SELECT *
FROM TABLE(SEM_MATCH(
'PREFIX : <http://www.example.org/electronics/>
SELECT ?cType ?totalPrice
WHERE
{?x rdf:type :Camera .
?x :cameraType ?cType .
?x :manufacturer ?m .
?x :price ?p .
?x :tax ?t .
}
GROUP BY ?cType (STR(?m)) ((?p*(1+?t)) AS ?totalPrice)',
SEM_Models('electronics'),
SEM_Rulebases('RDFS'),
null, null, null, ' ', null, null,
'RDFUSER', 'NET1'));
1-65
Chapter 1
Using the SEM_MATCH Table Function to Query Semantic Data
SEM_Models('electronics'),
SEM_Rulebases('RDFS'),
null, null, null, ' ', null, null,
'RDFUSER', 'NET1'));
1-66
Chapter 1
Using the SEM_MATCH Table Function to Query Semantic Data
{ ?x rdf:type :Camera .
?x :manufacturer ?m .
?x :price ?p
}
GROUP BY ?m
HAVING (MIN(?p) < 200)
ORDER BY ASC(?m)',
SEM_Models('electronics'),
SEM_Rulebases('RDFS'),
null, null, null, ' ', null, null,
'RDFUSER', 'NET1'));
1.6.7.4 Negation
SEM_MATCH supports two forms of negation in SPARQL query patterns: NOT EXISTS and
MINUS. NOT EXISTS can be used to filter results based on whether or not a graph pattern
matches, and MINUS can be used to remove solutions based on their relation to another
graph pattern.
Example 1-55 Negation with NOT EXISTS
Example 1-55 uses a NOT EXISTS FILTER to select those cameras that do not have any
user reviews.
SELECT *
FROM TABLE(SEM_MATCH(
'PREFIX : <http://www.example.org/electronics/>
SELECT ?x ?cType ?p
WHERE
{?x :price ?p .
?x :cameraType ?cType .
FILTER( NOT EXISTS({?x :userReview ?r}) )
}',
SEM_Models('electronics'),
SEM_Rulebases('RDFS'),
null, null, null, ' ', null, null,
'RDFUSER', 'NET1'));
1-67
Chapter 1
Using the SEM_MATCH Table Function to Query Semantic Data
result. That is, if a solution has the same values for all shared variables as a solution
from the MINUS pattern, it is removed from the result.
SELECT *
FROM TABLE(SEM_MATCH(
'PREFIX : <http://www.example.org/electronics/>
SELECT ?x ?cType ?p
WHERE
{?x :price ?p .
?x :cameraType ?cType .
MINUS {?x :userReview ?r}
}',
SEM_Models('electronics'),
SEM_Rulebases('RDFS'),
null, null, null, ' ', null, null,
'RDFUSER', 'NET1'));
1-68
Chapter 1
Using the SEM_MATCH Table Function to Query Semantic Data
The value of an expression can be assigned to a new variable in three ways: (1) expressions
in the SELECT clause, (2) expressions in the GROUP BY clause, and (3) the BIND keyword.
In each case, the new variable must not already be defined in the query. After assignment,
the new variable can be used in the query and returned in results. As discussed in
Expressions in the SELECT Clause, the syntax for value assignment is (<expression> AS
<alias>) where alias is the new variable, for example, ((?price * (1+?tax)) AS ?
totalPrice).
1-69
Chapter 1
Using the SEM_MATCH Table Function to Query Semantic Data
SELECT *
FROM TABLE(SEM_MATCH(
'PREFIX : <http://www.example.org/electronics/>
SELECT ?totalPrice (MAX(?mp) as ?maxMP)
WHERE
{?x rdf:type :Camera .
?x :price ?price .
?x :tax ?tax .
GROUP BY ( ((?price*(1+?tax)) AS ?totalPrice )
HAVING (?totalPrice < 1000)
}',
SEM_Models('electronics'),
SEM_Rulebases('RDFS'),
null, null));
1-70
Chapter 1
Using the SEM_MATCH Table Function to Query Semantic Data
VALUES ?m
{ :Company1
:Company2
}',
SEM_Models('electronics'),
SEM_Rulebases('RDFS'),
null, null, null, ' ', null, null,
'RDFUSER', 'NET1'));
1-71
Chapter 1
Using the SEM_MATCH Table Function to Query Semantic Data
1-72
Chapter 1
Using the SEM_MATCH Table Function to Query Semantic Data
SEM_ALIAS('foaf',' http://xmlns.com/foaf/0.1/')),
null, null, ' ', null, null,
'RDFUSER', 'NET1'));
1-73
Chapter 1
Using the SEM_MATCH Table Function to Query Semantic Data
Example 1-71 SPARQL SERVICE Clause to Join Remote and Local RDF Data
Example 1-71 joins remote RDF data with local RDF data. This example joins camera
types ?cType from local model electronics with the camera names ?name from the
SPARQL endpoint at http://www.example1.org/sparql.
SELECT cType, name
FROM TABLE(SEM_MATCH(
'PREFIX : <http://www.example.org/electronics/>
SELECT ?cType ?name
WHERE {
?s :cameraType ?cType
SERVICE <http://www.example1.org/sparql>{ ?s :name ?name }
}',
SEM_Models('electronics'),
null, null, null, null, ' ',
null, null,
'RDFUSER', 'NET1'));
1-74
Chapter 1
Using the SEM_MATCH Table Function to Query Semantic Data
Also, an Access Control List (ACL) should be used to grant the CONNECT privilege to the
user attempting a federated query. Example 1-72 creates a new ACL to grant the user
RDFUSER the CONNECT privilege and assigns the domain * to the ACL. For more
information about ACLs, see Oracle Database PL/SQL Packages and Types Reference.
Example 1-72 Access Control List and Host Assignment
dbms_network_acl_admin.create_acl (
acl => 'rdfuser.xml',
description => 'Allow rdfuser to query SPARQL endpoints',
principal => 'RDFUSER',
is_grant => true,
privilege => 'connect'
);
dbms_network_acl_admin.assign_acl (
acl => 'rdfuser.xml',
host => '*'
);
After the necessary privileges are granted, you are ready to execute federated queries from
SEM_MATCH
In Example 1-73, the local portion of the query will return a very small number of rows, but
the remote portion of the query is completely unbound and will return the entire remote
dataset. When the SERVICE_JPDWN=T option is specified, SEM_MATCH performs a nested-
loop style evaluation by first executing the local portion of the query and then executing a
modified version of the remote query once for each row returned by the local portion. The
1-75
Chapter 1
Using the SEM_MATCH Table Function to Query Semantic Data
remote query is modified with a FILTER clause that effectively performs a substitution
for the join variable ?s. For example, if <urn:camera1> and <urn:camera2> are
returned from the local portion of Example 1-73 as bindings for ?s, then the following
two queries are sent to the remote endpoint: { ?s ?prop ?obj FILTER (?s =
<urn:camera1>) } and { s ?prop ?obj FILTER (?s = <urn:camera2>) }.
1-76
Chapter 1
Using the SEM_MATCH Table Function to Query Semantic Data
After the privilege is granted, the user should save the user name and password for each
SPARQL Endpoint with HTTP Authentication through functions
mdsys.sdo_sem_http_ctx.set_usr and mdsys.sdo_sem_http_ctx.set_pwd. The following
example sets a user name and password for the SPARQL endpoint at http://
www.example1.org/sparql:
BEGIN
mdsys.sdo_sem_http_ctx.set_usr('http://www.example1.org/sparql','user');
mdsys.sdo_sem_http_ctx.set_pwd('http://www.example1.org/sparql','pwrd');
END;
/
1-77
Chapter 1
Using the SEM_MATCH Table Function to Query Semantic Data
SEM_Models('family'),
SEM_Rulebases('RDFS','family_rb'),
SEM_ALIASES(SEM_ALIAS('','http://www.example.org/family/')),
null, null, ' ', null, null,
'RDFUSER', 'NET1'));
The BGP_JOIN hint influences inter-BGP joins and has the following syntax:
BGP_JOIN(<join_type>), where <join_type> is USE_HASH or USE_NL. Example 1-77
uses the BGP_JOIN(USE_HASH) hint to specify that a hash join should be used when
joining the OPTIONAL BGP with its parent BGP.
Inline optimizer hints override any hints passed to SEM_MATCH through the options
argument. For example, a global ALL_ORDERED hint applies to each BGP that does
not specify an inline optimizer hint, but those BGPs with an inline hint use the inline
hint instead of the ALL_ORDERED hint.
Example 1-78 Inline Query Optimizer Hints (ANTI_JOIN)
The ANTI_JOIN hint influences the evaluation of NOT EXISTS and MINUS clauses.
This hint has the syntax ANTI_JOIN(<join_type>), where <join_type> is HASH_AJ,
NL_AJ, or MERGE_AJ. The following example uses a hint to indicate that a hash anti
join should be used. Global ALL_AJ_HASH, ALL_AJ_NL, ALL_AJ_MERGE can be
used in the options argument of SEM_MATCH to influence the join type of all NOT
EXISTS and MINUS clauses in the entire query.
SELECT x, y
FROM TABLE(SEM_MATCH(
'SELECT ?x ?y
WHERE {
?x :grandParentOf ?y . ?x rdf:type :Male . ?x :birthDate ?bd
FILTER (
NOT EXISTS {# HINT0={ ANTI_JOIN(HASH_AJ) }
?x :homepage ?hp . ?x :cellPhoneNum ?cp })
}',
SEM_Models('family'),
SEM_Rulebases('RDFS','family_rb'),
SEM_ALIASES(SEM_ALIAS('','http://www.example.org/family/')),
null, null, ' ', null, null,
'RDFUSER', 'NET1'));
1-78
Chapter 1
Using the SEM_MATCH Table Function to Query Semantic Data
WHERE {
?t :fname ?fname .
?t :lname ?lname }
}
}',
SEM_Models('family'),
SEM_Rulebases('RDFS','family_rb'),
SEM_ALIASES(SEM_ALIAS('','http://www.example.org/family/')),
null, null, ' ', null, null,
'RDFUSER', 'NET1'));
The first argument to orardf:textContains must be a local variable (that is, a variable
present in the BGP that contains the orardf:textContains filter), and the second argument
must be a constant plain literal.
For example, orardf:textContains(x, y) returns true if x matches the expression y, where
y is a valid expression for the Oracle Text SQL operator CONTAINS. For more information
about such expressions, see Oracle Text Reference.
Before using orardf:textContains, you must create an Oracle Text index for the RDF
network. To create such an index, invoke the SEM_APIS.ADD_DATATYPE_INDEX
procedure as follows:
EXECUTE SEM_APIS.ADD_DATATYPE_INDEX('http://xmlns.oracle.com/rdf/text',
network_owner=>'RDFUSER', network_name=>'NET1');
1-79
Chapter 1
Using the SEM_MATCH Table Function to Query Semantic Data
SELECT x, y, n, scr
FROM TABLE(SEM_MATCH(
'PREFIX <http://www.example.org/family/>
SELECT *
1-80
Chapter 1
Using the SEM_MATCH Table Function to Query Semantic Data
WHERE {
{ SELECT ?x ?y ?n (orardf:textScore(123) AS ?scr)
WHERE {
?x :grandParentOf ?y . ?x rdf:type :Male . ?x :name ?n
FILTER (orardf:textContains(?n, " A% | B% ", 123)) }
}
FILTER (?scr > 0.5)
}',
SEM_Models('family'),
SEM_Rulebases('RDFS','family_rb'),
null,
null,
null,
' REWRITE=F ',
null, null,
'RDFUSER', 'NET1'));
The first argument of orardf:like can be any variable or RDF term, as opposed to
orardf:Contains, which requires the first argument to be a local variable. When the first
argument to orardf:like is a URI, the match is performed against the URI suffix only. The
second argument must be a pattern expression, which can contain the following special
pattern-matching characters:
• The percent sign (%) can match zero or more characters.
• The underscore (_) matches exactly one character.
The following example shows a percent sign (%) wildcard search to find all grandparents
whose URIs start with Ja.
SELECT x, y, n
FROM TABLE(SEM_MATCH(
'PREFIX : <http://www.example.org/family/>
SELECT *
WHERE {
?x :grandParentOf ?y . ?y :name ?n
FILTER (orardf:like(?x, "Ja%")) }',
SEM_Models('family'),
SEM_Rulebases('RDFS','family_rb'),
1-81
Chapter 1
Using the SEM_MATCH Table Function to Query Semantic Data
The following example shows an underscore (_) wildcard search to find all the
grandchildren whose names start with J followed by two characters and end with k..
SELECT x, y, n
FROM TABLE(SEM_MATCH(
'PREFIX : <http://www.example.org/family/>
SELECT *
WHERE {
?x :grandParentOf ?y . ?y :name ?n
FILTER (orardf:like(?n, "J__k"))
}',
SEM_Models('family'),
SEM_Rulebases('RDFS','family_rb'),
For efficient execution of orardf:like, you can create an index using the
SEM_APIS.ADD_DATATYPE_INDEX procedure with http://xmlns.oracle.com/rdf/
like as the data type URI. This index can speed up queries when the first argument is
a local variable and the leading character of the search pattern is not a wildcard. The
underlying index is a simple function-based B-Tree index on a varchar function, which
has lower maintenance and storage costs than a full Oracle Text index. The index for
orardf:like is created as follows:
EXECUTE SEM_APIS.ADD_DATATYPE_INDEX('http://xmlns.oracle.com/rdf/
like');
1-82
Chapter 1
Using the SEM_MATCH Table Function to Query Semantic Data
1-83
Chapter 1
Using the SEM_MATCH Table Function to Query Semantic Data
the term geometry literal is used to refer to an RDF literal that is any one of these five
literal types.
Example 1-83 Spatial Point Geometry Represented as orageo:WKTLiteral
The following example shows the orageo:WKTLiteral encoding for a simple point
geometry.
"Point(-83.4 34.3)"^^<http://xmlns.oracle.com/rdf/geo/WKTLiteral>
"Point(-83.4 34.3)"^^<http://www.opengis.net/ont/geosparql#wktLiteral>
ogc:gmlLiteral encodings consist of a valid element from the GML schema that
implements a subtype of GM_Object. In contrast to WKT literals, A GML encoding
explicitly includes spatial reference system information, so a spatial reference system
URI prefix is not needed.
Example 1-86 Spatial Polygon Geometry Represented as ogc:geoJSONLiteral
The following example shows a valid ogc:geoJSONLiteral encoding for a polygon
geometry.
1-84
Chapter 1
Using the SEM_MATCH Table Function to Query Semantic Data
"<Polygon><extrude>0</extrude><tessellate>0</
tessellate><altitudeMode>relativeToGround</altitudeMode>
<outerBoundaryIs><LinearRing><coordinates>-73.0,44.0 -71.0,44.0 -71.0,47.0
-73.0,47.0 -73.0,44.0 </coordinates>
</LinearRing></outerBoundaryIs></Polygon>"^^<http://www.opengis.net/ont/
geosparql#kmlLiteral>
# spatial data for lot1 using the default WGS84 Longitude-Latitude spatial
reference system
<urn:lot1> <urn:hasExactGeometry> "Polygon((-83.6 34.1, -83.6 34.5, -83.2
34.5, -83.2 34.1, -83.6 34.1))"^^<http://www.opengis.net/ont/
geosparql#wktLiteral> .
<urn:lot1> <urn:hasPointGeometry> "Point(-83.4 34.3)"^^<http://
www.opengis.net/ont/geosparql#wktLiteral> .
# spatial data for lot2 using the NAD83 Longitude-Latitude spatial reference
system
<urn:lot2> <urn:hasExactGeometry> "<http://www.opengis.net/def/crs/
EPSG/0/4269> Polygon((-83.6 34.1, -83.6 34.3, -83.4 34.3, -83.4 34.1, -83.6
34.1))"^^<http://www.opengis.net/ont/geosparql#wktLiteral> .
<urn:lot2> <urn:hasPointGeometry> "<http://www.opengis.net/def/crs/
EPSG/0/4269> Point(-83.5 34.2)"^^<http://www.opengis.net/ont/
geosparql#wktLiteral> .
For more information, see the chapter about coordinate systems (spatial reference systems)
in Oracle Spatial Developer's Guide. See also the material about the WKT geometry
representation in the Open Geospatial Consortium (OGC) Simple Features document,
available at: http://www.opengeospatial.org/standards/sfa
1-85
Chapter 1
Using the SEM_MATCH Table Function to Query Semantic Data
1-86
Chapter 1
Using the SEM_MATCH Table Function to Query Semantic Data
<http://www.opengis.net/ont/geosparql#geoJSONLiteral>, or <http://
www.opengis.net/ont/geosparql#kmlLiteral>) will create an index for all the supported
geometry literal types. For example, if you create an index for ogc:wktLiteral, any
orageo:WKTLiteral, ogc:gmlLiteral, ogc:geoJSONLiteral, and ogc:kmlLiteral geometry
literals will also be indexed.
EXECUTE sem_apis.add_datatype_index('http://www.opengis.net/ont/
geosparql#wktLiteral',
options=>'TOLERANCE=0.1 SRID=8307 DIMENSIONS=((LONGITUDE,-180,180)
(LATITUDE,-90,90))',
network_owner=>'RDFUSER', network_name=>'NET1');
No more than one spatial data type index is supported for an RDF network. Geometry literal
values stored in the RDF network are automatically normalized to the spatial reference
system used for the index, so a single spatial index can simultaneously support geometry
literal values from different spatial reference systems. This coordinate transformation is done
transparently for indexing and spatial computations. When geometry literal values are
returned from a SEM_MATCH query, the original, untransformed geometry is returned.
For more information about spatial indexing, see the chapter about indexing and querying
spatial data in Oracle Spatial Developer's Guide.
Example 1-91 Adding a Spatial Data Type Materialized Index on RDF Data
When you manipulate spatial data, conversions from geometry literals to geometry objects
may be needed, but several conversions may lead to poor performance. To avoid this
situation, all the stored geometry literals can be transformed into SDO_GEOMETRY objects
and materialized at index creation time.
This can be achieved using the MATERIALIZE=T option when adding a spatial data type index.
If the amount of geometry literals to be indexed is very large, using the option INS_AS_SEL=T
may help to speed up the materialized index creation.
The following example shows the creation of a materialized spatial index.
EXECUTE sem_apis.add_datatype_index('http://www.opengis.net/ont/
geosparql#wktLiteral',
options=>'TOLERANCE=0.1 SRID=8307
DIMENSIONS=((LONGITUDE,-180,180) (LATITUDE,-90,90)) MATERIALIZE=T ');
conn rdfuser/<password>;
1-87
Chapter 1
Using the SEM_MATCH Table Function to Query Semantic Data
exec sem_apis.create_sem_model('geo3d','geo3d_tab','tri');
-- 3D Polygon
insert into geo3d_tab(tri) values(sdo_rdf_triple_s('geo3d','<http://
example.org/ApplicationSchema#A>',
'<http://example.org/
ApplicationSchema#hasExactGeometry>',
'<http://example.org/
ApplicationSchema#AExactGeom>'));
insert into geo3d_tab(tri) values(sdo_rdf_triple_s('geo3d','<http://
example.org/ApplicationSchema#AExactGeom>',
'<http://www.opengis.net/ont/
geosparql#asWKT>',
'"<http://xmlns.oracle.com/rdf/geo/
srid/31468> Polygon ((4467504.578 5333958.396 513.9,
1-88
Chapter 1
Using the SEM_MATCH Table Function to Query Semantic Data
-- Create 3D index
conn system/manager;
exec sem_apis.add_datatype_index('http://www.opengis.net/ont/
geosparql#wktLiteral' ,
options=>'TOLERANCE=0.1 SRID=3148
DIMENSIONS=((x,4386596.4101,4613610.5843)
(y,5237914.5325,6104496.9694) (z,0,10000))
SDO_INDX_DIMS=3 ');
conn rdfuser/rdfuser;
-- Find geometries within 200 M of my:A
-- Returns only one point because of 3D index
SELECT aGeom, f, fGeom, aWKT, fWKT
FROM TABLE(SEM_MATCH(
'{ my:A my:hasExactGeometry ?aGeom .
?aGeom ogc:asWKT ?aWKT .
?f my:hasExactGeometry ?fGeom .
?fGeom ogc:asWKT ?fWKT .
FILTER (orageo:withinDistance(?aWKT, ?fWKT,200,"M") &&
!sameTerm(?aGeom,?fGeom))
}',
SEM_Models('geo3d'),
null,
SEM_ALIASES(
SEM_ALIAS('my','http://example.org/ApplicationSchema#')),
null));
1-89
Chapter 1
Using the SEM_MATCH Table Function to Query Semantic Data
conn rdfuser/<password>;
RETURN term;
END;
/
1-90
Chapter 1
Using the SEM_MATCH Table Function to Query Semantic Data
1-91
Chapter 1
Using the SEM_MATCH Table Function to Query Semantic Data
An SVP table can have either of the following two naming conventions:
1-92
Chapter 1
Using the SEM_MATCH Table Function to Query Semantic Data
START_NODE_ID is a primary key, and each predicate covered by the SVP table has two
columns: one column for the named graph id (G<PREDICATE_ID>) and one column for the
object id (P<PREDICATE_ID).
By default, an SVP table has a unique index on the START_NODE_ID column using the
following naming convention:
<NETWORK_NAME>#RDF_XX$SVP_<MODEL_NAME>_UQ__<USER_SUPPLIED_NAME>.
The columns for an MVP table are shown in the following table:
1-93
Chapter 1
Using the SEM_MATCH Table Function to Query Semantic Data
By default, an MVP table has a non-unique index on the START_NODE_ID column using
the following naming convention:
<NETWORK_NAME>#RDF_XX$MVP_<MODEL_NAME>_P<PREDICATE_ID>
For example, each result of the following query can be found as a single row in a PCN
table for (:hasAddress, :addrCityState, :addrCity, instead of requiring two self
joins of RDF_LINK$.
SELECT ?s ?city
WHERE {
?s :hasAddress/:addrCityState/:addrCity ?city
}
The following table shows the PCN table columns for a property chain:
(<PREDICATE_ID_1>, <PREDICATE_ID_2>, …, <PREDICATE_ID_n>):
1-94
Chapter 1
Using the SEM_MATCH Table Function to Query Semantic Data
By default, a PCN table has a non-unique index on START_NODE_ID and all P<PREDICATE_ID>
columns.
The naming convention for the indexes are as follows:
• START_NODE_ID:
<NETWORK_NAME>#RDF_XX$PCN_<MODEL_NAME>_UQ__<USER_SUPPLIED_NAME>
• P<PREDICATE_ID>:
<NETWORK_NAME>#RDF_XX$PCN_<MODEL_NAME>__<USER_SUPPLIED_NAME>_P<PREDICATE_ID>
1-95
Chapter 1
Using the SEM_MATCH Table Function to Query Semantic Data
Note:
Ensure that the network owner must have read privileges on the predicate
information table when building an SVP or a PCN table.
The following example illustrates creation of a set of SPM tables for an RDF model
with SEM_APIS.GATHER_SPM_INFO and SEM_APIS.BUILD_SPM_TAB. These SPM tables
are automatically used for SPARQL query execution. This example uses SEM_MATCH,
but SPARQL queries executed through other APIs, such as Support for Apache Jena
or RDF server will also automatically use SPM tables.
1-96
Chapter 1
Using the SEM_MATCH Table Function to Query Semantic Data
SQL>
SQL> -- create a semantic model
SQL> exec
sem_apis.create_sem_model('M1',null,null,network_owner=>'RDFUSER',network_name=>'NET1')
;
SQL>
SQL> -- add some data
SQL> begin
2 sem_apis.update_model('M1',
3 'PREFIX : <http://www.example.com#>
4 PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
5 INSERT DATA {
6 :john :fname "John"
7 ; :lname "Brown"
8 ; :height 72
9 ; :email "[email protected]"
10 ; :email "[email protected]"
11 ; :nickName "Johnny B"
12 ; :friendOf :ann
13 ; :address [
14 :addrNum 20
15 ; :addrStreet "Elm Street"
16 ; :addrCityState [
17 :addrCity "Boston"
18 ; :addrState "MA" ] ] .
19 :ann :fname "Ann"
20 ; :lname "Green"
21 ; :height 65
22 ; :email "[email protected]"
23 ; :nickName "Annie"
24 ; :friendOf :john
25 ; :friendOf :bill
26 ; :address [
27 :addrNum 10
28 ; :addrStreet "Main Street"
29 ; :addrCityState [
30 :addrCity "New York"
31 ; :addrState "NY" ] ] .
32 :bill :fname "Bill"
33 ; :lname "Red"
34 ; :height 70
35 ; :email "[email protected]"
36 ; :nickName "Billy"
37 ; :friendOf :ann
38 ; :friendOf :jane
39 ; :address [
1-97
Chapter 1
Using the SEM_MATCH Table Function to Query Semantic Data
40 :addrNum 5
41 ; :addrStreet "Peachtree Street"
42 ; :addrCityState [
43 :addrCity "Atlanta"
44 ; :addrState "GA" ] ] .
45 :jane :fname "Jane"
46 ; :lname "Blue"
47 ; :height 68
48 ; :email "[email protected]"
49 ; :email "[email protected]"
50 ; :friendOf :bill
51 ; :address [
52 :addrNum 101
53 ; :addrStreet "Maple Street"
54 ; :addrCityState [
55 :addrCity "Chicago"
56 ; :addrState "IL" ] ] .
57 }'
58 ,network_owner=>'RDFUSER'
59 ,network_name=>'NET1');
60 end;
61 /
SQL>
SQL> -- gather optimizer statistics
SQL> begin
2 sem_perf.gather_stats(
3 network_owner=>'RDFUSER',
4 network_name=>'NET1');
5 end;
6 /
SQL>
SQL> -- create and populate a predicate information table named M1_PRED_INFO
SQL> begin
2 sem_apis.gather_spm_info(
3 model_name=>'M1',
4 pred_info_tabname=>'M1_PRED_INFO',
5 degree=>2,
6 network_owner=>'RDFUSER',
7 network_name=>'NET1');
8 end;
9 /
SQL>
SQL> -- check M1_PRED_INFO
SQL> select * from M1_PRED_INFO;
1-98
Chapter 1
Using the SEM_MATCH Table Function to Query Semantic Data
2 1.5 1.5 6
2282073771135796724 http://www.example.com#addrCityState 1 1
1.0 1.0 4
6664054864634376526 http://www.example.com#addrNum 1 1
1.0 1.0 4
7644445801044650266 http://www.example.com#lname 1 1
1.0 1.0 4
8337314745347241189 http://www.example.com#fname 1 1
1.0 1.0 4
594560333771551504 http://www.example.com#addrState 1 1
1.0 1.0 4
2558054308995111125 http://www.example.com#nickName 1 1
1.0 1.0 3
2930492586059823454 http://www.example.com#email 1 2
1.5 1.5 6
3131489775428233363 http://www.example.com#addrStreet 1 1
1.0 1.0 4
4791477124431525340 http://www.example.com#height 1 1
1.0 1.0 4
5055192271510902740 http://www.example.com#address 1 1
1.0 1.0 4
12 rows selected.
SQL>
SQL> -- mark all properties with 'N' to initialize pred
SQL> update M1_PRED_INFO
2 set INCLUDE = 'N';
12 rows updated.
SQL> commit;
Commit complete.
SQL>
SQL> -- create a SVP table for single-valued predicates :fname, :lname, :height
SQL> -- mark the desired properties for inclusion
SQL> update M1_PRED_INFO
2 set INCLUDE = 'Y'
3 where PRED_NAME IN
4 ('http://www.example.com#fname',
5 'http://www.example.com#lname',
6 'http://www.example.com#height');
3 rows updated.
SQL> commit;
Commit complete.
SQL>
SQL> begin
2 sem_apis.build_spm_tab(
3 model_name=>'M1',
4 pred_info_tabname=>'M1_PRED_INFO',
5 pred_name=>NULL,
6 options=>' svp_name=fnm_lnm_hght ',
7 degree=>2,
8 network_owner=>'RDFUSER',
9 network_name=>'NET1');
1-99
Chapter 1
Using the SEM_MATCH Table Function to Query Semantic Data
10 end;
11 /
SQL>
SQL> -- check the SVP table
SQL> select * from "NET1#RDF_XT$SVP_M1+__FNM_LNM_HGHT";
4 rows selected.
SQL>
SQL> -- create a PCN table for :address/:addrCityState/:addrState
SQL> update M1_PRED_INFO
2 set INCLUDE = 'N';
12 rows updated.
SQL> commit;
Commit complete.
SQL>
SQL> update M1_PRED_INFO
2 set INCLUDE = '1C'
3 where PRED_NAME = 'http://www.example.com#address';
1 row updated.
1 row updated.
1 row updated.
SQL> commit;
1-100
Chapter 1
Using the SEM_MATCH Table Function to Query Semantic Data
Commit complete.
SQL>
SQL> begin
2 sem_apis.build_spm_tab(
3 model_name=>'M1',
4 pred_info_tabname=>'M1_PRED_INFO',
5 pred_name=>NULL,
6 options=>' pcn_name=addr_state ',
7 degree=>2,
8 network_owner=>'RDFUSER',
9 network_name=>'NET1');
10 end;
11 /
SQL>
SQL> -- check the PCN table
SQL> select * from "NET1#RDF_XT$PCN_M1+__ADDR_STATE";
4 rows selected.
SQL>
SQL> -- create MVP tables for :email and :friendOf
SQL> -- :email
SQL> begin
2 sem_apis.build_spm_tab(
3 model_name=>'M1',
4 pred_info_tabname=>NULL,
5 pred_name=>'<http://www.example.com#email>',
6 degree=>2,
7 network_owner=>'RDFUSER',
8 network_name=>'NET1');
9 end;
10 /
SQL>
SQL> -- check the MVP table
SQL> select * from "NET1#RDF_XT$MVP_M1+_P2930492586059823454" order by
P2930492586059823454;
1-101
Chapter 1
Using the SEM_MATCH Table Function to Query Semantic Data
7024748068782994892 2096397932624357828
1399946303865654932 6100245385739701229
7024748068782994892 6480436012276020283
8972322488425499169 7251371240613573863
8531245907959123227 7834835188342349976
6 rows selected.
SQL>
SQL> -- :friendOf
SQL> begin
2 sem_apis.build_spm_tab(
3 model_name=>'M1',
4 pred_info_tabname=>NULL,
5 pred_name=>'<http://www.example.com#friendOf>',
6 degree=>2,
7 network_owner=>'RDFUSER',
8 network_name=>'NET1');
9 end;
10 /
SQL>
SQL> -- check the MVP table
SQL> select * from "NET1#RDF_XT$MVP_M1+_P1285894645615718351";
6 rows selected.
SQL>
SQL> -- gather optimizer statistics on SPM auxiliary tables
SQL> begin
2 sem_perf.analyze_aux_tables(
3 model_name=>'M1',
4 network_owner=>'RDFUSER',
5 network_name=>'NET1');
6 end;
7 /
SQL>
SQL> -- Execute a SPARQL query that uses SPM tables
SQL> SELECT s, fname, lname, height, email, nick, friend, state
2 FROM TABLE(SEM_MATCH(
3 'PREFIX : <http://www.example.com#>
4 SELECT *
5 WHERE {
6 ?s :fname ?fname
7 ; :lname ?lname
8 ; :height ?height
9 ; :email ?email
1-102
Chapter 1
Using the SEM_MATCH Table Function to Query Semantic Data
10 ; :nickName ?nick
11 ; :friendOf ?friend
12 ; :address/:addrCityState/:addrState ?state
13 }'
14 ,sem_models('M1')
15 ,null,null,null,null
16 ,' '
17 ,null,null
18 ,'RDFUSER','NET1'))
19 ORDER BY 1,2,3,4,5,6,7;
6 rows selected.
SQL>
SQL> -- Look at the SQL translation to show SPM table usage.
SQL> --
SQL> -- This SQL evaluates 9 triple patterns with only 4 joins
SQL> -- instead of the 8 joins that would normally be required
SQL> -- without SPM tables.
SQL> --
SQL> -- The SVP table is used for :fname, :lname, :height.
SQL> -- MVP tables are used for :email and :friendOf.
SQL> -- RDF_LINK$ isused for :nickName.
SQL> -- The PCN table is used for the sequence
SQL> -- :address/:addrCityState/:addrState
SQL> SELECT SEM_APIS.SPARQL_TO_SQL(
2 'PREFIX : <http://www.example.com#>
3 SELECT *
4 WHERE {
5 ?s :fname ?fname
6 ; :lname ?lname
7 ; :height ?height
8 ; :email ?email
9 ; :nickName ?nick
10 ; :friendOf ?friend
11 ; :address/:addrCityState/:addrState ?state
12 }'
13 ,sem_models('M1')
14 ,null,null,null
15 ,' '
16 ,null,null
17 ,'RDFUSER','NET1') AS SQL_TRANS
18 FROM SYS.DUAL;
1-103
Chapter 1
Using the SEM_MATCH Table Function to Query Semantic Data
SQL_TRANS
---------------------------------------------------------------------------------
---------------------------------------------------------------------------------
---------------------------------------------------------------------------------
-----------------------------------------------------------------------------
SELECT * FROM (
SELECT /*+ NO_MERGE(R) NO_SWAP_JOIN_INPUTS(R) LEADING(R V0 V1 V2 V3 V4 V5 V6 V7)
NO_SWAP_JOIN_INPUTS(V0) NO_SWAP_JOIN_INPUTS(V1) NO_SWAP_JOIN_INPUTS(V2)
NO_SWAP_JOIN_INPUTS(V3) NO_SWAP_JOIN_INPUTS(V4) NO_SWAP_JOIN_INPUTS(V5)
NO_SWAP_JOIN_INPUTS(V6) NO_SWAP_JOIN_INPUTS(V7) */ V0.VNAME_PREFIX ||
V0.VNAME_SUFFIX AS S,
V0.VALUE_ID AS S$RDFVID, V0.VNAME_PREFIX AS S$_PREFIX, V0.VNAME_SUFFIX AS
S$_SUFFIX, (CASE WHEN V0.VALUE_TYPE IS NULL THEN NULL WHEN V0.VALUE_TYPE IN
('UR','URI') THEN 'URI'
WHEN V0.VALUE_TYPE IN ('BN', 'BLN') THEN 'BLN'
ELSE 'LIT'
END) AS S$RDFVTYP, V0.LONG_VALUE AS S$RDFCLOB, V0.LITERAL_TYPE AS S$RDFLTYP,
V0.LANGUAGE_TYPE AS S$RDFLANG,
… OMITTED …
1 AS SEM$ROWNUM
FROM (SELECT SVP0.START_NODE_ID AS S$RDFVID,
SVP0.P7644445801044650266 AS LNAME$RDFVID,
MVP1.P1285894645615718351 AS FRIEND$RDFVID,
T4.CANON_END_NODE_ID AS NICK$RDFVID,
PCN0.P594560333771551504 AS STATE$RDFVID,
SVP0.P4791477124431525340 AS HEIGHT$RDFVID,
MVP0.P2930492586059823454 AS EMAIL$RDFVID,
SVP0.P8337314745347241189 AS FNAME$RDFVID,
SVP0.START_NODE_ID AS BGP$1
FROM (
SELECT * FROM "RDFUSER".NET1#RDFM_M1) T4,
"RDFUSER"."NET1#RDF_XT$SVP_M1+__FNM_LNM_HGHT" SVP0,
"RDFUSER"."NET1#RDF_XT$PCN_M1+__ADDR_STATE" PCN0,
"RDFUSER"."NET1#RDF_XT$MVP_M1+_P2930492586059823454" MVP0,
"RDFUSER"."NET1#RDF_XT$MVP_M1+_P1285894645615718351" MVP1
WHERE SVP0.P8337314745347241189 IS NOT NULL AND
SVP0.P7644445801044650266 IS NOT NULL AND
SVP0.P4791477124431525340 IS NOT NULL AND
T4.P_VALUE_ID = 2558054308995111125 AND
SVP0.START_NODE_ID = MVP0.START_NODE_ID AND
SVP0.START_NODE_ID = T4.START_NODE_ID AND
SVP0.START_NODE_ID = MVP1.START_NODE_ID AND
SVP0.START_NODE_ID = PCN0.START_NODE_ID
) R,
"RDFUSER".NET1#RDF_VALUE$ V0, "RDFUSER".NET1#RDF_VALUE$ V1,
"RDFUSER".NET1#RDF_VALUE$ V2, "RDFUSER".NET1#RDF_VALUE$ V3,
"RDFUSER".NET1#RDF_VALUE$ V4, "RDFUSER".NET1#RDF_VALUE$ V5,
"RDFUSER".NET1#RDF_VALUE$ V6, "RDFUSER".NET1#RDF_VALUE$ V7
WHERE (1=1) AND (R.S$RDFVID = V0.VALUE_ID) AND (R.LNAME$RDFVID = V1.VALUE_ID)
AND (R.FRIEND$RDFVID = V2.VALUE_ID) AND (R.NICK$RDFVID = V3.VALUE_ID) AND
(R.STATE$RDFVID = V4.VALUE_ID) AND (R.HEIGHT$RDFVID = V5.VALUE_ID) AND
(R.EMAIL$RDFVID = V6.VALUE_ID) AND (R.FNAME$RDFVID = V7.VALUE_ID)
) WHERE (1=1)
1 row selected.
1-104
Chapter 1
Using the SEM_MATCH Table Function to Query Semantic Data
SQL> BEGIN
2 SEM_APIS.BUILD_SPM_TAB(
3 model_name=>'M1',
4 pred_info_tabname=>'M1_PRED_INFO',
5 pred_name=>NULL,
6 options=>' INMEMORY=T ',
7 degree=>2,
8 network_owner=>'RDFUSER',
9 network_name=>'NET1');
10 END;
11 /
PL/SQL procedure successfully completed.
If a set of properties to access for all queries is known, an in-memory SVP table with a subset
of all properties can be built by altering the SVP table built using the set as follows:
If you choose to include lexical values for a property, new columns for the lexical property
values are added to the SVP, PCN tables. Note that these columns correspond exactly to the
columns with the same name in RDF_VALUE$. The following table describes the columns that
are added to include lexical property values:
1-105
Chapter 1
Using the SEM_MATCH Table Function to Query Semantic Data
Table 1-22 Lexical Values Columns in MVN, PCN and SVP Tables
1-106
Chapter 1
Using the SEM_MATCH Table Function to Query Semantic Data
There are several ways to include lexical values when building SPM auxiliary tables. The
inclusion of lexical values can be controlled for each predicate. The lexical value for the
subject can be added. The various ways to include lexical values are shown below:
• When building or re-building an SVP, MVP or a PCN table:
– Setting the value of INCLUDE to 'V' or '<SEQUENCE_POSITION>CV' for each predicate
in the predicate information table for which you would like to include lexical values.
– Executing SEM_APIS.BUILD_SPM_TAB with the string 'INCLUDE_VALUE=T' added to the
options argument.
– Executing SEM_APIS.BUILD_SPM_TAB with the string 'ADD_S_VALUE' added to the
options argument to include lexical values for the subject.
– Executing SEM_APIS.BUILD_SPM_TAB with the string 'ADD_ALL_VALUES' added to the
options argument to include all lexical values for the subject and predicates.
All of these options are the most efficient ways for adding a large number of in-line lexical
values, when building or rebuilding an SVP, MVP or a PCN table.
• When altering an existing SVP, PCN or MVP table:
– Executing SEM_APIS.ALTER_SPM_TAB with the command equal to 'ADD_VALUE' and
pred_name equal to the predicate for which you would like to include lexical values.
– Executing SEM_APIS.ALTER_SPM_TAB with the command equal to 'ADD_S_VALUE' to
include lexical values for the subject.
– Executing SEM_APIS.ALTER_SPM_TAB with the command equal to 'DROP_S_VALUE' to
drop lexical values for the subject.
The example below continues from Example 1-96. It illustrates how to add lexical values
for :fname, :height, :email and :addrState.
View created.
SQL>
SQL> -- Rebuild the SVP table. Note the use of CREATE_ANYWAY=T for rebuild.
SQL> -- Note that a rebuild is the most efficient way to add a large number
SQL> -- of in-line lexical values.
SQL> begin
2 sem_apis.build_spm_tab(
3 model_name=>'M1',
4 pred_info_tabname=>'M1_PRED_INFO_VIEW',
5 pred_name=>NULL,
1-107
Chapter 1
Using the SEM_MATCH Table Function to Query Semantic Data
6 degree=>2,
7 options=>' svp_name=fnm_lnm_hght CREATE_ANYWAY=T ',
8 network_owner=>'RDFUSER',
9 network_name=>'NET1');
10 end;
11 /
SQL>
SQL> -- Check columns in the SVP table
SQL> desc NET1#RDF_XT$SVP_M1+__FNM_LNM_HGHT;
Name
Null? Type
---------------------------------------------------------------------------------
---------------------------------------------------------------------------------
----------------------- --------
---------------------------------------------------------------------------------
-------------------------------------------
START_NODE_ID
G4791477124431525340
NUMBER
P4791477124431525340
NUMBER
G8337314745347241189
NUMBER
P8337314745347241189
NUMBER
G7644445801044650266
NUMBER
P7644445801044650266
NUMBER
P4791477124431525340_VALUE_TYPE
VARCHAR2(10)
P4791477124431525340_VNAME_PREFIX
VARCHAR2(4000)
P4791477124431525340_VNAME_SUFFIX
1-108
Chapter 1
Using the SEM_MATCH Table Function to Query Semantic Data
VARCHAR2(512)
P4791477124431525340_LITERAL_TYPE
VARCHAR2(1000)
P4791477124431525340_LANGUAGE_TYPE
VARCHAR2(80)
P4791477124431525340_ORDER_NUM
NUMBER
P4791477124431525340_ORDER_DATE
P4791477124431525340_LONG_VALUE
CLOB
P8337314745347241189_VALUE_TYPE
VARCHAR2(10)
P8337314745347241189_VNAME_PREFIX
VARCHAR2(4000)
P8337314745347241189_VNAME_SUFFIX
VARCHAR2(512)
P8337314745347241189_LITERAL_TYPE
VARCHAR2(1000)
P8337314745347241189_LANGUAGE_TYPE
VARCHAR2(80)
P8337314745347241189_ORDER_NUM
NUMBER
P8337314745347241189_ORDER_DATE
P8337314745347241189_LONG_VALUE
CLOB
SQL>
SQL> -- create a PCN table for :address/:addrCityState/:addrState
SQL> -- Add in-line lexical value for :addrState
SQL> -- Add trailing V to indicate value inclusion
SQL> create or replace view M1_pred_info_view as
2 select p_value_id, pred_name, max_cnt,
3 (case pred_name
1-109
Chapter 1
Using the SEM_MATCH Table Function to Query Semantic Data
View created.
SQL>
SQL> begin
2 sem_apis.build_spm_tab(
3 model_name=>'M1',
4 pred_info_tabname=>'M1_PRED_INFO_VIEW',
5 pred_name=>NULL,
6 options=>' pcn_name=addr_state CREATE_ANYWAY=T ',
7 degree=>2,
8 network_owner=>'RDFUSER',
9 network_name=>'NET1');
10 end;
11 /
SQL>
SQL> -- check the PCN table columns
SQL> desc NET1#RDF_XT$PCN_M1+__ADDR_STATE;
Name
Null? Type
---------------------------------------------------------------------------------
---------------------------------------------------------------------------------
----------------------- --------
---------------------------------------------------------------------------------
-------------------------------------------
START_NODE_ID
G5055192271510902740
NUMBER
P5055192271510902740
NUMBER
G2282073771135796724
NUMBER
P2282073771135796724
NUMBER
G594560333771551504
NUMBER
1-110
Chapter 1
Using the SEM_MATCH Table Function to Query Semantic Data
P594560333771551504
NUMBER
P594560333771551504_VALUE_TYPE
VARCHAR2(10)
P594560333771551504_VNAME_PREFIX
VARCHAR2(4000)
P594560333771551504_VNAME_SUFFIX
VARCHAR2(512)
P594560333771551504_LITERAL_TYPE
VARCHAR2(1000)
P594560333771551504_LANGUAGE_TYPE
VARCHAR2(80)
P594560333771551504_ORDER_NUM
NUMBER
P594560333771551504_ORDER_DATE
P594560333771551504_LONG_VALUE
CLOB
SQL>
SQL> -- Add in-line lexical value for email
SQL> begin
2 sem_apis.alter_spm_tab(
3 model_name=>'m1',
4 pred_name=>'<http://www.example.com#email>',
5 command=>'ADD_VALUE',
6 network_owner=>'RDFUSER',
7 network_name=>'NET1');
8 end;
9 /
SQL>
SQL> -- Check columns in the MVP table for email
SQL> desc NET1#RDF_XT$MVP_M1+_P2930492586059823454;
Name
Null? Type
---------------------------------------------------------------------------------------
---------------------------------------------------------------------------------------
1-111
Chapter 1
Using the SEM_MATCH Table Function to Query Semantic Data
----------- --------
---------------------------------------------------------------------------------
-------------------------------------------
START_NODE_ID
G2930492586059823454
NUMBER
P2930492586059823454
NUMBER
P2930492586059823454_VALUE_TYPE
VARCHAR2(10)
P2930492586059823454_VNAME_PREFIX
VARCHAR2(4000)
P2930492586059823454_VNAME_SUFFIX
VARCHAR2(512)
P2930492586059823454_LITERAL_TYPE
VARCHAR2(1000)
P2930492586059823454_LANGUAGE_TYPE
VARCHAR2(80)
P2930492586059823454_ORDER_NUM
NUMBER
P2930492586059823454_ORDER_DATE
P2930492586059823454_LONG_VALUE
CLOB
SQL>
SQL> -- Gather statistics since the tables have changed
SQL> begin
2 sem_perf.analyze_aux_tables(
3 model_name=>'M1',
4 network_owner=>'RDFUSER',
5 network_name=>'NET1');
6 end;
7 /
SQL>
1-112
Chapter 1
Using the SEM_MATCH Table Function to Query Semantic Data
6 rows selected.
SQL>
SQL> -- Look at the SQL translation to show in-line lexical
SQL> -- value usage.
SQL> --
SQL> -- This SQL has eliminated 4 RDF_VALUE$ joins compared
SQL> -- to the previous query execution.
SQL> SELECT SEM_APIS.SPARQL_TO_SQL(
2 'PREFIX : <http://www.example.com#>
3 SELECT *
4 WHERE {
5 ?s :fname ?fname
6 ; :lname ?lname
7 ; :height ?height
8 ; :email ?email
9 ; :nickName ?nick
10 ; :friendOf ?friend
11 ; :address/:addrCityState/:addrState ?state .
12 }'
13 ,sem_models('M1')
14 ,null,null,null
15 ,' '
1-113
Chapter 1
Using the SEM_MATCH Table Function to Query Semantic Data
16 ,null,null
17 ,'RDFUSER','NET1') AS SQL_TRANS
18 FROM SYS.DUAL;
SQL_TRANS
---------------------------------------------------------------------------------
---------------------------------------------------------------------------------
---------------------------------------------------------------------------------
-----------------------------------------------------------------------------
SELECT * FROM (
SELECT /*+ NO_MERGE(R) NO_SWAP_JOIN_INPUTS(R) LEADING(R V0 V1 V2 V3)
NO_SWAP_JOIN_INPUTS(V0) NO_SWAP_JOIN_INPUTS(V1) NO_SWAP_JOIN_INPUTS(V2)
NO_SWAP_JOIN_INPUTS(V3) */ V0.VNAME_PREFIX || V0.VNAME_SUFFIX AS S, V0.VALUE_ID
AS S$RDFVID, V0.VNAME_PREFIX AS S$_PREFIX, V0.VNAME_SUFFIX AS S$_SUFFIX, (CASE
WHEN V0.VALUE_TYPE
IS NULL THEN NULL WHEN V0.VALUE_TYPE IN ('UR','URI') THEN 'URI'
WHEN V0.VALUE_TYPE IN ('BN', 'BLN') THEN 'BLN'
ELSE 'LIT'
END) AS S$RDFVTYP, V0.LONG_VALUE AS S$RDFCLOB, V0.LITERAL_TYPE AS S$RDFLTYP,
V0.LANGUAGE_TYPE AS S$RDFLANG,
… OMITTED …
1 AS SEM$ROWNUM
FROM (SELECT SVP0.START_NODE_ID AS S$RDFVID,
SVP0.P7644445801044650266 AS LNAME$RDFVID,
MVP1.P1285894645615718351 AS FRIEND$RDFVID,
T4.CANON_END_NODE_ID AS NICK$RDFVID,
PCN0.P594560333771551504_VNAME_PREFIX || PCN0.P594560333771551504_VNAME_SUFFIX
AS STATE, (CASE WHEN PCN0.P594560333771551504_VALUE_TYPE IS NULL THEN NULL WHEN
PCN0.P594560333771551504_VALUE_TYPE IN ('UR','URI') THEN 'URI'
WHEN PCN0.P594560333771551504_VALUE_TYPE IN ('BN', 'BLN') THEN 'BLN'
ELSE 'LIT'
END) AS STATE$RDFVTYP, PCN0.P594560333771551504 AS STATE$RDFVID,
PCN0.P594560333771551504_VNAME_PREFIX AS STATE$_PREFIX,
PCN0.P594560333771551504_VNAME_SUFFIX AS STATE$_SUFFIX,
PCN0.P594560333771551504_LITERAL_TYPE AS STATE$RDFLTYP,
PCN0.P594560333771551504_LANGUAGE_TYPE AS STATE$RDFLANG,
PCN0.P594560333771551504_LONG
_VALUE AS STATE$RDFCLOB,
SVP0.P4791477124431525340_VNAME_PREFIX || SVP0.P4791477124431525340_VNAME_SUFFIX
AS HEIGHT, (CASE WHEN SVP0.P4791477124431525340_VALUE_TYPE IS NULL THEN NULL
WHEN SVP0.P4791477124431525340_VALUE_TYPE IN ('UR','URI') THEN 'URI'
WHEN SVP0.P4791477124431525340_VALUE_TYPE IN ('BN', 'BLN') THEN 'BLN'
ELSE 'LIT'
END) AS HEIGHT$RDFVTYP, SVP0.P4791477124431525340 AS HEIGHT$RDFVID,
SVP0.P4791477124431525340_VNAME_PREFIX AS HEIGHT$_PREFIX,
SVP0.P4791477124431525340_VNAME_SUFFIX AS HEIGHT$_SUFFIX,
SVP0.P4791477124431525340_LITERAL_TYPE AS HEIGHT$RDFLTYP,
SVP0.P4791477124431525340_LANGUAGE_TYPE AS HEIGHT$RDFLANG, SVP0.P479147712443
1525340_LONG_VALUE AS HEIGHT$RDFCLOB,
MVP0.P2930492586059823454_VNAME_PREFIX || MVP0.P2930492586059823454_VNAME_SUFFIX
AS EMAIL, (CASE WHEN MVP0.P2930492586059823454_VALUE_TYPE IS NULL THEN NULL
WHEN MVP0.P2930492586059823454_VALUE_TYPE IN ('UR','URI') THEN 'URI'
WHEN MVP0.P2930492586059823454_VALUE_TYPE IN ('BN', 'BLN') THEN 'BLN'
ELSE 'LIT'
END) AS EMAIL$RDFVTYP, MVP0.P2930492586059823454 AS EMAIL$RDFVID,
MVP0.P2930492586059823454_VNAME_PREFIX AS EMAIL$_PREFIX,
MVP0.P2930492586059823454_VNAME_SUFFIX AS EMAIL$_SUFFIX,
MVP0.P2930492586059823454_LITERAL_TYPE AS EMAIL$RDFLTYP,
MVP0.P2930492586059823454_LANGUAGE_TYPE AS EMAIL$RDFLANG,
MVP0.P293049258605982345
4_LONG_VALUE AS EMAIL$RDFCLOB,
1-114
Chapter 1
Using the SEM_MATCH Table Function to Query Semantic Data
SVP0.P8337314745347241189_VNAME_PREFIX || SVP0.P8337314745347241189_VNAME_SUFFIX AS
FNAME, (CASE WHEN SVP0.P8337314745347241189_VALUE_TYPE IS NULL THEN NULL WHEN
SVP0.P8337314745347241189_VALUE_TYPE IN ('UR','URI') THEN 'URI'
WHEN SVP0.P8337314745347241189_VALUE_TYPE IN ('BN', 'BLN') THEN 'BLN'
ELSE 'LIT'
END) AS FNAME$RDFVTYP, SVP0.P8337314745347241189 AS FNAME$RDFVID,
SVP0.P8337314745347241189_VNAME_PREFIX AS FNAME$_PREFIX,
SVP0.P8337314745347241189_VNAME_SUFFIX AS FNAME$_SUFFIX,
SVP0.P8337314745347241189_LITERAL_TYPE AS FNAME$RDFLTYP,
SVP0.P8337314745347241189_LANGUAGE_TYPE AS FNAME$RDFLANG, SVP0.P833731474534724118
9_LONG_VALUE AS FNAME$RDFCLOB,
SVP0.START_NODE_ID AS BGP$1
FROM (
SELECT * FROM "RDFUSER".NET1#RDFM_M1) T4,
"RDFUSER".NET1#RDF_XT$SVP_M1+__FNM_LNM_HGHT SVP0,
"RDFUSER".NET1#RDF_XT$PCN_M1+__ADDR_STATE PCN0,
"RDFUSER".NET1#RDF_XT$MVP_M1+_P2930492586059823454 MVP0,
"RDFUSER".NET1#RDF_XT$MVP_M1+_P1285894645615718351 MVP1
WHERE
SVP0.P8337314745347241189 IS NOT NULL AND
SVP0.P7644445801044650266 IS NOT NULL AND
SVP0.P4791477124431525340 IS NOT NULL AND
T4.P_VALUE_ID = 2558054308995111125 AND
SVP0.START_NODE_ID = MVP0.START_NODE_ID AND
SVP0.START_NODE_ID = T4.START_NODE_ID AND
SVP0.START_NODE_ID = MVP1.START_NODE_ID AND
SVP0.START_NODE_ID = PCN0.START_NODE_ID
) R,
"RDFUSER".NET1#RDF_VALUE$ V0, "RDFUSER".NET1#RDF_VALUE$ V1, "RDFUSER".NET1#RDF_VALUE$
V2, "RDFUSER".NET1#RDF_VALUE$ V3
WHERE (1=1) AND (R.S$RDFVID = V0.VALUE_ID) AND (R.LNAME$RDFVID = V1.VALUE_ID) AND
(R.FRIEND$RDFVID = V2.VALUE_ID) AND (R.NICK$RDFVID = V3.VALUE_ID)
) WHERE (1=1)
1 row selected.
SQL>
SQL> -- In addition to value projection. In-line lexical values
SQL> -- can be used to evaluate FILTER conditions.
SQL> -- The value for ?height can be taken directly from the
SQL> -- SVP table in this case.
SQL> SELECT s, height
2 FROM TABLE(SEM_MATCH(
3 'PREFIX : <http://www.example.com#>
4 SELECT ?s ?height
5 WHERE {
6 ?s :fname ?fname
7 ; :lname ?lname
8 ; :height ?height
9 FILTER (?height >= 72)
10 }'
11 ,sem_models('M1')
12 ,null,null,null,null
13 ,' '
14 ,null,null
15 ,'RDFUSER','NET1'))
16 ORDER BY 1,2;
S HEIGHT
------------------------------ ------
1-115
Chapter 1
Using the SEM_MATCH Table Function to Query Semantic Data
http://www.example.com#john 72
1 row selected.
SQL>
SQL> -- Look at the SQL translation to show in-line lexical
SQL> -- value usage for ?height >= 72.
SQL> SELECT SEM_APIS.SPARQL_TO_SQL(
2 'PREFIX : <http://www.example.com#>
3 SELECT ?s ?height
4 WHERE {
5 ?s :fname ?fname
6 ; :lname ?lname
7 ; :height ?height
8 FILTER (?height >= 72)
9 }'
10 ,sem_models('M1')
11 ,null,null,null
12 ,' '
13 ,null,null
14 ,'RDFUSER','NET1') AS SQL_TRANS
15 FROM SYS.DUAL;
SQL_TRANS
---------------------------------------------------------------------------------
---------------------------------------------------------------------------------
---------------------------------------------------------------------------------
-----------------------------------------------------------------------------
SELECT * FROM (
SELECT /*+ NO_MERGE(R) NO_SWAP_JOIN_INPUTS(R) LEADING(R V0)
NO_SWAP_JOIN_INPUTS(V0) */ V0.VNAME_PREFIX || V0.VNAME_SUFFIX AS S, V0.VALUE_ID
AS S$RDFVID, V0.VNAME_PREFIX AS S$_PREFIX, V0.VNAME_SUFFIX AS S$_SUFFIX, (CASE
WHEN V0.VALUE_TYPE IS NULL THEN NULL WHEN V0.VALUE_TYPE IN ('UR','URI') THEN
'URI'
WHEN V0.VALUE_TYPE IN ('BN', 'BLN') THEN 'BLN'
ELSE 'LIT'
END) AS S$RDFVTYP, V0.LONG_VALUE AS S$RDFCLOB, V0.LITERAL_TYPE AS S$RDFLTYP,
V0.LANGUAGE_TYPE AS S$RDFLANG,
R.HEIGHT, R.HEIGHT$RDFVID, R.HEIGHT$_PREFIX, R.HEIGHT$_SUFFIX, R.HEIGHT$RDFVTYP,
R.HEIGHT$RDFCLOB, R.HEIGHT$RDFLTYP, R.HEIGHT$RDFLANG,
1 AS SEM$ROWNUM
FROM (SELECT SVP0.START_NODE_ID AS S$RDFVID,
SVP0.P7644445801044650266 AS LNAME$RDFVID,
SVP0.P4791477124431525340_VNAME_PREFIX || SVP0.P4791477124431525340_VNAME_SUFFIX
AS HEIGHT, (CASE WHEN SVP0.P4791477124431525340_VALUE_TYPE IS NULL THEN NULL
WHEN SVP0.P4791477124431525340_VALUE_TYPE IN ('UR','URI') THEN 'URI'
WHEN SVP0.P4791477124431525340_VALUE_TYPE IN ('BN', 'BLN') THEN 'BLN'
ELSE 'LIT'
END) AS HEIGHT$RDFVTYP, SVP0.P4791477124431525340 AS HEIGHT$RDFVID,
SVP0.P4791477124431525340_VNAME_PREFIX AS HEIGHT$_PREFIX,
SVP0.P4791477124431525340_VNAME_SUFFIX AS HEIGHT$_SUFFIX,
SVP0.P4791477124431525340_LITERAL_TYPE AS HEIGHT$RDFLTYP,
SVP0.P4791477124431525340_LANGUAGE_TYPE AS HEIGHT$RDFLANG, SVP0.P479147712443
1525340_LONG_VALUE AS HEIGHT$RDFCLOB,
SVP0.P8337314745347241189 AS FNAME$RDFVID,
SVP0.START_NODE_ID AS BGP$1
FROM "RDFUSER".NET1#RDF_XT$SVP_M1+__FNM_LNM_HGHT SVP0
WHERE
SVP0.P8337314745347241189 IS NOT NULL AND
SVP0.P7644445801044650266 IS NOT NULL AND
SVP0.P4791477124431525340 IS NOT NULL AND
1-116
Chapter 1
Using the SEM_MATCH Table Function to Query Semantic Data
1 row selected.
1-117
Chapter 1
Using the SEM_MATCH Table Function to Query Semantic Data
SQL>
SQL> select * from spm_index_info order by 1,2;
INDEX_NAME
1-118
Chapter 1
Using the SEM_MATCH Table Function to Query Semantic Data
MYNET#RDF_XX$MVP_M1_P4326314471650369210 MYNET#RDF_XT$MVP_M1+_P4326314471650369210
NONUNIQUE ENABLED 1 TBS_3
START_NODE_ID
MYNET#RDF_XX$PCN_M1_UQ__DRIVES MYNET#RDF_XT$PCN_M1+__DRIVES
NONUNIQUE ENABLED 1 TBS_3
START_NODE_ID
MYNET#RDF_XX$PCN_M1_UQ__LINKED MYNET#RDF_XT$PCN_M1+__LINKED
NONUNIQUE ENABLED 1 TBS_3
START_NODE_ID
MYNET#RDF_XX$PCN_M1__DRIVES_P14284748913 MYNET#RDF_XT$PCN_M1+__DRIVES
NONUNIQUE ENABLED 1 TBS_3
81274755
P1428474891381274755
MYNET#RDF_XX$PCN_M1__DRIVES_P43263144716 MYNET#RDF_XT$PCN_M1+__DRIVES
NONUNIQUE ENABLED 1 TBS_3
50369210
P4326314471650369210
MYNET#RDF_XX$PCN_M1__LINKED_P12357259844 MYNET#RDF_XT$PCN_M1+__LINKED
NONUNIQUE ENABLED 1 TBS_3
93469672
P1235725984493469672
MYNET#RDF_XX$PCN_M1__LINKED_P23021838993 MYNET#RDF_XT$PCN_M1+__LINKED
NONUNIQUE ENABLED 1 TBS_3
73633243
P2302183899373633243
MYNET#RDF_XX$PCN_M1__LINKED_P80515265581 MYNET#RDF_XT$PCN_M1+__LINKED
NONUNIQUE ENABLED 1 TBS_3
7489328
P805152655817489328
MYNET#RDF_XX$SVP_M1_UQ MYNET#RDF_XT$SVP_M1+
UNIQUE DISABLED TBS_3
START_NODE_ID
10 rows selected.
Index dropped.
SQL>
SQL> -- SVP no prefixes
SQL> exec sem_apis.create_index_on_spm_tab('idx1', 'm1', '<http://www.example.org/
works_for> +G G+ <http://www.example.org/friend_of> S', network_owner=>'rdfuser',
network_name=>'mynet');
1-119
Chapter 1
Using the SEM_MATCH Table Function to Query Semantic Data
SQL>
SQL> select * from spm_index_info order by 1,2;
INDEX_NAME
TABLE_NAME UNIQUENES COMPRESSION PREFIX_LENGTH
TABLESPACE_NAME
----------------------------------------
---------------------------------------- --------- ------------- -------------
------------------------------
KEY
---------------------------------------------------------------------------------
---------------------------------------------------------------------
IDX1
MYNET#RDF_XT$SVP_M1+ UNIQUE DISABLED
TBS_3
P805152655817489328,G805152655817489328,G2302183899373633243,P2302183899373633243
,START_NODE_ID
MYNET#RDF_XX$MVP_M1_P4326314471650369210
MYNET#RDF_XT$MVP_M1+_P4326314471650369210 NONUNIQUE ENABLED 1
TBS_3
START_NODE_ID
MYNET#RDF_XX$PCN_M1_UQ__DRIVES
MYNET#RDF_XT$PCN_M1+__DRIVES NONUNIQUE ENABLED 1
TBS_3
START_NODE_ID
MYNET#RDF_XX$PCN_M1_UQ__LINKED
MYNET#RDF_XT$PCN_M1+__LINKED NONUNIQUE ENABLED 1
TBS_3
START_NODE_ID
MYNET#RDF_XX$PCN_M1__DRIVES_P14284748913
MYNET#RDF_XT$PCN_M1+__DRIVES NONUNIQUE ENABLED 1
TBS_3
81274755
P1428474891381274755
MYNET#RDF_XX$PCN_M1__DRIVES_P43263144716
MYNET#RDF_XT$PCN_M1+__DRIVES NONUNIQUE ENABLED 1
TBS_3
50369210
P4326314471650369210
MYNET#RDF_XX$PCN_M1__LINKED_P12357259844
MYNET#RDF_XT$PCN_M1+__LINKED NONUNIQUE ENABLED 1
TBS_3
93469672
P1235725984493469672
MYNET#RDF_XX$PCN_M1__LINKED_P23021838993
MYNET#RDF_XT$PCN_M1+__LINKED NONUNIQUE ENABLED 1
TBS_3
73633243
P2302183899373633243
MYNET#RDF_XX$PCN_M1__LINKED_P80515265581
MYNET#RDF_XT$PCN_M1+__LINKED NONUNIQUE ENABLED 1
TBS_3
7489328
P805152655817489328
MYNET#RDF_XX$SVP_M1_UQ
MYNET#RDF_XT$SVP_M1+ UNIQUE DISABLED
TBS_3
START_NODE_ID
10 rows selected.
1-120
Chapter 1
Using the SEM_MATCH Table Function to Query Semantic Data
Index dropped.
SQL>
SQL> -- PCN no prefixes
SQL> exec sem_apis.create_index_on_spm_tab('idx1', 'm1', '<http://www.example.org/
works_for> +G G+ <http://www.example.org/friend_of> S', options=>' PCN_NAME=linked',
network_owner=>'rdfuser', network_name=>'mynet');
PL/SQL procedure successfully completed.
SQL>
SQL> select * from spm_index_info order by 1,2;
INDEX_NAME TABLE_NAME
UNIQUENES COMPRESSION PREFIX_LENGTH TABLESPACE_NAME
---------------------------------------- ----------------------------------------
--------- ------------- ------------- ------------------------------
KEY
---------------------------------------------------------------------------------------
---------------------------------------------------------------
IDX1 MYNET#RDF_XT$PCN_M1+__LINKED
NONUNIQUE DISABLED TBS_3
P805152655817489328,G805152655817489328,G2302183899373633243,P2302183899373633243,START
_NODE_ID
MYNET#RDF_XX$MVP_M1_P4326314471650369210 MYNET#RDF_XT$MVP_M1+_P4326314471650369210
NONUNIQUE ENABLED 1 TBS_3
START_NODE_ID
MYNET#RDF_XX$PCN_M1_UQ__DRIVES MYNET#RDF_XT$PCN_M1+__DRIVES
NONUNIQUE ENABLED 1 TBS_3
START_NODE_ID
MYNET#RDF_XX$PCN_M1_UQ__LINKED MYNET#RDF_XT$PCN_M1+__LINKED
NONUNIQUE ENABLED 1 TBS_3
START_NODE_ID
MYNET#RDF_XX$PCN_M1__DRIVES_P14284748913 MYNET#RDF_XT$PCN_M1+__DRIVES
NONUNIQUE ENABLED 1 TBS_3
81274755
P1428474891381274755
MYNET#RDF_XX$PCN_M1__DRIVES_P43263144716 MYNET#RDF_XT$PCN_M1+__DRIVES
NONUNIQUE ENABLED 1 TBS_3
50369210
P4326314471650369210
MYNET#RDF_XX$PCN_M1__LINKED_P12357259844 MYNET#RDF_XT$PCN_M1+__LINKED
NONUNIQUE ENABLED 1 TBS_3
93469672
P1235725984493469672
MYNET#RDF_XX$PCN_M1__LINKED_P23021838993 MYNET#RDF_XT$PCN_M1+__LINKED
NONUNIQUE ENABLED 1 TBS_3
73633243
P2302183899373633243
MYNET#RDF_XX$PCN_M1__LINKED_P80515265581 MYNET#RDF_XT$PCN_M1+__LINKED
NONUNIQUE ENABLED 1 TBS_3
7489328
P805152655817489328
MYNET#RDF_XX$SVP_M1_UQ MYNET#RDF_XT$SVP_M1+
UNIQUE DISABLED TBS_3
START_NODE_ID
10 rows selected.
SQL> drop index idx1;
Index dropped.
1-121
Chapter 1
Using the SEM_MATCH Table Function to Query Semantic Data
SQL>
SQL> -- MVP
SQL> exec sem_apis.create_index_on_spm_tab('idx1', 'm1', 'P G S', 'ex:drives',
prefixes=>' PREFIX : <http://wwww.nothing.org/> PREFIX ex: <http://
www.example.org/>', prefix_length=> 3, network_owner=>'rdfuser',
network_name=>'mynet');
SQL>
SQL> select * from spm_index_info order by 1,2;
INDEX_NAME
TABLE_NAME UNIQUENES COMPRESSION PREFIX_LENGTH
TABLESPACE_NAME
----------------------------------------
---------------------------------------- --------- ------------- -------------
------------------------------
KEY
---------------------------------------------------------------------------------
---------------------------------------------------------------------
IDX1
MYNET#RDF_XT$MVP_M1+_P4326314471650369210 NONUNIQUE ENABLED 3
TBS_3
P4326314471650369210,G4326314471650369210,START_NODE_ID
MYNET#RDF_XX$MVP_M1_P4326314471650369210
MYNET#RDF_XT$MVP_M1+_P4326314471650369210 NONUNIQUE ENABLED 1
TBS_3
START_NODE_ID
MYNET#RDF_XX$PCN_M1_UQ__DRIVES
MYNET#RDF_XT$PCN_M1+__DRIVES NONUNIQUE ENABLED 1
TBS_3
START_NODE_ID
MYNET#RDF_XX$PCN_M1_UQ__LINKED
MYNET#RDF_XT$PCN_M1+__LINKED NONUNIQUE ENABLED 1
TBS_3
START_NODE_ID
MYNET#RDF_XX$PCN_M1__DRIVES_P14284748913
MYNET#RDF_XT$PCN_M1+__DRIVES NONUNIQUE ENABLED 1
TBS_3
81274755
P1428474891381274755
MYNET#RDF_XX$PCN_M1__DRIVES_P43263144716
MYNET#RDF_XT$PCN_M1+__DRIVES NONUNIQUE ENABLED 1
TBS_3
50369210
P4326314471650369210
MYNET#RDF_XX$PCN_M1__LINKED_P12357259844
MYNET#RDF_XT$PCN_M1+__LINKED NONUNIQUE ENABLED 1
TBS_3
93469672
P1235725984493469672
MYNET#RDF_XX$PCN_M1__LINKED_P23021838993
MYNET#RDF_XT$PCN_M1+__LINKED NONUNIQUE ENABLED 1
TBS_3
73633243
P2302183899373633243
MYNET#RDF_XX$PCN_M1__LINKED_P80515265581
MYNET#RDF_XT$PCN_M1+__LINKED NONUNIQUE ENABLED 1
TBS_3
1-122
Chapter 1
Using the SEM_MATCH Table Function to Query Semantic Data
7489328
P805152655817489328
MYNET#RDF_XX$SVP_M1_UQ MYNET#RDF_XT$SVP_M1+
UNIQUE DISABLED TBS_3
START_NODE_ID
10 rows selected.
Index dropped.
SQL>
SQL> -- PCN index
SQL> exec sem_apis.create_index_on_spm_tab('idx1', 'm1', 'ex:drives +G S', null,
prefixes=>' PREFIX : <http://wwww.nothing.org/> PREFIX ex: <http://
www.example.org/>', prefix_length=> 2, options=>' PCN_NAME=drives',
network_owner=>'rdfuser', network_name=>'mynet');
PL/SQL procedure successfully completed.
SQL>
SQL> select * from spm_index_info order by 1,2;
INDEX_NAME TABLE_NAME
UNIQUENES COMPRESSION PREFIX_LENGTH TABLESPACE_NAME
---------------------------------------- ----------------------------------------
--------- ------------- ------------- ------------------------------
KEY
---------------------------------------------------------------------------------------
---------------------------------------------------------------
IDX1 MYNET#RDF_XT$PCN_M1+__DRIVES
NONUNIQUE ENABLED 2 TBS_3
P4326314471650369210,G4326314471650369210,START_NODE_ID
MYNET#RDF_XX$MVP_M1_P4326314471650369210 MYNET#RDF_XT$MVP_M1+_P4326314471650369210
NONUNIQUE ENABLED 1 TBS_3
START_NODE_ID
MYNET#RDF_XX$PCN_M1_UQ__DRIVES MYNET#RDF_XT$PCN_M1+__DRIVES
NONUNIQUE ENABLED 1 TBS_3
START_NODE_ID
MYNET#RDF_XX$PCN_M1_UQ__LINKED MYNET#RDF_XT$PCN_M1+__LINKED
NONUNIQUE ENABLED 1 TBS_3
START_NODE_ID
MYNET#RDF_XX$PCN_M1__DRIVES_P14284748913 MYNET#RDF_XT$PCN_M1+__DRIVES
NONUNIQUE ENABLED 1 TBS_3
81274755
P1428474891381274755
MYNET#RDF_XX$PCN_M1__DRIVES_P43263144716 MYNET#RDF_XT$PCN_M1+__DRIVES
NONUNIQUE ENABLED 1 TBS_3
50369210
P4326314471650369210
MYNET#RDF_XX$PCN_M1__LINKED_P12357259844 MYNET#RDF_XT$PCN_M1+__LINKED
NONUNIQUE ENABLED 1 TBS_3
93469672
P1235725984493469672
MYNET#RDF_XX$PCN_M1__LINKED_P23021838993 MYNET#RDF_XT$PCN_M1+__LINKED
NONUNIQUE ENABLED 1 TBS_3
73633243
P2302183899373633243
MYNET#RDF_XX$PCN_M1__LINKED_P80515265581 MYNET#RDF_XT$PCN_M1+__LINKED
NONUNIQUE ENABLED 1 TBS_3
7489328
1-123
Chapter 1
Using the SEM_MATCH Table Function to Query Semantic Data
P805152655817489328
MYNET#RDF_XX$SVP_M1_UQ
MYNET#RDF_XT$SVP_M1+ UNIQUE DISABLED
TBS_3
START_NODE_ID
10 rows selected.
SQL> drop index idx1;
Index dropped.
SQL>
SQL> -- add value to index
SQL> -- SVP
SQL> select * from spm_index_info order by 1,2;
INDEX_NAME
TABLE_NAME UNIQUENES COMPRESSION PREFIX_LENGTH
TABLESPACE_NAME
----------------------------------------
---------------------------------------- --------- ------------- -------------
------------------------------
KEY
---------------------------------------------------------------------------------
---------------------------------------------------------------------
MYNET#RDF_XX$MVP_M1_P4326314471650369210
MYNET#RDF_XT$MVP_M1+_P4326314471650369210 NONUNIQUE ENABLED 1
TBS_3
START_NODE_ID
MYNET#RDF_XX$PCN_M1_UQ__DRIVES
MYNET#RDF_XT$PCN_M1+__DRIVES NONUNIQUE ENABLED 1
TBS_3
START_NODE_ID
MYNET#RDF_XX$PCN_M1_UQ__LINKED
MYNET#RDF_XT$PCN_M1+__LINKED NONUNIQUE ENABLED 1
TBS_3
START_NODE_ID
MYNET#RDF_XX$PCN_M1__DRIVES_P14284748913
MYNET#RDF_XT$PCN_M1+__DRIVES NONUNIQUE ENABLED 1
TBS_3
81274755
P1428474891381274755
MYNET#RDF_XX$PCN_M1__DRIVES_P43263144716
MYNET#RDF_XT$PCN_M1+__DRIVES NONUNIQUE ENABLED 1
TBS_3
50369210
P4326314471650369210
MYNET#RDF_XX$PCN_M1__LINKED_P12357259844
MYNET#RDF_XT$PCN_M1+__LINKED NONUNIQUE ENABLED 1
TBS_3
93469672
P1235725984493469672
MYNET#RDF_XX$PCN_M1__LINKED_P23021838993
MYNET#RDF_XT$PCN_M1+__LINKED NONUNIQUE ENABLED 1
TBS_3
73633243
P2302183899373633243
MYNET#RDF_XX$PCN_M1__LINKED_P80515265581
MYNET#RDF_XT$PCN_M1+__LINKED NONUNIQUE ENABLED 1
TBS_3
7489328
P805152655817489328
MYNET#RDF_XX$SVP_M1_UQ
1-124
Chapter 1
Using the SEM_MATCH Table Function to Query Semantic Data
INDEX_NAME TABLE_NAME
UNIQUENES COMPRESSION PREFIX_LENGTH TABLESPACE_NAME
---------------------------------------- ----------------------------------------
--------- ------------- ------------- ------------------------------
KEY
---------------------------------------------------------------------------------------
---------------------------------------------------------------
MYNET#RDF_XX$MVP_M1_P4326314471650369210 MYNET#RDF_XT$MVP_M1+_P4326314471650369210
NONUNIQUE ENABLED 1 TBS_3
START_NODE_ID
MYNET#RDF_XX$PCN_M1_UQ__DRIVES MYNET#RDF_XT$PCN_M1+__DRIVES
NONUNIQUE ENABLED 1 TBS_3
START_NODE_ID
MYNET#RDF_XX$PCN_M1_UQ__LINKED MYNET#RDF_XT$PCN_M1+__LINKED
NONUNIQUE ENABLED 1 TBS_3
START_NODE_ID
MYNET#RDF_XX$PCN_M1__DRIVES_P14284748913 MYNET#RDF_XT$PCN_M1+__DRIVES
NONUNIQUE ENABLED 1 TBS_3
81274755
P1428474891381274755
MYNET#RDF_XX$PCN_M1__DRIVES_P43263144716 MYNET#RDF_XT$PCN_M1+__DRIVES
NONUNIQUE ENABLED 1 TBS_3
50369210
P4326314471650369210
MYNET#RDF_XX$PCN_M1__LINKED_P12357259844 MYNET#RDF_XT$PCN_M1+__LINKED
NONUNIQUE ENABLED 1 TBS_3
93469672
P1235725984493469672
MYNET#RDF_XX$PCN_M1__LINKED_P23021838993 MYNET#RDF_XT$PCN_M1+__LINKED
NONUNIQUE ENABLED 1 TBS_3
73633243
P2302183899373633243
MYNET#RDF_XX$PCN_M1__LINKED_P80515265581 MYNET#RDF_XT$PCN_M1+__LINKED
NONUNIQUE ENABLED 1 TBS_3
7489328
P805152655817489328
MYNET#RDF_XX$SVP_M1_UQ MYNET#RDF_XT$SVP_M1+
UNIQUE DISABLED TBS_3
START_NODE_ID
9 rows selected.
1-125
Chapter 1
Using the SEM_MATCH Table Function to Query Semantic Data
SQL>
SQL> exec sem_apis.create_index_on_spm_tab('idx1', 'm1', 'VP+ ex:works_for +G
G+ +VS ex:friend_of S +VT', prefixes=>' PREFIX : <http://wwww.nothing.org/>
PREFIX ex: <http://www.example.org/>', prefix_length=> 4,
network_owner=>'rdfuser', network_name=>'mynet');
SQL>
SQL> select * from spm_index_info order by 1,2;
INDEX_NAME
TABLE_NAME UNIQUENES COMPRESSION PREFIX_LENGTH
TABLESPACE_NAME
----------------------------------------
---------------------------------------- --------- ------------- -------------
------------------------------
KEY
---------------------------------------------------------------------------------
---------------------------------------------------------------------
IDX1
MYNET#RDF_XT$SVP_M1+ UNIQUE ENABLED 4
TBS_3
P805152655817489328_VNAME_PREFIX,P805152655817489328,G805152655817489328,G2302183
899373633243,P805152655817489328_VNAME_SUFFIX,P2302183899373633243,ST
ART_NODE_ID,P2302183899373633243_VALUE_TYPE
MYNET#RDF_XX$MVP_M1_P4326314471650369210
MYNET#RDF_XT$MVP_M1+_P4326314471650369210 NONUNIQUE ENABLED 1
TBS_3
START_NODE_ID
MYNET#RDF_XX$PCN_M1_UQ__DRIVES
MYNET#RDF_XT$PCN_M1+__DRIVES NONUNIQUE ENABLED 1
TBS_3
START_NODE_ID
MYNET#RDF_XX$PCN_M1_UQ__LINKED
MYNET#RDF_XT$PCN_M1+__LINKED NONUNIQUE ENABLED 1
TBS_3
START_NODE_ID
MYNET#RDF_XX$PCN_M1__DRIVES_P14284748913
MYNET#RDF_XT$PCN_M1+__DRIVES NONUNIQUE ENABLED 1
TBS_3
81274755
P1428474891381274755
MYNET#RDF_XX$PCN_M1__DRIVES_P43263144716
MYNET#RDF_XT$PCN_M1+__DRIVES NONUNIQUE ENABLED 1
TBS_3
50369210
P4326314471650369210
MYNET#RDF_XX$PCN_M1__LINKED_P12357259844
MYNET#RDF_XT$PCN_M1+__LINKED NONUNIQUE ENABLED 1
TBS_3
93469672
P1235725984493469672
MYNET#RDF_XX$PCN_M1__LINKED_P23021838993
MYNET#RDF_XT$PCN_M1+__LINKED NONUNIQUE ENABLED 1
TBS_3
73633243
1-126
Chapter 1
Using the SEM_MATCH Table Function to Query Semantic Data
P2302183899373633243
MYNET#RDF_XX$PCN_M1__LINKED_P80515265581 MYNET#RDF_XT$PCN_M1+__LINKED
NONUNIQUE ENABLED 1 TBS_3
7489328
P805152655817489328
MYNET#RDF_XX$SVP_M1_UQ MYNET#RDF_XT$SVP_M1+
UNIQUE DISABLED TBS_3
START_NODE_ID
10 rows selected.
Index dropped.
SQL>
SQL> -- PCN
SQL> exec sem_apis.create_index_on_spm_tab('idx1', 'm1', 'VP+ ex:works_for +G G+ +VS
ex:friend_of S', prefixes=>' PREFIX : <http://wwww.nothing.org/> PREFIX ex: <http://
www.example.org/>', prefix_length=> 4, options=>' PCN_NAME=linked',
network_owner=>'rdfuser', network_name=>'mynet');
PL/SQL procedure successfully completed.
SQL>
SQL> select * from spm_index_info order by 1,2;
INDEX_NAME TABLE_NAME
UNIQUENES COMPRESSION PREFIX_LENGTH TABLESPACE_NAME
---------------------------------------- ----------------------------------------
--------- ------------- ------------- ------------------------------
KEY
---------------------------------------------------------------------------------------
---------------------------------------------------------------
IDX1 MYNET#RDF_XT$PCN_M1+__LINKED
NONUNIQUE ENABLED 4 TBS_3
P805152655817489328_VNAME_PREFIX,P805152655817489328,G805152655817489328,G2302183899373
633243,P805152655817489328_VNAME_SUFFIX,P2302183899373633243,ST
ART_NODE_ID
MYNET#RDF_XX$MVP_M1_P4326314471650369210 MYNET#RDF_XT$MVP_M1+_P4326314471650369210
NONUNIQUE ENABLED 1 TBS_3
START_NODE_ID
MYNET#RDF_XX$PCN_M1_UQ__DRIVES MYNET#RDF_XT$PCN_M1+__DRIVES
NONUNIQUE ENABLED 1 TBS_3
START_NODE_ID
MYNET#RDF_XX$PCN_M1_UQ__LINKED MYNET#RDF_XT$PCN_M1+__LINKED
NONUNIQUE ENABLED 1 TBS_3
START_NODE_ID
MYNET#RDF_XX$PCN_M1__DRIVES_P14284748913 MYNET#RDF_XT$PCN_M1+__DRIVES
NONUNIQUE ENABLED 1 TBS_3
81274755
P1428474891381274755
MYNET#RDF_XX$PCN_M1__DRIVES_P43263144716 MYNET#RDF_XT$PCN_M1+__DRIVES
NONUNIQUE ENABLED 1 TBS_3
50369210
P4326314471650369210
MYNET#RDF_XX$PCN_M1__LINKED_P12357259844 MYNET#RDF_XT$PCN_M1+__LINKED
NONUNIQUE ENABLED 1 TBS_3
93469672
P1235725984493469672
MYNET#RDF_XX$PCN_M1__LINKED_P23021838993 MYNET#RDF_XT$PCN_M1+__LINKED
NONUNIQUE ENABLED 1 TBS_3
1-127
Chapter 1
Using the SEM_MATCH Table Function to Query Semantic Data
73633243
P2302183899373633243
MYNET#RDF_XX$PCN_M1__LINKED_P80515265581
MYNET#RDF_XT$PCN_M1+__LINKED NONUNIQUE ENABLED 1
TBS_3
7489328
P805152655817489328
MYNET#RDF_XX$SVP_M1_UQ
MYNET#RDF_XT$SVP_M1+ UNIQUE DISABLED
TBS_3
START_NODE_ID
10 rows selected.
SQL> drop index idx1;
Index dropped.
SQL>
SQL>
SQL> exec sem_apis.create_index_on_spm_tab('idx1', 'm1', 'VP+ ex:works_for +G
G+ +VS ex:friend_of S +VT', prefixes=>' PREFIX : <http://wwww.nothing.org/>
PREFIX ex: <http://www.example.org/>', prefix_length=> 4, options=>'
PCN_NAME=linked', network_owner=>'rdfuser', network_name=>'mynet');
PL/SQL procedure successfully completed.
SQL>
SQL> --MVP
SQL> select * from spm_index_info order by 1,2;
INDEX_NAME
TABLE_NAME UNIQUENES COMPRESSION PREFIX_LENGTH
TABLESPACE_NAME
----------------------------------------
---------------------------------------- --------- ------------- -------------
------------------------------
KEY
---------------------------------------------------------------------------------
---------------------------------------------------------------------
IDX1
MYNET#RDF_XT$PCN_M1+__LINKED NONUNIQUE ENABLED 4
TBS_3
P805152655817489328_VNAME_PREFIX,P805152655817489328,G805152655817489328,G2302183
899373633243,P805152655817489328_VNAME_SUFFIX,P2302183899373633243,ST
ART_NODE_ID,P2302183899373633243_VALUE_TYPE
MYNET#RDF_XX$MVP_M1_P4326314471650369210
MYNET#RDF_XT$MVP_M1+_P4326314471650369210 NONUNIQUE ENABLED 1
TBS_3
START_NODE_ID
MYNET#RDF_XX$PCN_M1_UQ__DRIVES
MYNET#RDF_XT$PCN_M1+__DRIVES NONUNIQUE ENABLED 1
TBS_3
START_NODE_ID
MYNET#RDF_XX$PCN_M1_UQ__LINKED
MYNET#RDF_XT$PCN_M1+__LINKED NONUNIQUE ENABLED 1
TBS_3
START_NODE_ID
MYNET#RDF_XX$PCN_M1__DRIVES_P14284748913
MYNET#RDF_XT$PCN_M1+__DRIVES NONUNIQUE ENABLED 1
TBS_3
81274755
P1428474891381274755
MYNET#RDF_XX$PCN_M1__DRIVES_P43263144716
MYNET#RDF_XT$PCN_M1+__DRIVES NONUNIQUE ENABLED 1
TBS_3
50369210
1-128
Chapter 1
Using the SEM_MATCH Table Function to Query Semantic Data
P4326314471650369210
MYNET#RDF_XX$PCN_M1__LINKED_P12357259844 MYNET#RDF_XT$PCN_M1+__LINKED
NONUNIQUE ENABLED 1 TBS_3
93469672
P1235725984493469672
MYNET#RDF_XX$PCN_M1__LINKED_P23021838993 MYNET#RDF_XT$PCN_M1+__LINKED
NONUNIQUE ENABLED 1 TBS_3
73633243
P2302183899373633243
MYNET#RDF_XX$PCN_M1__LINKED_P80515265581 MYNET#RDF_XT$PCN_M1+__LINKED
NONUNIQUE ENABLED 1 TBS_3
7489328
P805152655817489328
MYNET#RDF_XX$SVP_M1_UQ MYNET#RDF_XT$SVP_M1+
UNIQUE DISABLED TBS_3
START_NODE_ID
10 rows selected.
SQL> drop index idx1;
Index dropped.
1 row selected.
1.6.13.8 Performing Bulk Load Operations on Models with SPM Auxiliary Tables
Bulk load to an RDF model is not supported if SPM auxiliary tables are present for that
model. Before invoking bulk load, all the SPM auxiliary tables for that model must be
dropped. You can call the SEM_APIS.DROP_SPM_TAB procedure to drop the SPM auxiliary
tables.
1-129
Chapter 1
Using the SEM_MATCH Table Function to Query Semantic Data
1-130
Chapter 1
Using the SEM_MATCH Table Function to Query Semantic Data
• A model with SPM auxiliary tables cannot be used as the destination model in a
SEM_APIS.MERGE_MODELS operation.
• SPARQL queries that use GeoSPARQL functions or Oracle Text functions do not utilize
SPM auxiliary tables.
• Evaluation of + and * property path expressions does not utilize SPM auxiliary tables.
• SPM auxiliary tables in MDSYS networks are not imported or exported by Oracle Data
Pump.
• SPM auxiliary tables are not supported for SEM_APIS.APPEND_SEM_NETWORK_DATA,
SEM_APIS.MOVE_SEM_NETWORK_DATA or SEM_APIS.RESTORE_SEM_NETWORK_DATA operations.
1-131
Chapter 1
Using the SEM_MATCH Table Function to Query Semantic Data
Indexes can be used to improve the performance of queries that contain a filter
condition involving a typed literal. For example, an xsd:date index may speed up
evaluation of the filter (?x < "1929-11-16Z"^^xsd:date).
Convenient interfaces are provided for creating, altering, and dropping these indexes
for order columns. For more information, see Using Data Type Indexes.
Note, however, that the existence of these indexes on the RDF_VALUE$ table can
significantly slow down bulk load operations. In many cases it may be faster to drop
the indexes, perform the bulk load, and then re-create the indexes, as opposed to
doing the bulk load with the indexes in place.
1-132
Chapter 1
Using the SEM_MATCH Table Function to Query Semantic Data
at the individual query level using the dynamic_sampling(level) SQL query hint. In general,
it is good to experiment with dynamic sampling levels between 3 and 6. For information about
estimating statistics with dynamic sampling, see Oracle Database SQL Tuning Guide.
Example 1-100 uses a SQL hint for a dynamic sampling level of 6.
Example 1-100 SQL Hint for Dynamic Sampling
SELECT /*+ DYNAMIC_SAMPLING(6) */ x, y
FROM TABLE(SEM_MATCH(
'PREFIX : <http://www.example.org/family/>
SELECT *
WHERE {
?x :grandParentOf ?y .
?x rdf:type :Male .
?x :birthDate ?bd }',
SEM_Models('family'),
SEM_Rulebases('RDFS','family_rb'),
null, null, null, '', null, null,
'RDFUSER', 'NET1'));
1-133
Chapter 1
Using the SEM_MATCH Table Function to Query Semantic Data
A backward chaining style inference using rdfs:subClassOf+ for ontologies with very
deep class hierarchies may be an exception to this rule. In such cases, unbounded
CONNECT BY-based evaluations may perform better than depth-limited evaluations
with very high depth limits (for example, 50).
select s, x
from table(sem_match(
'PREFIX : <http://scott-hr.org#>
SELECT *
WHERE {
?s :ename "ADAMS" .
?s :hasManager+ ?x .
}',
sem_models('scott_hr_data'),
null,null,null,null,' ALL_MAX_PP_DEPTH(0) ', null, null,
'RDFUSER', 'NET1'));
The query can be transformed to force the nested-loop strategy. Notice that the model
specified in the SERVICE graph is the same as the model specified in the
SEM_MATCH call.
select s, x
from table(sem_match(
'PREFIX : <http://scott-hr.org#>
SELECT *
WHERE {
?s :ename "ADAMS" .
service oram:scott_hr_data { ?s :hasManager+ ?x . }
}',
sem_models('scott_hr_data'),
null,null,null,null,' ALL_MAX_PP_DEPTH(0) OVERLOADED_NL=T ', null,
null,
'RDFUSER', 'NET1'));
1-134
Chapter 1
Using the SEM_MATCH Table Function to Query Semantic Data
conn / as sysdba;
grant create any context to testuser;
conn testuser/testuser;
1-135
Chapter 1
Using the SEM_MATCH Table Function to Query Semantic Data
function get_attribute(
name varchar2
) return varchar2 as
begin
return sys_context('MY_CTXT', name);
end;
end MY_CTXT_PKG;
/
-- Set a value
exec MY_CTXT_PKG.set_attribute('value','<http://www.example.org/family/
Martha>');
1-136
Chapter 1
Using the SEM_MATCH Table Function to Query Semantic Data
SELECT s, t
FROM TABLE(SEM_MATCH(
'PREFIX : <http://www.example.org/family/>
SELECT * WHERE {
{ SELECT ?s (CONCAT(?title, ". ", ?fullname) AS ?fulltitle)
WHERE { ?s :fullname ?fullname .
?s :title ?title }
}
{ SELECT ?t (CONCAT(?title, ". ", ?fname, " ", ?lname) AS ?fulltitle)
WHERE {
?t :fname ?fname .
?t :lname ?lname .
?t :title ?title }
}
}',
SEM_Models('family'),
SEM_Rulebases('RDFS','family_rb'),
null,
null,
null,
1-137
Chapter 1
Using the SEM_MATCH Table Function to Query Semantic Data
SELECT f, l, n, e
FROM table(sem_match(
'PREFIX : <http://www.example.com#>
SELECT ?f ?l ?n ?e
WHERE { ?s :fname ?f . ?s :lname ?l . ?s :nickName ?n . ?s :email ?
e }',
sem_models('m1'),
null,null,null,null,
' AUTO_HINTS=T ')
);
The following are a few general recommendations for Semantic Network Indexes:
• Most SPARQL queries have triple patterns with bound predicates, so it is a good
idea to have P, PC, and PS combinations covered as leading columns in your
overall index set. Such a combination is captured by the default index setup
(PCSGM, PSCGM in 19c, and PCSGM, SPCGM in 21c).
• If you have queries with unbound predicates (for example, { ?s :ssn 1234 . ?
s ?p ?o }), then a network index with a leading column other than P may be
needed. An SPCGM index would be more suitable for this example because of the
join on subject variable ?s.
• If you are running DESCRIBE queries or DESCRIBE-style patterns such as
{ { <urn:abc> ?p1 ?o1 } UNION { ?s2 ?p2 <urn:abc> } }, then a network
index with a leading C column (for example, CM) in addition to an index with a
leading S column may be needed.
1-138
Chapter 1
Using the SEM_MATCH Table Function to Query Semantic Data
• If you have named graph queries with selective FROM, FROM NAMED, or GRAPH
clauses, then a network index with a leading G column may be needed (for example,
GPCSM).
• An H index is needed for efficient SPARQL Update GRAPH operations (for example,
DROP GRAPH) on schema-private networks. An H index is not needed for MDSYS
networks because an index on the application table is used instead.
• A PSCGM index is usually smaller than an SPCGM index due to better prefix compression, so
if your workload does not include queries with unbound predicates, replacing an SPCGM
index with a PSCGM index may give better performance.
Note that the performance of very selective queries may suffer with RDF_LINK$ indexes
invisible, so you may need to experiment with index visibility depending on your query
workload.
In addition to these index settings, it is recommended to use parallel query execution with
Oracle Database In-Memory, as the speedup from parallelization can be significant in many
cases.
For larger datasets (100 M triples or more), it is also recommended to use a hash-
subpartitioned semantic network with Oracle Database In-Memory. Hash subpartitioning is
described in Semantic Networks.
1-139
Chapter 1
Using the SEM_MATCH Table Function to Query Semantic Data
SELECT ?y
WHERE {
:emp1 :salary ?s1 .
?y :salary ?s2 .
FILTER (xsd:decimal(?s2) < xsd:decimal(?s1))
}
1-140
Chapter 1
Using the SEM_MATCH Table Function to Query Semantic Data
– A compile-time error is raised when undefined variables are referenced in the source
of a value assignment.
• Grouping and aggregation
– Non-grouping variables (query variables not used for grouping and therefore not valid
for projection) cannot be reused as a target for value assignment.
– Non-numeric values are ignored by the AVG and SUM aggregates.
– By default, SEM_MATCH returns no rows for an aggregate query with a graph
pattern that fails to match. The W3C specification requires a single, null row for this
case. W3C-compliant behavior can be obtained with the STRICT_AGG_CARD=T query
option for a small performance penalty.
• ORDER BY
– When using SPARQL ORDER BY in SEM_MATCH, the containing SQL query should
be ordered by SEM$ROWNUM to ensure that the desired ordering is maintained
through any enclosing SQL blocks.
• Numeric computations
– The native Oracle NUMBER type is used internally for all arithmetic operations, and
the results of all arithmetic operations are serialized as xsd:decimal. Note that the
native Oracle NUMBER type is more precise than both BINARY_FLOAT and
BINARY_DOUBLE. See Oracle Database SQL Language Reference for more
information on the NUMBER built-in data type.
– Division by zero causes a runtime error instead of producing an unbound value.
• Negation
– EXISTS and NOT EXISTS filters that reference potentially unbound variables are not
supported in the following contexts:
* Non-aliased expressions in GROUP BY
* Input to aggregates
* Expressions in ORDER BY
* FILTER expressions within OPTIONAL graph patterns that also reference
variables that do not appear inside of the OPTIONAL graph pattern
The first three cases can be realized by first assigning the result of the EXISTS or
NOT EXISTS filter to a variable using a BIND clause or SELECT expression.
These restrictions do not apply to EXISTS and NOT EXISTS filters that only
reference definitely bound variables.
• Blank nodes
– Blank nodes are not supported within graph patterns.
– The BNODE(literal) function returns the same blank node value every time it is
called with the same literal argument.
• Property paths
– Unbounded operators + and * use a 10-hop depth limit by default for performance
reasons. This behavior can be changed to a truly unbounded search by setting a
depth limit of 0. See Property Paths for details.
• Long literals (CLOBs)
– SPARQL functions and aggregates do not support long literals by default.
1-141
Chapter 1
Using the SEM_APIS.SPARQL_TO_SQL Function to Query Semantic Data
DECLARE
c sys_refcursor;
sparql_stmt clob;
sql_stmt clob;
x_value varchar2(4000);
BEGIN
sparql_stmt :=
'PREFIX : <http://www.example.org/family/>
SELECT ?x
WHERE {
?x :grandParentOf ?y .
?x rdf:type :Male
}';
1-142
Chapter 1
Using the SEM_APIS.SPARQL_TO_SQL Function to Query Semantic Data
sql_stmt := sem_apis.sparql_to_sql(
sparql_stmt,
sem_models('family'),
SEM_Rulebases('RDFS','family_rb'),
null,
null,
' PLUS_RDFT=VC ', null, null,
'RDFUSER', 'NET1');
END;
/
With the bind variable option, the SQL translation will contain two bind variables for each
transformed SPARQL query variable: one for the value ID, and one for the RDF term string.
An RDF term value can be substituted for a SPARQL query variable by specifying the value
ID (from RDF_VALUE$ table) as the first bind value and the RDF term string as the second
bind value. The value ID for a bound-in RDF term is required for performance reasons. The
typical workflow would be to look up the value ID for an RDF term from the RDF_VALUE$
table (or with SEM_APIS.RES2VID) and then bind the ID and RDF term into the translated
SQL.
Multiple query variables can be transformed into bind variables in a single query. In such
cases, bind variables in the SQL translation will appear in the same order as the SPARQL
BIND clauses appear in the SPARQL query string. That is, the (id, term) pair for the first BIND
clause should be bound first, and the (id, term) pair for the second BIND clause should be
bound second.
The following example shows the use of bind variables for SEM_APIS.SPARQL_TO_SQL
from a PL/SQL block. A dummy bind variable ?n is declared..
DECLARE
sparql_stmt clob;
sql_stmt clob;
1-143
Chapter 1
Using the SEM_APIS.SPARQL_TO_SQL Function to Query Semantic Data
cur sys_refcursor;
vid number;
term varchar2(4000);
c_val varchar2(4000);
BEGIN
-- Add a dummy bind clause in the SPARQL statement
sparql_stmt := 'PREFIX : <http://www.example.org/family/>
SELECT ?c WHERE {
BIND("" as ?s)
?s :parentOf ?c }';
-- Get the SQL translation for SPARQL statement
sql_stmt := sem_apis.sparql_to_sql(
sparql_stmt,
sem_models('family'),
SEM_Rulebases('RDFS','family_rb'),
null,
null,' USE_BIND_VAR=PLSQL PLUS_RDFT=VC ', null, null,
'RDFUSER', 'NET1');
dbms_output.put_line(chr(10)||'?s='||term);
open cur for 'select c$rdfterm from('|| sql_stmt || ')' using
vid,term;
loop
fetch cur into c_val;
exit when cur%NOTFOUND;
dbms_output.put_line('|-->?c='||c_val);
end loop;
close cur;
dbms_output.put_line(chr(10)||'?s='||term);
open cur for 'select c$rdfterm from('|| sql_stmt || ')' using
vid,term;
loop
fetch cur into c_val;
exit when cur%NOTFOUND;
dbms_output.put_line('|-->?c='||c_val);
end loop;
close cur;
END;
/
1-144
Chapter 1
Using the SEM_APIS.SPARQL_TO_SQL Function to Query Semantic Data
The following example shows the use of bind variables from Java for
SEM_APIS.SPARQL_TO_SQL. In this case, the hint USE_BIND_VAR=JDBC is used.
try {
// Get connection
Connection conn=DriverManager.getConnection(
"jdbc:oracle:thin:@localhost:1521:orcl","testuser","testuser");
String sparqlStmt =
"PREFIX : http://www.example.org/family/ \n" +
"SELECT ?c WHERE { \n" +
" BIND(\"\" as ?s) \n" +
" ?s :parentOf ?c \n" +
"}";
1-145
Chapter 1
Using the SEM_APIS.SPARQL_TO_SQL Function to Query Semantic Data
stmt.setLong(1, valueId);
stmt.setString(2, term);
ResultSet rs=stmt.executeQuery();
// Print results
System.out.println("\n?s="+term);
while(rs.next()) {
System.out.println("|-->?c=" + rs.getString("c$rdfterm"));
}
rs.close();
stmt.setLong(1, valueId);
stmt.setString(2, term);
rs=stmt.executeQuery();
// Print results
System.out.println("\n?s="+term);
while(rs.next()) {
System.out.println("|-->?c=" + rs.getString("c$rdfterm"));
}
rs.close();
stmt.close();
ocsVid.close();
conn.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
1-146
Chapter 1
Using the SEM_APIS.GET_SQL Function and SEM_SQL SQL Macro to Query Semantic Data
• The plain SQL returned from SEM_APIS.SPARQL_TO_SQL can support PL/SQL and
JDBC bind variables.
SEM_MATCH, however, provides some unique capabilities that are not possible with
SEM_APIS.SPARQL_TO_SQL..
• Support for projection optimization: If only the VAR$RDFVID column of a projected
variable is selected from the SEM_MATCH invocation, the RDF_VALUE$ join for this
variable will be avoided.
• Support for advanced features that require the procedural start-fetch-close table function
execution: SERVICE_JPDWN=T and OVERLOADED_NL=T options with SPARQL SERVICE.
• The ability to execute queries interactively with tools like SQL*Plus.
1-147
Chapter 1
Using the SEM_APIS.GET_SQL Function and SEM_SQL SQL Macro to Query Semantic Data
SEM$ROWNUM
--------------------
John 4802682235912431956
John URI
OracleHQEmployee 9022701012979055032
OracleHQEmployee URI
1
Matt 5972784495178428863
Matt URI
OracleHQEmployee 9022701012979055032
OracleHQEmployee URI
1
Sue 8947116472173989398
Sue URI
OracleHQEmployee 9022701012979055032
OracleHQEmployee URI
3 rows selected.
Application developers can utilize SEM_SQL SQL Macro to run any translated query
stored in some other tables using RDF$S2S_SQL$ table and
SEM_APIS.SEM_SQL_COMPILE to compile the SQL in the table as shown in the
following example. This will save query translation time from SPARQL to SQL. Note
that before using SEM_SQL for the first time, you must execute
SEM_APIS.CREATE_SEM_SQL.
Table created.
SQL> DECLARE
2 sql_stmt CLOB;
3 BEGIN
4 sql_stmt := sem_apis.SPARQL_TO_SQL('SELECT ?s ?o { ?s <http://
www.w3.org/1999/02/22-rdf-syntax-ns#type> ?o }',
sem_models('m1'),null,null,null,'
',null,null,network_owner=>'RDFUSER2',network_name=>'MYNET');
5 EXECUTE IMMEDIATE 'INSERT INTO sql_tab VALUES (1, :1)' USING
sql_stmt;
6
7 sql_stmt := SEM_APIS.SPARQL_TO_SQL('SELECT ?s ?p ?o { ?s ?p ?
o }',
sem_models('m1'),null,null,null,null,null,null,network_owner=>'RDFUSER2
',network_name=>'MYNET');
8 EXECUTE IMMEDIATE 'INSERT INTO sql_tab VALUES (2, :1)' USING
sql_stmt;
1-148
Chapter 1
Using the SEM_APIS.GET_SQL Function and SEM_SQL SQL Macro to Query Semantic Data
Table truncated.
SQL> INSERT INTO RDF$S2S_SQL$ SELECT s2s_sql FROM sql_tab WHERE id=1;
1 row created.
1-149
Chapter 1
Using the SEM_APIS.GET_SQL Function and SEM_SQL SQL Macro to Query Semantic Data
3 rows selected.
Table truncated.
SQL> INSERT INTO RDF$S2S_SQL$ SELECT s2s_sql FROM sql_tab where id=2;
1 row created.
COUNT(*)
--------------------
26
1 row selected.
1-150
Chapter 1
Using the SEM_APIS.GET_SQL Function and SEM_SQL SQL Macro to Query Semantic Data
John 4802682235912431956
John URI
email 6480734238761529200
email URI
[email protected] 5315621098565335765
[email protected] LIT
1
John 4802682235912431956
John URI
foaf 2289371774016051690
foaf URI
Matt 5972784495178428863
Matt URI
1
John 4802682235912431956
John URI
http://www.w3.org/1999/02/22-r 834132227519661324
df-syntax-ns#type
http://www.w3.org/1999/02/22-r type URI
df-syntax-ns#
OracleHQEmployee 9022701012979055032
OracleHQEmployee URI
1
John 4802682235912431956
John URI
mbox 5760688889368728142
mbox URI
[email protected] 1322012223731379319
[email protected] LIT
1
John 4802682235912431956
John URI
name 6027014909707307188
name URI
John Doe 3287391926372438447
John Doe LIT
1
John 4802682235912431956
John URI
nick 4608123542649301902
nick URI
JD 8942401707893765892
JD LIT
1
Matt 5972784495178428863
Matt URI
age 7369467453923552448
age URI
40 1809238195348668799
40 LIT
http://www.w3.org/2001/XMLSchema#decimal
1
Matt 5972784495178428863
1-151
Chapter 1
Using the SEM_APIS.GET_SQL Function and SEM_SQL SQL Macro to Query Semantic Data
Matt URI
email 6480734238761529200
email URI
[email protected] 5816699135852471804
[email protected] LIT
1
Matt 5972784495178428863
Matt URI
foaf 2289371774016051690
foaf URI
Su 7425194847458329079
Su URI
1
Matt 5972784495178428863
Matt URI
http://www.w3.org/1999/02/22-r 834132227519661324
df-syntax-ns#type
http://www.w3.org/1999/02/22-r type URI
df-syntax-ns#
OracleHQEmployee 9022701012979055032
OracleHQEmployee URI
1
Matt 5972784495178428863
Matt URI
mbox 5760688889368728142
mbox URI
[email protected] 1674614553190527316
[email protected] LIT
1
Matt 5972784495178428863
Matt URI
name 6027014909707307188
name URI
Matt Adams 1025319037763704306
Matt Adams LIT
1
Matt 5972784495178428863
Matt URI
teleCommFrom 493206824495339087
teleCommFrom URI
teleCommLoc1 4570292005318753230
teleCommLoc1 URI
1
Sue 8947116472173989398
Sue URI
age 7369467453923552448
age URI
26 4033985797457567386
26 LIT
http://www.w3.org/2001/XMLSchema#decimal
1
Sue 8947116472173989398
Sue URI
1-152
Chapter 1
Using the SEM_APIS.GET_SQL Function and SEM_SQL SQL Macro to Query Semantic Data
email 6480734238761529200
email URI
[email protected] 5229415107273694944
[email protected] LIT
1
Sue 8947116472173989398
Sue URI
http://www.w3.org/1999/02/22-r 834132227519661324
df-syntax-ns#type
http://www.w3.org/1999/02/22-r type URI
df-syntax-ns#
OracleHQEmployee 9022701012979055032
OracleHQEmployee URI
1
Sue 8947116472173989398
Sue URI
mbox 5760688889368728142
mbox URI
[email protected] 31820890332196705
[email protected] LIT
1
Sue 8947116472173989398
Sue URI
nick 4608123542649301902
nick URI
Su 4914588660956121377
Su LIT
1
Sue 8947116472173989398
Sue URI
teleCommFrom 493206824495339087
teleCommFrom URI
teleCommLoc2 1084777556269608129
teleCommLoc2 URI
1
email 6480734238761529200
email URI
http://www.w3.org/2002/07/owl# 1982040897380465245
equivalentProperty
http://www.w3.org/2002/07/owl# equivalentProperty URI
mbox 5760688889368728142
mbox URI
1
teleCommLoc1 4570292005318753230
teleCommLoc1 URI
city 3506365445274213635
city URI
NYC 6275600577248419523
NYC URI
1
teleCommLoc1 4570292005318753230
teleCommLoc1 URI
state 4843125665925023053
state URI
NY 917887745150543696
1-153
Chapter 1
Loading and Exporting Semantic Data
NY URI
1
teleCommLoc1 4570292005318753230
teleCommLoc1 URI
zip 627678011281517369
zip URI
10101 9180109679895673868
10101 LIT
1
teleCommLoc2 1084777556269608129
teleCommLoc2 URI
state 4843125665925023053
state URI
NH 3642103339971966862
NH URI
1
teleCommLoc2 1084777556269608129
teleCommLoc2 URI
zip 627678011281517369
zip URI
03060 2914451030353375942
03060 LIT
1
26 rows selected.
1-154
Chapter 1
Loading and Exporting Semantic Data
Note:
Unicode data in the staging table should be escaped as specified in WC3 N-Triples
format (http://www.w3.org/TR/rdf-testcases/#ntriples). You can use the
SEM_APIS.ESCAPE_RDF_TERM function to escape Unicode values in the staging
table. For example:
To export semantic data, that is, to retrieve semantic data from Oracle Database where the
results are in N-Triple or N-Quad format that can be stored in a staging table, use the SQL
queries described in Exporting Semantic Data.
Note:
Effective with Oracle Database Release 12.1, you can export and import a semantic
network using the full database export and import features of the Oracle Data Pump
utility, as explained in Exporting or Importing a Semantic Network Using Oracle
Data Pump.
1-155
Chapter 1
Loading and Exporting Semantic Data
The following example shows the format for the staging table, including all required
columns and the required names for these columns, plus the optional
RDF$STC_graph column which must be included if one or more of the RDF triples to
be loaded include a graph name:
CREATE TABLE stage_table (
RDF$STC_sub varchar2(4000) not null,
RDF$STC_pred varchar2(4000) not null,
RDF$STC_obj varchar2(4000) not null,
RDF$STC_graph varchar2(4000)
);
If you also want to load non-semantic data, specify additional columns for the non-
semantic data in the CREATE TABLE statement. The non-semantic column names
must be different from the names of the required columns. The following example
creates the staging table with two additional columns (SOURCE and ID) for non-
semantic attributes.
CREATE TABLE stage_table_with_extra_cols (
source VARCHAR2(4000),
id NUMBER,
RDF$STC_sub varchar2(4000) not null,
RDF$STC_pred varchar2(4000) not null,
RDF$STC_obj varchar2(4000) not null,
RDF$STC_graph varchar2(4000)
);
Note:
For either form of the CREATE TABLE statement, you may want to add the
COMPRESS clause to use table compression, which will reduce the disk
space requirements and may improve bulk-load performance.
Both the invoker and the network owner user must have the following privileges:
SELECT privilege on the staging table, and INSERT privilege on the application table.
See also the following:
• Loading the Staging Table
• Recording Event Traces During Bulk Loading
1.9.1.1.1 Loading N-Triple Format Data into a Staging Table Using SQL*Loader
You can use the SQL*Loader utility to parse and load semantic data into a staging
table. If you installed the demo files from the Oracle Database Examples media (see
Oracle Database Examples Installation Guide), a sample control file is available
1-156
Chapter 1
Loading and Exporting Semantic Data
1.9.1.1.2 Loading N-Quad Format Data into a Staging Table Using an External Table
You can use an Oracle external table to load N-Quad format data (extended triple having four
components) into a staging table, as follows:
1. Call the SEM_APIS.CREATE_SOURCE_EXTERNAL_TABLE procedure to create an
external table, and then use the SQL STATEMENT ALTER TABLE to alter the external
table to include the relevant input file name or names. You must have READ and WRITE
privileges for the directory object associated with folder containing the input file or files.
2. After you create the external table, grant the MDSYS user SELECT and INSERT
privileges on the table.
3. Call the SEM_APIS.LOAD_INTO_STAGING_TABLE procedure to populate the staging
table.
4. After the loading is finished, issue a COMMIT statement to complete the transaction.
Example 1-102 Using an External Table to Load a Staging Table
-- Create a source external table (note: table names are case sensitive)
BEGIN
sem_apis.create_source_external_table(
source_table => 'stage_table_source'
,def_directory => 'DATA_DIR'
,bad_file => 'CLOBrows.bad'
);
END;
/
grant SELECT on "stage_table_source" to MDSYS;
-- Load the staging table (note: table names are case sensitive)
BEGIN
sem_apis.load_into_staging_table(
staging_table => 'STAGE_TABLE'
,source_table => 'stage_table_source'
,input_format => 'N-QUAD');
END;
/
Rows where the objects and graph URIs (combined) are longer than 4000 bytes will be
rejected and stored in a "bad" file. However, you can load these rejected rows by inserting
them into the application table using SQL INSERT statements (see Loading Semantic Data
Using INSERT Statements).
Example 1-102 shows the use of an external table to load a staging table.
1-157
Chapter 1
Loading and Exporting Semantic Data
Note:
If URIs are not encoded with < > and literals with " ", statements will still be
processed. However, the statements will take longer to load, since they will
have to be further processed to determine their VALUE_TYPE values.
1-158
Chapter 1
Loading and Exporting Semantic Data
MODEL_GRAPH
--------------------------------------------------------------------------------
SUB
--------------------------------------------------------------------------------
PRED
--------------------------------------------------------------------------------
OBJ
--------------------------------------------------------------------------------
ARTICLES
<http://nature.example.com/Article1>
<http://purl.org/dc/elements/1.1/title>
"All about XYZ"
ARTICLES
<http://nature.example.com/Article1>
1-159
Chapter 1
Loading and Exporting Semantic Data
<http://purl.org/dc/elements/1.1/creator>
"Jane Smith"
ARTICLES
<http://nature.example.com/Article1>
<http://purl.org/dc/terms/references>
<http://nature.example.com/Article2>
ARTICLES
<http://nature.example.com/Article1>
<http://purl.org/dc/terms/references>
<http://nature.example.com/Article3>
ARTICLES
<http://nature.example.com/Article2>
<http://purl.org/dc/elements/1.1/title>
"A review of ABC"
ARTICLES
<http://nature.example.com/Article2>
<http://purl.org/dc/elements/1.1/creator>
"Joe Bloggs"
ARTICLES
<http://nature.example.com/Article2>
<http://purl.org/dc/terms/references>
<http://nature.example.com/Article3>
7 rows selected.
GRAPH
------------------------------------------------------------
SUB
------------------------------------------------------------
PRED
------------------------------------------------------------
OBJ
---------------------------------------------------------------------------
1-160
Chapter 1
Loading and Exporting Semantic Data
<http://examples.com/ns#Graph1>
_:m99g3C687474703A2F2F6578616D706C65732E636F6D2F6E73234772617068313Egmb2
<http://purl.org/dc/elements/1.1/creator>
_:m99g3C687474703A2F2F6578616D706C65732E636F6D2F6E73234772617068313Egmb1
<http://examples.com/ns#Graph1>
<http://nature.example.com/Article102>
<http://purl.org/dc/elements/1.1/creator>
_:m99g3C687474703A2F2F6578616D706C65732E636F6D2F6E73234772617068313Egmb1
<http://examples.com/ns#Graph1>
<http://nature.example.com/Article101>
<http://purl.org/dc/elements/1.1/creator>
"John Smith"
<http://nature.example.com/Article1>
<http://purl.org/dc/elements/1.1/creator>
"Jane Smith"
1.9.3.3 Removing Model and Graph Information from Retrieved Blank Node
Identifiers
Blank node identifiers retrieved during the retrieval of semantic data can be trimmed to
remove the occurrence of model and graph information using the transformations shown in
the code excerpt in Example 1-105, which are applicable to VARCHAR2 (for example, subject
component) and CLOB (for example, object component) data, respectively.
Example 1-106 shows the results obtained after using these two transformations in
Example 1-105 on the sub and obj columns, respectively, using the semantic data retrieval
query described in Retrieving Semantic Data from an RDF Model.
Example 1-105 Retrieving Semantic Data from an Application Table
--
-- Transformation on column "sub VARCHAR2"
-- holding blank node identifier values
--
Select (case substr(sub,1,2) when '_:' then '_:' || substr(sub,instr(sub,'m',1,2)+1)
else sub end) from …
--
-- Transformation on column "obj CLOB"
-- holding blank node identifier values
--
Select (case dbms_lob.substr(obj,2,1) when '_:' then to_clob('_:' ||
substr(obj,instr(obj,'m',1,2)+1)) else obj end) from …
1-161
Chapter 1
Loading and Exporting Semantic Data
SUB
------------------------------------------------------------
PRED
------------------------------------------------------------
OBJ
---------------------------------------------------------------------------
_:b2
<http://purl.org/dc/elements/1.1/creator>
_:b1
<http://nature.example.com/Article102>
<http://purl.org/dc/elements/1.1/creator>
_:b1
The following usage notes apply to using Data Pump to export or import a semantic
network:
• The target database for an import must have the RDF Semantic Graph software
installed, and there cannot be a pre-existing semantic network.
• Semantic networks using fine-grained access control (triple-level or resource-level
OLS or VPD) cannot be exported or imported.
• Semantic document indexes for SEM_CONTAINS (MDSYS.SEMCONTEXT index
type) and semantic indexes for SEM_RELATED (MDSYS.SEM_INDEXTYPE
index type) must be dropped before an export and re-created after an import.
• Only default privileges for semantic network objects (those that exist just after
object creation) are preserved during export and import. For example, if user A
creates semantic model M and grants SELECT on RDFM_M to user B, only user
A's SELECT privilege on RDFM_M will be present after the import. User B will not
have SELECT privilege on RDFM_M after the import. Instead, user B's SELECT
privilege will have to be granted again.
• The Data Pump command line option transform=oid:n must be used when
exporting or importing semantic network data. For example, use a command in the
following format:
impdp system/<password-for-system> directory=dpump_dir dumpfile=rdf.dmp
full=YES version=12 transform=oid:n
For Data Pump usage information and examples, see the relevant chapters in Part I of
Oracle Database Utilities.
1-162
Chapter 1
Loading and Exporting Semantic Data
The contents of a semantic network can be moved to a staging schema. A semantic network
in a staging schema can then be (1) exported with Oracle Data Pump or a similar tool, (2)
appended to a different semantic network, or (3) restored back into the source semantic
network. Move, restore and append operations mostly use partition exchange to move data
rather than SQL inserts to copy data. Consequently, these operations are very efficient.
The procedures to move, restore, and append semantic network data are:
• SEM_APIS.MOVE_SEM_NETWORK_DATA
• SEM_APIS.RESTORE_SEM_NETWORK_DATA
• SEM_APIS.APPEND_SEM_NETWORK_DATA
1-163
Chapter 1
Loading and Exporting Semantic Data
2. Creates a database user (RDFEXPIMPU) that will hold the output of the export of
the semantic network.
3. Moves the semantic network data to the RDFEXPIMPU schema.
4. Uses Data Pump to export the moved semantic network data.
5. Uses Data Pump to export any user application tables referenced by models in the
semantic network.
6. Optionally, restores the semantic network data in the current network. (This allows
you to continue using the MDSYS-owned semantic network in the current
database.)
1-164
Chapter 1
Loading and Exporting Semantic Data
conn sys/<password_for_sys>
conn system/<password_for_system>
1-165
Chapter 1
Loading and Exporting Semantic Data
conn sys/<password_for_sys>
conn system/<password_for_system>
conn system/<password_for_system>
1-166
Chapter 1
Using Semantic Network Indexes
conn rdfadmin/<password>
-- enable sharing for rdfadmin’s network
exec
sem_apis.enable_network_sharing(network_owner=>'RDFADMIN',network_name=>'MYNE
T');
1-167
Chapter 1
Using Semantic Network Indexes
• If your graph pattern is '{?x <talksTo> ?y . ?z ?p ?y}', you may want to have
a usable semantic network index on the relevant model or models and entailment,
with C as the leading key (for example, 'CPSGM').
However, using semantic network indexes can affect overall performance by
increasing the time required for DML, load, and inference operations.
You can create and manage semantic network indexes using the following
subprograms:
• SEM_APIS.ADD_SEM_INDEX
• SEM_APIS.ALTER_SEM_INDEX_ON_MODEL
• SEM_APIS.ALTER_SEM_INDEX_ON_ENTAILMENT
• SEM_APIS.DROP_SEM_INDEX
All of these subprograms have an index_code parameter, which can contain any
sequence of the following letters (without repetition): P, C, S, G, M. These letters used in
the index_code correspond to the following columns in the SEMM_* and SEMI_*
views: P_VALUE_ID, CANON_END_NODE_ID, START_NODE_ID, G_ID, and
MODEL_ID.
The SEM_APIS.ADD_SEM_INDEX procedure creates a semantic network index that
results in creation of a nonunique B-tree index in UNUSABLE status for each of the
existing models and entailments. The name of the index is
RDF_LNK_<index_code>_IDX and the index is owned by the network owner. This
operation is allowed only if the invoker has DBA role or is the network owner. The
following example shows creation of the PSCGM index with the following key:
<P_VALUE_ID, START_NODE_ID, CANON_END_NODE_ID, G_ID, MODEL_ID>.
EXECUTE SEM_APIS.ADD_SEM_INDEX('PSCGM' network_owner=>'RDFUSER',
network_name=>'NET1');
After you create a semantic network index, each of the corresponding nonunique B-
tree indexes is in the UNUSABLE status, because making it usable can cause
significant time and resources to be used, and because subsequent index
maintenance operations might involve performance costs that you do not want to incur.
You can make a semantic network index usable or unusable for specific models or
entailments that you own by calling the SEM_APIS.ALTER_SEM_INDEX_ON_MODEL
and SEM_APIS.ALTER_SEM_INDEX_ON_ENTAILMENT procedures and specifying
'REBUILD' or 'UNUSABLE' as the command parameter. Thus, you can experiment by
making different semantic network indexes usable and unusable, and checking for any
differences in performance. For example, the following statement makes the PSCGM
index usable for the FAMILY model:
EXECUTE SEM_APIS.ALTER_SEM_INDEX_ON_MODEL('FAMILY','PSCGM','REBUILD'
network_owner=>'RDFUSER', network_name=>'NET1');
1-168
Chapter 1
Using Data Type Indexes
• Including the MODEL_ID column in a semantic network index key (by including 'M' in the
index_code value) may improve query performance. This is particularly relevant when
virtual models are used.
• SEM_NETWORK_INDEX_INFO View
1-169
Chapter 1
Using Data Type Indexes
The suitability of data type indexes depends on your query workload. Data type
indexes on xsd data types can be used for filters that compare a variable with a
constant value, and are particularly useful when queries have an unselective graph
pattern with a very selective filter condition. Appropriate data type indexes are required
for queries with spatial or text filters.
While data type indexes improve query performance, overhead from incremental index
maintenance can degrade the performance of DML and bulk load operations on the
semantic network. For bulk load operations, it may often be faster to drop data type
indexes, perform the bulk load, and then re-create the data type indexes.
You can add, alter, and drop data type indexes using the following procedures, which
are described in SEM_APIS Package Subprograms:
• SEM_APIS.ADD_DATATYPE_INDEX
• SEM_APIS.ALTER_DATATYPE_INDEX
• SEM_APIS.DROP_DATATYPE_INDEX
1-170
Chapter 1
Managing Statistics for Semantic Models and the Semantic Network
You can use the HINT0 hint to ensure that data type indexes are used during query
evaluation, as shown in Example 1-110, which finds all grandfathers who were born before
November 16, 1929.
Example 1-110 Using HINT0 to Ensure Use of Data Type Index
SELECT x, y
FROM TABLE(SEM_MATCH(
'PREFIX : <http://www.example.org/family/>
SELECT ?x ?y
WHERE {?x :grandParentOf ?y . ?x rdf:type :Male . ?x :birthDate ?bd
FILTER (?bd <= "1929-11-15T23:59:59Z"^^xsd:dateTime) }',
SEM_Models('family'),
SEM_Rulebases('RDFS','family_rb'),
1-171
Chapter 1
Managing Statistics for Semantic Models and the Semantic Network
• SEM_APIS.EXPORT_MODEL_STATS
• SEM_APIS.IMPORT_ENTAILMENT_STATS
• SEM_APIS.IMPORT_MODEL_STATS
• SEM_APIS.SET_ENTAILMENT_STATS
• SEM_APIS.SET_MODEL_STATS
• SEM_PERF.DELETE_NETWORK_STATS
• SEM_PERF.DROP_EXTENDED_STATS
• SEM_PERF.EXPORT_NETWORK_STATS
• SEM_PERF.IMPORT_NETWORK_STATS
This section contains the following topics related to managing statistics for semantic
models and the semantic network.
• Saving Statistics at a Model Level
• Restoring Statistics at a Model Level
• Saving Statistics at the Network Level
• Dropping Extended Statistics at the Network Level
• Restoring Statistics at the Network Level
• Setting Statistics at a Model Level
• Deleting Statistics at a Model Level
You can also save the statistics of an entailment (entailed graph) by using
SEM_APIS.EXPORT_ENTAILMENT_STATS .
execute
sem_apis.create_entailment('test_inf',sem_models('test'),sem_rulebases('owl2rl'),
0,null,network_owner=>'RDFUSER',network_name=>'NET1');
PL/SQL procedure successfully completed.
execute sem_apis.export_entailment_stats('TEST_INF','rdf_stat_tab',
'inf_stat_saved_on_AUG_10', true, 'SCOTT', 'OBJECT_STATS',
network_owner=>'RDFUSER', network_name=>'NET1');
1-172
Chapter 1
Managing Statistics for Semantic Models and the Semantic Network
You can also restore the statistics of an entailment (entailed graph) by using
SEM_APIS.IMPORT_ENTAILMENT_STATS .
execute sem_apis.import_entailment_stats('TEST','rdf_stat_tab',
'inf_stat_saved_on_AUG_10', true, 'SCOTT', false, true, 'OBJECT_STATS',
network_owner=>'RDFUSER', network_name=>'NET1');
conn RDFUSER/<password>
execute dbms_stats.create_stat_table('RDFUSER','rdf_stat_tab');
-- The next grant is only necessary if using the MDSYS semantic network
grant select, insert, delete, update on RDFUSER.rdf_stat_tab to MDSYS;
--
-- This API call will save the statistics of both the RDF_VALUE$ table
-- and RDF_LINK$ table
--
execute sem_perf.export_network_stats('rdf_stat_tab', 'NETWORK_ALL_saved_on_Aug_10',
true, 'RDFUSER', 'OBJECT_STATS', network_owner=>'RDFUSER', network_name=>'NET1');
--
-- Alternatively, you can save statistics of only the RDF_VALUE$ table
--
execute sem_perf.export_network_stats('rdf_stat_tab',
'NETWORK_VALUE_TAB_saved_on_Aug_10', true, 'RDFUSER', 'OBJECT_STATS', options=>
mdsys.sdo_rdf.VALUE_TAB_ONLY, network_owner=>'RDFUSER', network_name=>'NET1');
--
-- Or, you can save statistics of only the RDF_LINK$ table
--
execute sem_perf.export_network_stats('rdf_stat_tab',
'NETWORK_LINK_TAB_saved_on_Aug_10', true, 'RDFUSER', 'OBJECT_STATS', options=>
mdsys.sdo_rdf.LINK_TAB_ONLY, network_owner=>'RDFUSER', network_name=>'NET1');
1-173
Chapter 1
Managing Statistics for Semantic Models and the Semantic Network
See also the information about managing extended statistics in Oracle Database SQL
Tuning Guide.
execute sem_perf.import_network_stats('rdf_stat_tab',
'NETWORK_ALL_saved_on_Aug_10', true, 'RDFUSER', false, true, 'OBJECT_STATS',
network_owner=>'RDFUSER', network_name=>'NET1');
You can also set the statistics for the entailment by using
SEM_APIS.SET_ENTAILMENT_STATS .
execute sem_apis.set_entailment_stats('TEST_INF', numrows=>10,
numblks=>1,no_invalidate=>false,network_owner=>'RDFUSER',network_name=>'NET1');
You can also remove the statistics for the entailment by using
SEM_APIS.DELETE_ENTAILMENT_STATS. (However, before you remove statistics
of a model or an entailment, you should save the statistics first so that they can be
restored if necessary.)
execute sem_apis.delete_entailment_stats('TEST_INF', no_invalidate=> false,
network_owner=>'RDFUSER', network_name=>'NET1');
1-174
Chapter 1
Support for SPARQL Update Operations on a Semantic Model
1-175
Chapter 1
Support for SPARQL Update Operations on a Semantic Model
1-176
Chapter 1
Support for SPARQL Update Operations on a Semantic Model
:price 150;
:cameraType :Camera .
-- Update operation:
BEGIN
sem_apis.update_model('electronics',
'PREFIX : <http://www.example.org/electronics/>
DELETE { :camera1 :cameraType ?type . }
INSERT { :camera1 :cameraType :digitalCamera . }
WHERE { :camera1 :cameraType ?type . }',
network_owner=>'RDFUSER', network_name=>'NET1');
END;
/
Example 1-114 DELETE/INSERT Operation Involving Default Graph and Named Graph
Graphs can also be specified inside the DELETE and INSERT templates, as well as inside
the WHERE clause. This example moves all triples corresponding to digital cameras from the
default graph to the graph :digitalCameras.
-- Update operation:
BEGIN
sem_apis.update_model('electronics',
'PREFIX : <http://www.example.org/electronics/>
DELETE { ?s ?p ?o }
INSERT { graph :digitalCameras { ?s ?p ?o } }
WHERE { ?s :cameraType :digitalCamera .
?s ?p ?o }',
network_owner=>'RDFUSER', network_name=>'NET1');
END;
/
1-177
Chapter 1
Support for SPARQL Update Operations on a Semantic Model
:price 150;
:cameraType :Camera .
#Graph :digitalCameras
GRAPH :digitalCameras {
:camera1 :name "Camera 1";
:cameraType :digitalCamera .
}
-- INSERT WHERE
-- Dataset before operation:
@prefix : <http://www.example.org/electronics/>
#Default graph
:camera2 :name "Camera 2";
:price 150;
:cameraType :Camera .
#Graph :digitalCameras
GRAPH :digitalCameras {
:camera1 :name "Camera 1";
:cameraType :digitalCamera .
}
#Empty graph :cameras
-- Update operation:
BEGIN
sem_apis.update_model('electronics',
'PREFIX : <http://www.example.org/electronics/>
INSERT { graph :cameras { ?s ?p ?o } }
WHERE { graph :digitalCameras { ?s ?p ?o } }',
network_owner=>'RDFUSER', network_name=>'NET1');
END;
/
1-178
Chapter 1
Support for SPARQL Update Operations on a Semantic Model
-- DELETE WHERE
-- Dataset before operation:
@prefix : <http://www.example.org/electronics/>
#Default graph
:camera2 :name "Camera 2";
:price 150;
:cameraType :Camera .
#Graph :digitalCameras
GRAPH :digitalCameras {
:camera1 :name "Camera 1";
:cameraType :digitalCamera .
}
#Graph :cameras
GRAPH :cameras {
:camera1 :name "Camera 1";
:cameraType :digitalCamera .
}
-- Update operation:
BEGIN
sem_apis.update_model('electronics',
'PREFIX : <http://www.example.org/electronics/>
DELETE WHERE { graph :cameras { ?s ?p ?o } }',
network_owner=>'RDFUSER', network_name=>'NET1');
END;
/
1-179
Chapter 1
Support for SPARQL Update Operations on a Semantic Model
#Graph :digitalCameras
GRAPH :digitalCameras {
:camera1 :name "Camera 1";
:cameraType :digitalCamera .
}
#Graph :cameras
GRAPH :cameras {
:camera3 :name "Camera 3" .
}
-- Update operation:
BEGIN
sem_apis.update_model('electronics',
'PREFIX : <http://www.example.org/electronics/>
COPY DEFAULT TO GRAPH :cameras',
network_owner=>'RDFUSER', network_name=>'NET1');
END;
/
1-180
Chapter 1
Support for SPARQL Update Operations on a Semantic Model
:price 150;
:cameraType :Camera .
}
-- Update operation:
BEGIN
sem_apis.update_model('electronics',
'PREFIX : <http://www.example.org/electronics/>
ADD GRAPH :digitalCameras TO GRAPH :cameras',
network_owner=>'RDFUSER', network_name=>'NET1');
END;
/
1-181
Chapter 1
Support for SPARQL Update Operations on a Semantic Model
}
#Graph :digCam
GRAPH :digCam {
:camera4 :cameraType :digCamera .
}
-- Update operation:
BEGIN
sem_apis.update_model('electronics',
'PREFIX : <http://www.example.org/electronics/>
MOVE GRAPH :digitalCameras TO GRAPH :digCam',
network_owner=>'RDFUSER', network_name=>'NET1');
END;
/
1-182
Chapter 1
Support for SPARQL Update Operations on a Semantic Model
:price 150;
:cameraType :Camera .
}
#Graph :digCam
GRAPH :digCam {
:camera1 :name "Camera 1";
:cameraType :digitalCamera .
}
-- Update operation:
BEGIN
sem_apis.update_model('electronics',
'CLEAR DEFAULT ',
network_owner=>'RDFUSER', network_name=>'NET1');
END;
/
-- Datafile: /home/oracle/example.nq
<http://www.example.org/electronics/camera3> <http://www.example.org/
electronics/name> "Camera 3" <http://www.example.org/electronics/myGraph> .
<http://www.example.org/electronics/camera3> <http://www.example.org/
electronics/price> "125"^^<http://www.w3.org/2001/XMLSchema#decimal> .
1-183
Chapter 1
Support for SPARQL Update Operations on a Semantic Model
-- Update operation:
CREATE OR REPLACE DIRECTORY MY_DIR AS '/home/oracle';
BEGIN
sem_apis.update_model('electronics',
'PREFIX : <http://www.example.org/electronics/>
LOAD <file:///example.nq> INTO GRAPH :cameras',
options=>'LOAD_DIR={MY_DIR}',
network_owner=>'RDFUSER', network_name=>'NET1');
END;
END;
/
Several files under the same directory can be loaded in parallel with a single LOAD
operation. To specify extra N-Triple or N-Quad files to be loaded, you can use the
LOAD_OPTIONS hint. The degree of parallelism for the load can be specified with
PARALLEL(n) in the options string.. The following example shows how to load the
files /home/oracle/example1.nq, /home/oracle/example2.nq, and /home/oracle/
1-184
Chapter 1
Support for SPARQL Update Operations on a Semantic Model
example3.nq into a semantic model. A degree of parallelism of 3 is used for this example.
BEGIN
sem_apis.update_model('electronics',
'PREFIX : <http://www.example.org/electronics/>
LOAD <file:///example1.nq>',
options=> ' PARALLEL(3) LOAD_OPTIONS={ example2.nq example3.nq }
LOAD_DIR={MY_DIR} ',
network_owner=>'RDFUSER', network_name=>'NET1' );
END;
/
Related subtopics:
• Tuning the Performance of SPARQL Update Operations
• Transaction Management with SPARQL Update Operations
• Support for Bulk Operations
• Setting UPDATE_MODEL Options at the Session Level
• Load Operations: Special Considerations for SPARQL Update
• Long Literals: Special Considerations for SPARQL Update
• Blank Nodes: Special Considerations for SPARQL Update
1-185
Chapter 1
Support for SPARQL Update Operations on a Semantic Model
the example uses ALLOW_DUP=T as a match option when matching against the
virtual model VM1.
BEGIN
sem_apis.update_model(
'electronics',
'PREFIX : <http://www.example.org/electronics/>
INSERT { graph :digitalCameras { ?s ?p ?o } }
WHERE { ?s :cameraType :digitalCamera .
?s ?p ?o }',
match_models=>sem_models('VM1'),
match_models=>sem_models('VM1'),
match_options=>' ALLOW_DUP=T ',
options=>' PARALLEL(4) DYNAMIC_SAMPLING(6) ',
network_owner=>'RDFUSER', network_name=>'NET1');
END;
/
• Inline Query Optimizer Hints can be specified in the WHERE clause. The following
example extends the preceding example by using the HINT0 hint in the WHERE
clause and the FINAL_VALUE_NL hint in the match_options parameter.
BEGIN
sem_apis.update_model(
'electronics',
'PREFIX : <http://www.example.org/electronics/>
INSERT { graph :digitalCameras { ?s ?p ?o } }
WHERE { # HINT0={ LEADING(t0 t1) USE_NL(t0 t1)
?s :cameraType :digitalCamera .
?s ?p ?o }',
match_models=>sem_models('VM1'),
match_options=>' ALLOW_DUP=T FINAL_VALUE_NL ',
options=>' PARALLEL(4) DYNAMIC_SAMPLING(6) ',
network_owner=>'RDFUSER', network_name=>'NET1');
END;
/
BEGIN
sem_apis.update_model('electronics',
'PREFIX elec: <http://www.example.org/electronics/>
PREFIX ecom: <http://www.example.org/ecommerce/>
# insert camera data
INSERT DATA {
elec:camera1 elec:name "Camera 1" .
1-186
Chapter 1
Support for SPARQL Update Operations on a Semantic Model
BEGIN
sem_apis.update_model('electronics',
'PREFIX elec: <http://www.example.org/electronics/>
PREFIX ecom: <http://www.example.org/ecommerce/>
# insert camera data
INSERT DATA {
elec:camera1 elec:name "Camera 1" .
elec:camera1 elec:price 120 .
elec:camera1 elec:cameraType elec:DigitalCamera .
elec:camera2 elec:name "Camera 2" .
elec:camera2 elec:price 150 .
elec:camera2 elec:cameraType elec:DigitalCamera . }',
network_owner=>'RDFUSER', network_name=>'NET1');
END;
BEGIN
sem_apis.update_model('electronics',
'PREFIX elec: <http://www.example.org/electronics/>
PREFIX ecom: <http://www.example.org/ecommerce/>
# insert ecom:price triples
INSERT { ?c ecom:price ?p }
WHERE { ?c elec:price ?p }',
network_owner=>'RDFUSER', network_name=>'NET1');
END;
/
BEGIN
sem_apis.update_model('electronics',
'PREFIX elec: <http://www.example.org/electronics/>
PREFIX ecom: <http://www.example.org/ecommerce/>
# insert elec:price triples
1-187
Chapter 1
Support for SPARQL Update Operations on a Semantic Model
The AUTOCOMMIT=F option can be used to prevent separate transactions for each
SEM_APIS.UPDATE_MODEL call. With this option, transaction management is the
responsibility of the caller. The following example shows how to execute the update
operations in the preceding example as a single transaction instead of three separate
ones.
BEGIN
sem_apis.update_model('electronics',
'PREFIX elec: <http://www.example.org/electronics/>
PREFIX ecom: <http://www.example.org/ecommerce/>
# insert camera data
INSERT DATA {
elec:camera1 elec:name "Camera 1" .
elec:camera1 elec:price 120 .
elec:camera1 elec:cameraType elec:DigitalCamera .
elec:camera2 elec:name "Camera 2" .
elec:camera2 elec:price 150 .
elec:camera2 elec:cameraType elec:DigitalCamera . }',
options=>' AUTOCOMMIT=F ',
network_owner=>'RDFUSER', network_name=>'NET1');
END;
/
BEGIN
sem_apis.update_model('electronics',
'PREFIX elec: <http://www.example.org/electronics/>
PREFIX ecom: <http://www.example.org/ecommerce/>
# insert ecom:price triples
INSERT { ?c ecom:price ?p }
WHERE { ?c elec:price ?p }',
options=>' AUTOCOMMIT=F ',
network_owner=>'RDFUSER', network_name=>'NET1');
END;
/
BEGIN
sem_apis.update_model('electronics',
'PREFIX elec: <http://www.example.org/electronics/>
PREFIX ecom: <http://www.example.org/ecommerce/>
# insert elec:price triples
DELETE WHERE { ?c elec:price ?p }',
options=>' AUTOCOMMIT=F ',
network_owner=>'RDFUSER', network_name=>'NET1');
1-188
Chapter 1
Support for SPARQL Update Operations on a Semantic Model
END;
/
COMMIT;
Commit complete.
1-189
Chapter 1
Support for SPARQL Update Operations on a Semantic Model
BEGIN
sem_apis.update_model('electronics',
'PREFIX : <http://www.example.org/electronics/>
DELETE { ?s ?p ?o }
INSERT { graph :digitalCameras { ?s ?p ?o } }
WHERE { ?s :cameraType :digitalCamera .
?s ?p ?o }',
options=>' STREAMING=F ',
network_owner=>'RDFUSER', network_name=>'NET1');
END;
/
1-190
Chapter 1
Support for SPARQL Update Operations on a Semantic Model
BEGIN
sem_apis.update_model('electronics',
'PREFIX elec: <http://www.example.org/electronics/>
PREFIX ecom: <http://www.example.org/ecommerce/>
INSERT { ?c ecom:price ?p }
WHERE { ?c elec:price ?p }',
options=>' FORCE_BULK=T BULK_OPTIONS={ parallel=4
parallel_create_index }',
network_owner=>'RDFUSER', network_name=>'NET1');
END;
/
BEGIN
sem_apis.update_model('electronics',
'CLEAR NAMED',
options=>' DEL_AS_INS=T MM_OPTIONS={ dop=4 } ',
network_owner=>'RDFUSER', network_name=>'NET1');
END;
/
1-191
Chapter 1
Support for SPARQL Update Operations on a Semantic Model
begin
mdsys.sdo_sem_update_ctx.set_param('autocommit','false');
end;
/
Load operations for RDF documents that contain object values longer than 4000 bytes
may require additional operations. Load operations on Turtle and Trig documents will
automatically load all triples/quads regardless of object value size. However, load
operations on N-Triple and N-Quad documents will only load triples/quads with object
values that are less than 4000 bytes in length. For N-Triple and N-Quad data, a
1-192
Chapter 1
Support for SPARQL Update Operations on a Semantic Model
second load operation should be issued with the LOAD_CLOB_ONLY=T option to also load
triples/quads with object values larger than 4000 bytes.
Loads from Unix named pipes are only supported for N-Triple and N-Quad formats. Turtle
and Trig files should be uncompressed, physical files.
Unicode characters are handled differently depending on the format of the RDF file to load.
Unicode characters in N-Triple and N-Quad files should be escaped as
\u<HEX><HEX><HEX><HEX> or \U<HEX><HEX><HEX><HEX><HEX><HEX><HEX><HEX> using the hex
value of the Unicode codepoint value. Turtle and Trig files do not require Unicode escaping
and can be directly loaded with unescaped Unicode values.
Example 1-121 Short and Long Literal Load for N-Quad Data
BEGIN
-- short literal load
sem_apis.update_model('electronics',
'PREFIX : <http://www.example.org/electronics/>
LOAD <file:///example1.nq>',
options=> ' LOAD_DIR={MY_DIR} ',
network_owner=>'RDFUSER', network_name=>'NET1');
1-193
Chapter 1
Support for SPARQL Update Operations on a Semantic Model
prefixes ensure that blank node identifiers are unique across models and graphs. An
ID-only approach for ADD, COPY, and UPDATE operations does not update blank
node prefixes.
Example 1-122 ID-Only Update Causing Incorrect Blank Node Values
The update in the following example leads to the same blank node subject for both
triples in graphs :cameras and :cameras2. This can be verified running the provided
SEM_MATCH query.
BEGIN
sem_apis.update_model('electronics',
'PREFIX : <http://www.example.org/electronics/>
INSERT DATA {
GRAPH :cameras { :camera2 :owner _:bn1 .
_:bn1 :name "Axel" }
};
COPY :cameras TO :cameras2',
options=>' STRICT_BNODE=F ',
network_owner=>'RDFUSER', network_name=>'NET1');
END;
/
SELECT count(s)
FROM TABLE( SEM_MATCH('
PREFIX : <http://www.example.org/electronics/>
SELECT *
WHERE { { graph :cameras {?s :name "Axel" } }
{ graph :cameras2 {?s :name "Axel" } } }
', sem_models('electronics'),null,null,null,null,' STRICT_DEFAULT=T ',
null, null, 'RDFUSER', 'NET1'));
To avoid such errors, you should specify the STRICT_BNODE=F hint in the options
parameter for the SEM_APIS.UPDATE_MODEL procedure only when you are sure
that blank nodes are not involved in the ADD, COPY, or MOVE update operation.
However, ADD, COPY, and MOVE operations on large graphs with the
STRICT_BNODE=F option may run significantly faster than they would run using the
default method. If you need to run a series of ID-only updates, another option is to use
the STRICT_BNODE=F option, and then execute the SEM_APIS.CLEANUP_BNODES
procedure at the end. This approach resets the prefix of all blank nodes in a given
model, which effectively corrects ("cleans up") all erroneous blank node labels.
Note that this two-step strategy should not be used with a small number of ADD,
COPY, or MOVE operations. Performing a few operations using the default approach
will execute faster than running a few ID-only operations and then executing the
SEM_APIS.CLEANUP_BNODES procedure.
The following example corrects blank nodes in a semantic model named electronics.
EXECUTE sem_apis.cleanup_bnodes('electronics');
1-194
Chapter 1
RDF Support for Oracle Database In-Memory
Note:
To use RDF with Oracle Database In-Memory, you must understand how to enable
and configure Oracle Database In-Memory, as explained in Oracle Database In-
Memory Guide.
If the POPULATE_STATUS value is DONE, the RDF data has been fully loaded into memory.
To check if RDF data in memory is used, search for ‘TABLE ACCESS INMEMORY FULL’ in the
execution plan:
---------------------------------------------------------------------------------------
-----------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
1-195
Chapter 1
RDF Support for Oracle Database In-Memory
EXECUTE SEM_APIS.CREATE_VIRTUAL_MODEL
('vm2',SEM_MODELS('lubm1k','univbench'),SEM_RULEBASES
('owl2rl'),options=>'PXN=F INMEMORY=T', network_owner=>'RDFUSER',
network_name=>'NET1');
You can check for in-memory virtual models by examining the MDSYS.RDF_MODEL$
view, where the INMEMORY column is set to T for an in-memory virtual model.
The in-memory virtual model removes the need for joins with the RDF_VALUE$ table.
To check the usage of in-memory virtual models, use the same commands in Enabling
Oracle Database In-Memory for RDF.
For best performance, fully populate the in-memory virtual columns before any query
is processed, because unpopulated virtual columns are assembled at run time and this
overhead may impair performance.
1-196
Chapter 1
RDF Support for Materialized Join Views
EXECUTE SEM_APIS.ALTER_SEM_INDEXES('VISIBILITY','N',
network_owner=>'RDFUSER', network_name=>'NET1');
To make the RDF semantic network indexes visible again, use the following
EXECUTE SEM_APIS.ALTER_SEM_INDEXES('VISIBILITY','Y',
network_owner=>'RDFUSER', network_name=>'NET1');
Note:
RDF_VALUE$ indexes must be visible so that Oracle Database can efficiently look
up VALUE_IDs for query constants at compile time.
For an explanation of invisible and unusable indexes, see Oracle Database Administrator's
Guide.
1-197
Chapter 1
RDF Support in Oracle SQL Developer
• Subject ID: S
• Predicate ID: P
• Object ID: O
• Graph name: GV
• Subject name: SV
• Predicate name: PV
• Object name: OV
• value type: $RDFVTYP
• literal type: $RDFLTYP
• language type: $RDFLANG
• order_type: $RDFORDT
• order_num: $RDFORDN
• order_date: $RDFORDD
For example, if a materialized view named MVX is created, the following join views are
created:
SS-join (MVX$SS) and SO-join (MVX$SO)
The same column names for the MVX$SO join view are specified as well.
When a bitmap index is created on a SS-join view, the index is named <MView
name><index column name>_I0$. Similarly, the index is named <MView name><index
column name>_I1$ for SO-join view. For example, if an index is created on a column
T0P in the materialized view MVX, then the index name would be MVXT0P_I0$ for the
SS-join view and MVXT0P_I1$ for the SO-join view.
1-198
Chapter 1
Enhanced RDF ORDER BY Query Processing
EXECUTE sem_apis.add_datatype_index('http://www.w3.org/2001/
XMLSchema#decimal', options=>'FUNCTION=T', network_owner=>'RDFUSER',
network_name=>'NET1');
EXECUTE sem_apis.add_datatype_index('http://www.w3.org/2001/XMLSchema#date',
options=>'FUNCTION=T', network_owner=>'RDFUSER', network_name=>'NET1');
1-199
Chapter 1
Semantic Data Examples (PL/SQL and Java)
….
OPTIONAL { ?subj Pn ?On }
}'
, SEM_MODELS('M1')
,null, null, null, null));
After you have this structure defined, you can directly apply Oracle Machine Learning
algorithms on this view. Oracle Data Mining deals with three types of attributes:
• numerical attribute
• categorical attribute
• unstructured text
You must separate the data into three groups based on the data types of the three
types of attributes.
1-200
Chapter 1
Semantic Data Examples (PL/SQL and Java)
BEGIN
SEM_APIS.UPDATE_MODEL('articles',
'PREFIX nature: <http://nature.example.com/>
PREFIX dc: <http://purl.org/dc/elements/1.1/>
PREFIX dcterms: <http://purl.org/dc/terms/>
INSERT DATA {
1-201
Chapter 1
Semantic Data Examples (PL/SQL and Java)
(Female)
Cindy
Martha
Matt
(Male)
Tom
Janice
John
(Male)
Jack
Suzie
(sisterOf Jack)
Sammy
Cathy
-- Connect as the user that is to perform the RDF operations (not SYSTEM),
-- and do the following:
-- 1. For each desired model, create an application table
-- 2. For each desired model, create a model (SEM_APIS.CREATE_SEM_MODEL).
-- 3. Use various subprograms and constructors.
1-202
Chapter 1
Semantic Data Examples (PL/SQL and Java)
BEGIN
INSERT DATA {
# Person is a class.
family:Person rdf:type rdfs:Class .
# siblingOf is a property.
family:siblingOf rdf:type rdf:Property .
# parentOf is a property.
family:parentOf rdf:type rdf:Property .
# A brother is male.
family:brotherOf rdfs:domain family:Male .
# A sister is female.
family:sisterOf rdfs:domain family:Female .
1-203
Chapter 1
Semantic Data Examples (PL/SQL and Java)
# A father is male.
family:fatherOf rdfs:domain family:Male .
# A mother is female.
family:motherOf rdfs:domain family:Female .
}',
network_owner=>'RDFUSER',
network_name=>'NET1');
INSERT DATA {
# John is the father of Suzie and Matt
family:John family:fatherOf family:Suzie .
family:John family:fatherOf family:Matt .
# Jack is male
family:Jack rdf:type family:Male .
# Tom is male.
family:Tom rdf:type family:Male .
# Cindy is female.
family:Cindy rdf:type family:Female .
}',
network_owner=>'RDFUSER',
network_name=>'NET1');
END;
1-204
Chapter 1
Semantic Data Examples (PL/SQL and Java)
-- Select all males from the family model, with RDFS inferencing.
-- (Returns Jack, Tom, John, Sammy, and Matt.)
SELECT m$rdfterm
FROM TABLE(SEM_MATCH(
'PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX : <http://www.example.org/family/>
SELECT ?m
WHERE {?m rdf:type :Male}',
SEM_Models('family'),
SEM_Rulebases('RDFS'),
null, null, null,
' PLUS_RDFT=VC ',
null, null,
'RDFUSER', 'NET1'));
COMMIT;
-- Because a new rulebase has been created, and it will be used in the
-- entailment, drop the preceding entailment and then re-create it.
1-205
Chapter 1
Software Naming Changes Since Release 11.1
-- Select all grandfathers and their grandchildren from the family model,
-- without inferencing. (With no inferencing, no results are returned.)
SELECT x$rdfterm grandfather, y$rdfterm grandchild
FROM TABLE(SEM_MATCH(
'PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX : <http://www.example.org/family/>
SELECT ?x ?y
WHERE {?x :grandParentOf ?y . ?x rdf:type :Male}',
SEM_Models('family'),
null, null, null, null,
' PLUS_RDFT=VC ',
null, null,
'RDFUSER', 'NET1'));
-- Select all grandfathers and their grandchildren from the family model.
-- Use inferencing from both the RDFS and family_rb rulebases.
SELECT x$rdfterm grandfather, y$rdfterm grandchild
FROM TABLE(SEM_MATCH(
'PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX : <http://www.example.org/family/>
SELECT ?x ?y
WHERE {?x :grandParentOf ?y . ?x rdf:type :Male}',
SEM_Models('family'),
SEM_Rulebases('RDFS','family_rb'),
null, null, null,
' PLUS_RDFT=VC ',
null, null,
'RDFUSER', 'NET1'));
1-206
Chapter 1
For More Information About RDF Semantic Graph
Table 1-27 lists the old and new names for some objects related to support for semantic
technologies, in alphabetical order by old name.
Table 1-27 Semantic Technology Software Objects: Old and New Names
1-207
Chapter 1
Oracle RDF Graph Features that Support Accessibility
1-208
2
Quick Start for Using Semantic Data
This section provides the steps to help you get started on working with semantic data in an
Oracle Database.
To work with RDF data, you must create a semantic network either in the MDSYS schema or
in the user schema. Follow these general steps as applicable to your semantic network:
• Getting Started with Semantic Data in a Schema-Private Network
• Getting Started with Semantic Data in an MDSYS-Owned Network
• Quick Start for Using RDF Semantic Data in Oracle Autonomous Database
2. Create a database user to work with semantic data in the database and grant the
necessary privileges to the database user. You must be connected as a user with
appropriate privileges to create the database user.
The following example creates a network owner user rdfuser and grants the necessary
privileges to rdfuser:
CONNECT rdfuser/<password-for-rdfuser>
2-1
Chapter 2
Getting Started with Semantic Data in an MDSYS-Owned Network
EXECUTE SEM_APIS.CREATE_SEM_NETWORK('rdf_tblspace',
network_owner=>'rdfuser', network_name=>'net1');
5. Create a model.
When you create a model, you specify the model name, the table to hold
references to semantic data for the model, and the column of type
SDO_RDF_TRIPLE_S in that table.
The following command creates a model named articles in the net1 schema-
private network.
After you create the model, you can insert triples into the model, as shown in the
examples in Semantic Data Examples (PL/SQL and Java).
EXECUTE SEM_APIS.CREATE_SEM_NETWORK('rdf_tblspace');
3. Create a database user under whose schema you will manage your semantic data
and grant the necessary privileges to the database user. You must be connected
as a user with appropriate privileges to create the database user.
The following example creates a database user rdfuser and grants the necessary
privileges to rdfuser:
2-2
Chapter 2
Quick Start for Using RDF Semantic Data in Oracle Autonomous Database
CONNECT rdfuser/<password-for-rdfuser>
Note:
You must not perform the following steps while connected as SYS, SYSTEM, or
MDSYS.
5. Create an application table to store references to the semantic data and manage
privileges for insert, update and delete operations. (You do not need to be connected as
a user with DBA privileges for this step and the remaining steps.)
This table must contain a column of type SDO_RDF_TRIPLE_S, which will contain
references to all data associated with a single model.
The following example creates a table named articles_rdf_data with one column to
hold the data for triples:
6. Create a model.
When you create a model, you must specify the model name, the table to hold references
to semantic data for the model, and the column of type SDO_RDF_TRIPLE_S in that
table.
The following command creates a model named articles in the MDSYS-owned network,
which will use the table created in the preceding step.
After you create the model, you can insert triples into the model, as shown in the examples in
Semantic Data Examples (PL/SQL and Java).
Note:
You must omit the network_owner and network_name arguments in the Semantic
Data Examples (PL/SQL and Java) when using an MDSYS-owned semantic
network.
2-3
Chapter 2
Quick Start for Using RDF Semantic Data in Oracle Autonomous Database
Note:
If you are using Database Actions, you must REST Enable the user in
order to enable the new user to access Database Actions. See Create
User for more details.
2. Grant the required privileges to the newly created network owner user.
You must be connected as a user with administrative privileges to run the following
statement:
2-4
Chapter 2
Quick Start for Using RDF Semantic Data in Oracle Autonomous Database
Note:
If you are using Database Actions to create the new user in the preceding step,
the CONNECT and the RESOURCE privileges are provided by default. Hence, you
must only grant the CREATE VIEW privilege to the new user.
CONNECT rdfuser/<password-for-rdfuser>
2-5
Chapter 2
Quick Start for Using RDF Semantic Data in Oracle Autonomous Database
7. Execute SPARQL queries on the inserted data using RDF Graph Server and
Query UI.
See Deploying RDF Graph Server and Query UI from Oracle Cloud Marketplace to
launch the RDF Query UI application.
You can query the inserted data by running SPARQL queries on the SPARQL
query page in RDF Graph Query UI.
Alternatively, you can also execute SPARQL queries using SPARQL editor in SQL
Developer in a dedicated Autonomous Database deployment. But if you are using
Autonomous Database in a shared deployment, then the SPARQL editor is only
supported in SQL Developer 21.2 or later. See Connect with Oracle SQL
Developer for creating a connection to your autonomous database using Cloud
Wallet.
2.3.2 Deploying RDF Graph Server and Query UI from Oracle Cloud
Marketplace
You can set up RDF Graph Server and Query UI in your Autonomous Database
instance using the Oracle Cloud Marketplace image.
As a prerequisite, you must have the following already created:
2-6
Chapter 2
Quick Start for Using RDF Semantic Data in Oracle Autonomous Database
2-7
3
OWL Concepts
You should understand key concepts related to the support for a subset of the Web Ontology
Language (OWL).
This chapter builds on the information in RDF Semantic Graph Overview, and it assumes that
you are familiar with the major concepts associated with OWL, such as ontologies,
properties, and relationships. For detailed information about OWL, see the OWL Web
Ontology Language Reference at http://www.w3.org/TR/owl-ref/.
• Ontologies
An ontology is a shared conceptualization of knowledge in a particular domain.
• Using OWL Inferencing
You can use entailment rules to perform native OWL inferencing.
• Using Semantic Operators to Query Relational Data
You can use semantic operators to query relational data in an ontology-assisted manner,
based on the semantic relationship between the data in a table column and terms in an
ontology.
3.1 Ontologies
An ontology is a shared conceptualization of knowledge in a particular domain.
It consists of a collection of classes, properties, and optionally instances. Classes are
typically related by class hierarchy (subclass/ superclass relationship). Similarly, the
properties can be related by property hierarchy (subproperty/ superproperty relationship).
Properties can be symmetric or transitive, or both. Properties can also have domain, ranges,
and cardinality constraints specified for them.
RDFS-based ontologies only allow specification of class hierarchies, property hierarchies,
instanceOf relationships, and a domain and a range for properties.
3-1
Chapter 3
Ontologies
Immune_System_Disorder
Immunodeficiency_
Autoimmune_Disease Syndrome
T_Cell_Immunodeficiency
Rheumatoid_Arthritis
AIDS
The data in the PATIENTS table might include the PATIENT_ID and DIAGNOSIS
column values shown in Table 3-1.
PATIENT_ID DIAGNOSIS
1234 Rheumatoid_Arthritis
2345 Immunodeficiency_Syndrome
3456 AIDS
To query ontologies, you can use the SEM_MATCH table function or the
SEM_RELATED operator and its ancillary operators.
Related Topics
• Using the SEM_MATCH Table Function to Query Semantic Data
To query semantic data, use the SEM_MATCH table function.
• Using Semantic Operators to Query Relational Data
You can use semantic operators to query relational data in an ontology-assisted
manner, based on the semantic relationship between the data in a table column
and terms in an ontology.
3-2
Chapter 3
Ontologies
3-3
Chapter 3
Ontologies
Note that the OWL2EL rulebase support does not include reflexive object properties
(ReflexiveObjectProperty) simply because a reflexive object property will link
every individual with itself, which would probably cause an unnecessary and costly
expansion of the inference graph.
Table 3-2 lists the RDFS/OWL vocabulary constructs included in each supported
rulebase.
3-4
Chapter 3
Using OWL Inferencing
3-5
Chapter 3
Using OWL Inferencing
SQL> EXECUTE
sem_apis.create_sem_model('owltst','owltst','triple',network_owner=>'RDFUSER',net
work_name=>'NET1');
PL/SQL procedure successfully completed.
SQL> commit;
3-6
Chapter 3
Using OWL Inferencing
SQL> -- The following view is generated to represent the entailed graph (rules index).
SQL> desc mdsys.semi_owltst_idx;
SQL> -- Run the preceding query with an additional rulebase parameter to list
SQL> -- the original graph plus the inferred triples.
SQL> SELECT s$rdfterm,p$rdfterm,o$rdfterm FROM table(SEM_MATCH('SELECT * WHERE {?s ?
p ?o}', SEM_MODELS('OWLTST'),
SEM_RULEBASES('OWLPRIME'), null, null, null, null, 'PLUS_RDFT=VC', null,
null, 'RDFUSER', 'NET1'));
SQL> -- In the result of the following query, :Jack :uncleOf :Mary is inferred.
SQL> SELECT s$rdfterm,p$rdfterm,o$rdfterm FROM table(SEM_MATCH('SELECT * WHERE {?s ?
p ?o}',
SEM_MODELS('OWLTST'),
SEM_RULEBASES('OWLPRIME','USER_RULEBASE'), null, null, null, null,
'PLUS_RDFT=VC', null, null, 'RDFUSER', 'NET1'));
For performance, the inference engine by default executes each user rule without checking
the syntax legality of inferred triples (for example, literal value as a subject, blank node as a
predicate) until after the last round of entailment. After completing the last entailment round,
the inference engine removes all syntactically illegal triples without throwing any errors for
3-7
Chapter 3
Using OWL Inferencing
these triples. However, because triples with illegal syntax may exist during multiple
rounds of inference, rules can use these triples as part of their antecedents. For
example, consider the following user-defined rules:
• Rule 1:
(?s :account ?y)
(?s :country :Spain) --> (?y rdf:type :SpanishAccount)
• Rule 2:
(?s :account ?y)
(?y rdf:type :SpanishAccount) --> (?s :language "es_ES")
Rule 1 finds all Spanish users and designates their accounts as Spanish accounts.
Rule 2 sets the language for all users with Spanish accounts to es_ES (Spanish).
Consider the following data, displayed in Turtle format:
:Juan :account "123ABC4Z"
:country :Spain
Note there are no triples specifying which accounts are of type :SpanishAccount. The
user-defined rules infer those triples during creation of the entailment, but the
inference engine removes them after the last round of inference because they contain
illegal syntax. The accounts are the literal values, which cannot be used as subjects in
an RDF triple.
To force the checking of syntax legality of inferred triples, add the /*+
ENABLE_SYNTAX_CHECKING */ optimizer hint to the beginning of the rule's FILTER
expression. Forcing syntax checking for a rule can result in a performance penalty and
will throw an exception for any syntactically illegal triples. The following example,
similar to Rule 1, forces syntax checking. (In addition, merely to illustrate the use of a
filter expression, the example restricts accounts to those that do not end with the letter
'Z'.)
INSERT INTO RDFUSER.NET1#SEMR_USER_RULEBASE VALUES (
'spanish_account_rule',
'(?s <http://example.com/account> ?y)(?y <http://example.com/account> <http://
example.com/Spain>)',
'/*+ ENABLE_SYNTAX_CHECKING */ y not like ''%Z'' ',
'(?y <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://example.com/
SpanishAccount>)',
NULL
);
3-8
Chapter 3
Using OWL Inferencing
To generate the information required for proof, specify PROOF=T in the call to the
SEM_APIS.CREATE_ENTAILMENT procedure, as shown in the following example:
EXECUTE sem_apis.create_entailment('owltst_idx', sem_models('owltst'), -
sem_rulebases('owlprime'), SEM_APIS.REACH_CLOSURE, 'SAM', 'PROOF=T',
network_owner=>'RDFUSER', network_name=>'NET1');
Specifying PROOF=T causes a view to be created containing proof for each inferred triple. The
view name is the entailment name prefixed by MDSYS.SEMI_. Two relevant columns in this
view are LINK_ID and EXPLAIN (the proof). The following example displays the LINK_ID
value and proof of each generated triple (with LINK_ID values shortened for simplicity):
SELECT link_id || ' generated by ' || explain as
triple_and_its_proof FROM RDFUSER.NET1#SEMI_OWLST_IDX;
TRIPLE_AND_ITS_PROOF
--------------------------------------------------------------------
8_5_5_4 generated by 4_D_5_5 : SYMM_SAMH_SYMM
8_4_5_4 generated by 8_5_5_4 4_D_5_5 : SAM_SAMH
. . .
A proof consists of one or more triple (link) ID values and the name of the rule that is applied
on those triples:
link-id1 [link-id2 ... link-idn] : rule-name
3-9
Chapter 3
Using OWL Inferencing
If the entailment status is INCOMPLETE and if the last entailment was generated
without proof information, you cannot invoke SEM_APIS.CREATE_ENTAILMENT with
PROOF=T. In this case, you must first drop the entailment and create it again specifying
PROOF=T.
SQL> -- NOTE: The LINK_ID value and the numbers in the following
3-10
Chapter 3
Using OWL Inferencing
Each item in the validation report array includes the following information:
• Number of triples that cause this error (1 in Example 3-5)
• Error code (10001 Example 3-5)
• One or more triples (shown in parentheses in the output; (4_2_4_8 2 4 8) in
Example 3-5).
These numbers are the LINK_ID value and the ID values of the subject, predicate, and
object.
• Descriptive error message (Unsatisfiable class. in Example 3-5)
The output in Example 3-5 indicates that the error is caused by one triple that asserts that a
class is a subclass of an empty class owl:Nothing.
Because rules RDFS4A, RDFS4B, RDFS6, RDFS8, RDFS10, RDFS13 may not generate
meaningful inference for your applications, you can deselect those components for faster
inference. The following example deselects these rules.
EXECUTE sem_apis.create_entailment('rdfstst_idx', sem_models('my_model'),
sem_rulebases('RDFS'), SEM_APIS.REACH_CLOSURE, -
'RDFS4A-, RDFS4B-, RDFS6-, RDFS8-, RDFS10-, RDFS13-'), network_owner=>'RDFUSER',
network_name=>'NET1');
3-11
Chapter 3
Using OWL Inferencing
Applying OWLPrime inference (with the SAM component specified) to this set would
generate the following new triples:
:John1 owl:sameAs :John .
:John2 owl:sameAs :John .
:John1 owl:sameAs :John2 .
:John2 owl:sameAs :John1 .
:John owl:sameAs :John .
:John1 owl:sameAs :John1 .
:John2 owl:sameAs :John2 .
:John :hasAge "32" .
:John1 :hasAge "32" .
In the preceding example, :John, :John1 and :John2 are connected to each other with
the owl:sameAs relationship; that is, they are members of an owl:sameAs clique. To
provide optimized inference for large owl:sameAs cliques, you can consolidate
owl:sameAs triples without sacrificing correctness by specifying 'OPT_SAMEAS=T' in the
options parameter when performing OWLPrime entailment. For example:
EXECUTE sem_apis.create_entailment('M_IDX',sem_models('M'),
sem_rulebases('OWLPRIME'),null,null,'OPT_SAMEAS=T', network_owner=>'RDFUSER',
network_name=>'NET1');
When you specify this option, for each owl:sameAs clique, one resource from the
clique is chosen as a canonical representative and all of the inferences for that clique
are consolidated around that resource. Using the preceding example, if :John1 is the
3-12
Chapter 3
Using OWL Inferencing
clique representative, after consolidation the inferred graph would contain only the following
triples:
:John1 owl:sameAs :John1 .
:John1 :hasAge "32" .
Some overhead is incurred with owl:sameAs consolidation. During inference, all asserted
models are copied into the inference partition, where they are consolidated together with the
inferred triples. Additionally, for very large asserted graphs, consolidating and removing
duplicate triples incurs a large runtime overhead, so the OPT_SAMEAS=T option is
recommended only for ontologies that have a large number of owl:sameAs relationships and
large clique sizes.
After the OPT_SAMEAS=T option has been used for an entailment, all subsequent uses of
SEM_APIS.CREATE_ENTAILMENT for that entailment must also use OPT_SAMEAS=T, or an
error will be reported. To disable optimized sameAs handling, you must first drop the
entailment.
Clique membership information is stored in a view named SEMC_entailment-name, where
entailment-name is the name of the entailment (rules index). Each SEMC_entailment-name
view has the columns shown in Table 3-3.
To save space, the SEMC_entailment-name view does not contain reflexive rows like
(CLIQUE_ID, CLIQUE_ID).
• Querying owl:sameAs Consolidated Inference Graphs
In the following example query, the only result returned would be :John1, which is the
canonical clique representative.
SELECT A FROM TABLE (
SEM_MATCH ('SELECT ?A WHERE {?A :hasAge "32"}',SEM_MODELS('M'),
SEM_RULEBASES('OWLPRIME'),null, null, null, null, 'PLUS_RDFT=VC', null, null,
'RDFUSER', 'NET1'));
With the preceding example, even though :John2 :hasAge "32" occurs in the model, it has
been replaced during the inference consolidation phase where redundant triples are
removed. However, you can expand the query results by performing a join with the
MDSYS.SEMC_rules-index-name view that contains the consolidated owl:sameAs
3-13
Chapter 3
Using OWL Inferencing
information. For example, to get expanded result set for the preceding SEM_MATCH
query, you can use the following expanded query:
SELECT V.VALUE_NAME A_VAL FROM TABLE (
SEM_MATCH ('SELECT ?A WHERE {?A :hasAge "32"}',SEM_MODELS('M'),
SEM_RULEBASES('OWLPRIME'), null, null, null, null, 'PLUS_RDFT=VC', null,
null, 'RDFUSER', 'NET1')) Q,
RDFUSER.NET1#RDF_VALUE$ V, RDFUSER.NET1#SEMC_M_IDX C
WHERE V.VALUE_ID = C.VALUE_ID
AND C.CLIQUE_ID = Q.A$RDFVID
UNION ALL
SELECT A A_VAL FROM TABLE (
SEM_MATCH ('SELECT ?A WHERE {?A :hasAge "32"}',SEM_MODELS('M'),
SEM_RULEBASES('OWLPRIME'), null, null, null, null, 'PLUS_RDFT=VC', null,
null, 'RDFUSER', 'NET1'));
Or, you could rewrite the preceding expanded query using a left outer join, as follows:
SELECT V.VALUE_NAME A_VAL FROM TABLE (
SEM_MATCH ('(?A <http://hasAge> "33")',SEM_MODELS('M'),
SEM_RULEBASES('OWLPRIME'), null, null, null, null, 'PLUS_RDFT=VC', null,
null, 'RDFUSER', 'NET1')) Q,
RDFUSER.NET1#RDF_VALUE$ V,
(SELECT value_id, clique_id FROM RDFUSER.NET1#SEMC_M_IDX
UNION ALL
SELECT DISTINCT clique_id, clique_id
FROM RDFUSER.NET1#SEMC_M_IDX) C
WHERE Q.A$RDFVID = c.clique_id (+)
AND V.VALUE_ID = nvl(C.VALUE_ID, Q.A$RDFVID);
3-14
Chapter 3
Using OWL Inferencing
as in the following example, in which the triples from model M_NEW will be added to model M,
and entailment M_IDX will be updated with the new inferences:
EXECUTE sem_apis.create_entailment('M_IDX', sem_models('M'),
sem_rulebases('OWLPRIME''), SEM_APIS.REACH_CLOSURE, null, null,
sem_models('M_NEW'), network_owner=>'RDFUSER', network_name=>'NET1');
If multiple models are involved in the incremental inference call, then to specify the
destination model to which the delta_in model or models are to be added, specify
DEST_MODEL=<model_name> in the options parameter. For example, the following causes the
semantic data in model M_NEW to be added to model M2:
EXECUTE sem_apis.create_entailment('M_IDX', sem_models('M1','M2','M3'),
sem_rulebases('OWLPRIME''), SEM_APIS.REACH_CLOSURE, null, 'DEST_MODEL=M2',
sem_models('M_NEW')), network_owner=>'RDFUSER', network_name=>'NET1');
Another way to bypass the conventional path loading requirement when using incremental
inference is to set the UNDO_RETENTION parameter to cover the intervals between
entailments when you perform bulk loading. For example, if the last entailment was created 6
hours ago, the UNDO_RETENTION value should be set to greater than 6 hours; if it is less
than that, then (given a heavy workload and limited undo space) it is not guaranteed that all
relevant undo information will be preserved for incremental inference to apply. In such cases,
the SEM_APIS.CREATE_ENTAILMENT procedure falls back to regular (non-incremental)
inference.
To check if change tracking is enabled on a model, use the
SEM_APIS.GET_CHANGE_TRACKING_INFO procedure. To get additional information
about incremental inference for an entailment, use the SEM_APIS.GET_INC_INF_INFO
procedure.
The following restrictions apply to incremental inference:
• It does not work with optimized owl:sameAs handling (OPT_SAMEAS), user-defined rules,
VPD-enabled models, or version-enabled models.
• It supports only the addition of triples. With updates or deletions, the entailment will be
completely rebuilt.
• It depends on triggers on application tables.
• Column types (RAW8 or NUMBER) used in incremental inference must be consistent.
For instance, if RAW8=T is used to build the entailment initially, then for every subsequent
SEM_APIS.CREATE_ENTAILMENT call the same option must be used. To change the
column type to NUMBER, you must drop and rebuild the entailment.
Specifying the DOP keyword causes parallel execution to be enabled for an Oracle-chosen
set of inference components
3-15
Chapter 3
Using OWL Inferencing
3-16
Chapter 3
Using OWL Inferencing
also enables great flexibility in selecting the scope; for example, you can include triples from
zero or more named graphs and/or from the default graph, and you can include all triples with
a null graph name from specified models.
For example, in a hospital application you may only want to apply the inference rules on all
the information contained in a set of named graphs describing patients of a particular
hospital. If the patient-related named graphs contains only instance-related assertions
(ABox), you can specify one or multiple additional schema related-models (TBox), as in
Example 3-6.
Example 3-6 Named Graph Based Global Inference
EXECUTE sem_apis.create_entailment(
'patients_inf',
models_in => sem_models('patients','hospital_ontology'),
rulebases_in => sem_rulebases('owl2rl'),
passes => SEM_APIS.REACH_CLOSURE,
inf_components_in => null,
options => 'DOP=4,RAW8=T',
include_default_g => sem_models('hospital_ontology'),
include_named_g =>
sem_graphs('<urn:hospital1_patient1>','<urn:hospital1_patient2>'),
inf_ng_name => '<urn:inf_graph_for_hospital1>',
network_owner =>'RDFUSER',
network_name =>'NET1'
);
In Example 3-6:
• Two models are involved: patients contains a set of named graphs where each named
graph holds triples relevant to a particular patient, and hospital_ontology contains
schema information describing concepts and relationships that are defined for hospitals.
These two models together are the source models, and they set up an overall scope for
the inference.
• The include_default_g parameter causes all triples with a NULL graph name in the
specified models to participate in NGGI. In this example, all triples with a NULL graph
name in model hospital_ontology will be included in NGGI.
• The include_named_g parameter causes all triples from the specified named graphs
(across all source models) to participate in NGGI. In this example, triples from named
graphs <urn:hospital1_patient1> and <urn:hospital1_patient2> will be included in
NGGI.
• The inf_ng_name parameter assigns graph name <urn:inf_graph_for_hospital1> to all
the new triples inferred by NGGI.
Assertions from any two separate named graphs will never jointly produce any new
assertions.
3-17
Chapter 3
Using OWL Inferencing
NGLI currently does not work together with proof generation, user-defined rules,
optimized owl:sameAs handling, or incremental inference.
In Example 3-7:
• The two models patients and hospital_ontology together are the source models,
and they set up an overall scope for the inference, similar to the case of global
inference in Example 3-6. All triples with a null graph name are treated as part of
the common schema (TBox). Inference is performed within the boundary of every
single named graph combined with the common schema.
• Then options parameter keyword-value pair LOCAL_NG_INF=T specifies that
named graph based local inference (NGLI) is to be performed.
Note that, by design, NGLI does not apply to the default graph itself. However, you can
easily apply named graph based global inference (NGGI) on the default graph and set
the inf_ng_name parameter to null. In this way, the TBox inference is precomputed,
improving the overall performance and storage consumption.
NGLI does not allow the following:
• Inferring new relationships based on a mix of triples from multiple named graphs
• Inferring new relationships using only triples from the default graph.
To get the inference that you would normally expect, you should keep schema
assertions and instance assertions separate. Schema assertions (for example, :A
rdfs:subClassOf :B and :p1 rdfs:subPropertyOf :p2) should be stored in the
3-18
Chapter 3
Using OWL Inferencing
default graph as unnamed triples (with null graph names). By contrast, instance assertions
(for example, :X :friendOf :Y) should be stored in one of the named graphs.
For a discussion and example of using NGLI to perform document-centric inference with
semantically indexed documents, see Performing Document-Centric Inference.
ENTAIL_ANYWAY=T is specified because the NGGI call in step 1will set the status of
inferred graph to VALID, and the SEM_APIS.CREATE_ENTAILMENT procedure call in
step 2 will quit immediately unless ENTAIL_ANYWAY=T is specified.
3-19
Chapter 3
Using Semantic Operators to Query Relational Data
The following component codes are available: SCOH, COMPH, DISJH, SYMMH, INVH, SPIH,
MBRH, SPOH, DOMH, RANH, EQCH, EQPH, FPH, IFPH, DOM, RAN, SCO, DISJ, COMP, INV, SPO, FP,
IFP, SYMM, TRANS, DIF, SAM, CHAIN, HASKEY, ONEOF, INTERSECT, INTERSECTSCOH, MBRLST,
PROPDISJH, SKOSAXIOMS, SNOMED, SVFH, THINGH, THINGSAM, UNION, RDFP1, RDFP2, RDFP3,
RDFP4, RDFP6, RDFP7, RDFP8AX, RDFP8BX, RDFP9, RDFP10, RDFP11, RDFP12A, RDFP12B,
RDFP12C, RDFP13A, RDFP13B, RDFP13C, RDFP14A, RDFP14BX, RDFP15, RDFP16, RDFS2,
RDFS3, RDFS4a, RDFS4b, RDFS5, RDFS6, RDFS7, RDFS8, RDFS9, RDFS10, RDFS11, RDFS12,
RDFS13
U owl:sameAs V .
X p U . ==> X p V .
The reason for not including these rules is that they tend to generate many assertions.
If you need to include these assertions, you can include the SAM component code in
the call to the SEM_APIS.CREATE_ENTAILMENT procedure.
3-20
Chapter 3
Using Semantic Operators to Query Relational Data
Note:
SEM_RELATED and SEM_DISTANCE are not supported on schema-private
semantic networks.
The sub attribute is the name of table column that is being searched. The terms in the table
column are typically the subject in a <subject, predicate, object> triple pattern.
3-21
Chapter 3
Using Semantic Operators to Query Relational Data
The predExpr attribute represents the predicate that can appear as a label of the edge
on the path from the subject node to the object node.
The obj attribute represents the term in the ontology for which related terms (related
by the predExpr attribute) have to be found in the table (in the column specified by the
sub attribute). This term is typically the object in a <subject, predicate, object> triple
pattern. (In a query with the equality operator, this would be the query term.)
The ontologyName attribute is the name of the ontology that contains the relationships
between terms.
The rulebases attribute identifies one or more rulebases whose rules have been
applied to the ontology to infer new relationships. The query will be answered based
both on relationships from the ontology and the inferred new relationships when this
attribute is specified.
The index_status optional attribute lets you query the data even when the relevant
entailment (created when the specified rulebase was applied to the ontology) does not
have a valid status. If this attribute is null, the query returns an error if the entailment
does not have a valid status. If this attribute is not null, it must be the string VALID,
INCOMPLETE, or INVALID, to specify the minimum status of the entailment for the query
to succeed. Because OWL does not guarantee monotonicity, the value INCOMPLETE
should not be used when an OWL Rulebase is specified.
The lower_bound and upper_bound optional attributes let you specify a bound on the
distance measure of the relationship between terms that are related. See Using the
SEM_DISTANCE Ancillary Operator for the description of the distance measure.
The SEM_RELATED operator returns 1 if the two input terms are related with respect
to the specified predExpr relationship within the ontology, and it returns 0 if the two
input terms are not related. If the lower and upper bounds are specified, it returns 1 if
the two input terms are related with a distance measure that is greater than or equal to
lower_bound and less than or equal to upper_bound.
The number attribute can be any number, as long as it matches the number that is the
last attribute specified in the call to the SEM_RELATED operator (see Example 3-10).
The number is used to match the invocation of the ancillary operator SEM_DISTANCE
with a specific SEM_RELATED (primary operator) invocation, because a query can
have multiple invocations of primary and ancillary operators.
Example 3-10 SEM_DISTANCE Ancillary Operator
Example 3-10 expands Example 3-9 to show several statements that include the
SEM_DISTANCE ancillary operator, which gives a measure of how closely the two
terms (here, a patient's diagnosis and the term Immune_System_Disorder) are related
by measuring the distance between the terms. Using the ontology described in
Example: Disease Ontology, the distance between AIDS and Immune_System_Disorder
is 3.
3-22
Chapter 3
Using Semantic Operators to Query Relational Data
In Example 3-11, the lower and upper bounds are specified using the lower_bound and
upper_bound parameters in the SEM_RELATED operator instead of using the
SEM_DISTANCE operator. The SEM_DISTANCE operator can be also be used for restricting
the rows returned, as shown in the last SELECT statement in Example 3-10.
• Computation of Distance Information
3-23
Chapter 3
Using Semantic Operators to Query Relational Data
The column on which the index is built (DIAGNOSIS in Example 3-12) must be the first
parameter to the SEM_RELATED operator, in order for the index to be used. If it not
the first parameter, the index is not used during the execution of the query.
Example 3-13 Creating a Semantic Index Specifying a Model and Rulebase
To improve the performance of certain semantic queries, you can cause statistical
information to be generated for the semantic index by specifying one or more models
and rulebases when you create the index. Example 3-13 creates an index that will also
generate statistics information for the specified model and rulebase. The index can be
used with other models and rulebases during query, but the statistical information will
be used only if the model and rulebase specified during the creation of the index are
the same model and rulebase specified in the query.
3-24
Chapter 3
Using Semantic Operators to Query Relational Data
Assume, however, that this query instead needs to retrieve all rows that have a value in the
DIAGNOSIS column for which Immune_System_Disorder is a subclass. You could rewrite the
query as follows:
SELECT diagnosis FROM patients
WHERE SEM_RELATED
('<http://www.example.org/medical_terms/Immune_System_Disorder>',
'<http://www.w3.org/2000/01/rdf-schema#subClassOf>',
diagnosis,
sem_models('medical_ontology'), sem_rulebases('owlprime')) = 1;
However, in this case a semantic index on the DIAGNOSIS column will not be used, because
it is not the first parameter to the SEM_RELATED operator. To cause the index to be used,
you can change the preceding query to use the inverseOf keyword, as follows:
SELECT diagnosis FROM patients
WHERE SEM_RELATED (diagnosis,
'inverseOf(http://www.w3.org/2000/01/rdf-schema#subClassOf)',
'<http://www.example.org/medical_terms/Immune_System_Disorder>',
sem_models('medical_ontology'), sem_rulebases('owlprime')) = 1;
This form causes the table column (on which the index is built) to be the first parameter to the
SEM_RELATED operator, and it retrieves all rows that have a value in the DIAGNOSIS
column for which Immune_System_Disorder is a subclass.
3-25
Chapter 3
Using Semantic Operators to Query Relational Data
The slash (/) character at the end of the URI is important, because the URI is prefixed
to the table value (in the index structure) without any parsing.
3-26
4
Simple Knowledge Organization System
(SKOS) Support
You can perform inferencing based on a core subset of the Simple Knowledge Organization
System (SKOS) data model, which is especially useful for representing thesauri, classification
schemes, taxonomies, and other types of controlled vocabulary.
SKOS is based on standard semantic web technologies including RDF and OWL, which
makes it easy to define the formal semantics for those knowledge organization systems and
to share the semantics across applications.
Support is provided for most, but not all, of the features of SKOS, the detailed specification of
which is available at http://www.w3.org/TR/skos-reference/.
Around 40 SKOS-specific terms are included in the RDF Semantic Graph support, such as
skos:broader, skos:relatedMatch, and skos:Concept. Over 100 SKOS axiomatic triples
have been added, providing the basic coverage of SKOS semantics. However, support is not
included for the integrity conditions described in the SKOS specification.
To perform SKOS-based inferencing, specify the system-defined SKOSCORE rulebase in the
rulebases_in parameter in the call to the SEM_APIS.CREATE_ENTAILMENT procedure, as
in the following example:
EXECUTE sem_apis.create_entailment('tstidx',sem_models('tst'),
sem_rulebases('skoscore'), network_owner=>'RDFUSER', network_name=>'NET1');
Example 4-1 defines, in Turtle format, a simple electronics scheme and two relevant
concepts, cameras and digital cameras. Its meaning is straightforward and its representation
is in RDF. It can be managed by Oracle Database in the same way as other RDF and OWL
data.
Example 4-1 SKOS Definition of an Electronics Scheme
ex1:electronicsScheme rdf:type skos:ConceptScheme;
4-1
Chapter 4
Supported and Unsupported SKOS Semantics
Most SKOS axioms and definitions are supported including the following: S1-S8, S10-
S11, S15-S26, S28-S31, S33-S36, S38-S45, S47-S50, and S53-S54. (See the SKOS
detailed specification for definitions.)
4-2
Chapter 4
Performing Inference on SKOS Models
Most SKOS integrity conditions are supported, including S9, S13, S27, S37, and S46.
S52 is partially supported.
S55, S56, and S57 are not supported by default.
• S55, the property chain (skosxl:prefLabel, skosxl:literalForm), is a subproperty of
skos:prefLabel.
• S56, the property chain (skosxl:altLabel, skosxl:literalForm), is a subproperty of
skos:altLabel.
• S57, the property chain (skosxl:hiddenLabel, skosxl:literalForm), is a subproperty
of skos:hiddenLabel.chains.
However, S55, S56, and S57 can be implemented using the OWL 2 subproperty chain
construct. For information about property chain handling, see Property Chain Handling.
The inferred data will include many of the axioms defined in the SKOS detailed specification.
Like other system-defined rulebases, SKOSCORE has no explicit rules; all the semantics
supported are coded into the implementation.
• Validating SKOS Models and Entailments
• Property Chain Handling
4-3
Chapter 4
Performing Inference on SKOS Models
4-4
5
Semantic Indexing for Documents
Information extractors locate and extract meaningful information from unstructured
documents. The ability to search for documents based on this extracted information is a
significant improvement over the keyword-based searches supported by the full-text search
engines.
Semantic indexing for documents introduces an index type that can make use of information
extractors and annotators to semantically index documents stored in relational tables.
Documents indexed semantically can be searched using SEM_CONTAINS operator within a
standard SQL query. The search criteria for these documents are expressed using SPARQL
query patterns that operate on the information extracted from the documents, as in the
following example.
SELECT docId
FROM Newsfeed
WHERE SEM_CONTAINS (article,
' { ?org rdf:type typ:Organization .
?org pred:hasCategory cat:BusinessFinance } ', ..) = 1
The key components that facilitate Semantic Indexing for documents in an Oracle Database
include:
• Extensible information extractor framework, which allows third-party information
extractors to be plugged into the database
• SEM_CONTAINS operator to identify documents of interest, based on their extracted
information, using standard SQL queries
• SEM_CONTAINS_SELECT ancillary operator to return relevant information about the
documents identified using SEM_CONTAINS operator
• SemContext index type to interact with the information extractor and manage the
information extracted from a document set in an index structure and to facilitate
semantically meaningful searches on the documents
The application program interface (API) for managing extractor policies and semantic indexes
created for documents is provided in the SEM_RDFCTX PL/SQL package. SEM_RDFCTX
Package Subprograms provides the reference information about the subprograms in
SEM_RDFCTX package.
• Information Extractors for Semantically Indexing Documents
Information extractors process unstructured documents and extract meaningful
information from them, often using natural-language processing engines with the aid of
ontologies.
• Extractor Policies
An extractor policy is a named dictionary entity that determines the characteristics of a
semantic index that is created using the policy.
• Semantically Indexing Documents
Textual documents stored in a CLOB or VARCHAR2 column of a relational table can be
indexed using the MDSYS.SEMCONTEXT index type, to facilitate semantically
meaningful searches.
5-1
Chapter 5
5-2
Chapter 5
Information Extractors for Semantically Indexing Documents
5-3
Chapter 5
Information Extractors for Semantically Indexing Documents
extracted information as RDF triples. In the current release, the RDF triples are
expected to be serialized using RDF/XML format, and therefore the rdfReturnType
method should return 'RDF/XML'.
5-4
Chapter 5
Extractor Policies
The following example creates a dependent extractor policy that combines the metadata
extracted by the policy in the preceding example with a user-defined RDF model named
geo_ontology:
begin
sem_rdfctx.create_policy (policy_name => 'SEM_EXTR_PLUS_GEOONT',
base_policy => 'SEM_EXTR',
user_models => SEM_MODELS ('geo_ontology'));
end;
/
You can use an extractor policy to create one or more semantic indexes on columns that
store unstructured documents, as explained in Semantically Indexing Documents.
5-5
Chapter 5
SEM_CONTAINS and Ancillary Operators
The RDF model created for an index is managed internally and it is not associated
with an application table. The triples stored in such model are automatically
maintained for any modifications (such as update, insert, or delete) made to the
documents stored in the table column. Although a single RDF model is used to index
all documents stored in a table column, the triples stored in the model maintain
references to the documents from which they are extracted; therefore, all the triples
extracted from a specific document form an individual graph within the RDF model.
The documents that are semantically indexed can then be searched using a SPARQL
query pattern that operates on the triples extracted from the documents.
When creating a semantic index for documents, you can use a basic extractor policy
or a dependent policy, which may include one or more user-defined RDF models.
When you create an index with a dependent extractor policy, the document search
pattern specified using SPARQL could span the triples extracted from the documents
as well as those defined in user-defined models.
You can create an index using multiple extractor policies, in which case the triples
extracted by the corresponding extractors are maintained separately in distinct RDF
models. A document search query using one such index can select the specific policy
to be used for answering the query. For example, an extractor policy named CITY_EXTR
can be created to extract the names of the cities from a given document, and this
extractor policy can be used in combination with the SEM_EXTR policy to create a
semantic index, as in the following example:
CREATE INDEX ArticleIndex on Newsfeed (article)
INDEXTYPE IS mdsys.SemContext PARAMETERS ('SEM_EXTR CITY_EXTR');
The first extractor policy in the PARAMETERS list is considered to be the default policy
if a query does not refer to a specific policy; however, you can change the default
extractor policy for a semantic index by using the
SEM_RDFCTX.SET_DEFAULT_POLICY procedure, as in the following example:
begin
sem_rdfctx.set_default_policy (index_name => 'ArticleIndex',
policy_name => 'CITY_EXTR');
end;
/
The column and sparql attributes attribute are required. The other attributes are
optional (that is, each can be a null value).
5-6
Chapter 5
SEM_CONTAINS and Ancillary Operators
The column attribute identifies a VARCHAR2 or CLOB column in a relational table that stores
the documents or references to documents that are semantically indexed. An index of type
MDSYS.SEMCONTEXT must be defined in this column for the SEM_CONTAINS operator to
use.
The sparql attribute is a string literal that defines the document search criteria, expressed in
SPARQL format.
The optional policy attribute specifies the name of an extractor policy, usually to override the
default policy. A semantic document index can have one or more extractor policies specified
at index creation, and one of these policies is the default, which is used if the policy attribute
is null in the call to SEM_CONTAINS.
The optional aliases attribute identifies one or more namespaces, including a default
namespace, to be used for expansion of qualified names in the query pattern. Its data type is
SEM_ALIASES, which has the following definition: TABLE OF SEM_ALIAS, where each
SEM_ALIAS element identifies a namespace ID and namespace value. The SEM_ALIAS
data type has the following definition: (namespace_id VARCHAR2(30), namespace_val
VARCHAR2(4000))
The optional index_status attribute is relevant only when a dependent policy involving one
or more entailments is being used for the SEM_CONTAINS invocation. The index_status
value identifies the minimum required validity status of the entailments. The possible values
are 0 (for VALID, the default), 1 (for INCOMPLETE), and 2 (for INVALID).
The optional ancoper attribute specifies a number as the binding to be used when the
SEM_CONTAINS_SELECT ancillary operator is used with this operator in a query. The
number specified for the ancoper attribute should be the same as number specified for the
operbind attribute in the SEM_CONTAINS_SELECT ancillary operator.
The SEM_CONTAINS operator returns 1 for each document instance matching the specified
search criteria, and returns 0 for all other cases.
For more information about using the SEM_CONTAINS operator, including an example, see
Searching for Documents Using SPARQL Query Patterns.
• SEM_CONTAINS_SELECT Ancillary Operator
• SEM_CONTAINS_COUNT Ancillary Operator
5-7
Chapter 5
Searching for Documents Using SPARQL Query Patterns
The SPARQL query pattern specified with the SEM_CONTAINS operator is matched
against the individual graphs corresponding to each document, and a document is
considered to match a search criterion if the triples from the corresponding graph
satisfy the query pattern. In the preceding example, the SPARQL query pattern
identifies the individual graphs (thus, the documents) that refer to an Organization
that belong to BusinessFinance category. The SQL query returns the rows
corresponding to the matching documents in its result set. The preceding example
assumes that the URIs used in the query are generated by the underlying extractor,
and that you (the user searching for documents) are aware of the properties and terms
that are generated by the extractor in use.
5-8
Chapter 5
Bindings for SPARQL Variables in Matching Subgraphs in a Document (SEM_CONTAINS_SELECT Ancillary Operator)
When you create an index using a dependent extractor policy that includes one or more user-
defined RDF models, the triples asserted in the user models are considered to be common to
all the documents. Document searches involving such policies test the search criteria against
the triples in individual graphs corresponding to the documents, combined with the triples in
the user models. For example, the following query identifies all articles referring to
organizations in the state of New Hampshire, using the geographical ontology (geo_ontology
RDF Model from a preceding example) that maps cities to states:
SELECT docId FROM Newsfeed
WHERE SEM_CONTAINS (article,
'{ ?org rdf:type class:Organization .
?org pred:hasLocation ?city .
?city geo:hasState state:NewHampshire }',
'SEM_EXTR_PLUS_GEOONT',
sem_aliases(
sem_alias('class', 'http://www.myorg.com/classes/'),
sem_alias('pred', 'http://www.myorg.com/pred/'),
sem_alias('geo', 'http://geoont.org/rel/'),
sem_alias('state', 'http://geoont.org/state/'))) = 1;
The SEM_CONTAINS_SELECT ancillary operator returns the bindings for the variables in
SPARQL Query Results XML format, as CLOB data. The variables may be bound to multiple
data instances from a single document, in which case all bindings for the variables are
returned. The following example is an excerpt from the output of the preceding query: a value
returned by the SEM_CONTAINS_SELECT ancillary operator for a document matching the
specified search criteria.
5-9
Chapter 5
Improving the Quality of Document Search Operations
<results>
<result>
<binding name="ORG">
<uri>http://newscorp.com/Org/AcmeCorp</uri>
</binding>
</result>
<result>
<binding name="ORG">
<uri>http://newscorp.com/Org/ABCCorp</uri>
</binding>
</result>
</results>
You can rank the search results by creating an instance of XMLType for the CLOB
value returned by the SEM_CONTAINS_SELECT ancillary operator and applying an
XPath expression to sort the results on some attribute values.
By default, the SEM_CONTAINS_SELECT ancillary operator returns bindings for all
variables used in the SPARQL-based document search criteria. However, when the
values for only a subset of the variables are relevant for a search, the SPARQL pattern
can include a SELECT clause with space-separated list of variables for which the
values should be returned, as in the following example:
SELECT docId, SEM_CONTAINS_SELECT(1) as result
FROM Newsfeed
WHERE SEM_CONTAINS (article,
'SELECT ?org ?city
WHERE { ?org rdf:type class:Organization .
?org pred:hasLocation ?city .
?city geo:hasState state:NewHampshire }', ..,
1) = 1;
5-10
Chapter 5
Indexing External Documents
The index name and the WHERE clause specified in the preceding example identify specific
instances of the document to be annotated, and the RDF/XML content passed in is used to
add additional triples to the individual graphs corresponding to those documents. This allows
domain experts and user communities to improve the quality of search by adding relevant
triples to annotate some documents.
The <Datastore> element in the preferences document specifies the type of repository used
for the documents to be indexed. When the value for the type attribute is set to FILE, the
<Path> element identifies a directory object in the database (created using the SQL statement
CREATE DIRECTORY). A table column indexed using the specified extractor policy is
expected to contain relative paths to individual files within the directory object, as shown in
the following example:
CREATE TABLE newsfeed (docid number,
articleLoc VARCHAR2(100));
INSERT INTO into newsfeed (docid, articleLoc) values
(1, 'article1.txt');
INSERT INTO newsfeed (docid, articleLoc) values
(2, 'folder/article2.txt');
To index documents that are accessed using HTTP protocol, create a extractor policy with
preferences that set the type attribute of the <Datastore> element to URL and that list one or
more hosts in the <Path> elements, as shown in the following excerpt:
<RDFCTXPreferences>
<Datastore type="URL">
<Path>http://cnn.com</Path>
<Path>http://abc.com</Path>
</Datastore>
</RDFCTXPreferences>
5-11
Chapter 5
Configuring the Calais Extractor type
The schema in which a semantic index for external documents is created must have
the necessary privileges to access the external objects, including access to any proxy
server used to access documents outside the firewall, as shown in the following
example:
-- Grant read access to the directory object for FILE data store --
grant read on directory EXTFILES_DIR to SEMUSR;
begin
dbms_network_acl_admin.assign_acl (
acl => 'network_docs.xml',
host => 'cnn.com',
lower_port => 1,
upper_port => 10000);
end;
/
External documents that are semantically indexed in the database may be in one of
the well-known formats such as Microsoft Word, RTF, and PDF. This takes advantage
of the Oracle Text capability to extract plain text version from formatted documents
using filters (see the CTX_DOC.POLICY_FILTER procedure, described in Oracle Text
Reference). To semantically index formatted documents, you must specify the name of
a CTX policy in the extractor preferences, as shown in the following excerpt:
<RDFCTXPreferences>
<Datastore type="FILE" filter="CTX_FILTER_POLICY">
<Path>EXTFILES_DIR</Path>
</Datastore>
</RDFCTXPreferences>
To do so, you must connect as SYSTEM (not SYS … AS SYSDBA) or another non-
SYS user with the DBA role, and configure the Calais extractor type with Web service
5-12
Chapter 5
Working with General Architecture for Text Engineering (GATE)
end point, the SOAP action, and the license key by setting corresponding parameters, as
shown in the following example:
begin
sem_rdfctx.set_extractor_param (
param_key => 'CALAIS_WS_ENDPOINT',
param_value => 'http://api1.opencalais.com/enlighten/calais.asmx',
param_desc => 'Calais web service end-point');
sem_rdfctx.set_extractor_param (
param_key => 'CALAIS_KEY',
param_value => '<Calais license key goes here>',
param_desc => 'Calais extractor license key');
sem_rdfctx.set_extractor_param (
param_key => 'CALAIS_WS_SOAPACTION',
param_value => 'http://clearforest.com/Enlighten',
param_desc => 'Calais web service SOAP Action');
end;
To enable access to a Web service outside the firewall, you must also set the parameter for
the proxy host, as in the following example:
begin
sem_rdfctx.set_extractor_param (
param_key => 'HTTP_PROXY',
param_value => 'www-proxy.example.com',
param_desc => 'Proxy server');
end;
You can use GATE to perform semantic indexing of documents stored in the database. The
extractor type mdsys.gatenlp_extractor is defined as a subtype of the
RDFCTX_EXTRACTOR type. The implementation of this extractor type sends an
unstructured document to a GATE engine over a TCP connection, receives corresponding
annotations, and converts them into RDF following a user-specified XML style sheet.
The requests for information extraction are handled by a server socket implementation, which
instantiates the GATE components and listens to extraction requests at a pre-determined
port. The host and the post for the GATE listener are recorded in the database, as shown in
the following example, for all instances of the mdsys.gatenlp_extractor type to use.
begin
sem_rdfctx.set_extractor_param (
param_key => 'GATE_NLP_HOST',
param_value => 'gateserver.example.com',
param_desc => 'Host for GATE NLP Listener ');
sem_rdfctx.set_extractor_param (
param_key => 'GATE_NLP_PORT',
param_value => '7687',
5-13
Chapter 5
Creating a New Extractor Type
5-14
Chapter 5
Creating a Local Semantic Index on a Range-Partitioned Table
end;
5-15
Chapter 5
Altering a Semantic Index
The following example creates a range-partitioned table and a local semantic index on
that table:
CREATE TABLE part_newsfeed (
docid number, article CLOB, cdate DATE)
partition by range (cdate)
(partition p1 values less than (to_date('01-Jan-2001')),
partition p2 values less than (to_date('01-Jan-2004')),
partition p3 values less than (to_date('01-Jan-2008')),
partition p4 values less than (to_date('01-Jan-2012'))
);
Note that every partition of the local semantic index will have content generated for the
same set of policies. When you use the ALTER INDEX statement on a local index to
add or drop policies associated with a semantic index partition, you should try to keep
the same set of policies associated with each partition. You can achieve this result by
using ALTER INDEX statements in a loop over the set of partitions. (For more
information about altering semantic indexes, see Altering a Semantic Index,)
5-16
Chapter 5
Passing Extractor-Specific Parameters in CREATE INDEX and ALTER INDEX
5-17
Chapter 5
Metadata Views for Semantic Indexing
5-18
Chapter 5
Metadata Views for Semantic Indexing
5-19
Chapter 5
Default Style Sheet for GATE Extractor Output
5-20
Chapter 5
Default Style Sheet for GATE Extractor Output
<xsl:param name="docbase">http://xmlns.oracle.com/rdfctx/</xsl:param>
<xsl:param name="docident">0</xsl:param>
<xsl:param name="classpfx">
<xsl:value-of select="$docbase"/>
<xsl:text>class/</xsl:text>
</xsl:param>
<xsl:template match="/">
<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#"
xmlns:owl="http://www.w3.org/2002/07/owl#"
xmlns:prop="http://xmlns.oracle.com/rdfctx/property/">
<xsl:for-each select="AnnotationSet/Annotation">
<rdf:Description>
<xsl:attribute name="rdf:about">
<xsl:value-of select="$docbase"/>
<xsl:text>docref/</xsl:text>
<xsl:value-of select="$docident"/>
<xsl:text>/</xsl:text>
<xsl:value-of select="@Id"/>
</xsl:attribute>
<xsl:for-each select="./Feature">
<xsl:choose>
<xsl:when test="./Name[text()='majorType']">
<rdf:type>
<xsl:attribute name="rdf:resource">
<xsl:value-of select="$classpfx"/>
<xsl:text>major/</xsl:text>
<xsl:value-of select="translate(./Value/text(),
' ', '#')"/>
</xsl:attribute>
</rdf:type>
</xsl:when>
<xsl:when test="./Name[text()='minorType']">
<xsl:element name="prop:hasMinorType">
<xsl:attribute name="rdf:resource">
<xsl:value-of select="$docbase"/>
<xsl:text>minorType/</xsl:text>
<xsl:value-of select="translate(./Value/text(),
' ', '#')"/>
</xsl:attribute>
</xsl:element>
</xsl:when>
<xsl:when test="./Name[text()='kind']">
<xsl:element name="prop:hasKind">
<xsl:attribute name="rdf:resource">
<xsl:value-of select="$docbase"/>
<xsl:text>kind/</xsl:text>
<xsl:value-of select="translate(./Value/text(),
' ', '#')"/>
</xsl:attribute>
</xsl:element>
</xsl:when>
<xsl:when test="./Name[text()='locType']">
<xsl:element name="prop:hasLocType">
<xsl:attribute name="rdf:resource">
<xsl:value-of select="$docbase"/>
<xsl:text>locType/</xsl:text>
<xsl:value-of select="translate(./Value/text(),
' ', '#')"/>
</xsl:attribute>
</xsl:element>
5-21
Chapter 5
Default Style Sheet for GATE Extractor Output
</xsl:when>
<xsl:when test="./Name[text()='entityValue']">
<xsl:element name="prop:hasEntityValue">
<xsl:attribute name="rdf:datatype">
<xsl:text>
http://www.w3.org/2001/XMLSchema#string
</xsl:text>
</xsl:attribute>
<xsl:value-of select="./Value/text()"/>
</xsl:element>
</xsl:when>
<xsl:otherwise>
<xsl:element name="prop:has{translate(
substring(./Name/text(),1,1),
'abcdefghijklmnopqrstuvwxyz',
'ABCDEFGHIJKLMNOPQRSTUVWXYZ')}{
substring(./Name/text(),2)}">
<xsl:attribute name="rdf:datatype">
<xsl:text>
http://www.w3.org/2001/XMLSchema#string
</xsl:text>
</xsl:attribute>
<xsl:value-of select="./Value/text()"/>
</xsl:element>
</xsl:otherwise>
</xsl:choose>
</xsl:for-each>
</rdf:Description>
</xsl:for-each>
</rdf:RDF>
</xsl:template>
</xsl:stylesheet>
5-22
6
Fine-Grained Access Control for RDF Data
The default control of access to the Oracle Database semantic data store is at the model
level: the owner of a model can grant select, delete, and insert privileges on the model to
other users by granting appropriate privileges on the view named RDFM_<model_name>.
However, for applications with stringent security requirements, you can enforce a fine-grained
access control mechanism by using the Oracle Label Security option of Oracle Database.
Oracle Label Security (OLS) for RDF data allows sensitivity labels to be associated with
individual triples stored in an RDF model. For each query, access to specific triples is granted
by comparing their labels with the user's session labels. This triple-level security option
provides a thin layer of RDF-specific capabilities on top of the Oracle Database native
support for label security.
For information about using OLS, see Oracle Label Security Administrator's Guide.
• Triple-Level Security
The triple-level security option provides a thin layer of RDF-specific capabilities on top of
the Oracle Database native support for label security.
6-1
Chapter 6
Triple-Level Security
This does not prevent a low-privileged (UNCLASSIFIED) user from inserting the triple
(<urn:X>,<urn:P>,<urn:Y>, "UNCLASSIFIED"). Because SPARQL and SEM_MATCH
do not return label information, a query will return both rows (assuming the user has
appropriate privileges), and it will not be easy to distinguish between the TOPSECRET
and UNCLASSIFIED triples.
To filter out such low-security triples when querying the semantic models, you can one
or more the following options with SEM_MATCH:
• POLICY_NAME specifies the OLS policy name.
• MIN_LABEL specifies the minimum label for triples that are included in the query
In other words, every triple that contains a label that is strictly dominated by MIN_LABEL
is not included in the query. For example, to filter out the "UNCLASSIFIED" triple, you
could use the following query (assuming the OLS policy name is DEFENSE and that the
query user has read privileges over UNCLASSIFIED and TOPSECRET triples):
SELECT s,p,y FROM table(sem_match('{?s ?p ?y}' ,
sem_models(TEST'), null, null, null, null,
'MIN_LABEL=TOPSECRET POLICY_NAME=DEFENSE',
null, null, ‘FGAC_ADMIN’, 'OLS_NET'));
Note that the filtering in the preceding example occurs in addition to the security
checks performed by the native OLS software.
After a triple has been inserted, you can view and update the label information through
the CTXT1 column in the application table for the semantic model (assuming that you
have the WRITEUP and WRITEDOWN privileges to modify the labels).
There are no restrictions on who can perform inference or bulk loading with triple-level
security; all of the inferred or bulk loaded triples are inserted with the user's session
row label. Note that you can change the session labels by using the SA_UTL package.
(For more information about SA_UTL, see Oracle Label Security Administrator's
Guide.)
• Fine-Grained Security for Inferred Data and Ladder-Based Inference (LBI)
• Extended Example: Applying OLS Triple-Level Security on Semantic Data
These newly inferred relationships are derived solely based on the information that the
user is allowed to access. These relationships do, however, share the same data label.
This is understandable because a SEM_APIS.CREATE_ENTAILMENT call can be
viewed as a three-step process: read operation, followed by a logical inference
computation, followed by a write operation. The read operation gathers information
upon which inference computation is based, and it is restricted by access privileges,
the user's label, and the data labels; the logical inference computation step is purely
mathematical; and the final write of inferred information into the entailed graph is no
6-2
Chapter 6
Triple-Level Security
different from the same user asserting some new facts (which happen to be calculated by the
previous step).
Having all inferred assertions tagged with a single label is sufficient if a user only owns a
single label. It is, however, not fine-grained enough when there are multiple labels owned by
the same user, which is a common situation in a multitenancy setup.
For example, assume a user sets its user label and data label as TopSecret, invokes
SEM_APIS.CREATE_ENTAILMENT, switches to a weaker label named Secret, and finally
performs a SPARQL query. The query will not be able to see any of those newly inferred
relationships because they were all tagged with the TopSecret label. However, if the user
switches back to the TopSecret label, now every single inferred relationship is visible. It is "all
or nothing" (that is, all visible or nothing visible) as far as inferred relationships are
concerned.
When multiple labels are available for use by a given user, you normally want to assign
different labels to different inferred relationships. There are two ways to achieve this goal:
• Invoking SEM_APIS.CREATE_ENTAILMENT Multiple Times
• Using Ladder-Based Inference (LBI)
Ladder-based inference, effective with Oracle Database 12c Release 1 (12.1), is probably the
simpler and more convenient of the two approaches.
Now, SCOTT switches the label to Label2, runs the inference a second time, and tags the
newly inferred triples with Label2. Obviously, if Label2 is dominated by Label1, then no new
triples will be inferred because Label2 cannot see anything beyond what Label1 is allowed to
see. If Label2 is not dominated by Label1, the read step of the inference process will probably
see a different set of triples, and consequently the inference call can produce some new
triples, which will in turn be tagged with Label2.
For the purpose of this example, assume the following condition holds true: for any 1 <= i < j
<= n, Labelj is not dominated by Labeli.
EXECUTE sa_utl.set_label('defense',char_to_label('defense','Label2'));
EXECUTE sa_utl.set_row_label('defense',char_to_label('defense','Label2'));
EXECUTE sem_apis.create_entailment('inf', sem_models('contracts'),
sem_rulebases('owlprime'), SEM_APIS.REACH_CLOSURE, null, 'ENTAIL_ANYWAY=T',
network_owner=>'FGAC_ADMIN', network_name=>'OLS_NET');
SCOTT continues the preceding actions using the rest of the labels in the label sequence:
Label1, Label2, ..., Labeln. The last step will be as follows:
EXECUTE sa_utl.set_label('defense',char_to_label('defense','Labeln'));
EXECUTE sa_utl.set_row_label('defense',char_to_label('defense','Labeln'));
EXECUTE sem_apis.create_entailment('inf', sem_models('contracts'),
6-3
Chapter 6
Triple-Level Security
After all these actions are performed, the inference graph probably consists of triples
tagged with various different labels.
6-4
Chapter 6
Triple-Level Security
d. Connect as the security administrator and set up network sharing for users a, b, and
c.
CONNECT fgac_admin/<password-for- fgac_admin>;
EXECUTE
sem_apis.enable_network_sharing(network_owner=>'FGAC_ADMIN',network_name=>'OLS_
NET');
EXECUTE
sem_apis.grant_network_access_privs(network_owner=>'FGAC_ADMIN',network_name=>'
OLS_NET', network_user=>'A');
EXECUTE
sem_apis.grant_network_access_privs(network_owner=>'FGAC_ADMIN',network_name=>'
OLS_NET', network_user=>'B');
EXECUTE
sem_apis.grant_network_access_privs(network_owner=>'FGAC_ADMIN',network_name=>'
OLS_NET', network_user=>'C');
f. Create three security levels (For simplicity, compartments and groups are omitted.)
EXECUTE SA_COMPONENTS.CREATE_LEVEL('defense',3000,'TS','TOP SECRET');
EXECUTE SA_COMPONENTS.CREATE_LEVEL('defense',2000,'SE','SECRET');
EXECUTE SA_COMPONENTS.CREATE_LEVEL('defense',1000,'UN','UNCLASSIFIED');
6-5
Chapter 6
Triple-Level Security
EXECUTE SA_USER_ADMIN.SET_USER_LABELS('defense','fgac_admin','TS');
EXECUTE SA_USER_ADMIN.SET_USER_PRIVS('defense','FGAC_ADMIN', 'full');
Note that the application table now has an extra column named CTXT1:
CONNECT a/<password-for-a>
DESCRIBE project_tpl;
Name Null? Type
----------------------------------------- -------- --------------------------
TRIPLE PUBLIC.SDO_RDF_TRIPLE_S
CTXT1 NUMBER(10)
6-6
Chapter 6
Triple-Level Security
6 rows selected.
SELECT count(1) from fgac_admin.ols_net#rdfm_project;
6
6-7
Chapter 6
Triple-Level Security
connect a/<password-for-a>
-- Repeat the preceding query
SQL> /
As expected, different users (with different labels) can see different sets of triples
in the project RDF graph.
6. Query the same data as user C using different labels.
exec sa_utl.set_label('defense',char_to_label('defense','SE'));
exec sa_utl.set_row_label('defense',char_to_label('defense','SE'));
The same query used in the preceding step produces just 6 matches with label set
to SE:
urn:A urn:expenseReportAmount 100
urn:A urn:hasManager urn:B
urn:B urn:expenseReportAmount 200
urn:B urn:hasManager urn:C
6-8
Chapter 6
Triple-Level Security
urn:expenseReportAmount http://www.w3.org/2000/01/rdf-schema#subPropertyOf
urn:projExp
urn:proj1 urn:deadline 2012-12-25
6 rows selected.
If user C picks the weakest label ("unclassified"), then user C sees even less
exec sa_utl.set_label('defense',char_to_label('defense','UN'));
exec sa_utl.set_row_label('defense',char_to_label('defense','UN'));
The same query used in the preceding step produces just 4 matches:
urn:A urn:expenseReportAmount 100
urn:A urn:hasManager urn:B
urn:B urn:hasManager urn:C
urn:expenseReportAmount http://www.w3.org/2000/01/rdf-schema#subPropertyOf
urn:projExp
If user C wants to run the query only against triples/quads with data label that dominates
"Secret":
-- First set the label back
exec sa_utl.set_label('defense',char_to_label('defense','TS'));
exec sa_utl.set_row_label('defense',char_to_label('defense','TS'));
select lpad(nvl(g, ' '), 20) || ' ' || s || ' ' || p || ' ' || o
from table(sem_match('select * where { graph ?g { ?s ?p ?o }}',
sem_models('project'),
null,
null,
null,
null,
'MIN_LABEL=SE POLICY_NAME=DEFENSE GRAPH_MATCH_UNNAMED=T',
null,
null,
'FGAC_ADMIN',
'OLS_NET'))
order by g, s, p, o;
6 rows selected.
The same query can be executed as User A. However, no matches are returned, as
expected.
You can delete semantic data when OLS is enabled for RDF. In the following example,
assume that SEM_RDFSA.APPLY_OLS_POLICY has been executed successfully, and that
the same user setup and label designs are used as in the preceding example.
-- First, create a test model as user A and grant access to users B and C
connect a/<password-for-a>
6-9
Chapter 6
Triple-Level Security
connect fgac_admin/<password-for-fgac_admin>
-- Now model creation (after OLS policy has been applied) can go through
connect a/<password-for-a>
EXECUTE sem_apis.create_sem_model('test', 'test_tpl',
'triple',network_owner=>'FGAC_ADMIN',network_name=>'OLS_NET');
-- Now User B can see both triples in the application table as well as the model
view
set numwidth 20
SELECT * from a.test_tpl;
-- User A can only see one triple due to A's label assignment, as expected.
6-10
Chapter 6
Triple-Level Security
COMMIT;
Commit complete.
-- Note that the preceding delete does not affect the same assertion made by B.
connect b/<password-for-b>
SELECT * from a.test_tpl;
1 row deleted.
6-11
7
RDF Semantic Graph Support for Apache
Jena
RDF Semantic Graph support for Apache Jena (also referred to here as support for Apache
Jena) provides a Java-based interface to Oracle Graph RDF Semantic Graph by
implementing the well-known Jena Graph, Model, and DatasetGraph APIs.
Note:
This feature was previously referred to as the Jena Adapter for Oracle Database
and the Jena Adapter.
Support for Apache Jena extends the semantic data management capabilities of Oracle
Database RDF/OWL.
(Apache Jena is an open source framework. For license and copyright conditions, see
http://www.apache.org/licenses/ and http://www.apache.org/licenses/LICENSE-2.0.)
The DatasetGraph APIs are for managing named graph data, also referred to as quads. In
addition, RDF Semantic Graph support for Apache Jena provides network analytical functions
on top of semantic data through integrating with the Oracle Spatial Network Data Model
Graph feature.
This chapter assumes that you are familiar with major concepts explained in RDF Semantic
Graph Overview and OWL Concepts . It also assumes that you are familiar with the overall
capabilities and use of the Jena Java framework. For information about the Jena framework,
see http://jena.apache.org/, especially the Jena Documentation page. If you use the
network analytical function, you should also be familiar with the Network Data Model Graph
feature, which is documented in Oracle Spatial Topology and Network Data Model
Developer's Guide.
Note:
The current RDF Semantic Graph support for Apache Jena release has been tested
against Apache Jena 3.1.0, and it supports the RDF schema-private networks
environment in Release 19c databases. Because of the nature of open source
projects, you should not use this support for Apache Jena with later versions of
Jena.
Apache Joseki support has been deprecated, although it still is part of the OTN kit
distribution for adapter version 3.1.0 with support for Release 19c databases.
References to Joseki have been removed from this book for Release 19c, but you
can find information about Joseki in previous versions of the book.
7-1
Chapter 7
7-2
Chapter 7
Setting Up the Software Environment
7-3
Chapter 7
Setting Up the Software Environment
|-- joseki
|-- joseki_web_app
|-- protege_plugin
|-- README
|-- sparqlgateway_web_app
8. If the SPARQL service to support the SPARQL protocol is not set up, set it up as
explained in Setting Up the SPARQL Service.
After setting up the software environment, ensure that your RDF Semantic Graph
environment can enable you to use the support for Apache Jena to perform queries,
as explained in Setting Up the RDF Semantic Graph Environment.
• If You Used a Previous Version of the Support for Apache Jena
7.1.1 If You Used a Previous Version of the Support for Apache Jena
If you used a previous version of the support for Apache Jena, you must drop all
functions/procedure installed by previous Jena adapter in user schemas. Installing the
new kit will automatically load the updated functions and procedures, which are
compatible with new RDF schema private networks in 19c, and with the support in
previous releases.
Connect to the user schema that you have used with the previous Jena adapter and
execute the following commands to clean the internal functions and procedures.
(Some of the functions and procedures referenced in these commands might not exist
in the previous installation, so any failed commands can be ignored.)
7-4
Chapter 7
Setting Up the SPARQL Service
Although there are several ways to deploy applications in WebLogic Server, this topic refers
to the autodeploy option.
Note:
If you want to deploy Fuseki in Apache Tomcat instead of WebLogic Server, see
Deploying Fuseki in Apache Tomcat.
EXECUTE SEM_APIS.CREATE_SEM_NETWORK('RDFTBS',
options=>'MODEL_PARTITIONING=BY_HASH_P MODEL_PARTITIONS=16',
network_owner=>'RDFUSER', network_name=>'SAMPLE_NET' );
b. Edit file config.ttl, and add an oracle:Dataset definition using a model named
M_NAMED_GRAPHS. The following snippet shows the configuration. The
oracle:allGraphs predicate denotes that the SPARQL service endpoint will serve
queries using all graphs stored in the M_NAMED_GRAPHS model.
7-5
Chapter 7
Setting Up the SPARQL Service
c. Link the oracle dataset in the service section of the Fuseki configuration file:
fuseki:dataset <#oracle> ;
.
5. Go to the autodeploy directory of WebLogic Server and copy files, as follows. (For
information about automatically deploying applications in development domains,
see: http://docs.oracle.com/cd/E24329_01/web.1211/e24443/autodeploy.htm)
7-6
Chapter 7
Setting Up the SPARQL Service
cd <domain_name>/autodeploy
cp -rf /tmp/jena_adapter/fuseki_web_app/fuseki.war <domain_name>/autodeploy
SELECT ?g ?s ?p ?o
WHERE
{ GRAPH ?g { ?s ?p ?o} }
The result should be an HTML table with four columns and two sets of result bindings.
• Client Identifiers
• Using OLTP Compression for Application Tables and Staging Tables
• N-Triples Encoding for Non-ASCII Characters
To start the tracing of only RDF Semantic Graph support for Apache Jena-related activities on
the database side, you can use the DBMS_MONITOR.CLIENT_ID_TRACE_ENABLE
procedure. For example:
SQL> EXECUTE DBMS_MONITOR.CLIENT_ID_TRACE_ENABLE('JenaAdapter', true, true);
7.2.2 Using OLTP Compression for Application Tables and Staging Tables
By default, the support for Apache Jena creates the application tables and any staging tables
(the latter used for bulk loading, as explained in Bulk Loading Using RDF Semantic Graph
Support for Apache Jena) using basic table compression with the following syntax:
CREATE TABLE .... (... column definitions ...) ... compress;
7-7
Chapter 7
Setting Up the RDF Semantic Graph Environment
However, if you are licensed to use the Oracle Advanced Compression option no the
database, you can set the following JVM property to turn on OLTP compression, which
compresses data during all DML operations against the underlying application tables
and staging tables:
-Doracle.spatial.rdf.client.jena.advancedCompression="compress for oltp"
3. Create a database user (for connecting to the database to use the semantic
network and the support for Apache Jena). For example:
CREATE USER rdfusr IDENTIFIED BY <password-for-udfusr>
DEFAULT TABLESPACE rdf_users;
7-8
Chapter 7
SEM_MATCH and RDF Semantic Graph Support for Apache Jena Queries Compared
6. To use the support for Apache Jena with your own semantic data, perform the
appropriate steps to store data, create a model, and create database indexes, as
explained in Quick Start for Using Semantic Data. Then perform queries by compiling and
running Java code; see Example Queries Using RDF Semantic Graph Support for
Apache Jena for information about example queries.
To use the support for Apache Jena with supplied example data, see Example Queries
Using RDF Semantic Graph Support for Apache Jena.
These two queries perform the same kind of functions; however, there are some important
differences. Query 1 (SEM_MATCH-based):
• Reads all triples out of Test_Model.
• Does not differentiate among URI, bNode, plain literals, and typed literals, and it does not
handle long literals.
• Does not unescape certain characters (such as '\n').
Query 2 (SPARQL query executed through the support for Apache Jena) also reads all triples
out of Test_Model (assume it executed a call to ModelOracleSem referring to the same
underlying Test_Model). However, Query 2:
• Reads out additional columns (as opposed to just the s, p, and o columns with the
SEM_MATCH table function), to differentiate URI, bNodes, plain literals, typed literals,
and long literals. This is to ensure proper creation of Jena Node objects.
• Unescapes those characters that are escaped when stored in Oracle Database
Blank node handling is another difference between the two approaches:
• In a SEM_MATCH-based query, blank nodes are always treated as constants.
• In a SPARQL query, a blank node that is not wrapped inside < and > is treated as a
variable when the query is executed through the support for Apache Jena. This matches
the SPARQL standard semantics. However, a blank node that is wrapped inside < and >
7-9
Chapter 7
Retrieving User-Friendly Java Objects from SEM_MATCH or SQL-Based Query Results
is treated as a constant when the query is executed, and the support for Apache
Jena adds a proper prefix to the blank node label as required by the underlying
data modeling.
The maximum length for the name of a semantic model created using the support for
Apache Jena API is 22 characters.
7-10
Chapter 7
Retrieving User-Friendly Java Objects from SEM_MATCH or SQL-Based Query Results
while (rs.next()) {
node = OracleSemIterator.retrieveNodeFromRS(rs, iStartColPos,
OracleSemQueryPlan.CONST_FIVE_COL, translator);
System.out.println("Result " + node.getClass().getName() + " = " + node + " " +
rs.getString(1));
}
7-11
Chapter 7
Retrieving User-Friendly Java Objects from SEM_MATCH or SQL-Based Query Results
Example 7-2 Hybrid Query Mixing SEM_MATCH with Regular SQL Constructs
Example 7-2 uses the OracleSemIterator.retrieveNodeFromRS API to construct a
Jena object by reading the five consecutive columns (in the exact order of value type,
literal type, language type, long value, and value name), and by performing the
necessary unescaping and object instantiations. This example bypasses
SEM_MATCH and directly joins the graph view with MDSYS.RDF_VALUE$.
iStartColPos = 1;
queryString = "select g$RDFVTYP, g, count(1) as cnt "
+ " from table(sem_match('{ GRAPH ?g { ?s ?p ?
o . } }',sem_models('tgraph'),null,null,null,null,null)) "
+ " group by g$RDFVTYP, g";
In Example 7-2:
• The helper function executeQuery in the Oracle class is used to run the SQL
statement, and the OracleSemIterator.retrieveNodeFromRS API (also used in
Example 7-1) is used to construct Jena objects.
• Only two columns are used in the output: value type (g$RDFVTYP) and value
name (g), it is known that this g variable can never be a literal RDF resource.
• The column order is significant. For a two-column variable, the first column must
be the value type and the second column must be the value name.
Example 7-3 SEM_MATCH Query
Example 7-3 runs a SEM_MATCH query and constructs an iterator (instance of
OracleSemIterator) that returns a list of Jena objects.
queryString = "select g$RDFVTYP, g, s$RDFVTYP, s, p$RDFVTYP, p,
o$RDFVTYP,o$RDFLTYP,o$RDFLANG,o$RDFCLOB,o "
+ " from table(sem_match('{ GRAPH ?g { ?s ?p ?
o . } }',sem_models('tgraph'),null,null,null,null,null))";
7-12
Chapter 7
Optimized Handling of SPARQL Queries
while (osi.hasNext()) {
result = osi.next();
System.out.println("Result " + result.getClass().getName() + " = " + result);
}
In Example 7-3:
• OracleSemIterator takes in a JDBC result set. OracleSemIterator needs guidance on
parsing all the columns that represent the bind values of SPARQL variables. A guide is
simply a list of string values. Two constants have been defined to differentiate a 2-column
variable (for subject or predicate position) from a 5-column variable (for object position).
A translator is also required.
• Four variables are used in the output. The first three variables are not RDF literal
resources, so CONST_TWO_COL is used as their guide. The last variable can be an
RDF literal resource, so CONST_FIVE_COL is used as its guide.
• The column order is significant, and it must be as shown in the example.
7-13
Chapter 7
Optimized Handling of SPARQL Queries
In this case, the support for Apache Jena converts the inner UNION query into a single
SEM_MATCH table function, and then passes on the result set to the Jena ARQ query
engine for further evaluation.
7-14
Chapter 7
Additions to the SPARQL Syntax to Support Other Features
• Complex paths: p+, p*, p{0, n} where p could be an alternative, sequence, reverse path,
or property URI
Path expressions that cannot be captured in this grammar are not translated directly to SQL
by the support for Apache Jena, and they are answered using the Jena query engine.
The following example contains a code snippet using a property path expression with path
sequences:
String m = "PROP_PATH";
graph.add(Triple.create(Node.createURI("http://b"),
Node.createURI("http://p2"),
Node.createURI("http://c")));
graph.add(Triple.create(Node.createURI("http://c"),
Node.createURI("http://p5"),
Node.createURI("http://d")));
String query =
" SELECT ?s " +
" WHERE {?s (<http://p1>/<http://p2>/<http://p5>)+ <http://d>.}";
QueryExecution qexec =
QueryExecutionFactory.create(QueryFactory.create(query,
Syntax.syntaxARQ), model);
try {
ResultSet results = qexec.execSelect();
ResultSetFormatter.out(System.out, results);
}
finally {
if (qexec != null)
qexec.close();
}
OracleUtils.dropSemanticModel(oracle, m);
model.close();
• SQL Hints
• Using Bind Variables in SPARQL Queries
7-15
Chapter 7
Additions to the SPARQL Syntax to Support Other Features
In this example, t0,t1 refers to the first and second patterns in the query.
Note the slight difference in specifying hints when compared to SEM_MATCH. Due to
restrictions of namespace value syntax, a comma (,) must be used to separate t0 and
t1 (or other hint components) instead of a space.
For more information about using SQL hints, see Using the SEM_MATCH Table
Function to Query Semantic Data, specifically the material about the HINT0 keyword in
the options attribute.
SELECT ?x
WHERE { ... <some complex query> ... };
Query 2:
SELECT ?subject ?x
WHERE {?subject <urn:related> ?x .};
7-16
Chapter 7
Additions to the SPARQL Syntax to Support Other Features
The following example shows Query 2 with the syntax for using bind variables with the
support for Apache Jena:
PREFIX ORACLE_SEM_FS_NS: <http://oracle.com/semtech#no_fall_back,s2s>
PREFIX ORACLE_SEM_UEAP_NS: <http://oracle.com/semtech#x$RDFVID%20in(?,?,?)>
PREFIX ORACLE_SEM_UEPJ_NS: <http://oracle.com/semtech#x$RDFVID>
PREFIX ORACLE_SEM_UEBV_NS: <http://oracle.com/semtech#1,2,3>
SELECT ?subject ?x
WHERE {
?subject <urn:related> ?x
};
In the preceding SPARQL example of Query 2, the three integers 1, 2, and 3 come from
Query 1. You can use the oext:build-uri-for-id function to generate such internal integer
IDs for RDF resources. The following example gets the internal integer IDs from Query 1:
PREFIX oext: <http://oracle.com/semtech/jena-adaptor/ext/function#>
SELECT ?x (oext:build-uri-for-id(?x) as ?xid)
WHERE { ... <some complex query> ... };
The values of ?xid have the form of <rdfvid:integer-value>. The application can strip out the
angle brackets and the "rdfvid:" strings to get the integer values and pass them to Query 2.
Consider another case, with a single query structure but potentially many different constants.
For example, the following SPARQL query finds the hobby for each user who has a hobby
and who logs in to an application. Obviously, different users will provide different <uri> values
to this SPARQL query, because users of the application are represented using different URIs.
SELECT ?hobby
WHERE { <uri> <urn:hasHobby> ?hobby };
One approach, which would not use bind variables, is to generate a different SPARQL query
for each different <uri> value. For example, user Jane Doe might trigger the execution of the
following SPARQL query:
7-17
Chapter 7
Additions to the SPARQL Syntax to Support Other Features
Where pred reflects the WHERE clause content to be appended to the query. For
example:
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX ORACLE_SEM_AP_NS:<http://www.oracle.com/semtech#label$RDFLANG='fr'>
SELECT DISTINCT ?inst ?label
WHERE { ?inst a <http://someCLass>. ?inst rdfs:label ?label . }
ORDER BY (?label) LIMIT 20
In this example, a restriction is added to the query that the language type of the label
variable must be 'fr'.
7-18
Chapter 7
Additions to the SPARQL Syntax to Support Other Features
Where option reflects a query option (or multiple query options delimited by commas) to be
appended to the query. For example:
PREFIX ORACLE_SEM_FS_NS:
<http://oracle.com/semtech#timeout=3,dop=4,INF_ONLY,ORDERED,ALLOW_DUP=T>
SELECT * WHERE {?subject ?property ?object }
7-19
Chapter 7
Additions to the SPARQL Syntax to Support Other Features
You can use the JOIN option (described in Additional Query Options) and the
SERVICE keyword in a federated query that uses the support for Apache Jena. For
example, assume the following query:
SELECT ?s ?s1 ?o
WHERE { ?s1 ?p1 ?s .
{
SERVICE <http://sparql.org/books> { ?s ?p ?o }
}
}
If the local query portion (?s1 ?p1 ?s,) is very selective, you can specify join=2, as
shown in the following query:
PREFIX ORACLE_SEM_FS_NS: <http://oracle.com/semtech#join=2>
SELECT ?s ?s1 ?o
WHERE { ?s1 ?p1 ?s .
{
SERVICE <http://sparql.org/books> { ?s ?p ?o }
}
}
7-20
Chapter 7
Additions to the SPARQL Syntax to Support Other Features
In this case, the local query portion (?s1 ?p1 ?s,) is executed locally against the Oracle
database. Each binding of ?s from the results is then pushed into the SERVICE part (remote
query portion), and a call is made to the service endpoint specified. Conceptually, this
approach is somewhat like nested loop join.
If the remote query portion (?s ?s1 ?o) is very selective, you can specify join=3, as shown in
the following query, so that the remote portion is executed first and results are used to drive
the execution of local portion:
PREFIX ORACLE_SEM_FS_NS: <http://oracle.com/semtech#join=3>
SELECT ?s ?s1 ?o
WHERE { ?s1 ?p1 ?s .
{
SERVICE <http://sparql.org/books> { ?s ?p ?o }
}
}
In this case, a single call is made to the remote service endpoint and each binding of ?s
triggers a local query. As with join=2, this approach is conceptually a nested loop based join,
but the difference is that the order is switched.
If neither the local query portion nor the remote query portion is very selective, then we can
choose join=1, as shown in the following query:
PREFIX ORACLE_SEM_FS_NS: <http://oracle.com/semtech#join=1>
SELECT ?s ?s1 ?o
WHERE { ?s1 ?p1 ?s .
{
SERVICE <http://sparql.org/books> { ?s ?p ?o }
}
}
In this case, the remote query portion and the local portion are executed independently, and
the results are joined together by Jena. Conceptually, this approach is somewhat like a hash
join.
For debugging or tracing federated queries, you can use the HTTP Analyzer in Oracle
JDeveloper to see the underlying SERVICE calls.
7-21
Chapter 7
Functions Supported in SPARQL Queries through RDF Semantic Graph Support for Apache Jena
To control the maximum size (in bytes) of the in-memory cache, use the
oracle.spatial.rdf.client.jena.cacheMaxSize system property. The default cache
maximum size is 1GB.
Midtier resource caching is most effective for queries using ORDER BY or DISTINCT
(or both) constructs, or queries with multiple projection variables. Midtier cache can be
combined with the other options specified in Additional Query Options.
If you want to pre-populate the cache with all of the resources in a model, use the
GraphOracleSem.populateCache or DatasetGraphOracleSem.populateCache method.
Both methods take a parameter specifying the number of threads used to build the
internal midtier cache. Running either method in parallel can significantly increase the
cache building performance on a machine with multiple CPUs (cores).
7-22
Chapter 7
Functions Supported in SPARQL Queries through RDF Semantic Graph Support for Apache Jena
The following examples use the upper-case and namespace functions. In these examples, the
prefix fn is <http://www.w3.org/2005/xpath-functions#> and the prefix afn is <http://
jena.hpl.hp.com/ARQ/function#>.
PREFIX fn: <http://www.w3.org/2005/xpath-functions#>
PREFIX afn: <http://jena.hpl.hp.com/ARQ/function#>
SELECT (fn:upper-case(?object) as ?object1)
WHERE { ?subject dc:title ?object }
Note:
In the preceding URL, note the spelling jena-adaptor, which is retained for
compatibility with existing applications and which must be used in queries. The
adapter spelling is used in regular text, to follow Oracle documentation style
guidelines.
• oext:upper-literal converts literal values (except for long literals) to uppercase. For
example:
PREFIX oext: <http://oracle.com/semtech/jena-adaptor/ext/function#>
SELECT (oext:upper-literal(?object) as ?object1)
WHERE { ?subject dc:title ?object }
• oext:lower-literal converts literal values (except for long literals) to lowercase. For
example:
PREFIX oext: <http://oracle.com/semtech/jena-adaptor/ext/function#>
SELECT (oext:lower-literal(?object) as ?object1)
WHERE { ?subject dc:title ?object }
• oext:build-uri-for-id converts the value ID of a URI, bNode, or literal into a URI form.
For example:
PREFIX oext: <http://oracle.com/semtech/jena-adaptor/ext/function#>
SELECT (oext:build-uri-for-id(?object) as ?object1)
WHERE { ?subject dc:title ?object }
7-23
Chapter 7
Functions Supported in SPARQL Queries through RDF Semantic Graph Support for Apache Jena
A set of functions (five in all) is used to implement a user-defined function that can be
referenced from SPARQL, because this aligns with the internal representation of an
RDF resource (in MDSYS.RDF_VALUE$). There are five major columns describing an
RDF resource in terms of its value, language, literal type, long value, and value type,
and these five columns can be selected out using SEM_MATCH. In this context, a
user-defined function simply converts one RDF resource that is represented by five
columns to another RDF resource.
These functions are defined as follows:
create or replace function my_strlen(rdfvtyp in varchar2,
rdfltyp in varchar2,
rdflang in varchar2,
rdfclob in clob,
value in varchar2
) return varchar2
as
7-24
Chapter 7
Functions Supported in SPARQL Queries through RDF Semantic Graph Support for Apache Jena
ret_val varchar2(4000);
begin
-- value
if (rdfvtyp = 'LIT') then
if (rdfclob is null) then
return length(value);
else
return dbms_lob.getlength(rdfclob);
end if;
else
-- Assign -1 for non-literal values so that application can
-- easily differentiate
return '-1';
end if;
end;
/
7-25
Chapter 7
Functions Supported in SPARQL Queries through RDF Semantic Graph Support for Apache Jena
as
ret_val varchar2(3);
begin
return 'LIT';
end;
/
User-defined functions can also accept a parameter of VARCHAR2 type. The following
five functions together define a my_shorten_str function that accepts an integer (in
VARCHAR2 form) for the substring length and returns the substring. (The substring in
this example is 12 characters, and it must not be greater than 4000 bytes.)
-- SPARQL query that returns the first 12 characters of literal values.
--
PREFIX ouext: <http://oracle.com/semtech/jena-adaptor/ext/user-def-function#>
SELECT (ouext:my_shorten_str(?object, "12") as ?obj1) ?subject
WHERE { ?subject dc:title ?object }
7-26
Chapter 7
SPARQL Update Support
arg in varchar2
) return varchar2
as
ret_val varchar2(4000);
begin
-- lang
if (rdfvtyp = 'LIT') then
return rdflang;
else
return null;
end if;
end;
/
7-27
Chapter 7
SPARQL Update Support
Note that Oracle Database does not keep any information about an empty named
graph. This implies if you invoke CREATE GRAPH <graph_name> without adding any
triples into this graph, then no additional rows in the application table or the underlying
RDF_LINK$ table will be created. To an Oracle database, you can safely skip the
CREATE GRAPH step, as is the case in Example 7-4.
Example 7-5 SPARQL Update with Insert and Delete Operations
Example 7-5 shows a SPARQL Update operation (from ARQ 2.8.8) involving multiple
insert and delete operations.
PREFIX : <http://example/>
CREATE GRAPH <http://example/graph> ;
INSERT DATA { :r :p 123 } ;
INSERT DATA { :r :p 1066 } ;
DELETE DATA { :r :p 1066 } ;
INSERT DATA {
GRAPH <http://example/graph> { :r :p 123 . :r :p 1066 }
} ;
DELETE DATA {
GRAPH <http://example/graph> { :r :p 123 }
}
Using the same data, running the SPARQL query SELECT ?g ?s ?p ?o where
{GRAPH ?g {?s ?p ?o}} generates the following response:
---------------------------------------------------------------------------------
----------------------------------------
| g | s | p |
o |
=================================================================================
========================================
| <http://example/graph> | <http://example/r> | <http://example/p> |
"1066"^^<http://www.w3.org/2001/XMLSchema#decimal> |
---------------------------------------------------------------------------------
----------------------------------------
7-28
Chapter 7
Analytical Functions for RDF Data
This support integrates the Network Data Model Graph logic with the underlying RDF data
structures. Therefore, to use analytical functions on RDF data, you must be familiar with the
Network Data Model Graph feature, which is documented in Oracle Spatial Topology and
Network Data Model Developer's Guide.
The required NDM Java libraries, including sdonm.jar and sdoutl.jar, are under the
directory $ORACLE_HOME/md/jlib. Note that xmlparserv2.jar (under $ORACLE_HOME/xdk/lib)
must be included in the classpath definition.
// An anonymous node
Node ano = Node.createAnon(new AnonId("m1"));
graph.commitTransaction();
HashMap<Node, Double> costMap = new HashMap<Node, Double>();
costMap.put(relL, Double.valueOf((double)0.5));
costMap.put(relD, Double.valueOf((double)1.5));
7-29
Chapter 7
Analytical Functions for RDF Data
costMap.put(relC, Double.valueOf((double)5.5));
graph.close();
oracle.dispose();
...
...
In Example 7-6:
• A GraphOracleSem object is constructed and a few triples are added to the
GraphOracleSem object. These triples describe several individuals and their
relationships including likes, dislikes, knows, and differs.
7-30
Chapter 7
Analytical Functions for RDF Data
7-31
Chapter 7
Analytical Functions for RDF Data
import java.io.*;
import java.util.*;
import org.apache.jena.graph.*;
import org.apache.jena.update.*;
import oracle.spatial.rdf.client.jena.*;
import oracle.spatial.rdf.client.jena.SemNetworkAnalyst;
import oracle.spatial.network.lod.LODGoalNode;
import oracle.spatial.network.lod.LODNetworkConstraint;
import oracle.spatial.network.lod.NetworkAnalyst;
import oracle.spatial.network.lod.PointOnNet;
import oracle.spatial.network.lod.LogicalSubPath;
/**
* This class implements a nearestNeighbors function on top of semantic data
* using public APIs provided in SemNetworkAnalyst and Oracle Spatial NDM
*/
public class TestNearestNeighbor
{
public static void main(String[] args) throws Exception
{
String szJdbcURL = args[0];
String szUser = args[1];
String szPasswd = args[2];
GraphOracleSem g = model.getGraph();
g.commitTransaction();
g.setDOP(4);
7-32
Chapter 7
Analytical Functions for RDF Data
if (lsps != null) {
for (int idx = 0; idx < lsps.length; idx++) {
LogicalSubPath lsp = lsps[idx];
Node[] nodePath = sna.processLogicalSubPath(lsp, nodeStart);
psOut.println("Path " + idx);
printNodeArray(nodePath, psOut);
}
}
g.close();
sna.close();
oracle.dispose();
}
7-33
Chapter 7
Analytical Functions for RDF Data
iFlag = 1 - iFlag;
}
}
}
Path 1
printNodeArray: full path starts
printNodeArray: full path item 0 = [n] http://my.com/A
printNodeArray: full path item 1 = [e] http://my.com/likes
printNodeArray: full path item 2 = [n] http://my.com/B
Path 2
printNodeArray: full path starts
printNodeArray: full path item 0 = [n] http://my.com/A
printNodeArray: full path item 1 = [e] http://my.com/knows
printNodeArray: full path item 2 = [n] http://my.com/D
Path 3
printNodeArray: full path starts
printNodeArray: full path item 0 = [n] http://my.com/A
printNodeArray: full path item 1 = [e] http://my.com/likes
printNodeArray: full path item 2 = [n] http://my.com/C
printNodeArray: full path item 3 = [e] http://my.com/likes
printNodeArray: full path item 4 = [n] http://my.com/E
Path 4
printNodeArray: full path starts
printNodeArray: full path item 0 = [n] http://my.com/A
printNodeArray: full path item 1 = [e] http://my.com/likes
printNodeArray: full path item 2 = [n] http://my.com/C
printNodeArray: full path item 3 = [e] http://my.com/likes
printNodeArray: full path item 4 = [n] http://my.com/F
Path 5
printNodeArray: full path starts
printNodeArray: full path item 0 = [n] http://my.com/A
printNodeArray: full path item 1 = [e] http://my.com/knows
printNodeArray: full path item 2 = [n] http://my.com/D
printNodeArray: full path item 3 = [e] http://my.com/likes
printNodeArray: full path item 4 = [n] http://my.com/H
7-34
Chapter 7
Support for Server-Side APIs
usage of generating a DOT file with contextual information, specifically the output from the
analytical functions used in Example 7-6.
nodeArray = sna.shortestPathDijkstra(nodeA, nodeD);
printNodeArray(nodeArray, psOut);
The generated output DOT file from the preceding example is straightforward, as shown in
the following example:
% cat Shortest_Path_A_to_D.gv
digraph { rankdir = LR; charset="utf-8";
You can also use methods in the SemNetworkAnalyst and GraphOracleSem classes to
produce more sophisticated visualization of the analytical function output.
You can convert the preceding DOT file into a variety of image formats. Figure 7-1 is an
image representing the information in the preceding DOT file.
7-35
Chapter 7
Support for Server-Side APIs
For comprehensive documentation of the API calls that support the available features,
see the RDF Semantic Graph support for Apache Jena reference information
(Javadoc). For additional information about the server-side features exposed by the
support for Apache Jena, see the relevant chapters in this manual.
• Virtual Models Support
• Connection Pooling Support
• Semantic Model PL/SQL Interfaces
• Inference Options
• PelletInfGraph Class Support Deprecated
Note:
Virtual model support through the support for Apache Jena is available only
with Oracle Database Release 11.2 or later.
ModelOracleSem defaultModel =
ModelOracleSem.createOracleSemModel(oracle, modelName);
7-36
Chapter 7
Support for Server-Side APIs
Node.createURI("mailto:alice@example")));
ModelOracleSem model = new ModelOracleSem(graph);
String queryString =
try {
ResultSet results = qexec.execSelect() ;
for ( ; results.hasNext() ; ) {
QuerySolution soln = results.nextSolution() ;
psOut.println("soln " + soln);
}
}
finally {
qexec.close() ;
}
OracleUtils.dropSemanticModel(oracle, modelName);
OracleUtils.dropSemanticModel(oracle, m1);
oracle.dispose();
You can also use the GraphOracleSem constructor to create a virtual model, as in the
following example:
GraphOracleSem graph = new GraphOracleSem(oracle, modelName, attachment, true);
In this example, the fourth parameter (true) specifies that a virtual model needs to be created
for the specified modelName and attachment.
The following example sets up an OraclePool object with five (5) initial connections.
public static void main(String[] args) throws Exception
{
String szJdbcURL = args[0];
String szUser = args[1];
String szPasswd = args[2];
String szModelName = args[3];
7-37
Chapter 7
Support for Server-Side APIs
System.out.println("Creating OraclePool");
OraclePool op = new OraclePool(szJdbcURL, szUser, szPasswd, prop,
"OracleSemConnPool");
System.out.println("Done creating OraclePool");
OracleUtils.dropSemanticModel(oracle, szModelName);
For information about these PL/SQL utility subprograms, see the reference information
in SEM_APIS Package Subprograms. For information about the corresponding Java
7-38
Chapter 7
Support for Server-Side APIs
class and methods, see the RDF Semantic Graph support for Apache Jena API Reference
documentation (Javadoc).
7-39
Chapter 7
Support for Server-Side APIs
String insertString =
" PREFIX my: <http://my.com/> " +
" PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> " +
" INSERT DATA " +
" { GRAPH my:G1 { my:I1 rdf:type my:C1 . " +
" my:I2 rdf:type my:C2 . " +
" } " +
" }; " +
" INSERT DATA " +
" { GRAPH my:G2 { my:J1 rdf:type my:C3 . " +
" } " +
" } ";
UpdateAction.parseExecute(insertString, dataset);
dataset.close();
}
String queryString =
7-40
Chapter 7
Support for Server-Side APIs
ResultSetFormatter.out(psOut, results);
dsgos.close();
oracle.dispose();
}
}
---------------------------------------------------------------------------------------
-----------------------------
| g | s |
p | o |
=======================================================================================
=============================
| <http://my.com/G1> | <http://my.com/I2> | <http://www.w3.org/1999/02/22-rdf-syntax-
ns#type> | <http://my.com/C3> |
| <http://my.com/G1> | <http://my.com/I2> | <http://www.w3.org/1999/02/22-rdf-syntax-
ns#type> | <http://my.com/C2> |
| <http://my.com/G1> | <http://my.com/I2> | <http://www.w3.org/1999/02/22-rdf-syntax-
ns#type> | <http://my.com/C4> |
| <http://my.com/G1> | <http://my.com/I1> | <http://www.w3.org/1999/02/22-rdf-syntax-
ns#type> | <http://my.com/C3> |
| <http://my.com/G1> | <http://my.com/I1> | <http://www.w3.org/1999/02/22-rdf-syntax-
ns#type> | <http://my.com/C1> |
| <http://my.com/G1> | <http://my.com/I1> | <http://www.w3.org/1999/02/22-rdf-syntax-
ns#type> | <http://my.com/C2> |
| <http://my.com/G1> | <http://my.com/I1> | <http://www.w3.org/1999/02/22-rdf-syntax-
ns#type> | <http://my.com/C4> |
| <http://my.com/G2> | <http://my.com/J1> | <http://www.w3.org/1999/02/22-rdf-syntax-
ns#type> | <http://my.com/C3> |
| <http://my.com/G2> | <http://my.com/J1> | <http://www.w3.org/1999/02/22-rdf-syntax-
ns#type> | <http://my.com/C4> |
---------------------------------------------------------------------------------------
-----------------------------
For information about using OWL inferencing, see Using OWL Inferencing.
7-41
Chapter 7
Bulk Loading Using RDF Semantic Graph Support for Apache Jena
try {
InputStream is = new FileInputStream(szIndFileName);
graph.getBulkUpdateHandler().prepareBulk(
is, // input stream
"http://example.com", // base URI
"RDF/XML", // data file type: can be RDF/XML, N-TRIPLE, etc.
"SEMTS", // tablespace
null, // flags
null, // listener
null // staging table name.
);
7-42
Chapter 7
Bulk Loading Using RDF Semantic Graph Support for Apache Jena
is.close();
}
catch (Throwable t) {
psOut.println("Hit exception " + t.getMessage());
}
}
graph.close();
oracle.dispose();
The code in Example 7-9, starting from creating a new Oracle object and ending with
disposing of the Oracle object, can be executed in parallel. Assume there is a quad-core CPU
and enough I/O capacity on the database hardware system; you can divide up all the data
files and save them into four separate directories: dir_1, dir_2, dir_3, and dir_4. Four Java
threads of processes can be started to work on those directories separately and concurrently.
(For more information, see Using prepareBulk in Parallel (Multithreaded) Mode.)
Example 7-10 Loading Data from the Staging Table into the Semantic Network
(completeBulk)
After all data files are processed, you can invoke, just once, the completeBulk method to load
the data from staging table into the semantic network, as shown in Example 7-10. Triples with
long literals will be loaded also.
graph.getBulkUpdateHandler().completeBulk(
null, // flags for invoking SEM_APIS.bulk_load_from_staging_table
null // staging table name
);
The prepareBulk method can also take a Jena model as an input data source, in which case
triples in that Jena model are loaded into the underlying staging table. For more information,
see the Javadoc.
Example 7-11 Using prepareBulk with RDFa
In addition to loading triples from Jena models and data files, the prepareBulk method
supports RDFa, as shown in Example 7-11. (RDFa is explained in http://www.w3.org/TR/
xhtml-rdfa-primer/.)
graph.getBulkUpdateHandler().prepareBulk(
rdfaUrl, // url to a web page using RDFa
"SEMTS", // tablespace
null, // flags
null, // listener
null // staging table name
);
To parse RDFa, the relevant java-rdfa libraries must be included in the classpath. No
additional setup or API calls are required. (For information about java-rdfa, see http://
www.rootdev.net/maven/projects/java-rdfa/ and the other topics there under Project
Information.)
Note that if the rdfaUrl is located outside a firewall, you may need to set the following HTTP
Proxy-related Java VM properties:
-Dhttp.proxyPort=...
-Dhttp.proxyHost=...
7-43
Chapter 7
Bulk Loading Using RDF Semantic Graph Support for Apache Jena
try {
InputStream is = new FileInputStream(szFileName);
// load NQUADS file into a staging table. This file can be gzipp'ed.
dataset.prepareBulk(
is, // input stream
"http://my.base/", // base URI
"N-QUADS", // data file type; can be "TRIG"
"SEMTS", // tablespace
null, // flags
null, // listener
null, // staging table name
false // truncate staging table before load
);
// Load quads from staging table into the dataset
dataset.completeBulk(
null, // flags; can be "PARSE PARALLEL_CREATE_INDEX PARALLEL=4
// mbv_method=shadow" on a quad core machine
null // staging table name
);
}
catch (Throwable t) {
System.out.println("Hit exception " + t.getMessage());
}
finally {
dataset.close();
oracle.dispose();
}
On a balanced hardware setup with 4 or more CPU cores, setting iMaxThreads to 8 (or
16) can improve significantly the speed of prepareBulk operation when there are
many data files to be processed.
7-44
Chapter 7
Bulk Loading Using RDF Semantic Graph Support for Apache Jena
7-45
Chapter 7
Bulk Loading Using RDF Semantic Graph Support for Apache Jena
{
long lStartTime = System.currentTimeMillis();
for (int idxFile = idx; idxFile < files.length; idxFile += threads) {
File file = files[idxFile];
try {
FileInputStream fis = new FileInputStream(file);
graph.getBulkUpdateHandler().prepareBulk(
fis,
"http://base.com/",
lang,
tbs,
null, // flags
new MyListener(psOut), // listener
null // table name
);
fis.close();
}
catch (Exception e) {
psOut.println("PrepareWorker: thread ["+getName()+"] error "+
e.getMessage());
}
psOut.println("PrepareWorker: thread ["+getName()+"] done to "
+ idxFile + ", file = " + file.toString()
+ " in (ms) " + (System.currentTimeMillis() - lStartTime));
}
}
7-46
Chapter 7
Bulk Loading Using RDF Semantic Graph Support for Apache Jena
lLastBatch = count;
}
}
graph.getBulkUpdateHandler().prepareBulk(
new FileInputStream(rdfDataFilename),
"http://base.com/", // base
lang, // data format, can be "N-TRIPLES" "RDF/XML" ...
tbs, // tablespace name
null, // flags
new MyListener(psOut), // call back to show progress and also process illegal
triples/quads
null, // tableName, if null use default names
false // truncate existing staging tables
);
graph.close();
oracle.dispose();
....
7-47
Chapter 7
Automatic Variable Renaming
}
}
Currently, this query does not fail, because a "smart scan" is performed and automatic
replacement is done on certain reserved variable names (or variable names that are
very long) before the query is sent to Oracle database for execution. The replacement
is based on a list of reserved keywords that are stored in the following file embedded
in sdordfclient.jar:
oracle/spatial/rdf/client/jena/oracle_sem_reserved_keywords.lst
This file contains over 100 entries, and you can edit the file to add entries if necessary.
The following are examples of SPARQL queries that use SQL or PL/SQL reserved
keywords as variables, and that will succeed because of automatic variable renaming:
• Query using SELECT as a variable name:
PREFIX foaf: <http://xmlns.com/foaf/0.1/>
select ?SELECT ?z
where
{ ?SELECT foaf:name ?y.
optional {?SELECT foaf:knows ?z.}
}
7-48
Chapter 7
JavaScript Object Notation (JSON) Format Support
graph.add(new Triple(
Node.createURI("http://ds1"),
Node.createURI("http://dp1"),
Node.createURI("http://do1")
)
);
graph.add(new Triple(
Node.createURI("http://ds2"),
Node.createURI("http://dp2"),
Node.createURI("http://do2")
)
);
graph.commitTransaction();
The preceding example can be changed as follows to query a remote SPARQL endpoint
instead of directly against an Oracle database. (If the remote SPARQL endpoint is outside a
firewall, then the HTTP Proxy probably needs to be set.)
Query q = QueryFactory.create("select ?s ?p ?o where {?s ?p ?o}",
Syntax.syntaxARQ);
QueryExecution qe = QueryExecutionFactory.sparqlService(sparqlURL, q);
To extend the first example in this section to named graphs, the following code snippet adds
two quads to the same Oracle model, executes a named graph-based SPARQL query, and
serializes the query output into JSON format:
7-49
Chapter 7
JavaScript Object Notation (JSON) Format Support
dsgos.add(new Quad(Node.createURI("http://g1"),
Node.createURI("http://s1"),
Node.createURI("http://p1"),
Node.createURI("http://o1")
)
);
dsgos.add(new Quad(Node.createURI("http://g2"),
Node.createURI("http://s2"),
Node.createURI("http://p2"),
Node.createURI("http://o2")
)
);
Query q1 = QueryFactory.create(
"select ?g ?s ?p ?o where { GRAPH ?g {?s ?p ?o} }");
dsgos.close();
oracle.dispose();
You can also get a JSON response through HTTP against a Fuseki-based SPARQL
endpoint, as in the following example. Normally, when executing a SPARQL query
against a SPARQL Web service endpoint, the Accept request-head field is set to be
application/sparql-results+xml. For JSON output format, replace the Accept
request-head field with application/sparql-results+json.
http://hostname:7001/fuseki/oracle?query=<URL_ENCODED_SPARQL_QUERY>&output=json
7-50
Chapter 7
Other Recommendations and Guidelines
(1 ?x 3 4) :p "w" .
(1 [:p :q] ( 2 ) ) .
7-51
Chapter 7
Other Recommendations and Guidelines
7-52
Chapter 7
Other Recommendations and Guidelines
// Build a model around the hybrid graph and wrap the model with Jena's
// OntModel
Model model = ModelFactory.createModelForGraph(hybridGraph);
OntModel ontModel = ModelFactory.createOntologyModel(ontModelSpec, model);
Note that any OntModel object created using OracleGraphWrapperForOntModel will not reflect
changes made to the underlying Oracle model by another process, through a separate
OntModel, or through a separate Oracle graph referencing the same underlying model. All
changes to an ontology should go through a single OntModel object and its underlying
OracleGraphWrapperForOntModel graph until the model or graph have been closed.
7-53
Chapter 7
Example Queries Using RDF Semantic Graph Support for Apache Jena
Note:
The javac and java commands must each be on a single command line.
7-54
Chapter 7
Example Queries Using RDF Semantic Graph Support for Apache Jena
Note:
All examples in the following subtopics are based on RDF metadata stored in the
MDSYS schema. For schema-private networks (supported starting in Oracle
Database 19c, the equivalent Java test files can be found in the OTN kit.
The main difference is that for schema-private networks, extra parameters defining
the network owner and network name should be used when creating the semantic
model objects.
7-55
Chapter 7
Example Queries Using RDF Semantic Graph Support for Apache Jena
model.getGraph().add(Triple.create(
Node.createURI("http://example.com/John"),
Node.createURI("http://example.com/fatherOf"),
Node.createURI("http://example.com/Mary")));
Query query = QueryFactory.create(
"select ?f ?k WHERE {?f <http://example.com/fatherOf> ?k .}");
QueryExecution qexec = QueryExecutionFactory.create(query, model);
ResultSet results = qexec.execSelect();
ResultSetFormatter.out(System.out, results, query);
model.close();
oracle.dispose();
}
}
The following are the commands to compile and run Example 7-17, as well as the
expected output of the java command.
javac -classpath ../jar/'*' Test.java
java -classpath ./:../jar/'*' Test jdbc:oracle:thin:@localhost:1521:orcl scott
<password-for-scott> M1
---------------------------------------------------------
| f | k |
=========================================================
| <http://example.com/John> | <http://example.com/Mary> |
---------------------------------------------------------
7-56
Chapter 7
Example Queries Using RDF Semantic Graph Support for Apache Jena
String queryString =
" SELECT ?subject ?prop ?object WHERE { ?subject ?prop ?object } ";
try {
int iTriplesCount = 0;
ResultSet results = qexec.execSelect() ;
for ( ; results.hasNext() ; ) {
QuerySolution soln = results.nextSolution() ;
iTriplesCount++;
}
System.out.println("Asserted triples count: " + iTriplesCount);
}
finally {
qexec.close() ;
}
query = QueryFactory.create(queryString) ;
qexec = QueryExecutionFactory.create(query,new ModelOracleSem(graph)) ;
try {
int iTriplesCount = 0;
ResultSet results = qexec.execSelect() ;
for ( ; results.hasNext() ; ) {
QuerySolution soln = results.nextSolution() ;
iTriplesCount++;
}
System.out.println("Asserted + Infered triples count: " + iTriplesCount);
}
finally {
qexec.close() ;
}
model.close();
OracleUtils.dropSemanticModel(oracle, szModelName);
oracle.dispose();
}
}
The following are the commands to compile and run Example 7-18, as well as the expected
output of the java command.
7-57
Chapter 7
Example Queries Using RDF Semantic Graph Support for Apache Jena
Note that this output reflects an older version of the LUBM ontology. The latest version
of the ontology has more triples.
GraphOracleSem g = modelDest.getGraph();
g.dropApplicationTableIndex();
7-58
Chapter 7
Example Queries Using RDF Semantic Graph Support for Apache Jena
else {
System.out.println("start bulk load");
g.getBulkUpdateHandler().addInBulk(
GraphUtil.findAll(model.getGraph()), tbs);
System.out.println("end size " + modelDest.size());
}
g.rebuildApplicationTableIndex();
The following are the commands to compile and run Example 7-19, as well as the expected
output of the java command.
javac -classpath ../jar/'*' Test7.java
java -classpath ./:../jar/'*' Test7 jdbc:oracle:thin:@localhost:1521:orcl scott
<password-for-scott> M1
start bulk load
end size 293
Asserted triples count: 293
Note that this output reflects an older version of the LUBM ontology. The latest version of the
ontology has more triples.
7-59
Chapter 7
Example Queries Using RDF Semantic Graph Support for Apache Jena
g.add(Triple.create(
Node.createURI("u:John"), Node.createURI("u:parentOf"),
Node.createURI("u:Mary")));
g.add(Triple.create(
Node.createURI("u:John"), Node.createURI("u:parentOf"),
Node.createURI("u:Jack")));
g.add(Triple.create(
Node.createURI("u:Mary"), Node.createURI("u:parentOf"),
Node.createURI("u:Jill")));
String queryString =
" SELECT ?s ?o ?gkid " +
" WHERE { ?s <u:parentOf> ?o . OPTIONAL {?o <u:parentOf> ?gkid }} ";
try {
int iMatchCount = 0;
ResultSet results = qexec.execSelect() ;
ResultSetFormatter.out(System.out, results, query);
}
finally {
qexec.close() ;
}
model.close();
OracleUtils.dropSemanticModel(oracle, szModelName);
oracle.dispose();
}
}
The following are the commands to compile and run Example 7-20, as well as the
expected output of the java command.
javac -classpath ../jar/'*' Test8.java
java -classpath ./:../jar/'*' Test8 jdbc:oracle:thin:@localhost:1521:orcl scott
<password-for-scott> M1
----------------------------------
| s | o | gkid |
==================================
| <u:John> | <u:Mary> | <u:Jill> |
| <u:Mary> | <u:Jill> | |
| <u:John> | <u:Jack> | |
----------------------------------
7-60
Chapter 7
Example Queries Using RDF Semantic Graph Support for Apache Jena
g.add(Triple.create(Node.createURI("u:John"), Node.createURI("u:parentOf"),
Node.createURI("u:Mary")));
g.add(Triple.create(Node.createURI("u:John"), Node.createURI("u:parentOf"),
Node.createURI("u:Jack")));
g.add(Triple.create(Node.createURI("u:Mary"),
Node.createURI("u:parentOf"),
Node.createURI("u:Jill")));
String queryString =
" SELECT ?s ?o ?gkid " +
" WHERE { ?s <u:parentOf> ?o . OPTIONAL {?o <u:parentOf> ?gkid }} " +
" LIMIT 1 OFFSET 2";
int iMatchCount = 0;
ResultSet results = qexec.execSelect() ;
ResultSetFormatter.out(System.out, results, query);
qexec.close() ;
model.close();
OracleUtils.dropSemanticModel(oracle, szModelName);
oracle.dispose();
}
}
The following are the commands to compile and run Example 7-21, as well as the expected
output of the java command.
javac -classpath ../jar/'*' Test9.java
java -classpath ./:../jar/'*' Test9 jdbc:oracle:thin:@localhost:1521:orcl scott
<password-for-scott> M1
------------------------------
| s | o | gkid |
==============================
| <u:John> | <u:Jack> | |
------------------------------
7-61
Chapter 7
Example Queries Using RDF Semantic Graph Support for Apache Jena
g.add(Triple.create(Node.createURI("u:John"), Node.createURI("u:parentOf"),
Node.createURI("u:Mary")));
g.add(Triple.create(Node.createURI("u:John"), Node.createURI("u:parentOf"),
Node.createURI("u:Jack")));
g.add(Triple.create(Node.createURI("u:Mary"), Node.createURI("u:parentOf"),
Node.createURI("u:Jill")));
String queryString =
" PREFIX ORACLE_SEM_FS_NS: <http://oracle.com/semtech#dop=4,timeout=1> "
+ " SELECT ?s ?o ?gkid WHERE { ?s <u:parentOf> ?o . "
+ " OPTIONAL {?o <u:parentOf> ?gkid }} "
+ " LIMIT 1 OFFSET 2";
int iMatchCount = 0;
ResultSet results = qexec.execSelect() ;
ResultSetFormatter.out(System.out, results, query);
qexec.close() ;
model.close();
OracleUtils.dropSemanticModel(oracle, szModelName);
oracle.dispose();
}
}
The following are the commands to compile and run Example 7-22, as well as the
expected output of the java command.
javac -classpath ../jar/'*' Test10.java
java -classpath ./:../jar/'*' Test10 jdbc:oracle:thin:@localhost:1521:orcl
scott <password-for-scott> M1
------------------------------
| s | o | gkid |
==============================
7-62
Chapter 7
Example Queries Using RDF Semantic Graph Support for Apache Jena
| <u:John> | <u:Jack> | |
------------------------------
7-63
Chapter 7
Example Queries Using RDF Semantic Graph Support for Apache Jena
Node.createURI("http://xmlns.com/foaf/0.1/name"),
Node.createLiteral("Alice")));
dataset.add(new Quad(
Node.createURI("http://example.org/alice"), // graph name
Node.createURI("urn:alice"),
Node.createURI("http://xmlns.com/foaf/0.1/mbox"),
Node.createURI("mailto:alice@example")));
DataSource ds = DatasetFactory.create(dataset);
String queryString =
" PREFIX foaf: <http://xmlns.com/foaf/0.1/> "
+ " PREFIX dc: <http://purl.org/dc/elements/1.1/> "
+ " SELECT ?who ?graph ?mbox "
+ " FROM NAMED <http://example.org/alice> "
+ " FROM NAMED <http://example.org/bob> "
+ " WHERE "
+ " { "
+ " ?graph dc:publisher ?who . "
+ " GRAPH ?graph { ?x foaf:mbox ?mbox } "
+ " } ";
qexec.close();
dataset.close();
oracle.dispose();
}
}
The following are the commands to compile and run Example 7-23, as well as the
expected output of the java command.
javac -classpath ./:./jena-2.6.4.jar:./sdordfclient.jar:./ojdbc6.jar:./slf4j-
api-1.5.8.jar:./slf4j-log4j12-1.5.8.jar:./arq-2.8.8.jar:./xercesImpl-2.7.1.jar
Test11.java
java -classpath ./:../jar/'*' Test11 jdbc:oracle:thin:@localhost:1521:orcl
scott <password-for-scott> M1
------------------------------------------------------------------------
| who | graph | mbox |
========================================================================
| "alice Hacker" | <http://example.org/alice> | <mailto:alice@example> |
| "Bob Hacker" | <http://example.org/bob> | <mailto:bob@example> |
------------------------------------------------------------------------
7-64
Chapter 7
Example Queries Using RDF Semantic Graph Support for Apache Jena
{
public static void main(String[] args) throws Exception
{
String szJdbcURL = args[0];
String szUser = args[1];
String szPasswd = args[2];
String szModelName = args[3];
g.add(Triple.create(Node.createURI("u:John"), Node.createURI("u:parentOf"),
Node.createURI("u:Mary")));
String queryString = " ASK { <u:John> <u:parentOf> <u:Mary> } ";
model.close();
OracleUtils.dropSemanticModel(oracle, szModelName);
oracle.dispose();
}
}
The following are the commands to compile and run Example 7-24, as well as the expected
output of the java command.
javac -classpath ../jar/'*' Test12.java
java -classpath ./:../jar/'*' Test12 jdbc:oracle:thin:@localhost:1521:orcl scott
<password-for-scott> M1
ask result = TRUE
7-65
Chapter 7
Example Queries Using RDF Semantic Graph Support for Apache Jena
g.add(Triple.create(Node.createURI("u:John"), Node.createURI("u:parentOf"),
Node.createURI("u:Mary")));
g.add(Triple.create(Node.createURI("u:John"), Node.createURI("u:parentOf"),
Node.createURI("u:Jack")));
g.add(Triple.create(Node.createURI("u:Amy"), Node.createURI("u:parentOf"),
Node.createURI("u:Jack")));
String queryString = " DESCRIBE ?x WHERE {?x <u:parentOf> <u:Jack>}";
qexec.close() ;
model.close();
OracleUtils.dropSemanticModel(oracle, szModelName);
oracle.dispose();
}
}
The following are the commands to compile and run Example 7-25, as well as the
expected output of the java command.
javac -classpath ../jar/'*' Test13.java
java -classpath ./:../jar/'*' Test13 jdbc:oracle:thin:@localhost:1521:orcl
scott <password-for-scott> M1
describe result = <ModelCom {u:Amy @u:parentOf u:Jack;
u:John @u:parentOf u:Jack; u:John @u:parentOf u:Mary} | [u:Amy,
u:parentOf, u:Jack] [u:John, u:parentOf,
u:Jack] [u:John, u:parentOf, u:Mary]>
7-66
Chapter 7
Example Queries Using RDF Semantic Graph Support for Apache Jena
g.add(Triple.create(Node.createURI("u:John"), Node.createURI("u:parentOf"),
Node.createURI("u:Mary")));
g.add(Triple.create(Node.createURI("u:John"), Node.createURI("u:parentOf"),
Node.createURI("u:Jack")));
g.add(Triple.create(Node.createURI("u:Amy"), Node.createURI("u:parentOf"),
Node.createURI("u:Jack")));
String queryString = " CONSTRUCT { ?s <u:loves> ?o } WHERE {?s <u:parentOf> ?o}";
qexec.close() ;
model.close();
OracleUtils.dropSemanticModel(oracle, szModelName);
oracle.dispose();
}
}
The following are the commands to compile and run Example 7-26, as well as the expected
output of the java command.
javac -classpath ../jar/'*' Test14.java
java -classpath ./:../jar/'*' Test14 jdbc:oracle:thin:@localhost:1521:orcl scott
<password-for-scott> M1
Construct result = <ModelCom {u:Amy @u:loves u:Jack;
u:John @u:loves u:Jack; u:John @u:loves u:Mary} | [u:Amy, u:loves, u:Jack] [u:John,
u:loves,
u:Jack] [u:John, u:loves, u:Mary]>
7-67
Chapter 7
Example Queries Using RDF Semantic Graph Support for Apache Jena
import oracle.spatial.rdf.client.jena.*;
import org.apache.jena.graph.*;
qexec.close() ;
model.close();
OracleUtils.dropSemanticModel(oracle, szModelName1);
OracleUtils.dropSemanticModel(oracle, szModelName2);
oracle.dispose();
}
}
The following are the commands to compile and run Example 7-27, as well as the
expected output of the java command.
javac -classpath ../jar/'*' Test15.java
java -classpath ./:../jar/'*' Test15 jdbc:oracle:thin:@localhost:1521:orcl
scott <password-for-scott> M1 M2
Construct result = <ModelCom {u:Mary @u:loves u:Jack; u:John @u:loves u:Jack}
| [u:Mary, u:loves, u:Jack] [u:John, u:loves, u:Jack]>
7-68
Chapter 7
Example Queries Using RDF Semantic Graph Support for Apache Jena
UpdateAction.parseExecute(insertString, model);
ExtendedIterator ei = GraphUtil.findAll(g);
while (ei.hasNext()) {
System.out.println("Triple " + ei.next().toString());
}
model.close();
OracleUtils.dropSemanticModel(oracle, szModelName);
oracle.dispose();
}
}
The following are the commands to compile and run Example 7-28, as well as the expected
output of the java command.
javac -classpath ../jar/'*' Test16.java
java -classpath ./:../jar/'*' Test16 jdbc:oracle:thin:@localhost:1521:orcl scott
<password-for-scott> M1
Triple http://example/book3 @dc:title "A new book"
Triple http://example/book3 @dc:creator "A.N.Other"
7-69
Chapter 7
Example Queries Using RDF Semantic Graph Support for Apache Jena
import org.apache.jena.update.*;
UpdateAction.parseExecute(insertString, model);
String queryString = "PREFIX dc: <http://purl.org/dc/elements/1.1/> " +
" PREFIX fn: <http://www.w3.org/2005/xpath-functions#> " +
" SELECT ?subject (fn:upper-case(?object) as ?object1) " +
" (fn:string-length(?object) as ?strlen) " +
" WHERE { ?subject dc:title ?object } "
;
Query query = QueryFactory.create(queryString, Syntax.syntaxARQ);
QueryExecution qexec = QueryExecutionFactory.create(query, model);
ResultSet results = qexec.execSelect();
ResultSetFormatter.out(System.out, results, query);
model.close();
OracleUtils.dropSemanticModel(oracle, szModelName);
oracle.dispose();
}
}
The following are the commands to compile and run Example 7-29, as well as the
expected output of the java command.
javac -classpath ../jar/'*' Test17.java
java -classpath ./:../jar/'*' Test17 jdbc:oracle:thin:@localhost:1521:orcl
scott <password-for-scott> M1
----------------------------------------------------------
| subject | object1 | strlen |
==========================================================
| <http://example/book3> | "A NEW BOOK" | 10 |
| <http://example/book4> | "SEMANTIC WEB ROCKS" | 18 |
----------------------------------------------------------
7-70
Chapter 7
Example Queries Using RDF Semantic Graph Support for Apache Jena
UpdateAction.parseExecute(insertString, model);
String queryString =
" PREFIX fn: <http://www.w3.org/2005/xpath-functions#> " +
" SELECT ?subject ((?temp - 32.0)*5/9 as ?celsius_temp) " +
"WHERE { ?subject <u:temp> ?temp } "
;
Query query = QueryFactory.create(queryString, Syntax.syntaxARQ);
QueryExecution qexec = QueryExecutionFactory.create(query, model);
ResultSet results = qexec.execSelect();
ResultSetFormatter.out(System.out, results, query);
model.close();
OracleUtils.dropSemanticModel(oracle, szModelName);
oracle.dispose();
}
}
The following are the commands to compile and run Example 7-30, as well as the expected
output of the java command.
javac -classpath ../jar/'*' Test18.java
java -classpath ./:../jar/'*' Test18 jdbc:oracle:thin:@localhost:1521:orcl scott
<password-for-scott> M1
------------------------------------------------------------------------
| subject | celsius_temp |
========================================================================
| <u:Object1> | "-7.7222223"^^<http://www.w3.org/2001/XMLSchema#float> |
| <u:Object2> | "0.0"^^<http://www.w3.org/2001/XMLSchema#float> |
------------------------------------------------------------------------
7-71
Chapter 7
Example Queries Using RDF Semantic Graph Support for Apache Jena
g.add(Triple.create(Node.createURI("u:John"), Node.createURI("u:parentOf"),
Node.createURI("u:Mary")));
g.add(Triple.create(Node.createURI("u:John"),
Node.createURI("u:parentOf"),
Node.createURI("u:Jack")));
g.add(Triple.create(Node.createURI("u:Mary"), Node.createURI("u:parentOf"),
Node.createURI("u:Jill")));
String queryString =
" SELECT ?s ?o WHERE { ?s <u:parentOf> ?o .} ";
Query query = QueryFactory.create(queryString) ;
QueryExecution qexec = QueryExecutionFactory.create(query, model) ;
The following are the commands to compile and run Example 7-31, as well as the
expected output of the java command.
7-72
Chapter 7
Example Queries Using RDF Semantic Graph Support for Apache Jena
System.out.println("Creating OraclePool");
OraclePool op = new OraclePool(szJdbcURL, szUser, szPasswd, prop,
"OracleSemConnPool");
System.out.println("Done creating OraclePool");
7-73
Chapter 7
SPARQL Gateway and Semantic Data
OracleUtils.dropSemanticModel(oracle, szModelName);
The following are the commands to compile and run Example 7-32, as well as the
expected output of the java command.
javac -classpath ../jar/'*' Test20.java
java -classpath ./:../jar/'*' Test20 jdbc:oracle:thin:@localhost:1521:orcl
scott <password-for-scott> M1
Creating OraclePool
Done creating OraclePool
Getting an Oracle from OraclePool
Done
Is logical connection:true
Getting an Oracle from OraclePool
Done
Is logical connection:true
7-74
Chapter 7
SPARQL Gateway and Semantic Data
To address these challenges, SPARQL Gateway manages SPARQL queries and XSLT
operations, executes SPARQL queries against any arbitrary standard-compliant SPARQL
endpoints, and performs necessary XSL transformations before passing the response back to
applications. Applications can then consume semantic data as if it is coming from an existing
data source.
Different triple stores or quad stores often have different capabilities. For example, the
SPARQL endpoint supported by Oracle Database, with RDF Semantic Graph support for
Apache Jena, allows parallel execution, query timeout, dynamic sampling, result cache, and
other features, in addition to the core function of parsing and answering a given standard-
compliant SPARQL query. However, these features may not be available from another given
semantic data store.
With the RDF Semantic Graph SPARQL Gateway, you get certain highly desirable
capabilities, such as the ability to set a timeout on a long running query and the ability to get
partial results from a complex query in a given amount of time. Waiting indefinitely for a query
to finish is a challenge for end users, as is an application with a response time constraint.
SPARQL Gateway provides both timeout and best effort query functions on top of a SPARQL
endpoint. This effectively removes some uncertainty from consuming semantic data through
SPARQL query executions. (See Specifying a Timeout Value and Specifying Best Effort
Query Execution.)
7.17.2.1 Download the RDF Semantic Graph Support for Apache Jena .zip File (if
Not Already Done)
If you have not already done so, download the RDF Semantic Graph support for Apache
Jena file from the RDF Semantic Graph page and unzip it into a temporary directory, as
explained in Setting Up the Software Environment.
Note that the SPARQL Gateway Java class implementations are embedded in
sdordfclient.jar (see Using the SPARQL Gateway Java API).
7-75
Chapter 7
SPARQL Gateway and Semantic Data
7-76
Chapter 7
SPARQL Gateway and Semantic Data
If the OracleSGDS data source is configured and available, SPARQL Gateway servlet will
automatically create all the necessary tables and indexes upon initialization.
To be able to log in to either of these JSP pages, you must use the WebLogic Server to add a
group named SparqlGatewayAdminGroup, and create a new user or assign an existing user to
this group.
7-77
Chapter 7
SPARQL Gateway and Semantic Data
Tip:
Use the file extension .sparql for SPARQL query files, and the file
extension .xslt for XSL transformation files.
The syntax for specifying these files (using the provided example file names) is
wq=qb1.sparql for a SPARQL query file and wx=default.xslt for an XSL
transformation file.
If you want to customize the default XSL transformations, see the examples in
Customizing the Default XSLT File.
If you specify wx=noop.xslt, XSL transformation is not performed and the
SPARQL response is returned "as is" to the client.
• Store the SPARQL queries and XSL transformations in a file system directory, and
make sure that the directory is accessible for the deployed SPARQL Gateway Web
application.
By default, the directory is set to /tmp, as shown in the following <init-param>
setting:
<init-param>
<param-name>sparql_gateway_repository_filedir</param-name>
<param-value>/tmp/</param-value>
</init-param>
It is recommended that you customize this directory before deploying the SPARQL
Gateway. To change the directory setting, edit the text in between the <param-
value> and </param-value> tags.
The following example specifies a SPARQL query file and an XSL transformation
file that are in the directory specified in the <init-param> element for
sparql_gateway_repository_filedir:
fq=qb1.sparql
fx=myxslt1.xslt
• Make the SPARQL queries and XSL transformations accessible from a website.
7-78
Chapter 7
SPARQL Gateway and Semantic Data
Customize this directory before deploying the SPARQL Gateway. To change the website
setting, edit the text in between the <param-value> and </param-value> tags.
The following example specifies a SPARQL query file and an XSL transformation file that
are in the URL specified in the <init-param> element for
sparql_gateway_repository_url.
uq=qb1.sparql
ux=myxslt1.xslt
Internally, SPARQL Gateway computes the appropriate complete URL, fetches the
content, starts query execution, and applies the XSL transformation to the query
response XML.
• Store the SPARQL queries and XSL transformations in an Oracle database.
This approach requires that the J2EE data source OracleSGDS be defined. After SPARQL
Gateway retrieves a database connection from the OracleSGDS data source, a SPARQL
query is read from the database table ORACLE_ORARDF_SG_QUERY using the integer
ID provided.
The syntax for fetching a SPARQL query from an Oracle database is dq=<integer-id>,
and the syntax for fetching an XSL transformation from an Oracle database is
dx=<integer-id>.
Upon servlet initialization, the following tables are created automatically if they do not
already exist (you do not need to create them manually):
– ORACLE_ORARDF_SG_QUERY with a primary key of QID (integer type)
– ORACLE_ORARDF_SG_XSLT with a primary key of XID (integer type)
If a query does not finish when timeout occurs, then an empty SPARQL response is
constructed by SPARQL Gateway.
Note that even if SPARQL Gateway times out a query execution at the HTTP connection
level, the query may still be running on the server side. The actual behavior will be vendor-
dependent.
7-79
Chapter 7
SPARQL Gateway and Semantic Data
Note:
You can specify best effort query execution only if you also specify a timeout
value (described in Specifying a Timeout Value).
When you submit a potentially long-running query using the URL format described in
Using SPARQL Gateway with Semantic Data, if you specify a timeout value, you can
also specify a "best effort" limitation on the query. For example, the following shows
the URL format with a timeout specification of 1000 milliseconds (1 second) and a best
effort specification (&b=t):
http://host:port/sparqlgateway/sg?
<SPARQL_ENDPOINT>&<SPARQL_QUERY>&<XSLT>&t=1000&b=t
The web.xml file includes two parameter settings that affect the behavior of the best
effort option: sparql_gateway_besteffort_maxrounds and
sparql_gateway_besteffort_maxthreads. The following show the default definitions:
<init-param>
<param-name>sparql_gateway_besteffort_maxrounds</param-name>
<param-value>10</param-value>
</init-param>
<init-param>
<param-name>sparql_gateway_besteffort_maxthreads</param-name>
<param-value>3</param-value>
</init-param>
When a SPARQL SELECT query is executed in best effort style, a series of queries
will be executed with an increasing LIMIT value setting in the SPARQL query body.
(The core idea is based on the observation that a SPARQL query runs faster with a
smaller LIMIT setting.) SPARQL Gateway starts query execution with a "LIMIT 1"
setting. Ideally, this query can finish before the timeout is due. Assume that is the
case, the next query will have its LIMIT setting is increased, and subsequent queries
have higher limits. The maximum number of query executions is controlled by the
sparql_gateway_besteffort_maxrounds parameter.
7-80
Chapter 7
SPARQL Gateway and Semantic Data
The following example implements this namespace prefix replacement logic: if a variable
binding returns a URI that starts with http://purl.org/goodrelations/v1#, that portion is
replaced by gr:; and if a variable binding returns a URI that starts with http://www.w3.org/
2000/01/rdf-schema#, that portion is replaced by rdfs:.
<xsl:when test="starts-with(text(),'http://purl.org/goodrelations/v1#')">
<xsl:value-of select="concat('gr:',substring-after(text(),'http://purl.org/
goodrelations/v1#'))"/>
</xsl:when>
...
<xsl:when test="starts-with(text(),'http://www.w3.org/2000/01/rdf-schema#')">
<xsl:value-of select="concat('rdfs:',substring-after(text(),'http://www.w3.org/
2000/01/rdf-schema#'))"/>
</xsl:when>
7-81
Chapter 7
SPARQL Gateway and Semantic Data
These methods manipulate and retrieve entries in the SPARQL Gateway associated
tables that are stored in an Oracle Database instance. To use these methods, the
necessary associated tables must already exist. If the tables do not exist, deploy the
SPARQL Gateway on a Web server and access a URL in the following format:
http://<host>:<port>/sparqlgateway/sg?
where <host> is the host name of the Web server and <port> is the listening port of the
Web server. Accessing this URL will automatically create the necessary tables if they
do not already exist.
Any changes made through the Java API affect the SPARQL Gateway Web service in
the same way as changes made through the administration Web interface. This
provides the flexibility to manage queries and transformations using the interface you
find most convenient.
Note that the insert methods provided by the Java API will not replace existing queries
or transformations stored in the tables. Attempting to replace an existing query or
transformation will fail. To replace a query or transformation, you must remove the
existing entry in the table using one of the delete methods, and then insert the new
query or transformation using one of the insert methods.
The following examples demonstrate how to perform common management tasks
using the Java API. The examples assume a connection has already been established
to the underlying Oracle Database instance backing the SPARQL Gateway.
Example 7-33 Storing a SPARQL Query and an XSL Transformation
Example 7-33 adds a query and an XSL transformation to the database backing the
SPARQL Gateway. After the query and transformation are added, other programs can
use the query and transformation through the gateway by specifying the appropriate
query ID (qid) and XSL transformation ID (xid) in the request URL.
Note that Although Example 7-33 inserts both a query and transformation, the query
and transformation are not necessarily related and do not need to be used together
when accessing SPARQL Gateway. Any query in the database can be used with any
transformation in the database when submitting a request to SPARQL Gateway.
String query = "PREFIX ... SELECT ..."; // full SPARQL query text
String xslt = "<?xml ...> ..."; // full XSLT transformation text
7-82
Chapter 7
SPARQL Gateway and Semantic Data
// Populate these with the query text and description from the database
query = new StringBuilder( );
description = new StringBuilder( );
7-83
Chapter 7
SPARQL Gateway and Semantic Data
// Populate these with the XSLT text and description from the database
xslt = new StringBuilder( );
description = new StringBuilder( );
try {
SGDBHandler.getXslt( connection, xsltId, xslt, description );
} catch( SQLException sqle ) {
// Handle exception
// NOTE: exception is thrown if transformation with specified ID does not exist
}
7-84
Chapter 7
SPARQL Gateway and Semantic Data
Enter or select a SPARQL Endpoint, specify the SPARQL SELECT Query Body, and press
Submit Query.
For example, if you specify http://dbpedia.org/sparql as the SPARQL endpoint and use
the SPARQL query body from Figure 7-2, the response will be similar to Figure 7-3. Note that
the default transformations (in default.xslt) have been applied to the XML output in this
figure.
7-85
Chapter 7
SPARQL Gateway and Semantic Data
7-86
Chapter 7
SPARQL Gateway and Semantic Data
Enter or select a SPARQL Endpoint, specify the SPARQL SELECT Query Body, optionally
specify a Timeout (ms) value in milliseconds and the Best Effort option, and press Submit
Query.
The SPARQL response is parsed and then presented in table form, as shown in Figure 7-5.
In Figure 7-5, note that URIs are clickable to allow navigation, and that when users move the
cursor over a URI, tool tips are shown for the URIs which have been shortened for readability
(as in http://purl.org.dc/elements/1.1/title being displayed as the tool tip for dc:title
in the figure).
If you click the URI http://example.org/book/book5 in the output shown in Figure 7-5, a
new SPARQL query is automatically generated and executed. This generated SPARQL query
has three query patterns that use this particular URI as subject, predicate, and object, as
7-87
Chapter 7
SPARQL Gateway and Semantic Data
shown in Figure 7-6. Such a query can give you a good idea about how this URI is
used and how it is related to other resources in the data set.
When there are many matches of a query, the results are organized in pages and you
can click on any page. The page size by default is 50 results. To display more (or
fewer) than 50 rows per page in a response with the Browsing and Navigation Page
(browse.jsp), you can specify the &resultsPerPage parameter in the URL. For
example, to allow 100 rows per page, include the following in the URL:
&resultsPerPage=100
7-88
Chapter 7
SPARQL Gateway and Semantic Data
7-89
Chapter 7
SPARQL Gateway and Semantic Data
7-90
Chapter 7
SPARQL Gateway and Semantic Data
7-91
Chapter 7
SPARQL Gateway and Semantic Data
Select the desired metadata types to be imported. Be sure that Tables is included
in the selected types.
4. Click Next. The third page of the Import Metadata wizard is displayed, as shown in
Figure 7-11.
7-92
Chapter 7
Deploying Fuseki in Apache Tomcat
In the Data Source View, expand the node that has the table icon, select the column
names (mapped from projected variables defined in the SPARQL SELECT statement),
and click the right-arrow (>) button to move the selected columns to the Repository
View.
5. Click Finish.
6. Complete the remaining steps for the usual BI Business Model work and Mapping and
Presentation definition work, which are not specific to SPARQL Gateway or RDF data.
7-93
Chapter 7
ORARDFLDR Utility for Bulk Loading RDF Data
2. Copy the fuseki.war into the Tomcat webapps folder. For example:
cd $CATALINA_HOME/webapps
cp /tmp/jena_adapter/fuseki_web_app/fuseki.war .
3. Start Tomcat:
$CATALINA_HOME/bin/startup.sh
If this file does not have executable permission, enter the following command and
then again attempt to start Tomcat:
chmod u+x $CATALINA_HOME/bin/startup.sh
For convenience, a shell script in the bin directory can also be executed. The following
describes the commands to use this script
Prerequisite: Set ${ORACLE_JENA_HOME} and ensure ${ORACLE_JENA_HOME}/bin is in
your Unix PATH environment variable.
Usage:
orardfldr <command_line_arguments>
7-94
Chapter 7
ORARDFLDR Utility for Bulk Loading RDF Data
1. Unzip your wallet_<dbname>.zip file. You should see something similar to the listing
below after unzipping the file.
[oracle@localhost Wallet_Info]$ ls
cwallet.sso keystore.jks README tnsnames.ora
ewallet.p12 ojdbc.properties sqlnet.ora truststore.jks
2. Modify ojdbc.properties to add JKS related connection properties. The final version of
your ojdbc.properties file should be similar as shown below:
# Connection property while using Oracle wallets.
#oracle.net.wallet_location=(SOURCE=(METHOD=FILE)(METHOD_DATA=(DIRECTORY=$
{TNS_ADMIN})))
# FOLLOW THESE STEPS FOR USING JKS
# (1) Uncomment the following properties to use JKS.
# (2) Comment out the oracle.net.wallet_location property above
# (3) Set the correct password for both trustStorePassword and keyStorePassword.
# It's the password you specified when downloading the wallet from OCI Console or
the Service Console.
javax.net.ssl.trustStore=${TNS_ADMIN}/truststore.jks
javax.net.ssl.trustStorePassword=password
javax.net.ssl.keyStore=${TNS_ADMIN}/keystore.jks
javax.net.ssl.keyStorePassword=password
Invoke ORARDFLDR to load RDF files from your client computer to an Autonomous database.
orardfldr --modelName=M1 --fileDir=./data --lang=N-TRIPLE
--jdbcUrl=jdbc:oracle:thin:@rdfdb_medium?TNS_ADMIN=/home/oracle/RDF/Wallet_Info/
--user="RDFUSER" --password=password --networkOwner="RDFUSER" --networkName=NET1
7-95
Chapter 7
ORARDFLDR Utility for Bulk Loading RDF Data
It loads RDF data in N-Triple format into a model named M1 in a network named NET1
owned by RDFUSER. RDFUSER is also used for the database connection.
7-96
8
RDF Semantic Graph Support for Eclipse
RDF4J
Oracle RDF Graph Adapter for Eclipse RDF4J utilizes the popular Eclipse RDF4J framework
to provide Java developers support to use the RDF Semantic Graph feature of Oracle
Database.
Note:
This feature was previously referred to as the Sesame Adapter for Oracle Database
and the Sesame Adapter.
The Eclipse RDF4J is a powerful Java framework for processing and handling RDF data.
This includes creating, parsing, scalable storage, reasoning and querying with RDF and
Linked Data. See https://rdf4j.org for more information.
This chapter assumes that you are familiar with major concepts explained in RDF Semantic
Graph Overview and OWL Concepts . It also assumes that you are familiar with the overall
capabilities and use of the Eclipse RDF4J Java framework. See https://rdf4j.org for more
information.
The Oracle RDF Graph Adapter for Eclipse RDF4J extends the semantic data management
capabilities of Oracle Database RDF/OWL by providing a popular standards based API for
Java developers.
• Oracle RDF Graph Support for Eclipse RDF4J Overview
The Oracle RDF Graph Adapter for Eclipse RDF4J API provides a Java-based interface
to Oracle semantic data through an API framework and tools that adhere to the Eclipse
RDF4J SAIL API.
• Prerequisites for Using Oracle RDF Graph Adapter for Eclipse RDF4J
Before you start using the Oracle RDF Graph Adapter for Eclipse RDF4J, you must
ensure that your system environment meets certain prerequisites.
• Setup and Configuration for Using Oracle RDF Graph Adapter for Eclipse RDF4J
To use the Oracle RDF Graph Adapter for Eclipse RDF4J, you must first setup and
configure the system environment.
• Database Connection Management
The Oracle RDF Graph Adapter for Eclipse RDF4J provides support for Oracle Database
Connection Pooling.
• SPARQL Query Execution Model
SPARQL queries executed through the Oracle RDF Graph Adapter for Eclipse RDF4J
API run as SQL queries against Oracle’s relational schema for storing RDF data.
• SPARQL Update Execution Model
This section explains the SPARQL Update Execution Model for Oracle RDF Graph
Adapter for Eclipse RDF4J.
8-1
Chapter 8
Oracle RDF Graph Support for Eclipse RDF4J Overview
The following example demonstrates a typical usage flow for the RDF Semantic Graph
support for Eclipse RDF4J.
Example 8-1 Sample Usage flow for RDF Semantic Graph Support for Eclipse
RDF4J Using a Schema-Private Semantic Network
String networkOwner = "SCOTT";
String networkName = "MYNET";
String modelName = "UsageFlow";
OraclePool oraclePool = new OraclePool(jdbcurl, user, password);
8-2
Chapter 8
Prerequisites for Using Oracle RDF Graph Adapter for Eclipse RDF4J
//A ValueFactory factory for creating IRIs, blank nodes, literals and statements
ValueFactory vf = conn.getValueFactory();
IRI alice = vf.createIRI("http://example.org/Alice");
IRI friendOf = vf.createIRI("http://example.org/friendOf");
IRI bob = vf.createIRI("http://example.org/Bob");
Resource context1 = vf.createIRI("http://example.org/");
8-3
Chapter 8
Setup and Configuration for Using Oracle RDF Graph Adapter for Eclipse RDF4J
8.3.1 Setting up Oracle RDF Graph Adapter for Eclipse RDF4J for Use
with Java
To use the Oracle RDF Graph Adapter for Eclipse RDF4J programatically through
Java code, you must first ensure that the system environment meets all the
prerequisites as explained in Prerequisites for Using Oracle RDF Graph Adapter for
Eclipse RDF4J.
Before you can start using the adapter to store, manage, and query RDF graphs in the
Oracle database, you need to create a semantic network. A semantic network acts like
a folder that can hold multiple RDF graphs, referred to as “semantic (or RDF) models”,
created by database users. Semantic networks can be created in the MDSYS system
schema (referred to as the MDSYS network) or, starting with version 19c, in a user
schema (referred to as a schema-private network).
A network can be created by invoking the appropriate command for the relevant
database version as shown in the following table:
8-4
Chapter 8
Setup and Configuration for Using Oracle RDF Graph Adapter for Eclipse RDF4J
Note:
The only difference in the command for creating an MDSYS-owned semantic
network in an Oracle Database 18c or 19c and Oracle Database 21c is the use of
the options parameter to pass the property NETWORK_STORAGE_FORM=ESC as
indicated in Table 8-1
Note:
RDF4J Server, Workbench and SPARQL Service only supports the MDSYS-owned
semantic network in the current version of Oracle RDF Graph Adapter for Eclipse
RDF4J.
2. Create a tablespace for storing the RDF graphs. Use a suitable operating system folder
and filename.
8-5
Chapter 8
Setup and Configuration for Using Oracle RDF Graph Adapter for Eclipse RDF4J
4. Create a tablespace for storing the user data. Use a suitable operating system
folder and filename.
5. Create a database user to create or use RDF graphs or do both using the adapter.
CREATE USER rdfuser
IDENTIFIED BY <password-for-rdfuser>
DEFAULT TABLESPACE usertbs
QUOTA 5G ON usertbs;
SELECT table_name
FROM sys.all_tables
WHERE table_name = 'RDF_VALUE$' AND owner='MDSYS';
Presence of RDF_VALUE$ table in the MDSYS schema shows that the MDSYS-
owned semantic network has been created successfully.
TABLE_NAME
-----------
RDF_VALUE$
2. Create a tablespace for storing the user data. Use a suitable operating system
folder and filename.
8-6
Chapter 8
Setup and Configuration for Using Oracle RDF Graph Adapter for Eclipse RDF4J
3. Create a database user to create and own the semantic network. This user can create or
use RDF graphs or do both within this schema-private network using the adapter.
CREATE USER rdfuser
IDENTIFIED BY <password-for-rdfuser>
DEFAULT TABLESPACE usertbs
QUOTA 5G ON usertbs;
SELECT table_name
FROM sys.all_tables
WHERE table_name = 'MYNET#RDF_VALUE$' AND owner='RDFUSER';
TABLE_NAME
-----------
MYNET#RDF_VALUE$
You can now set up the Oracle RDF Graph Adapter for Eclipse RDF4J for use with Java code
by performing the following actions:
1. Download and configure Eclipse RDF4J Release 3.2 from RDF4J Downloads page.
2. Download the adapter for Eclipse RDF4J, RDF4J.zip file from Oracle Software Delivery
Cloud.
3. Unzip the downloaded kit into a temporary directory, such as /tmp/oracle_adapter,
(on a Linux system) . If this temporary directory does not already exist, create it before
the unzip operation.
4. Include the following three supporting libraries in your CLASSPATH, in order to run your
Java code via your IDE:
• eclipse-rdf4j-3.2.0-onejar.jar: Download this Eclipse RDF4J jar library from
RDF4J Downloads page.
• ojdbc8.jar: Download this JDBC thin driver from JDBC Downloads page.
8-7
Chapter 8
Setup and Configuration for Using Oracle RDF Graph Adapter for Eclipse RDF4J
• ucp.jar: Download this Universal Connection Pool jar file from JDBC
Downloads page.
• log4j-api-2.13.3.jar, log4j-core-2.13.3.jar, log4j-slf4j-
impl-2.13.3.jar, slf4j-api-1.7.25.jar, commons-io-2.11.0.jar:
Download from Apache Software Foundation.
5. Install JDK 8 if it is not already installed.
6. Set the JAVA_HOME environment variable to refer to the JDK 8 installation.
Define and verify the setting by executing the following command:
echo $JAVA_HOME
8.3.2 Setting Up Oracle RDF Graph Adapter for Eclipse RDF4J for
Use in RDF4J Server and Workbench
This section describes the installation and configuration of the Oracle RDF Graph
Adapter for Eclipse RDF4J in RDF4J Server and RDF4J Workbench.
The RDF4J Server is a database management application that provides HTTP access
to RDF4J repositories, exposing them as SPARQL endpoints. The RDF4J Workbench
provides a web interface for creating, querying, updating and exploring the repositories
of an RDF4J Server.
Note:
RDF4J Server, Workbench and SPARQL Service only supports the MDSYS-
owned semantic network in the current version of Oracle RDF Graph Adapter
for Eclipse RDF4J.
Prerequisites
Ensure the following prerequisites are configured to use the adapter for Eclipse RDF4J
in RDF4J Server and Workbench:
1. Java 8 Runtime Environment
2. Download the supporting libraries as explained in Include Supporting Libraries.
3. A Java Servlet Container that supports Java Servlet API 2.5 and Java Server
Pages (JSP) 2.0, or newer.
Note:
All examples in this chapter are executed on the recent, stable version of
Apache Tomcat.
8-8
Chapter 8
Setup and Configuration for Using Oracle RDF Graph Adapter for Eclipse RDF4J
Note:
If the Oracle Data Source Repository is already set up in the RDF4J Workbench
Repository, then it will appear in the above drop-down list.
- Using UCP
<Resource name="jdbc/OracleSemDS" auth="Container"
factory="oracle.ucp.jdbc.PoolDataSourceImpl"
8-9
Chapter 8
Setup and Configuration for Using Oracle RDF Graph Adapter for Eclipse RDF4J
type="oracle.ucp.jdbc.PoolDataSource"
connectionFactoryClassName="oracle.jdbc.pool.OracleDataSource"
minPoolSize="15"
maxPoolSize="100"
inactiveConnectionTimeout="60"
abandonedConnectionTimeout="30"
initialPoolSize="15"
user="<<username>>"
password="<<pwd>>"
url="jdbc:oracle:thin:@<< host:port:sid >>"
/>
8-10
Chapter 8
Setup and Configuration for Using Oracle RDF Graph Adapter for Eclipse RDF4J
</td>
<td></td>
</tr>
<tr>
<th>
<xsl:value-of select="$repository-title.label" />
</th>
<td>
<input type="text" id="title" name="Repository title" size="48"
value="Native store" />
</td>
<td></td>
</tr>
<tr>
<th>
Model Name <strong style="color:Red">*</strong>
</th>
<td>
<input type="text" id="oracleSemModelName" name="Model Name"
size="50" value="" />
</td>
<td></td>
</tr>
<tr>
<th> Application Table Index </th>
<td>
<input type="text" id="oracleSemAppTabIndexes" name="Application
Table Index" size="5"
value="CPSO" />( C=Context, P=Predicate, S=Subject, O=Object )
</td>
<td></td>
</tr>
<tr>
<th>Index option</th>
<td></td>
<td></td>
</tr>
<tr>
<th style="padding: 0 40px;"> Degree of Parallelism </th>
<td>
<input type="text" id="oracleSemParallel"
name="Degree of parallelism" size="5" value="1" />
</td>
<td></td>
</tr>
<tr>
<th style="padding: 0 40px;"> Prefix Length to Compress </th>
<td>
<input type="text" id="oracleSemCompress"
name="Prefix Length to Compress" size="5" value="2" />
</td>
<td></td>
</tr>
<tr>
<th> Enforce Uniqueness </th>
<td>
<input type="radio" id="oracleSemEnforceUniqueness"
name="Enforce Uniqueness" size="10"
value="FALSE" checked="checked" />
FALSE
<input type="radio" id="oracleSemEnforceUniqueness"
8-11
Chapter 8
Setup and Configuration for Using Oracle RDF Graph Adapter for Eclipse RDF4J
<xsl:template match="sparql:sparql">
<form action="create">
<table class="dataentry">
<tbody>
<tr>
<th> <xsl:value-of select="$repository-type.label" /> </th>
<td>
<select id="type" name="type">
<option value="memory"> In Memory Store </option>
8-12
Chapter 8
Setup and Configuration for Using Oracle RDF Graph Adapter for Eclipse RDF4J
8-13
Chapter 8
Setup and Configuration for Using Oracle RDF Graph Adapter for Eclipse RDF4J
</xsl:template>
</xsl:stylesheet>
Note:
The configuration files, create-oracle.xsl and create.xsl contain the word
"Oracle", which you can see in the dop-down in Figure 8-2
Oracle will now appear as an option on the drop-down in the RDF4J Workbench.
8.3.2.1 Using the Adapter for Eclipse RFD4J via RDF4J Workbench
You can use the RDF4J workbench for creating and querying repositories.
The RDF4J provies a web interface for creating, querying, updating and exploring
repositories in RDF4J server.
Create a New Repository using RDF4J Workbench
1. Start the RDF4J Workbench by entering the url https://localhost:8080/rdf4j-
workbench in your browser.
2. Click New Repository in the sidebar menu and select the new repository Type as
"Oracle".
3. Enter the new repository ID and Title as shown in the following figure and click
Next.
8-14
Chapter 8
Setup and Configuration for Using Oracle RDF Graph Adapter for Eclipse RDF4J
4. Enter your Model details and click Create to create the new repository.
8-15
Chapter 8
Setup and Configuration for Using Oracle RDF Graph Adapter for Eclipse RDF4J
You can also view the newly created repository in the List Of Repositories page
in RDF4J Workbench.
8.3.3 Setting Up Oracle RDF Graph Adapter for Eclipse RDF4J for
Use As SPARQL Service
In order to use the SPARQL service via the RDF4J Workbench, ensure that the
Eclipse RDF4J server is installed and the Oracle Data Source repository is configured
as explained in Setting Up Oracle RDF Graph Adapter for Eclipse RDF4J for Use in
RDF4J Server and Workbench
8-16
Chapter 8
Database Connection Management
The Eclipse RDF4J server installation provides a REST API that uses the HTTP Protocol and
covers a fully compliant implementation of the SPARQL 1.1 Protocol W3C Recommendation.
This ensures that RDF4J server functions as a fully standards-compliant SPARQL endpoint.
See The RDF4J REST API for more information on this feature.
Note:
RDF4J Server, Workbench and SPARQL Service only supports the MDSYS-owned
semantic network in the current version of Oracle RDF Graph Adapter for Eclipse
RDF4J.
8.3.3.1 Using the Adapter Over SPARQL Endpoint in Eclipse RDF4J Workbench
This section explains the usecases for using the adapter for Eclipse RDF4J through SPARQL
Endpoint served by the Eclipse RDF4J Workbench.
Request Examples
Request to replace all data in testRepo repository.
PUT /rdf4j-server/repositories/testRepo/statements HTTP/1.1
Content-Type: application/rdf+xml;charset=UTF-8
[RDF/XML ENCODED RDF DATA]
8-17
Chapter 8
SPARQL Query Execution Model
8-18
Chapter 8
SPARQL Query Execution Model
In the above query, you can set the value <urn:john> for the query variable ?s. The
tansformed query in that case would be:
SELECT * WHERE { BIND (<urn:john> AS ?s) ?s <urn:fname> ?fname }
Note:
This approach is subject to the standard variable scoping rules of SPARQL. So
query variables that are not visible in the outermost graph pattern, such as variables
that are not projected out of a subquery, cannot be replaced with bind values.
The following code snippet illustrates how to use JDBC bind values.
Example 8-2 Using JDBC Bind Values
8-19
Chapter 8
SPARQL Query Execution Model
Note:
The JDBC bind value capability of Oracle RDF Graph Adapter for Eclipse
RDF4J utilizes the bind variables feature of SEM_APIS.SPARQL_TO_SQL
described in Using Bind Variables with SEM_APIS.SPARQL_TO_SQL.
8-20
Chapter 8
SPARQL Query Execution Model
The option in the above SPARQL PREFIX reflects a query option (or multiple options
separated by commas) to be used during query execution.
The following options are supported:
• DOP=n: specifies the degree of parallelism (n) to use during query execution.
• ODS=n: specifies the level of optimizer dynamic sampling to use when generating an
execution plan.
The following example query uses the ORACLE_SEM_FS_NS prefix to specify that a degree of
parallelism of 4 should be used for query execution.
The option in the above PREFIX reflects a SPARQL_TO_SQL option (or multiple options
separated by commas) to be used during query execution.
The available options are detailed in Using the SEM_MATCH Table Function to Query
Semantic Data. Any valid keywords or keyword – value pairs listed as valid for the options
argument of SEM_MATCH or SEM_APIS.SPARQL_TO_SQL can be used with this prefix.
8-21
Chapter 8
SPARQL Update Execution Model
The following example query uses the ORACLE_SEM_SM_NS prefix to specify that HASH
join should be used to join all triple patterns in the query.
PREFIX ORACLE_SEM_SM_NS: <http://oracle.com/semtech#all_link_hash>
PREFIX ex: <http://www.example.org/>
SELECT *
WHERE {?s ex:fname ?fname ;
ex:lname ?lname ;
ex:dob ?dob}
8-22
Chapter 8
SPARQL Update Execution Model
Note:
You must have an OracleSailRepositoryConnection instance. A plain
SailRepository instance created from an OracleSailStore will not run the update
properly.
The following example illustrates how to update an Oracle RDF model through the RDF4J
API:
String updString =
"PREFIX people: <http://www.example.org/people/>\n"+
"PREFIX ont: <http://www.example.org/ontology/>\n"+
"INSERT DATA { GRAPH <urn:g1> { \n"+
" people:Sue a ont:Person; \n"+
" ont:name \"Sue\" . } }";
Update upd = conn.prepareUpdate(QueryLanguage.SPARQL, updString);
upd.execute();
• UPDATE_MODEL Options
• UPDATE_MODEL Match Options
The option in the above PREFIX reflects an UPDATE_MODEL option (or multiple options
separated by commas) to be used during update execution.
8-23
Chapter 8
SPARQL Update Execution Model
The following example query uses the ORACLE_SEM_UM_NS prefix to specify a degree of
parallelism of 2 for the update.
PREFIX ORACLE_SEM_UM_NS: <http://oracle.com/semtech#parallel(2)>
PREFIX ex: <http://www.example.org/>
INSERT {GRAPH ex:g1 {ex:a ex:reachable ?y}}
WHERE {ex:a ex:p1* ?y}
The option reflects an UPDATE_MODEL match option (or multiple match options
separated by commas) to be used during SPARQL update execution.
The available options are detailed in SEM_APIS.UPDATE_MODEL. Any valid
keywords or keyword – value pairs listed as valid for the match_options argument of
UPDATE_MODEL can be used with this PREFIX.
8-24
Chapter 8
Efficiently Loading RDF Data
Oracle RDF Graph Adapter for Eclipse RDF4J does not allow dataset specification outside of
the SPARQL update string. Dataset specification through the setDataset method of
Operation and its subinterfaces is not supported. Instead, use the WITH, USING and USING
NAMED SPARQL clauses to specify the dataset in the SPARQL update string itself.
Bind Values
Bind values are not supported for SPARQL update operations.
Long RDF Literals
As noted in the previous section, large RDF literal values greater than 4000 bytes in length
are not supported by some SPARQL query functions. This limitation will affect SPARQL
update operations using any of these functions on long literal data. See Special
Considerations When Using SEM_MATCH for more information.
Update Timeout
Update timeout through the setMaxExecutionTime method on Operation and its
subinterfaces is not supported.
Bulk loading from compressed file is supported as well, but currently limited to gzip files only.
8-25
Chapter 8
Best Practices for Oracle RDF Graph Adapter for Eclipse RDF4J
Closing Resources
Application programmers should take care to avoid resource leaks. For Oracle RDF
Graph Adapter for Eclipse RDF4J, the two most important types of resource leaks to
prevent are JDBC connection leaks and database cursor leaks.
String queryString =
"PREFIX ex: <http://example.org/ontology/>\n"+
"SELECT * WHERE {?x ex:name ?y}\n" +
"ORDER BY ASC(STR(?y)) LIMIT 1 ";
TupleQuery tupleQuery =
conn.prepareTupleQuery(QueryLanguage.SPARQL, queryString);
8-26
Chapter 8
Blank Nodes Support in Oracle RDF Graph Adapter for Eclipse RDF4J
String queryString =
"PREFIX ex: <http://example.org/ontology/>\n"+
"SELECT * WHERE {?x ex:name ?y}\n" +
"ORDER BY ASC(STR(?y)) LIMIT 1 ";
TupleQuery tupleQuery = conn.prepareTupleQuery(QueryLanguage.SPARQL,
queryString);
TupleQueryResult result = tupleQuery.evaluate();
try {
while (result.hasNext()) {
BindingSet bindingSet = result.next();
System.out.println("value of x: " +
bindingSet.getValue("x"));
System.out..println("value of y: " + bindingSet.getValue("y"))
}
}
finally {
result.close();
}
Gathering Statistics
It is strongly recommended that you analyze the application table, semantic model, and
inferred graph in case it exists before performing inference and after loading a significant
amount of semantic data into the database. Performing the analysis operations causes
statistics to be gathered, which will help the Oracle optimizer select efficient execution plans
when answering queries.
To gather relevant statistics, you can use the following methods in the
OracleSailConnection:
• OracleSailConnection.analyze
• OracleSailConnection.analyzeApplicationTable
For information about these methods, including their parameters, see the RDF Semantic
Graph Support for Eclipse RDF4J Javadoc.
8-27
Chapter 8
Unsupported Features in Oracle RDF Graph Adapter for Eclipse RDF4J
However, a blank node that is wrapped inside < and > is treated as a constant when
the query is executed, and the support for Eclipse RDF4J adds a proper prefix to the
blank node label as required by the underlying data modeling. Do not use blank nodes
for the CONTEXT column in the application table, because blank nodes in named graphs
from two different semantic models will be treated as the same resource if they have
the same label. This is not the case for blank nodes in triples, where they are stored
separately if coming from different models.
The blank node when stored in Oracle database is embedded with a prefix based on
the model ID and graph name. Therefore, a conversion is needed between blank
nodes used in RDF4J API’s and Oracle Database. This can be done using the
following methods:
• OracleUtils.addOracleBNodePrefix
• OracleUtils.removeOracleBNodePrefix
8-28
Chapter 8
Example Queries Using Oracle RDF Graph Adapter for Eclipse RDF4J
To run these examples, ensure that all the supporting libraries mentioned in Supporting
libraries for using adapter with Java code are included in the CLASSPATH definition.
setenv CP .:ojdbc8.jar:oracle-rdf4j-adapter-3.2.0.jar:log4j-
api-2.13.3.jar:log4j-core-2.13.3.jar:log4j-slf4j-impl-2.13.3.jar:slf4j-
api-1.7.25.jar:eclipse-rdf4j-3.2.0-onejar.jar:commons-io-2.11.0.jar
Note:
The preceding setenv command assumes that the jar files are located in the
current directory. You may need to alter the command to indicate the location of
these jar files in your environment.
3. Compile the Java source file. For example, to compile the source file Test.java, run the
following command:
4. Run the compiled file by passing the command line arguments required by the specific
Java program.
• You can run the compiled file for the examples in this section for an existing MDSYS
network. For example, to run the compiled file on an RDF graph (model) named
TestModel in an existing MDSYS network, execute the following command:
• The examples also allow optional use of schema-private network. Therefore, you can
run the compiled file for the examples in this section for an existing schema-private
network. For example, to run the compiled file on an RDF graph (model) named
TestModel in an existing schema-private network whose owner is SCOTT and name
is NET1, execute the following command:
8-29
Chapter 8
Example Queries Using Oracle RDF Graph Adapter for Eclipse RDF4J
import java.io.IOException;
import java.io.PrintStream;
import java.sql.SQLException;
import oracle.rdf4j.adapter.OraclePool;
import oracle.rdf4j.adapter.OracleRepository;
import oracle.rdf4j.adapter.OracleSailConnection;
import oracle.rdf4j.adapter.OracleSailStore;
import oracle.rdf4j.adapter.exception.ConnectionSetupException;
import oracle.rdf4j.adapter.utils.OracleUtils;
import org.eclipse.rdf4j.common.iteration.CloseableIteration;
import org.eclipse.rdf4j.model.IRI;
import org.eclipse.rdf4j.model.Statement;
import org.eclipse.rdf4j.model.ValueFactory;
import org.eclipse.rdf4j.repository.Repository;
import org.eclipse.rdf4j.sail.SailException;
try {
op = new OraclePool(jdbcUrl, user, password);
store = new OracleSailStore(op, model, networkOwner,
networkName);
8-30
Chapter 8
Example Queries Using Oracle RDF Graph Adapter for Eclipse RDF4J
sr = new OracleRepository(store);
ValueFactory f = sr.getValueFactory();
conn = store.getConnection();
// returns OracleStatements
CloseableIteration < ?extends Statement, SailException > it;
int cnt;
finally {
if (conn != null && conn.isOpen()) {
conn.close();
}
if (op != null && op.getOracleDB() != null)
8-31
Chapter 8
Example Queries Using Oracle RDF Graph Adapter for Eclipse RDF4J
To run this example for an existing MDSYS network, execute the following command:
To run this example for an existing schema-private network whose owner is SCOTT
and name is NET1, execute the following command:
import java.io. * ;
import java.sql.SQLException;
import org.eclipse.rdf4j.repository.Repository;
import org.eclipse.rdf4j.repository.RepositoryConnection;
import org.eclipse.rdf4j.repository.RepositoryException;
import org.eclipse.rdf4j.rio.RDFParseException;
import org.eclipse.rdf4j.sail.SailException;
import org.eclipse.rdf4j.rio.RDFFormat;
import oracle.rdf4j.adapter.OraclePool;
import oracle.rdf4j.adapter.OracleRepository;
import oracle.rdf4j.adapter.OracleSailConnection;
import oracle.rdf4j.adapter.OracleSailStore;
import oracle.rdf4j.adapter.exception.ConnectionSetupException;
import oracle.rdf4j.adapter.utils.OracleUtils;
8-32
Chapter 8
Example Queries Using Oracle RDF Graph Adapter for Eclipse RDF4J
RepositoryException,
IOException {
OraclePool op = null;
OracleSailStore store = null;
Repository sr = null;
RepositoryConnection repConn = null;
try {
op = new OraclePool(jdbcUrl, user, password);
store = new OracleSailStore(op, model, networkOwner, networkName);
sr = new OracleRepository(store);
repConn = sr.getConnection();
psOut.println("testBulkLoad: start: before-load Size=" +
repConn.size());
repConn.add(new File(trigFile), "http://my.com/", RDFFormat.TRIG);
repConn.commit();
psOut.println("size " + Long.toString(repConn.size()));
}
finally {
if (repConn != null) {
repConn.close();
}
if (op != null)
OracleUtils.dropSemanticModelAndTables(op.getOracleDB(), model, null, null,
networkOwner, networkName);
if (sr != null) sr.shutDown();
if (store != null) store.shutDown();
if (op != null) op.close();
}
}
}
For running this example, assume that a sample TRIG data file named test.trig was
created as:
8-33
Chapter 8
Example Queries Using Oracle RDF Graph Adapter for Eclipse RDF4J
# default graph
{
<http://example.org/bob> dc:publisher "Bob Hacker".
<http://example.org/alice> dc:publisher "Alice Hacker".
}
:bob{
_:a foaf:mbox <mailto:[email protected]>.
}
:alice{
_:a foaf:name "Alice".
_:a foaf:mbox <mailto:[email protected]>.
}
:jack {
_:a foaf:name "Jack".
_:a foaf:mbox <mailto:[email protected]>.
}
To run this example for an existing MDSYS network, execute the following command:
To run this example for an existing schema-private network whose owner is SCOTT
and name is NET1, execute the following command:
import java.io.IOException;
import java.io.PrintStream;
import java.sql.SQLException;
import oracle.rdf4j.adapter.OraclePool;
import oracle.rdf4j.adapter.OracleRepository;
import oracle.rdf4j.adapter.OracleSailStore;
import oracle.rdf4j.adapter.exception.ConnectionSetupException;
8-34
Chapter 8
Example Queries Using Oracle RDF Graph Adapter for Eclipse RDF4J
import oracle.rdf4j.adapter.utils.OracleUtils;
import org.eclipse.rdf4j.model.IRI;
import org.eclipse.rdf4j.model.Literal;
import org.eclipse.rdf4j.model.ValueFactory;
import org.eclipse.rdf4j.model.vocabulary.RDF;
import org.eclipse.rdf4j.query.BindingSet;
import org.eclipse.rdf4j.query.QueryLanguage;
import org.eclipse.rdf4j.query.TupleQuery;
import org.eclipse.rdf4j.query.TupleQueryResult;
import org.eclipse.rdf4j.repository.Repository;
import org.eclipse.rdf4j.repository.RepositoryConnection;
OraclePool op = null;
OracleSailStore store = null;
Repository sr = null;
RepositoryConnection conn = null;
try {
op = new OraclePool(jdbcUrl, user, password);
store = new OracleSailStore(op, model, networkOwner, networkName);
sr = new OracleRepository(store);
ValueFactory f = sr.getValueFactory();
conn = sr.getConnection();
8-35
Chapter 8
Example Queries Using Oracle RDF Graph Adapter for Eclipse RDF4J
To run this example for an existing MDSYS network, execute the following command:
To run this example for an existing schema-private network whose owner is SCOTT
and name is NET1, execute the following command:
value of x: http://example.org/people/alice
value of y: "Alice"
8-36
Chapter 8
Example Queries Using Oracle RDF Graph Adapter for Eclipse RDF4J
import java.io. * ;
import java.sql.SQLException;
import org.eclipse.rdf4j.model.IRI;
import org.eclipse.rdf4j.model.ValueFactory;
import org.eclipse.rdf4j.model.Resource;
import org.eclipse.rdf4j.repository.RepositoryException;
import org.eclipse.rdf4j.rio.RDFParseException;
import org.eclipse.rdf4j.sail.SailException;
import org.eclipse.rdf4j.rio.RDFFormat;
import org.eclipse.rdf4j.repository.Repository;
import oracle.rdf4j.adapter.OraclePool;
import oracle.rdf4j.adapter.OracleRepository;
import oracle.rdf4j.adapter.OracleSailConnection;
import oracle.rdf4j.adapter.OracleSailStore;
import oracle.rdf4j.adapter.exception.ConnectionSetupException;
import oracle.rdf4j.adapter.utils.OracleUtils;
try {
psOut.println("testBulkLoad: start");
8-37
Chapter 8
Example Queries Using Oracle RDF Graph Adapter for Eclipse RDF4J
}
finally {
if (osc != null && osc.isOpen()) osc.close();
if (op != null)
OracleUtils.dropSemanticModelAndTables(op.getOracleDB(), model, null,
null, networkOwner, networkName);
if (sr != null) sr.shutDown();
if (store != null) store.shutDown();
if (op != null) op.close();
}
}
}
For running this example, assume that a sample ntriples data file named
test.ntriples was created as:
To run this example for an existing MDSYS network, execute the following command:
8-38
Chapter 8
Example Queries Using Oracle RDF Graph Adapter for Eclipse RDF4J
To run this example for an existing schema-private network whose owner is SCOTT and
name is NET1, execute the following command:
testBulkLoad: start
testBulkLoad: 8222ms.
Size: NO_CONTEXTS=0 ALL_CONTEXTS=6
size of store: 0
import java.io. * ;
import java.sql.SQLException;
import org.eclipse.rdf4j.model.Resource;
import org.eclipse.rdf4j.repository.Repository;
import org.eclipse.rdf4j.repository.RepositoryConnection;
import org.eclipse.rdf4j.repository.RepositoryException;
import org.eclipse.rdf4j.rio.RDFParseException;
import org.eclipse.rdf4j.sail.SailException;
import org.eclipse.rdf4j.rio.RDFFormat;
import oracle.rdf4j.adapter.OraclePool;
import oracle.rdf4j.adapter.OracleRepository;
import oracle.rdf4j.adapter.OracleSailConnection;
import oracle.rdf4j.adapter.OracleSailStore;
import oracle.rdf4j.adapter.exception.ConnectionSetupException;
import oracle.rdf4j.adapter.utils.OracleUtils;
OraclePool op = null;
OracleSailStore store = null;
8-39
Chapter 8
Example Queries Using Oracle RDF Graph Adapter for Eclipse RDF4J
Repository sr = null;
OracleSailConnection conn = null;
try {
op = new OraclePool(jdbcUrl, user, password);
store = new OracleSailStore(op, model, networkOwner,
networkName);
sr = new OracleRepository(store);
conn = store.getConnection();
For running this example, assume that a sample file named RdfXmlData.rdfxml was
created as:
<?xml version="1.0"?>
<!DOCTYPE owl [
<!ENTITY owl "http://www.w3.org/2002/07/owl#" >
<!ENTITY xsd "http://www.w3.org/2001/XMLSchema#" >
]>
<rdf:RDF
xmlns = "http://a/b#" xml:base = "http://a/b#" xmlns:my =
"http://a/b#"
8-40
Chapter 8
Example Queries Using Oracle RDF Graph Adapter for Eclipse RDF4J
xmlns:owl = "http://www.w3.org/2002/07/owl#"
xmlns:rdf = "http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:rdfs= "http://www.w3.org/2000/01/rdf-schema#"
xmlns:xsd = "http://www.w3.org/2001/XMLSchema#">
<owl:Class rdf:ID="Color">
<owl:oneOf rdf:parseType="Collection">
<owl:Thing rdf:ID="Red"/>
<owl:Thing rdf:ID="Blue"/>
</owl:oneOf>
</owl:Class>
</rdf:RDF>
To run this example for an existing MDSYS network, execute the following command:
To run this example for an existing schema-private network whose owner is SCOTT and
name is NET1, execute the following command:
import java.io.PrintStream;
import java.sql.SQLException;
import oracle.rdf4j.adapter.OraclePool;
import oracle.rdf4j.adapter.OracleRepository;
import oracle.rdf4j.adapter.OracleSailConnection;
import oracle.rdf4j.adapter.OracleSailRepositoryConnection;
import oracle.rdf4j.adapter.OracleSailStore;
import oracle.rdf4j.adapter.exception.ConnectionSetupException;
import oracle.rdf4j.adapter.utils.OracleUtils;
import org.eclipse.rdf4j.model.IRI;
import org.eclipse.rdf4j.model.ValueFactory;
import org.eclipse.rdf4j.model.vocabulary.RDFS;
import org.eclipse.rdf4j.query.BooleanQuery;
8-41
Chapter 8
Example Queries Using Oracle RDF Graph Adapter for Eclipse RDF4J
import org.eclipse.rdf4j.query.QueryLanguage;
import org.eclipse.rdf4j.repository.Repository;
import org.eclipse.rdf4j.repository.RepositoryConnection;
OraclePool op = null;
OracleSailStore store = null;
Repository sr = null;
RepositoryConnection conn = null;
try {
op = new OraclePool(jdbcUrl, user, password);
store = new OracleSailStore(op, model, networkOwner,
networkName);
sr = new OracleRepository(store);
conn = sr.getConnection();
OracleSailConnection osc =
(OracleSailConnection)((OracleSailRepositoryConnection)
conn).getSailConnection();
ValueFactory vf = sr.getValueFactory();
IRI p = vf.createIRI("http://p");
IRI cls = vf.createIRI("http://cls");
conn.clear();
conn.add(p, RDFS.DOMAIN, cls);
conn.commit();
8-42
Chapter 8
Example Queries Using Oracle RDF Graph Adapter for Eclipse RDF4J
store.shutDown();
op.close();
}
}
}
To run this example for an existing MDSYS network, execute the following command:
To run this example for an existing schema-private network whose owner is SCOTT and
name is NET1, execute the following command:
Answer is true
import java.io.PrintStream;
import java.sql.SQLException;
import oracle.rdf4j.adapter.OraclePool;
import oracle.rdf4j.adapter.OracleRepository;
import oracle.rdf4j.adapter.OracleSailConnection;
import oracle.rdf4j.adapter.OracleSailRepositoryConnection;
import oracle.rdf4j.adapter.OracleSailStore;
import oracle.rdf4j.adapter.exception.ConnectionSetupException;
import oracle.rdf4j.adapter.utils.OracleUtils;
import org.eclipse.rdf4j.model.IRI;
import org.eclipse.rdf4j.model.Statement;
import org.eclipse.rdf4j.model.ValueFactory;
import org.eclipse.rdf4j.model.vocabulary.RDFS;
import org.eclipse.rdf4j.query.GraphQuery;
import org.eclipse.rdf4j.query.GraphQueryResult;
import org.eclipse.rdf4j.query.QueryLanguage;
import org.eclipse.rdf4j.repository.Repository;
import org.eclipse.rdf4j.repository.RepositoryConnection;
8-43
Chapter 8
Example Queries Using Oracle RDF Graph Adapter for Eclipse RDF4J
OraclePool op = null;
OracleSailStore store = null;
Repository sr = null;
RepositoryConnection conn = null;
try {
op = new OraclePool(jdbcUrl, user, password);
store = new OracleSailStore(op, model, networkOwner,
networkName);
sr = new OracleRepository(store);
conn = sr.getConnection();
ValueFactory vf = sr.getValueFactory();
IRI p = vf.createIRI("http://p");
IRI cls = vf.createIRI("http://cls");
conn.clear();
conn.add(p, RDFS.DOMAIN, cls);
conn.commit();
OracleSailConnection osc =
(OracleSailConnection)((OracleSailRepositoryConnection)
conn).getSailConnection();
osc.analyze(); // analyze the semantic model
osc.analyzeApplicationTable(); // and then the application table
8-44
Chapter 8
Example Queries Using Oracle RDF Graph Adapter for Eclipse RDF4J
To run this example for an existing MDSYS network, execute the following command:
To run this example for an existing schema-private network whose owner is SCOTT and
name is NET1, execute the following command:
import java.io.File;
import java.io.IOException;
import java.io.PrintStream;
import java.sql.SQLException;
import oracle.rdf4j.adapter.OraclePool;
import oracle.rdf4j.adapter.OracleRepository;
import oracle.rdf4j.adapter.OracleSailConnection;
import oracle.rdf4j.adapter.OracleSailRepositoryConnection;
import oracle.rdf4j.adapter.OracleSailStore;
import oracle.rdf4j.adapter.exception.ConnectionSetupException;
import oracle.rdf4j.adapter.utils.OracleUtils;
import org.eclipse.rdf4j.query.BindingSet;
import org.eclipse.rdf4j.query.QueryLanguage;
import org.eclipse.rdf4j.query.TupleQuery;
import org.eclipse.rdf4j.query.TupleQueryResult;
import org.eclipse.rdf4j.repository.Repository;
8-45
Chapter 8
Example Queries Using Oracle RDF Graph Adapter for Eclipse RDF4J
import org.eclipse.rdf4j.repository.RepositoryConnection;
import org.eclipse.rdf4j.rio.RDFFormat;
OraclePool op = null;
OracleSailStore store = null;
Repository sr = null;
RepositoryConnection conn = null;
try {
op = new OraclePool(jdbcUrl, user, password);
store = new OracleSailStore(op, model, networkOwner,
networkName);
sr = new OracleRepository(store);
conn = sr.getConnection();
conn.begin();
conn.clear();
8-46
Chapter 8
Example Queries Using Oracle RDF Graph Adapter for Eclipse RDF4J
}
}
finally {
if (conn != null && conn.isOpen()) {
conn.clear();
conn.close();
}
OracleUtils.dropSemanticModelAndTables(op.getOracleDB(), model, null,
null, networkOwner, networkName);
sr.shutDown();
store.shutDown();
op.close();
}
}
}
For running this example, assume that the test.trig file in TRIG format has been created as
follows:
:bobGraph {
:bob foaf:mbox <mailto:[email protected]> .
}
:aliceGraph {
:alice foaf:name "Alice" .
:alice foaf:mbox <mailto:[email protected]> .
}
:jackGraph {
:jack foaf:name "Jack" .
:jack foaf:mbox <mailto:[email protected]> .
}
8-47
Chapter 8
Example Queries Using Oracle RDF Graph Adapter for Eclipse RDF4J
To run this example for an existing MDSYS network, execute the following command:
To run this example for an existing schema-private network whose owner is SCOTT
and name is NET1, execute the following command:
solution
[p=http://xmlns.com/foaf/0.1/mbox;s=http://example.org/alice;g=http://
example.org/aliceGraph;o=mailto:[email protected]]
solution
[p=http://xmlns.com/foaf/0.1/name;s=http://example.org/alice;g=http://
example.org/aliceGraph;o="Alice"]
solution
[p=http://xmlns.com/foaf/0.1/mbox;s=http://example.org/bob;g=http://
example.org/bobGraph;o=mailto:[email protected]]
total # of solution 3
import java.io.PrintStream;
import java.sql.SQLException;
import oracle.rdf4j.adapter.OraclePool;
import oracle.rdf4j.adapter.OracleRepository;
import oracle.rdf4j.adapter.OracleSailConnection;
import oracle.rdf4j.adapter.OracleSailRepositoryConnection;
import oracle.rdf4j.adapter.OracleSailStore;
import oracle.rdf4j.adapter.exception.ConnectionSetupException;
import oracle.rdf4j.adapter.utils.OracleUtils;
import org.eclipse.rdf4j.model.IRI;
import org.eclipse.rdf4j.model.Literal;
import org.eclipse.rdf4j.model.ValueFactory;
import org.eclipse.rdf4j.model.vocabulary.RDF;
import org.eclipse.rdf4j.query.BindingSet;
import org.eclipse.rdf4j.query.QueryLanguage;
import org.eclipse.rdf4j.query.TupleQuery;
import org.eclipse.rdf4j.query.TupleQueryResult;
import org.eclipse.rdf4j.repository.Repository;
import org.eclipse.rdf4j.repository.RepositoryConnection;
8-48
Chapter 8
Example Queries Using Oracle RDF Graph Adapter for Eclipse RDF4J
OraclePool op = null;
OracleSailStore store = null;
Repository sr = null;
RepositoryConnection conn = null;
try {
op = new OraclePool(jdbcUrl, user, password);
store = new OracleSailStore(op, model, networkOwner, networkName);
sr = new OracleRepository(store);
conn = sr.getConnection();
ValueFactory f = conn.getValueFactory();
conn.begin();
// clear model to start fresh
conn.clear();
conn.add(alice, RDF.TYPE, person);
conn.add(alice, name, alicesName);
conn.commit();
OracleSailConnection osc =
(OracleSailConnection)((OracleSailRepositoryConnection)
conn).getSailConnection();
osc.analyze();
osc.analyzeApplicationTable();
// Run a query and only return the number of matches (the count ! )
String queryString = " SELECT (COUNT(*) AS ?totalCount) WHERE {?s ?p ?
y} ";
8-49
Chapter 8
Example Queries Using Oracle RDF Graph Adapter for Eclipse RDF4J
bindingSet.getValue("totalCount").stringValue();
psOut.println("number of matches: " + totalCount);
}
}
}
finally {
if (conn != null && conn.isOpen()) {
conn.clear();
conn.close();
}
OracleUtils.dropSemanticModelAndTables(op.getOracleDB(), model,
null, null, networkOwner, networkName);
sr.shutDown();
store.shutDown();
op.close();
}
}
}
To run this example for an existing MDSYS network, execute the following command:
To run this example for an existing schema-private network whose owner is SCOTT
and name is NET1, execute the following command:
number of matches: 2
import java.io.PrintStream;
import java.sql.SQLException;
import oracle.rdf4j.adapter.OraclePool;
8-50
Chapter 8
Example Queries Using Oracle RDF Graph Adapter for Eclipse RDF4J
import oracle.rdf4j.adapter.OracleRepository;
import oracle.rdf4j.adapter.OracleSailStore;
import oracle.rdf4j.adapter.exception.ConnectionSetupException;
import oracle.rdf4j.adapter.utils.OracleUtils;
import org.eclipse.rdf4j.model.IRI;
import org.eclipse.rdf4j.model.Literal;
import org.eclipse.rdf4j.model.ValueFactory;
import org.eclipse.rdf4j.model.vocabulary.RDF;
import org.eclipse.rdf4j.query.BindingSet;
import org.eclipse.rdf4j.query.QueryLanguage;
import org.eclipse.rdf4j.query.TupleQuery;
import org.eclipse.rdf4j.query.TupleQueryResult;
import org.eclipse.rdf4j.repository.Repository;
import org.eclipse.rdf4j.repository.RepositoryConnection;
OraclePool op = null;
OracleSailStore store = null;
Repository sr = null;
RepositoryConnection conn = null;
try {
op = new OraclePool(jdbcUrl, user, password);
store = new OracleSailStore(op, model, networkOwner, networkName);
sr = new OracleRepository(store);
conn = sr.getConnection();
ValueFactory f = conn.getValueFactory();
conn.begin();
conn.clear();
// Alice
IRI alice = f.createIRI("http://example.org/people/alice");
IRI name = f.createIRI("http://example.org/ontology/name");
IRI person = f.createIRI("http://example.org/ontology/Person");
Literal alicesName = f.createLiteral("Alice");
conn.add(alice, RDF.TYPE, person);
conn.add(alice, name, alicesName);
//Bob
IRI bob = f.createIRI("http://example.org/people/bob");
Literal bobsName = f.createLiteral("Bob");
8-51
Chapter 8
Example Queries Using Oracle RDF Graph Adapter for Eclipse RDF4J
conn.commit();
String queryString =
" PREFIX ex: <http://example.org/ontology/> " +
" Select ?name \n" + " WHERE \n" + " { SELECT * WHERE { ?
person ex:name ?name} }\n" +
" ORDER BY ?name";
8-52
Chapter 8
Example Queries Using Oracle RDF Graph Adapter for Eclipse RDF4J
To run this example for an existing MDSYS network, execute the following command:
To run this example for an existing schema-private network whose owner is SCOTT and
name is NET1, execute the following command:
solution [name="Alice";person=http://example.org/people/alice]
solution [name="Bob";person=http://example.org/people/bob]
import java.io.PrintStream;
import java.sql.SQLException;
import oracle.rdf4j.adapter.OraclePool;
import oracle.rdf4j.adapter.OracleRepository;
import oracle.rdf4j.adapter.OracleSailStore;
import oracle.rdf4j.adapter.exception.ConnectionSetupException;
import oracle.rdf4j.adapter.utils.OracleUtils;
import org.eclipse.rdf4j.query.BindingSet;
import org.eclipse.rdf4j.query.QueryLanguage;
import org.eclipse.rdf4j.query.TupleQuery;
import org.eclipse.rdf4j.query.TupleQueryResult;
import org.eclipse.rdf4j.query.Update;
import org.eclipse.rdf4j.repository.Repository;
import org.eclipse.rdf4j.repository.RepositoryConnection;
8-53
Chapter 8
Example Queries Using Oracle RDF Graph Adapter for Eclipse RDF4J
"[p=http://example.org/ontology/name;g=urn:g1;x=http://example.org/
people/Sue;y=\"Susan\"]" +
"[p=http://www.w3.org/1999/02/22-rdf-syntax-
ns#type;g=urn:g1;x=http://example.org/people/Sue;y=http://example.org/
ontology/Person]" +
"[p=http://example.org/ontology/name;g=urn:g2;x=http://example.org/
people/Sue;y=\"Susan\"]" +
"[p=http://www.w3.org/1999/02/22-rdf-syntax-
ns#type;g=urn:g2;x=http://example.org/people/Sue;y=http://example.org/
ontology/Person]";
8-54
Chapter 8
Example Queries Using Oracle RDF Graph Adapter for Eclipse RDF4J
OraclePool op = null;
OracleSailStore store = null;
Repository sr = null;
RepositoryConnection conn = null;
try {
op = new OraclePool(jdbcUrl, user, password);
store = new OracleSailStore(op, model, networkOwner, networkName);
sr = new OracleRepository(store);
conn = sr.getConnection();
8-55
Chapter 8
Example Queries Using Oracle RDF Graph Adapter for Eclipse RDF4J
// Add contents of g2 to g1
updString = "PREFIX people: <http://example.org/people/>\n" +
"PREFIX ont: <http://example.org/ontology/>\n" +
"ADD <urn:g2> TO <urn:g1>";
upd = conn.prepareUpdate(QueryLanguage.SPARQL, updString);
upd.execute();
conn.commit();
repositoryData = getRepositoryData(conn, out);
if (! (DATA_5.equals(repositoryData)) ) out.println("DATA_5
mismatch");
}
finally {
if (conn != null && conn.isOpen()) {
conn.clear();
conn.close();
}
OracleUtils.dropSemanticModelAndTables(op.getOracleDB(), model,
null, null, networkOwner, networkName);
sr.shutDown();
store.shutDown();
op.close();
}
}
}
To run this example for an existing MDSYS network, execute the following command:
To run this example for an existing schema-private network whose owner is SCOTT
and name is NET1, execute the following command:
8-56
Chapter 8
Example Queries Using Oracle RDF Graph Adapter for Eclipse RDF4J
[p=http://example.org/ontology/name;g=urn:g1;x=http://example.org/people/
Sue;y="Sue"]
[p=http://www.w3.org/1999/02/22-rdf-syntax-ns#type;g=urn:g1;x=http://
example.org/people/Sue;y=http://example.org/ontology/Person]
[p=http://example.org/ontology/name;g=urn:g1;x=http://example.org/people/
Sue;y="Susan"]
[p=http://www.w3.org/1999/02/22-rdf-syntax-ns#type;g=urn:g1;x=http://
example.org/people/Sue;y=http://example.org/ontology/Person]
[p=http://example.org/ontology/name;g=urn:g1;x=http://example.org/people/
Sue;y="Susan"]
[p=http://www.w3.org/1999/02/22-rdf-syntax-ns#type;g=urn:g1;x=http://
example.org/people/Sue;y=http://example.org/ontology/Person]
[p=http://example.org/ontology/name;g=urn:g2;x=http://example.org/people/
Sue;y="Susan"]
[p=http://www.w3.org/1999/02/22-rdf-syntax-ns#type;g=urn:g2;x=http://
example.org/people/Sue;y=http://example.org/ontology/Person]
[p=http://www.w3.org/1999/02/22-rdf-syntax-ns#type;g=urn:g1;x=http://
example.org/people/Sue;y=http://example.org/ontology/Person]
[p=http://example.org/ontology/name;g=urn:g2;x=http://example.org/people/
Sue;y="Susan"]
[p=http://www.w3.org/1999/02/22-rdf-syntax-ns#type;g=urn:g2;x=http://
example.org/people/Sue;y=http://example.org/ontology/Person]
[p=http://example.org/ontology/name;g=urn:g1;x=http://example.org/people/
Sue;y="Susan"]
[p=http://www.w3.org/1999/02/22-rdf-syntax-ns#type;g=urn:g1;x=http://
example.org/people/Sue;y=http://example.org/ontology/Person]
[p=http://example.org/ontology/name;g=urn:g2;x=http://example.org/people/
Sue;y="Susan"]
[p=http://www.w3.org/1999/02/22-rdf-syntax-ns#type;g=urn:g2;x=http://
example.org/people/Sue;y=http://example.org/ontology/Person]
import java.sql.SQLException;
import oracle.rdf4j.adapter.OracleDB;
import oracle.rdf4j.adapter.OraclePool;
import oracle.rdf4j.adapter.OracleRepository;
import oracle.rdf4j.adapter.OracleSailStore;
import oracle.rdf4j.adapter.exception.ConnectionSetupException;
import oracle.rdf4j.adapter.utils.OracleUtils;
import org.eclipse.rdf4j.query.BindingSet;
import org.eclipse.rdf4j.query.QueryLanguage;
import org.eclipse.rdf4j.query.TupleQuery;
import org.eclipse.rdf4j.query.TupleQueryResult;
import org.eclipse.rdf4j.query.Update;
import org.eclipse.rdf4j.repository.Repository;
import org.eclipse.rdf4j.repository.RepositoryConnection;
8-57
Chapter 8
Example Queries Using Oracle RDF Graph Adapter for Eclipse RDF4J
OraclePool op = null;
OracleSailStore store = null;
Repository sr = null;
RepositoryConnection conn = null;
try {
op = new OraclePool(jdbcUrl, user, password);
store = new OracleSailStore(op, model, networkOwner,
networkName);
sr = new OracleRepository(store);
conn = sr.getConnection();
TupleQuery tupleQuery =
conn.prepareTupleQuery(QueryLanguage.SPARQL, sparql);
8-58
Chapter 8
Example Queries Using Oracle RDF Graph Adapter for Eclipse RDF4J
Update u = conn.prepareUpdate(sparql);
u.execute();
8-59
Chapter 8
Example Queries Using Oracle RDF Graph Adapter for Eclipse RDF4J
To run this example for an existing MDSYS network, execute the following command:
To run this example for an existing schema-private network whose owner is SCOTT
and name is NET1, execute the following command:
import java.io.PrintStream;
import java.sql.SQLException;
import oracle.rdf4j.adapter.OracleDB;
import oracle.rdf4j.adapter.OraclePool;
import oracle.rdf4j.adapter.OracleRepository;
import oracle.rdf4j.adapter.OracleSailStore;
8-60
Chapter 8
Example Queries Using Oracle RDF Graph Adapter for Eclipse RDF4J
import oracle.rdf4j.adapter.exception.ConnectionSetupException;
import oracle.rdf4j.adapter.utils.OracleUtils;
import org.eclipse.rdf4j.model.IRI;
import org.eclipse.rdf4j.model.Literal;
import org.eclipse.rdf4j.model.ValueFactory;
import org.eclipse.rdf4j.model.vocabulary.RDF;
import org.eclipse.rdf4j.query.BindingSet;
import org.eclipse.rdf4j.query.QueryLanguage;
import org.eclipse.rdf4j.query.TupleQuery;
import org.eclipse.rdf4j.query.TupleQueryResult;
import org.eclipse.rdf4j.repository.Repository;
import org.eclipse.rdf4j.repository.RepositoryConnection;
try {
op = new OraclePool(jdbcUrl, user, password);
store = (networkName == null) ? new OracleSailStore(op, model) : new
OracleSailStore(op, model, networkOwner, networkName);
sr = new OracleRepository(store);
conn = sr.getConnection();
ValueFactory f = conn.getValueFactory();
conn.begin();
conn.clear();
//Bob
IRI bob = f.createIRI("http://example.org/people/bob");
Literal bobsName = f.createLiteral("Bob");
conn.add(bob, RDF.TYPE, person);
8-61
Chapter 8
Example Queries Using Oracle RDF Graph Adapter for Eclipse RDF4J
conn.commit();
8-62
Chapter 8
Example Queries Using Oracle RDF Graph Adapter for Eclipse RDF4J
op.close();
}
}
}
To run this example for an existing MDSYS network, execute the following command:
To run this example for an existing schema-private network whose owner is SCOTT and
name is NET1, execute the following command:
solution [name="Alice";person=http://example.org/people/alice]
solution [name="Bob";person=http://example.org/people/bob]
import java.io.IOException;
import java.io.PrintStream;
import java.sql.SQLException;
import oracle.rdf4j.adapter.OraclePool;
import oracle.rdf4j.adapter.OracleRepository;
import oracle.rdf4j.adapter.OracleSailStore;
import oracle.rdf4j.adapter.OracleSailConnection;
import oracle.rdf4j.adapter.exception.ConnectionSetupException;
import oracle.rdf4j.adapter.utils.OracleUtils;
import org.eclipse.rdf4j.model.IRI;
import org.eclipse.rdf4j.model.Literal;
import org.eclipse.rdf4j.model.ValueFactory;
import org.eclipse.rdf4j.model.vocabulary.RDF;
import org.eclipse.rdf4j.model.vocabulary.RDFS;
import org.eclipse.rdf4j.query.BindingSet;
import org.eclipse.rdf4j.query.QueryLanguage;
import org.eclipse.rdf4j.query.TupleQuery;
import org.eclipse.rdf4j.query.TupleQueryResult;
import org.eclipse.rdf4j.repository.Repository;
import org.eclipse.rdf4j.repository.RepositoryConnection;
8-63
Chapter 8
Example Queries Using Oracle RDF Graph Adapter for Eclipse RDF4J
import oracle.rdf4j.adapter.Attachment;
import oracle.rdf4j.adapter.OracleSailConnection;
import oracle.rdf4j.adapter.OracleSailRepositoryConnection;
OraclePool op = null;
OracleSailStore store = null;
Repository sr = null;
RepositoryConnection conn = null;
try {
op = new OraclePool(jdbcUrl, user, password);
ValueFactory f = sr.getValueFactory();
conn = sr.getConnection();
8-64
Chapter 8
Example Queries Using Oracle RDF Graph Adapter for Eclipse RDF4J
triples)
osc.performInference();
// run the same query again: returns some results because alice and
bob now belong to superclass Person
try (TupleQueryResult result = tupleQuery.evaluate()) {
while (result.hasNext()) {
BindingSet bindingSet = result.next();
psOut.println("value of x: " + bindingSet.getValue("x"));
psOut.println("value of y: " + bindingSet.getValue("y"));
}
}
}
finally {
if (conn != null && conn.isOpen()) {
conn.clear();
conn.close();
}
OracleUtils.dropSemanticModelAndTables(op.getOracleDB(), model, null,
null, networkOwner, networkName);
sr.shutDown();
store.shutDown();
op.close();
}
}
}
8-65
Chapter 8
Example Queries Using Oracle RDF Graph Adapter for Eclipse RDF4J
To run this example for an existing MDSYS network, execute the following command:
To run this example for an existing schema-private network whose owner is SCOTT
and name is NET1, execute the following command:
number of results: 0
value of x: http://example.org/people/alice
value of y: http://example.org/people/bob
import java.io.IOException;
import java.io.PrintStream;
import java.sql.SQLException;
import oracle.rdf4j.adapter.OraclePool;
import oracle.rdf4j.adapter.OracleRepository;
import oracle.rdf4j.adapter.OracleSailStore;
import oracle.rdf4j.adapter.exception.ConnectionSetupException;
import oracle.rdf4j.adapter.utils.OracleUtils;
import org.eclipse.rdf4j.model.IRI;
import org.eclipse.rdf4j.model.ValueFactory;
import org.eclipse.rdf4j.model.vocabulary.RDF;
import org.eclipse.rdf4j.model.vocabulary.RDFS;
import org.eclipse.rdf4j.query.BindingSet;
import org.eclipse.rdf4j.query.QueryLanguage;
import org.eclipse.rdf4j.query.TupleQuery;
import org.eclipse.rdf4j.query.TupleQueryResult;
import org.eclipse.rdf4j.repository.Repository;
import org.eclipse.rdf4j.repository.RepositoryConnection;
import oracle.rdf4j.adapter.Attachment;
8-66
Chapter 8
Example Queries Using Oracle RDF Graph Adapter for Eclipse RDF4J
OraclePool op = null;
try {
op = new OraclePool(jdbcUrl, user, password);
// create two models and then a virtual model that uses those two
models
8-67
Chapter 8
Example Queries Using Oracle RDF Graph Adapter for Eclipse RDF4J
// clear any data (in case any of the two non-virtual models
were already present)
conn.clear();
conn2.clear();
// run the same query again: returns some additional info in the
results
try (TupleQueryResult result = tupleQuery.evaluate()) {
int resultCount = 0;
while (result.hasNext()) {
resultCount++;
BindingSet bindingSet = result.next();
psOut.println("values of x | xC | y | yC: " +
8-68
Chapter 8
Example Queries Using Oracle RDF Graph Adapter for Eclipse RDF4J
vmSr.shutDown();
vmStore.shutDown();
op.close();
}
}
}
To run this example for an existing MDSYS network, execute the following command:
To run this example for an existing schema-private network whose owner is SCOTT and
name is NET1, execute the following command:
8-69
Chapter 8
Example Queries Using Oracle RDF Graph Adapter for Eclipse RDF4J
8-70
9
User-Defined Inferencing and Querying
RDF Semantic Graph extension architectures enable the addition of user-defined capabilities.
Effective with Oracle Database 12c Release 1 (12.1):
• The inference extension architecture enables you to add user-defined inferencing to the
presupplied inferencing support.
• The query extension architecture enables you to add user-defined functions and
aggregates to be used in SPARQL queries, both through the SEM_MATCH table function
and through the support for Apache Jena.
Note:
The capabilities described in this chapter are intended for advanced users. You are
assumed to be familiar with the main concepts and techniques described in RDF
Semantic Graph Overview and OWL Concepts .
• User-Defined Inferencing
The RDF Semantic Graph inference extension architecture enables you to add user-
defined inferencing to the presupplied inferencing support.
• User-Defined Functions and Aggregates
The RDF Semantic Graph query extension architecture enables you to add user-defined
functions and aggregates to be used in SPARQL queries, both through the SEM_MATCH
table function and through the support for Apache Jena.
9-1
Chapter 9
User-Defined Inferencing
?C rdfs:subClassOf ?D .
?x rdf:type ?C . ==> ?x rdf:type ?D
The preceding rule says that any instance x of a subclass C will be an instance of C's
superclass, D. The consequent part of the rule mentions two variables ?x and ?D.
However, these variables must already exist in the antecedents of the rule, which
further implies that these RDF resources must already exist in the knowledge base. In
other words, for example, you can derive that John is a Student only if you know that
John exists as a GraduateStudent and if an axiom specifies that the GraduateStudent
class is a subclass of the Student class.
Another example of a limitation is that before Oracle Database 12c Release 1 (12.1),
the inference functions did not support combining a person's first name and last name
to produce a full name as a new RDF resource in the inference process. Specifically,
this requirement can be captured as a rule like the following:
?x :firstName ?fn
?x :lastName ?ln ==> ?x :fullName concatenate(?fn ?ln)
Effective with Oracle Database 12c Release 1 (12.1), the RDF Semantic Graph
inference extension architecture opens the inference process so that users can
implement their own inference extension functions and integrate them into the native
inference process. This architecture:
• Supports rules that require the generation of new RDF resources.
Examples might include concatenation of strings or other string operations,
mathematical calculations, and web service callouts.
• Allows implementation of certain existing rules using customized optimizations.
Although the native OWL inference engine has optimizations for many rules and
these rules work efficiently for a variety of large-scale ontologies, for some new
untested ontologies a customized optimization of a particular inference component
may work even better. In such a case, you can disable a particular inference
component in the SEM_APIS.CREATE_ENTAILMENT call and specify a
customized inference extension function (using the inf_ext_user_func_name
parameter) that implements the new optimization.
• Allows the inference engine to be extended with sophisticated inference
capabilities.
Examples might include integrating geospatial reasoning, time interval reasoning,
and text analytical functions into the native database inference process.
9-2
Chapter 9
User-Defined Inferencing
In the user-defined function format, the optimization_flag output parameter can specify one
or more Oracle-defined names that are associated with numeric values. You can specify one
or more of the following:
• SDO_SEM_INFERENCE.INF_EXT_OPT_FLAG_NONE indicates that the inference engine should
not enable any optimizations for the extension function. (This is the default behavior of
the inference engine when the optimization_flag parameter is not set.)
• SDO_SEM_INFERENCE.INF_EXT_OPT_FLAG_ALL_IDS indicates that all triples/quads inferred
by the extension function use only resource IDs. In other words, the output_tab table
only contains resource IDs (columns gid, sid, pid, and oid) and does not contain any
lexical values (columns g, s, p, and o are all null). Enabling this optimization flag allows
the inference engine to skip resource ID lookups.
• SDO_SEM_INFERENCE.INF_EXT_OPT_FLAG_NEWDATA_ONLY indicates that all the triples/quads
inferred by the extension function are new and do not already exist in src_tab_view.
9-3
Chapter 9
User-Defined Inferencing
Enabling this optimization flag allows the inference engine to skip checking for
duplicates between the output_tab table and src_tab_view. Note that the
src_tab_view contains triples/quads from previous rounds of reasoning, including
triples/quads inferred from extension functions.
• SDO_SEM_INFERENCE.INF_EXT_OPT_FLAG_UNIQDATA_ONLY indicates that all the
triples/quads inferred by the extension function are unique and do not already exist
in the output_tab table. Enabling this optimization flag allows the inference engine
to skip checking for duplicates within the output_tab table (for example, no need
to check for the same triple inferred twice by an extension function). Note that the
output_tab table is empty at the beginning of each round of reasoning for an
extension function, so uniqueness of the data must only hold for the current round
of reasoning.
• SDO_SEM_INFERENCE.INF_EXT_OPT_FLAG_IGNORE_NULL indicates that the inference
engine should ignore an inferred triple or quad if the subject, predicate, or object
resource is null. The inference engine considers a resource null if both of its
columns in the output_tab table are null (for example, subject is null if the s and
sid columns are both null). Enabling this optimization flag allows the inference
engine to skip invalid triples/quads in the output_tab table. Note that the inference
engine interprets null graph columns (g and gid) as the default graph.
To specify more than one value for the optimization_flag output parameter, use the
plus sign (+) to concatenate the values. For example:
optimization_flag := SDO_SEM_INFERENCE.INF_EXT_OPT_FLAG_ALL_IDS +
SDO_SEM_INFERENCE.INF_EXT_OPT_FLAG_NEWDATA_ONLY +
SDO_SEM_INFERENCE.INF_EXT_OPT_FLAG_UNIQDATA_ONLY;
For more information about using the optimization_flag output parameter, see
Example 3: Optimizing Performance.
9-4
Chapter 9
User-Defined Inferencing
For requirements and guidelines for creating user-defined inference extension functions, see
API Support for User-Defined Inferencing.
• Example 1: Adding Static Triples
• Example 2: Adding Dynamic Triples
• Example 3: Optimizing Performance
• Example 4: Temporal Reasoning (Several Related Examples)
• Example 5: Spatial Reasoning
• Example 6: Calling a Web Service
The following user-defined inference extension function (sem_inf_static) adds three static
triples to an entailment:
-- this user-defined rule adds static triples
create or replace function sem_inf_static(
src_tab_view in varchar2,
resource_id_map_view in varchar2,
output_tab in varchar2,
action in varchar2,
num_calls in number,
tplInferredLastRound in number,
options in varchar2 default null,
optimization_flag out number,
diag_message out varchar2
)
return boolean
as
query varchar2(4000);
pragma autonomous_transaction;
begin
if (action = 'RUN') then
-- generic query we use to insert triples
query :=
'insert /*+ parallel append */ into ' || output_tab ||
' ( s, p, o) VALUES ' ||
' (:1, :2, :3) ';
9-5
Chapter 9
User-Defined Inferencing
-- duplicate quad
execute immediate query using
'<http://example.org/S2>', '<http://example.org/P2>', '"2"^^xsd:int';
The sem_inf_static function inserts new data by executing a SQL insert query, with
output_tab as the target table for insertion. The output_tab table will only contain
triples added by the sem_inf_static function during the current call (see the
num_calls parameter). The inference engine will always call a user-defined inference
extension function at least three times, once for each possible value of the action
parameter ('START', 'RUN', and 'END'). Because sem_inf_static does not need to
perform any preparation or cleanup, the function only adds data during the RUN phase.
The extension function can be called more than once during the RUN phase, depending
on the data inferred during the current round of reasoning.
Although the sem_inf_static function makes no checks for existing triples (to prevent
duplicate triples), the inference engine will not generate duplicate triples in the
resulting entailment. The inference engine will filter out duplicates from the output_tab
table (the data inserted by the extension function) and from the final entailment (the
model or models and other inferred data). Setting the appropriate optimization flags
(using the optimization_flag parameter) will disable this convenience feature and
improve performance. (See Example 3: Optimizing Performance for more information
about optimization flags.)
Although the table definition for output_tab shows a column for graph names, the
inference engine will ignore and override all graph names on triples added by
extension functions when performing Global Inference (default behavior of
SEM_APIS.CREATE_ENTAILMENT) and Named Graph Global Inference (NGGI). To
add triples to specific named graphs in a user-defined extension function, use NGLI
(Named Graph Local Inference). During NGLI, all triples must belong to a named
graph (that is, the gid and g columns of output_tab cannot both be null).
The MDSYS user must have execute privileges on the sem_inf_static function to use
the function for reasoning. The following example shows how to grant the appropriate
privileges on the sem_inf_static function and create an entailment using the function
(along with OWLPRIME inference logic):
-- grant appropriate privileges
grant execute on sem_inf_static to mdsys;
9-6
Chapter 9
User-Defined Inferencing
-- show results
select s, p, o from table(SEM_MATCH(
'select ?s ?p ?o where { ?s ?p ?o } order by ?s ?p ?o'
, sem_models('EMPLOYEES')
, sem_rulebases('OWLPRIME')
, null, null, null
, 'INF_ONLY=T'));
The preceding query returns the three unique static triples added by sem_inf_static, with no
duplicates:
S P O
---------------------- ---------------------- -----------------------
http://example.org/S1 http://example.org/P2 O1
http://example.org/S2 http://example.org/P2 2
http://example.org/S3 http://example.org/P3 3E0
9-7
Chapter 9
User-Defined Inferencing
return boolean
as
firstNamePropertyId number;
lastNamePropertyId number;
fullNamePropertyId number;
sqlStmt varchar2(4000);
insertStmt varchar2(4000);
pragma autonomous_transaction;
begin
if (action = 'RUN') then
-- retrieve ID of resource that already exists in the data (will
-- throw exception if resource does not exist). These will improve
-- performance of our SQL queries.
firstNamePropertyId := sdo_sem_inference.oracle_orardf_res2vid('http://
example.org/firstName');
lastNamePropertyId := sdo_sem_inference.oracle_orardf_res2vid('http://
example.org/lastName');
fullNamePropertyId := sdo_sem_inference.oracle_orardf_res2vid('http://
example.org/name');
-- SQL query to find all employees and their first and last names
sqlStmt :=
'select ids1.sid employeeId,
values1.value_name firstName,
values2.value_name lastName
from ' || resource_id_map_view || ' values1,
' || resource_id_map_view || ' values2,
' || src_tab_view || ' ids1,
' || src_tab_view || ' ids2
where ids1.sid = ids2.sid
AND ids1.pid = ' || to_char(firstNamePropertyId,'TM9') || '
AND ids2.pid = ' || to_char(lastNamePropertyId,'TM9') || '
AND ids1.oid = values1.value_id
AND ids2.oid = values2.value_id
/* below ensures we have NEWDATA (a no duplicate optimization flag) */
AND not exists
(select 1
from ' || src_tab_view || '
where sid = ids1.sid AND
pid = ' || to_char(fullNamePropertyId,'TM9') || ')';
9-8
Chapter 9
User-Defined Inferencing
The sem_inf_dynamic function inserts new data using two main steps. First, the function
builds a SQL query that collects all first and last names from the existing data. The sqlStmt
variable stores this SQL query. Next, the function inserts new triples based on the first and
last names it collects, to form a full name for each employee. The insertStmt variable stores
this SQL query. Note that the insertStmt query includes the sqlStmt query because it is
performing an INSERT with a subquery.
The sqlStmt query performs a join across two main views: the resource view
(resource_id_map_view) and the existing data view (src_tab_view). The existing data view
contains all existing triples but stores the values of those triples using numeric IDs instead of
lexical values. Because the sqlStmt query must extract the lexical values of the first and last
names of an employee, it joins with the resource view twice (once for the first name and once
for the last name).
The sqlStmt query contains the PARALLEL SQL hint to help improve performance. Parallel
execution on a balanced hardware configuration can significantly improve performance. (See
Example 3: Optimizing Performance for more information.)
The insertStmt query also performs a duplicate check to avoid adding a triple if it already
exists in the existing data view (src_tab_view). The function indicates it has performed this
check by enabling the INF_EXT_OPT_FLAG_NEWDATA_ONLY optimization flag. Doing the check
inside the extension function improves overall performance of the reasoning. Note that the
existing data view does not contain the new triples currently being added by the
sem_inf_dynamic function, so duplicates may still exist within the output_tab table. If the
sem_inf_dynamic function additionally checked for duplicates within the output_tab table,
then it could also enable the INF_EXT_OPT_FLAG_UNIQUEDATA_ONLY optimization flag.
Both SQL queries use numeric IDs of RDF resources to perform their joins and inserts. Using
IDs instead of lexical values improves the performance of the queries. The sem_inf_dynamic
function takes advantage of this performance benefit by looking up the IDs of the lexical
values it plans to use. In this case, the function looks up three URIs representing the first
name, last name, and full name properties. If the sem_inf_dynamic function inserted all new
triples purely as IDs, then it could enable the INF_EXT_OPT_FLAG_ALL_IDS optimization flag.
For this example, however, the new triples each contain a single, new, lexical value: the full
name of the employee.
To create an entailment with the sem_inf_dynamic function, grant execution privileges to the
MDSYS user, then pass the function name to the SEM_APIS.CREATE_ENTAILMENT
procedure, as follows:
-- grant appropriate privileges
grant execute on sem_inf_dynamic to mdsys;
9-9
Chapter 9
User-Defined Inferencing
);
end;
/
The entailment should contain the following two new triples added by
sem_inf_dynamic:
S P O
------------------------ ------------------------ -----------------------
http://example.org/Bob http://example.org/name Bob Billow
http://example.org/John http://example.org/name John Smith
Note that the sem_inf_dynamic function in the preceding example did not infer a full
name for Mary Smith, because Mary Smith already had her full name specified in the
existing data.
sqlStmt varchar2(4000);
insertStmt varchar2(4000);
pragma autonomous_transaction;
begin
if (action = 'RUN') then
-- retrieve ID of resource that already exists in the data (will
-- throw exception if resource does not exist).
lastNamePropertyId := sdo_sem_inference.oracle_orardf_res2vid('http://
example.org/lastName');
9-10
Chapter 9
User-Defined Inferencing
9-11
Chapter 9
User-Defined Inferencing
The sem_inf_related function has a few key differences from previous examples.
First, the sem_inf_related function queries purely with resource IDs and inserts new
triples using only resource IDs. Because all the added triples in the output_tab table
only use resource IDs, the function can enable the INF_EXT_OPT_FLAG_ALL_IDS
optimization flag. For optimal performance, functions should try to use resource IDs
over lexical values. However, sometimes this is not possible, as in Example 2: Adding
Dynamic Triples, which concatenates lexical values to form a new lexical value. Note
that in cases like Example 2: Adding Dynamic Triples, it is usually better to join with
the resource view (resource_id_map_view) than to embed calls to
oracle_orardf_res2vid within the SQL query. This is due to the overhead of calling
the function for each possible match as opposed to joining with another table.
Another key difference in the sem_inf_related function is the use of the
oracle_orardf_add_res function (compared to oracle_orardf_res2vid). Unlike the
res2vid function, the add_res function will add a resource to the resource view
(resource_id_map_view) if the resource does not already exist. Inference extensions
functions should use the add_res function if adding the resource to the resource view
is not a concern. Calling the function multiple times will not generate duplicate entries
in the resource view.
The last main difference is the additional NOT EXISTS clause in the SQL query. The
first NOT EXISTS clause avoids adding any triples that may be duplicates of triples
already in the model or triples inferred by other rules (src_tab_view). Checking for
these duplicates allows sem_inf_related to enable the
INF_EXT_OPT_FLAG_NEWDATA_ONLY optimization flag. The second NOT EXISTS clause
avoids adding triples that may be duplicates of triples already added by the
sem_inf_related function to the output_tab table during the current round of
reasoning (see the num_calls parameter). Checking for these duplicates allows
sem_inf_related to enable the INF_EXT_OPT_FLAG_UNIQDATA_ONLY optimization flag.
The entailment should contain the following two new triples added by
sem_inf_related:
9-12
Chapter 9
User-Defined Inferencing
S P O
------------------------ ------------------------------------ ------------------------
http://example.org/John http://example.org/possibleRelative http://example.org/Mary
http://example.org/Mary http://example.org/possibleRelative http://example.org/John
EVENT_ONT
@prefix owl: <http://www.w3.org/2002/07/owl#> .
@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 : <http://example.org/event/> .
EVENT_TBOX
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
@prefix : <http://example.org/event/> .
9-13
Chapter 9
User-Defined Inferencing
xsdTimeFormat varchar2(100);
sqlStmt varchar2(4000);
insertStmt varchar2(4000);
pragma autonomous_transaction;
begin
if (action = 'RUN') then
-- retrieve ID of resource that already exists in the data (will
-- throw exception if resource does not exist).
eventClassId := sdo_sem_inference.oracle_orardf_res2vid('http://
example.org/event/Event');
startTimePropertyId := sdo_sem_inference.oracle_orardf_res2vid('http://
example.org/event/startTime');
endTimePropertyId := sdo_sem_inference.oracle_orardf_res2vid('http://
example.org/event/endTime');
durationPropertyId := sdo_sem_inference.oracle_orardf_res2vid('http://
example.org/event/lengthInMins');
rdfTypePropertyId := sdo_sem_inference.oracle_orardf_res2vid('http://
9-14
Chapter 9
User-Defined Inferencing
www.w3.org/1999/02/22-rdf-syntax-ns#type');
9-15
Chapter 9
User-Defined Inferencing
-- in output_tab (UNIQDATA)
optimization_flag := SDO_SEM_INFERENCE.INF_EXT_OPT_FLAG_NEWDATA_ONLY +
SDO_SEM_INFERENCE.INF_EXT_OPT_FLAG_UNIQDATA_ONLY;
In addition to the triples inferred by OWLPRIME, the entailment should contain the
following three new triples added by sem_inf_durations:
9-16
Chapter 9
User-Defined Inferencing
S P O
---------------------------- -------------------------------------- ---------
http://example.org/event/m1 http://example.org/event/lengthInMins 90
http://example.org/event/m2 http://example.org/event/lengthInMins 60
http://example.org/event/p1 http://example.org/event/lengthInMins 120
xsdTimeFormat varchar2(100);
sqlStmt varchar2(4000);
insertStmt varchar2(4000);
pragma autonomous_transaction;
begin
if (action = 'RUN') then
-- retrieve ID of resource that already exists in the data (will
-- throw exception if resource does not exist).
eventClassId := sdo_sem_inference.oracle_orardf_res2vid('http://example.org/
event/Event');
startTimePropertyId := sdo_sem_inference.oracle_orardf_res2vid('http://example.org/
event/startTime');
endTimePropertyId := sdo_sem_inference.oracle_orardf_res2vid('http://example.org/
event/endTime');
overlapsPropertyId := sdo_sem_inference.oracle_orardf_res2vid('http://example.org/
event/overlaps');
noOverlapPropertyId := sdo_sem_inference.oracle_orardf_res2vid('http://example.org/
event/noOverlap');
rdfTypePropertyId := sdo_sem_inference.oracle_orardf_res2vid('http://www.w3.org/
1999/02/22-rdf-syntax-ns#type');
9-17
Chapter 9
User-Defined Inferencing
sqlStmt :=
'select idsA1.sid eventAId,
idsB1.sid eventBId,
TO_TIMESTAMP_TZ(valuesA1.value_name,''YYYY-MM-
DD"T"HH24:MI:SSTZH:TZM'') startTimeA,
TO_TIMESTAMP_TZ(valuesA2.value_name,''YYYY-MM-
DD"T"HH24:MI:SSTZH:TZM'') endTimeA,
TO_TIMESTAMP_TZ(valuesB1.value_name,''YYYY-MM-
DD"T"HH24:MI:SSTZH:TZM'') startTimeB,
TO_TIMESTAMP_TZ(valuesB2.value_name,''YYYY-MM-
DD"T"HH24:MI:SSTZH:TZM'') endTimeB
from ' || resource_id_map_view || ' valuesA1,
' || resource_id_map_view || ' valuesA2,
' || resource_id_map_view || ' valuesB1,
' || resource_id_map_view || ' valuesB2,
' || src_tab_view || ' idsA1,
' || src_tab_view || ' idsA2,
' || src_tab_view || ' idsA3,
' || src_tab_view || ' idsB1,
' || src_tab_view || ' idsB2,
' || src_tab_view || ' idsB3
where idsA1.sid = idsA3.sid
AND idsA3.pid = ' || to_char(rdfTypePropertyId,'TM9') || '
AND idsA3.oid = ' || to_char(eventClassId,'TM9') || '
AND idsB1.sid = idsB3.sid
AND idsB3.pid = ' || to_char(rdfTypePropertyId,'TM9') || '
AND idsB3.oid = ' || to_char(eventClassId,'TM9') || '
/* only do half the checks, our TBOX ontology will handle symmetries */
AND idsA1.sid < idsB1.sid
/* grab values of startTime and endTime for event A */
AND idsA1.sid = idsA2.sid
AND idsA1.pid = ' || to_char(startTimePropertyId,'TM9') || '
AND idsA2.pid = ' || to_char(endTimePropertyId,'TM9') || '
AND idsA1.oid = valuesA1.value_id
AND idsA2.oid = valuesA2.value_id
/* grab values of startTime and endTime for event B */
AND idsB1.sid = idsB2.sid
AND idsB1.pid = ' || to_char(startTimePropertyId,'TM9') || '
AND idsB2.pid = ' || to_char(endTimePropertyId,'TM9') || '
AND idsB1.oid = valuesB1.value_id
AND idsB2.oid = valuesB2.value_id
/* ensures we have NEWDATA */
AND not exists
(select 1
from ' || src_tab_view || '
where sid = idsA1.sid
AND oid = idsB1.sid
AND pid in (' || to_char(overlapsPropertyId,'TM9') || ',' ||
to_char(noOverlapPropertyId,'TM9') || '))
/* ensures we have UNIQDATA */
AND not exists
(select 1
from ' || output_tab || '
where sid = idsA1.sid
AND oid = idsB1.sid
AND pid in (' || to_char(overlapsPropertyId,'TM9') || ',' ||
to_char(noOverlapPropertyId,'TM9') || '))';
9-18
Chapter 9
User-Defined Inferencing
9-19
Chapter 9
User-Defined Inferencing
In addition to the triples inferred by OWLPRIME, the entailment should contain the
following six new triples added by sem_inf_overlap:
S P O
---------------------------- -----------------------------------
----------------------------
http://example.org/event/m1 http://example.org/event/noOverlap http://
example.org/event/m2
http://example.org/event/m1 http://example.org/event/noOverlap http://
example.org/event/p1
http://example.org/event/m2 http://example.org/event/noOverlap http://
example.org/event/m1
http://example.org/event/m2 http://example.org/event/overlaps http://
example.org/event/p1
http://example.org/event/p1 http://example.org/event/noOverlap http://
example.org/event/m1
http://example.org/event/p1 http://example.org/event/overlaps http://
example.org/event/m2
In addition to the triples inferred by OWLPRIME, the entailment should contain the
following nine new triples added by sem_inf_durations and sem_inf_overlap:
S P O
---------------------------- --------------------------------------
----------------------------
http://example.org/event/m1 http://example.org/event/lengthInMins 90
http://example.org/event/m1 http://example.org/event/noOverlap http://
example.org/event/m2
http://example.org/event/m1 http://example.org/event/noOverlap http://
example.org/event/p1
http://example.org/event/m2 http://example.org/event/lengthInMins 60
9-20
Chapter 9
User-Defined Inferencing
Notice that the extension functions, sem_inf_durations and sem_inf_overlap, did not need
to use the same optimization flags. It is possible to use extension functions with contradictory
optimization flags (for example, one function using INF_EXT_OPT_FLAG_ALL_IDS and another
function inserting all new triples as lexical values).
9-21
Chapter 9
User-Defined Inferencing
output_tab in varchar2,
action in varchar2,
num_calls in number,
tplInferredLastRound in number,
options in varchar2 default null,
optimization_flag out number,
diag_message out varchar2
)
return boolean
as
stateClassId number;
capitalClassId number;
boundaryPropertyId number;
locationPropertyId number;
rdfTypePropertyId number;
capitalPropertyId number;
xsdTimeFormat varchar2(100);
sqlStmt varchar2(4000);
insertStmt varchar2(4000);
pragma autonomous_transaction;
begin
if (action = 'RUN') then
-- retrieve ID of resource that already exists in the data (will
-- throw exception if resource does not exist).
stateClassId := sdo_sem_inference.oracle_orardf_res2vid('http://
example.org/geo/State');
capitalClassId := sdo_sem_inference.oracle_orardf_res2vid('http://
example.org/geo/StateCapital');
boundaryPropertyId := sdo_sem_inference.oracle_orardf_res2vid('http://
example.org/geo/boundary');
locationPropertyId := sdo_sem_inference.oracle_orardf_res2vid('http://
example.org/geo/location');
rdfTypePropertyId := sdo_sem_inference.oracle_orardf_res2vid('http://
www.w3.org/1999/02/22-rdf-syntax-ns#type');
9-22
Chapter 9
User-Defined Inferencing
9-23
Chapter 9
User-Defined Inferencing
exception
when others then
diag_message := 'error occurred: ' || SQLERRM;
return false;
end sem_inf_capitals;
/
show errors;
In addition to the triples inferred by OWLPRIME, the entailment should contain the
following three new triples added by sem_inf_capitals:
S P O
-------------------------------- -------------------------------
--------------------------------
http://example.org/geo/Colorado http://example.org/geo/capital http://
example.org/geo/Denver
http://example.org/geo/Utah http://example.org/geo/capital http://
example.org/geo/SaltLake
9-24
Chapter 9
User-Defined Inferencing
In this case, an inference call using sem_inf_geocoding will produce the following new
assertions:
<urn:NEDC> <http://www.w3.org/2003/01/geo/wgs84_pos#long> "-71.46421"
<urn:NEDC> <http://www.w3.org/2003/01/geo/wgs84_pos#lat> "42.75836"
<urn:NEDC> <http://www.opengis.net/geosparql#asWKT> "POINT(-71.46421
42.75836)"^^<http://www.opengis.net/geosparql#wktLiteral>
<urn:NEDC> <http://xmlns.oracle.com/rdf/geo/asWKT> "POINT(-71.46421
42.75836)"^^<http://xmlns.oracle.com/rdf/geo/WKTLiteral>
nLong number;
nLat number;
nWKT number;
nOWKT number;
nStreetAddr number;
sidTab dbms_sql.number_table;
oidTab dbms_sql.number_table;
vcRequestBody varchar2(32767);
vcStmt varchar2(32767);
vcStreeAddr varchar2(3000);
9-25
Chapter 9
User-Defined Inferencing
vcLat varchar2(100);
begin
if (action = 'START') then
nLat := sdo_sem_inference.oracle_orardf_add_res('http://www.w3.org/
2003/01/geo/wgs84_pos#lat');
nLong := sdo_sem_inference.oracle_orardf_add_res('http://www.w3.org/
2003/01/geo/wgs84_pos#long');
nWKT := sdo_sem_inference.oracle_orardf_add_res('http://www.opengis.net/
geosparql#asWKT');
nOWKT := sdo_sem_inference.oracle_orardf_add_res('http://
xmlns.oracle.com/rdf/geo/asWKT');
end if;
vcStmt := '
select /*+ parallel */ distinct s1.sid as s_id, s1.oid as o_id
from ' || src_tab_view || ' s1
where s1.pid = :1
and not exists ( select 1
from ' || src_tab_view || ' x
where x.sid = s1.sid
and x.pid = :2
) ';
open cursorFind for vcStmt using nStreetAddr, nLong;
loop
fetch cursorFind bulk collect into sidTab, oidTab limit 10000;
for i in 1..sidTab.count loop
vcStreeAddr := sdo_sem_inference.oracle_orardf_vid2lit(oidTab(i));
-- dbms_output.put_line('Now processing street addr ' || vcStreeAddr);
geocoding(vcStreeAddr, vcLong, vcLat);
execute immediate 'insert into ' || output_tab ||
'(sid,pid,oid,gid,s,p,o,g)
values(:1, :2, null, null, null, null, :3, null) '
using sidTab(i), nLong, '"'||vcLong||'"';
execute immediate 'insert into ' || output_tab ||
'(sid,pid,oid,gid,s,p,o,g)
values(:1, :2, null, null, null, null, :3, null) '
using sidTab(i), nLat, '"'||vcLat||'"';
execute immediate 'insert into ' || output_tab ||
'(sid,pid,oid,gid,s,p,o,g)
values(:1, :2, null, null, null, null, :3, null) '
using sidTab(i), nWKT, '"POINT('|| vcLong || ' ' ||vcLat
||')"^^<http://www.opengis.net/geosparql#wktLiteral>';
execute immediate 'insert into ' || output_tab ||
'(sid,pid,oid,gid,s,p,o,g)
values(:1, :2, null, null, null, null, :3, null) '
using sidTab(i), nOWKT, '"POINT('|| vcLong || ' ' ||vcLat
||')"^^<http://xmlns.oracle.com/rdf/geo/WKTLiteral>';
end loop;
9-26
Chapter 9
User-Defined Inferencing
The sem_inf_geocoding function makes use of the following helper procedure named
geocoding, which does the actual HTTP communication with the Geocoder web service
endpoint. Note that proper privileges are required to connect to the web server.
create or replace procedure geocoding(addr varchar2,
vcLong out varchar2,
vcLat out varchar2
)
as
httpReq utl_http.req;
httpResp utl_http.resp;
vcRequestBody varchar2(32767);
vcBuffer varchar2(32767);
idxLat integer;
idxLatEnd integer;
begin
vcRequestBody := utl_url.escape('xml_request=<?xml version="1.0" standalone="yes"?>
<geocode_request vendor="elocation">
<address_list>
<input_location id="27010">
<input_address match_mode="relax_street_type">
<unformatted country="US">
<address_line value="'|| addr ||'"/>
</unformatted>
</input_address>
</input_location>
</address_list>
</geocode_request>
');
dbms_output.put_line('request ' || vcRequestBody);
-- utl_http.set_proxy('<your_proxy_here_if_necessary>', null);
httpReq := utl_http.begin_request (
'http://maps.oracle.com/geocoder/gcserver', 'POST');
utl_http.write_text(httpReq, vcRequestBody);
httpResp := utl_http.get_response(httpReq);
9-27
Chapter 9
User-Defined Functions and Aggregates
9-28
Chapter 9
User-Defined Functions and Aggregates
VNAME_PREFIX VARCHAR2(4000),
VNAME_SUFFIX VARCHAR2(512),
LITERAL_TYPE VARCHAR2(1000),
LANGUAGE_TYPE VARCHAR2(80),
LONG_VALUE CLOB,
CTX1 VARCHAR2(4000) )
The following constructors are available for creating SDO_RDF_TERM objects. The first
constructor populates each attribute from a single, lexical RDF term string. The second and
third constructors receive individual attribute values as input. Only the first RDF term string
constructor sets values for VNAME_PREFIX and VNAME_SUFFIX. These values are
initialized to null by the other constructors.
SDO_RDF_TERM (
rdf_term_str VARCHAR2)
RETURN SELF;
SDO_RDF_TERM (
value_type VARCHAR2,
value_name VARCHAR2,
literal_type VARCHAR2,
language_type VARCHAR2,
long_value CLOB)
RETURN SELF;
SDO_RDF_TERM (
value_type VARCHAR2,
value_name VARCHAR2,
literal_type VARCHAR2,
language_type VARCHAR2,
long_value CLOB,
ctx1 VARCHAR2)
RETURN SELF;
9-29
Chapter 9
User-Defined Functions and Aggregates
This signature supports an arbitrary number of RDF term arguments, which are
passed in using a single SDO_RDF_TERM_LIST object, and returns a single RDF
term as output, which is represented as a single SDO_RDF_TERM object. Type
checking or other verifications for these parameters are not performed. You should
take steps to validate the data according to the function goals.
Note that PL/SQL supports callouts to functions written in other programming
languages, such as C and Java, so the PL/SQL function that implements a user-
defined query function can serve only as a wrapper for functions written in other
programming languages.
<http://xmlns.oracle.com/rdf/extensions/my_schema.my_function>(arg_1, …, arg_n)
9-30
Chapter 9
User-Defined Functions and Aggregates
Note that the sum_squares function in Example 9-1 does not verify the data type of the value
received. It is intended as a demonstration only, and relies on TO_NUMBER to obtain the
numeric value stored in the VALUE_NAME field of SDO_RDF_TERM.
Example 9-2 User-Defined Function Used in a FILTER Clause
Example 9-2 shows the sum_squares function (from Example 9-1) used in a FILTER clause.
SELECT s, o
FROM table(sem_match(
'SELECT ?s ?o
WHERE { ?s ?p ?o
FILTER (<http://xmlns.oracle.com/rdf/extensions/schema.sum_squares>(?o,?o) > 2)}',
sem_models('MYMODEL'),null,null,null,null,''));
9-31
Chapter 9
User-Defined Functions and Aggregates
b 1.5 4.5
c 3 18
d 4 32
9-32
Chapter 9
User-Defined Functions and Aggregates
This scheme results in the following signatures for the PL/SQL ODCIAggregate interface
functions (with my_aggregate_obj_type representing the actual object type name):
STATIC FUNCTION ODCIAggregateInitialize(
sctx IN OUT my_aggregate_obj_type)
RETURN NUMBER
The DISTINCT modifier can be used with user-defined aggregates, as in the following
example:
<http://xmlns.oracle.com/rdf/aggExtensions/schema.my_aggregate>(DISTINCT arg_1)
In this case, only distinct argument values are passed to the aggregate. Note, however, that
the DISTINCT modifier can only be used with aggregates that have exactly one argument.
9-33
Chapter 9
User-Defined Functions and Aggregates
9-34
Chapter 9
User-Defined Functions and Aggregates
END;
/
SHOW ERRORS;
9-35
Chapter 9
User-Defined Functions and Aggregates
c 2
d 0
9-36
10
RDF Views: Relational Data as RDF
You can create and use RDF views over relational data in RDF Semantic Graph.
Relational data is viewed as virtual RDF triples using one of the two forms of RDB2RDF
mapping described in W3C documents on Direct Mapping and R2RML mapping:
• R2RML: RDB to RDF Mapping Language, W3C Recommendation (http://
www.w3.org/TR/r2rml/)
• A Direct Mapping of Relational Data to RDF, W3C Recommendation (http://
www.w3.org/TR/rdb-direct-mapping/)
This chapter explains the following topics:
• Why Use RDF Views on Relational Data?
Using RDF views on relational data enables you to query relational data using SPARQL
and integrate data available from different sources.
• API Support for RDF Views
Subprograms are included in the SEM_APIS package for creating, dropping, and
exporting (that is, materializing the content of) RDF views.
• Example: Using an RDF View Model with Direct Mapping
This section shows an example of using an RDF view model with direct mapping.
• Combining Native RDF Data with Virtual RDB2RDF Data
You can combine native triple data with virtual RDB2RDF triple data (from an RDF view
model) in a single SEM_MATCH query by means of the SERVICE keyword.
10-1
Chapter 10
API Support for RDF Views
An RDF view model is created as an RDF model, but the RDF model physically
contains only the mapping metadata. The actual data remains in the relational tables
for which the RDF view model has been created. (The SEM_APIS subprograms are
documented in SEM_APIS Package Subprograms.)
Once an RDF view model is created, you can also materialize the RDF triples into a
staging table by using the SEM_APIS.EXPORT_RDFVIEW_MODEL subprogram.
For the examples throughout this chapter, assume that the relational tables, EMP and
DEPT, are present in the TESTUSER schema (see Section 10.3 for the definitions of these
two tables). Also, assume that a schema-private network, named NET1 and owned by
the RDFUSER schema, already exists and RDFUSER has READ privilege on these
two tables.
For the example illustrating the use of exporting of RDF triples, assume that the
staging table to which the materialized RDF triples will be stored are owned by
TESTUSER and the network owner has INSERT privilege on that table.
BEGIN
sem_apis.create_rdfview_model(
model_name => 'empdb_model',
tables => SYS.ODCIVarchar2List('"TESTUSER"."EMP"',
'"TESTUSER"."DEPT"'),
prefix => 'http://empdb/',
options => 'KEY_BASED_REF_PROPERTY=T',
network_owner=>'RDFUSER',
network_name=>'NET1'
);
END;
/
To see the properties that are generated, enter the following query:
SELECT p
FROM TABLE(SEM_MATCH(
'SELECT DISTINCT ?p {?s ?p ?o} ORDER BY ?p',
SEM_Models('empdb_model'),
NULL, NULL, NULL, NULL,
NULL, NULL, NULL,
10-2
Chapter 10
API Support for RDF Views
'RDFUSER', 'NET1'));
P
-----------------------------------------------------------------------------
---
http://empdb/TESTUSER.EMP#EMPNO
http://empdb/TESTUSER.EMP#JOB
http://empdb/TESTUSER.EMP#ENAME
http://empdb/TESTUSER.EMP#DEPTNO
http://www.w3.org/1999/02/22-rdf-syntax-ns#type
http://empdb/TESTUSER.EMP#ref-DEPTNO
http://empdb/TESTUSER.DEPT#DEPTNO
http://empdb/TESTUSER.DEPT#DNAME
http://empdb/TESTUSER.DEPT#LOC
9 rows selected.
ex:TriplesMap_Dept
rr:logicalTable [ rr:tableName "TESTUSER.DEPT" ];
rr:subjectMap [
rr:template "http://data.example.com/department/{DEPTNO}";
rr:class ex:Department;
];
rr:predicateObjectMap [
rr:predicate ex:deptNum;
rr:objectMap [ rr:column "DEPTNO" ; rr:datatype xsd:integer ];
];
rr:predicateObjectMap [
rr:predicate ex:deptName;
rr:objectMap [ rr:column "DNAME" ];
];
rr:predicateObjectMap [
rr:predicate ex:deptLocation;
rr:objectMap [ rr:column "LOC" ];
].
ex:TriplesMap_Emp
rr:logicalTable [ rr:tableName "TESTUSER.EMP" ];
rr:subjectMap [
rr:template "http://data.example.com/employee/{EMPNO}";
rr:class ex:Employee;
];
rr:predicateObjectMap [
rr:predicate ex:empNum;
rr:objectMap [ rr:column "EMPNO" ; rr:datatype xsd:integer ];
];
10-3
Chapter 10
API Support for RDF Views
rr:predicateObjectMap [
rr:predicate ex:empName;
rr:objectMap [ rr:column "ENAME" ];
];
rr:predicateObjectMap [
rr:predicate ex:jobType;
rr:objectMap [ rr:column "JOB" ];
];
rr:predicateObjectMap [
rr:predicate ex:worksForDeptNum;
rr:objectMap [ rr:column "DEPTNO" ; rr:dataType xsd:integer ];
];
rr:predicateObjectMap [
rr:predicate ex:worksForDept;
rr:objectMap [
rr:parentTriplesMap ex:TriplesMap_Dept ;
rr:joinCondition [ rr:child "DEPTNO"; rr:parent "DEPTNO" ]]].
Example 10-2 Creating an RDF View Model with an R2RML Mapping String
The following example creates an RDF view model directly from an R2RML string,
using the preceding R2RML mapping:
DECLARE
r2rmlStr CLOB;
BEGIN
r2rmlStr :=
'@prefix rr: <http://www.w3.org/ns/r2rml#>. '||
'@prefix xsd: <http://www.w3.org/2001/XMLSchema#>. '||
'@prefix ex: <http://example.com/ns#>. '||'
ex:TriplesMap_Dept
rr:logicalTable [ rr:tableName "TESTUSER.DEPT" ];
rr:subjectMap [
rr:template "http://data.example.com/department/{DEPTNO}";
rr:class ex:Department;
];
rr:predicateObjectMap [
rr:predicate ex:deptNum;
rr:objectMap [ rr:column "DEPTNO" ; rr:datatype
xsd:integer ];
];
rr:predicateObjectMap [
rr:predicate ex:deptName;
rr:objectMap [ rr:column "DNAME" ];
];
rr:predicateObjectMap [
rr:predicate ex:deptLocation;
rr:objectMap [ rr:column "LOC" ];
].'||'
ex:TriplesMap_Emp
rr:logicalTable [ rr:tableName "TESTUSER.EMP" ];
10-4
Chapter 10
API Support for RDF Views
rr:subjectMap [
rr:template "http://data.example.com/employee/{EMPNO}";
rr:class ex:Employee;
];
rr:predicateObjectMap [
rr:predicate ex:empNum;
rr:objectMap [ rr:column "EMPNO" ; rr:datatype xsd:integer ];
];
rr:predicateObjectMap [
rr:predicate ex:empName;
rr:objectMap [ rr:column "ENAME" ];
];
rr:predicateObjectMap [
rr:predicate ex:jobType;
rr:objectMap [ rr:column "JOB" ];
];
rr:predicateObjectMap [
rr:predicate ex:worksForDeptNum;
rr:objectMap [ rr:column "DEPTNO" ; rr:dataType xsd:integer ];
];
rr:predicateObjectMap [
rr:predicate ex:worksForDept;
rr:objectMap [
rr:parentTriplesMap ex:TriplesMap_Dept ;
rr:joinCondition [ rr:child "DEPTNO"; rr:parent "DEPTNO" ]]].';
sem_apis.create_rdfview_model(
model_name => 'empdb_model',
tables => NULL,
r2rml_string => r2rmlStr,
r2rml_string_fmt => 'TURTLE',
network_owner=>'RDFUSER',
network_name=>'NET1'
);
END;
/
BEGIN
sem_apis.drop_rdfview_model(
model_name => 'empdb_model',
network_owner=>'RDFUSER',
network_name=>'NET1'
);
END;
/
10-5
Chapter 10
Example: Using an RDF View Model with Direct Mapping
BEGIN
sem_apis.export_rdfview_model(
model_name => 'empdb_model',
rdf_table_owner => 'TESTUSER',
rdf_table_name => 'R2RTAB',
network_owner => 'RDFUSER',
network_name => 'NET1'
);
END;
PL/SQL procedure successfully completed.
10-6
Chapter 10
Example: Using an RDF View Model with Direct Mapping
3. Connect as RDFUSER and create an RDF view model, empdb_model, using direct mapping
of the two tables created and populated in the preceding steps.
-- Create an RDF view model using direct mapping of two tables, EMP and
DEPT,
-- with a base prefix of http://empdb/.
-- Specify KEY_BASED_REF_PROPERTY=T for the options parameter.
BEGIN
sem_apis.create_rdfview_model(
model_name => 'empdb_model',
tables => SYS.ODCIVarchar2List('"TESTUSER"."EMP"',
'"TESTUSER"."DEPT"'),
prefix => 'http://empdb/',
options => 'KEY_BASED_REF_PROPERTY=T'
network_owner=>'RDFUSER',
network_name=>'NET1'
);
END;
/
4. Query the newly created RDF view model using a SEM_MATCH-based SQL query.
SELECT emp
FROM TABLE(SEM_MATCH(
'PREFIX dept: <http://empdb/TESTUSER.DEPT#>
PREFIX emp: <http://empdb/TESTUSER.EMP#>
SELECT ?emp {?emp emp:ref-DEPTNO ?dept . ?dept dept:LOC "Boston"}',
SEM_Models('empdb_model'),
NULL,
10-7
Chapter 10
Combining Native RDF Data with Virtual RDB2RDF Data
NULL,
NULL, NULL,NULL, NULL,NULL, 'RDFUSER', 'NET1'));
EMP
--------------------------------------------------------------------
------------
http://empdb/TESTUSER.EMP/EMPNO=1
http://empdb/TESTUSER.EMP/EMPNO=3
EMPNO
----------
1
3
10-8
Chapter 10
Combining Native RDF Data with Virtual RDB2RDF Data
SEM_MODELS('m1'), NULL, NULL, NULL, NULL, ' ', NULL, NULL, 'RDFUSER',
'NET1'));
Overloaded SERVICE use is only allowed with a single model specified in the models
argument of SEM_MATCH. Overloaded SERVICE queries do not allow multiple models or a
rulebase as input. A virtual model that contains multiple models and/or entailments should be
used instead for such combinations. In addition, the index_status argument for
SEM_MATCH will only check the entailment contained in the virtual model passed as input in
the models parameter. This means the status of entailments that are referenced in
overloaded SERVICE calls will not be checked.
Example 10-6 queries two data sets: the empdb_model from Example: Using an RDF View
Model with Direct Mapping and a native model named people.
Example 10-6 Querying Virtual RDB2RDF Data and Native RDF Data in a Schema-
Private Network
BEGIN
sem_apis.update_model('people',
'PREFIX peop: <http://people.org/>
INSERT DATA {
<http://empdb/TESTUSER.EMP/EMPNO=1> peop:age 35 .
<http://empdb/TESTUSER.EMP/EMPNO=2> peop:age 39 .
<http://empdb/TESTUSER.EMP/EMPNO=3> peop:age 30 .
<http://empdb/TESTUSER.EMP/EMPNO=4> peop:age 42 .
} ');
END;
/
COMMIT;
EMP AGE
--------------------------------------------------
10-9
Chapter 10
Combining Native RDF Data with Virtual RDB2RDF Data
--------------------------------------------------
http://empdb/TESTUSER.EMP/EMPNO=1 35
http://empdb/TESTUSER.EMP/EMPNO=3 30
EMP DEPT
P O
---------------------------------- -----------------------------------
------------------------------------------------
--------------------------
http://empdb/TESTUSER.EMP/EMPNO=1 http://empdb/TESTUSER.DEPT/
DEPTNO=1 http://empdb/TESTUSER.DEPT#DEPTNO 1
http://empdb/TESTUSER.EMP/EMPNO=1 http://empdb/TESTUSER.DEPT/
DEPTNO=1 http://empdb/TESTUSER.DEPT#DNAME Sales
http://empdb/TESTUSER.EMP/EMPNO=1 http://empdb/TESTUSER.DEPT/
DEPTNO=1 http://empdb/TESTUSER.DEPT#LOC Boston
http://empdb/TESTUSER.EMP/EMPNO=1 http://empdb/TESTUSER.DEPT/
DEPTNO=1 http://www.w3.org/1999/02/22-rdf-syntax-ns#type http://
empdb/TESTUSER.DEPT
To get all the results that match for given graph pattern, first the triple pattern { ?emp
peop:age 35 } is matched against model people, then the triple patterns { ?emp
emp:ref-DEPTNO ?d . ?d dept:DNAME ?dept } are matched against model
empdb_model, and finally the results are joined. Assume that there is only one 35-year-
old person in the model people, but there are 100,000 triples with information about
departments. Obviously, a strategy that retrieves all the results is not the most efficient,
10-10
Chapter 10
Combining Native RDF Data with Virtual RDB2RDF Data
and query may have poor performance because a large number of results that need to be
processed before being joined with the rest of the query.
An nested-loop service can improve performance in this case. If the hint OVERLOADED_NL=T is
used, the results of the first part of the query are computed and the SERVICE pattern is
executed procedurally in a nested loop once for each ?emp value from the root triple pattern.
The ?emp subject variable in the SERVICE pattern is replaced with a constant from the root
triple pattern in each execution. This effectively pushes the join condition down into the
SERVICE clause.
The following example shows the use of the OVERLOADED_NL=T hint for the preceding query.
The hint OVERLOADED_NL=T can be specified among SEM_MATCH options or among inline
comments for a given SERVICE graph.
10-11
11
RDF Integration with Property Graph Data
Stored in Oracle Database
The property graph data model is supported in Oracle Graph. Oracle Graph provides built-in
support for RDF views of property graph data stored in Oracle Database.
• About RDF Integration with Property Graph Data
• R2RML Mapping for the Property Graph Relational Schema
You can use the built-in R2RML mapping to construct an RDF view from the property
graph relational schema.
• PL/SQL API for Creating and Maintaining Property Graph RDF Views
Subprograms in the SEM_APIS package simplify the creation and maintenance of
property graph RDF views.
• Sample RDF Workflow with Property Graph Data
This topic presents a sample RDF workflow with property graph data.
• Special Considerations When Using Property Graph RDF Views
The following special considerations apply when using property graph RDF views.
11-1
Chapter 11
About RDF Integration with Property Graph Data
The example shown in the following figure illustrates a property graph to RDF
mapping. Note that edges in the property graph model become an RDF quad, where
the predicate is the edge label and the named graph is a URI constructed from the
edge identifier. Edge properties are then modeled as RDF quads within the named
graph for the edge. As an illustration, the Trig serialization for RDF graph in the
following figure is as follows:
11-2
Chapter 11
About RDF Integration with Property Graph Data
Figure 11-1 Equivalent Property Graph and RDF Representations of the Same Graph
In the preceding figure, the property graph model at the top is simpler than the RDF model at
the bottom. Both models show four vertices (nodes) representing four people (John, Jill,
Frank, Susan), but the property graph model shows simple boxes for name and label
information. The property graph model shows many edges with properties represented using
the following prefixes:
• PREFIX edge: <http://xminx,oracle.com/pg/edge/>
• PREFIX vertex: <http://xminx,oracle.com/pg/vertex/>
• PREFIX ep: <http://xminx,oracle.com/pg/property/edge/>
11-3
Chapter 11
R2RML Mapping for the Property Graph Relational Schema
• PREFIX vp http://xminx,oracle.com/pg/property/vertex/>
• PREFIX label: <http://xminx,oracle.com/pg/property/edge/label/>
-- 5 VT$ views --
-- Varchar --
create or replace view "USER"."M1$V1" as
select
"VID",
to_char(substr("K",1,200)) KC,
"T",
to_char("V") VC,
"SL",
"VTS",
"VTE",
"FE"
from "USER"."G1VT$"
where T=1;
-- Number --
create or replace view "USER"."M1$V2" as
select
"VID",
to_char(substr("K",1,200)) KC,
"T",
"VN",
"SL",
"VTS",
"VTE",
"FE"
from "USER"."G1VT$"
where T IN (2,3,4);
-- DateTime --
create or replace view "USER"."M1$V3" as
select
"VID",
to_char(substr("K",1,200)) KC,
"T",
"VT",
"SL",
11-4
Chapter 11
R2RML Mapping for the Property Graph Relational Schema
"VTS",
"VTE",
"FE"
from "USER"."G1VT$"
where T=5;
-- Boolean --
create or replace view "USER"."M1$V4" as
select
"VID",
to_char(substr("K",1,200)) KC,
"T",
DECODE("V",'y',to_char('true'),
'Y',to_char('true'),
'n',to_char('false'),
'N',to_char('false')) VB,
"SL",
"VTS",
"VTE",
"FE"
from "USER"."G1VT$"
where T=6;
-- ID View –
create or replace view "USER"."M1$VT" as
select DISTINCT
"VID"
from "USER"."G1VT$";
-- 4 GE$ Views --
-- Varchar --
create or replace view "USER"."M1$G1" as
select
"EID",
"SVID",
"DVID",
"EL",
to_char(substr("K",1,200)) KC,
"T",
to_char("V") VC,
"SL",
"VTS",
"VTE",
"FE"
from "USER"."G1GE$"
where T=1;
-- Number --
create or replace view "USER"."M1$G2" as
select
"EID",
"SVID",
"DVID",
"EL",
to_char(substr("K",1,200)) KC,
11-5
Chapter 11
R2RML Mapping for the Property Graph Relational Schema
"T",
"VN",
"SL",
"VTS",
"VTE",
"FE"
from "USER"."G1GE$"
where T IN (2,3,4);
-- DateTime --
create or replace view "USER"."M1$G3" as
select
"EID",
"SVID",
"DVID",
"EL",
to_char(substr("K",1,200)) KC,
"T",
"VT",
"SL",
"VTS",
"VTE",
"FE"
from "USER"."G1GE$"
where T=5;
-- Boolean --
create or replace view "USER"."M1$G4" as
select
"EID",
"SVID",
"DVID",
"EL",
to_char(substr("K",1,200)) KC,
"T",
DECODE("V",'y',to_char('true'),
'Y',to_char('true'),
'n',to_char('false'),
'N',to_char('false')) VB,
"SL",
"VTS",
"VTE",
"FE"
from "USER"."G1GE$"
where T=6;
-- GT$ View –
create or replace view "USER"."M1$GT" as
select DISTINCT
"EID",
"SVID",
"DVID",
to_char(substr("EL",1,200)) LC
from "USER"."G1GE$";
11-6
Chapter 11
R2RML Mapping for the Property Graph Relational Schema
The built-in R2RML mapping that uses these views is shown in the following output in turtle
format.
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>.
@prefix rr: <http://www.w3.org/ns/r2rml#>.
@prefix xsd: <http://www.w3.org/2001/XMLSchema#>.
@prefix pg: <http://xmlns.oracle.com/pg/>.
@prefix pgvtpr: <http://xmlns.oracle.com/pg/property/vertex/>.
@prefix pgedpr: <http://xmlns.oracle.com/pg/property/edge/>.
# Vertex Property views ===============================================
pg:TMap_VERTEXPR_VC_TAB
rr:logicalTable [ rr:tableName "\"USER\".\"M1$V1\"" ] ;
rr:subjectMap [
rr:template "http://xmlns.oracle.com/pg/vertex/v{VID}" ;
rr:class pg:VERTEX ] ;
rr:predicateObjectMap [
rr:predicateMap [
rr:template "http://xmlns.oracle.com/pg/property/vertex/{KC}" ] ;
rr:objectMap [ rr:column "VC" ]
]
.
pg:TMap_VERTEXPR_VN_TAB
rr:logicalTable [ rr:tableName "\"USER\".\"M1$V2\"" ] ;
rr:subjectMap [
rr:template "http://xmlns.oracle.com/pg/vertex/v{VID}" ;
rr:class pg:VERTEX ] ;
rr:predicateObjectMap [
rr:predicateMap [
rr:template "http://xmlns.oracle.com/pg/property/vertex/{KC}" ] ;
rr:objectMap [
rr:column "VN" ;
rr:datatype xsd:decimal ]
]
.
pg:TMap_VERTEXPR_VT_TAB
rr:logicalTable [
rr:tableName "\"USER\".\"M1$V3\"" ] ;
rr:subjectMap [
rr:template "http://xmlns.oracle.com/pg/vertex/v{VID}" ;
rr:class pg:VERTEX ] ;
rr:predicateObjectMap [
rr:predicateMap [
rr:template "http://xmlns.oracle.com/pg/property/vertex/{KC}" ] ;
rr:objectMap [
rr:column "VT" ;
rr:datatype xsd:dateTime ]
]
.
pg:TMap_VERTEXPR_VB_TAB
rr:logicalTable [
rr:tableName "\"USER\".\"M1$V4\"" ] ;
rr:subjectMap [
rr:template "http://xmlns.oracle.com/pg/vertex/v{VID}" ;
rr:class pg:VERTEX ] ;
rr:predicateObjectMap [
rr:predicateMap [
rr:template "http://xmlns.oracle.com/pg/property/vertex/{KC}" ] ;
rr:objectMap [
rr:column "VB" ;
rr:datatype xsd:boolean ]
]
11-7
Chapter 11
R2RML Mapping for the Property Graph Relational Schema
.
# VERTEX ID view ==============================================
pg:TMap_VERTEXID_TAB
rr:logicalTable [
rr:tableName "\"USER\".\"M1$VT\"" ] ;
rr:subjectMap [
rr:template "http://xmlns.oracle.com/pg/vertex/v{VID}" ;
rr:class pg:VERTEX ] ;
rr:predicateObjectMap [
rr:predicate pgvtpr:id ;
rr:objectMap [
rr:column "VID" ]
]
.
# Edge Property views ===============================================
pg:TMap_EDGEPR_VC_TAB
rr:logicalTable [
rr:tableName "\"USER\".\"M1$G1\"" ] ;
rr:subjectMap [
rr:template "http://xmlns.oracle.com/pg/edge/e{EID}" ;
rr:graphMap [
rr:template "http://xmlns.oracle.com/pg/edge/e{EID}" ] ] ;
rr:predicateObjectMap [
rr:predicateMap [
rr:template "http://xmlns.oracle.com/pg/property/edge/{KC}" ] ;
rr:objectMap [
rr:column "VC" ]
]
.
pg:TMap_EDGEPR_VN_TAB
rr:logicalTable [
rr:tableName "\"USER\".\"M1$G2\"" ] ;
rr:subjectMap [
rr:template "http://xmlns.oracle.com/pg/edge/e{EID}" ;
rr:graphMap [
rr:template "http://xmlns.oracle.com/pg/edge/e{EID}" ] ] ;
rr:predicateObjectMap [
rr:predicateMap [
rr:template "http://xmlns.oracle.com/pg/property/edge/{KC}" ] ;
rr:objectMap [
rr:column "VN" ;
rr:datatype xsd:decimal ]
]
.
pg:TMap_EDGEPR_VT_TAB
rr:logicalTable [
rr:tableName "\"USER\".\"M1$G3\"" ] ;
rr:subjectMap [
rr:template "http://xmlns.oracle.com/pg/edge/e{EID}" ;
rr:graphMap [
rr:template "http://xmlns.oracle.com/pg/edge/e{EID}" ] ] ;
rr:predicateObjectMap [
rr:predicateMap [
rr:template "http://xmlns.oracle.com/pg/property/edge/{KC}" ] ;
rr:objectMap [
rr:column "VT" ;
rr:datatype xsd:dateTime ]
]
.
pg:TMap_EDGEPR_VB_TAB
rr:logicalTable [
11-8
Chapter 11
PL/SQL API for Creating and Maintaining Property Graph RDF Views
rr:tableName "\"USER\".\"M1$G4\"" ] ;
rr:subjectMap [
rr:template "http://xmlns.oracle.com/pg/edge/e{EID}" ;
rr:graphMap [
rr:template "http://xmlns.oracle.com/pg/edge/e{EID}" ] ] ;
rr:predicateObjectMap [
rr:predicateMap [
rr:template "http://xmlns.oracle.com/pg/property/edge/{KC}" ] ;
rr:objectMap [
rr:column "VB" ;
rr:datatype xsd:boolean ]
]
.
# Edge IDLABEL views ==========================================
pg:TMap_EDGEIDLABEL_TAB
rr:logicalTable [
rr:tableName "\"USER\".\"M1$GT\"" ] ;
rr:subjectMap [
rr:template "http://xmlns.oracle.com/pg/edge/e{EID}" ;
rr:class pg:EDGE ;
rr:graphMap [
rr:template "http://xmlns.oracle.com/pg/edge/e{EID}" ] ] ;
rr:predicateObjectMap [
rr:predicate pgedpr:id ;
rr:objectMap [
rr:column "EID" ]
] ;
rr:predicateObjectMap [
rr:predicate pgedpr:label ;
rr:objectMap [
rr:column "LC" ]
]
.
# Edge views ===================================================
pg:TMap_EDGE_TAB
rr:logicalTable [
rr:tableName "\"USER\".\"M1$GT\"" ] ;
rr:subjectMap [
rr:template "http://xmlns.oracle.com/pg/vertex/v{SVID}" ;
rr:graphMap [
rr:template "http://xmlns.oracle.com/pg/edge/e{EID}" ] ] ;
rr:predicateObjectMap [
rr:predicateMap [
rr:template "http://xmlns.oracle.com/pg/label/{LC}" ] ;
rr:objectMap [
rr:template "http://xmlns.oracle.com/pg/vertex/v{DVID}" ;
rr:termType rr:IRI ]
]
.
11-9
Chapter 11
Sample RDF Workflow with Property Graph Data
Example 11-2 Find the Names and Ages of All of John’s Friends
Example 11-3 Find the Names and Ages of All of John’s Good Friends (Weight
> 1.5)
11-10
Chapter 11
Special Considerations When Using Property Graph RDF Views
SELECT name$rdfterm
FROM TABLE(SEM_MATCH(
'PREFIX edge: <http://xmlns.oracle.com/pg/edge/>
PREFIX vertex: <http://xmlns.oracle.com/pg/vertex/>
PREFIX ep: <http://xmlns.oracle.com/pg/property/edge/>
PREFIX vp: <http://xmlns.oracle.com/pg/property/vertex/>
PREFIX label: <http://xmlns.oracle.com/pg/property/edge/label/>
SELECT ?name
WHERE {
?v1 vp:name "John" .
GRAPH ?e {
?v1 label:friend_of ?v2 .
?e ep:weight ?w .
}
?v2 vp:name ?name . }
ORDER BY DESC(?w)
LIMIT 1'
, sem_models('M1')
, null, null, null, null
, ' PLUS_RDFT=VC '));
11-11
Chapter 11
Special Considerations When Using Property Graph RDF Views
11-12
Part II
RDF Graph Server and Query UI
Part II provides information about using RDF Graph Server and Query UI.
This part contains the following chapters:
• Introduction to RDF Graph Server and Query UI
The RDF Graph Server and Query UI allows you to run SPARQL queries and perform
advanced RDF graph data management operations using a REST API and an Oracle
JET based query UI.
• RDF Graph Server and Query UI Concepts
Learn the key concepts for using the RDF Graph Server and Query UI.
• Oracle RDF Graph Query UI
The Oracle RDF Graph Query UI is an Oracle JET based client that can be used to
manage RDF objects from different data sources, and to perform SPARQL queries and
updates.
12
Introduction to RDF Graph Server and Query
UI
The RDF Graph Server and Query UI allows you to run SPARQL queries and perform
advanced RDF graph data management operations using a REST API and an Oracle JET
based query UI.
The RDF Graph Server and Query UI consists of RDF RESTful services and a Java EE client
application called RDF Graph Query UI. This client serves as an administrative console for
Oracle RDF and can be deployed to a Java EE container.
The RDF Graph Server and RDF RESTful services can be used to create a SPARQL
endpoint for RDF graphs in Oracle Database.
The following figure shows the RDF Graph Server and Query UI architecture:
12-1
Chapter 12
• Allows you to perform CRUD operations on various RDF objects such as private
networks, models, rule bases, entailments, network indexes and data types for
Oracle data sources.
• Allows you to execute SPARQL queries and update RDF data.
• Provides a graph view of SPARQL query results.
• Uses Oracle JET for user application web pages.
12-2
13
RDF Graph Server and Query UI Concepts
Learn the key concepts for using the RDF Graph Server and Query UI.
• Data Sources
Data sources are repositories of RDF objects.
• RDF Datasets
Each RDF data source contains metadata information that describe the avaliable RDF
objects.
• REST Services
An RDF REST API allows communication between client and backend RDF data stores.
13-1
Chapter 13
Data Sources
* Host machine
* Database listening port
* User name and password credentials
– For a container data source:
* JNDI name - Java naming and directory interface (JNDI) name
– For a wallet data source:
* A string describing the wallet service
* User name and password credentials (required if the user credentials are
not stored in the wallet)
* Optional proxy details
For a cloud wallet it is usually an alias name stored in the tnsnames.ora file,
but for a simple wallet it contains the host, port, and service name
information.
The following example shows the JSON representation of a JDBC URL data source.
{
"name" : "rdfuser_jdbc_sid",
"type" : "DATABASE",
"description" : "",
"properties" : {
"host" : "127.0.0.1"
"sid" : "orcl193"
"port" : "1524",
"user" : "rdfuser",
"password" : "<password>"
}
}
The following example shows the JSON representation of a container data source:
{
"name": "rdfuser_ds_ct",
"type": "DATABASE",
"description": "Database Container connection",
"properties": {
"jndiName": "jdbc/RDFUSER193c"
}
}
The following example shows the JSON representation of a wallet data source where
the credentials are stored in the wallet:
{
"name": "rdfuser_ds_wallet",
"type": "DATABASE",
"description": "Database wallet connection",
"properties": {
13-2
Chapter 13
Data Sources
"walletService": "db202002041627_medium"
}
}
Parameters Description
name A generic name of the data source.
type The type of the data source. For external data sources, the type must
be ‘ENDPOINT’.
description A generic description of the data source.
properties Specific mapping parameters with values for data source properties:
• base URL: the base URL to issue SPARQL queries to RDF store.
This is the default URL.
• query URL (optional): the URL to execute SPARQL queries. If
defined, it will overwrite the base URL value.
• update URL (optional): the URL to execute SPARQL updates. If
defined, it will overwrite the base URL value.
• capabilities (optional): Some RDF stores (like Apache Jena
Fuseki) may provide a capabilities URL that returns the datasets
available in service. A JSON response is expected in this case.
• get URL: the get capabilities URL.
• datasets parameter: defines the JSON parameter that contains the
RDF datasets information.
• dataset parameter name: defines the JSON parameter that
contains the RDF dataset name.
The following example shows the JSON representation of a Dbpedia external data source :
{
"name": "dbpedia",
"type": "ENDPOINT",
"description": "Dbpedia RDF data - Dbpedia.org",
"properties": {
"baseUrl": "http://dbpedia.org/sparql",
"provider": "Dbpedia"
}
}
The following example shows the JSON representation of a Apache Jena Fuseki external
data source. The ${DATASET} is a parameter that is replaced at run time with the Fuseki
dataset name:
{
"name": "Fuseki",
"type": "ENDPOINT",
"description": "Jena Fuseki server",
13-3
Chapter 13
RDF Datasets
"properties": {
"queryUrl": "http://localhost:8080/fuseki/${DATASET}/query",
"baseUrl": "http://localhost:8080/fuseki",
"capabilities": {
"getUrl": "http://localhost:8080/fuseki/$/server",
"datasetsParam": "datasets",
"datasetNameParam": "ds.name"
},
"provider": "Apache",
"updateUrl": "http://localhost:8080/fuseki/${DATASET}/update"
}
}
For RDF stores that do not have a specific dataset, a simple JSON {} or a 'Default'
name as shown for Apache Jena Fuseki in the above example can be used.
13-4
Chapter 13
REST Services
Most of the REST services are protected with Form-based authentication. Administrator
users can define a public RDF data source using the RDF Graph Server and Query UI web
application. The public REST endpoints will then be available to perform SPARQL queries on
published datasets.
Note:
The examples in this section and throughout this chapter reference host machine as
localhost and port number as 7101. These values can vary depending on your
application deployment.
13-5
Chapter 13
REST Services
http://localhost:7101/orardf/api/v1/datasets/query?
datasource=rdfuser_ds_193c&query=select ?s ?p ?o where { ?s ?p ?o}
limit 10&datasetDef={"metadata":[ {"networkOwner":"RDFUSER",
"networkName":"LOCALNET","models":["UNIV_BENCH"]} ] }
• Put request to publish an RDF model:
http://localhost:7101/orardf/api/v1/datasets/publish/DSETNAME?
datasetDef={"metadata":[ {"networkOwner":"RDFUSER",
"networkName":"LOCALNET" "models":["UNIV_BENCH"]} ]}
Default SPARQL Query Payload: select ?s ?p ?o where { ?s ?p ?o} limit 10
This default SPARQL can be overwritten when requesting the contents of a
published dataset. The datasource parameter in the preceding request is optional.
However, if you define this parameter on the URL, it must match the current
publishing data source name because this API version supports just one
publishing data source. Otherwise, the published data source name is
automatically used.
• Get request for a published dataset:
The following is a public endpoint URL. It is using the default parameters
(SPARQL query, output format, and others) that are stored in dataset definition.
However, these default parameters can be overwritten in REST request by
passing new parameter values.
http://localhost:7101/orardf/api/v1/datasets/query/published/DSETNAME
A detailed list of available REST services can be found in the Swagger json file,
orardf_swagger.json, which is packaged in the application documentation directory.
13-6
14
Oracle RDF Graph Query UI
The Oracle RDF Graph Query UI is an Oracle JET based client that can be used to manage
RDF objects from different data sources, and to perform SPARQL queries and updates.
This Java EE application helps to build application webpages that query and display RDF
graphs. It supports queries across multiple data sources.
• Installing RDF Graph Query UI
• Managing User Roles for RDF Graph Query UI
• Getting Started with RDF Graph Query UI
• Accessibility
The deployment of the RDF .war file provides the Oracle RDF Graph Query UI console.
14-1
Chapter 14
Managing User Roles for RDF Graph Query UI
This deployment also includes the REST API running on the application server to
handle communication between users and backend RDF data stores.
Application servers, such as WebLogic Server, Tomcat, and others, allow you to define
and assign users to user groups. Administrators are set up at the time of the RDF
Graph server installation, but the RDF and guest users must be created to access the
application console.
• Managing Groups and Users in WebLogic Server
• Managing Users and Roles in Tomcat Server
14-2
Chapter 14
Managing User Roles for RDF Graph Query UI
14-3
Chapter 14
Managing User Roles for RDF Graph Query UI
4. Select a user name and click Groups to assign the user to a specific group.
5. Assign rdfuser to RDFreadwriteUser group.
14-4
Chapter 14
Managing User Roles for RDF Graph Query UI
14-5
Chapter 14
Managing User Roles for RDF Graph Query UI
<role rolename="rdf-admin-user"/>
<role rolename="rdf-read-user"/>
<role rolename="rdf-readwrite-user"/>
14-6
Chapter 14
Getting Started with RDF Graph Query UI
username="admin"/>
</tomcat-users>
14-7
Chapter 14
Getting Started with RDF Graph Query UI
Database or to an external RDF data provider. For Oracle data sources, there are
three types of connections:
• JDBC data source defined with database parameters
• JDBC data source defined on an application server
• Oracle wallet connection defined in a zip file
These database connections must be available in order to link the RDF web
application to the data source.
To create a data source, click Data Sources, then Create.
14-8
Chapter 14
Getting Started with RDF Graph Query UI
14-9
Chapter 14
Getting Started with RDF Graph Query UI
4. Enter the JDBC data source information (name and JNDI name), then click Next.
14-10
Chapter 14
Getting Started with RDF Graph Query UI
14-11
Chapter 14
Getting Started with RDF Graph Query UI
The JDBC data gets added to the data source table and the JNDI name is added to
the combo box list in the create container dialog.
14-12
Chapter 14
Getting Started with RDF Graph Query UI
auth="Container"
type="javax.sql.DataSource" />
</Context>
Note that the tnsnames.ora file in the wallet zip file contains the wallet service alias names,
and TCPS information. It does not contain the user credentials for each service.
Using this wallet zip file, you can define an RDF wallet data source in the Query UI web
application by directly entering the user credentials. Optionally, you can also have the user
credentials stored inside the wallet for each desired service. If you choose to store the user
credentials in the wallet, then see Storing User Credentials in a Wallet for more information.
The following describes the steps to create a wallet data source:
1. Click Wallet in Figure 14-11.
Create Wallet Data source dialog opens as shown:
14-13
Chapter 14
Getting Started with RDF Graph Query UI
2. Click the upload icon and select the wallet zip file.
The zip file gets uploaded to the server.
3. Enter the data source Name.
4. Optionally, enter the Description.
5. Select the required Wallet Service name.
6. Provide the user credentials using one of the following options as it applies to you.
• Enable Use wallet credentials if you have stored the user credentials in the
wallet.
• Otherwise, enter directly the User and Password credentials.
7. Optionally, enter the proxy details.
• Storing User Credentials in a Wallet
14-14
Chapter 14
Getting Started with RDF Graph Query UI
14-15
Chapter 14
Getting Started with RDF Graph Query UI
Note:
For Jena Fuseki, the expression ${DATASET} will be replaced by the
dataset name at runtime when SPARQL queries or SPARQL updates are
being executed.
The following figure shows an example for creating an Apache Jena Fuseki data
source.
14-16
Chapter 14
Getting Started with RDF Graph Query UI
The left panel contains information on the available RDF data in the data source. The right
panel is used for opening properties of a RDF object. Depending on the property type,
SPARQL queries and SPARQL updates can be executed.
• Data Source Selection
• Semantic Network Actions
• Importing Data
14-17
Chapter 14
Getting Started with RDF Graph Query UI
Select the desired Oracle RDF semantic network for the selected data source. Each
network is identified by a network owner and network name.
Note:
Before Release 19, all semantic networks were stored on MDSYS schema.
From Release 19 onwards, private networks are being supported.
14-18
Chapter 14
Getting Started with RDF Graph Query UI
14-19
Chapter 14
Getting Started with RDF Graph Query UI
You can clear cache at different levels. The following describes the cache cleared
against each level:
• Data source: All network caches are cleared.
• Network: All model caches are cleared.
• Model: All cached queries for model are cleared.
• Model Cache Identifier: Selected cache identifier is cleared.
14-20
Chapter 14
Getting Started with RDF Graph Query UI
• For endpoint RDF data sources, the RDF navigator will have a list of names representing
the available RDF datasets in the RDF store.
• If an external RDF data source does not have a capabilities URL, then just a default
dataset is shown.
To execute SPARQL queries and SPARQL updates, open the selected RDF object in the
RDF objects navigator. For Oracle RDF objects, SPARQL queries are available for models
(regular models, virtual models, and view models).
14-21
Chapter 14
Getting Started with RDF Graph Query UI
14-22
Chapter 14
Getting Started with RDF Graph Query UI
• Runtime parameters: fetch size, query timeout and others (this is applied to Oracle RDF
data sources)
• Binding parameters: the expression ?ora__bind is used as a binding parameter in a
SPARQL string. Each binding parameter is defined by a type (uri or literal) and a value.
For example:
The number of results on the SPARQL query is determined by the limit parameter in SPARQL
string, or by the maximum number of rows that can be fetched from server. As an
administrator you can set the maximum number of rows to be fetched in the settings page.
A graph view can be displayed for the query results. On the graph view, you must map the
columns for the triple values (subject, predicate, and object). In a table view, the columns that
represent URI values have hyperlinks.
Besides the Execute button to run the SPARQL query, there is also the Explain Plan button
to retrieve the SQL query plan for the SPARQL. This basically displays a dialog with the
EXPLAIN PLAN results and the SPARQL translation.
14-23
Chapter 14
Getting Started with RDF Graph Query UI
For Oracle data sources, if the SPARQL query selects an RDF object value that
represents a GeoSPARQL data type (such as WKT, GML, KML, or GeoJSON), a map
visualization can be displayed by switching on Map view result. In this case, the
SPARQL query must select the geometry attribute which is an RDF literal of a
GeoSPARQL data type. On execution, this query will produce a GeoJSON result which
is then passed to the map component for visualization. For example:
Figure 14-36 Map Visualization for GeoSPARQL Data Types in a SPARQL Query
14-24
Chapter 14
Getting Started with RDF Graph Query UI
Note:
It is important to be aware that by enabling RDF data publishing and defining a
public RDF data source, your public URL endpoints for RDF datasets are exposed.
This endpoint URL can be used directly in applications without entering credentials.
However, public endpoints have some security constraints related to execution of SPARQL
queries. SPARQL updates, SPARQL SERVICE, and SPARQL user-defined functions are not
allowed.
To publish an Oracle RDF model as a dataset:
1. Right-click on the RDF model and select Publish from the menu as shown:
2. Enter the Dataset name (mandatory), Description, and Default SPARQL. This default
SPARQL can be overwritten on the REST request.
14-25
Chapter 14
Getting Started with RDF Graph Query UI
3. Click OK.
The public endpoint GET URL for the dataset is displayed. Note that the POST
request can also be used to access the endpoint.
14-26
Chapter 14
Getting Started with RDF Graph Query UI
This URL uses the default values defined for the dataset and follows the pattern shown:
http://${hostname}:${port_number}/orardf/api/v1/datasets/query/published/$
{dataset_name}
You can override the default parameters stored in the dataset by modifying the URL to
include one or more of the following parameters:
• query: SPARQL query
• format: output format (JSON, XML, CSV, TSV, GeoJSON, N-Triples, Turtle)
• options: string with Oracle RDF options
• params: JSON string with runtime parameters (timeout, fetchSize, and others)
• bindings: JSON string with binding parameters (URI or literal values)
The following shows the general pattern of the REST request to query published datasets
(assuming the context root as orardf):
http://${hostname}:${port_number}/orardf/api/v1/datasets/query/published/$
{dataset_name}?datasource=${datasource_name}&query=${sparql}&format=$
{format}&options=${rdf_options}¶ms=${runtime_params}&bindings=$
{binding_params}
In order to modify the default parameters, you must open the RDF dataset definition by
selecting Open from the menu options shown in the following figure or by double clicking
the published dataset:
The RDF dataset definition for the selected published dataset opens as shown:
14-27
Chapter 14
Getting Started with RDF Graph Query UI
You can update the default parameters and preview the results.
Note:
• RDF user with administrator privileges can update and unpublish any
dataset.
• RDF user with read and write privileges can only manage the
datasets that the user created.
• RDF user with read privileges can only query the dataset.
For example:
http://localhost:7101/orardf/public.html
14-28
Chapter 14
Getting Started with RDF Graph Query UI
• The tab panel on the right allows you to execute SPARQL queries against the published
RDF dataset. SPARQL query results are displayed in tabular as well as graph view
formats. However, if the Accessibility switch on the top right corner of the page is
switched ON, then the results are only displayed in tabular format.
The following options are supported in the tab panel:
– Templates: SPARQL template queries to use.
– Add prefix: click to add the selected prefix in the combo box to a SPARQL query.
– SPARQL: enter the SPARQL to be executed in the text area.
– select/ask: select the output format for SPARQL SELECT and SPARQL ASK queries.
– construct/describe: select the output format for SPARQL CONSTRUCT and SPARQL
DESCRIBE queries.
14-29
Chapter 14
Getting Started with RDF Graph Query UI
– Execute: click this button to execute the SPARQL query against the RDF
public endpoint.
– Table: shows the result in a tabular format.
– Raw: shows the raw SPARQL result on specified format returned from server.
Multi-Valued Property (MVP) tables hold values for multi-valued RDF properties. A
property p is multi-valued in an RDF model if there exist two triples in the model (s p
o1) and (s p o2) with o1 not equal to o2.
Property Chain (PCN) tables hold paths in the RDF graph. A set of triples t1, t2, …,
tn form a path if for each ti where i > 1, the object value of ti-1 is equal to the
subject value of ti.
SVP and PCN tables can be used to reduce joins on SPARQL query execution, while
MVP tables allow better query optimizer statistics and query plans, which can help in
speeding up the query execution. These auxiliary tables are associated with RDF
models. Once they are created, they are automatically used during SPARQL queries
execution, unless options are passed to not to use them.
The RDF Server and Query UI web application extends support to the SPM tables.
You can manage these auxiliary tables by right clicking the RDF model and selecting
the Auxiliary tables menu item as shown:
14-30
Chapter 14
Getting Started with RDF Graph Query UI
• Create one of the following types of auxiliary tables depending on your requirement:
14-31
Chapter 14
Getting Started with RDF Graph Query UI
– Click Create SVP table after entering the SVP table name to create an SVP
table.
– Click Create MVP table to create an MVP table. Note that to create an MVP
table, you must select only one predicate in the Predicate List.
– Click Create PCN table after entering the PCN table name to create a PCN
table. Note that to create a PCN table, you must select at least two predicates
in the Predicate List.
14-32
Chapter 14
Getting Started with RDF Graph Query UI
– Click View Indexes to view the secondary indexes that are associated with an SPM
table.
14-33
Chapter 14
Getting Started with RDF Graph Query UI
This dialog aims to build the index key string value which is used for creating a
unique index on an SPM table. This index key string value is built as per your
configurations in the preceding figure and is displayed as a read only value.
For instance:
* The order of the columns defines the index order during creation.
* The number of compressed columns is determined by the row order in the
table. If the value is one, then the column in the first row will be
compressed. Similarly, if the value is two, then two columns in the first two
rows will be compressed, and so on. A zero value indicates that there are
no columns for compression.
See Creating Secondary Indexes on SPM Auxiliary Tables for more
information on this key column.
– Click Drop table and confirm to drop an SPM table.
14-34
Chapter 14
Getting Started with RDF Graph Query UI
14-35
Chapter 14
Getting Started with RDF Graph Query UI
14-36
Chapter 14
Getting Started with RDF Graph Query UI
Each root class has its own summary of incoming and outgoing predicates. You can double
click on a root class to view the graph representation in the graph view panel.
It is highly recommended to define PREFIX expressions on the query to shorten the result
labels in the graph nodes. It also helps to consume less space for the graphic representation
of the nodes. Some well known RDF SPARQL prefixes (such as rdf, rdfs, owl, and others) are
automatically recognized and can be avoided in the query expression.
As seen in the preceding figure, you can double click the tree node to open the element as a
graph in the graph view. You can then interact directly with the graph in the graph view
without using the root tree nodes in the Query selector panel. This panel can be collapsed to
provide more space on the page for the graph view.
The following figure shows the owl:Class and lehigh:Person elements displayed in the
graph view.
Note that in some cases the SPARQL query execution may generate several root classes.
However, it is not necessary to add all the root classes to a graph. This also helps to maintain
a clean and readable graph area.
14-37
Chapter 14
Getting Started with RDF Graph Query UI
– Zoom Options: Includes zoom in, zoom out, fit all, and clear all actions.
Additionally, zoom in and out actions can be achieved with the mouse wheel.
Drag to pan graph is also available.
– Layout: A few built-in layouts (such as random, grid, circle, concentric,
breadth first, and cose).
– Spacing factor: A slider to adjust the spacing between nodes (useful for
lengthy edges).
– Expand limit: The maximum number of node entries that can be expanded for
an edge.
• A drawing area with the RDF nodes and edges.
You can interact with the edges and nodes of the graph displayed in the graph view
area. Initially, the graph displayed is based on the root class summaries (counts), but
you can always expand the elements.
To expand a node in the graph, click on the node and then select Expand. New node
elements with new edges linked to the selected node gets added to the graph. For
example, in the following figure, the node lehigh:Person is shown expanded:
Star nodes (magenta color) contain the values associated with the edge predicate. To
see these values, click on the node and select View Values:
14-38
Chapter 14
Getting Started with RDF Graph Query UI
To expand the edge predicate summary, click on the edge and select Expand. Then the star
node associated with it will be divided into new nodes and edges in the graph. However, if the
expand limit value is lower than the summary count, then all the nodes will not be expanded.
For example:
14-39
Chapter 14
Getting Started with RDF Graph Query UI
The following basic conventions apply to the graph displayed in the graph view:
• URI nodes are displayed in orange color with labels inside the ellipse shape.
• Blank nodes are displayed in green color with circle shape. Mousing over the
blank node shows its label value.
• Collapsed edges have the predicate with the count (if more than 1).
• Star nodes in magenta color and circle shape contain the values associated with
the collapsed edge.
• Literal nodes are displayed with different colors depending on its type. A string
literal is shown in cyan color with the label value. For long string values, the label
length is reduced and mousing over literal node shows the full label value. Literals
with datatype are displayed in different colors, and mousing over them shows the
datatype name.
14-40
Chapter 14
Getting Started with RDF Graph Query UI
It is important to note the following when creating the vertex and edge views from an RDF
model:
• The RDF model must have classes defined and the application uses a SPARQL query to
retrieve the distinct classes defined on an RDF model. For example:
SELECT DISTINCT ?o
WHERE { ?s a ?o } order by ?o
• One or more RDF classes can define a vertex view. A vertex view consists of:
– Database vertex view name
– Key attribute name
– Vertex properties from RDF class
• One or two vertex views can define an edge view. An edge view consists of:
– Database edge view name
– Source and destination vertex keys
– Label property from RDF classes
The following sections explain the steps to create a database graph view:
• Creating a Graph View
• Creating a Vertex View
• Creating an Edge View
14-41
Chapter 14
Getting Started with RDF Graph Query UI
Note that the database graph views cannot be created if there are no RDF
classes.
3. Add Vertex Views as required.
See Creating a Vertex View for more information.
4. Add Edge Views as required.
See Creating an Edge View for more information.
5. Review and verify the graph representation of the Database Views.
The following figure shows a sample graph representation:
6. Optionally, you can hover over a table row and click the action menu icon to
Remove, Edit, or Preview a specific vertex or an edge view.
14-42
Chapter 14
Getting Started with RDF Graph Query UI
a. Optionally, switch ON the Overwrite option to replace any existing view definition.
14-43
Chapter 14
Getting Started with RDF Graph Query UI
b. Click Create.
The database graph view gets created.
The following figure shows the views that are created in the database for the
sample graph definition shown in step-5:
14-44
Chapter 14
Getting Started with RDF Graph Query UI
14-45
Chapter 14
Getting Started with RDF Graph Query UI
14-46
Chapter 14
Getting Started with RDF Graph Query UI
Note:
If the RDF Graph Query application is deployed from an unexploded .war file, and if
no JVM parameter is defined for the workspace folder location, then the default
workspace location for the application is WEB-INF/workspace. However, any
updates to the configuration, log, and temp files done by the application may be lost
if the application is redeployed. Also, wallet data source files and published dataset
files can be lost.
To overcome this, you must start the application server, such as Weblogic or
Tomcat, with the JVM parameter oracle.rdf.workspace.dir set. For example:
=Doracle.rdf.workspace.dir=/rdf/server/workspace. The workspace folder
must exist on the file system. Otherwise, the workspace folder defaults to WEB-INF/
workspace.
14-47
Chapter 14
Getting Started with RDF Graph Query UI
]
}
14-48
Chapter 14
Getting Started with RDF Graph Query UI
14-49
Chapter 14
Getting Started with RDF Graph Query UI
14-50
Chapter 14
Accessibility
14.4 Accessibility
You can turned on or off the accessibility during the user session.
When accessibility is turned on, the graph view of SPARQL queries is disabled.
14-51
Part III
Reference Information
Part III provides reference information about RDF Semantic Graph subprograms.
This part contains the following chapters with reference information. To understand the
examples in the reference chapters, you must understand the conceptual and data type
information in RDF Semantic Graph Overview and OWL Concepts.
• SEM_APIS Package Subprograms
The SEM_APIS package contains subprograms (functions and procedures) for working
with the Resource Description Framework (RDF) and Web Ontology Language (OWL) in
an Oracle database.
• SEM_OLS Package Subprograms
The SEM_OLS package contains subprograms (functions and procedures) related to
triple-level security to RDF data, using Oracle Label Security (OLS).
• SEM_PERF Package Subprograms
The SEM_PERF package contains subprograms for examining and enhancing the
performance of the Resource Description Framework (RDF) and Web Ontology
Language (OWL) support in an Oracle database.
• SEM_RDFCTX Package Subprograms
The SEM_RDFCTX package contains subprograms (functions and procedures) to
manage extractor policies and semantic indexes created for documents.
• SEM_RDFSA Package Subprograms
The SEM_RDFSA package contains subprograms (functions and procedures) for
providing fine-grained access control to RDF data using Oracle Label Security (OLS).
15
SEM_APIS Package Subprograms
The SEM_APIS package contains subprograms (functions and procedures) for working with
the Resource Description Framework (RDF) and Web Ontology Language (OWL) in an
Oracle database.
To use the subprograms in this chapter, you must understand the conceptual and usage
information in RDF Semantic Graph Overview and OWL Concepts .
This chapter provides reference information about the subprograms, listed in alphabetical
order.
• SEM_APIS.ADD_DATATYPE_INDEX
• SEM_APIS.ADD_SEM_INDEX
• SEM_APIS.ALTER_DATATYPE_INDEX
• SEM_APIS.ALTER_ENTAILMENT
• SEM_APIS.ALTER_MODEL
• SEM_APIS.ALTER_SEM_INDEX_ON_ENTAILMENT
• SEM_APIS.ALTER_SEM_INDEX_ON_MODEL
• SEM_APIS.ALTER_SEM_INDEXES
• SEM_APIS.ALTER_SPM_TAB
• SEM_APIS.ANALYZE_ENTAILMENT
• SEM_APIS.ANALYZE_MODEL
• SEM_APIS.APPEND_SEM_NETWORK_DATA
• SEM_APIS.BUILD_PG_RDFVIEW_INDEXES
• SEM_APIS.BUILD_SPM_TAB
• SEM_APIS.BULK_LOAD_FROM_STAGING_TABLE
• SEM_APIS.CLEANUP_BNODES
• SEM_APIS.CLEANUP_FAILED
• SEM_APIS.COMPOSE_RDF_TERM
• SEM_APIS.CONVERT_TO_GML311_LITERAL
• SEM_APIS.CONVERT_TO_WKT_LITERAL
• SEM_APIS.CREATE_ENTAILMENT
• SEM_APIS.CREATE_INDEX_ON_SPM_TAB
• SEM_APIS.CREATE_MATERIALIZED_VIEW
• SEM_APIS.SEM_APIS.CREATE_MV_BITMAP_INDEX
• SEM_APIS.CREATE_PG_RDFVIEW
• SEM_APIS.CREATE_RDFVIEW_MODEL
15-1
Chapter 15
• SEM_APIS.CREATE_RULEBASE
• SEM_APIS.CREATE_SEM_MODEL
• SEM_APIS.CREATE_SEM_NETWORK
• SEM_APIS.CREATE_SEM_SQL
• SEM_APIS.CREATE_SOURCE_EXTERNAL_TABLE
• SEM_APIS.CREATE_SPARQL_UPDATE_TABLES
• SEM_APIS.CREATE_VIRTUAL_MODEL
• SEM_APIS.DELETE_ENTAILMENT_STATS
• SEM_APIS.DELETE_MODEL_STATS
• SEM_APIS.DISABLE_CHANGE_TRACKING
• SEM_APIS.DISABLE_INC_INFERENCE
• SEM_APIS.DISABLE_INMEMORY
• SEM_APIS.DISABLE_INMEMORY_FOR_ENT
• SEM_APIS.DISABLE_INMEMORY_FOR_MODEL
• SEM_APIS.DISABLE_NETWORK_SHARING
• SEM_APIS.DROP_DATATYPE_INDEX
• SEM_APIS.DROP_ENTAILMENT
• SEM_APIS.DROP_MATERIALIZED_VIEW
• SEM_APIS.DROP_MV_BITMAP_INDEX
• SEM_APIS.DROP_PG_RDFVIEW
• SEM_APIS.DROP_PG_RDFVIEW_INDEXES
• SEM_APIS.DROP_RDFVIEW_MODEL
• SEM_APIS.DROP_RULEBASE
• SEM_APIS.DROP_SEM_INDEX
• SEM_APIS.DROP_SEM_MODEL
• SEM_APIS.DROP_SEM_NETWORK
• SEM_APIS.DROP_SEM_SQL
• SEM_APIS.DROP_SPARQL_UPDATE_TABLES
• SEM_APIS.DROP_SPM_TAB
• SEM_APIS.DROP_USER_INFERENCE_OBJS
• SEM_APIS.DROP_VIRTUAL_MODEL
• SEM_APIS.ENABLE_CHANGE_TRACKING
• SEM_APIS.ENABLE_INC_INFERENCE
• SEM_APIS.ENABLE_INMEMORY
• SEM_APIS.ENABLE_INMEMORY_FOR_ENT
• SEM_APIS.ENABLE_INMEMORY_FOR_MODEL
• SEM_APIS.ENABLE_NETWORK_SHARING
15-2
Chapter 15
• SEM_APIS.ESCAPE_CLOB_TERM
• SEM_APIS.ESCAPE_CLOB_VALUE
• SEM_APIS.ESCAPE_RDF_TERM
• SEM_APIS.ESCAPE_RDF_VALUE
• SEM_APIS.EXPORT_ENTAILMENT_STATS
• SEM_APIS.EXPORT_MODEL_STATS
• SEM_APIS.EXPORT_RDFVIEW_MODEL
• SEM_APIS.GATHER_SPM_INFO
• SEM_APIS.GET_CHANGE_TRACKING_INFO
• SEM_APIS.GET_INC_INF_INFO
• SEM_APIS.GET_MODEL_ID
• SEM_APIS.GET_MODEL_NAME
• SEM_APIS.GET_PLAN_COST
• SEM_APIS.GET_SQL
• SEM_APIS.GET_TRIPLE_ID
• SEM_APIS.GETV$DATETIMETZVAL
• SEM_APIS.GETV$DATETZVAL
• SEM_APIS.GETV$GEOMETRYVAL
• SEM_APIS.GETV$NUMERICVAL
• SEM_APIS.GETV$STRINGVAL
• SEM_APIS.GETV$TIMETZVAL
• SEM_APIS.GRANT_MODEL_ACCESS_PRIV
• SEM_APIS.GRANT_MODEL_ACCESS_PRIVS
• SEM_APIS.GRANT_NETWORK_ACCESS_PRIVS
• SEM_APIS.GRANT_NETWORK_SHARING_PRIVS
• SEM_APIS.IMPORT_ENTAILMENT_STATS
• SEM_APIS.IMPORT_MODEL_STATS
• SEM_APIS.IS_TRIPLE
• SEM_APIS.LOAD_INTO_STAGING_TABLE
• SEM_APIS.LOOKUP_ENTAILMENT
• SEM_APIS.MERGE_MODELS
• SEM_APIS.MIGRATE_DATA_TO_CURRENT
• SEM_APIS.MIGRATE_DATA_TO_STORAGE_V2
• SEM_APIS.MOVE_SEM_NETWORK_DATA
• SEM_APIS.PRIVILEGE_ON_APP_TABLES
• SEM_APIS.PURGE_UNUSED_VALUES
• SEM_APIS.REFRESH_MATERIALIZED_VIEW
15-3
Chapter 15
SEM_APIS.ADD_DATATYPE_INDEX
• SEM_APIS.REFRESH_SEM_NETWORK_INDEX_INFO
• SEM_APIS.REMOVE_DUPLICATES
• SEM_APIS.RENAME_ENTAILMENT
• SEM_APIS.RENAME_MODEL
• SEM_APIS.RES2VID
• SEM_APIS.RESTORE_SEM_NETWORK_DATA
• SEM_APIS.REVOKE_MODEL_ACCESS_PRIV
• SEM_APIS.REVOKE_MODEL_ACCESS_PRIVS
• SEM_APIS.REVOKE_NETWORK_ACCESS_PRIVS
• SEM_APIS.REVOKE_NETWORK_SHARING_PRIVS
• SEM_APIS.SEM_SQL_COMPILE
• SEM_APIS.SET_ENTAILMENT_STATS
• SEM_APIS.SET_MODEL_STATS
• SEM_APIS.SPARQL_TO_SQL
• SEM_APIS.SWAP_NAMES
• SEM_APIS.TRUNCATE_SEM_MODEL
• SEM_APIS.UNESCAPE_CLOB_TERM
• SEM_APIS.UNESCAPE_CLOB_VALUE
• SEM_APIS.UNESCAPE_RDF_TERM
• SEM_APIS.UNESCAPE_RDF_VALUE
• SEM_APIS.UPDATE_MODEL
• SEM_APIS.VALIDATE_ENTAILMENT
• SEM_APIS.VALIDATE_GEOMETRIES
• SEM_APIS.VALIDATE_MODEL
• SEM_APIS.VALUE_NAME_PREFIX
• SEM_APIS.VALUE_NAME_SUFFIX
15.1 SEM_APIS.ADD_DATATYPE_INDEX
Format
SEM_APIS.ADD_DATATYPE_INDEX(
datatype IN VARCHAR2,
tablespace_name IN VARCHAR2 DEFAULT NULL,
parallel IN PLS_INTEGER DEFAULT NULL,
online IN BOOLEAN DEFAULT FALSE,
options IN VARCHAR2 DEFAULT NULL,
network_owner IN VARCHAR2 DEFAULT NULL,
network_name IN VARCHAR2 DEFAULT NULL);
Description
Adds a data type index for the specified data type to a semantic network.
15-4
Chapter 15
SEM_APIS.ADD_DATATYPE_INDEX
Parameters
datatype
URI of the data type to index.
tablespace_name
Destination tablespace for the index.
parallel
Degree of parallelism to use when building the index.
online
TRUE allows DML operations affecting the index during creation of the index; FALSE (the
default) does not allow DML operations affecting the index during creation of the index.
options
String specifying options for index creation using the form OPTION_NAME=option_value.
Supported options associated with spatial index creation are SRID, TOLERANCE, and
DIMENSIONS. For materialized spatial index creation, use MATERIALIZE=T. Supported options
associated with text index creation are PREFIX_INDEX, PREFIX_MIN_LENGTH,
PREFIX_MAX_LENGTH, SUBSTRING_INDEX, PREDLIST, PREFIXES, and STRING_LITERALS_ONLY.
For function-based numeric or dateTime index creation, use FUNCTION=T. The option name
keywords are case sensitive and must be specified in uppercase.
network_owner
Owner of the semantic network. (See Table 1-1.)
network_name
Name of the semantic network. (See Table 1-1.)
Usage Notes
You must have DBA privileges or be the network owner to call this procedure.
For more information about data type indexing, see Using Data Type Indexes.
For information about creating a like index, see the lightweight text search material in Full-
Text Search.
For information about creating a data type index on RDF spatial data, see Indexing Spatial
Data.
For information about semantic network types and options, see Semantic Networks.
Examples
The following example creates an index on xsd:string typed literals and plain literals in the
MY_TBS tablespace.
EXECUTE SEM_APIS.ADD_DATATYPE_INDEX('http://www.w3.org/2001/XMLSchema#string',
tablespace_name=>'MY_TBS', parallel=>4);
15-5
Chapter 15
SEM_APIS.ADD_SEM_INDEX
15.2 SEM_APIS.ADD_SEM_INDEX
Format
SEM_APIS.ADD_SEM_INDEX(
index_code IN VARCHAR2,
tablespace_name IN VARCHAR2 DEFAULT NULL,
compression_length IN NUMBER(38) DEFAULT NULL,
options IN VARCHAR2 DEFAULT NULL,
network_owner IN VARCHAR2 DEFAULT NULL,
network_name IN VARCHAR2 DEFAULT NULL);
Description
Creates a semantic network index that results in creation of a non-unique B-tree index
in UNUSABLE status for each of the existing models and entailments of the semantic
network.
Parameters
index_code
Index code string.
tablespace_name
Destination tablespace for the index.
compression_length
options
network_owner
Owner of the semantic network. (See Table 1-1.)
network_name
Name of the semantic network. (See Table 1-1.)
Usage Notes
You must have DBA privileges to call this procedure.
For an explanation of semantic network indexes, see Using Semantic Network
Indexes.
For information about semantic network types and options, see Semantic Networks.
Examples
The following example creates a semantic network index with the index code string
CSPGM on the models and entailments of the semantic network.
EXECUTE SEM_APIS.ADD_SEM_INDEX('CSPGM');
15-6
Chapter 15
SEM_APIS.ALTER_DATATYPE_INDEX
15.3 SEM_APIS.ALTER_DATATYPE_INDEX
Format
SEM_APIS.ALTER_DATATYPE_INDEX(
datatype IN VARCHAR2,
command IN VARCHAR2,
tablespace_name IN VARCHAR2 DEFAULT NULL,
parallel IN PLS_INTEGER DEFAULT NULL,
online IN BOOLEAN DEFAULT FALSE,
network_owner IN VARCHAR2 DEFAULT NULL,
network_name IN VARCHAR2 DEFAULT NULL);
Description
Alters a data type index.
Parameters
datatype
URI of the data type to index.
command
String specifying the command to be performed: REBUILD to rebuild the data type index, or
UNUSABLE to marks the data type index as unusable. The value for this parameter is not case-
sensitive.
tablespace_name
Destination tablespace for the index.
parallel
Degree of parallelism to use when rebuilding the index.
online
TRUE allows DML operations affecting the index during rebuilding of the index; FALSE (the
default) does not allow DML operations affecting the index during rebuilding of the index.
network_owner
Owner of the semantic network. (See Table 1-1.)
network_name
Name of the semantic network. (See Table 1-1.)
Usage Notes
You must have DBA privileges to call this procedure.
For an explanation of data type indexes, see Using Data Type Indexes.
For information about semantic network types and options, see Semantic Networks.
Examples
The following example rebuilds the index on xsd:string typed literals and plain literals in the
MY_TBS tablespace.
15-7
Chapter 15
SEM_APIS.ALTER_ENTAILMENT
EXECUTE SEM_APIS.ALTER_DATATYPE_INDEX('http://www.w3.org/2001/XMLSchema#string',
command=>'REBUILD', tablespace_name=>'MY_TBS', parallel=>4);
15.4 SEM_APIS.ALTER_ENTAILMENT
Format
SEM_APIS.ALTER_ENTAILMENT(
entailment_name IN VARCHAR2,
command IN VARCHAR2,
tablespace_name IN VARCHAR2,
parallel IN NUMBER(38) DEFAULT NULL,
network_owner IN VARCHAR2 DEFAULT NULL,
network_name IN VARCHAR2 DEFAULT NULL);
Description
Alters an entailment (rules index). Currently, the only action supported is to move the
entailment to a specified tablespace.
Parameters
entailment_name
Name of the entailment.
command
Must be the string MOVE.
tablespace_name
Name of the destination tablespace.
parallel
Degree of parallelism to be associated with the operation. For more information about
parallel execution, see Oracle Database VLDB and Partitioning Guide.
network_owner
Owner of the semantic network. (See Table 1-1.)
network_name
Name of the semantic network. (See Table 1-1.)
Usage Notes
For an explanation of entailments, see Entailments (Rules Indexes).
For information about semantic network types and options, see Semantic Networks.
Examples
The following example moves the entailment named rdfs_rix_family to the
tablespace named my_tbs.
EEXECUTE SEM_APIS.ALTER_ENTAILMENT('rdfs_rix_family', 'MOVE', 'my_tbs');
15-8
Chapter 15
SEM_APIS.ALTER_MODEL
15.5 SEM_APIS.ALTER_MODEL
Format
SEM_APIS.ALTER_MODEL(
model_name IN VARCHAR2,
command IN VARCHAR2,
tablespace_name IN VARCHAR2,
parallel IN NUMBER(38) DEFAULT NULL,
network_owner IN VARCHAR2 DEFAULT NULL,
network_name IN VARCHAR2 DEFAULT NULL);
Description
Alters a model. Currently, the only action supported is to move the model to a specified
tablespace.
Parameters
model_name
Name of the model.
command
Must be the string MOVE.
tablespace_name
Name of the destination tablespace.
parallel
Degree of parallelism to be associated with the operation. For more information about
parallel execution, see Oracle Database VLDB and Partitioning Guide.
network_owner
Owner of the semantic network. (See Table 1-1.)
network_name
Name of the semantic network. (See Table 1-1.)
Usage Notes
For an explanation of models, see Semantic Data Modeling and Semantic Data in the
Database.
For information about semantic network types and options, see Semantic Networks.
Examples
The following example moves the model named family to the tablespace named my_tbs.
EEXECUTE SEM_APIS.ALTER_MODEL('family', 'MOVE', 'my_tbs');
15-9
Chapter 15
SEM_APIS.ALTER_SEM_INDEX_ON_ENTAILMENT
15.6 SEM_APIS.ALTER_SEM_INDEX_ON_ENTAILMENT
Format
SEM_APIS.ALTER_SEM_INDEX_ON_ENTAILMENT(
entailment_name IN VARCHAR2,
index_code IN VARCHAR2,
command IN VARCHAR2,
tablespace_name IN VARCHAR2 DEFAULT NULL,
use_compression IN BOOLEAN DEFAULT NULL,
parallel IN NUMBER(38) DEFAULT NULL,
online IN BOOLEAN DEFAULT FALSE),
options IN VARCHAR2 DEFAULT NULL,
network_owner IN VARCHAR2 DEFAULT NULL,
network_name IN VARCHAR2 DEFAULT NULL);
Description
Alters a semantic network index on an entailment.
Parameters
entailment_name
Name of the entailment.
index_code
Index code string.
command
String value containing one of the following commands: REBUILD rebuilds the semantic
network index on the entailment, or UNUSABLE marks as unusable the semantic
network index on the entailment. The value for this parameter is not case-sensitive.
tablespace_name
Name of the destination tablespace for the rebuild operation.
use_compression
Specifies whether compression should be used when rebuilding the index.
parallel
Degree of parallelism to be associated with the operation. For more information about
parallel execution, see Oracle Database VLDB and Partitioning Guide.
online
TRUE allows DML operations affecting the index during the rebuilding of the index;
FALSE (the default) does not allow DML operations affecting the index during the
rebuilding of the index.
options
(Not currently used.)
network_owner
Owner of the semantic network. (See Table 1-1.)
15-10
Chapter 15
SEM_APIS.ALTER_SEM_INDEX_ON_MODEL
network_name
Name of the semantic network. (See Table 1-1.)
Usage Notes
For an explanation of semantic network indexes, see Using Semantic Network Indexes.
For information about semantic network types and options, see Semantic Networks.
Examples
The following example rebuilds (and makes usable if it is unusable) the semantic network
index on the entailment named rdfs_rix_family.
EXECUTE SEM_APIS.ALTER_SEM_INDEX_ON_ENTAILMENT('rdfs_rix_family', 'pscm', 'rebuild');
15.7 SEM_APIS.ALTER_SEM_INDEX_ON_MODEL
Format
SEM_APIS.ALTER_SEM_INDEX_ON_MODEL(
model_name IN VARCHAR2,
index_code IN VARCHAR2,
command IN VARCHAR2,
tablespace_name IN VARCHAR2 DEFAULT NULL,
use_compression IN BOOLEAN DEFAULT NULL,
parallel IN NUMBER(38) DEFAULT NULL,
online IN BOOLEAN DEFAULT FALSE),
options IN VARCHAR2 DEFAULT NULL),
network_owner IN VARCHAR2 DEFAULT NULL,
network_name IN VARCHAR2 DEFAULT NULL);
Description
Alters a semantic network index on a model.
Parameters
model_name
Name of the model.
index_code
Index code string.
command
String value containing one of the following commands: REBUILD rebuilds the semantic
network index on the model, or UNUSABLE marks as unusable the semantic network index on
the model. The value for this parameter is not case-sensitive.
tablespace_name
Name of the destination tablespace for the rebuild operation.
use_compression
Specifies whether compression should be used when rebuilding the index.
15-11
Chapter 15
SEM_APIS.ALTER_SEM_INDEXES
parallel
Degree of parallelism to be associated with the operation. For more information about
parallel execution, see Oracle Database VLDB and Partitioning Guide.
online
TRUE allows DML operations affecting the index during the rebuilding of the index;
FALSE (the default) does not allow DML operations affecting the index during the
rebuilding of the index.
options
(Not currently used.)
network_owner
Owner of the semantic network. (See Table 1-1.)
network_name
Name of the semantic network. (See Table 1-1.)
Usage Notes
For an explanation of semantic network indexes, see Using Semantic Network
Indexes.
For information about semantic network types and options, see Semantic Networks.
Examples
The following example rebuilds (and makes usable if it is unusable) the semantic
network index on the model named family.
EXECUTE SEM_APIS.ALTER_SEM_INDEX_ON_MODEL('family', 'pscm', 'rebuild');
15.8 SEM_APIS.ALTER_SEM_INDEXES
Format
SEM_APIS.ALTER_SEM_INDEXES(
attr_name IN VARCHAR2,
new_val IN VARCHAR2,
options IN VARCHAR2 DEFAULT NULL,
network_owner IN VARCHAR2 DEFAULT NULL,
network_name IN VARCHAR2 DEFAULT NULL);
Description
Alters an attribute of all indexes on RDF_VALUE$ and RDF_LINK$ tables.
Parameters
attr_name
Attribute to be altered..
new_val
New value for the attribute.
options
(Not currently used.)
15-12
Chapter 15
SEM_APIS.ALTER_SPM_TAB
network_owner
Owner of the semantic network. (See Table 1-1.)
network_name
Name of the semantic network. (See Table 1-1.)
Usage Notes
You must have DBA privileges to call this procedure.
Currently, the only attr_name value supported is VISIBILITY, and the only new_val values
supported are Y (visible indexes) and N (invisible indexes).
For an explanation of semantic network indexes, see Using Semantic Network Indexes,
including the subtopic about using invisible indexes.
For information about semantic network types and options, see Semantic Networks.
Examples
The following example makes all semantic network indexes invisible.
EXECUTE SEM_APIS.ALTER_SEM_INDEXES(‘VISIBILITY’, 'N');
15.9 SEM_APIS.ALTER_SPM_TAB
Format
SEM_APIS.ALTER_SPM_TAB (
model_name IN VARCHAR2,
pred_name IN VARCHAR2,
command IN VARCHAR2,
degree IN NUMBER DEFAULT NULL,
options IN VARCHAR2 DEFAULT NULL,
network_owner IN DBMS_ID DEFAULT NULL,
network_name IN VARCHAR2 DEFAULT NULL);
Description
Alters the presence or extent of presence of the columns corresponding to a predicate in a
given SPM table.
Parameters
model_name
Name of the RDF model.
pred_name
Name of the target predicate.
command
Determines the type of alteration.
The supported commands are:
• ADD_PREDICATE: Adds columns for the target predicate to an SPM table, where the target
predicate is found. Applies to SVP tables only and succeeds only if the target predicate
is single-valued in the given RDF model.
15-13
Chapter 15
SEM_APIS.ANALYZE_ENTAILMENT
• DROP_PREDICATE: Drops columns for the target predicate from the SPM table,
where the target predicate is found. Note that this applies to SVP tables only.
• ADD_VALUE: Adds value columns for the target predicate to an SPM table, where
the target predicate is found.
• DROP_VALUE: Drops value columns for the target predicate from an SPM table,
where the target predicate is found.
• ADD_S_VALUE: Includes lexical values for the subject.
• DROP_S_VALUE: Drops lexical values for the subject.
degree
Degree of parallelism to use for alter index operation.
options
String specifying any of the options to use during the operation.
Supported options are:
• SVP_NAME=<name>: Locates the target SVP table.
• PCN_NAME=<name>: Locates the target PCN table.
network_owner
Owner of the semantic network. (See Table 1-1.)
network_name
Name of the semantic network. (See Table 1-1.)
Usage Notes
Examples
The following example adds in-line lexical value for email:
begin
sem_apis.alter_spm_tab(
model_name =>'m1',
pred_name =>'<http://www.example.com#email>',
command =>'ADD_VALUE',
network_owner =>'RDFUSER',
network_name =>'NET1'
);
end;
15.10 SEM_APIS.ANALYZE_ENTAILMENT
Format
SEM_APIS.ANALYZE_ENTAILMENT(
entailment_name IN VARCHAR2,
estimate_percent IN NUMBER DEFAULT to_estimate_percent_type
(get_param('ESTIMATE_PERCENT')),
method_opt IN VARCHAR2 DEFAULT get_param('METHOD_OPT'),
degree IN NUMBER DEFAULT to_degree_type(get_param('DEGREE')),
cascade IN BOOLEAN DEFAULT to_cascade_type(get_param('CASCADE')),
no_invalidate IN BOOLEAN DEFAULT to_no_invalidate_type
(get_param('NO_INVALIDATE')),
15-14
Chapter 15
SEM_APIS.ANALYZE_ENTAILMENT
Description
Collects statistics for a specified entailment (rules index).
Parameters
entailment_name
Name of the entailment.
estimate_percent
Percentage of rows to estimate in the internal table partition containing information about the
entailment (NULL means compute). The valid range is [0.000001,100]. Use the constant
DBMS_STATS.AUTO_SAMPLE_SIZE to have Oracle determine the appropriate sample size for
good statistics. This is the usual default.
method_opt
Accepts either of the following options, or both in combination, for the internal table partition
containing information about the entailment:
• FOR ALL [INDEXED | HIDDEN] COLUMNS [size_clause]
• FOR COLUMNS [size clause] column|attribute [size_clause] [,column|attribute
[size_clause]...]
size_clause is defined as size_clause := SIZE {integer | REPEAT | AUTO | SKEWONLY}
column is defined as column := column_name | (extension)
- integer : Number of histogram buckets. Must be in the range [1,254].
- REPEAT : Collects histograms only on the columns that already have histograms.
- AUTO : Oracle determines the columns to collect histograms based on data distribution
and the workload of the columns.
- SKEWONLY : Oracle determines the columns to collect histograms based on the data
distribution of the columns.
- column_name : name of a column
- extension: Can be either a column group in the format of (column_name, column_name
[, ...]) or an expression.
The usual default is FOR ALL COLUMNS SIZE AUTO.
degree
Degree of parallelism for the internal table partition containing information about the
entailment. The usual default for degree is NULL, which means use the table default value
specified by the DEGREE clause in the CREATE TABLE or ALTER TABLE statement. Use the
constant DBMS_STATS.DEFAULT_DEGREE to specify the default value based on the initialization
parameters. The AUTO_DEGREE value determines the degree of parallelism automatically. This
is either 1 (serial execution) or DEFAULT_DEGREE (the system default value based on number
of CPUs and initialization parameters) according to size of the object.
cascade
Gathers statistics on the indexes for the internal table partition containing information about
the entailment. Use the constant DBMS_STATS.AUTO_CASCADE to have Oracle determine
whether index statistics are to be collected or not. This is the usual default.
15-15
Chapter 15
SEM_APIS.ANALYZE_MODEL
no_invalidate
Does not invalidate the dependent cursors if set to TRUE. The procedure invalidates
the dependent cursors immediately if set to FALSE. Use DBMS_STATS.AUTO_INVALIDATE.
to have Oracle decide when to invalidate dependent cursors. This is the usual default.
force
TRUE gathers statistics even if the entailment is locked; FALSE (the default) does not
gather statistics if the entailment is locked.
network_owner
Owner of the semantic network. (See Table 1-1.)
network_name
Name of the semantic network. (See Table 1-1.)
Usage Notes
Index statistics collection can be parellelized except for cluster, domain, and join
indexes.
This procedure internally calls the DBMS_STATS.GATHER_TABLE_STATS
procedure, which collects statistics for the internal table partition that contains
information about the entailment. The DBMS_STATS.GATHER_TABLE_STATS
procedure is documented in Oracle Database PL/SQL Packages and Types
Reference.
See also Managing Statistics for Semantic Models and the Semantic Network.
For information about entailments, see Entailments (Rules Indexes).
For information about semantic network types and options, see Semantic Networks.
Examples
The following example collects statistics for the entailment named rdfs_rix_family.
EXECUTE SEM_APIS.ANALYZE_ENTAILMENT('rdfs_rix_family');
15.11 SEM_APIS.ANALYZE_MODEL
Format
SEM_APIS.ANALYZE_MODEL(
model_name IN VARCHAR2,
estimate_percent IN NUMBER DEFAULT to_estimate_percent_type
(get_param('ESTIMATE_PERCENT')),
method_opt IN VARCHAR2 DEFAULT get_param('METHOD_OPT'),
degree IN NUMBER DEFAULT to_degree_type(get_param('DEGREE')),
cascade IN BOOLEAN DEFAULT to_cascade_type(get_param('CASCADE')),
no_invalidate IN BOOLEAN DEFAULT to_no_invalidate_type
(get_param('NO_INVALIDATE')),
force IN BOOLEAN DEFAULT FALSE),
network_owner IN VARCHAR2 DEFAULT NULL,
network_name IN VARCHAR2 DEFAULT NULL);
Description
Collects optimizer statistics for a specified model.
15-16
Chapter 15
SEM_APIS.ANALYZE_MODEL
Parameters
model_name
Name of the model.
estimate_percent
Percentage of rows to estimate in the internal table partition containing information about the
model (NULL means compute). The valid range is [0.000001,100]. Use the constant
DBMS_STATS.AUTO_SAMPLE_SIZE to have Oracle determine the appropriate sample size for
good statistics. This is the usual default.
method_opt
Accepts either of the following options, or both in combination, for the internal table partition
containing information about the model:
• FOR ALL [INDEXED | HIDDEN] COLUMNS [size_clause]
• FOR COLUMNS [size clause] column|attribute [size_clause] [,column|attribute
[size_clause]...]
size_clause is defined as size_clause := SIZE {integer | REPEAT | AUTO | SKEWONLY}
column is defined as column := column_name | (extension)
- integer : Number of histogram buckets. Must be in the range [1,254].
- REPEAT : Collects histograms only on the columns that already have histograms.
- AUTO : Oracle determines the columns to collect histograms based on data distribution
and the workload of the columns.
- SKEWONLY : Oracle determines the columns to collect histograms based on the data
distribution of the columns.
- column_name : name of a column
- extension: Can be either a column group in the format of (column_name, column_name
[, ...]) or an expression.
The usual default is FOR ALL COLUMNS SIZE AUTO.
degree
Degree of parallelism for the internal table partition containing information about the model.
The usual default for degree is NULL, which means use the table default value specified by
the DEGREE clause in the CREATE TABLE or ALTER TABLE statement. Use the constant
DBMS_STATS.DEFAULT_DEGREE to specify the default value based on the initialization
parameters. The AUTO_DEGREE value determines the degree of parallelism automatically. This
is either 1 (serial execution) or DEFAULT_DEGREE (the system default value based on number
of CPUs and initialization parameters) according to size of the object.
cascade
Gathers statistics on the indexes for the internal table partition containing information about
the model. Use the constant DBMS_STATS.AUTO_CASCADE to have Oracle determine whether
index statistics are to be collected or not. This is the usual default.
no_invalidate
Does not invalidate the dependent cursors if set to TRUE. The procedure invalidates the
dependent cursors immediately if set to FALSE. Use DBMS_STATS.AUTO_INVALIDATE. to have
Oracle decide when to invalidate dependent cursors. This is the usual default.
15-17
Chapter 15
SEM_APIS.APPEND_SEM_NETWORK_DATA
force
TRUE gathers statistics even if the model is locked; FALSE (the default) does not gather
statistics if the model is locked.
network_owner
Owner of the semantic network. (See Table 1-1.)
network_name
Name of the semantic network. (See Table 1-1.)
Usage Notes
Index statistics collection can be parellelized except for cluster, domain, and join
indexes.
This procedure internally calls the DBMS_STATS.GATHER_TABLE_STATS
procedure, which collects optimizer statistics for the internal table partition that
contains information about the model. The DBMS_STATS.GATHER_TABLE_STATS
procedure is documented in Oracle Database PL/SQL Packages and Types
Reference.
See also Managing Statistics for Semantic Models and the Semantic Network.
For information about semantic network types and options, see Semantic Networks.
Examples
The following example collects statistics for the semantic model named family.
EXECUTE SEM_APIS.ANALYZE_MODEL('family');
15.12 SEM_APIS.APPEND_SEM_NETWORK_DATA
Format
SEM_APIS.APPEND_SEM_NETWORK_DATA(
from_schema IN DBMS_ID,
degree IN INTEGER DEFAULT NULL,
options IN VARCHAR2 DEFAULT NULL,
network_owner IN VARCHAR2 DEFAULT NULL,
network_name IN VARCHAR2 DEFAULT NULL);
Description
Appends moved semantic network data from a staging schema into a semantic
network.
Parameters
from_schema
The staging schema that contains moved semantic network data to be appended.
degree
Degree of parallelism to use for any SQL insert or index building operations. The
default is no parallel execution.
15-18
Chapter 15
SEM_APIS.BUILD_PG_RDFVIEW_INDEXES
options
String specifying any options to use during the append operation. Supported options are:
• PURGE=T – drop all remaining semantic network data in the staging schema after the
append operation completes.
network_owner
Owner of the destination semantic network for the append operation. (See Table 1-1.)
network_name
Name of the destination semantic network for the append operation. (See Table 1-1.)
Usage Notes
Partition exchange operations rather than SQL INSERT statements are used to move most of
the data during the append operation, so the staging schema will no longer contain complete
semantic network data after the operation is complete.
You must have DBA privileges to call this procedure.
For more information and examples, see Moving, Restoring, and Appending a Semantic
Network.
For information about semantic network types and options, see Semantic Networks.
Examples
The following example appends a semantic network from the RDFEXPIMPU staging schema
into the MYNET semantic network owned by RDFADMIN.
EXECUTE
sem_apis.append_sem_network_data(from_schema=>'RDFEXPIMPU',network_owner=>'RDFADMIN',ne
twork_name=>'MYNET'):
15.13 SEM_APIS.BUILD_PG_RDFVIEW_INDEXES
Format
SEM_APIS.BUILD_PG_RDFVIEW_INDEXES(
pg_name IN VARCHAR2,
tsblespace_name IN VARCHAR2 DEFAULT NULL,
options IN VARCHAR2 DEFAULT NULL,
network_owner IN VARCHAR2 DEFAULT NULL,
network_name IN VARCHAR2 DEFAULT NULL);
or
SEM_APIS.BUILD_PG_RDFVIEW_INDEXES(
pg_name IN VARCHAR2,
tsblespace_name IN VARCHAR2 DEFAULT NULL,
pg_edge_kv_tab IN VARCHAR2,
pg_node_kv_tab IN VARCHAR2,
pg_edge_tab IN VARCHAR2,
options IN VARCHAR2 DEFAULT NULL,
network_owner IN VARCHAR2 DEFAULT NULL,
network_name IN VARCHAR2 DEFAULT NULL);
Description
Creates a set of default indexes to speed up queries against property graph RDF views.
15-19
Chapter 15
SEM_APIS.BUILD_PG_RDFVIEW_INDEXES
Parameters
pg_name
Name of the property graph to index.
tablespace_name
Destination tablespace for the indexes.
pg_edge_kv_tab
Name of the table storing edge properties
pg_node_kv_tab
Name of the table storing node properties.
pg_edge_tab
Name of the table storing distinct edges.
options
String specifying options for index creation using the form
OPTION_NAME=option_value. Supported options are:
• SUB_K=N, SUB_EL=N (use a substring of N characters for property key name or
edge label)
• GT_TABLE=T (assume a populated GT$ table)
• PARALLEL=N (use a degree of parallelism of N during index creation)
• SKIP_VAL_IDX=T (skip creation of indexes on vertex/edge property values)
• SKIP_FUNC_IDX=T (skip creation of function based indexes on edge start and
end vertex URIs)
• SUB_V_IDX=N (use a substring of N characters when indexing string-valued
vertex and edge properties)
network_owner
Owner of the semantic network. (See Table 1-1.)
network_name
Name of the semantic network. (See Table 1-1.)
Usage Notes
Indexes should be created on the property graph tables for improved performance of
RDF view queries. You can create any number of index schemes on these tables, but
the SEM_APIS.BUILD_PG_RDFVIEW_INDEXES procedure is provided for
convenience.
Several indexes are created by default by the
SEM_APIS.BUILD_PG_RDFVIEW_INDEXES procedure. The following indexes are
used to look up vertex and edge properties based on property name and type:
create index g1$ntk on g1vt$(
T
, substr(K,1,200))
compress local nologging;
15-20
Chapter 15
SEM_APIS.BUILD_PG_RDFVIEW_INDEXES
, substr(k,1,200))
compress local nologging;
The following indexes are used for graph traversals. If you indicate that the G1LGT$ table is
populated (by specifying options => ‘GT_TABLE=T’), these indexes will be created on the
G1GT$ table instead of on the G1GE$ table.
create index g1$lsd on g1ge$(
substr(el,1,200)
, svid
, dvid
, eid)
compress local nologging;
The following function-based are used for graph traversals based on vertex URIs. These
function-based indexes can be skipped with the 'SKIP_FUNC_IDX=T' option. If you indicate
that the G1LGT$ table is populated (by specifying options => ‘GT_TABLE=T’), these indexes
will be created on the G1GT$ table instead of on the G1GE$ table.
create index g1$lsd on g1ge$(
substr(el,1,200)
, svid
, dvid
, eid)
compress local nologging;
The following function-based indexes are used to look up vertices and edges based on their
URIs.
create index g1$idf on g1ge$(
'<http://xmlns.oracle.com/pg/edge/e'||TO_CHAR("EID")||'>')
compress local nologging;
The following indexes are used to lookup vertices and edges based on their property values.
These indexes can be skipped with the 'SKIP_VAL_IDX=T' option..
-- varchar --
create index g1$nvt on g1vt$(
substr(to_char(V),1,200)
, T
compress local nologging;
-- number --
15-21
Chapter 15
SEM_APIS.BUILD_SPM_TAB
-- date --
create index g1$ndt on g1vt$(
VT
, T
compress local nologging;
-- varchar --
create index g1$evt on g1ge$(
substr(to_char(V),1,200)
, T
compress local nologging;
-- number --
create index g1$ent on g1ge$(
VN
, T
compress local nologging;
-- date --
create index g1$edt on g1ge$(
VT
, T
compress local nologging;
For more information, see RDF Integration with Property Graph Data Stored in Oracle
Database.
For information about semantic network types and options, see Semantic Networks.
Examples
The following example builds indexes for the property graph G1 in tablespace
MY_TBS and skips creation of value indexes.
EXECUTE SEM_APIS.BUILD_PG_RDFVIEW_INDEXES('G1', 'MY_TBS', ' SKIP_VAL_IDX=T ');
The following example builds indexes for the property graph G1in tablespace MY_TBS
with property graph tables MY_EDGE_KV_TAB, MY_NODE_KV_TAB, and
MY_EDGE_TAB. In addition, a populated distinct edges table is specified.
EXECUTE SEM_APIS.BUILD_PG_RDFVIEW_INDEXES('G1', 'MY_TBS', 'MY_EDGE_KV_TAB',
'MY_NODE_KV_TAB', 'MY_EDGE_TAB', 'GT_TABLE=T');
15.14 SEM_APIS.BUILD_SPM_TAB
Format
SEM_APIS.BUILD_SPM_TAB (
model_name IN VARCHAR2,
pred_info_tabname IN DBMS_ID DEFAULT NULL,
pred_name IN VARCHAR2 DEFAULT NULL,
tablespace_name IN DBMS_ID DEFAULT NULL,
degree IN NUMBER DEFAULT NULL,
pred_info_owner IN DBMS_ID DEFAULT NULL,
options IN VARCHAR2 DEFAULT NULL,
15-22
Chapter 15
SEM_APIS.BUILD_SPM_TAB
Description
Creates an SPM table for the specified RDF model.
The type of SPM table can be SVP, MVP, or PCN depending upon values passed for the
pred_info_tabname, pred_name, and options parameters. More information on these
parameters are described in the following Parameters section.
Parameters
model_name
Name of the RDF model.
pred_info_tabname
Name of the table to use to get predicate information, when creating an SVP or a PCN table.
Otherwise, this value must be NULL.
pred_name
Name of the target predicate, when creating an MVP table. Otherwise, this value must be
NULL.
tablespace_name
Name of the target tablespace for the SPM table.
degree
Degree of parallelism to use for alter index operation.
pred_info_owner
Owner of the pred_info_tabname. If NULL, then the invoker is assumed to be the owner.
options
String specifying any options to use during the operation.
Supported options are:
• CREATE_ANYWAY=T: Drops the target SPM table is it exists.
• PCN_NAME=<name>: Generates the given name for the PCN table.
• SVP_NAME=<name>: Generates the given name for the SVP table, if the specified name is
not DEFAULT.
• INCLUDE_VALUE=T: Includes the lexical value columns, when creating an MVP table.
• INCLUDE_VALUE: Same as INCLUDE_VALUE=T.
• S_INDEX=F: Index on the START_NODE_ID column, will not be created for an MVP table.
• P_INDEX=F: Indexes on the individual predicate columns (that make up the predicate-
chain) will not be created.
• ADD_S_VALUE: Includes lexical values for the subject.
• ADD_ALL_VALUES: Includes all lexical values for the subject and predicates.
• INMEMORY=T: Builds the in-memory SVP table with all predicates or in-memory MVP
table.
15-23
Chapter 15
SEM_APIS.BUILD_SPM_TAB
network_owner
Owner of the semantic network. (See Table 1-1.)
network_name
Name of the semantic network. (See Table 1-1.)
Usage Notes
• This operation has a DDL semantics.
• The invoker must be the owner of the RDF model or the RDF network or both.
• The network owner must have READ privilege on table specified by
pred_info_tabname.
• When creating SVP and PCN tables, content of the INCLUDE column in each row
(that corresponds to a predicate) in pred_info_tabname determines whether the ID
column and optionally the VALUE columns corresponding to a predicate must be
included in the SPM table that is being created.
The following are all the possibilities regarding inclusion (and relative position) or
exclusion of columns for a predicate, based on INCLUDE column content:
– INCLUDE=N: excluded in SVP table.
– INCLUDE=NULL and max_cnt=1: included in SVP table.
– INCLUDE=V and max_cnt=1: included in SVP table along with value columns.
– INCLUDE=<positiveInteger>C or INCLUDE=<positiveInteger>CV: included in
PCN table, along with value columns if V is present. The
specified<positiveInteger> determines the relative ordering of columns for
different predicates included in the PCN table.
Examples
The following example creates a SVP table:
begin
sem_apis.build_spm_tab(
model_name => 'M1',
pred_info_tabname => 'M1_PRED_INFO',
pred_name => NULL,
options => 'svp_name=fnm_lnm_hght ',
degree => 2,
network_owner => 'RDFUSER',
network_name => 'NET1'
);
end;
begin
sem_apis.build_spm_tab(
model_name => 'M1',
pred_info_tabname => 'M1_PRED_INFO',
pred_name => NULL,
options => ' pcn_name=addr_state ',
degree => 2,
network_owner => 'RDFUSER',
network_name => 'NET1'
15-24
Chapter 15
SEM_APIS.BULK_LOAD_FROM_STAGING_TABLE
);
end;
begin
sem_apis.build_spm_tab(
model_name => 'M1',
pred_info_tabname => NULL,
pred_name => '<http://www.example.com#friendOf>',
options => ' mvp_pred_id=6549504896746291108 ',,
degree => 2,
network_owner => 'RDFUSER',
network_name => 'NET1'
);
end;
15.15 SEM_APIS.BULK_LOAD_FROM_STAGING_TABLE
Format
SEM_APIS.BULK_LOAD_FROM_STAGING_TABLE(
model_name IN VARCHAR2,
table_owner IN VARCHAR2,
table_name IN VARCHAR2,
flags IN VARCHAR2 DEFAULT NULL,
debug IN INTEGER DEFAULT NULL,
start_comment IN VARCHAR2 DEFAULT NULL,
end_comment IN VARCHAR2 DEFAULT NULL,
network_owner IN VARCHAR2 DEFAULT NULL,
network_name IN VARCHAR2 DEFAULT NULL);
Description
Loads semantic data from a staging table.
Parameters
model_name
Name of the model.
table_owner
Name of the schema that owns the staging table that holds semantic data to be loaded.
table_name
Name of the staging table that holds semantic data to be loaded.
flags
An optional quoted string with one or more of the following keyword specifications:
• COMPRESS=CSCQH uses COLUMN STORE COMPRESS FOR QUERY HIGH on the
RDF_LINK$ partition for the model.
• COMPRESS=CSCQL uses COLUMN STORE COMPRESS FOR QUERY LOW on the
RDF_LINK$ partition for the model.
15-25
Chapter 15
SEM_APIS.BULK_LOAD_FROM_STAGING_TABLE
debug
(Reserved for future use)
start_comment
Optional comment about the start of the load operation.
end_comment
Optional comment about the end of the load operation.
network_owner
Owner of the semantic network. (See Table 1-1.)
network_name
Name of the semantic network. (See Table 1-1.)
Usage Notes
You must first load semantic data into a staging table before calling this procedure.
See Bulk Loading Semantic Data Using a Staging Table for more information.
Using BULK_LOAD_FROM_STAGING_TABLE with Fine Grained Access Control
(OLS)
When fine-grained access control (explained in Fine-Grained Access Control for RDF
Data ) is enabled for the entire network using OLS, only a user with FULL access
privileges to the associated policy may perform the bulk load operation. When OLS is
enabled, full access privileges to the OLS policy are granted using the
SA_USER_ADMIN.SET_USER_PRIVS procedure.
When the OLS is used, the label column in the tables storing the RDF triples must be
maintained. By default, with OLS enabled, the label column in the tables storing the
RDF triples is set to null. If you have FULL access, you can reset the labels for the
15-26
Chapter 15
SEM_APIS.CLEANUP_BNODES
newly inserted triples as well as any resources introduced by the new batch of triples by
using appropriate subprograms (SEM_RDFSA.SET_RESOURCE_LABEL and
SEM_RDFSA.SET_PREDICATE_LABEL).
Optionally, you can define a numeric column named RDF$STC_CTXT1 in the staging table
and the application table, to assign the sensitivity label of the triple before the data is loaded
into the desired model. Such labels are automatically applied to the corresponding triples
stored in the RDF_LINK$ table. The labels for the newly introduced resources may still have
to be applied separately before or after the load, and the system does not validate the labels
assigned during bulk load operation.
The RDF$STC_CTXT1 column in the application table has no significance, and it may be
dropped after the bulk load operation.
By default, SEM_APIS.BULK_LOAD_FROM_STAGING_TABLE uses the semantic network
compression setting (stored in RDF_PARAMETER table) for the model.
Examples
The following example loads semantic data stored in the staging table named
STAGE_TABLE in schema SCOTT into the semantic model named family. The example
includes some join hints.
EXECUTE SEM_APIS.BULK_LOAD_FROM_STAGING_TABLE('family', 'scott', 'stage_table', flags
=> 'IZC_JOIN_HINT=USE_HASH MBV_JOIN_HINT=USE_HASH');
15.16 SEM_APIS.CLEANUP_BNODES
Format
SEM_APIS.CLEANUP_BNODES(
model_name IN VARCHAR2,
tablespace_name IN VARCHAR2 DEFAULT NULL,
options IN VARCHAR2 DEFAULT NULL);
Description
Corrects blank node identifiers for blank nodes in a specified model.
Parameters
model_name
Name of the model.
tablespace_name
Name of the tablespace to use for storing intermediate data.
options
String specifying one or more options to influence the behavior of the procedure. See the
Usage Notes for available option values.
Usage Notes
See Blank Nodes: Special Considerations for SPARQL Update.
The options parameter can contain one or more of the following keywords:
• APPEND: Uses the APPEND hint when populating tables during blank node correction.
15-27
Chapter 15
SEM_APIS.CLEANUP_FAILED
Examples
The following example corrects blank node identifiers for the electronics semantic
model.
EXECUTE SEM_APIS.CLEANUP_BNODES('electronics');
15.17 SEM_APIS.CLEANUP_FAILED
Format
SEM_APIS.CLEANUP_FAILED(
rdf_object_type IN VARCHAR2,
rdf_object_name IN VARCHAR2),
options IN VARCHAR2 DEFAULT NULL,
network_owner IN VARCHAR2 DEFAULT NULL,
network_name IN VARCHAR2 default NULL);
Description
Drops (deletes) a specified rulebase or entailment if it is in a failed state.
Parameters
rdf_object_type
Type of the RDF object: RULEBASE for a rulebase or RULES_INDEX for an entailment
(rules index).
rdf_object_name
Name of the RDF object of type rdf_object_type.
options
(Not currently used.)
network_owner
Owner of the semantic network. (See Table 1-1.)
network_name
Name of the semantic network. (See Table 1-1.)
Usage Notes
This procedure checks to see if the specified RDF object is in a failed state; and if the
object is in a failed state, the procedure deletes the object.
A rulebase or entailment is in a failed state if a system failure occurred during the
creation of that object. You can check if a rulebase or entailment is in a failed state by
checking to see if the value of the STATUS column is FAILED in the
SDO_RULEBASE_INFO view (described in Inferencing: Rules and Rulebases) or the
SDO_RULES_INDEX_INFO view (described in Entailments (Rules Indexes)),
respectively.
15-28
Chapter 15
SEM_APIS.COMPOSE_RDF_TERM
If the rulebase or entailment is not in a failed state, this procedure performs no action and
returns a successful status.
An exception is generated if the RDF object is currently being used.
For information about semantic network types and options, see Semantic Networks.
Examples
The following example deletes the rulebase named family_rb if (and only if) that rulebase is
in a failed state.
EXECUTE SEM_APIS.CLEANUP_FAILED('RULEBASE', 'family_rb');
15.18 SEM_APIS.COMPOSE_RDF_TERM
Format
SEM_APIS.COMPOSE_RDF_TERM(
value_name IN VARCHAR2,
value_type IN VARCHAR2,
literal_type IN VARCHAR2,
language_type IN VARCHAR2
) RETURN VARCHAR2;
or
SEM_APIS.COMPOSE_RDF_TERM(
value_name IN VARCHAR2,
value_type IN VARCHAR2,
literal_type IN VARCHAR2,
language_type IN VARCHAR2,
long_value IN CLOB,
options IN VARCHAR2 DEFAULT NULL,
) RETURN CLOB;
Description
Creates and returns an RDF term using the specified parameters.
Parameters
value_name
Value name. Must match a value in the VALUE_NAME column in the RDF_VALUE$ table
(described in Statements) or in the var attribute returned from SEM_MATCH table function.
value_type
The type of text information. Must match a value in the VALUE_TYPE column in the
RDF_VALUE$ table (described in Statements) or in the var$RDFVTYP attribute returned
from SEM_MATCH table function.
literal_type
For typed literals, the type information; otherwise, null. Must either be a null value or match a
value in the LITERAL_TYPE column in the RDF_VALUE$ table (described in Statements) or
in the var$RDFLTYP attribute returned from SEM_MATCH table function.
15-29
Chapter 15
SEM_APIS.COMPOSE_RDF_TERM
language_type
Language tag. Must match a value in the LANGUAGE_TYPE column in the
RDF_VALUE$ table (described in Statements) or in the var$RDFLANG attribute
returned from SEM_MATCH table function.
long_value
The character string if the length of the lexical value is greater than 4000 bytes. Must
match a value in the LONG_VALUE column in the RDF_VALUE$ table (described in
Statements) or in the var$RDFCLOB attribute returned from SEM_MATCH table
function.
options
(Reserved for future use.)
Usage Notes
If you specify an inconsistent combination of values for the parameters, this function
returns a null value. If a null value is returned but you believe that the values for the
parameters are appropriate (reflecting columns from the same row in the
RDF_VALUE$ table or from a SEM_MATCH query for the same variable), contact
Oracle Support.
Examples
The following example returns, for each member of the family whose height is known,
the RDF term for the height and also just the value portion of the height.
SELECT x, SEM_APIS.COMPOSE_RDF_TERM(h, h$RDFVTYP, h$RDFLTYP, h$RDFLANG)
h_rdf_term, h
FROM TABLE(SEM_MATCH(
'{?x :height ?h}',
SEM_Models('family'),
null,
SEM_ALIASES(SEM_ALIAS('','http://www.example.org/family/')),
null))
ORDER BY x;
X
--------------------------------------------------------------------------------
H_RDF_TERM
--------------------------------------------------------------------------------
H
--------------------------------------------------------------------------------
http://www.example.org/family/Cathy
"5.8"^^<http://www.w3.org/2001/XMLSchema#decimal>
5.8
http://www.example.org/family/Cindy
"6"^^<http://www.w3.org/2001/XMLSchema#decimal>
6
http://www.example.org/family/Jack
"6"^^<http://www.w3.org/2001/XMLSchema#decimal>
6
http://www.example.org/family/Tom
"5.75"^^<http://www.w3.org/2001/XMLSchema#decimal>
5.75
4 rows selected.
15-30
Chapter 15
SEM_APIS.CONVERT_TO_GML311_LITERAL
The following example returns the RDF terms for a few of the values stored in the
RDF_VALUE$ table.
SELECT SEM_APIS.COMPOSE_RDF_TERM(value_name, value_type, literal_type,
language_type)
FROM RDF_VALUE$ WHERE ROWNUM < 5;
SEM_APIS.COMPOSE_RDF_TERM(VALUE_NAME,VALUE_TYPE,LITERAL_TYPE,LANGUAGE_TYPE)
--------------------------------------------------------------------------------
<http://www.w3.org/1999/02/22-rdf-syntax-ns#object>
<http://www.w3.org/1999/02/22-rdf-syntax-ns#type>
<http://www.w3.org/1999/02/22-rdf-syntax-ns#subject>
<http://www.w3.org/1999/02/22-rdf-syntax-ns#Property>
15.19 SEM_APIS.CONVERT_TO_GML311_LITERAL
Format
SEM_APIS.CONVERT_TO_GML311_LITERAL(
geom IN SDO_GEOMETRY,
options IN VARCHAR2 default NULL
)RETURN CLOB;
Description
Serializes an SDO_GEOMETRY object into an ogc:gmlLiteral value.
Parameters
geom
SDO_GEOMETRY object to be serialized.
options
(Reserved for future use.)
Usage Notes
The procedure SDO_UTIL.TO_GML311GEOMETRY is used internally to create the geometry
literal with a certain spatial reference system URI.
For more information about geometry serialization, see SDO_UTIL.TO_GML311GEOMETRY.
Examples
The following example shows the use of this function for a geometry with SRID 8307 The
COLA_MARKETS table is the one from the simple example in Oracle Spatial Developer's
Guide.
INSERT INTO cola_markets VALUES(
10,
'cola_x',
SDO_GEOMETRY(
2003,
8307, -- SRID
NULL,
SDO_ELEM_INFO_ARRAY(1,1003,3),
SDO_ORDINATE_ARRAY(1,1, 6,13)
)
);
15-31
Chapter 15
SEM_APIS.CONVERT_TO_WKT_LITERAL
commit;
SELECT
sem_apis.convert_to_gml311_literal(shape) as gml1
FROM cola_markets;
15.20 SEM_APIS.CONVERT_TO_WKT_LITERAL
Format
SEM_APIS.CONVERT_TO_WKT_LITERAL(
geom IN SDO_GEOMETRY,
srid_prefix IN VARCHAR2 default NULL,
options IN VARCHAR2 default NULL,
network_owner IN VARCHAR2 DEFAULT NULL,
network_name IN VARCHAR2 default NULL
)RETURN CLOB;
Description
Serializes an SDO_GEOMETRY object into an ogc:wktLiteral value.
Parameters
geom
SDO_GEOMETRY object to be serialized.
srid_prefix
Spatial reference system URI prefix that should be used in the ogc:wktLiteral
instead of the default. The resulting SRID URI will be of the form <srid_prefix/
{srid}>.
options
String specifying options for transformation. Available options are:
• ORACLE_PREFIX=T. Generate SRID URIs of the form <http://
xmlns.oracle.com/rdf/geo/srid/{srid}>.
network_owner
Owner of the semantic network. (See Table 1-1.)
network_name
Name of the semantic network. (See Table 1-1.)
Usage Notes
The procedure SDO_UTIL.TO_WKTGEOMETRY is used internally to create the
geometry literal with a certain spatial reference system URI.
Standard SRID URIs are used by default (<http://www.opengis.net/def/crs/
EPSG/0/{srid}> or (<http://www.opengis.net/def/crs/OGC/1.3/CRS84>>).
15-32
Chapter 15
SEM_APIS.CREATE_ENTAILMENT
Examples
The following example shows three different uses of this function for a geometry with SRID
8307. The COLA_MARKETS table is the one from the simple example in Oracle Spatial
Developer's Guide.
INSERT INTO cola_markets VALUES(
10,
'cola_x',
SDO_GEOMETRY(
2003,
8307, -- SRID
NULL,
SDO_ELEM_INFO_ARRAY(1,1003,3),
SDO_ORDINATE_ARRAY(1,1, 6,13)
)
);
commit;
SELECT
sem_apis.convert_to_wkt_literal(shape) as wkt1,
sem_apis.convert_to_wkt_literal(shape,'http://my.org/') as wkt2,
sem_apis.convert_to_wkt_literal(shape,null,' ORACLE_PREFIX=T ') as wkt3
FROM cola_markets;
15.21 SEM_APIS.CREATE_ENTAILMENT
Format
SEM_APIS.CREATE_ENTAILMENT(
index_name_in IN VARCHAR2,
models_in IN SEM_MODELS,
rulebases_in IN SEM_RULEBASES,
passes IN NUMBER DEFAULT SEM_APIS.REACH_CLOSURE,
inf_components_in IN VARCHAR2 DEFAULT NULL,
options IN VARCHAR2 DEFAULT NULL,
delta_in IN SEM_MODELS DEFAULT NULL,
label_gen IN RDFSA_LABELGEN DEFAULT NULL,
include_named_g IN SEM_GRAPHS DEFAULT NULL,
include_default_g IN SEM_MODELS DEFAULT NULL,
include_all_g IN SEM_MODELS DEFAULT NULL,
inf_ng_name IN VARCHAR2 DEFAULT NULL,
inf_ext_user_func_name IN VARCHAR2 DEFAULT NULL,
ols_ladder_inf_lbl_sec IN VARCHAR2 DEFAULT NULL,
network_owner IN VARCHAR2 DEFAULT NULL,
network_name IN VARCHAR2 DEFAULT NULL);
15-33
Chapter 15
SEM_APIS.CREATE_ENTAILMENT
Description
Creates an entailment (rules index) that can be used to perform OWL or RDFS
inferencing, and optionally use user-defined rules.
Parameters
index_name_in
Name of the entailment to be created.
models_in
One or more model names. Its data type is SEM_MODELS, which has the following
definition: TABLE OF VARCHAR2(25)
rulebases_in
One or more rulebase names. Its data type is SEM_RULEBASES, which has the
following definition: TABLE OF VARCHAR2(25). Rules and rulebases are explained in
Inferencing: Rules and Rulebases.
passes
The number of rounds that the inference engine should run. The default value is
SEM_APIS.REACH_CLOSURE, which means the inference engine will run till a closure is
reached. If the number of rounds specified is less than the number of actual rounds
needed to reach a closure, the status of the entailment will then be set to INCOMPLETE.
inf_components_in
A comma-delimited string of keywords representing inference components, for
performing selective or component-based inferencing. If this parameter is null, the
default set of inference components is used. See the Usage Notes for more
information about inference components.
options
A comma-delimited string of options to control the inference process by overriding the
default inference behavior. To enable an option, specify option-name=T; to disable an
option, you can specify option-name=F (the default). The available option-name
values are COL_COMPRESS, DEST_MODEL, DISTANCE,DOP, ENTAIL_ANYWAY, HASH_PART,
INC, LOCAL_NG_INF, OPT_SAMEAS, RAW8, PROOF, and USER_RULES. See the Usage Notes
for explanations of each value.
delta_in
If incremental inference is in effect, specifies one or more models on which to perform
incremental inference. Its data type is SEM_MODELS, which has the following
definition: TABLE OF VARCHAR2(25)
The triples in the first model in delta_in are copied to the first model in models_in,
and the entailment (rules index) in rules_index_in is updated; then the triples in the
second model (if any) in delta_in are copied to the second model (if any) in
models_in, and the entailment in rules_index_in is updated; and so on until all
triples are copied and the entailment is updated. (The delta_in parameter has no
effect if incremental inference is not enabled for the entailment.)
label_gen
An instance of RDFSA_LABELGEN or a subtype of it, defining the logic for generating
Oracle Label Security (OLS) labels for inferred triples. What you specify for this
15-34
Chapter 15
SEM_APIS.CREATE_ENTAILMENT
parameter depends on whether you use the default label generator or a custom label
generator:
• If you use the default label generator, specify one of the following constants:
SEM_RDFSA.LABELGEN_RULE for Use Rule Label, SEM_RDFSA.LABELGEN_SUBJECT for Use
Subject Label, SEM_RDFSA.LABELGEN_PREDICATE for Use Predicate Label,
SEM_RDFSA.LABELGEN_OBJECT for Use Object Label, SEM_RDFSA.LABELGEN_DOMINATING for
Use Dominating Label, SEM_RDFSA.LABELGEN_ANTECED for Use Antecedent Labels.
• If you use a custom label generator, specify the custom label generator type.
include_named_g
Causes all triples from the specified named graphs (across all source models) to participate
in named graph based global inference (NGGI, explained in Named Graph Based Global
Inference (NGGI)). For example, include_named_g =>
sem_graphs('<urn:G1>','<urn:G2>') implies that triples from named graphs G1 and G2 will
be included in NGGI.
Its data type is SEM_GRAPHS, which has the following definition: TABLE OF
VARCHAR2(4000).
include_default_g
Causes all triples with a null graph name in the specified models to participate in named
graph based global inference (NGGI, explained in Named Graph Based Global Inference
(NGGI)). For example, include_default_g => sem_models('m1') causes all triples with a
null graph name from model M1 to be included in NGGI.
include_all_g
Causes all triples, regardless of their graph name values, in the specified models to
participate in named graph based global inference (NGGI, explained in Named Graph Based
Global Inference (NGGI)). For example, include_all_g => sem_models('m2')causes all
triples in model M2 to be included in NGGI.
inf_ng_name
Assigns the specified graph name to all the new triples inferred by the named graph based
global inference (NGGI, explained in Named Graph Based Global Inference (NGGI)).
inf_ext_user_func_name
The name of a user-defined inference function, or a comma-delimited list of names of user-
defined functions. For information about creating user-defined inference functions, including
format requirements and options for certain parameters, see API Support for User-Defined
Inferencing. (For information about user-defined inferencing, including examples, see User-
Defined Inferencing and Querying.)
ols_ladder_inf_lbl_sec
network_owner
Owner of the semantic network. (See Table 1-1.)
network_name
Name of the semantic network. (See Table 1-1.)
Usage Notes
For the inf_components_in parameter, you can specify any combination of the following
keywords: SCOH, COMPH, DISJH, SYMMH, INVH, SPIH, MBRH, SPOH, DOMH, RANH, EQCH, EQPH, FPH,
IFPH, DOM, RAN, SCO, DISJ, COMP, INV, SPO, FP, IFP, SYMM, TRANS, DIF, SAM, CHAIN, HASKEY,
ONEOF, INTERSECT, INTERSECTSCOH, MBRLST, PROPDISJH, SKOSAXIOMS, SNOMED, SVFH, THINGH,
15-35
Chapter 15
SEM_APIS.CREATE_ENTAILMENT
THINGSAM, UNION, RDFP1, RDFP2, RDFP3, RDFP4, RDFP6, RDFP7, RDFP8AX, RDFP8BX, RDFP9,
RDFP10, RDFP11, RDFP12A, RDFP12B, RDFP12C, RDFP13A, RDFP13B, RDFP13C, RDFP14A,
RDFP14BX, RDFP15, RDFP16, RDFS2, RDFS3, RDFS4a, RDFS4b, RDFS5, RDFS6, RDFS7, RDFS8,
RDFS9, RDFS10, RDFS11, RDFS12, RDFS13. For an explanation of the meaning of these
keywords, see Table 15-1, where the keywords are listed in alphabetical order.
The default set of inference components for the OWLPrime vocabulary includes the
following: SCOH, COMPH, DISJH, SYMMH, INVH, SPIH, SPOH, DOMH, RANH, EQCH, EQPH, FPH,
IFPH, SAMH, DOM, RAN, SCO, DISJ, COMP, INV, SPO, FP, IFP, SYMM, TRANS, DIF, RDFP14A,
RDFP14BX, RDFP15, RDFP16. However, note the following:
• Component SAM is not in this default OWLPrime list, because it tends to generate
many new triples for some ontologies.
• Effective with Release 11.2, the native OWL inference engine supports the
following new inference components: CHAIN, HASKEY, INTERSECT, INTERSECTSCOH,
MBRLST, ONEOF, PROPDISJH, SKOSAXIOMS, SNOMED, SVFH, THINGH, THINGSAM, UNION.
However, for backward compatibility, the OWLPrime rulebase and any existing
rulebases do not include these new components by default; instead, to use these
new inference components, you must specify them explicitly, and they are included
in Table 15-1 The following example creates an OWLPrime entailment for two
OWL ontologies named LUBM and UNIV. Because of the additional inference
components specified, this entailment will include the new semantics introduced in
those inference components.
EXECUTE sem_apis.create_entailment('lubm1000_idx',sem_models('lubm','univ'),
sem_rulebases('owlprime'), SEM_APIS.REACH_CLOSURE,
'INTERSECT,INTERSECTSCOH,SVFH,THINGH,THINGSAM,UNION');
Keyword Explanation
CHAIN Captures the property chain semantics defined in OWL 2. Only chains of
length 2 are supported. By default, this is included in the SKOSCORE
rulebase. Subproperty chaining is an OWL 2 feature, and for backward
compatibility this component is not by default included in the OWLPrime
rulebase. (For information about property chain handling, see Property
Chain Handling.) (New as of Release 11.2.)
COMPH Performs inference based on owl:complementOf assertions and the
interaction of owl:complementOf with other language constructs.
DIF Generates owl:differentFrom assertions based on the symmetricity of
owl:differentFrom.
DISJ Infers owl:differentFrom relationships at instance level using
owl:disjointWith assertions.
DISJH Performs inference based on owl:disjointWith assertions and their
interactions with other language constructs.
DOM Performs inference based on RDFS2.
DOMH Performs inference based on rdfs:domain assertions and their interactions
with other language constructs.
EQCH Performs inference that are relevant to owl:equivalentClass.
EQPH Performs inference that are relevant to owl:equivalentProperty.
FP Performs instance-level inference using instances of
owl:FunctionalProperty.
15-36
Chapter 15
SEM_APIS.CREATE_ENTAILMENT
Keyword Explanation
FPH Performs inference using instances of owl:FunctionalProperty.
HASKEY Covers the semantics behind "keys" defined in OWL 2. In OWL 2, a
collection of properties can be treated as a key to a class expression. For
efficiency, the size of the collection must not exceed 3. (New as of
Release 11.2.)
IFP Performs instance-level inference using instances of
owl:InverseFunctionalProperty.
IFPH Performs inference using instances of owl:InverseFunctionalProperty.
INTERSECT Handles the core semantics of owl:intersectionOf. For example, if class C
is the intersection of classes C1, C2 and C3, then C is a subclass of C1,
C2, and C3. In addition, common instances of all C1, C2, and C3 are also
instances of C. (New as of Release 11.2.)
INTERSECTSCOH Handles the fact that an intersection is the maximal common subset. For
example, if class C is the intersection of classes C1, C2, and C3, then any
common subclass of all C1, C2, and C3 is a subclass of C. (New as of
Release 11.2.)
INV Performs instance-level inference using owl:inverseOf assertions.
INVH Performs inference based on owl:inverseOf assertions and their
interactions with other language constructs.
MBRLST Captures the semantics that for any resource, every item in the list given
as the value of the skos:memberList property is also a value of the
skos:member property. (See S36 in the SKOS detailed specification.) By
default, this is included in the SKOSCORE rulebase. (New as of Release
11.2.)
ONEOF Generates classification assertions based on the definition of the
enumeration classes. In OWL, class extensions can be enumerated
explicitly with the owl:oneOf constructor. (New as of Release 11.2.)
PROPDISJH Captures the interaction between owl:propertyDisjointWith and
rdfs:subPropertyOf. By default, this is included in SKOSCORE
rulebase. propertyDisjointWith is an OWL 2 feature, and for backward
compatibility this component is not by default included in the OWLPrime
rulebase. (New as of Release 11.2.)
RANH Performs inference based on rdfs:range assertions and their
interactions with other language constructs.
RDFP* (The rules corresponding to components with a prefix of RDFP can be
found in Completeness, decidability and complexity of entailment for RDF
Schema and a semantic extension involving the OWL vocabulary, by H.J.
Horst.)
RDFS2, ... RDFS2, RDFS3, RDFS4a, RDFS4b, RDFS5, RDFS6, RDFS7, RDFS8,
RDFS13 RDFS9, RDFS10, RDFS11, RDFS12, and RDFS13 are described in
Section 7.3 of RDF Semantics (http://www.w3.org/TR/rdf-mt/).
Note that many of the RDFS components are not relevant for OWL
inference.
SAM Performs inference about individuals based on existing assertions for
those individuals and owl:sameAs.
SAMH Infers owl:sameAs assertions using transitivity and symmetricity of
owl:sameAs.
15-37
Chapter 15
SEM_APIS.CREATE_ENTAILMENT
Keyword Explanation
SCO Performs inference based on RDFS9.
SCOH Generates the subClassOf hierarchy based on existing rdfs:subClassOf
assertions. Basically, C1 rdfs:subClassOf C2 and C2 rdfs:subClassOf C3
will infer C1 rdfs:subClassOf C3 based on transitivity. SCOH is also an
alias of RDFS11.
SKOSAXIOMS Captures most of the axioms defined in the SKOS detailed specification.
By default, this is included in the SKOSCORE rulebase. (New as of Release
11.2.)
SNOMED Performs inference based on the semantics of the OWL 2 EL profile,
which captures the expressiveness of SNOMED CT (Systematized
Nomenclature of Medicine - Clinical Terms), which is one of the most
expressive and complex medical terminologies. (New as of Release 11.2.)
SPIH Performs inference based on interactions between rdfs:subPropertyOf and
owl:inverseOf assertions.
SPO Performs inference based on RDFS7.
SPOH Generates rdfs:subPropertyOf hierarchy based on transitivity of
rdfs:subPropertyOf. It is an alias of RDFS5.
SVFH Handles the following semantics that involves the interaction between
owl:someValuesFrom and rdfs:subClassOf. Consider two existential
restriction classes C1 and C2 that both use the same restriction property.
Assume further that the owl:someValuesFrom constraint class for C1 is a
subclass of that for C2. Then C1 can be inferred as a subclass of C2.
(New as of Release 11.2.)
SYMM Performs instance-level inference using instances of
owl:SymmetricProperty.
SYMH Performs inference for properties of type owl:SymmetricProperty.
THINGH Handles the semantics that any defined OWL class is a subclass of
owl:Thing. The consequence of this rule is that instances of all defined
OWL classes will become instances of owl:Thing. The size of the inferred
graph will very likely be bigger with this component selected. (New as of
Release 11.2.)
THINGSAM Handles the semantics that instances of owl:Thing are equal to
(owl:sameAs) themselves. This component is provided for the
convenience of some applications. Note that an application does not have
to select this inference component to figure out an individual is equal to
itself; this kind of information can easily be built in the application logic.
(New as of Release 11.2.)
TRANS Calculates transitive closure for instances of owl:TransitiveProperty.
UNION Captures the core semantics of the owl:unionOf construct. Basically, the
union class is a superclass of all member classes. For backward
compatibility, this component is not by default included in the OWLPrime
rulebase. (New as of Release 11.2.)
To deselect a component, use the component name followed by a minus (-) sign. For
example, SCOH- deselects inference of the subClassOf hierarchy.
For the options parameter, you can enable the following options to override the
default inferencing behavior:
15-38
Chapter 15
SEM_APIS.CREATE_ENTAILMENT
• COL_COMPRESS=T creates temporary, intermediate working tables. This option can reduce
the space required for such tables, and can improve the performance of the
CREATE_ENTAILMENT operation with large data sets.
By default COL_COMPRESS=T uses the "compress for query level low" setting; however, you
can add CPQH=T to change to the "compress for query level high" setting.
Note:
You can specify COL_COMPRESS=T only on systems that support Hybrid Columnar
Compression (HCC). For information about HCC, see Oracle Database
Concepts.
15-39
Chapter 15
SEM_APIS.CREATE_ENTAILMENT
For the delta_in parameter, inference performance is best if the value is small
compared to the overall size of those models. In a typical scenario, the best results
might be achieved when the delta contains fewer than 10,000 triples; however, some
tests have shown significant inference performance improvements with deltas as large
as 100,000 triples.
For the label_gen parameter, if you want to use the default OLS label generator,
specify the appropriate SEM_RDFSA package constant value fromTable 15-2.
Constant Description
SEM_RDFSA.LABELGEN_ Label generator that applies the label associated with the inferred
SUBJECT triple's subject as the triple's label.
SEM_RDFSA.LABELGEN_ Label generator that applies the label associated with the inferred
PREDICATE triple's subject as the triple's label.
SEM_RDFSA.LABELGEN_ Label generator that applies the label associated with the inferred
OBJECT triple's subject as the triple's label.
SEM_RDFSA.LABELGEN_ Label generator that applies the label associated with the rule that
RULE directly produced the inferred triple as the triple's label. If you
specify this option, you must also specify PROOF=T in the
options parameter.
SEM_RDFSA.LABELGEN_ Label generator that computes a dominating label of all the
DOMINATING available labels for the triple's components (subject, predicate,
object, and rule), and applies it as the label for the inferred triple.
Inferred triples accessed through generated labels might not be same as conceptual
triples inferred directly from the user accessible triples and rules. The labels generated
using a subset of triple components may be weaker than intended. For example, one
of the antecedents for the inferred triple may have a higher label than any of the
components of the triple. When the label is generated based on just the triple
components, end users with no access to one of the antecedents may still have
access to the inferred triple. Even when the antecedents are used for custom label
generation, the generated label may be stronger than intended. The inference process
is not exhaustive, and information pertaining to any alternate ways of inferring the
same triple is not available. So, the label generated using a given set of antecedents
may be too strong, because the user with access to all the triples in the alternate path
could infer the triple with lower access.
Even when generating a label that dominates all its components and antecedents, the
label may not be precise. This is the case when labels considered for dominating
relationship have non-overlapping group information. For example, consider two labels
L:C:NY and L:C:NH where L is a level, C is a component and NY and NH are two
groups. A simple label that dominates these two labels is L:C:NY,NH, and a true
supremum for the two labels is L:C:US, where US is parent group for both NY and NH.
Unfortunately, neither of these two dominating labels is precise for the triple inferred
from the triples with first two labels. If L:C:NY,NH is used for the inferred triple, a user
15-40
Chapter 15
SEM_APIS.CREATE_ENTAILMENT
with membership in either of these groups has access to the inferred triple, whereas the
same user does not have access to one of its antecedents. On the other hand, if L:C:US is
used for the inferred triple, a user with membership in both the groups and not in the US
group will not be able to access the inferred triple, whereas that user could infer the triple by
directly accessing its components and antecedents.
Because of these unique challenges with inferred triples, extra caution must be taken when
choosing or implementing the label generator.
See also the OLS example in the Examples section.
For information about semantic network types and options, see Semantic Networks.
Note:
If the SEM_APIS.CREATE_ENTAILMENT procedure with OWL2RL reasoning takes a
long time to execute , then the create entailment procedure needs to be executed
with options as shown for the OWL2RL rulebase example in the Examples section.
Examples
The following example creates an entailment named OWLTST_IDX using the OWLPrime
rulebase, and it causes proof to be generated for inferred triples.
EXECUTE sem_apis.create_entailment('owltst_idx', sem_models('owltst'),
sem_rulebases('OWLPRIME'), SEM_APIS.REACH_CLOSURE, null, 'PROOF=T');
The following example assumes an OLS environment. It creates a rulebase with a rule, and it
creates an entailment.
-- Create an entailment with a rule. --
exec sdo_rdf_inference.create_entailment('contracts_rb');
15-41
Chapter 15
SEM_APIS.CREATE_INDEX_ON_SPM_TAB
end;
/
The following example shows the steps to overcome long execution time when
creating entailments with OWL2RL rulebase.
15.22 SEM_APIS.CREATE_INDEX_ON_SPM_TAB
Format
SEM_APIS.create_index_on_spm_tab (
index_name IN VARCHAR2,
model_name IN VARCHAR2,
key_string IN VARCHAR2 DEFAULT NULL,
pred_name IN VARCHAR2 DEFAULT NULL,
tablespace_name IN DBMS_ID DEFAULT NULL,
degree IN NUMBER DEFAULT NULL,
prefixes IN VARCHAR2 DEFAULT NULL,
prefix_length IN NUMBER DEFAULT NULL,
options IN VARCHAR2 DEFAULT NULL,
network_owner IN DBMS_ID DEFAULT NULL,
network_name IN VARCHAR2 DEFAULT NULL);
Description
Creates a unique or a nonunique B-tree index on Subject-Predicate Matrix table.
Parameters
index_name
Name of the index.
model_name
Source of the data used to build the index.
key_string
Index key is composed of subject ID, graph ID, and predicates and their
corresponding value components.
The following codes are used for representing index keys:
• G: graph ID
• S: subject ID
15-42
Chapter 15
SEM_APIS.CREATE_INDEX_ON_SPM_TAB
pred_name
Identifies an MVP table on which the index is built.
tablespace_name
Destination tablespace for the index.
degree
Degree of parallelism to use for create index operation.
prefixes
SPARQL preamble style string.
For example, ‘PREFIX bsbm: <http://www4.wiwiss.fu-berlin.de/bizer/bsbm/v01/
vocabulary/> PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>‘
prefix_length
Number of columns to be compressed.
options
String specifying any options to use during the create index operation. Supported options
are:
• PCN_NAME= <name> - index is created on the named PCN table.
• SVP_NAME= <name> - index created on the named SVP table.
• CREATE_ANYWAY=T - the index is replaced.
network_owner
Owner of the semantic network. (See Table 1-1.)
network_name
Name of the semantic network. (See Table 1-1.)
15-43
Chapter 15
SEM_APIS.CREATE_MATERIALIZED_VIEW
Usage Notes
Examples
The following example creates the index ‘idx1’ on model ‘berlin’.
EXECUTE sem_apis.create_index_on_spm_tab('idx1', 'berlin',
'bsbm:productPropertyNumeric1 +G G+ bsbm:productPropertyNumeric2 S',
prefixes=>' PREFIX bsbm: <http://www4.wiwiss.fu-berlin.de/bizer/
bsbm/v01/vocabulary/>',
network_owner=>'rdfuser', network_name=>'mynet');
15.23 SEM_APIS.CREATE_MATERIALIZED_VIEW
Format
SEM_APIS.CREATE_MATERIALIZED_VIEW (
mv_name IN VARCHAR2,
model_name IN VARCHAR2,
compression IN BOOLEAN DEFAULT TRUE,
inmemory IN BOOLEAN DEFAULT FALSE,
values_as_vc IN BOOLEAN DEFAULT FALSE,
refresh IN VARCHAR2 DEFAULT 'C',
pred_list IN SYS.ODCIVARCHAR2LIST DEFAULT NULL,
options IN VARCHAR2 DEFAULT NULL,
network_owner IN VARCHAR2 DEFAULT NULL,
network_name IN VARCHAR2 DEFAULT NULL,
);
Description
Creates a materialized view for an RDF graph stored in Oracle Database.
Parameters
mv_name
Name of the materialized view to create.
model_name
Name of the model on which to create the materialized view.
compression
Specifies whether the materialized view is compressed.
inmemory
Specifies whether the materialized view is created in IMC format.
values_as_vc
Specifies whether the values of G,S,P,O are created as virtual columns.
refresh
The materialized view refresh method.
pred_list
Specifies the predicates list.
15-44
Chapter 15
SEM_APIS.SEM_APIS.CREATE_MV_BITMAP_INDEX
options
String specifying any options to use during the create materialized view operation.
Supported options are:
• TABLESPACE= <name>: materialized view is created in the named tablespace.
• PARALLEL= <degree>: materialized view is created with the parallel degree <degree>.
network_owner
Owner of the semantic network. (See Table 1-1.)
network_name
Name of the semantic network. (See Table 1-1.)
Usage Notes
For conceptual and usage information, see RDF Support for Materialized Join Views.
For information about semantic network types and options, see Semantic Networks.
Examples
The following example creates the materialized view MVX for the RDF model M0.
The following example creates the materialized view MVX for the RDF virtual model VM0.
The following example creates the materialized view MVY for the RDF model M1 using the
following supported options:
EXECUTE SEM_APIS.CREATE_MATERIALIZED_VIEW('MVY','M1',options=>'
TABLESPACE=TBS_3 PARALLEL=2 ');
The following example creates the materialized view MVX for the RDF model M0 using a list
of predicates.
EXECUTE SEM_APIS.CREATE_MATERIALIZED_VIEW('MVX','M0',
pred_list=>sys.odcivarchar2list('http://www.w3.org/2002/07/owl#sameAs',
'http://foo-example.com/name/hasSSN'));
15.24 SEM_APIS.SEM_APIS.CREATE_MV_BITMAP_INDEX
Format
SEM_APIS.CREATE_MV_BITMAP_INDEX (
mv_name IN VARCHAR2,
idx_columns IN VARCHAR2,
options IN VARCHAR2 DEFAULT NULL,
network_owner IN VARCHAR2 DEFAULT NULL,
network_name IN VARCHAR2 DEFAULT NULL,
);
15-45
Chapter 15
SEM_APIS.CREATE_PG_RDFVIEW
Description
Creates a bitmap index on a materialized join view for an RDF graph stored in Oracle
Database.
Parameters
mv_name
Name of the materialized view on which to create the bitmap index.
idx_columns
Name of the columns on which to create the bitmap index.
options
(Reserved for future use.)
network_owner
Owner of the semantic network. (See Table 1-1.)
network_name
Name of the semantic network. (See Table 1-1.)
Usage Notes
For more information, see RDF Support for Materialized Join Views.
For information about semantic network types and options, see Semantic Networks.
Examples
The following example creates two bitmap indexes on columns T0P and T1O for the
materialized view MVX.
The following example creates five bitmap indexes for the materialized view MVX..
15.25 SEM_APIS.CREATE_PG_RDFVIEW
Format
SEM_APIS.CREATE_PG_RDFVIEW(
model_name IN VARCHAR2,
pg_name IN VARCHAR2,
tsblespace_name IN VARCHAR2 DEFAULT NULL,
options IN VARCHAR2 DEFAULT NULL,
network_owner IN VARCHAR2 DEFAULT NULL,
network_name IN VARCHAR2 DEFAULT NULL);
or
SEM_APIS.CREATE_PG_RDFVIEW(
model_name IN VARCHAR2,
15-46
Chapter 15
SEM_APIS.CREATE_PG_RDFVIEW
pg_name IN VARCHAR2,
tsblespace_name IN VARCHAR2 DEFAULT NULL,
pg_stag_tab IN VARCHAR2,
pg_edge_kv_tab IN VARCHAR2,
pg_node_kv_tab IN VARCHAR2,
pg_edge_tab IN VARCHAR2,
options IN VARCHAR2 DEFAULT NULL,
network_owner IN VARCHAR2 DEFAULT NULL,
network_name IN VARCHAR2 default NULL);
Description
Creates an RDF view model for a property graph stored in Oracle Database.
Parameters
model_name
Name of the RDF view model to create.
pg_name
Name of the property graph for the RDF view.
tablespace_name
Destination tablespace for the RDF view model and the R2RML staging table.
pg_stag_tab
Name of the staging table. (See the Usage Notes for more information.)
pg_edge_kv_tab
Name of the table storing edge properties.
pg_node_kv_tab
Name of the table storing node properties.
pg_edge_tab
Name of the table storing distinct edges.
options
String specifying options for index creation using the form OPTION_NAME=option_value.
Supported options are:
• SUB_K=N, SUB_EL=N (use a substring of N characters for property key name or edge
label)
• GT_TABLE=T (assume a populated GT$ table)
• RECREATE=T (re-create an existing property graph RDF view model)
network_owner
Owner of the semantic network. (See Table 1-1.)
network_name
Name of the semantic network. (See Table 1-1.)
Usage Notes
This procedure has two formats. The first format has minimal input that uses default names
for the staging table and each table in the property graph schema, and that creates the
staging table automatically if it does not exist. The second format lets you specify custom
table names for the staging table and the property graph tables.
15-47
Chapter 15
SEM_APIS.CREATE_RDFVIEW_MODEL
If you use the second format, the staging table must already exist. If the staging table
is not empty, you must specify the RECREATE=T option. (With the second format, if the
staging table is not empty and if you do not specify the RECREATE=T option, then an
error is generated.)
For more information, see RDF Integration with Property Graph Data Stored in Oracle
Database.
For information about semantic network types and options, see Semantic Networks.
Examples
The following example creates the RDF view M1 for the property graph G1 in
tablespace MY_TBS, and it specifies a populated distinct edges table.
EXECUTE SEM_APIS.CREATE_PG_RDFVIEW('M1', 'G1', 'MY_TBS', ' GT_TABLE=T ');
The following example creates the RDF view M1 for the property graph G1 in
tablespace MY_TBS with property graph tables MY_EDGE_KV_TAB,
MY_NODE_KV_TAB, and MY_EDGE_TAB. and staging table MY_STAB.
EXECUTE SEM_APIS.CREATE_PG_RDFVIEW('M1', 'G1', 'MY_TBS', 'MY_STAB',
'MY_EDGE_KV_TAB', 'MY_NODE_KV_TAB', 'MY_EDGE_TAB');
15.26 SEM_APIS.CREATE_RDFVIEW_MODEL
Format
SEM_APIS.CREATE_RDFVIEW_MODEL(
model_name IN VARCHAR2,
tables IN SYS.ODCIVarchar2List,
prefix IN VARCHAR2 DEFAULT NULL,
r2rml_table_owner IN VARCHAR2 DEFAULT NULL,
r2rml_table_name IN VARCHAR2 DEFAULT NULL,
schema_table_owner IN VARCHAR2 DEFAULT NULL,
schema_table_name IN VARCHAR2 DEFAULT NULL,
options IN VARCHAR2 DEFAULT NULL,
r2rml_string IN CLOB DEFAULT NULL,
r2rml_string_fmt IN VARCHAR2 DEFAULT NULL,
network_owner IN VARCHAR2 DEFAULT NULL,
network_name IN VARCHAR2 DEFAULT NULL);
Description
Creates an RDF view using direct mapping for the specified list of tables or views or
using R2RML mapping.
Parameters
model_name
Name of the RDF view to be created.
tables
List of tables or views that are the sources of relational data for the RDF view to be
created using direct mapping. This parameter must be null if you want to use R2RML
mapping.
15-48
Chapter 15
SEM_APIS.CREATE_RDFVIEW_MODEL
prefix
Base prefix to be added at the beginning of the URIs in the RDF view.
r2rml_table_owner
For R2ML mapping, this parameter is required and specifies the name of the schema that
owns the staging table that holds the R2RML mapping (in N-triple format) to be used for
creating the RDF view.
For direct mapping, this parameter is optional and specifies the name of the schema that
owns the staging table into which the R2RML mapping (in N-triple format) generated from
the direct mapping will be stored.
r2rml_table_name
For R2ML mapping, this parameter is required and specifies the name of the staging table
that holds the R2RML mapping (in N-triple format) to be used for creating the RDF view.
For direct mapping, this parameter is optional and specifies the name of the staging table
into which the R2RML mapping (in N-triple format) generated from the direct mapping will be
stored.
schema_table_owner
Name of the schema that owns the staging table where the RDF schema generated for the
RDF view will be stored.
schema_table_name
Name of the staging table where the RDF schema generated for the RDF view will be stored.
options
For direct mapping, you can optionally specify any combination (including none) of the
following:
• CONFORMANCE=T suppresses some of the information that would otherwise get included by
default, including use of database constraint names and schema-qualified table or view
names for constructing RDF predicate names.
• GENERATE_ONLY=T only generates the R2RML mapping for the specified tables and stores
it in the specified r2rml_table_name, but the underlying RDF view model is not created.
If you specify this option, the r2rml_table_name parameter must not be null.
• KEY_BASED_REF_PROPERTY=T uses the foreign key column names to construct the RDF
predicate name. If this option is not specified, then the database constraint name is used
for constructing the RDF predicate name.
For direct mapping, RDF predicate names are derived from the corresponding database
names; therefore, preserving the name for the foreign key constraint is the default
behavior.
For an example that uses KEY_BASED_REF_PROPERTY=T , see Example 10-1 in Creating
an RDF View with Direct Mapping.
• SCALAR_COLUMNS_ONLY=T generates the R2RML mapping for only the scalar columns in
the specified tables or views. Other non-scalar columns in the tables or views are
ignored. Without this option, if you attempt to create a direct mapping on a table with
user-defined types or LOB columns, an error is raised.
r2rml_string
An R2RML mapping string in Turtle or N-Triple format to be used for creating the RDF view.
15-49
Chapter 15
SEM_APIS.CREATE_RDFVIEW_MODEL
r2rml_string_fmt
The format of the R2RML mapping string specified in r2rml_string. Possible values
are TURTLE and N-TRIPLE.
network_owner
Owner of the semantic network. (See Table 1-1.)
network_name
Name of the semantic network. (See Table 1-1.)
Usage Notes
You must grant the SELECT and INSERT privileges on r2rml_table_name and
schema_table_name to MDSYS.
For more information about RDF views, see RDF Views: Relational Data as RDF.
For information about semantic network types and options, see Semantic Networks.
Examples
The following example creates an RDF view using direct mapping for tables EMP and
DEPT. The prefix used for the URIs is http://empdb/.
BEGIN
sem_apis.create_rdfview_model(
model_name => 'empdb_model_direct',
tables => sem_models('EMP', 'DEPT'),
prefix => 'http://empdb/',
network_owner=>'RDFUSER',
network_name=>'NET1'
);
END;
/
The following example creates an RDF view using R2RML mapping as specified by
the RDF triples in the staging table SCOTT.R2RTAB.
BEGIN
sem_apis.create_rdfview_model(
model_name => 'empdb_model_R2RML',
tables => NULL,
r2rml_table_owner => 'SCOTT',
r2rml_table_name => 'R2RTAB',
network_owner=>'RDFUSER',
network_name=>'NET1'
);
END;
/
The following example creates an RDF view using an R2RML mapping specified
directly as a string.
DECLARE
r2rmlStr CLOB;
BEGIN
r2rmlStr :=
'@prefix rr: <http://www.w3.org/ns/r2rml#>. '||
'@prefix xsd: <http://www.w3.org/2001/XMLSchema#>. '||
'@prefix ex: <http://example.com/ns#>. '||'
15-50
Chapter 15
SEM_APIS.CREATE_RDFVIEW_MODEL
ex:TriplesMap_Emp
rr:logicalTable [ rr:tableName "EMP" ];
rr:subjectMap [
rr:template "http://data.example.com/employee/{EMPNO}";
rr:class ex:Employee;
];
rr:predicateObjectMap [
rr:predicate ex:empNum;
rr:objectMap [ rr:column "EMPNO" ; rr:datatype xsd:integer ];
];
rr:predicateObjectMap [
rr:predicate ex:empName;
rr:objectMap [ rr:column "ENAME" ];
];
rr:predicateObjectMap [
rr:predicate ex:jobType;
rr:objectMap [ rr:column "JOB" ];
];
rr:predicateObjectMap [
rr:predicate ex:worksForDeptNum;
rr:objectMap [ rr:column "DEPTNO" ; rr:dataType xsd:integer ];
].';
sem_apis.create_rdfview_model(
model_name => 'empdb_model_R2RML',
tables => NULL,
r2rml_string => r2rmlStr,
r2rml_string_fmt => 'TURTLE',
network_owner=>'RDFUSER',
network_name=>'NET1'
);
END;
/
The following example creates an RDF view using direct mapping as specified by the RDF
triples in the tables EMP and DEPT in the schema-private network owned by RDFUSER. It
also selects information about employees who work at the Boston location.
BEGIN
sem_apis.create_rdfview_model(
model_name => 'empdb_model',
tables => SYS.ODCIVarchar2List('EMP', 'DEPT'),
prefix => 'http://empdb/',
options => 'KEY_BASED_REF_PROPERTY=T',
network_owner=>'RDFUSER',
network_name=>'NET1'
);
END;
/
SELECT e.empno FROM emp e, dept d WHERE e.deptno = d.deptno AND d.loc =
'Boston';
SELECT emp
FROM TABLE(SEM_MATCH('{?emp emp:ref-DEPTNO ?dept . ?dept dept:LOC
"Boston"}',SEM_Models('empdb_model'),NULL,SEM_ALIASES(
15-51
Chapter 15
SEM_APIS.CREATE_RULEBASE
SEM_ALIAS('dept','http://empdb/RDFUSER.DEPT#'),SEM_ALIAS('emp','http://
empdb/RDFUSER.EMP#')),null,null,null,null,null,'RDF_USER','NET1'));
15.27 SEM_APIS.CREATE_RULEBASE
Format
SEM_APIS.CREATE_RULEBASE(
rulebase_name IN VARCHAR2),
options IN VARCHAR2 DEFAULT NULL),
network_owner IN VARCHAR2 DEFAULT NULL,
network_name IN VARCHAR2 DEFAULT NULL);
Description
Creates a rulebase.
Parameters
rulebase_name
Name of the rulebase.
options
(Not currently used.)
network_owner
Owner of the semantic network. (See Table 1-1.)
network_name
Name of the semantic network. (See Table 1-1.)
Usage Notes
This procedure creates a user-defined rulebase. After creating the rulebase, you can
add rules to it. To cause the rules in the rulebase to be applied in a query of RDF data,
you can specify the rulebase in the call to the SEM_MATCH table function.
Rules and rulebases are explained in Inferencing: Rules and Rulebases. The
SEM_MATCH table function is described in Using the SEM_MATCH Table Function to
Query Semantic Data,
For information about semantic network types and options, see Semantic Networks.
Examples
The following example creates a rulebase named family_rb. (It is an excerpt from
Example 1-124 in Example: Family Information.)
EXECUTE SEM_APIS.CREATE_RULEBASE('family_rb');
15.28 SEM_APIS.CREATE_SEM_MODEL
Format
SEM_APIS.CREATE_SEM_MODEL(
model_name IN VARCHAR2,
table_name IN VARCHAR2,
15-52
Chapter 15
SEM_APIS.CREATE_SEM_MODEL
column_name IN VARCHAR2,
model_tablespace IN VARCHAR2 DEFAULT NULL,
options IN VARCHAR2 DEFAULT NULL,
network_owner IN VARCHAR2 DEFAULT NULL,
network_name IN VARCHAR2 DEFAULT NULL);
Description
Creates a semantic technology model.
Parameters
model_name
Name of the model.
table_name
Name of the table to hold references to semantic technology data for this model.
This parameter must be NULL for a schema-private network.
column_name
Name of the column of type SDO_RDF_TRIPLE_S in table_name.
This parameter must be NULL for a schema-private network.
model_tablespace
Name of the tablespace for the tables and other database objects used by Oracle to support
this model. The default value is the tablespace that was specified in the call to the
SEM_APIS.CREATE_SEM_NETWORK procedure.
options
An optional quoted string with one or more of the following model creation options:
• COMPRESS=CSCQH uses COLUMN STORE COMPRESS FOR QUERY HIGH on the
RDF_LINK$ partition for the model.
• COMPRESS=CSCQL uses COLUMN STORE COMPRESS FOR QUERY LOW on the
RDF_LINK$ partition for the model.
• COMPRESS=RSCA uses ROW STORE COMPRESS ADVANCED on the RDF_LINK$
partition for the model.
• COMPRESS=RSCB uses ROW STORE COMPRESS BASIC on the RDF_LINK$ partition for
the model.
• MODEL_PARTITIONS=n overrides the default number of subpartitions in a composite
partitioned semantic network and creates the specified number (n) of subpartitions in the
RDF_LINK$ partition for the model.
network_owner
Owner of the semantic network. (See Table 1-1.)
network_name
Name of the semantic network. (See Table 1-1.)
Usage Notes
For an MDSYS-owned network, you must create the table to hold references to semantic
technology data before calling this procedure to create the semantic technology model.
However, this table creation step is not required when using a schema-private network. For
more information, see Quick Start for Using Semantic Data.
15-53
Chapter 15
SEM_APIS.CREATE_SEM_NETWORK
This procedure adds the model to the SEM_MODEL$ view, which is described in
Metadata for Models.
This procedure is the only supported way to create a model. Do not use SQL INSERT
statements with the SEM_MODEL$ view.
To delete a model, use the SEM_APIS.DROP_SEM_MODEL procedure.
The options COMPRESS=CSCQH, COMPRESS=CSCQL, and COMPRESS=RSCA should be used
only if you have the appropriate licenses.
For information about semantic network types and options, see Semantic Networks.
Examples
The following example creates a semantic technology model named articles in the
schema-private network. (This example is an excerpt from Example 1-123 in Example:
Journal Article Information.)
15.29 SEM_APIS.CREATE_SEM_NETWORK
Format
SEM_APIS.CREATE_SEM_NETWORK(
tablespace_name IN VARCHAR2,
options IN VARCHAR2 DEFAULT NULL,
network_owner IN VARCHAR2 DEFAULT NULL,
network_name IN VARCHAR2 DEFAULT NULL);
Description
Creates structures for persistent storage of semantic data.
Parameters
tablespace_name
Name of the tablespace to be used for tables created by this procedure. This
tablespace will be the default for all models that you create, although you can override
15-54
Chapter 15
SEM_APIS.CREATE_SEM_NETWORK
the default when you create a model by specifying the model_tablespace parameter in the
call to the SEM_APIS.CREATE_SEM_MODEL procedure.
options
An optional quoted string with one or more of the following network creation options:
• COMPRESS=CSCQH uses COLUMN STORE COMPRESS FOR QUERY HIGH on the
RDF_LINK$ and RDF_VALUE$ tables.
• COMPRESS=CSCQL uses COLUMN STORE COMPRESS FOR QUERY LOW on the
RDF_LINK$ and RDF_VALUE$ tables.
• COMPRESS=RSCA uses ROW STORE COMPRESS ADVANCED on the RDF_LINK$ and
RDF_VALUE$ tables.
• COMPRESS=RSCB uses ROW STORE COMPRESS BASIC on the RDF_LINK$ and
RDF_VALUE$ tables. This is the default compression level.
• MODEL_PARTITIONING=BY_HASH_P uses list-hash composite partitioning to partition
RDF_LINK$ by model ID and further subpartition each model by a hash of the predicate
ID.
• MODEL_PARTITIONS=n sets the default number (n) of subpartitions to use for each model.
This option is used in conjunction with MODEL_PARTITIONING=BY_HASH_P.
• MODEL_PARTITIONING=BY_LIST_G uses list-list composite partitioning to partition
RDF_LINK$ by model ID and further subpartition each model by graph ID. This
subpartition is automatically maintained as data is inserted into the model.
• NETWORK_STORAGE_FORM=ESC specifies use of escaped storage form for lexical values in
RDF_VALUE$. Unicode characters and special characters will be stored using ASCII
escape sequences. (You cannot specify both the escaped and unescaped storage
forms.)
• NETWORK_STORAGE_FORM=UNESC specifies use of unescaped storage form for lexical
values in RDF_VALUE$. Unicode characters and special characters will be stored as
single characters. This is the default.
network_owner
Owner of the semantic network. (See Table 1-1.)
network_name
Name of the semantic network. (See Table 1-1.)
Usage Notes
This procedure creates system tables and other database objects used for semantic
technology support.
You should create a tablespace for the semantic technology system tables and specify the
tablespace name in the call to this procedure. (You should not specify the SYSTEM
tablespace.) The size needed for the tablespace that you create will depend on the amount of
semantic technology data you plan to store.
You must connect to the database as a user with DBA privileges or as the intended network
owner in order to call this procedure, and you should call the procedure only once for the
database.
To drop these structures for persistent storage of semantic data, you must connect as a user
with DBA privileges or as the owner of the schema-private network, and call the
SEM_APIS.DROP_SEM_NETWORK procedure.
15-55
Chapter 15
SEM_APIS.CREATE_SEM_SQL
Examples
The following example creates a tablespace for semantic technology system tables
and creates structures for persistent storage of semantic data in this tablespace.
Advanced compression is used for the semantic network.
CREATE TABLESPACE rdf_tblspace
DATAFILE '/oradata/orcl/rdf_tblspace.dat' SIZE 1024M REUSE
AUTOEXTEND ON NEXT 256M MAXSIZE UNLIMITED
SEGMENT SPACE MANAGEMENT AUTO;
. . .
EXECUTE SEM_APIS.CREATE_SEM_NETWORK('rdf_tblspace',
options=>'MODEL_PARTITIONING=BY_HASH_P MODEL_PARTITIONS=16');
15.30 SEM_APIS.CREATE_SEM_SQL
Format
SEM_APIS.CREATE_SEM_SQL;
Description
Creates SEM_SQL SQL Macro.
Parameters
Usage Notes
Examples
The following example creates SEM_SQL SQL Macro.
EXECUTE SEM_APIS.CREATE_SEM_SQL;
15.31 SEM_APIS.CREATE_SOURCE_EXTERNAL_TABLE
Format
SEM_APIS.CREATE_SOURCE_EXTERNAL_TABLE(
source_table IN VARCHAR2,
def_directory IN VARCHAR2,
log_directory IN VARCHAR2 DEFAULT NULL,
bad_directory IN VARCHAR2 DEFAULT NULL,
log_file IN VARCHAR2 DEFAULT NULL,
bad_file IN VARCHAR2 DEFAULT NULL,
parallel IN INTEGER DEFAULT NULL,
15-56
Chapter 15
SEM_APIS.CREATE_SOURCE_EXTERNAL_TABLE
Description
Creates an external table to map an N-Triple or N-Quad format file into a table.
Parameters
source_table
Name of the external table to be created.
def_directory
Database directory where the input files are located. To load from this staging table, you
must have READ privilege on this directory.
log_directory
Database directory where the log files will be generated when loading from the external
table. If not specified, the value of the def_directory parameter is used. When loading from
the external table, you must have WRITE privilege on this directory.
bad_directory
Database directory where the bad files will be generated when loading from the external
table. If not specified, the value of the def_directory parameter is used. When loading from
the external table, you must have WRITE privilege on this directory.
log_file
Name of the log file. If not specified, the name will be generated automatically during a load
operation.
bad_file
Name of the bad file. If not specified, the name will be generated automatically during a load
operation.
parallel
Degree of parallelism to associate with the external table being created.
source_table_owner
Owner for the external table being created. If not specified, the invoker becomes the owner.
flags
(Reserved for future use)
Usage Notes
For more information and an example, see Loading N-Quad Format Data into a Staging Table
Using an External Table.
Examples
The following example creates a source external table. (This example is an excerpt from
Example 1-102 in Loading N-Quad Format Data into a Staging Table Using an External
Table.)
BEGIN
sem_apis.create_source_external_table(
source_table => 'stage_table_source'
,def_directory => 'DATA_DIR'
,bad_file => 'CLOBrows.bad'
15-57
Chapter 15
SEM_APIS.CREATE_SPARQL_UPDATE_TABLES
);
END;
15.32 SEM_APIS.CREATE_SPARQL_UPDATE_TABLES
Format
SEM_APIS.CREATE_SPARQL_UPDATE_TABLES();
Description
Creates global temporary tables in the caller’s schema for use with SPARQL Update
operations.
Parameters
None.
Usage Notes
Invoking SEM_APIS.UPDATE_MODEL with STREAMING=F, FORCE_BULK=T, or
DEL_AS_INS=T option requires that the following temporary tables exist in the caller’s
schema: RDF_UPD_DEL$, RDF_UPD_INS$, and RDF_UPD_INS_CLOB$. These
tables are created with the following definitions:
Examples
The following example creates the necessary global temporary tables in the caller’s
schema for use with SPARQL Update operations.
15-58
Chapter 15
SEM_APIS.CREATE_VIRTUAL_MODEL
EXECUTE SEM_APIS.CREATE_SPARQL_UPDATE_TABLES;
15.33 SEM_APIS.CREATE_VIRTUAL_MODEL
Format
SEM_APIS.CREATE_VIRTUAL_MODEL(
vm_name IN VARCHAR2,
models IN SEM_MODELS,
rulebases IN SEM_RULEBASES DEFAULT NULL,
options IN VARCHAR2 DEFAULT NULL,
entailments IN SEM_ENTAILMENTS DEFAULT NULL,
network_owner IN VARCHAR2 DEFAULT NULL,
network_name IN VARCHAR2 DEFAULT NULL);
Description
Creates a virtual model containing the specified semantic models and/or entailments.
Entailments can be specified in one of the following ways:
• By specifying one or more models and one or more rulebases. In this case, a virtual
model will be created using the single entailment that corresponds to the exact
combination of models and rulebases specified. An error is raised if no such entailment
exists.
• By specifying zero or more models and one or more entailments. In this case, the
contents of the models and entailments will be combined regardless of their relationship.
The first method ensures a sound and complete dataset, whereas the second method relaxes
the sound and complete constraints for more flexibility.
Parameters
vm_name
Name of the virtual model to be created.
models
One or more semantic model names. Its data type is SEM_MODELS, which has the
following definition: TABLE OF VARCHAR2(25). If this parameter is null, no models are included
in the virtual model definition.
rulebases
One or more rulebase names. Its data type is SEM_RULEBASES, which has the following
definition: TABLE OF VARCHAR2(25). If this parameter is null, no rulebases are included in the
virtual model definition. Rules and rulebases are explained in Inferencing: Rules and
Rulebases.
If you specify this parameter, you cannot also specify the entailments parameter.
options
Options for creation:
• PXN=T forces a UNION ALL-based view definition for the virtual model. This is the default
for virtual models with 16 or fewer components.
• PXN=F forces an IN LIST-based view definition for the virtual model. This is the default for
virtual models with more than 16 components.
15-59
Chapter 15
SEM_APIS.CREATE_VIRTUAL_MODEL
• PXN=F INMEMORY=T (in combination) let you to create an in-memory virtual model.
If you specify INMEMORY=T but not PXN=F, then the in-memory virtual columns are
created, but the performance will suffer. If you do not specify INMEMORY=T, the
virtual model is not created in-memory. (See also Using In-Memory Virtual
Columns with RDF.)
• REPLACE=T lets you to replace a virtual model without dropping it. (Using this
option is analogous to using CREATE OR REPLACE VIEW with a view.)
entailments
One or more entailment names. Its data type is SEM_ENTAILMENTS, which has the
following definition: TABLE OF VARCHAR2(25). If this parameter is null, no entailments
are included in the virtual model definition. Entailments are explained in Using OWL
Inferencing.
If you specify this parameter, you cannot also specify the rulebases parameter.
network_owner
Owner of the semantic network. (See Table 1-1.)
network_name
Name of the semantic network. (See Table 1-1.)
Usage Notes
For an explanation of virtual models, including usage information, see Virtual Models.
An entailment must exist for each specified combination of semantic model and
rulebase.
To create a virtual model, you must either be (A) the owner of each specified model
and any corresponding entailments, or (B) a user with DBA privileges.
To replace a virtual model, you must be the owner of the virtual model or a user with
DBA privileges.
The option INMEMORY=T should be used only if you have the appropriate licenses.
15-60
Chapter 15
SEM_APIS.DELETE_ENTAILMENT_STATS
The user that invokes this procedure will be the owner of the virtual model and will have
SELECT WITH GRANT privileges on the SEMU_vm_name and SEMV_vm_name views. To
query the corresponding virtual model, a user must have select privileges on these views.
For information about semantic network types and options, see Semantic Networks.
Examples
The following example creates a virtual model named VM1.
EXECUTE sem_apis.create_virtual_model('VM1', sem_models('model_1', 'model_2'),
sem_rulebases('OWLPRIME'));
The following example creates a virtual model named VM1 using the relaxed entailment
specification.
EXECUTE sem_apis.create_virtual_model('VM1', models=>sem_models('model_1', 'model_2'),
entailments=>sem_entailments('entailment1','entailment2'));
The following example effectively redefines virtual model VM1 by using the REPLACE=T option.
EXECUTE sem_apis.create_virtual_model('VM1', models=>sem_models('model_1', 'model_2'),
entailments=>sem_entailments('entailment1'), options=>'REPLACE=T');
15.34 SEM_APIS.DELETE_ENTAILMENT_STATS
Format
SEM_APIS.DELETE_ENTAILMENT_STATS (
entailment_name IN VARCHAR2,
cascade_parts IN BOOLEAN DEFAULT TRUE,
cascade_columns IN BOOLEAN DEFAULT TRUE,
cascade_indexes IN BOOLEAN DEFAULT TRUE,
no_invalidate IN BOOLEAN DEFAULT DBMS_STATS.AUTO_INVALIDATE,
force IN BOOLEAN DEFAULT FALSE,
network_owner IN VARCHAR2 DEFAULT NULL,
network_name IN VARCHAR2 DEFAULT NULL);
Description
Deletes statistics for a specified entailment.
15-61
Chapter 15
SEM_APIS.DELETE_MODEL_STATS
Parameters
entailment_name
Name of the entailment.
(other parameters)
See the parameter explanations for the DBMS_STATS.DELETE_TABLE_STATS
procedure in Oracle Database PL/SQL Packages and Types Reference, although
force here applies to entailment statistics.
network_owner
Owner of the semantic network. (See Table 1-1.)
network_name
Name of the semantic network. (See Table 1-1.)
Usage Notes
See the information about the DBMS_STATS package inOracle Database PL/SQL
Packages and Types Reference.
See also Managing Statistics for Semantic Models and the Semantic Network.
For information about semantic network types and options, see Semantic Networks.
Examples
The following example deletes statistics for an entailment named OWLTST_IDX.
EXECUTE SEM_APIS.DELETE_ENTAILMENT_STATS('owltst_idx');
15.35 SEM_APIS.DELETE_MODEL_STATS
Format
SEM_APIS.DELETE_MODEL_STATS (
model_name IN VARCHAR2,
cascade_parts IN BOOLEAN DEFAULT TRUE,
cascade_columns IN BOOLEAN DEFAULT TRUE,
cascade_indexes IN BOOLEAN DEFAULT TRUE,
no_invalidate IN BOOLEAN DEFAULT DBMS_STATS.AUTO_INVALIDATE,
force IN BOOLEAN DEFAULT FALSE,
network_owner IN VARCHAR2 DEFAULT NULL,
network_name IN VARCHAR2 DEFAULT NULL);
Description
Deletes statistics for a specified model.
Parameters
model_name
Name of the model.
15-62
Chapter 15
SEM_APIS.DISABLE_CHANGE_TRACKING
(other parameters)
See the parameter explanations for the DBMS_STATS.DELETE_TABLE_STATS procedure
in Oracle Database PL/SQL Packages and Types Reference, although force here applies to
model statistics.
network_owner
Owner of the semantic network. (See Table 1-1.)
network_name
Name of the semantic network. (See Table 1-1.)
Usage Notes
Only the model owner or a users with DBA privileges can execute this procedure.
See the information about the DBMS_STATS package inOracle Database PL/SQL Packages
and Types Reference.
See also Managing Statistics for Semantic Models and the Semantic Network.
For information about semantic network types and options, see Semantic Networks.
Examples
The following example deletes statistics for a model named FAMILY.
EXECUTE SEM_APIS.DELETE_MODEL_STATS('family');
15.36 SEM_APIS.DISABLE_CHANGE_TRACKING
Format
SEM_APIS.DISABLE_CHANGE_TRACKING(
models_in IN SEM_MODELS,
network_owner IN VARCHAR2 DEFAULT NULL,
network_name IN VARCHAR2 DEFAULT NULL);
Description
Disables change tracking for a specified set of models.
Parameters
models_in
One or more model names. Its data type is SEM_MODELS, which has the following
definition: TABLE OF VARCHAR2(25)
network_owner
Owner of the semantic network. (See Table 1-1.)
network_name
Name of the semantic network. (See Table 1-1.)
Usage Notes
Disabling change tracking on a model automatically disables incremental inference on all
entailment that use the model.
15-63
Chapter 15
SEM_APIS.DISABLE_INC_INFERENCE
To use this procedure, you must be the owner of the specified model, and incremental
inference must have been previously enabled.
For an explanation of incremental inference, including usage information, see
Performing Incremental Inference.
For information about semantic network types and options, see Semantic Networks.
Examples
The following example disables change tracking for the family model.
EXECUTE sem_apis.disable_change_tracking(sem_models('family'));
15.37 SEM_APIS.DISABLE_INC_INFERENCE
Format
SEM_APIS.DISABLE_INC_INFERENCE(
entailment_name IN VARCHAR2,
network_owner IN VARCHAR2 DEFAULT NULL,
network_name IN VARCHAR2 DEFAULT NULL);
Description
Disables incremental inference for a specified entailment (rules index).
Parameters
entailment_name
Name of the entailment for which to disable incremental inference.
network_owner
Owner of the semantic network. (See Table 1-1.)
network_name
Name of the semantic network. (See Table 1-1.)
Usage Notes
To use this procedure, you must be the owner of the specified entailment, and
incremental inference must have been previously enabled by the
SEM_APIS.ENABLE_INC_INFERENCE procedure.
Calling this procedure automatically disables change tracking for all models owned by
the invoking user that were having changes tracked only because of this particular
inference.
For an explanation of incremental inference, including usage information, see
Performing Incremental Inference.
For information about semantic network types and options, see Semantic Networks.
Examples
The following example enables incremental inference for the entailment named
RDFS_RIX_FAMILY.
EXECUTE sem_apis.disable_inc_inference('rdfs_rix_family');
15-64
Chapter 15
SEM_APIS.DISABLE_INMEMORY
15.38 SEM_APIS.DISABLE_INMEMORY
Format
SEM_APIS.DISABLE_INMEMORY(
network_owner IN VARCHAR2 DEFAULT NULL,
network_name IN VARCHAR2 DEFAULT NULL);
Description
Disables in-memory population of RDF data in a semantic network.
Parameters
network_owner
Owner of the semantic network. (See Table 1-1.)
network_name
Name of the semantic network. (See Table 1-1.)
Usage Notes
To use this procedure, you must have DBA privileges.
See the information in RDF Support for Oracle Database In-Memory.
For information about semantic network types and options, see Semantic Networks.
Examples
The following example disables in-memory population of RDF data in the semantic network.
EXECUTE SEM_APIS.DISABLE_INMEMORY;
15.39 SEM_APIS.DISABLE_INMEMORY_FOR_ENT
Format
SEM_APIS.DISABLE_INMEMORY_FOR_ENT(
entailment_name IN VARCHAR2,
network_owner IN VARCHAR2 DEFAULT NULL,
network_name IN VARCHAR2 DEFAULT NULL);
Description
Disables in-memory population of RDF data for an entailment in a semantic network.
Parameters
entailment_name
Name of the entailment.
network_owner
Owner of the semantic network. (See Table 1-1.)
15-65
Chapter 15
SEM_APIS.DISABLE_INMEMORY_FOR_MODEL
network_name
Name of the semantic network. (See Table 1-1.)
Usage Notes
To use this procedure, you must have DBA privileges.
See the information in RDF Support for Oracle Database In-Memory.
For information about semantic network types and options, see Semantic Networks.
Examples
The following example disables in-memory population of RDF data for entailment
RIDX1 in the MDSYS-owned semantic network.
EXECUTE SEM_APIS.DISABLE_INMEMORY_FOR_ENT('RIDX1');
15.40 SEM_APIS.DISABLE_INMEMORY_FOR_MODEL
Format
SEM_APIS.DISABLE_INMEMORY_FOR_MODEL(
model_name IN VARCHAR2,
network_owner IN VARCHAR2 DEFAULT NULL,
network_name IN VARCHAR2 DEFAULT NULL);
Description
Disables in-memory population of RDF data for a model in a semantic network.
Parameters
model_name
Name of the model.
network_owner
Owner of the semantic network. (See Table 1-1.)
network_name
Name of the semantic network. (See Table 1-1.)
Usage Notes
To use this procedure, you must have DBA privileges.
See the information in RDF Support for Oracle Database In-Memory.
For information about semantic network types and options, see Semantic Networks.
Examples
The following example enables in-memory population of RDF data for model M1 in the
MDSYS-owned semantic network.
EXECUTE SEM_APIS.DISABLE_INMEMORY_FOR_MODEL('M1');
15-66
Chapter 15
SEM_APIS.DISABLE_NETWORK_SHARING
15.41 SEM_APIS.DISABLE_NETWORK_SHARING
Format
SEM_APIS.DISABLE_NETWORK_SHARING(
network_owner IN VARCHAR2,
network_name IN VARCHAR2,
options IN VARCHAR2 DEFAULT NULL);
Description
Disables sharing of a semantic network.
Parameters
network_owner
Owner of the semantic network. (See Table 1-1.)
network_name
Name of the semantic network. (See Table 1-1.)
options
(Reserved for future use)
Usage Notes
To use this procedure, you must have DBA privileges or be the owner of the specified
network.
For information about semantic network types and options, see Semantic Networks.
Examples
The following example enables sharing of the mynetwork schema-private network owned by
database user scott.
EXECUTE SEM_APIS.DISABLE_NETWORK_SHARING('scott', 'mynetwork');
15.42 SEM_APIS.DROP_DATATYPE_INDEX
Format
SEM_APIS.DROP_DATATYPE_INDEX(
datatype IN VARCHAR2,
force_drop IN BOOLEAN default FALSE,
network_owner IN VARCHAR2 DEFAULT NULL,
network_name IN VARCHAR2 DEFAULT NULL);
Description
Drops (deletes) an existing data type index.
15-67
Chapter 15
SEM_APIS.DROP_ENTAILMENT
Parameters
datatype
URI of the data type for the index to drop.
force_drop
TRUE forces the index to be dropped if an error occurs during the processing of the
statement; FALSE (the default) does not drop the index if an error occurs during the
processing of the statement.
network_owner
Owner of the semantic network. (See Table 1-1.)
network_name
Name of the semantic network. (See Table 1-1.)
Usage Notes
You must have DBA privileges to call this procedure.
For an explanation of data type indexes, see Using Data Type Indexes.
For information about semantic network types and options, see Semantic Networks.
Examples
The following example drops the data type index for xsd:string typed literals and
plain literals.
EXECUTE SEM_APIS.DROP_DATATYPE_INDEX('http://www.w3.org/2001/XMLSchema#string');
15.43 SEM_APIS.DROP_ENTAILMENT
Format
SEM_APIS.DROP_ENTAILMENT(
index_name_in IN VARCHAR2,
named_g_in IN SEM_GRAPHS DEFAULT NULL,
dop IN INT DEFAULT 1,
network_owner IN VARCHAR2 DEFAULT NULL,
network_name IN VARCHAR2 DEFAULT NULL);
Description
Drops (deletes) an entailment (rules index).
Parameters
index_name_in
Name of the entailment to be deleted.
named_g_in
Causes only the triples with the specified graph names in the entailment to be
deleted. A null value (the default) drops the entire entailment.
15-68
Chapter 15
SEM_APIS.DROP_MATERIALIZED_VIEW
dop
Degree of parallelism for a parallel execution of triple deletion. Applies only if the named_g_in
parameter is not null.
network_owner
Owner of the semantic network. (See Table 1-1.)
network_name
Name of the semantic network. (See Table 1-1.)
Usage Notes
You can use this procedure to delete an entailment that you created using the
SEM_APIS.CREATE_ENTAILMENT procedure.
If you drop only a subset of the entailment with specified named graphs (that is, when
named_g_in is not null) on an entailment with a VALID or INCOMPLETE status, then the resulting
status of the entailment after the drop is set to INCOMPLETE.
For information about semantic network types and options, see Semantic Networks.
Examples
The following example deletes a entailment named OWLTST_IDX.
EXECUTE sem_apis.drop_entailment('owltst_idx');
The following example deletes only inferred triples with graph names G1 and G2 that belong to
the entailment named OWLNG_IDX. Any inferred triples in the default graph and other named
graphs remain in the entailment.
EXECUTE sem_apis.drop_entailment('owlng_idx',sem_graphs('<urn:G1>','<urn:G2>'));
15.44 SEM_APIS.DROP_MATERIALIZED_VIEW
Format
SEM_APIS.DROP_MATERIALIZED_VIEW (
mv_name IN VARCHAR2,
options IN VARCHAR2 DEFAULT NULL,
network_owner IN VARCHAR2 DEFAULT NULL,
network_name IN VARCHAR2 DEFAULT NULL,
);
Description
Drops a materialized join view for an RDF graph stored in Oracle Database.
Parameters
mv_name
Name of the materialized view to drop.
15-69
Chapter 15
SEM_APIS.DROP_MV_BITMAP_INDEX
options
(Reserved for future use.)
network_owner
Owner of the semantic network. (See Table 1-1.)
network_name
Name of the semantic network. (See Table 1-1.)
Usage Notes
For more information, see RDF Support for Materialized Join Views.
For information about semantic network types and options, see Semantic Networks.
Examples
The following example drops the materialized view MVX.
EXECUTE SEM_APIS.DROP_MATERIALIZED_VIEW('MVX');
15.45 SEM_APIS.DROP_MV_BITMAP_INDEX
Format
SEM_APIS.DROP_MV_BITMAP_INDEX (
mv_name IN VARCHAR2,
idx_columns IN VARCHAR2,
options IN VARCHAR2 DEFAULT NULL,
network_owner IN VARCHAR2 DEFAULT NULL,
network_name IN VARCHAR2 DEFAULT NULL,
);
Description
Drops a bitmap index on a materialized join view for an RDF graph stored in Oracle
Database.
Parameters
mv_name
Name of the materialized view from which to drop the bitmap index.
idx_columns
Name of the columns on which to drop the bitmap index.
options
(Reserved for future use.)
network_owner
Owner of the semantic network. (See Table 1-1.)
network_name
Name of the semantic network. (See Table 1-1.)
15-70
Chapter 15
SEM_APIS.DROP_PG_RDFVIEW
Usage Notes
For more information, see RDF Support for Materialized Join Views.
For information about semantic network types and options, see Semantic Networks.
Examples
The following example drops two bitmap indexes on columns T1O and T0SV for the
materialized view MVX.
15.46 SEM_APIS.DROP_PG_RDFVIEW
Format
SEM_APIS.DROP_PG_RDFVIEW(
model_name IN VARCHAR2,
options IN VARCHAR2 DEFAULT NULL,
network_owner IN VARCHAR2 DEFAULT NULL,
network_name IN VARCHAR2 DEFAULT NULL);
or
SEM_APIS.DROP_PG_RDFVIEW(
model_name IN VARCHAR2,
pg_stag_tab IN VARCHAR2,
options IN VARCHAR2 DEFAULT NULL,
network_owner IN VARCHAR2 DEFAULT NULL,
network_name IN VARCHAR2 DEFAULT NULL);
Description
Drops an RDF view model for a property graph stored in Oracle Database.
Parameters
model_name
Name of the RDF view model to drop.
pg_stag_tab
Name of the staging table. (See also the TRUNCATE=T option.)
options
String specifying options for index creation using the form OPTION_NAME=option_value.
Supported options are:
• TRUNCATE=T (truncate the staging table instead of dropping it)
network_owner
Owner of the semantic network. (See Table 1-1.)
network_name
Name of the semantic network. (See Table 1-1.)
15-71
Chapter 15
SEM_APIS.DROP_PG_RDFVIEW_INDEXES
Usage Notes
For more information, see RDF Integration with Property Graph Data Stored in Oracle
Database.
For information about semantic network types and options, see Semantic Networks.
Examples
The following example drops the RDF view M1.
EXECUTE SEM_APIS.DROP_PG_RDFVIEW('M1');
The following example drops the RDF view with the staging table MY_STAB, and
truncates the staging table instead of dropping it.
EXECUTE SEM_APIS.DROP_PG_RDFVIEW('M1', 'MY_STAB', 'TRUNCATE_STAB=T');
15.47 SEM_APIS.DROP_PG_RDFVIEW_INDEXES
Format
SEM_APIS.DROP_PG_RDFVIEW_INDEXES(
pg_name IN VARCHAR2,
options IN VARCHAR2 DEFAULT NULL,
network_owner IN VARCHAR2 DEFAULT NULL,
network_name IN VARCHAR2 DEFAULT NULL);
Description
Drops indexes that were created using the
SEM_APIS.BUILD_PG_RDFVIEW_INDEXES procedure.
Parameters
pg_name
Name of the property graph to index.
options
(Reserved for future use.)
network_owner
Owner of the semantic network. (See Table 1-1.)
network_name
Name of the semantic network. (See Table 1-1.)
Usage Notes
For more information, see RDF Integration with Property Graph Data Stored in Oracle
Database.
For information about semantic network types and options, see Semantic Networks.
Examples
The following example drops indexes for the property graph G1.
15-72
Chapter 15
SEM_APIS.DROP_RDFVIEW_MODEL
EXECUTE SEM_APIS.DROP_PG_RDFVIEW_INDEXES('G1');
15.48 SEM_APIS.DROP_RDFVIEW_MODEL
Format
SEM_APIS.DROP_RDFVIEW_MODEL(
model_name IN VARCHAR2,
options IN VARCHAR2 DEFAULT NULL,
network_owner IN VARCHAR2 DEFAULT NULL,
network_name IN VARCHAR2 DEFAULT NULL);
Description
Drops (deletes) an RDF view.
Parameters
model_name
Name of the RDF view to be dropped.
options
(Reserved for future use.)
network_owner
Owner of the semantic network. (See Table 1-1.)
network_name
Name of the semantic network. (See Table 1-1.)
Usage Notes
You must be the owner of the RDF view to be dropped.
For more information about RDF views, see RDF Views: Relational Data as RDF.
For information about semantic network types and options, see Semantic Networks.
Examples
The following example drops an RDF view.
BEGIN
sem_apis.drop_rdfview_model(
model_name => 'empdb_model'
);
END;
/
15.49 SEM_APIS.DROP_RULEBASE
Format
SEM_APIS.DROP_RULEBASE(
rulebase_name IN VARCHAR2,
options IN VARCHAR2 DEFAULT NULL,
network_owner IN VARCHAR2 DEFAULT NULL,
network_name IN VARCHAR2 DEFAULT NULL);
15-73
Chapter 15
SEM_APIS.DROP_SEM_INDEX
Description
Deletes a rulebase.
Parameters
rulebase_name
Name of the rulebase.
options
(Reserved for future use.)
network_owner
Owner of the semantic network. (See Table 1-1.)
network_name
Name of the semantic network. (See Table 1-1.)
Usage Notes
This procedure deletes the specified rulebase, making it no longer available for use in
calls to the SEM_MATCH table function. For information about rulebases, see
Inferencing: Rules and Rulebases.
Only the creator of a rulebase can delete the rulebase.
For information about semantic network types and options, see Semantic Networks.
Examples
The following example drops the rulebase named family_rb.
EXECUTE SEM_APIS.DROP_RULEBASE('family_rb');
15.50 SEM_APIS.DROP_SEM_INDEX
Format
SEM_APIS.DROP_SEM_INDEX(
index_code IN VARCHAR2,
options IN VARCHAR2 DEFAULT NULL,
network_owner IN VARCHAR2 DEFAULT NULL,
network_name IN VARCHAR2 DEFAULT NULL);
Description
Drops a semantic network index on the models and entailments of the semantic
network.
Parameters
index_code
Index code string. Must match the index_code value that was specified in an earlier
call to the SEM_APIS.ADD_SEM_INDEX procedure.
15-74
Chapter 15
SEM_APIS.DROP_SEM_MODEL
options
(Reserved for future use.)
network_owner
Owner of the semantic network. (See Table 1-1.)
network_name
Name of the semantic network. (See Table 1-1.)
Usage Notes
For an explanation of semantic network indexes, see Using Semantic Network Indexes.
For information about semantic network types and options, see Semantic Networks.
Examples
The following example drops a semantic network index with the index code string pcsm on the
models and entailments of the semantic network.
EXECUTE SEM_APIS.DROP_SEM_INDEX('pscm');
15.51 SEM_APIS.DROP_SEM_MODEL
Format
SEM_APIS.DROP_SEM_MODEL(
model_name IN VARCHAR2,
options IN VARCHAR2 DEFAULT NULL,
network_owner IN VARCHAR2 DEFAULT NULL,
network_name IN VARCHAR2 DEFAULT NULL);
Description
Drops (deletes) a semantic technology model.
Parameters
model_name
Name of the model.
options
(Reserved for future use.)
network_owner
Owner of the semantic network. (See Table 1-1.)
network_name
Name of the semantic network. (See Table 1-1.)
Usage Notes
This procedure deletes the model from the SEM_MODEL$ view, which is described in
Metadata for Models.
This procedure is the only supported way to delete a model. Do not use SQL DELETE
statements with the SEM_MODEL$ view.
Only the creator of a model can delete the model.
15-75
Chapter 15
SEM_APIS.DROP_SEM_NETWORK
Examples
The following example drops the semantic technology model named articles.
EXECUTE SEM_APIS.DROP_SEM_MODEL('articles');
15.52 SEM_APIS.DROP_SEM_NETWORK
Format
SEM_APIS.DROP_SEM_NETWORK(
cascade IN BOOLEAN DEFAULT FALSE,
options IN VARCHAR2 DEFAULT NULL,
network_owner IN VARCHAR2 DEFAULT NULL,
network_name IN VARCHAR2 DEFAULT NULL);
Description
Removes structures used for persistent storage of semantic data.
Parameters
cascade
TRUE drops any existing semantic technology models and rulebases, and removes
structures used for persistent storage of semantic data; FALSE (the default) causes the
operation to fail if any semantic technology models or rulebases exist.
options
(Reserved for future use.)
network_owner
Owner of the semantic network. (See Table 1-1.)
network_name
Name of the semantic network. (See Table 1-1.)
Usage Notes
To remove structures used for persistent storage of semantic data, you must connect
as a user with DBA privileges or as the owner of the schema-private network, and call
this procedure.
If any version-enabled models exist, this procedure will fail regardless of the value of
the cascade parameter.
For information about semantic network types and options, see Semantic Networks.
Examples
The following example removes structures used for persistent storage of semantic
data.
EXECUTE SEM_APIS.DROP_SEM_NETWORK;
15-76
Chapter 15
SEM_APIS.DROP_SEM_SQL
15.53 SEM_APIS.DROP_SEM_SQL
Format
SEM_APIS.DROP_SEM_SQL;
Description
Drops SEM_SQL SQL Macro.
Parameters
Usage Notes
Examples
The following example drops SEM_SQL SQL Macro.
EXECUTE SEM_APIS.DROP_SEM_SQL;
15.54 SEM_APIS.DROP_SPARQL_UPDATE_TABLES
Format
SEM_APIS.DROP_SPARQL_UPDATE_TABLES();
Description
Drops the global temporary tables in the caller’s schema for use with SPARQL Update
operations.
Parameters
None.
Usage Notes
This procedure drops the global temporary tables that were created by the
SEM_APIS.CREATE_SPARQL_UPDATE_TABLES procedure.
For more information, see Support for SPARQL Update Operations on a Semantic Model.
Examples
The following example drops the global temporary tables that had been created in the caller’s
schema for use with SPARQL Update operations.
EXECUTE SEM_APIS.DROP_SPARQL_UPDATE_TABLES;
15-77
Chapter 15
SEM_APIS.DROP_SPM_TAB
15.55 SEM_APIS.DROP_SPM_TAB
Format
SEM_APIS.DROP_SPM_TAB (
model_name IN VARCHAR2,
target IN VARCHAR2,
options IN VARCHAR2 DEFAULT NULL,
network_owner IN DBMS_ID DEFAULT NULL,
network_name IN VARCHAR2 DEFAULT NULL);
Description
Drops a specific SPM table identified by name and type, all SPM tables of given type,
or all SPM tables.
Parameters
model_name
Name of the RDF model.
target
Must be NULL, unless used for dropping all SPM tables or SPM tables belonging to a
specific category namely SVP, PCN, or MVP. In that case, the supported options are:
• ALL_SPM: drops all SPM tables.
• SVP_ALL: drops all SVP tables.
• MVP_ALL: drops all MVP tables.
• PCN_ALL: drops all PCN tables.
options
String specifying any of the following supported drop options:
• SVP_NAME=<name>: locates the target SVP table.
• PCN_NAME=<name>: locates the target PCN table.
• PRED_ID=<number>: locates the target MVP table.
• PRED_NAME=<absolute_IRI>: locates the target MVP table.
network_owner
Owner of the semantic network. (See Table 1-1.)
network_name
Name of the semantic network. (See Table 1-1.)
Usage Notes
• This operation has a DDL semantics.
• The invoker must be the owner of the target RDF model or the RDF network or
both.
15-78
Chapter 15
SEM_APIS.DROP_SPM_TAB
Examples
The following example drops all SPM tables:
The following example drops the default SVP table that was created without a name:
The following example drops a specific MVP table, identified by an ID specified for the
predicate, mvp_pred_id:
15-79
Chapter 15
SEM_APIS.DROP_USER_INFERENCE_OBJS
The following example drops a specific MVP table, identified by a predicate specified
as shown:
15.56 SEM_APIS.DROP_USER_INFERENCE_OBJS
Format
SEM_APIS.DROP_USER_INFERENCE_OBJS(
uname IN VARCHAR2,
options IN VARCHAR2 DEFAULT NULL,
network_owner IN VARCHAR2 DEFAULT NULL,
network_name IN VARCHAR2 DEFAULT NULL);
Description
Drops (deletes) all rulebases and entailments owned by a specified database user.
Parameters
uname
Name of a database user. (This value is case-sensitive; for example, HERMAN and
herman are considered different users.)
options
(Reserved for future use.)
network_owner
Owner of the semantic network. (See Table 1-1.)
network_name
Name of the semantic network. (See Table 1-1.)
Usage Notes
You must have sufficient privileges to delete rules and rulebases for the specified user.
This procedure does not delete the database user. It deletes only RDF rulebases and
entailments owned by that user.
For information about semantic network types and options, see Semantic Networks.
Examples
The following example deletes all rulebases and entailments owned by user SCOTT.
EXECUTE SEM_APIS.DROP_USER_INFERENCE_OBJS('SCOTT');
15-80
Chapter 15
SEM_APIS.DROP_VIRTUAL_MODEL
15.57 SEM_APIS.DROP_VIRTUAL_MODEL
Format
SEM_APIS.DROP_VIRTUAL_MODEL(
vm_name IN VARCHAR2,
options IN VARCHAR2 DEFAULT NULL,
network_owner IN VARCHAR2 DEFAULT NULL,
network_name IN VARCHAR2 DEFAULT NULL);
Description
Drops (deletes) a virtual model.
Parameters
vm_name
Name of the virtual model to be deleted.
options
(Reserved for future use.)
network_owner
Owner of the semantic network. (See Table 1-1.)
network_name
Name of the semantic network. (See Table 1-1.)
Usage Notes
You can use this procedure to delete a virtual model that you created using the
SEM_APIS.CREATE_VIRTUAL_MODEL procedure. A virtual model is deleted automatically
if any of its component models, rulebases, or entailment are deleted.
To use this procedure, you must be the owner of the specified virtual model.
For an explanation of virtual models, including usage information, see Virtual Models.
For information about semantic network types and options, see Semantic Networks.
Examples
The following example deletes a virtual model named VM1.
EXECUTE sem_apis.drop_virtual_model('VM1');
15.58 SEM_APIS.ENABLE_CHANGE_TRACKING
Format
SEM_APIS.ENABLE_CHANGE_TRACKING(
models_in IN SEM_MODELS,
network_owner IN VARCHAR2 DEFAULT NULL,
network_name IN VARCHAR2 DEFAULT NULL);
15-81
Chapter 15
SEM_APIS.ENABLE_INC_INFERENCE
Description
Enables change tracking for a specified set of models.
Parameters
models_in
One or more model names. Its data type is SEM_MODELS, which has the following
definition: TABLE OF VARCHAR2(25)
network_owner
Owner of the semantic network. (See Table 1-1.)
network_name
Name of the semantic network. (See Table 1-1.)
Usage Notes
Change tracking must be enabled on a model before incremental inference can be
enabled on any entailments that use the model.
To use this procedure, you must be the owner of the specified model or models.
If the owner of an entailment is also an owner of any underlying models, then enabling
incremental inference on the entailment (by calling the
SEM_APIS.ENABLE_INC_INFERENCE procedure) automatically enables change
tracking on those models owned by that user.
To disable change tracking for a set of models, use the
SEM_APIS.DISABLE_CHANGE_TRACKING procedure.
For an explanation of incremental inference, including usage information, see
Performing Incremental Inference.
For information about semantic network types and options, see Semantic Networks.
Examples
The following example enables change tracking for the family model.
EXECUTE sem_apis.enable_change_tracking(sem_models('family'));
15.59 SEM_APIS.ENABLE_INC_INFERENCE
Format
SEM_APIS.ENABLE_INC_INFERENCE(
entailment_name IN VARCHAR2,
network_owner IN VARCHAR2 DEFAULT NULL,
network_name IN VARCHAR2 DEFAULT NULL);
Description
Enables incremental inference for a specified entailment (rules index).
15-82
Chapter 15
SEM_APIS.ENABLE_INMEMORY
Parameters
entailment_name
Name of the entailment for which to enable incremental inference.
network_owner
Owner of the semantic network. (See Table 1-1.)
network_name
Name of the semantic network. (See Table 1-1.)
Usage Notes
To use this procedure, you must be the owner of the specified entailment.
Before this procedure is executed, all underlying models involved in the entailment must have
change tracking enabled. If the owner of the entailment is also an owner of any underlying
models, calling this procedure automatically enables change tracking on those models.
However, if some underlying model are not owned by the owner of the entailment, the
appropriate model owners must first call the SEM_APIS.ENABLE_CHANGE_TRACKING
procedure to enable change tracking on those models.
To disable incremental inference for an entailment, use the
SEM_APIS.DISABLE_INC_INFERENCE procedure.
For an explanation of incremental inference, including usage information, see Performing
Incremental Inference.
For information about semantic network types and options, see Semantic Networks.
Examples
The following example enables incremental inference for the entailment named
RDFS_RIX_FAMILY.
EXECUTE sem_apis.enable_inc_inference('rdfs_rix_family');
15.60 SEM_APIS.ENABLE_INMEMORY
Format
SEM_APIS.ENABLE_INMEMORY(
populate_wait IN BOOLEAN,
options IN VARCHAR2 DEFAULT NULL,
network_owner IN VARCHAR2 DEFAULT NULL,
network_name IN VARCHAR2 DEFAULT NULL);
Description
Loads RDF data for the semantic network into memory.
Parameters
populate_wait
Boolean value to indicate whether to wait until all RDF data is loaded into memory before
finishing:
15-83
Chapter 15
SEM_APIS.ENABLE_INMEMORY_FOR_ENT
options
Options for in-memory data population:
• The string POPULATE_TRIPLES=F disables populating RDF_LINK$ table data in
memory. (RDF_VALUE$ table data is still populated in memory.) If this option is
not specified, RDF_LINK$ table data is populated in memory by default.
network_owner
Owner of the semantic network. (See Table 1-1.)
network_name
Name of the semantic network. (See Table 1-1.)
Usage Notes
To use this procedure, you must have DBA privileges.
See the information in RDF Support for Oracle Database In-Memory.
To disable in-memory population of RDF data in the semantic network, use the
SEM_APIS.DISABLE_INMEMORY.
For information about semantic network types and options, see Semantic Networks.
Examples
The following example enables in-memory population of RDF data, and waits until all
RDF data is loaded into memory before finishing.
EXECUTE SEM_APIS.ENABLE_INMEMORY(true);
15.61 SEM_APIS.ENABLE_INMEMORY_FOR_ENT
Format
SEM_APIS.ENABLE_INMEMORY_FOR_ENT(
entailment_name IN VARCHAR2,
network_owner IN VARCHAR2 DEFAULT NULL,
network_name IN VARCHAR2 DEFAULT NULL);
Description
Enables in-memory population of RDF data for an entailment in a semantic network.
Parameters
entailment_name
Name of the entailment.
network_owner
Owner of the semantic network. (See Table 1-1.)
network_name
Name of the semantic network. (See Table 1-1.)
15-84
Chapter 15
SEM_APIS.ENABLE_INMEMORY_FOR_MODEL
Usage Notes
To use this procedure, you must have DBA privileges.
See the information in RDF Support for Oracle Database In-Memory.
For information about semantic network types and options, see Semantic Networks.
Examples
The following example enables in-memory population of RDF data for entailment RIDX1 in
the MDSYS-owned semantic network.
EXECUTE SEM_APIS.ENABLE_INMEMORY_FOR_ENT('RIDX1');
15.62 SEM_APIS.ENABLE_INMEMORY_FOR_MODEL
Format
SEM_APIS.ENABLE_INMEMORY_FOR_MODEL(
model_name IN VARCHAR2,
network_owner IN VARCHAR2 DEFAULT NULL,
network_name IN VARCHAR2 DEFAULT NULL);
Description
Enables in-memory population of RDF data for a model in a semantic network.
Parameters
model_name
Name of the model.
network_owner
Owner of the semantic network. (See Table 1-1.)
network_name
Name of the semantic network. (See Table 1-1.)
Usage Notes
To use this procedure, you must have DBA privileges.
See the information in RDF Support for Oracle Database In-Memory.
For information about semantic network types and options, see Semantic Networks.
Examples
The following example enables in-memory population of RDF data for model M1 in the
MDSYS-owned semantic network.
EXECUTE SEM_APIS.ENABLE_INMEMORY_FOR_MODEL('M1');
15-85
Chapter 15
SEM_APIS.ENABLE_NETWORK_SHARING
15.63 SEM_APIS.ENABLE_NETWORK_SHARING
Format
SEM_APIS.ENABLE_NETWORK_SHARING(
network_owner IN VARCHAR2,
network_name IN VARCHAR2,
options IN VARCHAR2 DEFAULT NULL);
Description
Enables sharing of a semantic network.
Parameters
network_owner
Owner of the semantic network. (See Table 1-1.)
network_name
Name of the semantic network. (See Table 1-1.)
options
(Reserved for future use)
Usage Notes
To use this procedure, you must have DBA privileges or be the owner of the specified
network.
For information about semantic network types and options, see Semantic Networks.
Examples
The following example enables sharing of the mynetwork schema-private network
owned by database user scott.
EXECUTE SEM_APIS.ENABLE_NETWORK_SHARING('scott', 'mynetwork');
15.64 SEM_APIS.ESCAPE_CLOB_TERM
Format
SEM_APIS.ESCAPE_CLOB_TERM(
term IN CLOB CHARACTER SET ANY_CS,
utf_encode IN NUMBER DEFAULT 1
) RETURN CLOB CHARACTER SET val%CHARSET;
Description
Returns the input RDF term with special characters and non-ASCII characters
escaped as specified by the W3C N-Triples format (http://www.w3.org/TR/rdf-
testcases/#ntriples).
15-86
Chapter 15
SEM_APIS.ESCAPE_CLOB_VALUE
Parameters
term
The RDF term to escape.
utf_encode
Set to 1 (the default) if non-ASCII characters and non-printable ASCII characters other than
chr(8), chr(9), chr(10), chr(12), and chr(13) should be escaped. Otherwise, such characters
will not be escaped.
Usage Notes
For information about using the DO_UNESCAPE keyword in the options parameter of the
SEM_MATCH table function, see Using the SEM_MATCH Table Function to Query Semantic
Data.
Examples
The following example escapes an input RDF term containing TAB and NEWLINE characters.
SELECT SEM_APIS.ESCAPE_CLOB_TERM('"abc' || chr(9) || 'def' || chr(10) ||
'hij"^^<http://www.w3.org/2001/XMLSchema#string>')
FROM DUAL;
15.65 SEM_APIS.ESCAPE_CLOB_VALUE
Format
SEM_APIS.ESCAPE_CLOB_VALUE(
val IN CLOB CHARACTER SET ANY_CS,
start_offset IN NUMBER DEFAULT 1,
end_offset IN NUMBER DEFAULT 0,
utf_encode IN NUMBER DEFAULT 1,
include_start IN NUMBER DEFAULT 0
) RETURN VARCHAR2 CHARACTER SET val%CHARSET;
Description
Returns the input CLOB value with special characters and non-ASCII characters escaped as
specified by the W3C N-Triples format (http://www.w3.org/TR/rdf-testcases/#ntriples).
Parameters
val
The CLOB text to escape.
start_offset
The offset in val from which to start character escaping. The default (1) causes escaping to
start at the first character of val.
end_offset
The offset in val from which to end character escaping. The default (0) causes escaping to
continue through the end of val.
15-87
Chapter 15
SEM_APIS.ESCAPE_RDF_TERM
utf_encode
Set to 1 (the default) if non-ASCII characters and non-printable ASCII characters
other than chr(8), chr(9), chr(10), chr(12), and chr(13) should be escaped. Otherwise,
such characters will not be escaped.
include_start
Set to 1 if the characters in val from 1 to start_offset should be prefixed
(prepended) to the return value. Otherwise, no such characters will be prefixed to the
return value.
Usage Notes
For information about using the DO_UNESCAPE keyword in the options parameter of the
SEM_MATCH table function, see Using the SEM_MATCH Table Function to Query
Semantic Data.
Examples
The following example escapes an input character string containing TAB and
NEWLINE characters.
SELECT SEM_APIS.ESCAPE_CLOB_VALUE('abc' || chr(9) || 'def' || chr(10) || 'hij')
FROM DUAL;
15.66 SEM_APIS.ESCAPE_RDF_TERM
Format
SEM_APIS.ESCAPE_RDF_TERM(
term IN VARCHAR2 CHARACTER SET ANY_CS,
utf_encode IN NUMBER DEFAULT 1
) RETURN VARCHAR2 CHARACTER SET val%CHARSET;
Description
Returns the input RDF term with special characters and non-ASCII characters
escaped as specified by the W3C N-Triples format (http://www.w3.org/TR/rdf-
testcases/#ntriples).
Parameters
term
The RDF term to escape.
utf_encode
Set to 1 (the default) if non-ASCII characters and non-printable ASCII characters
other than chr(8), chr(9), chr(10), chr(12), and chr(13) should be escaped. Otherwise,
such characters will not be escaped.
Usage Notes
For information about using the DO_UNESCAPE keyword in the options parameter of the
SEM_MATCH table function, see Using the SEM_MATCH Table Function to Query
Semantic Data.
15-88
Chapter 15
SEM_APIS.ESCAPE_RDF_VALUE
Examples
The following example escapes an input RDF term containing TAB and NEWLINE characters.
SELECT SEM_APIS.ESCAPE_RDF_TERM('"abc' || chr(9) || 'def' || chr(10) || 'hij"^^<http://
www.w3.org/2001/XMLSchema#string>')
FROM DUAL;
15.67 SEM_APIS.ESCAPE_RDF_VALUE
Format
SEM_APIS.ESCAPE_RDF_VALUE(
val IN VARCHAR2 CHARACTER SET ANY_CS,
utf_encode IN NUMBER DEFAULT 1
) RETURN VARCHAR2 CHARACTER SET val%CHARSET;
Description
Returns the input CLOB value with special characters and non-ASCII characters escaped as
specified by the W3C N-Triples format (http://www.w3.org/TR/rdf-testcases/#ntriples).
Parameters
val
The text to escape.
utf_encode
Set to 1 (the default) if non-ASCII characters and non-printable ASCII characters other than
chr(8), chr(9), chr(10), chr(12), and chr(13) should be escaped. Otherwise, such characters
will not be escaped.
Usage Notes
For information about using the DO_UNESCAPE keyword in the options parameter of the
SEM_MATCH table function, see Using the SEM_MATCH Table Function to Query Semantic
Data.
Examples
The following example escapes an input character string containing TAB and NEWLINE
characters.
SELECT SEM_APIS.ESCAPE_RDF_VALUE('abc' || chr(9) || 'def' || chr(10) || 'hij')
FROM DUAL;
15.68 SEM_APIS.EXPORT_ENTAILMENT_STATS
Format
SEM_APIS.EXPORT_ENTAILMENT_STATS (
entailment_name IN VARCHAR2,
stattab IN VARCHAR2,
statid IN VARCHAR2 DEFAULTNULL,
cascade IN BOOLEAN DEFAULT TRUE,
statown IN VARCHAR2 DEFAULT NULL,
stat_category IN VARCHAR2 DEFAULT 'OBJECT_STATS',
15-89
Chapter 15
SEM_APIS.EXPORT_MODEL_STATS
Description
Exports statistics for a specified entailment and stores them in the user statistics table.
Parameters
entailment_name
Name of the entailment.
(other parameters)
See the parameter explanations for the DBMS_STATS.EXPORT_TABLE_STATS
procedure in Oracle Database PL/SQL Packages and Types Reference, although
force here applies to entailment statistics.
Specifying cascade also exports all index statistics associated with the entailment.
network_owner
Owner of the semantic network. (See Table 1-1.)
network_name
Name of the semantic network. (See Table 1-1.)
Usage Notes
See the information about the DBMS_STATS package inOracle Database PL/SQL
Packages and Types Reference.
See also Managing Statistics for Semantic Models and the Semantic Network.
For information about semantic network types and options, see Semantic Networks.
Examples
The following example exports statistics for an entailment named OWLTST_IDX and
stores them in a table named STAT_TABLE.
EXECUTE SEM_APIS.EXPORT_ENTAILMENT_STATS('owltst_idx', 'stat_table');
15.69 SEM_APIS.EXPORT_MODEL_STATS
Format
SEM_APIS.EXPORT_MODEL_STATS (
model_name IN VARCHAR2,
stattab IN VARCHAR2,
statid IN VARCHAR2 DEFAULT NULL,
cascade IN BOOLEAN DEFAULT TRUE,
statown IN VARCHAR2 DEFAULT NULL,
stat_category IN VARCHAR2 DEFAULT 'OBJECT_STATS',
network_owner IN VARCHAR2 DEFAULT NULL,
network_name IN VARCHAR2 DEFAULT NULL);
Description
Exports statistics for a specified model and stores them in the user statistics table.
15-90
Chapter 15
SEM_APIS.EXPORT_RDFVIEW_MODEL
Parameters
entailment_name
Name of the entailment.
(other parameters)
See the parameter explanations for the DBMS_STATS.EXPORT_TABLE_STATS procedure
in Oracle Database PL/SQL Packages and Types Reference.
Specifying cascade also exports all index statistics associated with the model.
network_owner
Owner of the semantic network. (See Table 1-1.)
network_name
Name of the semantic network. (See Table 1-1.)
Usage Notes
See the information about the DBMS_STATS package inOracle Database PL/SQL Packages
and Types Reference.
See also Managing Statistics for Semantic Models and the Semantic Network.
For information about semantic network types and options, see Semantic Networks.
Examples
The following example exports statistics for a model named FAMILY and stores them in a table
named STAT_TABLE.
EXECUTE SEM_APIS.EXPORT_MODEL_STATS('family', 'stat_table');
15.70 SEM_APIS.EXPORT_RDFVIEW_MODEL
Format
SEM_APIS.EXPORT_RDFVIEW_MODEL(
model_name IN VARCHAR2,
rdf_table_owner IN VARCHAR2 DEFAULT NULL,
rdf_table_name IN VARCHAR2 DEFAULT NULL,
options IN VARCHAR2 DEFAULT NULL,
network_owner IN VARCHAR2 DEFAULT NULL,
network_name IN VARCHAR2 DEFAULT NULL);
Description
Exports (materializes) the virtual RDF triples of an RDF view to a staging table.
Parameters
model_name
Name of the RDF view to be exported.
rdf_table_owner
Name of the schema that owns the staging table where the RDF triples obtained from the
RDF view are to be stored.
15-91
Chapter 15
SEM_APIS.GATHER_SPM_INFO
rdf_table_name
Name of the staging table where the RDF triples obtained from the RDF view are to
be stored.
options
(Reserved for future use)
network_owner
Owner of the semantic network. (See Table 1-1.)
network_name
Name of the semantic network. (See Table 1-1.)
Usage Notes
You must have the SELECT privilege for the database view SEMM_<model_name>.
For more information about RDF views, see RDF Views: Relational Data as RDF. For
information about exporting RDF views, see Exporting Virtual Content of an RDF View
into a Staging Table.
For information about semantic network types and options, see Semantic Networks.
Examples
The following example exports RDF triples from RDF view empdb_model to the staging
table SCOTT.RDFTAB.
BEGIN
sem_apis.export_rdfview_model(
model_name => 'empdb_model',
rdf_table_owner => 'SCOTT',
rdf_table_name => 'RDFTAB'
);
END;
/
15.71 SEM_APIS.GATHER_SPM_INFO
Format
SEM_APIS.GATHER_SPM_INFO (
model_name IN VARCHAR2,
pred_info_tabname IN DBMS_ID,
tablespace_name IN DBMS_ID DEFAULT NULL,
degree IN NUMBER DEFAULT NULL,
options IN VARCHAR2 DEFAULT NULL,
network_owner IN DBMS_ID DEFAULT NULL,
network_name IN VARCHAR2 DEFAULT NULL);
Description
Gathers information about predicate use in a given RDF model.
For more information on SPM tables content, see Creating SPM Tables.
15-92
Chapter 15
SEM_APIS.GET_CHANGE_TRACKING_INFO
Parameters
model_name
Name of the RDF model.
pred_info_tabname
Name of the table to be created to contain the information about predicate use.
tablespace_name
Name of the target tablespace for the pred_info_tabname table.
degree
Degree of parallelism.
options
String specifying the options to use during the operation.
Supported option is:
CREATE_ANYWAY=T: Truncate the table specified in pred_info_tabname.
network_owner
Owner of the semantic network. (See Table 1-1.)
network_name
Name of the semantic network. (See Table 1-1.)
Usage Notes
• The pred_info_tabname table will be created in the invoker’s schema.
• Invoker must have READ privilege for the RDF model.
Examples
The following example creates a new table M1_PRED_INFO in the invoker’s schema. This table
contains predicate use information for the specified model M1 in the RDF network named NET1
owned by RDFUSER.
begin
sem_apis.gather_spm_info(
model_name => 'M1',
pred_info_tabname => 'M1_PRED_INFO',
degree => 2,
network_owner => 'RDFUSER',
network_name => 'NET1'
);
end;
15.72 SEM_APIS.GET_CHANGE_TRACKING_INFO
Format
SEM_APIS.GET_CHANGE_TRACKING_INFO(
model_name IN VARCHAR2,
enabled OUT BOOLEAN,
tracking_start_time OUT TIMESTAMP,
15-93
Chapter 15
SEM_APIS.GET_CHANGE_TRACKING_INFO
Description
Returns change tracking information for a model.
Parameters
model_name
Name of the semantic technology model.
enabled
Boolean value returned by the procedure: TRUE if change tracking is enabled for the
model, or FALSE if change tacking is not enabled for the model.
tracking_start_time
Timestamp indicating when change tracking was enabled for the model (if it is
enabled).
network_owner
Owner of the semantic network. (See Table 1-1.)
network_name
Name of the semantic network. (See Table 1-1.)
Usage Notes
The model_name value must match a value in the MODEL_NAME column in the
SEM_MODEL$ view, which is described in Metadata for Models.
To enable change tracking for a set of models, use the
SEM_APIS.ENABLE_CHANGE_TRACKING procedure.
For an explanation of incremental inference, including usage information, see
Performing Incremental Inference.
For information about semantic network types and options, see Semantic Networks.
Examples
The following example displays change tracking information for a model.
DECLARE
bEnabled boolean;
tsEnabled timestamp;
BEGIN
EXECUTE IMMEDIATE 'create table m1 (t SDO_RDF_TRIPLE_S)';
sem_apis.create_sem_model('m1','m1','t');
sem_apis.enable_change_tracking(sem_models('m1'));
15-94
Chapter 15
SEM_APIS.GET_INC_INF_INFO
15.73 SEM_APIS.GET_INC_INF_INFO
Format
SEM_APIS.GET_INC_INF_INFO(
entailment_name IN VARCHAR2,
enabled OUT BOOLEAN,
prev_inf_start_time OUT TIMESTAMP,
network_owner IN VARCHAR2 DEFAULT NULL,
network_name IN VARCHAR2 DEFAULT NULL);
Description
Returns incremental inference information for an entailment.
Parameters
entailment_name
Name of the entailment.
enabled
Boolean value returned by the procedure: TRUE if incremental inference is enabled for the
entailment, or FALSE if incremental inference is not enabled for the entailment.
prev_inf_start_time
Timestamp indicating when the entailment was most recently updated (if incremental
inference is enabled).
network_owner
Owner of the semantic network. (See Table 1-1.)
network_name
Name of the semantic network. (See Table 1-1.)
Usage Notes
To enable incremental inference for an entailment, use the
SEM_APIS.ENABLE_INC_INFERENCE procedure.
For an explanation of incremental inference, including usage information, see Performing
Incremental Inference.
For information about semantic network types and options, see Semantic Networks.
Examples
The following example displays incremental inference information for an entailment.
DECLARE
bEnabled boolean;
tsEnabled timestamp;
DECLARE
EXECUTE IMMEDIATE 'create table m1 (t SDO_RDF_TRIPLE_S)';
sem_apis.create_sem_model('m1','m1','t');
sem_apis.create_entailment('m1_inf',sem_models('m1'),
sem_rulebases('owlprime'),null,null,'INC=T');
15-95
Chapter 15
SEM_APIS.GET_MODEL_ID
15.74 SEM_APIS.GET_MODEL_ID
Format
SEM_APIS.GET_MODEL_ID(
model_name IN VARCHAR2
) RETURN NUMBER;
Description
Returns the model ID number of a semantic technology model.
Parameters
model_name
Name of the semantic technology model.
Usage Notes
The model_name value must match a value in the MODEL_NAME column in the
SEM_MODEL$ view, which is described in Metadata for Models.
Examples
The following example returns the model ID number for the model named articles.
(This example is an excerpt from Example 1-123 in Example: Journal Article
Information.)
SELECT SEM_APIS.GET_MODEL_ID('articles') AS model_id FROM DUAL;
MODEL_ID
----------
1
15.75 SEM_APIS.GET_MODEL_NAME
Format
SEM_APIS.GET_MODEL_NAME(
model_id IN NUMBER
) RETURN VARCHAR2;
Description
Returns the model name of a semantic technology model.
15-96
Chapter 15
SEM_APIS.GET_PLAN_COST
Parameters
model_id
ID number of the semantic technology model.
Usage Notes
The model_id value must match a value in the MODEL_ID column in the SEM_MODEL$
view, which is described in Metadata for Models.
Examples
The following example returns the model ID number for the model with the ID value of 1. This
example is an excerpt from Example 1-123 in Example: Journal Article Information.)
SQL> SELECT SEM_APIS.GET_MODEL_NAME(1) AS model_name FROM DUAL;
MODEL_NAME
--------------------------------------------------------------------------------
ARTICLES
15.76 SEM_APIS.GET_PLAN_COST
Format
SEM_APIS.GET_PLAN_COST(
query IN CLOB
) RETURN NUMBER;
Description
Gets the cost of the execution plan for the query.
Parameters
query
The input query string.
Usage Notes
Examples
The following example gets the execution plan cost of the query.
15-97
Chapter 15
SEM_APIS.GET_SQL
15.77 SEM_APIS.GET_SQL
Format
SEM_APIS.GET_SQL(
sparql_query IN CLOB,
models IN RDF_MODELS DEFAULT NULL,
rulebases IN RDF_RULEBASES DEFAULT NULL,
aliases IN RDF_ALIASES DEFAULT NULL,
index_status IN VARCHAR2 DEFAULT NULL,
options IN VARCHAR2 DEFAULT NULL
graphs IN RDF_GRAPHS DEFAULT NULL,
named_graphs IN RDF_GRAPHS DEFAULT NULL,
network_owner IN VARCHAR2 DEFAULT NULL,
network_name IN VARCHAR2 DEFAULT NULL) RETURN CLOB;
Description
Translates a SPARQL query into a SQL query string that can be executed by an
application program.
Parameters
sparql_query
A string literal with one or more triple patterns, usually containing variables.
models
The model or models to use.
rulebases
One or more rulebases whose rules are to be applied to the query.
aliases
One or more namespaces to be used for expansion of qualified names in the query
pattern.
index_status
The status of the relevant entailment for this query.
options
Options that can affect the results of queries.
graphs
The set of named graphs from which to construct the default graph for the query.
named_graphs
The set of named graphs that can be matched by a GRAPH clause.
network_owner
Owner of the semantic network. (See Table 1-1.)
network_name
Name of the semantic network. (See Table 1-1.)
15-98
Chapter 15
SEM_APIS.GET_TRIPLE_ID
Usage Notes
Before using this procedure, ensure you understand the material in Using the
SEM_APIS.GET_SQL Function and SEM_SQL SQL Macro to Query Semantic Data.
For information about semantic network types and options, see Semantic Networks.
Examples
The following example translates a SPARQL query into a SQL query string.
15.78 SEM_APIS.GET_TRIPLE_ID
Format
SEM_APIS.GET_TRIPLE_ID(
model_id IN NUMBER,
subject IN VARCHAR2,
property IN VARCHAR2,
object IN VARCHAR2
) RETURN VARCHAR2;
or
SEM_APIS.GET_TRIPLE_ID(
model_name IN VARCHAR2,
subject IN VARCHAR2,
property IN VARCHAR2,
object IN VARCHAR2
) RETURN VARCHAR2;
Description
Returns the ID of a triple in the specified semantic technology model, or a null value if the
triple does not exist.
Parameters
model_id
ID number of the semantic technology model. Must match a value in the MODEL_ID column
of the SEM_MODEL$ view, which is described in Metadata for Models.
model_name
Name of the semantic technology model. Must match a value in the MODEL_NAME column
of the SEM_MODEL$ view, which is described in Metadata for Models.
subject
Subject. Must match a value in the VALUE_NAME column of the RDF_VALUE$ table, which
is described in Statements.
15-99
Chapter 15
SEM_APIS.GETV$DATETIMETZVAL
property
Property. Must match a value in the VALUE_NAME column of the RDF_VALUE$
table, which is described in Statements.
object
Object. Must match a value in the VALUE_NAME column of the RDF_VALUE$ table,
which is described in Statements.
Usage Notes
This function has two formats, enabling you to specify the semantic technology model
by its model number or its name.
Examples
The following example returns the ID number of a triple. (This example is an excerpt
from Example 1-123 in Example: Journal Article Information.)
SELECT SEM_APIS.GET_TRIPLE_ID(
'articles',
'http://nature.example.com/Article2',
'http://purl.org/dc/terms/references',
'http://nature.example.com/Article3') AS RDF_triple_id FROM DUAL;
RDF_TRIPLE_ID
--------------------------------------------------------------------------------
2_9F2BFF05DA0672E_90D25A8B08C653A_46854582F25E8AC5
15.79 SEM_APIS.GETV$DATETIMETZVAL
Format
SEM_APIS.GETV$DATETIMETZVAL(
value_type IN VARCHAR2,
vname_prefix IN VARCHAR2,
vname_suffix IN VARCHAR2,
literal_type IN VARCHAR2,
language_type IN VARCHAR2,
) RETURN NUMBER;
Description
Returns a TIMESTAMP WITH TIME ZONE value for xsd:dateTime typed literals, and
returns a null value for all other RDF terms. Greenwich Mean Time is used as the
default time zone for xsd:dateTime values without time zones.
Parameters
value_type
Type of the RDF term.
vname_prefix
Prefix value of the RDF term.
vname_suffix
Suffix value of the RDF term.
15-100
Chapter 15
SEM_APIS.GETV$DATETZVAL
literal_type
Literal type of the RDF term.
language_type
Language type of the RDF term.
Usage Notes
For better performance, consider creating a function-based index on this function. For more
information, see Function-Based Indexes for FILTER Constructs Involving Typed Literals.
Examples
The following example returns TIMESTAMP WITH TIME ZONE values for all xsd:dateTime
literals in the RDF_VALUE$ table:
SELECT SEM_APIS.GETV$DATETIMETZVAL(value_type, vname_prefix, vname_suffix,
literal_type, language_type)
FROM RDF_VALUE$;
15.80 SEM_APIS.GETV$DATETZVAL
Format
SEM_APIS.GETV$DATETZVAL(
value_type IN VARCHAR2,
vname_prefix IN VARCHAR2,
vname_suffix IN VARCHAR2,
literal_type IN VARCHAR2,
language_type IN VARCHAR2,
) RETURN TIMESTAMP WITH TIME ZONE;
Description
Returns a TIMESTAMP WITH TIME ZONE value for xsd:date typed literals, and returns a null
value for all other RDF terms. Greenwich Mean Time is used as the default time zone for
xsd:date values without time zones.
Parameters
value_type
Type of the RDF term.
vname_prefix
Prefix value of the RDF term.
vname_suffix
Suffix value of the RDF term.
literal_type
Literal type of the RDF term.
language_type
Language type of the RDF term.
15-101
Chapter 15
SEM_APIS.GETV$GEOMETRYVAL
Usage Notes
For better performance, consider creating a function-based index on this function. For
more information, see Function-Based Indexes for FILTER Constructs Involving Typed
Literals.
Examples
The following example returns TIMESTAMP WITH TIME ZONE values for all xsd:date
literals in the RDF_VALUE$ table:
SELECT SEM_APIS.GETV$DATETZVAL(value_type, vname_prefix, vname_suffix,
literal_type, language_type)
FROM RDF_VALUE$;
15.81 SEM_APIS.GETV$GEOMETRYVAL
Format
SEM_APIS.GETV$GEOMETRYVAL(
value_type IN VARCHAR2,
vname_prefix IN VARCHAR2,
vname_suffix IN VARCHAR2,
literal_type IN VARCHAR2,
language_type IN VARCHAR2,
long_value IN CLOB,
srid IN NUMBER,
) RETURN SDO_GEOMETRY;
Description
Returns an SDO_GEOMETRY object in the spatial reference system identified by an
input SRID for ogc:wktLiteral or ogc:gmlLiteral typed literals, and returns a null value
for all other RDF terms.
Parameters
value_type
Type of the RDF term.
vname_prefix
Prefix value of the RDF term.
vname_suffix
Suffix value of the RDF term.
literal_type
Literal type of the RDF term.
language_type
Language type of the RDF term.
long_value
CLOB value for long literals.
15-102
Chapter 15
SEM_APIS.GETV$NUMERICVAL
srid
Target coordinate system (spatial reference system) identifier for the SDO_GEOMETRY
object to be returned.
Usage Notes
ogc:wktLiteral and ogc:gmlLiteral values encode spatial reference system information in the
literal value itself (referred to as the source SRID).
If the srid parameter value (the target SRID) is different from the source SRID, the newly
created SDO_GEOMETRY object is transformed to the target SRID before it is returned.
This operation can be expensive in terms of performance.
For information about the SDO_GEOMETRY type (including SRID values), see Oracle
Spatial Developer's Guide.
Examples
The following example returns SDO_GEOMETRY values in the WGS84 (Longitude, Latitude)
spatial reference system (SRID 8307) for all geometry literals in the RDF_VALUE$ table:
SELECT SEM_APIS.GETV$GEOMETRYVAL(value_type, vname_prefix, vname_suffix,
literal_type, language_type, long_value, 8307)
FROM RDF_VALUE$;
15.82 SEM_APIS.GETV$NUMERICVAL
Format
SEM_APIS.GETV$NUMERICVAL(
value_type IN VARCHAR2,
vname_prefix IN VARCHAR2,
vname_suffix IN VARCHAR2,
literal_type IN VARCHAR2,
language_type IN VARCHAR2,
) RETURN NUMBER;
Description
Returns a numeric value for XML Schema numeric typed literals, and returns a null value for
all other RDF terms.
Parameters
value_type
Type of the RDF term.
vname_prefix
Prefix value of the RDF term.
vname_suffix
Suffix value of the RDF term.
literal_type
Literal type of the RDF term.
15-103
Chapter 15
SEM_APIS.GETV$STRINGVAL
language_type
Language type of the RDF term.
Usage Notes
For better performance, consider creating a function-based index on this function. For
more information, see Function-Based Indexes for FILTER Constructs Involving Typed
Literals.
Examples
The following example returns numeric values for all numeric literals in the
RDF_VALUE$ table:
SELECT SEM_APIS.GETV$NUMERICVAL(value_type, vname_prefix, vname_suffix,
literal_type, language_type)
FROM RDF_VALUE$;
15.83 SEM_APIS.GETV$STRINGVAL
Format
SEM_APIS.GETV$STRINGVAL(
value_type IN VARCHAR2,
vname_prefix IN VARCHAR2,
vname_suffix IN VARCHAR2,
literal_type IN VARCHAR2,
language_type IN VARCHAR2,
) RETURN TIMESTAMP WITH TIME ZONE;
Description
Returns a VARCHAR2 string of the lexical form of plain literals and xsd:string typed
literals, and returns a null value for all other RDF terms. CHR(0) is returned for empty
literals.
Parameters
value_type
Type of the RDF term.
vname_prefix
Prefix value of the RDF term.
vname_suffix
Suffix value of the RDF term.
literal_type
Literal type of the RDF term.
language_type
Language type of the RDF term.
Usage Notes
For better performance, consider creating a function-based index on this function. For
more information, see Function-Based Indexes for FILTER Constructs Involving Typed
Literals.
15-104
Chapter 15
SEM_APIS.GETV$TIMETZVAL
Examples
The following example returns lexical values for all plain literals and xsd:string literals in the
RDF_VALUE$ table:
SELECT SEM_APIS.GETV$STRINGVAL(value_type, vname_prefix, vname_suffix,
literal_type, language_type)
FROM RDF_VALUE$;
15.84 SEM_APIS.GETV$TIMETZVAL
Format
SEM_APIS.GETV$TIMETZVAL(
value_type IN VARCHAR2,
vname_prefix IN VARCHAR2,
vname_suffix IN VARCHAR2,
literal_type IN VARCHAR2,
language_type IN VARCHAR2,
) RETURN TIMESTAMP WITH TIME ZONE;
Description
Returns a TIMESTAMP WITH TIME ZONE value for xsd:time typed literals, and returns a null
value for all other RDF terms. Greenwich Mean Time is used as the default time zone for
xsd:time values without time zones. 2009-06-26 is used as the default date in all the
generated TIMESTAMP WITH TIME ZONE values.
Parameters
value_type
Type of the RDF term.
vname_prefix
Prefix value of the RDF term.
vname_suffix
Suffix value of the RDF term.
literal_type
Literal type of the RDF term.
language_type
Language type of the RDF term.
Usage Notes
For better performance, consider creating a function-based index on this function. For more
information, see Function-Based Indexes for FILTER Constructs Involving Typed Literals.
Because xsd:time values include only a time but not a date, the returned TIMESTAMP WITH
TIME ZONE values (which include a date component) have 2009-06-26 added as the date.
This is done so that the returned values can be indexed internally, and so that the date is the
same for all of them.
15-105
Chapter 15
SEM_APIS.GRANT_MODEL_ACCESS_PRIV
Examples
The following example returns TIMESTAMP WITH TIME ZONE values (using the
default 2009-06-26 for the date) for all xsd:time literals in the RDF_VALUE$ table. (
SELECT SEM_APIS.GETV$DATETIMETZVAL(value_type, vname_prefix, vname_suffix,
literal_type, language_type)
FROM RDF_VALUE$;
15.85 SEM_APIS.GRANT_MODEL_ACCESS_PRIV
Format
SEM_APIS.GRANT_MODEL_ACCESS_PRIV(
model_name IN VARCHAR2,
user_name IN VARCHAR2,
privilege IN VARCHAR2,
user_view IN VARCHAR2 DEFAULT NULL,
options IN VARCHAR2 DEFAULT NULL,
network_owner IN VARCHAR2 DEFAULT NULL,
network_name IN VARCHAR2 DEFAULT NULL);
Description
Grants access privilege on a model or entailment.
Parameters
model_name
Name of the model.
user_name
Database user that is recipient of this privilege.
privilege
Specifies the type of privilege that is granted. Currently allowed values include the
following:
• QUERY: Query the model using SPARQL
• SELECT, READ: Retrieve model content using SQL. For schema-private network,
the source for the content is the RDFT_<model> view in the network owner's
schema or the view name, if any, specified for the user_view parameter. For
MDSYS-owned network, the source for the content is the application table.
• INSERT, UPDATE, DELETE: Perform SPARQL Update (DML) operations on the
model or SQL DML operations. For SQL DML, the target object is different
depending upon the type of network. For schema-private network, it is the
RDFT_<model> view in the network owner's schema and for MDSYS-owned
network, it is the application table.
15-106
Chapter 15
SEM_APIS.GRANT_MODEL_ACCESS_PRIVS
Note:
QUERY is the only valid choice if the model is not a regular model (that is, not
created using sem_apis.create_sem_model).
user_view
Applicable to schema-private network only. If a view was created on the RDFT_<model> view
at model creation time using sem_apis.create_sem_model or later, privilege is granted on
that view.
options
If user specifies the word ENTAILMENT as part of the string value, then the specified
model_name is taken as the name of an entailment (rules index). (Additional words or phrases
may be allowed in future.)
network_owner
Owner of the semantic network. (See Table 1-1.)
network_name
Name of the semantic network. (See Table 1-1.)
Usage Notes
The recipient must already have query-only or full access to the semantic network (which
guarantees access to dictionary tables, but not individual models). This operation grants
access to the specified model.
Examples
The following example grants privilege to database user USER1 to use SPARQL query against
a semantic technology model named articles in the schema-private network NET1 owned by
database user RDFUSER. (This example refers to the model described in Example 1-123.)
EXECUTE SEM_APIS.GRANT_MODEL_ACCESS_PRIV('articles', 'USER1', 'QUERY',
network_owner=>'RDFUSER', network_name=>'NET1');
15.86 SEM_APIS.GRANT_MODEL_ACCESS_PRIVS
Format
SEM_APIS.GRANT_MODEL_ACCESS_PRIVS(
model_name IN VARCHAR2,
user_name IN VARCHAR2,
priv_list IN SYS.ODCIVARCHAR2LIST,
user_view IN VARCHAR2 DEFAULT NULL,
options IN VARCHAR2 DEFAULT NULL,
network_owner IN VARCHAR2 DEFAULT NULL,
network_name IN VARCHAR2 DEFAULT NULL);
Description
Grants access privileges on a model or entailment.
15-107
Chapter 15
SEM_APIS.GRANT_MODEL_ACCESS_PRIVS
Parameters
model_name
Name of the model.
user_name
Database user that is recipient of this privilege.
priv_list
Specifies the list of privileges that are granted. Currently allowed values include the
following:
• QUERY: Query the model using SPARQL
• SELECT, READ: Retrieve model content using SQL. For schema-private network,
the source for the content is the RDFT_<model> view in the network owner's
schema or the view name, if any, specified for the user_view parameter. For
MDSYS-owned network, the source for the content is the application table.
• INSERT, UPDATE, DELETE: Perform SPARQL Update (DML) operations on the
model or SQL DML operations. For SQL DML, the target object is different
depending upon the type of network. For schema-private network, it is the
RDFT_<model> view in the network owner's schema and for MDSYS-owned
network, it is the application table.
Note:
QUERY is the only valid choice if the model is not a regular model (that is, not
created using sem_apis.create_sem_model).
user_view
Applicable to schema-private network only. If a view was created on the RDFT_<model>
view at model creation time using sem_apis.create_sem_model or later, privileges are
granted on that view.
options
If user specifies the word ENTAILMENT as part of the string value, then the specified
model_name is taken as the name of an entailment (rules index).(Additional words or
phrases may be allowed in future.)
network_owner
Owner of the semantic network. (See Table 1-1.)
network_name
Name of the semantic network. (See Table 1-1.)
Usage Notes
The recipient must already have query-only or full access to the semantic network
(which guarantees access to dictionary tables, but not individual models). This
operation grants access to the specified model.
15-108
Chapter 15
SEM_APIS.GRANT_NETWORK_ACCESS_PRIVS
Examples
The following example grants privileges to perform DML operations against a semantic
technology model named articles in the schema-private network NET1 owned by database
user RDFUSER. (This example refers to the model described in Example 1-123.)
EXECUTE SEM_APIS.GRANT_MODEL_ACCESS_PRIVS('articles', 'USER1',
sys.odcivarchar2list('INSERT','UPDATE','DELETE'), network_owner=>'RDFUSER',
network_name=>'NET1');
15.87 SEM_APIS.GRANT_NETWORK_ACCESS_PRIVS
Format
SEM_APIS.GRANT_NETWORK_ACCESS_PRIVS(
network_owner IN VARCHAR2,
network_name IN VARCHAR2,
network_user IN VARCHAR2,
options IN VARCHAR2 default NULL);
Description
Grants query-only or full access privileges to a database user other than the owner of a
schema-private semantic network.
Parameters
network_owner
Owner of the network. (Cannot be MDSYS.)
network_name
Name of the network. (Must be a schema-private network.)
network_user
Database user (other than the network owner) to which to grant access privileges to the
network.
options
String specifying options for access using the form OPTION_NAME=option_value. By
default, full access privileges are given; but to give query-only access, specify QUERY_ONLY=T
for the option value.
Usage Notes
You must have DBA privileges or be the owner of the specified network to call this procedure.
For information about semantic network types and options, see Semantic Networks.
Examples
The following example grants full access on the mynet1 network owned by scott to rdfuser1.
EXECUTE SEM_APIS.GRANT_NETWORK_ACCESS_PRIVS('scott','mynet1','rdfuser1');
The following example grants query-only access on the mynet1 network owned by scott to
rdfuser2.
15-109
Chapter 15
SEM_APIS.GRANT_NETWORK_SHARING_PRIVS
EXECUTE SEM_APIS.GRANT_NETWORK_ACCESS_PRIVS('scott','mynet1','rdfuser2',
options=>' QUERY_ONLY=T ');
15.88 SEM_APIS.GRANT_NETWORK_SHARING_PRIVS
Format
SEM_APIS.GRANT_NETWORK_SHARING_PRIVS(
network_owner IN VARCHAR2,
options IN VARCHAR2 default NULL);
Description
Grants to a database user the privileges required for sharing, with other database
users, any schema-private networks owned (currently or in the future) by the database
user.
Parameters
network_owner
Owner of the semantic network. (See Table 1-1.)
options
(Reserved for future use)
Usage Notes
You must have DBA privileges to call this procedure.
For information about semantic network types and options, see Semantic Networks.
Examples
The following example grants to database user scott the privileges for sharing any
schema-private networks that this user owns or will own.
EXECUTE SEM_APIS.GRANT_NETWORK_SHARING_PRIVS('scott');
15.89 SEM_APIS.IMPORT_ENTAILMENT_STATS
Format
SEM_APIS.IMPORT_ENTAILMENT_STATS (
entailment_name IN VARCHAR2,
stattab IN VARCHAR2,
statid IN VARCHAR2 DEFAULT NULL,
cascade IN BOOLEAN DEFAULT TRUE,
statown IN VARCHAR2 DEFAULT NULL,
no_invalidate IN BOOLEAN DEFAULT FALSE,
force IN BOOLEAN DEFAULT FALSE,
stat_category IN VARCHAR2 DEFAULT 'OBJECT_STATS',
network_owner IN VARCHAR2 DEFAULT NULL,
network_name IN VARCHAR2 DEFAULT NULL);
Description
Retrieves statistics for an entailment from a user statistics table and stores them in the
dictionary.
15-110
Chapter 15
SEM_APIS.IMPORT_MODEL_STATS
Parameters
entailment_name
Name of the entailment.
(other parameters)
See the parameter explanations for the DBMS_STATS.IMPORT_TABLE_STATS procedure
in Oracle Database PL/SQL Packages and Types Reference, although force here applies to
entailment statistics.
Specifying cascade also exports all index statistics associated with the model.
network_owner
Owner of the semantic network. (See Table 1-1.)
network_name
Name of the semantic network. (See Table 1-1.)
Usage Notes
See the information about the DBMS_STATS package inOracle Database PL/SQL Packages
and Types Reference.
See also Managing Statistics for Semantic Models and the Semantic Network.
For information about semantic network types and options, see Semantic Networks.
Examples
The following example imports statistics for an entailment named OWLTST_IDX from a table
named STAT_TABLE.
EXECUTE SEM_APIS.IMPORT_ENTAILMENT_STATS('owltst_idx', 'stat_table');
15.90 SEM_APIS.IMPORT_MODEL_STATS
Format
SEM_APIS.IMPORT_MODEL_STATS (
model_name IN VARCHAR2,
stattab IN VARCHAR2,
statid IN VARCHAR2 DEFAULT NULL,
cascade IN BOOLEAN DEFAULT TRUE,
statown IN VARCHAR2 DEFAULT NULL,
no_invalidate IN BOOLEAN DEFAULT FALSE,
force IN BOOLEAN DEFAULT FALSE,
stat_category IN VARCHAR2 DEFAULT 'OBJECT_STATS,
network_owner IN VARCHAR2 DEFAULT NULL,
network_name IN VARCHAR2 DEFAULT NULL);
Description
Retrieves statistics for a specified model from a user statistics table and stores them in the
dictionary.
15-111
Chapter 15
SEM_APIS.IS_TRIPLE
Parameters
model_name
Name of the entailment.
(other parameters)
See the parameter explanations for the DBMS_STATS.IMPORT_TABLE_STATS
procedure in Oracle Database PL/SQL Packages and Types Reference.
Specifying cascade also imports all index statistics associated with the model.
network_owner
Owner of the semantic network. (See Table 1-1.)
network_name
Name of the semantic network. (See Table 1-1.)
Usage Notes
See the information about the DBMS_STATS package inOracle Database PL/SQL
Packages and Types Reference.
See also Managing Statistics for Semantic Models and the Semantic Network.
For information about semantic network types and options, see Semantic Networks.
Examples
The following example imports statistics for a model named FAMILY from a table
named STAT_TABLE, and stores them in the dictionary.
EXECUTE SEM_APIS.IMOPRT_MODEL_STATS('family', 'stat_table');
15.91 SEM_APIS.IS_TRIPLE
Format
SEM_APIS.IS_TRIPLE(
model_id IN NUMBER,
subject IN VARCHAR2,
property IN VARCHAR2,
object IN VARCHAR2) RETURN VARCHAR2;
or
SEM_APIS.IS_TRIPLE(
model_name IN VARCHAR2,
subject IN VARCHAR2,
property IN VARCHAR2,
object IN VARCHAR2) RETURN VARCHAR2;
Description
Checks if a statement is an existing triple in the specified model in the database.
15-112
Chapter 15
SEM_APIS.LOAD_INTO_STAGING_TABLE
Parameters
model_id
ID number of the semantic technology model. Must match a value in the MODEL_ID column
of the SEM_MODEL$ view, which is described in Metadata for Models.
model_name
Name of the semantic technology model. Must match a value in the MODEL_NAME column
of the SEM_MODEL$ view, which is described in Metadata for Models.
subject
Subject. Must match a value in the VALUE_NAME column of the RDF_VALUE$ table, which
is described in Statements.
property
Property. Must match a value in the VALUE_NAME column of the RDF_VALUE$ table, which
is described in Statements.
object
Object. Must match a value in the VALUE_NAME column of the RDF_VALUE$ table, which
is described in Statements.
Usage Notes
This function returns the string value FALSE, TRUE, or TRUE (EXACT):
• FALSE means that the statement is not a triple in the specified model the database.
• TRUE means that the statement matches the value of a triple or is the canonical
representation of the value of a triple in the specified model the database.
• TRUE (EXACT) means that the specified subject, property, and object values have
exact matches in a triple in the specified model in the database.
Examples
The following example checks if a statement is a triple in the database. In this case, there is
an exact match. (This example is an excerpt from Example 1-123 in Example: Journal Article
Information.)
SELECT SEM_APIS.IS_TRIPLE(
'articles',
'http://nature.example.com/Article2',
'http://purl.org/dc/terms/references',
'http://nature.example.com/Article3') AS is_triple FROM DUAL;
IS_TRIPLE
--------------------------------------------------------------------------------
TRUE (EXACT)
15.92 SEM_APIS.LOAD_INTO_STAGING_TABLE
Format
SEM_APIS.LOAD_INTO_STAGING_TABLE(
stagong_table IN VARCHAR2,
source_table IN VARCHAR2,
input_format IN VARCHAR2 DEFAULT NULL,
15-113
Chapter 15
SEM_APIS.LOOKUP_ENTAILMENT
Description
Loads data into a staging table from an external table mapped to an N-Triple or N-
Quad format input file.
Parameters
staging_table
Name of the staging table.
source_table
Name of the source external table.
input_format
Format of the input file mapped by the source external table: N-TRIPLE or N-QUAD
parallel
Degree of parallelism to use during the load.
staging_table_owner
Owner for the staging table being created. If not specified, the invoker is assumed to
be the owner.
source_table_owner
Owner for the source table. If not specified, the invoker is assumed to be the owner.
flags
(Reserved for future use)
Usage Notes
For more information and an example, see Loading N-Quad Format Data into a
Staging Table Using an External Table.
Examples
The following example loads the staging table. (This example is an excerpt from
Example 1-102 in Loading N-Quad Format Data into a Staging Table Using an
External Table.)
BEGIN
sem_apis.load_into_staging_table(
staging_table => 'STAGE_TABLE'
,source_table => 'stage_table_source'
,input_format => 'N-QUAD');
END;
15.93 SEM_APIS.LOOKUP_ENTAILMENT
Format
SEM_APIS.LOOKUP_ENTAILMENT (
models IN SEM_MODELS,
15-114
Chapter 15
SEM_APIS.MERGE_MODELS
rulebases IN SEM_RULEBASES
) RETURN VARCHAR2;
Description
Returns the name of the entailment (rules index) based on the specified models and
rulebases.
Parameters
models
One or more model names. Its data type is SEM_MODELS, which has the following
definition: TABLE OF VARCHAR2(25)
rulebases
One or more rulebase names. Its data type is SEM_RULEBASES, which has the following
definition: TABLE OF VARCHAR2(25)Rules and rulebases are explained in Inferencing: Rules
and Rulebases.
Usage Notes
For a rulebase index to be returned, it must be based on all specified models and rulebases.
Examples
The following example finds the entailment that is based on the family model and the RDFS
and family_rb rulebases. (It is an excerpt from Example 1-124 in Example: Family
Information.)
SELECT SEM_APIS.LOOKUP_ENTAILMENT(SEM_MODELS('family'),
SEM_RULEBASES('RDFS','family_rb')) AS lookup_entailment FROM DUAL;
LOOKUP_ENTAILMENT
--------------------------------------------------------------------------------
RDFS_RIX_FAMILY
15.94 SEM_APIS.MERGE_MODELS
Format
SEM_APIS.MERGE_MODELS(
source_model IN VARCHAR2,
destination_model IN VARCHAR2,
rebuild_apptab_index IN BOOLEAN DEFAULT TRUE,
drop_source_model IN BOOLEAN DEFAULT FALSE,
options IN VARCHAR2 DEFAULT NULL,
network_owner IN VARCHAR2 DEFAULT NULL,
network_name IN VARCHAR2 DEFAULT NULL);
Description
Inserts the content from a source model into a destination model, and updates the destination
application table.
15-115
Chapter 15
SEM_APIS.MERGE_MODELS
Parameters
source_model
Name of the source model.
destination_model
Name of the destination model.
rebuild_apptab_index
TRUE causes indexes on the destination application table to be rebuilt after the models
are merged; FALSE does not rebuild any indexes.
drop_source_model
TRUE causes the source model (source_model) to be deleted after the models are
merged; FALSE (the default) does not delete the source model.
options
A comma-delimited string of options that overrides the default behavior of the
procedure. Currently, only the DOP (degree of parallelism) option is supported, to
enable parallel execution of this procedure and to specify the degree of parallelism to
be associated with the operation.
network_owner
Owner of the semantic network. (See Table 1-1.)
network_name
Name of the semantic network. (See Table 1-1.)
Usage Notes
Before you merge any models, if you are using positional parameters, check to be
sure that you are specifying the correct models for the first and second parameters
(source model for the first, destination model for the second). This is especially
important if you plan to specify drop_source_model=TRUE.
If appropriate, make copies of the destination model or both models before performing
the merge. To make a copy of a model, use SEM_APIS.CREATE_SEM_MODEL to
create an empty model with the desired name for the copy, and use
SEM_APIS.MERGE_MODELS to populate the newly created copy as the destination
model.
Some common uses for this procedure include the following:
• If you have read-only access to a model that you want to modify, you can clone
that model into an empty model on which you have full access, and then modify
this latter model.
• If you want to consolidate multiple models, you can use this procedure as often as
necessary to merge the necessary models. Merging all models beforehand and
using only the merged model simplifies entailment and can improve entailment
performance.
On a multi-core or multi-cpu machine, the DOP (degree of parallelism) option can be
beneficial. See Examples for an example that uses the DOP option.
15-116
Chapter 15
SEM_APIS.MIGRATE_DATA_TO_CURRENT
If the source model is large, you may want to update the optimizer statistics on the
destination after the merge operation by calling the SEM_APIS.ANALYZE_MODEL
procedure.
The following considerations apply to the use of this procedure:
• You must be the owner of the destination model and have SELECT privilege on the
source model. If drop_second_model=TRUE, you must also be owner of the source model.
• This procedure is not supported on virtual models (explained in Virtual Models).
• No table constraints are allowed on the destination application table.
For information about semantic network types and options, see Semantic Networks.
Examples
The following example inserts the contents of model M1 into M2.
EXECUTE SEM_APIS.MERGE_MODELS('M1', 'M2');
The following example inserts the contents of model M1 into M2, and it specifies a degree of
parallelism of 4 (up to four parallel threads for execution of the merge operation).
EXECUTE SEM_APIS.MERGE_MODELS('M1', 'M2', null, null, 'DOP=4');
15.95 SEM_APIS.MIGRATE_DATA_TO_CURRENT
Format
SEM_APIS.MIGRATE_DATA_TO_CURRENT(
options IN VARCHAR2 DEFAULT NULL,
network_owner IN VARCHAR2 DEFAULT NULL,
network_name IN VARCHAR2 DEFAULT NULL);
Description
Migrates semantic data from before Oracle Database Release 20 data format to the format
needed for use with RDF in the current Oracle Database release.
Parameters
options
If you specify INS_AS_SEL=T, the migration is performed using a bulk load operation. If you
do not specify that value, then by default update operations are performed. See the Usage
Notes for more information.
network_owner
Owner of the semantic network. (See Table 1-1.)
network_name
Name of the semantic network. (See Table 1-1.)
Usage Notes
You must use this procedure to migrate semantic data created using versions of Oracle
Database earlier than Release 20, as explained in Required Migration of Pre-12.2 Semantic
Data.
15-117
Chapter 15
SEM_APIS.MIGRATE_DATA_TO_STORAGE_V2
This procedure does not perform any operation on semantic data that is already in the
current format.
For schema-private semantic networks, this procedure also updates the definition of
semantic network triggers, views, and PL/SQL packages in the network owner’s
schema.
For the options parameter, if the amount of data to be migrated is small, the default
(not specifying the parameter) probably provides adequate performance. However, for
large amounts of data, specifying INS_AS_SEL=T can improve performance
significantly.
For an MDSYS-owned network, this procedure must be run as a DBA user. For a
schema-private network, this procedure must be run as the network owner.
Examples
The following example migrates Release 19 semantic data in the MDSYS-owned
network to the format for the current Oracle Database version. It performs the
migration using a bulk load operation.
EXECUTE sem_apis.migrate_data_to_current('INS_AS_SEL=T');
15.96 SEM_APIS.MIGRATE_DATA_TO_STORAGE_V2
Format
SEM_APIS.MIGRATE_DATA_TO_STORAGE_V2(
options IN VARCHAR2 DEFAULT NULL,
network_owner IN VARCHAR2 DEFAULT NULL,
network_name IN VARCHAR2 DEFAULT NULL);
Description
Migrates semantic data from escaped storage form to unescaped storage form.
Parameters
options
If you specify PARALLEL=<n>, the migration is performed using the specified degree of
parallelism. If you do not specify this option, then by default no parallel processing is
used.
15-118
Chapter 15
SEM_APIS.MOVE_SEM_NETWORK_DATA
network_owner
Owner of the semantic network. (See Table 1-1.)
network_name
Name of the semantic network. (See Table 1-1.)
Usage Notes
It is strongly recommended that you use unescaped storage form for your semantic network,
because it reduces storage cost and improves query performance, while requiring no
changes to your existing applications.
For an MDSYS-owned network, this procedure must be run as a DBA user. For a schema-
private network, this procedure must be run as the network owner.
After executing this procedure, a row with the following column values should be present in
the network’s RDF_PARAMETER table (described in RDF_PARAMETER Table in Semantic
Networks):
• Namespace: NETWORK
• Attribute: STORAGE_FORM
• Value: UNESC
• Description: Storage form setting for a semantic network.
See also Migrating from Escaped to Unescaped Storage Form.
Examples
The following example migrates the MDSYS semantic network from escaped storage form to
unescaped storage form. A degree of parallelism of 4 is used for the operation.
EXECUTE sem_apis.migrate_data_to_storage_v2(options=>' PARALLEL=4 ');
The following example migrates a schema-private semantic network named NET1 owned by
RDFUSER from escaped storage form to unescaped storage form.
EXECUTE sem_apis.migrate_data_to_storage_v2(network_owner=>'RDFUSER',
network_name=>'NET1');
15.97 SEM_APIS.MOVE_SEM_NETWORK_DATA
Format
SEM_APIS.MOVE_SEM_NETWORK_DATA(
dest_schema IN DBMS_ID,
dest_tbs_name IN DBMS_ID DEFAULT NULL,
degree IN INTEGER DEFAULT NULL,
options IN VARCHAR2 DEFAULT NULL,
network_owner IN VARCHAR2 DEFAULT NULL,
network_name IN VARCHAR2 DEFAULT NULL);
Description
Moves semantic network data from a source semantic network to a destination (staging)
schema.
15-119
Chapter 15
SEM_APIS.PRIVILEGE_ON_APP_TABLES
Parameters
dest_schema
The staging schema to which the semantic network data will be moved.
dest_tbs_name
The tablespace to use for objects created in the destination (staging) schema. If null,
the default tablespace for the destination schema will be used.
degree
Degree of parallelism to use for any SQL insert or index building operations. The
default is no parallel execution.
options
(Reserved for future use.)
network_owner
Owner of the source semantic network for the move operation. (See Table 1-1.)
network_name
Name of the source semantic network for the move operation. (See Table 1-1.)
Usage Notes
You must have DBA privileges to call this procedure.
For more information and examples, see Moving, Restoring, and Appending a
Semantic Network.
For information about semantic network types and options, see Semantic Networks.
Examples
The following example moves a semantic network from the MYNET semantic network
owned by RDFADMIN to the RDFEXPIMPU staging schema>
EXECUTE
sem_apis.move_sem_network_data(dest_schema=>'RDFEXPIMPU',network_owner=>'RDFADMIN
',network_name=>'MYNET');
15.98 SEM_APIS.PRIVILEGE_ON_APP_TABLES
Format
SEM_APIS.PRIVILEGE_ON_APP_TABLES(
command IN VARCHAR2 DEFAULT 'GRANT',
privilege IN VARCHAR2 DEFAULT 'SELECT',
network_owner IN VARCHAR2 DEFAULT NULL,
network_name IN VARCHAR2 DEFAULT NULL);
Description
Grants (or revokes) SELECT or INSERT privilege to (or from) MDSYS on application
tables corresponding to all the RDF models owned by the invoker.
15-120
Chapter 15
SEM_APIS.PURGE_UNUSED_VALUES
Parameters
command
SQL statement, with possible values GRANT (the default) or REVOKE (case insensitive).
privilege
Privilege name, with possible values SELECT (the default) or INSERT (case insensitive).
network_owner
network_name
Usage Notes
For information about semantic network types and options, see Semantic Networks.
Examples
The following example grants SELECT privilege to MDSYS on application tables
corresponding to all the RDF models owned by the invoker.
EXECUTE SEM_APIS.PRIVILEGE_ON_APP_TABLES('grant', 'select');
15.99 SEM_APIS.PURGE_UNUSED_VALUES
Format
SEM_APIS.PURGE_UNUSED_VALUES(
flags IN VARCHAR2 DEFAULT NULL,
network_owner IN VARCHAR2 DEFAULT NULL,
network_name IN VARCHAR2 DEFAULT NULL);
Description
Purges purges invalid geometry literal values from the semantic network.
Parameters
flags
An optional quoted string with one or more of the following keyword specifications:
• MBV_METHOD=SHADOW allows the use of a different value loading strategy that may lead to
faster processing when a large number of values need to be purged.
• PARALLEL=<integer> allows much of the processing to be done in parallel using the
specified integer degree of parallelism to be associated with the operation. If only
PARALLEL is specified without a degree, a default degree will be used.
• PUV_COMPUTE_VIDS_USED allows use of a different strategy that may lead to faster
processing when most of the values are expected to be purged.
15-121
Chapter 15
SEM_APIS.REFRESH_MATERIALIZED_VIEW
network_owner
Owner of the semantic network. (See Table 1-1.)
network_name
Name of the semantic network. (See Table 1-1.)
Usage Notes
Before calling this procedure, you must grant to MDSYS the SELECT privilege on
application tables for all the currently existing RDF models.
For more usage information and an extended example, see Purging Unused Values.
It is recommended that you execute this procedure after using
SEM_APIS.VALIDATE_GEOMETRIES to check that all geometry literals in the
specified model are valid for the provided SRID and tolerance values.
For information about semantic network types and options, see Semantic Networks.
Examples
The following example purges unused values using a degree of parallelism of 4.
EXECUTE SEM_APIS.PURGE_UNUSED_VALUES(flags => 'PARALLEL=4');
15.100 SEM_APIS.REFRESH_MATERIALIZED_VIEW
Format
SEM_APIS.REFRESH_MATERIALIZED_VIEW (
mv_name IN VARCHAR2,
options IN VARCHAR2 DEFAULT NULL,
network_owner IN VARCHAR2 DEFAULT NULL,
network_name IN VARCHAR2 DEFAULT NULL,
);
Description
Refreshes a materialized join view for an RDF graph stored in Oracle Database.
Parameters
mv_name
Name of the materialized view to refresh.
options
(Reserved for future use.)
network_owner
Owner of the semantic network. (See Table 1-1.)
network_name
Name of the semantic network. (See Table 1-1.)
Usage Notes
For more information, see RDF Support for Materialized Join Views.
For information about semantic network types and options, see Semantic Networks.
15-122
Chapter 15
SEM_APIS.REFRESH_SEM_NETWORK_INDEX_INFO
Examples
The following example refreshes the materialized view MVX.
EXECUTE SEM_APIS.REFRESH_MV_BITMAP_INDEX('MVX');
15.101 SEM_APIS.REFRESH_SEM_NETWORK_INDEX_INFO
Format
SEM_APIS.REFRESH_SEM_NETWORK_INDEX_INFO(
options IN VARCHAR2 DEFAULT NULL,
network_owner IN VARCHAR2 DEFAULT NULL,
network_name IN VARCHAR2 DEFAULT NULL);
Description
Refreshes the information about semantic network indexes.
Parameters
options
(Reserved for future use)
network_owner
Owner of the semantic network. (See Table 1-1.)
network_name
Name of the semantic network. (See Table 1-1.)
Usage Notes
This procedure updates the information in the SEM_NETWORK_INDEX_INFO view, which is
described in SEM_NETWORK_INDEX_INFO View.
For information about semantic network types and options, see Semantic Networks.
Examples
The following example refreshes the information about semantic network indexes.
EXECUTE sem_apis.refresh_sem_network_index_info;
15.102 SEM_APIS.REMOVE_DUPLICATES
Format
SEM_APIS.REMOVE_DUPLICATES(
model_name IN VARCHAR2,
threshold IN FLOAT DEFAULT 0.3,
rebuild_apptab_index IN BOOLEAN DEFAULT TRUE,
options IN VARCHAR2 DEFAULT NULL,
network_owner IN VARCHAR2 DEFAULT NULL,
network_name IN VARCHAR2 DEFAULT NULL);
15-123
Chapter 15
SEM_APIS.REMOVE_DUPLICATES
Description
Removes duplicate triples from a model.
Parameters
model_name
Name of the model.
threshold
A value to determine how numerous triples must be in order for the removal operation
to be performed. This procedure removes triples only if the number of triples in the
model exceeds the following formula: (total-triples - total-unique-triples + 0.01) / (total-
unique-triples + 0.01). For the default value of 0.3 and a model containing 1000 total
triples (including duplicates), duplicate triples would be removed only if the number of
duplicates exceeds approximately 230.
The lower the threshold value, the fewer duplicates are needed for the procedure to
remove duplicates; the higher the threshold value, the more duplicates are needed for
the procedure to remove duplicates.
rebuild_apptab_index
TRUE (the default) causes all usable indexes on tables that were affected by this
operation to be rebuilt after the duplicate triples are removed; FALSE does not rebuild
any indexes.
options
(Reserved for future use.)
network_owner
Owner of the semantic network. (See Table 1-1.)
network_name
Name of the semantic network. (See Table 1-1.)
Usage Notes
When duplicate triples are removed, all information in the removed rows is lost,
including information in columns other than the triple column.
This procedure is not supported on virtual models (explained in Virtual Models).
If the model is empty, or if it contains no duplicate triples or not enough duplicate
triples (as computed using the threshold value), this procedure does not perform any
removal operations.
If there are not enough duplicates (as computed using the threshold value) to perform
the operation, an informational message is displayed.
If unusable indexes are involved, be sure that the SKIP_UNUSABLE_INDEXES
system parameter is set to TRUE. Although TRUE is the default value for this parameter,
some production databases may use the value FALSE; therefore, if you need to change
it, enter the following:
SQL> alter session set skip_unusable_indexes=true;
15-124
Chapter 15
SEM_APIS.RENAME_ENTAILMENT
To use this procedure on an application table with one or more user-defined triggers, you
must connect as a DBA user and grant the ALTER ANY TRIGGER privilege to the MDSYS
user, as follows:
SQL> grant alter any trigger to MDSYS;
For information about semantic network types and options, see Semantic Networks.
Examples
The following example removes duplicate triples in the model named family. It accepts the
default threshold value of 0.3 and (by default) rebuilds indexes after the duplicates are
removed.
EXECUTE SEM_APIS.REMOVE_DUPLICATES('family');
15.103 SEM_APIS.RENAME_ENTAILMENT
Format
SEM_APIS.RENAME_ENTAILMENT(
old_name IN VARCHAR2,
new_name IN VARCHAR2,
network_owner IN VARCHAR2 DEFAULT NULL,
network_name IN VARCHAR2 DEFAULT NULL);
Description
Renames an entailment (rules index).
Parameters
old_name
Name of the existing entailment to be renamed.
new_name
New name for the entailment.
network_owner
Owner of the semantic network. (See Table 1-1.)
network_name
Name of the semantic network. (See Table 1-1.)
Usage Notes
For information about semantic network types and options, see Semantic Networks.
Examples
The following example renames a entailment named OWLTST_IDX to MY_OWLTST_IDX.
EXECUTE sem_apis.rename_entailment('owltst_idx', 'my_owltst_idx');
15-125
Chapter 15
SEM_APIS.RENAME_MODEL
15.104 SEM_APIS.RENAME_MODEL
Format
SEM_APIS.RENAME_MODEL(
old_name IN VARCHAR2,
new_name IN VARCHAR2,
network_owner IN VARCHAR2 DEFAULT NULL,
network_name IN VARCHAR2 DEFAULT NULL);
Description
Renames a model.
Parameters
old_name
Name of the existing model to be renamed.
new_name
New name for the model.
network_owner
Owner of the semantic network. (See Table 1-1.)
network_name
Name of the semantic network. (See Table 1-1.)
Usage Notes
The following considerations apply to the use of this procedure:
• You must be the owner of the existing model.
• This procedure is not supported on virtual models (explained in Virtual Models).
Contrast this procedure with SEM_APIS.SWAP_NAMES, which swaps (exchanges)
the names of two existing models.
For information about semantic network types and options, see Semantic Networks.
Examples
The following example renames a model named MODEL1 to MODEL2.
EXECUTE sem_apis.rename_model('model1', 'model2');
15.105 SEM_APIS.RES2VID
Format
SEM_APIS.RES2VID(
vTab IN VARCHAR2,
uri IN VARCHAR2,
lt IN VARCHAR2 DEFAULT NULL,
lang IN VARCHAR2 DEFAULT NULL,
lval IN CLOB DEFAULT NULL,
) RETURN NUMBER;
15-126
Chapter 15
SEM_APIS.RESTORE_SEM_NETWORK_DATA
Description
Returns the VALUE_ID for the canonical version of an RDF term, or NULL if the term does
not exist in the values table.
Parameters
vTab
Values table to query for the VALUE_ID value. (Usually RDF_VALUE$)
uri
Prefix value of the RDF term.
lt
Data type URI of a types literal to look up. Do not include the enclosing angle brackets (‘<’
and ‘>’).
lang
Language tag of a language tagged literal to look up.
lval
The plain literal portion of a long literal to look up.
Usage Notes
For information about the components of an RDF term stored in the RDF_VALUE$ table, see
Semantic Metadata Tables and Views..
See also RDF Integration with Property Graph Data Stored in Oracle Database.
Examples
The following example returns VALUE_ID values for the canonical versions of RDF terms.
Comments before each SQL statement describe the purpose of the statement.
-- Look up the VALUE_ID for the RDF term <http://www.example.com/a>.
SELECT sem_apis.res2vid('RDF_VALUE$','<http://www.example.com/a>') FROM DUAL;
-- Look up the VALUE_ID for the long literal RDF term '"a CLOB literal"'.
SELECT sem_apis.res2vid('RDF_VALUE$',null,lval=>'"a CLOB literal"') FROM DUAL;
15.106 SEM_APIS.RESTORE_SEM_NETWORK_DATA
Format
SEM_APIS.RESTORE_SEM_NETWORK_DATA(
from_schema DBMS_ID,
15-127
Chapter 15
SEM_APIS.RESTORE_SEM_NETWORK_DATA
Description
Restores moved semantic network data from a staging schema back into a source
semantic network.
Parameters
from_schema
The staging schema that contains moved semantic network data to be restored.
degree
Degree of parallelism to use for any SQL insert or index building operations. The
default is no parallel execution.
options
String specifying any options to use during the append operation. Supported options
are:
• PURGE=T – drop all remaining semantic network data in the staging schema
after the append operation completes.
network_owner
Owner of the destination semantic network for the restore operation. (See Table 1-1.)
network_name
Name of the destination semantic network for the restore operation. (See Table 1-1.)
Usage Notes
Partition exchange operations rather than SQL INSERT statements are used to move
most of the data during the append operation, so the staging schema will no longer
contain complete semantic network data after the restore operation is complete.
Moved semantic network data can only be restored into the original source semantic
network from which it was moved.
You must have DBA privileges to call this procedure.
For more information, see Moving, Restoring, and Appending a Semantic Network.
For information about semantic network types and options, see Semantic Networks.
Examples
The following example restores a semantic network from the RDFEXPIMPU staging
schema into the MYNET semantic network owned by RDFADMIN.
EXECUTE
sem_apis.restore_sem_network_data(from_schema=>'RDFEXPIMPU',network_owner=>'RDFAD
MIN',network_name=>'MYNET');
15-128
Chapter 15
SEM_APIS.REVOKE_MODEL_ACCESS_PRIV
15.107 SEM_APIS.REVOKE_MODEL_ACCESS_PRIV
Format
SEM_APIS.REVOKE_MODEL_ACCESS_PRIV(
model_name IN VARCHAR2,
user_name IN VARCHAR2,
privilege IN VARCHAR2,
user_view IN VARCHAR2 DEFAULT NULL,
options IN VARCHAR2 DEFAULT NULL,
network_owner IN VARCHAR2 DEFAULT NULL,
network_name IN VARCHAR2 DEFAULT NULL);
Description
Revokes access privilege on a model or entailment.
Parameters
model_name
Name of the model.
user_name
Database user that is recipient of this privilege.
privilege
Specifies the type of privilege that is granted. Currently allowed values include the following:
• QUERY: Query the model using SPARQL
• SELECT, READ: Retrieve model content using SQL. For schema-private network, the
source for the content is the RDFT_<model> view in the network owner's schema or the
view name, if any, specified for the user_view parameter. For MDSYS-owned network,
the source for the content is the application table.
• INSERT, UPDATE, DELETE: Perform SPARQL Update (DML) operations on the model or
SQL DML operations. For SQL DML, the target object is different depending upon the
type of network. For schema-private network, it is the RDFT_<model> view in the network
owner's schema and for MDSYS-owned network, it is the application table.
Note:
QUERY is the only valid choice if the model is not a regular model (that is, not
created using sem_apis.create_sem_model).
user_view
Applicable to schema-private network only. If a view was created on the RDFT_<model> view
at model creation time using sem_apis.create_sem_model or later, privilege is revoked on
that view.
15-129
Chapter 15
SEM_APIS.REVOKE_MODEL_ACCESS_PRIVS
options
If user specifies the word ENTAILMENT as part of the string value, then the specified
model_name is taken as the name of an entailment (rules index). (Additional words or
phrases may be allowed in future.)
network_owner
Owner of the semantic network. (See Table 1-1.)
network_name
Name of the semantic network. (See Table 1-1.)
Usage Notes
This does not affect the recipient's query-only or full access to the semantic network
(which guarantees access to dictionary tables, but not individual models). This
operation revokes access to the specified model only.
Examples
The following example revokes privilege from database user USER1 for use of SPARQL
query against a semantic technology model named articles in the schema-private
network NET1 owned by database user RDFUSER. (This example refers to the model
described in Example 1-123.)
EXECUTE SEM_APIS.REVOKE_MODEL_ACCESS_PRIV('articles', 'USER1', 'QUERY',
network_owner=>'RDFUSER', network_name=>'NET1');
15.108 SEM_APIS.REVOKE_MODEL_ACCESS_PRIVS
Format
SEM_APIS.REVOKE_MODEL_ACCESS_PRIVS(
model_name IN VARCHAR2,
user_name IN VARCHAR2,
priv_list IN VARCHAR2,
user_view IN VARCHAR2 DEFAULT NULL,
options IN VARCHAR2 DEFAULT NULL,
network_owner IN VARCHAR2 DEFAULT NULL,
network_name IN VARCHAR2 DEFAULT NULL);
Description
Revokes access privileges on a model or entailment.
Parameters
model_name
Name of the model.
user_name
Database user that is recipient of this privilege.
privilege
Specifies the type of privilege that is granted. Currently allowed values include the
following:
15-130
Chapter 15
SEM_APIS.REVOKE_MODEL_ACCESS_PRIVS
Note:
QUERY is the only valid choice if the model is not a regular model (that is, not
created using sem_apis.create_sem_model).
user_view
Applicable to schema-private network only. If a view was created on the RDFT_<model> view
at model creation time using sem_apis.create_sem_model or later, privileges are revoked on
that view.
options
If user specifies the word ENTAILMENT as part of the string value, then the specified
model_name is taken as the name of an entailment (rules index). (Additional words or phrases
may be allowed in future.)
network_owner
Owner of the semantic network. (See Table 1-1.)
network_name
Name of the semantic network. (See Table 1-1.)
Usage Notes
This does not affect the recipient's query-only or full access to the semantic network (which
guarantees access to dictionary tables, but not individual models). This operation revokes
access to the specified model only.
Examples
The following example revokes privilege from database user USER1 for performing DML
operations against a semantic technology model named articles in the schema-private
network NET1 owned by database user RDFUSER. (This example refers to the model described
in Example 1-123.)
EXECUTE SEM_APIS.REVOKE_MODEL_ACCESS_PRIVS('articles', 'USER1',
sys.odcivarchar2list('INSERT','UPDATE','DELETE'), network_owner=>'RDFUSER',
network_name=>'NET1');
15-131
Chapter 15
SEM_APIS.REVOKE_NETWORK_ACCESS_PRIVS
15.109 SEM_APIS.REVOKE_NETWORK_ACCESS_PRIVS
Format
SEM_APIS.REVOKE_NETWORK_ACCESS_PRIVS(
network_owner IN VARCHAR2,
network_name IN VARCHAR2,
network_user IN VARCHAR2,
options IN VARCHAR2 default NULL);
Description
Revokes access privileges from a database user other than the owner of a schema-
private semantic network.
Parameters
network_owner
Owner of the network. (Cannot be MDSYS.)
network_name
Name of the network. (Must be a schema-private network.)
network_user
Database user (other than the network owner) from which to revoke access privileges
to the network.
options
String specifying options for access using the form OPTION_NAME=option_value.
If CASCADE=T is specified, any RDF objects owned by the database user will be
dropped as part of this operation.
Usage Notes
You must have DBA privileges or be the owner of the specified network to call this
procedure.
If the database user (network_user) owns any RDF objects in the schema-private
network and if CASCADE=T is not specified, an error will be raised.
For information about semantic network types and options, see Semantic Networks.
Examples
The following example revokes full access on the mynet1 network owned by scott
from rdfuser1.
EXECUTE SEM_APIS.REVOKE_NETWORK_ACCESS_PRIVS('scott','mynet1','rdfuser1');
15-132
Chapter 15
SEM_APIS.REVOKE_NETWORK_SHARING_PRIVS
15.110 SEM_APIS.REVOKE_NETWORK_SHARING_PRIVS
Format
SEM_APIS.REVOKE_NETWORK_SHARING_PRIVS(
network_owner IN VARCHAR2,
options IN VARCHAR2 default NULL);
Description
Revokes from a database user the privileges required for sharing, with other database users,
any schema-private networks owned (currently or in the future) by the database user
Parameters
network_owner
Owner of the network. (Cannot be MDSYS.)
options
(Reserved for future use)
Usage Notes
You must have DBA privileges to call this procedure.
If the database user owns at least one schema-private network that has sharing enabled, an
exception will be raised. (The user must first disable sharing of any such networks.)
For information about semantic network types and options, see Semantic Networks.
Examples
The following example revokes from database user scott the privileges for sharing any
schema-private networks that this user owns or will own.
EXECUTE SEM_APIS.REVOKE_NETWORK_SHARING_PRIVS('scott');
15.111 SEM_APIS.SEM_SQL_COMPILE
Format
SEM_APIS.SEM_SQL_COMPILE;
Description
Compiles SQL inserted into RDF$S2S_SQL$ table to be used by SEM_SQL SQL Macro.
15-133
Chapter 15
SEM_APIS.SET_ENTAILMENT_STATS
Parameters
Usage Notes
Examples
The following example compiles SQL inserted into RDF$S2S_SQL$ table.
EXECUTE SEM_APIS.SEM_SQL_COMPILE;
15.112 SEM_APIS.SET_ENTAILMENT_STATS
Format
SEM_APIS.SET_ENTAILMENT_STATS (
entailment_name IN VARCHAR2,
numrows IN NUMBER DEFAULT NULL,
numblks IN NUMBER DEFAULT NULL,
avgrlen IN NUMBER DEFAULT NULL,
flags IN NUMBER DEFAULT NULL,
no_invalidate IN BOOLEAN DEFAULT DBMS_STATS.AUTO_INVALIDATE,
cachedblk IN NUMBER DEFAULT NULL,
cachehit IN NUMBER DEFAULT NULL,
force IN BOOLEAN DEFAULT FALSE,
network_owner IN VARCHAR2 DEFAULT NULL,
network_name IN VARCHAR2 DEFAULT NULL);
Description
Sets statistics for a specified entailment.
Parameters
entailment_name
Name of the entailment.
(other parameters)
See the parameter explanations for the DBMS_STATS.SET_TABLE_STATS
procedure in Oracle Database PL/SQL Packages and Types Reference, although
force here applies to entailment statistics.
network_owner
Owner of the semantic network. (See Table 1-1.)
network_name
Name of the semantic network. (See Table 1-1.)
Usage Notes
See the information about the DBMS_STATS package inOracle Database PL/SQL
Packages and Types Reference.
15-134
Chapter 15
SEM_APIS.SET_MODEL_STATS
See also Managing Statistics for Semantic Models and the Semantic Network.
For information about semantic network types and options, see Semantic Networks.
Examples
The following example sets statistics for an entailment named OWLTST_IDX.
EXECUTE SEM_APIS.SET_ENTAILMENT_STATS('owltst_idx', numrows => 100);
15.113 SEM_APIS.SET_MODEL_STATS
Format
SEM_APIS.SET_MODEL_STATS (
model_name IN VARCHAR2,
numrows IN NUMBER DEFAULT NULL,
numblks IN NUMBER DEFAULT NULL,
avgrlen IN NUMBER DEFAULT NULL,
flags IN NUMBER DEFAULT NULL,
no_invalidate IN BOOLEAN DEFAULT DBMS_STATS.AUTO_INVALIDATE,
cachedblk IN NUMBER DEFAULT NULL,
cachehit IN NUMBER DEFAULT NULL,
force IN BOOLEAN DEFAULT FALSE,
network_owner IN VARCHAR2 DEFAULT NULL,
network_name IN VARCHAR2 DEFAULT NULL);
Description
Sets statistics for a specified model.
Parameters
model_name
Name of the model.
(other parameters)
See the parameter explanations for the DBMS_STATS.DELETE_TABLE_STATS procedure
in Oracle Database PL/SQL Packages and Types Reference, although force here applies to
model statistics.
network_owner
Owner of the semantic network. (See Table 1-1.)
network_name
Name of the semantic network. (See Table 1-1.)
Usage Notes
See the information about the DBMS_STATS package inOracle Database PL/SQL Packages
and Types Reference.
See also Managing Statistics for Semantic Models and the Semantic Network.
For information about semantic network types and options, see Semantic Networks.
Examples
The following example sets statistics for a model named FAMILY.
15-135
Chapter 15
SEM_APIS.SPARQL_TO_SQL
15.114 SEM_APIS.SPARQL_TO_SQL
Format
SEM_APIS.SPARQL_TO_SQL(
sparql_query IN CLOB,
models IN RDF_MODELS DEFAULT NULL,
rulebases IN RDF_RULEBASES DEFAULT NULL,
aliases IN RDF_ALIASES DEFAULT NULL,
index_status IN VARCHAR2 DEFAULT NULL,
options IN VARCHAR2 DEFAULT NULL
graphs IN RDF_GRAPHS DEFAULT NULL,
named_graphs IN RDF_GRAPHS DEFAULT NULL,
network_owner IN VARCHAR2 DEFAULT NULL,
network_name IN VARCHAR2 DEFAULT NULL) RETURN CLOB;
Description
Translates a SPARQL query into a SQL query string that can be executed by an
application program.
Parameters
sparql_query
A string literal with one or more triple patterns, usually containing variables.
models
The model or models to use.
rulebases
One or more rulebases whose rules are to be applied to the query
aliases
One or more namespaces to be used for expansion of qualified names in the query
pattern.
index_status
The status of the relevant entailment for this query.
options
Options that can affect the results of queries.
graphs
The set of named graphs from which to construct the default graph for the query.
named_graphs
The set of named graphs that can be matched by a GRAPH clause.
network_owner
Owner of the semantic network. (See Table 1-1.)
network_name
Name of the semantic network. (See Table 1-1.)
15-136
Chapter 15
SEM_APIS.SWAP_NAMES
Usage Notes
Before using this procedure, be sure you understand the material in Using the
SEM_APIS.SPARQL_TO_SQL Function to Query Semantic Data.
For information about semantic network types and options, see Semantic Networks.
Examples
The following example translates a SPARQL query into a SQL query string.
DECLARE
sparql_stmt clob;
sql_stmt clob;
BEGIN
sparql_stmt := '{?x :grandParentOf ?y . ?x rdf:type :Male}';
sql_stmt := sem_apis.sparql_to_sql(
sparql_stmt,
sem_models('family'),
SEM_Rulebases('RDFS','family_rb'),
SEM_ALIASES(SEM_ALIAS('','http://www.example.org/family/')),
null);
execute immediate
'create table gf_table as
select x grandfather, y grandchild from('|| sql_stmt || ')';
END;
/
15.115 SEM_APIS.SWAP_NAMES
Format
SEM_APIS.SWAP_NAMES(
model1 IN VARCHAR2,
model2 IN VARCHAR2,
network_owner IN VARCHAR2 DEFAULT NULL,
network_name IN VARCHAR2 DEFAULT NULL);
Description
Swaps (exchanges) the names of two existing models.
Parameters
model1
Name of a model.
model2
Name of another model.
network_owner
Owner of the semantic network. (See Table 1-1.)
network_name
Name of the semantic network. (See Table 1-1.)
15-137
Chapter 15
SEM_APIS.TRUNCATE_SEM_MODEL
Usage Notes
As a result of this procedure, the name of model model1 is changed to the (old) name
of model2, and the name of model model2 is changed to the (old) name of model1.
The order of the names does not affect the result. For example, you could specify TEST
for model1 and PRODUCTION for model2, or PRODUCTION for model1 and TEST for model2,
and the result will be the same.
Contrast this procedure with SEM_APIS.RENAME_MODEL, which renames an
existing model.
For information about semantic network types and options, see Semantic Networks.
Examples
The following example changes the name of the (old) TEST model to PRODUCTION,
and the name of the (old) PRODUCTION model to TEST.
EXECUTE sem_apis.swap_names('test', 'production');
15.116 SEM_APIS.TRUNCATE_SEM_MODEL
Format
SEM_APIS.TRUNCATE_SEM_MODEL(
model_name IN VARCHAR2,
options IN VARCHAR2 DEFAULT NULL,
network_owner IN VARCHAR2 DEFAULT NULL,
network_name IN VARCHAR2 DEFAULT NULL);
Description
Truncates a semantic technology model.
Parameters
model_name
Name of the model.
options
(Reserved for future use)
network_owner
Owner of the semantic network. (See Table 1-1.)
network_name
Name of the semantic network. (See Table 1-1.)
Usage Notes
This procedure removes all triples and quads from the specified semantic model. For
an MDSYS-owned network, it also truncates the corresponding application table.
For a schema-private network, this is the only supported way to truncate a model. For
the MDSYS-owned network, you can truncate the model by using this procedure or by
truncating the corresponding application table.
15-138
Chapter 15
SEM_APIS.UNESCAPE_CLOB_TERM
Examples
The following example truncates a semantic technology model named articles. (This
example refers to the model described in Example 1-123.)
EXECUTE SEM_APIS.TRUNCATE_SEM_MODEL('articles', NULL, network_owner=>'RDFUSER',
network_name=>'NET1');
15.117 SEM_APIS.UNESCAPE_CLOB_TERM
Format
SEM_APIS.UNESCAPE_CLOB_TERM(
term IN CLOB CHARACTER SET ANY_CS
) RETURN CLOB CHARACTER SET val%CHARSET;
Description
Returns the input RDF term with special characters and non-ASCII characters unescaped as
specified by the W3C N-Triples format (http://www.w3.org/TR/rdf-testcases/#ntriples).
Parameters
term
The RDF term to unescape.
Usage Notes
For information about using the DO_UNESCAPE keyword in the options parameter of the
SEM_MATCH table function, see Using the SEM_MATCH Table Function to Query Semantic
Data.
Examples
The following example unescapes an input RDF term containing TAB and NEWLINE
characters.
SEM_APIS.UNESCAPE_CLOB_TERM('"abc\tdef\nhij"^^<http://www.w3.org/2001/
XMLSchema#string>')
FROM DUAL;
15.118 SEM_APIS.UNESCAPE_CLOB_VALUE
Format
SEM_APIS.UNESCAPE_CLOB_VALUE(
val IN CLOB CHARACTER SET ANY_CS,
start_offset IN NUMBER DEFAULT 1,
end_offset IN NUMBER DEFAULT 0,
include_start IN NUMBER DEFAULT 0
) RETURN VARCHAR2 CHARACTER SET val%CHARSET;
15-139
Chapter 15
SEM_APIS.UNESCAPE_RDF_TERM
Description
Returns the input CLOB value with special characters and non-ASCII characters
unescaped as specified by the W3C N-Triples format (http://www.w3.org/TR/rdf-
testcases/#ntriples).
Parameters
val
The CLOB text to unescape.
start_offset
The offset in val from which to start character unescaping. The default (1) causes
escaping to start at the first character of val.
end_offset
The offset in val from which to end character unescaping. The default (0) causes
escaping to continue through the end of val.
include_start
Set to 1 if the characters in val from 1 to start_offset should be prefixed
(prepended) to the return value. Otherwise, no such characters will be prefixed to the
return value.
Usage Notes
For information about using the DO_UNESCAPE keyword in the options parameter of the
SEM_MATCH table function, see Using the SEM_MATCH Table Function to Query
Semantic Data.
Examples
The following example unescapes an input character string containing TAB and
NEWLINE characters.
SELECT SEM_APIS.UNESCAPE_CLOB_VALUE('abc\tdef\nhij')
FROM DUAL;
15.119 SEM_APIS.UNESCAPE_RDF_TERM
Format
SEM_APIS.UNESCAPE_RDF_TERM(
term IN VARCHAR2 CHARACTER SET ANY_CS
) RETURN VARCHAR2 CHARACTER SET val%CHARSET;
Description
Returns the input RDF term with special characters and non-ASCII characters
unescaped as specified by the W3C N-Triples format (http://www.w3.org/TR/rdf-
testcases/#ntriples).
15-140
Chapter 15
SEM_APIS.UNESCAPE_RDF_VALUE
Parameters
term
The RDF term to unescape.
Usage Notes
For information about using the DO_UNESCAPE keyword in the options parameter of the
SEM_MATCH table function, see Using the SEM_MATCH Table Function to Query Semantic
Data.
Examples
The following example unescapes an input RDF term containing TAB and NEWLINE
characters.
SELECT SEM_APIS.UNESCAPE_RDF_TERM('"abc\tdef\nhij"^^<http://www.w3.org/2001/
XMLSchema#string>')
FROM DUAL;
15.120 SEM_APIS.UNESCAPE_RDF_VALUE
Format
SEM_APIS.UNESCAPE_RDF_VALUE(
val IN VARCHAR2 CHARACTER SET ANY_CS
) RETURN VARCHAR2 CHARACTER SET val%CHARSET;
Description
Returns the input CLOB value with special characters and non-ASCII characters unescaped
as specified by the W3C N-Triples format (http://www.w3.org/TR/rdf-testcases/
#ntriples).
Parameters
val
The text to unescape.
utf_encode
Set to 1 (the default) if non-ASCII characters and non-printable ASCII characters other than
chr(8), chr(9), chr(10), chr(12), and chr(13) should be escaped. Otherwise, such characters
will not be escaped.
Usage Notes
For information about using the DO_UNESCAPE keyword in the options parameter of the
SEM_MATCH table function, see Using the SEM_MATCH Table Function to Query Semantic
Data.
Examples
The following example unescapes an input character string containing TAB and NEWLINE
characters.
SELECT SEM_APIS.UNESCAPE_RDF_VALUE('abc\tdef\nhij')
FROM DUAL;
15-141
Chapter 15
SEM_APIS.UPDATE_MODEL
15.121 SEM_APIS.UPDATE_MODEL
Format
SEM_APIS.UPDATE_MODEL(
apply_model IN VARCHAR2,
update_stmt IN CLOB,
match_models IN RDF_MODELS DEFAULT NULL,
match_rulebases IN RDF_RULEBASES DEFAULT NULL,
match_index_status IN VARCHAR2 DEFAULT NULL,
match_options IN VARCHAR2 DEFAULT NULL,
options IN VARCHAR2 DEFAULT NULL,
network_owner IN VARCHAR2 DEFAULT NULL,
network_name IN VARCHAR2 DEFAULT NULL);
Description
Executes a SPARQL Update statement on a semantic model.
Parameters
apply_model
Name of the RDF model to be updated. This is the name specified when the model
was created using the SEM_APIS.CREATE_SEM_MODEL procedure.
It cannot be a virtual model (see Virtual Models) or an RDF view).
update_stmt
One or more SPARQL Update commands to be executed on the apply_model model.
Use the semicolon (;) to separate commands.
match_models
A list of models that forms the SPARQL data set to query for graph pattern matching
during a SPARQL Update operation (INSERT WHERE, DELETE WHERE, COPY,
MOVE, ADD). Can include virtual models and/or RDF views If this parameter is not
specified, the apply_model model is used.
match_rulebases
A list of rulebases to use with match_models to provide an entailment that generates
additional triples or quads to use for graph pattern matching during a SPARQL Update
operation.
match_index_status
The desired status for any entailments used for graph pattern matching during a
SPARQL Update operation.
match_options
String specifying hints to influence graph pattern matching during a SPARQL Update
operation. The set of hints that can be used here is identical to those that can be used
in the options parameter of SEM_MATCH.
options
String specifying hints that affect SPARQL operations. See the Usage Notes for a list
of available options.
15-142
Chapter 15
SEM_APIS.UPDATE_MODEL
network_owner
Owner of the semantic network. (See Table 1-1.)
network_name
Name of the semantic network. (See Table 1-1.)
Usage Notes
Before using this procedure, be sure you understand the material in Support for SPARQL
Update Operations on a Semantic Model.
The options parameter can specify one or more of the following options:
15-143
Chapter 15
SEM_APIS.VALIDATE_ENTAILMENT
You can override some options settings at the session level by using the
MDSYS.SDO_SEM_UPDATE_CTX.SET_PARAM procedure, as explained in Setting
UPDATE_MODEL Options at the Session Level.
For information about semantic network types and options, see Semantic Networks.
Examples
The following example inserts six triples into a semantic model.
BEGIN
sem_apis.update_model('electronics',
'PREFIX : <http://www.example.org/electronics/>
INSERT DATA {
:camera1 :name "Camera 1" .
:camera1 :price 120 .
:camera1 :cameraType :Camera .
:camera2 :name "Camera 2" .
:camera2 :price 150 .
:camera2 :cameraType :Camera .
} ');
END;
/
15.122 SEM_APIS.VALIDATE_ENTAILMENT
Format
SEM_APIS.VALIDATE_ENTAILMENT(
models_in IN SEM_MODELS,
rulebases_in IN SEM_RULEBASES,
criteria_in IN VARCHAR2 DEFAULT NULL,
max_conflict IN NUMBER DEFAULT 100,
options IN VARCHAR2 DEFAULT NULL,
network_owner IN VARCHAR2 DEFAULT NULL,
network_name IN VARCHAR2 DEFAULT NULL
) RETURN RDF_LONGVARCHARARRAY;
Description
Validates entailments (rules indexes) that can be used to perform OWL or RDFS
inferencing for one or more models.
Parameters
models_in
One or more model names. Its data type is SEM_MODELS, which has the following
definition: TABLE OF VARCHAR2(25)
rulebases_in
One or more rulebase names. Its data type is SEM_RULEBASES, which has the
following definition: TABLE OF VARCHAR2(25). Rules and rulebases are explained in
Inferencing: Rules and Rulebases.
criteria_in
A comma-delimited string of validation checks to run. If you do not specify this
parameter, by default all of the following checks are run:
15-144
Chapter 15
SEM_APIS.VALIDATE_GEOMETRIES
max_conflict
The maximum number of conflicts to find before the validation process stops. The default
value is 100.
options
(Not currently used. Reserved for Oracle use.).
network_owner
Owner of the semantic network. (See Table 1-1.)
network_name
Name of the semantic network. (See Table 1-1.)
Usage Notes
This procedure can be used to detect inconsistencies in the original entailment. For more
information, see Validating OWL Models and Entailments.
This procedure returns a null value if no errors are detected or (if errors are detected) an
object of type RDF_LONGVARCHARARRAY, which has the following definition:
VARRAY(32767) OF VARCHAR2(4000)
Examples
For an example of this procedure, see Example 3-5 in Validating OWL Models and
Entailments.
15.123 SEM_APIS.VALIDATE_GEOMETRIES
Format
SEM_APIS.VALIDATE_GEOMETRIES(
model_name IN VARCHAR2,
SRID IN NUMBER,
tolerance IN NUMBER,
parallel IN PLS_INTEGER DEFAULT NULL,
tablespace_name IN VARCHAR2 DEFAULT NULL,
15-145
Chapter 15
SEM_APIS.VALIDATE_GEOMETRIES
Description
Determines if all geometry literals in the specified model are valid for the provided
SRID and tolerance values.
Parameters
model_name
Name of the model containing geometry literals to validate. Only native models can be
specified.
SRID
SRID for the spatial reference system.
tolerance
Tolerance value that should be used for validation.
parallel
Degree of parallelism to be associated with the operation. For more information about
parallel execution, see Oracle Database VLDB and Partitioning Guide.
tablespace_name
Destination tablespace for the tables {model_name}_IVG$, {model_name}_FXT$, and
{model_name}_NFT$.
options
String specifying options for validation. Supported options are:
• RECTIFY=T. Staging tables {model_name}_FXT$ and {model_name}_NFT$ are
created, containing rectifiable and non-rectifiable triples, respectively. You can use
these tables to correct the model.
• AUTOCORRECT=T. Triples containing invalid but rectifiable geometries are
corrected. Also, table {model_name}_NFT$ containing triples with non-rectifiable
geometries is created so that you can correct such triples manually.
• STANDARD_CRS_URI=T. Use standard CRS (coordinate reference systems)
URIs.
• GML_LIT_SRL=T. Use ogc:gmlLiteral serialization for corrected geometry
literals. ogc:wktLiteral serialization is the default.
• GEOJSON_LIT_SRL=T. Use ogc:geoJSONLiteral serialization for corrected
geometry literals. ogc:wktLiteral serialization is the default.
• KML_LIT_SRL=T. Use ogc:kmlLiteral serialization for corrected geometry
literals. ogc:wktLiteral serialization is the default.
network_owner
Owner of the semantic network. (See Table 1-1.)
network_name
Name of the semantic network. (See Table 1-1.)
15-146
Chapter 15
SEM_APIS.VALIDATE_GEOMETRIES
Usage Notes
This procedure is a wrapper for SDO_GEOM.VALIDATE_GEOMETRY_WITH_CONTEXT
function.
A table {model_name}_IVG$ containing invalid geometry literals is created. Optionally,
staging tables {model_name}_FXT$ and {model_name}_NFT$ can be created, containing
rectifiable and non-rectifiable triples, respectively. Staging tables allow the user to correct
invalid geometries. Invalid but rectifiable geometry literals in a model can also be rectified
automatically if specified.
After correction of invalid geometries in a model, it is recommended that you execute
SEM_APIS.PURGE_UNUSED_VALUES to purge invalid geometry literal values from the
semantic network.
For an explanation of models, see Semantic Data Modeling and Semantic Data in the
Database.
For information about semantic network types and options, see Semantic Networks.
Examples
The following example creates a model with some invalid geometry literals and then validates
the model using the RECTIFY=T and STANDARD_CRS_URI=T options.
-- Create model
CREATE TABLE atab (id int, tri sdo_rdf_triple_s);
GRANT INSERT ON atab TO mdsys;
EXEC sem_apis.create_sem_model('m','atab','tri');
-- Validate
EXEC sem_apis.validate_geometries(model_name=>'m',SRID=>8307,tolerance=>0.1,
options=>'STANDARD_CRS_URI=T RECTIFY=T');
15-147
Chapter 15
SEM_APIS.VALIDATE_MODEL
15.124 SEM_APIS.VALIDATE_MODEL
Format
SEM_APIS.VALIDATE_MODEL(
models_in IN SEM_MODELS,
criteria_in IN VARCHAR2 DEFAULT NULL,
max_conflict IN NUMBER DEFAULT 100,
options IN VARCHAR2 DEFAULT NULL
) RETURN RDF_LONGVARCHARARRAY;
Description
Validates one or more models.
Parameters
models_in
One or more model names. Its data type is SEM_MODELS, which has the following
definition: TABLE OF VARCHAR2(25)
criteria_in
A comma-delimited string of validation checks to run. If you do not specify this
parameter, by default all of the following checks are run:
• UNSAT: Find unsatisfiable classes.
• EMPTY: Find instances that belong to unsatisfiable classes.
• SYNTAX_S: Find triples whose subject is neither URI nor blank node.
• SYNTAX_P: Find triples whose predicate is not URI.
• SELF_DIF: Find individuals that are different from themselves.
• INST: Find individuals that simultaneously belong to two disjoint classes.
• SAM_DIF: Find pairs of individuals that are same (owl:sameAs) and different
(owl:differentFrom) at the same time.
To specify fewer checks, specify a string with only the checks to be performed. For
example, criteria_in => 'UNSAT' causes the validation process to search only for
unsatisfiable classes.
max_conflict
The maximum number of conflicts to find before the validation process stops. The
default value is 100.
options
(Not currently used. Reserved for Oracle use.).
Usage Notes
This procedure can be used to detect inconsistencies in the original data model. For
more information, see Validating OWL Models and Entailments.
This procedure returns a null value if no errors are detected or (if errors are detected)
an object of type RDF_LONGVARCHARARRAY, which has the following definition:
VARRAY(32767) OF VARCHAR2(4000)
15-148
Chapter 15
SEM_APIS.VALUE_NAME_PREFIX
Examples
The following example validates the model named family.
SELECT SEM_APIS.VALIDATE_MODEL(SEM_MODELS('family')) FROM DUAL;
15.125 SEM_APIS.VALUE_NAME_PREFIX
Format
SEM_APIS.VALUE_NAME_PREFIX (
value_name IN VARCHAR2,
value_type IN VARCHAR2
) RETURN VARCHAR2;
Description
Returns the value in the VNAME_PREFIX column for the specified value name and value
type pair in the RDF_VALUE$ table.
Parameters
value_name
Value name. Must match a value in the VALUE_NAME column in the RDF_VALUE$ table,
which is described in Statements.
value_type
Value type. Must match a value in the VALUE_TYPE column in the RDF_VALUE$ table,
which is described in Statements.
Usage Notes
This function usually causes an index on the RDF_VALUE$ table to be used for processing a
lookup for values, and thus can make a query run faster.
Examples
The following query returns value name portions of all the lexical values in RDF_VALUE$
table with a prefix value same as that returned by the VALUE_NAME_PREFIX function. This
query uses an index on the RDF_VALUE$ table, thereby providing efficient lookup.
SELECT value_name FROM RDF_VALUE$
WHERE vname_prefix = SEM_APIS.VALUE_NAME_PREFIX(
'http://www.w3.org/1999/02/22-rdf-syntax-ns#type','UR');
VALUE_NAME
--------------------------------------------------------------------------------
http://www.w3.org/1999/02/22-rdf-syntax-ns#Alt
http://www.w3.org/1999/02/22-rdf-syntax-ns#Bag
http://www.w3.org/1999/02/22-rdf-syntax-ns#List
http://www.w3.org/1999/02/22-rdf-syntax-ns#Property
http://www.w3.org/1999/02/22-rdf-syntax-ns#Seq
http://www.w3.org/1999/02/22-rdf-syntax-ns#Statement
http://www.w3.org/1999/02/22-rdf-syntax-ns#XMLLiteral
http://www.w3.org/1999/02/22-rdf-syntax-ns#first
http://www.w3.org/1999/02/22-rdf-syntax-ns#nil
http://www.w3.org/1999/02/22-rdf-syntax-ns#object
http://www.w3.org/1999/02/22-rdf-syntax-ns#predicate
15-149
Chapter 15
SEM_APIS.VALUE_NAME_SUFFIX
http://www.w3.org/1999/02/22-rdf-syntax-ns#rest
http://www.w3.org/1999/02/22-rdf-syntax-ns#subject
http://www.w3.org/1999/02/22-rdf-syntax-ns#type
http://www.w3.org/1999/02/22-rdf-syntax-ns#value
15 rows selected.
15.126 SEM_APIS.VALUE_NAME_SUFFIX
Format
SEM_APIS.VALUE_NAME_SUFFIX (
value_name IN VARCHAR2,
value_type IN VARCHAR2
) RETURN VARCHAR2;
Description
Returns the value in the VNAME_SUFFIX column for the specified value name and
value type pair in the RDF_VALUE$ table.
Parameters
value_name
Value name. Must match a value in the VALUE_NAME column in the RDF_VALUE$
table, which is described in Statements.
value_type
Value type. Must match a value in the VALUE_TYPE column in the RDF_VALUE$
table, which is described in Statements.
Usage Notes
This function usually causes an index on the RDF_VALUE$ table to be used for
processing a lookup for values, and thus can make a query run faster.
Examples
The following query returns value name portions of all the lexical values in
RDF_VALUE$ table with a suffix value same as that returned by the
VALUE_NAME_SUFFIX function. This query uses an index on the RDF_VALUE$
table, thereby providing efficient lookup.
SELECT value_name FROM RDF_VALUE$
WHERE vname_suffix = SEM_APIS.VALUE_NAME_SUFFIX(
'http://www.w3.org/1999/02/22-rdf-syntax-ns#type','UR');
VALUE_NAME
--------------------------------------------------------------------------------
http://www.w3.org/1999/02/22-rdf-syntax-ns#type
15-150
16
SEM_OLS Package Subprograms
The SEM_OLS package contains subprograms (functions and procedures) related to triple-
level security to RDF data, using Oracle Label Security (OLS).
To use the subprograms in this chapter, you should understand the conceptual and usage
information in RDF Semantic Graph Overview and Fine-Grained Access Control for RDF
Data.
This chapter provides reference information about the subprograms, listed in alphabetical
order.
• SEM_OLS.APPLY_POLICY_TO_APP_TAB
• SEM_OLS.REMOVE_POLICY_FROM_APP_TAB
16.1 SEM_OLS.APPLY_POLICY_TO_APP_TAB
Format
SEM_OLS.APPLY_POLICY_TO_APP_TAB(
policy_name IN VARCHAR2,
schema_name IN VARCHAR2,
table_name IN VARCHAR2,
predicate IN VARCHAR2 DEFAULT NULL);
Description
Applies an OLS policy to an application table in the MDSYS-owned network.
Parameters
policy_name
Name of an existing OLS policy.
schema_name
Name of the schema containing the application table.
table_name
Name of the application table.
predicate
An additional predicate to combine with the label-based predicate.
Usage Notes
When you use triple-level security, OLS is applied to each semantic model in the network.
That is, label security is applied to the relevant internal tables and to all the application tables;
there is no need to manually apply policies to the application tables of existing semantic
models. However, if you need to create additional models after applying the OLS policy, you
must use the SEM_OLS.APPLY_POLICY_TO_APP_TAB procedure to apply OLS to the
application table before creating the model.
16-1
Chapter 16
SEM_OLS.REMOVE_POLICY_FROM_APP_TAB
You must have the following to execute this procedure: EXECUTE privilege for the
SA_POLICY_ADMIN package, and the policy_DBA role.
To remove the OLS policy from the application table, use the
SEM_OLS.REMOVE_POLICY_FROM_APP_TAB procedure.
For information about support for OLS, see Fine-Grained Access Control for RDF
Data.
This procedure applies only to the MDSYS-owned network, not to schema-private
networks. (If you try to apply this procedure to a schema-private network, the error
"ORA-20000: No application tables for schema-private network" is returned.) For
information about semantic network types and options, see Semantic Networks.
Examples
The following example applies an OLS policy named defense to the
MY_SCHEMA.MY_APP_TABLE application table.
begin
sem_ols.apply_policy_to_app_table(
policy_name => 'defense',
schema_name => 'my_schema',
table_name => 'my_app_table');
end;
/
16.2 SEM_OLS.REMOVE_POLICY_FROM_APP_TAB
Format
SEM_OLS.REMOVE_POLICY_FROM_APP_TAB(
policy_name IN VARCHAR2,
schema_name IN VARCHAR2,
table_name IN VARCHAR2,
check_model IN BOOLEAN DEFAULT TRUE);
Description
Permanently removes or detaches the OLS policy from an application table associated
with a model in the MDSYS-owned network.
Parameters
policy_name
Name of the existing OLS policy.
schema_name
Name of the schema containing the application table.
table_name
Name of the application table.
16-2
Chapter 16
SEM_OLS.REMOVE_POLICY_FROM_APP_TAB
check_model
TRUE (the default) checks if the model associated with the application table exists (and
generates an exception if the model exists); FALSE does not check if the model exists before
performing the operation.
Usage Notes
If you have dropped a semantic model and you no longer need to protect the application
table, you can use this procedure.
You must have the following to execute this procedure: EXECUTE privilege for the
SA_POLICY_ADMIN package, and the policy_DBA role.
If check_model is TRUE (the default), an exception is generated if the associated model exists.
In this case, if you want to execute this procedure, you must first drop the model.
For information about support for OLS, see Fine-Grained Access Control for RDF Data.
This procedure applies only to the MDSYS-owned network, not to schema-private networks.
(If you try to apply this procedure to a schema-private network, the error "ORA-20000: No
application tables for schema-private network" is returned.) For information about semantic
network types and options, see Semantic Networks.
Examples
The following example removes the OLS policy named defense from the
MY_SCHEMA.MY_APP_TABLE application table.
begin
sem_ols.remove_policy_from_app_table(
policy_name => 'defense',
schema_name => 'my_schema',
table_name => 'my_app_table');
end;
/
16-3
17
SEM_PERF Package Subprograms
The SEM_PERF package contains subprograms for examining and enhancing the
performance of the Resource Description Framework (RDF) and Web Ontology Language
(OWL) support in an Oracle database.
To use the subprograms in this chapter, you must understand the conceptual and usage
information in RDF Semantic Graph Overview and OWL Concepts.
This chapter provides reference information about the subprograms, listed in alphabetical
order.
• SEM_PERF.ANALYZE_AUX_TABLES
• SEM_PERF.DELETE_NETWORK_STATS
• SEM_PERF.DROP_EXTENDED_STATS
• SEM_PERF.EXPORT_NETWORK_STATS
• SEM_PERF.GATHER_STATS
• SEM_PERF.IMPORT_NETWORK_STATS
17.1 SEM_PERF.ANALYZE_AUX_TABLES
Format
SEM_PERF.ANALYZE_AUX_TABLES(
model_name IN VARCHAR2,
estimate_percent IN NUMBER DEFAULT DBMS_STATS.AUTO_SAMPLE_SIZE,
method_opt IN VARCHAR2 DEFAULT NULL,
degree IN NUMBER DEFAULT DBMS_STATS.AUTO_DEGREE,
network_owner IN DBMS_ID DEFAULT NULL,
network_name IN VARCHAR2 DEFAULT NULL);
Description
Analyzes all the SPM tables currently present for the given RDF model.
Parameters
model_name
Name of the RDF model.
estimate_percent
Determines the percentage of rows to sample. For more information on gathering the
estimate_percent statistics, see DBMS_STATS.GATHER_TABLE_STATS procedure.
method_opt
Determines the column statistics collection. For more information on gathering the column
statistics, see DBMS_STATS.GATHER_TABLE_STATS
17-1
Chapter 17
SEM_PERF.DELETE_NETWORK_STATS
degree
Determines the degree of parallelism used for gathering statistics. For more
information on this procedure parameter see
DBMS_STATS.GATHER_TABLE_STATS
network_owner
Owner of the semantic network. (See Table 1-1.)
network_name
Name of the semantic network. (See Table 1-1.)
Usage Notes
Examples
The following example gathers statistics for SPM auxiliary tables.
EXECUTE
SEM_PERF.ANALYZE_AUX_TABLES('m1',network_owner=>'RDFUSER',network_name=>'NET1');
17.2 SEM_PERF.DELETE_NETWORK_STATS
Format
SEM_PERF.DELETE_NETWORK_STATS (
cascade_parts IN BOOLEAN DEFAULT TRUE,
cascade_columns IN BOOLEAN DEFAULT TRUE,
cascade_indexes IN BOOLEAN DEFAULT TRUE,
no_invalidate IN BOOLEAN DEFAULT DBMS_STATS.AUTO_INVALIDATE,
force IN BOOLEAN DEFAULT FALSE,
options IN VARCHAR2 DEFAULT NULL,
network_owner IN VARCHAR2 DEFAULT NULL,
network_name IN VARCHAR2 DEFAULT NULL);
Description
Deletes statistics for the semantic network.
Parameters
options
Controls the scope of the operation:
• If MDSYS.SDO_RDF.VALUE_TABLE_ONLY, the operation applies only to the
MDSYS.RDF_VALUE$ table.
• If MDSYS.SDO_RDF.LINK_TABLE_ONLY, the operation applies only to the
MDSYS.RDF_LINK$ table.
• If null (the default), the operation applies to both the MDSYS.RDF_VALUE$ and
MDSYS.RDF_LINK$ tables.
(other parameters)
See the parameter explanations for the DBMS_STATS.DELETE_TABLE_STATS
procedure in Oracle Database PL/SQL Packages and Types Reference, although
force here applies to network statistics.
17-2
Chapter 17
SEM_PERF.DROP_EXTENDED_STATS
network_owner
Owner of the semantic network. (See Table 1-1.)
network_name
Name of the semantic network. (See Table 1-1.)
Usage Notes
See the information about the DBMS_STATS package inOracle Database PL/SQL Packages
and Types Reference.
See also Managing Statistics for Semantic Models and the Semantic Network.
For information about semantic network types and options, see Semantic Networks.
Examples
The following example deletes statistics for the semantic network:
EXECUTE SEM_APIS.DELETE_NETWORK_STATS;
17.3 SEM_PERF.DROP_EXTENDED_STATS
Format
SEM_PERF.DROP_EXTENDED_STATS (
network_owner IN VARCHAR2 DEFAULT NULL,
network_name IN VARCHAR2 DEFAULT NULL);
Description
Drops column groups used for extended optimizer statistics on the RDF_LINK$ table.
Parameters
network_owner
Owner of the semantic network. (See Table 1-1.)
network_name
Name of the semantic network. (See Table 1-1.)
Usage Notes
To use this procedure, you must connect as a user with permission to execute it. By default,
when Spatial and Graph is installed as part of Oracle Database, only the MDSYS user can
execute this procedure; however, execution permission on this procedure can be granted to
users as needed.
The default column groups that will be dropped from RDF_LINK$ are: (CANON_END_NODE_ID,
START_NODE_ID) (P_VALUE_ID, CANON_END_NODE_ID) (P_VALUE_ID, START_NODE_ID)
See also:
• Dropping Extended Statistics at the Network Level
• The information about the DBMS_STATS package in Oracle Database PL/SQL Packages
and Types Reference
For information about semantic network types and options, see Semantic Networks.
17-3
Chapter 17
SEM_PERF.EXPORT_NETWORK_STATS
Examples
The following example drops extended statistics for the semantic network:
EXECUTE SEM_PERF.DROP_EXTENDED_STATS;
17.4 SEM_PERF.EXPORT_NETWORK_STATS
Format
SEM_PERF.EXPORT_NETWORK_STATS (
stattab IN VARCHAR2,
statid IN VARCHAR2 DEFAULT NULL,
cascade IN BOOLEAN DEFAULT TRUE,
statown IN VARCHAR2 DEFAULT NULL,
stat_category IN VARCHAR2 DEFAULT 'OBJECT_STATS',
options IN VARCHAR2 DEFAULT NULL);
Description
Exports the statistics for the semantic network and stores them in the user statistics
table.
Parameters
options
Controls the scope of the operation:
• If MDSYS.SDO_RDF.VALUE_TABLE_ONLY, the operation applies only to the
MDSYS.RDF_VALUE$ table.
• If MDSYS.SDO_RDF.LINK_TABLE_ONLY, the operation applies only to the
MDSYS.RDF_LINK$ table.
• If null (the default), the operation applies to both the MDSYS.RDF_VALUE$ and
MDSYS.RDF_LINK$ tables.
(other parameters)
See the parameter explanations for the DBMS_STATS.EXPORT_TABLE_STATS
procedure in Oracle Database PL/SQL Packages and Types Reference.
network_owner
Owner of the semantic network. (See Table 1-1.)
network_name
Name of the semantic network. (See Table 1-1.)
Usage Notes
See the information about the DBMS_STATS package inOracle Database PL/SQL
Packages and Types Reference.
See also Managing Statistics for Semantic Models and the Semantic Network.
For information about semantic network types and options, see Semantic Networks.
17-4
Chapter 17
SEM_PERF.GATHER_STATS
Examples
The following example exports the statistics for the semantic network and stores them in a
table named STAT_TABLE.
EXECUTE SEM_APIS.EXPORT_NETWORK_STATS('stat_table');
17.5 SEM_PERF.GATHER_STATS
Format
SEM_PERF.GATHER_STATS(
just_on_values_table IN BOOLEAN DEFAULT FALSE,
degree IN NUMBER(38) DEFAULT NULL,
estimate_percent IN NUMBER DEFAULT DBMS_STATS.AUTO_SAMPLE_SIZE,
value_method_opt IN VARCHAR2 DEFAULT NULL,
link_method_opt IN VARCHAR2 DEFAULT NULL,
network_owner IN VARCHAR2 DEFAULT NULL,
network_name IN VARCHAR2 DEFAULT NULL);
Description
Gathers statistics about RDF and OWL tables and their indexes.
Parameters
just_on_values_table
TRUE collects statistics only on the table containing the lexical values of triples; FALSE (the
default) collects statistics on all major tables related to the storage of RDF and OWL data.
A value of TRUE reduces the execution time for the procedure; and it may be sufficient if you
need only to collect statistics on the values table (for example, if you use other interfaces to
collect any other statistics that you might need).
degree
Degree of parallelism. For more information about parallel execution, see Oracle Database
VLDB and Partitioning Guide.
estimate_percent
Determines the percentage of rows in MDSYS.RDF_LINK$ and MDSYS.RDF_VALUE$ to
sample.
The valid range is between 0.000001 and 100. You can use the constant
DBMS_STATS.AUTO_SAMPLE_SIZE (the default) to enable Oracle Database to determine the
appropriate sample size for optimal statistics.
value_method_opt
Accepts either of the following options, or both in combination, for the MDSYS.RDF_VALUE$
table:
• FOR ALL [INDEXED | HIDDEN] COLUMNS [size_clause]
• FOR COLUMNS [size clause] column|attribute [size_clause] [,column|attribute
[size_clause]...]
size_clause is defined as: size_clause := SIZE {integer | REPEAT | AUTO | SKEWONLY}
column is defined as: column := column_name | (extension)
17-5
Chapter 17
SEM_PERF.GATHER_STATS
link_method_opt
Accepts either of the following options, or both in combination, for the
MDSYS.RDF_LINK$ table:
• FOR ALL [INDEXED | HIDDEN] COLUMNS [size_clause]
• FOR COLUMNS [size clause] column|attribute [size_clause] [,column|
attribute [size_clause]...]
size_clause is defined as: size_clause := SIZE {integer | REPEAT | AUTO |
SKEWONLY}
column is defined as: column := column_name | (extension)
• integer : Number of histogram buckets. Must be in the range [1,2048].
• REPEAT : Collects histograms only on the columns that already have histograms.
• AUTO : Oracle Database determines the columns to collect histograms based on
data distribution and the workload of the columns.
• SKEWONLY : Oracle Database determines the columns to collect histograms based
on the data distribution of the columns.
• column_name : Name of a column.
• extension: Can be either a column group in the format of (column_name,
column_name [, ...]) or an expression.
The usual default is: FOR ALL COLUMNS SIZE AUTO FOR COLUMNS SIZE 2048
P_VALUE_ID CANON_END_NODE_ID START_NODE_ID G_ID (CANON_END_NODE_ID,
START_NODE_ID) (P_VALUE_ID, CANON_END_NODE_ID) (P_VALUE_ID,
START_NODE_ID)
network_owner
Owner of the semantic network. (See Table 1-1.)
network_name
Name of the semantic network. (See Table 1-1.)
Usage Notes
To use this procedure, you must connect as a user with permission to execute it. By
default, when Spatial and Graph is installed as part of Oracle Database, only the
MDSYS user can execute this procedure; however execution permission on this
procedure can be granted to users as needed.
17-6
Chapter 17
SEM_PERF.IMPORT_NETWORK_STATS
This procedure collects statistical information that can help you to improve inferencing
performance, as explained in Enhancing Inference Performance. This procedure internally
calls the DBMS_STATS.GATHER_TABLE_STATS procedure to collect statistics on RDF- and
OWL-related tables and their indexes, and stores the statistics in the Oracle Database data
dictionary. For information about using the DBMS_STATS package, see Oracle Database
PL/SQL Packages and Types Reference.
Gathering statistics uses significant system resources, so execute this procedure when it
cannot adversely affect essential applications and operations.
See also Managing Statistics for Semantic Models and the Semantic Network.
Examples
The following example gathers statistics about RDF and OWL related tables and their
indexes.
EXECUTE SEM_PERF.GATHER_STATS;
17.6 SEM_PERF.IMPORT_NETWORK_STATS
Format
SEM_PERF.IMPORT_NETWORK_STATS (
stattab IN VARCHAR2,
statid IN VARCHAR2 DEFAULT NULL,
cascade IN BOOLEAN DEFAULT TRUE,
statown IN VARCHAR2 DEFAULT NULL,
no_invalidate IN BOOLEAN DEFAULT FALSE,
force IN BOOLEAN DEFAULT FALSE,
stat_category IN VARCHAR2 DEFAULT 'OBJECT_STATS',
options IN VARCHAR2 DEFAULT NULL,
network_owner IN VARCHAR2 DEFAULT NULL,
network_name IN VARCHAR2 DEFAULT NULL);
Description
Retrieves the statistics for the semantic network from a user statistics table and stores them
in the dictionary.
Parameters
options
Controls the scope of the operation:
• If MDSYS.SDO_RDF.VALUE_TABLE_ONLY, the operation applies only to the
MDSYS.RDF_VALUE$ table.
• If MDSYS.SDO_RDF.LINK_TABLE_ONLY, the operation applies only to the
MDSYS.RDF_LINK$ table.
• If null (the default), the operation applies to both the MDSYS.RDF_VALUE$ and
MDSYS.RDF_LINK$ tables.
(other parameters)
See the parameter explanations for the DBMS_STATS.IMPORT_TABLE_STATS procedure
in Oracle Database PL/SQL Packages and Types Reference, although force here applies to
network statistics.
17-7
Chapter 17
SEM_PERF.IMPORT_NETWORK_STATS
network_owner
Owner of the semantic network. (See Table 1-1.)
network_name
Name of the semantic network. (See Table 1-1.)
Usage Notes
See the information about the DBMS_STATS package inOracle Database PL/SQL
Packages and Types Reference.
See also Managing Statistics for Semantic Models and the Semantic Network.
For information about semantic network types and options, see Semantic Networks.
Examples
The following example imports the statistics for the semantic network in a table named
STAT_TABLE, and stores them in the dictionary.
EXECUTE SEM_APIS.IMPORT_NETWORK_STATS('stat_table');
17-8
18
SEM_RDFCTX Package Subprograms
The SEM_RDFCTX package contains subprograms (functions and procedures) to manage
extractor policies and semantic indexes created for documents.
To use the subprograms in this chapter, you should understand the conceptual and usage
information in Semantic Indexing for Documents.
This chapter provides reference information about the subprograms, listed in alphabetical
order.
• SEM_RDFCTX.ADD_DEPENDENT_POLICY
• SEM_RDFCTX.CREATE_POLICY
• SEM_RDFCTX.DROP_POLICY
• SEM_RDFCTX.MAINTAIN_TRIPLES
• SEM_RDFCTX.SET_DEFAULT_POLICY
• SEM_RDFCTX.SET_EXTRACTOR_PARAM
18.1 SEM_RDFCTX.ADD_DEPENDENT_POLICY
Format
SEM_RDFCTX.ADD_DEPENDENT_POLICY(
index_name IN VARCHAR2,
policy_name IN VARCHAR2,
partition_name IN VARCHAR2 DEFAULT NULL,
network_owner IN VARCHAR2 DEFAULT NULL,
network_name IN VARCHAR2 DEFAULT NULL);
Description
Adds a dependent policy to an (already created) index or index partition.
Parameters
index_name
Name of the index.
policy_name
Name of the dependent policy.
partition_name
If the specified index is local, the name of the target partition. (Otherwise, must be null.)
network_owner
Owner of the semantic network. (See Table 1-1.)
18-1
Chapter 18
SEM_RDFCTX.CREATE_POLICY
network_name
Name of the semantic network. (See Table 1-1.)
Usage Notes
The base policy corresponding to the new dependent policy must already be a part of
the index.
For information about semantic network types and options, see Semantic Networks.
Examples
The following example adds a new dependent policy SEM_EXTR_PLUS_GEOONT to the
index ArticleIndex.
begin
sem_rdfctx.add_dependent_policy (index_name => 'ArticleIndex',
policy_name => 'SEM_EXTR_PLUS_GEOONT');
end;
/
18.2 SEM_RDFCTX.CREATE_POLICY
Format
SEM_RDFCTX.CREATE_POLICY(
policy_name IN VARCHAR2,
extractor IN mdsys.rdfctx_extractor,
preferences IN sys.XMLType DEFAULT NULL,
network_owner IN VARCHAR2 DEFAULT NULL,
network_name IN VARCHAR2 DEFAULT NULL);
or
SEM_RDFCTX.CREATE_POLICY(
policy_name IN VARCHAR2,
base_policy IN VARCHAR2,
user_models IN SEM_MODELS DEFAULT NULL,
user_entailments IN SEM_MODELS DEFAULT NULL,
network_owner IN VARCHAR2 DEFAULT NULL,
network_name IN VARCHAR2 DEFAULT NULL);
Description
Creates an extractor policy. (The first format is for a base policy; the second format is
for a policy that is dependent on a base policy.)
Parameters
policy_name
Name of the extractor policy.
extractor
An instance of a subtype of the RDFCTX_EXTRACTOR type that encapsulates the
extraction logic for the information extractor.
preferences
Any preferences associated with the policy.
18-2
Chapter 18
SEM_RDFCTX.CREATE_POLICY
base_policy
Base extractor policy for a dependent policy.
user_models
List of user models for a dependent policy.
user_entailments
List of user entailments for a dependent policy.
network_owner
Owner of the semantic network. (See Table 1-1.)
network_name
Name of the semantic network. (See Table 1-1.)
Usage Notes
An extractor policy created using this procedure determines the characteristics of a semantic
index that is created using the policy. Each extractor policy refers to an instance of an
extractor type, either directly or indirectly. An extractor policy with a direct reference to an
extractor type instance can be used to compose other extractor policies that include
additional RDF models for ontologies.
An instance of the extractor type assigned to the extractor parameter must be an instance of
a direct or indirect subtype of type mdsys.rdfctx_extractor.
The RDF models specified in the user_models parameter must be accessible to the user that
is creating the policy.
The RDF entailments specified in the user_entailments parameter must be accessible to the
user that is creating the policy. Note that the RDF models underlying the entailments do not
get automatically included in the dependent policy. To include one or more of those
underlying RDF models, you need to include the models in the user_models parameter.
The preferences specified for extractor policy determine the type of repository used for the
documents to be indexed and other relevant information. For more information, see Indexing
External Documents.
For information about semantic network types and options, see Semantic Networks.
Examples
The following example creates an extractor policy using the gatenlp_extractor extractor type,
which is included with the Oracle Database support for semantic indexing.
begin
sem_rdfctx.create_policy (policy_name => 'SEM_EXTR',
extractor => mdsys.gatenlp_extractor());
end;
/
The following example creates a dependent policy for the previously created extractor policy,
and it adds the user-defined RDF model geo_ontology to the dependent policy.
begin
sem_rdfctx.create_policy (policy_name => 'SEM_EXTR_PLUS_GEOONT',
base_policy => 'SEM_EXTR',
user_models => SEM_MODELS ('geo_ontology'));
end;
/
18-3
Chapter 18
SEM_RDFCTX.DROP_POLICY
18.3 SEM_RDFCTX.DROP_POLICY
Format
SEM_RDFCTX.DROP_POLICY(
policy_name IN VARCHAR2,
network_owner IN VARCHAR2 DEFAULT NULL,
network_name IN VARCHAR2 DEFAULT NULL);
Description
Deletes (drops) an unused extractor policy.
Parameters
policy_name
Name of the extractor policy.
network_owner
Owner of the semantic network. (See Table 1-1.)
network_name
Name of the semantic network. (See Table 1-1.)
Usage Notes
An exception is generated if the specified policy being is used for a semantic index for
documents or if a dependent extractor policy exists for the specified policy.
For information about semantic network types and options, see Semantic Networks.
Examples
The following example drops the SEM_EXTR_PLUS_GEOONT extractor policy.
begin
sem_rdfctx.drop_policy (policy_name => 'SSEM_EXTR_PLUS_GEOONT');
end;
/
18.4 SEM_RDFCTX.MAINTAIN_TRIPLES
Format
SEM_RDFCTX.MAINTAIN_TRIPLES(
index_name IN VARCHAR2,
where_clause IN VARCHAR2,
rdfxml_content IN sys.XMLType,
policy_name IN VARCHAR2 DEFAULT NULL,
action IN VARCHAR2 DEFAULT 'ADD',
network_owner IN VARCHAR2 DEFAULT NULL,
network_name IN VARCHAR2 DEFAULT NULL);
Description
Adds one or more triples to graphs that contain information extracted from specific
documents.
18-4
Chapter 18
SEM_RDFCTX.MAINTAIN_TRIPLES
Parameters
index_name
Name of the semantic index for documents.
where_clause
A SQL predicate (WHERE clause text without the WHERE keyword) on the table in which the
documents are stored, to identify the rows for which to maintain the index.
rdfxml_content
Triples, in the form of an RDF/XML document, to be added to the individual graphs
corresponding to the documents.
policy_name
Name of the extractor policy. If policy_name is null (the default), the triples are added to the
information extracted by the default (or the only) extractor policy for the index; if you specify
a policy name, the triples are added to the information extracted by that policy.
action
Type of maintenance operation to perform on the triples. The only value currently supported
in ADD (the default), which adds the triples that are specified in the rdfxml_content
parameter.
network_owner
Owner of the semantic network. (See Table 1-1.)
network_name
Name of the semantic network. (See Table 1-1.)
Usage Notes
The information extracted from the semantically indexed documents may be incomplete and
lacking in proper context. This procedure enables a domain expect to add triples to individual
graphs pertaining to specific semantically indexed documents, so that all subsequent
SEM_CONTAINS queries can consider these triples in their document search criteria.
This procedure accepts the index name and WHERE clause text to identify the specific
documents to be annotated with the additional triples. For example, the where_clause might
be specified as a simple predicate involving numeric data, such as 'docId IN (1,2,3)'.
For information about semantic network types and options, see Semantic Networks.
Examples
The following example annotates a specific document with the semantic index ArticleIndex
by adding triples to the corresponding individual graph.
begin
sem_rdfctx.maintain_triples(
index_name => 'ArticleIndex',
where_clause => 'docid = 15',
rdfxml_content => sys.xmltype(
'<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#"
xmlns:pred="http://myorg.com/pred/">
<rdf:Description rdf:about=" http://newscorp.com/Org/ExampleCorp">
<pred:hasShortName
rdf:datatype="http://www.w3.org/2001/XMLSchema#string">
18-5
Chapter 18
SEM_RDFCTX.SET_DEFAULT_POLICY
Example
</pred:hasShortName>
</rdf:Description>
</rdf:RDF>'));
end;
/
18.5 SEM_RDFCTX.SET_DEFAULT_POLICY
Format
SEM_RDFCTX.SET_DEFAULT_POLICY(
index_name IN VARCHAR2,
policy_name IN VARCHAR2,
network_owner IN VARCHAR2 DEFAULT NULL,
network_name IN VARCHAR2 DEFAULT NULL);
Description
Sets the default extractor policy for a semantic index that is configured with multiple
extractor policies.
Parameters
index_name
Name of the semantic index for documents.
policy_name
Name of the extractor policy to be used as the default extractor policy for the specified
semantic index. Must be one of the extractor policies listed in the PARAMETERS
clause of the CREATE INDEX statement that created index_name.
network_owner
Owner of the semantic network. (See Table 1-1.)
network_name
Name of the semantic network. (See Table 1-1.)
Usage Notes
When you create a semantic index for documents, you can specify multiple extractor
policies as a space-separated list of names in the PARAMETERS clause of the
CREATE INDEX statement. As explained in Semantically Indexing Documents, the
first policy from this list is used as the default extractor policy for all SEM_CONTAINS
queries that do not identify an extractor policy by name. You can use the
SEM_RDFCTX.SET_DEFAULT_POLICY procedure to set a different default policy for
the index.
For information about semantic network types and options, see Semantic Networks.
Examples
The following example sets CITY_EXTR as the default extractor policy for the
ArticleIndex index.
begin
sem_rdfctx.set_default_policy (index_name => 'ArticleIndex',
policy_name => 'CITY_EXTR');
18-6
Chapter 18
SEM_RDFCTX.SET_EXTRACTOR_PARAM
end;
/
18.6 SEM_RDFCTX.SET_EXTRACTOR_PARAM
Format
SEM_RDFCTX.SET_EXTRACTOR_PARAM(
param_key IN VARCHAR2,
patam_value IN VARCHAR2,
param_desc IN VARCHAR2,
network_owner IN VARCHAR2 DEFAULT NULL,
network_name IN VARCHAR2 DEFAULT NULL);
Description
Configures the Oracle Database semantic indexing support to work with external information
extractors, such as Calais and GATE.
Parameters
param_key
Key for the parameter to be set.
param_value
Value for the parameter to be set.
param_desc
Short description for the parameter to be set.
network_owner
Owner of the semantic network. (See Table 1-1.)
network_name
Name of the semantic network. (See Table 1-1.)
Usage Notes
To use this procedure, you must be connected as SYSTEM (not SYS … AS SYSDBA) or
another non-SYS user with the DBA role.
To work with the Calais extractor type (see Configuring the Calais Extractor type), you must
specify values for the following parameters:
• CALAIS_WS_ENDPOINT: Web service end point for Calais.
• CALAIS_KEY: License key for Calais.
• CALAIS_WS_SOAPACTION: SOAP action for the Calais Web service.
To work with the General Architecture for Text Engineering (GATE) extractor type (see
Working with General Architecture for Text Engineering (GATE)), you must specify values for
the following parameters:
• GATE_NLP_HOST: Host for the GATE NLP Listener.
• GATE_NLP_PORT: Port for the GATE NLP Listener.
18-7
Chapter 18
SEM_RDFCTX.SET_EXTRACTOR_PARAM
In addition to these parameters, you may need to specify a value for the HTTP_PROXY
parameter to work with information extractors or index documents that are outside the
firewall.
A database instance only has one set of values for these parameters, and they are
used for all instances of semantic indexes using the corresponding information
extractor. You can use this procedure if you need to change the existing values of any
of the parameters.
For information about semantic network types and options, see Semantic Networks.
Examples
For examples, see the following sections:
• Configuring the Calais Extractor type
• Working with General Architecture for Text Engineering (GATE)
18-8
19
SEM_RDFSA Package Subprograms
The SEM_RDFSA package contains subprograms (functions and procedures) for providing
fine-grained access control to RDF data using Oracle Label Security (OLS).
To use the subprograms in this chapter, you should understand the conceptual and usage
information in RDF Semantic Graph Overview and Fine-Grained Access Control for RDF
Data.
This chapter provides reference information about the subprograms, listed in alphabetical
order.
• SEM_RDFSA.APPLY_OLS_POLICY
• SEM_RDFSA.DISABLE_OLS_POLICY
• SEM_RDFSA.ENABLE_OLS_POLICY
• SEM_RDFSA.REMOVE_OLS_POLICY
• SEM_RDFSA.RESET_MODEL_LABELS
• SEM_RDFSA.SET_PREDICATE_LABEL
• SEM_RDFSA.SET_RDFS_LABEL
• SEM_RDFSA.SET_RESOURCE_LABEL
• SEM_RDFSA.SET_RULE_LABEL
19.1 SEM_RDFSA.APPLY_OLS_POLICY
Format
SEM_RDFSA.APPLY_OLS_POLICY(
policy_name IN VARCHAR2,
rdfsa_options IN NUMBER DEFAULT SEM_RDFSA.SECURE_SUBJECT,
table_options IN VARCHAR2 DEFAULT 'ALL_CONTROL',
label_function IN VARCHAR2 DEFAULT NULL,
predicate IN VARCHAR2 DEFAULT NULL,
network_owner IN VARCHAR2 DEFAULT NULL,
network_name IN VARCHAR2 DEFAULT NULL);
Description
Applies an OLS policy to the semantic data store.
Parameters
policy_name
Name of an existing OLS policy.
19-1
Chapter 19
SEM_RDFSA.APPLY_OLS_POLICY
rdfsa_options
Options specifying the mode of fine-grained access control to be enabled for RDF
data. The default option for securing RDF data involves assigning sensitivity labels for
the resources appearing the triples' subject position. You can override the defaults by
using the rdfsa_options parameter and specifying one of the constants defined in
Table 19-1 in the Usage Notes.
table_options
Policy enforcement options. The default value (ALL_CONTROL) is the only supported
value for this procedure.
label_function
A string invoking a function to return a label value to use as the default.
predicate
An additional predicate to combine with the label-based predicate.
network_owner
Owner of the semantic network. (See Table 1-1.)
network_name
Name of the semantic network. (See Table 1-1.)
Usage Notes
The OLS policy specified with this procedure must be created with CTXT1 as the
column name, and it should use default policy options. For information about policy
options, see Oracle Label Security Administrator's Guide.
This procedure invokes the sa_policy_admin.apply_table_policy procedure on
multiple tables defined in the MDSYS schema. The parameters table_options,
label_function, and predicate for the SEM_RDFSA.APPLY_OLS_POLICY
procedure have same semantics as the parameters with same names in the
sa_policy_admin.apply_table_policy procedure.
For the rdfsa_options parameter, you can specify the package constant for the
desired option. Table 19-1 lists these constants and their descriptions.
Constant Description
SEM_RDFSA.SECURE_ Assigns sensitivity labels for the resources appearing the triples'
SUBJECT subject position.
SEM_RDFSA.SECURE_ Assigns sensitivity labels for the resources appearing the triples'
PREDICATE predicate position.
SEM_RDFSA.SECURE_ Assigns sensitivity labels for the resources appearing the triples'
OBJECT object position.
SEM_RDFSA.TRIPLE_LE Applies triple-level security. Provides good performance, and
VEL_ONLY eliminates the need to assign labels to individual resources.
(Requires that Patch 9819833, available from My Oracle Support,
be installed.)
SEM_RDFSA.OPT_DEFI Restricts the use of an RDF resource in a triple before the
NE_BEFORE_USE sensitivity label is defined for the resource. If this option is not
specified, the user's initial row label is used as the default label for
the resource upon first use.
19-2
Chapter 19
SEM_RDFSA.APPLY_OLS_POLICY
Constant Description
SEM_RDFSA.OPT_RELA Relaxes the dominating relationship that exists between the triple
X_TRIPLE_LABEL label and the labels associated with all its components. With this
option, a triple can be defined if the user has READ access to all
the triple components and the triple label may not bear any
relationship with the component labels. Without this option, the
triple label should at least cover the label for all its components.
You can specify a function in the label_function parameter to generate custom labels for
newly inserted triples. The label function is associated with the MDSYS.RDF_LINK$ table,
and the columns in this table may be configured as parameters to the label function as shown
in the following example:
fgac_admin.new_triple_label(:new.model_id,
:new.start_node_id,
:new.p_value_id,
:new.canon_end_node_id)'
Because the OLS policy is applied to more than one table with different structures, the only
valid column reference in any predicates assigned to the predicate parameter is that of the
label column: CTXT1. If OLS is enabled for a semantic data store with existing data, you can
specify a predicate of the form 'OR CTXT1 is null' to be able to continue using this data
with no access restrictions.
An OLS-enabled semantic data store uses sensitivity labels for all the RDF triples organized
in multiple models. User access to such triples, through model views and SEM_MATCH
queries, is restricted by the OLS policy. Additionally, independent of a user owning the
application table, access to the triple column (of type SDO_RDF_TRIPLE_S) in the table is
restricted to users with FULL access privileges with the OLS policy.
The triples are inserted into a specific RDF model using the INSERT privileges on the
corresponding application table. A sensitivity label for the new triple is generated using the
user's session context (initial row label) or the label function. The triple is validated for any
RDF policy violations using labels associated with the triple components. Although the triple
information may not be accessed trough the application table, the model view may be queried
to access the triples, while enforcing the OLS policy restrictions. If you have the necessary
policy privileges (such as writeup, writeacross), you can update the CTXT1 column in the
model view to reset the label assigned to the triple. The new label is automatically validated
for any RDF policy violations involving the triple components. Update privilege on the CTXT1
column of the model view is granted to the owner of the model, and this user may selectively
grant this privilege to other users.
If the RDF models are created in schemas other than the user with FULL access, necessary
privileges on the model objects -- specifically, read/write access on the application table, read
access to the model view, and write access to the CTXT1 column in the model view -- can be
granted to such users for maintenance operations. These operations include bulk loading into
the model, resetting any sensitivity labels assigned to the triples, and creating entailments
using the model.
To disable the OLS policy, use the SEM_RDFSA.DISABLE_OLS_POLICY procedure.
For information about support for OLS, see Fine-Grained Access Control for RDF Data.
19-3
Chapter 19
SEM_RDFSA.DISABLE_OLS_POLICY
For information about semantic network types and options, see Semantic Networks.
Examples
The following example enable secure access to RDF data with secure subject and
secure predicate options.
begin
sem_rdfsa.apply_ols_policy(
policy_name => 'defense',
rdfsa_options => sem_rdfsa.SECURE_SUBJECT+
sem_rdfsa.SECURE_PREDICATE);
end;
/
The following example extends the preceding example by specifying a Define Before
Use option, which allows a user to define a triple only if the triple components secured
(Subject, Predicate or Object) are predefined with an associated sensitivity label. This
configuration is effective if the user inserting the triple does not have execute privileges
on the SEM_RDFSA package.
begin
sem_rdfsa.apply_ols_policy(
policy_name => 'defense',
rdfsa_options => sem_rdfsa.SECURE_SUBJECT+
sem_rdfsa.SECURE_PREDICATE+
sem_rdfsa.OPT_DEFINE_BEFORE_USE);
end;
/
19.2 SEM_RDFSA.DISABLE_OLS_POLICY
Format
SEM_RDFSA.DISABLE_OLS_POLICY(
network_owner IN VARCHAR2 DEFAULT NULL,
network_name IN VARCHAR2 DEFAULT NULL);
Description
Disables the OLS policy that has been previously applied to or enabled on the
semantic data store.
Parameters
network_owner
Owner of the semantic network. (See Table 1-1.)
network_name
Name of the semantic network. (See Table 1-1.)
Usage Notes
You can use this procedure to disable temporarily the OLS policy that had been
applied to or enabled for the semantic data store. The user disabling the policy should
have the necessary privileges to administer OLS policies and should also have access
to the OLS policy applied to RDF data.
19-4
Chapter 19
SEM_RDFSA.ENABLE_OLS_POLICY
The sensitivity labels assigned to various RDF resources and triples are preserved and the
OLS policy may be re-enabled to enforce them. New resources with specific labels can be
added, or labels for existing triples and resources can be updated when the OLS policy is
disabled.
To apply an OLS policy, use the SEM_RDFSA.APPLY_OLS_POLICY procedure; to enable
an OLS policy that had been disabled, use the SEM_RDFSA.ENABLE_OLS_POLICY
procedure.
For information about support for OLS, see Fine-Grained Access Control for RDF Data.
For information about semantic network types and options, see Semantic Networks.
Examples
The following example disables the OLS policy for the semantic data store.
begin
sem_rdfsa.disable_ols_policy;
end;
/
19.3 SEM_RDFSA.ENABLE_OLS_POLICY
Format
SEM_RDFSA.ENABLE_OLS_POLICY(
network_owner IN VARCHAR2 DEFAULT NULL,
network_name IN VARCHAR2 DEFAULT NULL);
Description
Enables the OLS policy that has been previously disabled.
Parameters
network_owner
Owner of the semantic network. (See Table 1-1.)
network_name
Name of the semantic network. (See Table 1-1.)
Usage Notes
You can use this procedure to enable the OLS policy that had been disabled for the semantic
data store. The user enabling the policy should have the necessary privileges to administer
OLS policies and should also have access to the OLS policy applied to RDF data.
To disable an OLS policy, use the SEM_RDFSA.DISABLE_OLS_POLICY procedure.
For information about support for OLS, see Fine-Grained Access Control for RDF Data.
For information about support for OLS, see Fine-Grained Access Control for RDF Data.
Examples
The following example enables the OLS policy for the semantic data store.
begin
sem_rdfsa.enable_ols_policy;
19-5
Chapter 19
SEM_RDFSA.REMOVE_OLS_POLICY
end;
/
19.4 SEM_RDFSA.REMOVE_OLS_POLICY
Format
SEM_RDFSA.REMOVE_OLS_POLICY(
network_owner IN VARCHAR2 DEFAULT NULL,
network_name IN VARCHAR2 DEFAULT NULL);
Description
Permanently removes or detaches the OLS policy from the semantic data store.
Parameters
network_owner
Owner of the semantic network. (See Table 1-1.)
network_name
Name of the semantic network. (See Table 1-1.)
Usage Notes
You should have the necessary privileges to administer OLS policies, and you should
also have access to the OLS policy applied to RDF data. Once the OLS policy is
detached from the semantic data store, all the sensitivity labels previously assigned to
the triples and resources are lost.
This operation drops objects that are specifically created to maintain the RDF security
policies.
To apply an OLS policy, use the SEM_RDFSA.APPLY_OLS_POLICY procedure.
For information about support for OLS, see Fine-Grained Access Control for RDF
Data.
For information about semantic network types and options, see Semantic Networks.
Examples
The following example removes the OLS policy that had been previously applied to the
semantic data store.
begin
sem_rdfsa.remove_ols_policy;
end;
/
19.5 SEM_RDFSA.RESET_MODEL_LABELS
Format
SEM_RDFSA.RESET_MODEL_LABELS(
model_name IN VARCHAR2,
network_owner IN VARCHAR2 DEFAULT NULL,
network_name IN VARCHAR2 DEFAULT NULL);
19-6
Chapter 19
SEM_RDFSA.SET_PREDICATE_LABEL
Description
Resets the labels associated with a model or with global resources; requires that the
associated model or models be empty.
Parameters
model_name
Name of the model for which the labels should be reset, or the string RDF$GLOBAL to reset the
labels associated with all global resources.
network_owner
Owner of the semantic network. (See Table 1-1.)
network_name
Name of the semantic network. (See Table 1-1.)
Usage Notes
If you specify a model name, the model must be empty. If you specify RDF$GLOBAL, all the
models must be empty (that is, no triples in the RDF repository).
You must have FULL access privilege with the OLS policy applied to the semantic data store.
For information about support for OLS, see Fine-Grained Access Control for RDF Data.
For information about semantic network types and options, see Semantic Networks.
Examples
The following example removes all resources and their labels associated with the Contracts
model.
begin
sem_rdfsa.reset_model_labels(model_name => 'Contracts');
end;
/
19.6 SEM_RDFSA.SET_PREDICATE_LABEL
Format
SEM_RDFSA.SET_PREDICATE_LABEL(
model_name IN VARCHAR2,
predicate IN VARCHAR2,
label_string IN VARCHAR2,
network_owner IN VARCHAR2 DEFAULT NULL,
network_name IN VARCHAR2 DEFAULT NULL);
Description
Sets a sensitivity label for a predicate at the model level or for the whole repository.
19-7
Chapter 19
SEM_RDFSA.SET_PREDICATE_LABEL
Parameters
model_name
Name of the model to which the predicate belongs, or the string RDF$GLOBAL if the
same label should applied for the use of the predicate in all models.
predicate
Predicate for which the label should be assigned.
label_string
OLS row label in string representation.
network_owner
Owner of the semantic network. (See Table 1-1.)
network_name
Name of the semantic network. (See Table 1-1.)
Usage Notes
If you specify a model name, you must have read access to the model and execute
privileges on the SEM_RDFSA package to perform this operation. If you specify
RDF$GLOBAL, you must have FULL access privilege with the OLS policy applied to RDF
data.
You must have access to the specified label and OLS policy privilege to overwrite an
existing label if a label already exists for the predicate. The SECURE_PREDICATE
option must be enabled for RDF data.
If an existing predicate label is updated with this operation, the labels for the triples
using this predicate must all dominate the new predicate label. The only exception is
when the OPT_RELAX_TRIPLE_LABEL option is chosen for the OLS-enabled RDF
data.
If you specify RDF$GLOBAL, a global predicate with a unique sensitivity label across
models is created. If the same predicate is previously defined in one or more models,
the global label dominates all such labels and the model-specific labels are replaced
for the given predicate.
After a label for a predicate is set, new triples with the predicate can be added only if
the triple label (which may be initialized from user's initial row label or using a label
function) dominates the predicate's sensitivity label. This dominance relationship can
be relaxed with the OPT_RELAX_TRIPLE_LABEL option, in which case the user
should at least have read access to the predicate to be able to define a new triple
using the predicate.
For information about support for OLS, see Fine-Grained Access Control for RDF
Data.
For information about semantic network types and options, see Semantic Networks.
Examples
The following example sets a predicate label for Contracts model and another
predicate label for all models in the database instance.
begin
sem_rdfsa.set_predicate_label(
19-8
Chapter 19
SEM_RDFSA.SET_RDFS_LABEL
begin
sem_rdfsa.set_predicate_label(
model_name => 'rdf$global',
predicate => '<http://www.myorg.com/pred/hasStatus>',
label_string => 'SE:US_SPCL:US');
end;
/
19.7 SEM_RDFSA.SET_RDFS_LABEL
Format
SEM_RDFSA.SET_RDFS_LABEL(
label_string IN VARCHAR2,
inf_override IN VARCHAR2,
network_owner IN VARCHAR2 DEFAULT NULL,
network_name IN VARCHAR2 DEFAULT NULL);
Description
Sets a sensitivity label for RDFS schema elements.
Parameters
label_string
OLS row label in string representation, to be used as the sensitivity label for all RDF schema
constructs.
inf_override
OLS row label to be used as the override for generating labels for inferred triples.
network_owner
Owner of the semantic network. (See Table 1-1.)
network_name
Name of the semantic network. (See Table 1-1.)
Usage Notes
This procedure sets or resets the sensitivity label associated with the RDF schema
resources, often recognized by http://www.w3.org/1999/02/22-rdf-syntax-ns# and
http://www.w3.org/2000/01/rdf-schema# prefixes for their URIs. You can assign a
sensitivity label with restricted access to these resources, so that operations such as creating
new RDF classes and adding new properties can be restricted to users with higher privileges.
You must have FULL access privilege with policy applied to RDF data.
RDF schema elements implicitly use the relaxed triple label option, so that the triples using
RDFS and OWL constructs for subject, predicate, or object are not forced to have a
sensitivity label that dominates the labels associated with the schema constructs. Therefore,
a user capable of defining new RDF classes and properties must least have read access to
the schema elements.
19-9
Chapter 19
SEM_RDFSA.SET_RESOURCE_LABEL
When RDF schema elements are referred to in the inferred triples, the system-defined
and custom label generators consider the inference override label in determining the
appropriate label for the inferred triples. If a custom label generator is used, this
override label is passed instead of the actual label when an RDF schema element is
involved.
For information about support for OLS, see Fine-Grained Access Control for RDF
Data.
For information about semantic network types and options, see Semantic Networks.
Examples
The following example sets a label with a unique compartment for all RDF schema
elements. A user capable of defining new RDF classes and properties is expected to
have an exclusive membership to the compartment.
begin
sem_rdfsa.set_rdfs_label(
label_string => 'SE:RDFS:',
inf_override => 'SE:US_SPCL:US');
end;
/
19.8 SEM_RDFSA.SET_RESOURCE_LABEL
Format
SEM_RDFSA.SET_RESOURCE_LABEL(
model_name IN VARCHAR2,
resource_uri IN VARCHAR2,
label_string IN VARCHAR2,
resource_pos IN VARCHAR2 DEFAULT 'S',
network_owner IN VARCHAR2 DEFAULT NULL,
network_name IN VARCHAR2 DEFAULT NULL);
Description
Sets a sensitivity label for a resource that may be used in the subject and/or object
position of a triple.
Parameters
model_name
Name of the model to which the resource belongs, or the string RDF$GLOBAL if the
same label should applied for using the resource in all models.
resource_uri
URI for the resource that may be used as subject or object in one or more triples.
label_string
OLS row label in string representation.
resource_pos
Position of the resource within a triple: S, O, or S,O. You can specify up to two separate
labels for the same resource, one to be considered when the resource is used in the
subject position of a triple and the other to be considered when it appears in the
19-10
Chapter 19
SEM_RDFSA.SET_RESOURCE_LABEL
object position. The values 'S', 'O' or 'S,O' set a label for the resource in subject, object or both
subject and object positions, respectively.
network_owner
Owner of the semantic network. (See Table 1-1.)
network_name
Name of the semantic network. (See Table 1-1.)
Usage Notes
If you specify a model name, you must have read access to the model and execute privileges
on the SEM_RDFSA package to perform this operation. If you specify RDF$GLOBAL, you must
have FULL access privilege with the OLS policy applied to RDF data.
You must have access to the specified label and OLS policy privilege to overwrite an existing
label if a label already exists for the predicate. The SECURE_PREDICATE option must be
enabled for RDF data.
If an existing resource label is updated with this operation, the labels for the triples using this
resource in the specified position must all dominate the new resource label. The only
exception is when the OPT_RELAX_TRIPLE_LABEL option is chosen for the OLS-enabled
RDF data.
If you specify RDF$GLOBAL, a global resource with a unique sensitivity label across models is
created. If the same resource is previously defined in one or more models with the same
triple position, the global label dominates all such labels and the model-specific labels are
replaced for the given resource in that position.
After a label for a predicate is set, new triples using the resource in the specified position can
be added only if the triple label dominates the resource's sensitivity label. This dominance
relationship can be relaxed with OPT_RELAX_TRIPLE_LABEL option, in which case, the
user should at least have read access to the resource.
For information about support for OLS, see Fine-Grained Access Control for RDF Data.
For information about semantic network types and options, see Semantic Networks.
Examples
The following example sets sensitivity labels for multiple resources based on their position.
begin
sem_rdfsa.set_resource_label(
model_name => 'contracts',
resource_uri => '<http://www.myorg.com/contract/projectHLS>',
label_string => 'SE:US_SPCL:US',
resource_pos => 'S,O');
end;
/
begin
sem_rdfsa.set_resource_label(
model_name => 'rdf$global',
resource_uri => '<http://www.myorg.com/contract/status/Complete>',
label_string => 'SE:US_SPCL:US',
resource_pos => 'O');
end;
/
19-11
Chapter 19
SEM_RDFSA.SET_RULE_LABEL
19.9 SEM_RDFSA.SET_RULE_LABEL
Format
SEM_RDFSA.SET_RULE_LABEL(
rule_base IN VARCHAR2,
rule_name IN VARCHAR2,
label_string IN VARCHAR2,
network_owner IN VARCHAR2 DEFAULT NULL,
network_name IN VARCHAR2 DEFAULT NULL);
Description
Sets sensitivity label for a rule belonging to a rulebase.
Parameters
rule_base
Name of an existing RDF rulebase.
rule_name
Name of the rule belonging to the rulebase.
label_string
OLS row label in string representation.
network_owner
Owner of the semantic network. (See Table 1-1.)
network_name
Name of the semantic network. (See Table 1-1.)
Usage Notes
The sensitivity label assigned to the rule is used to generate the label for the inferred
triples when an appropriate label generator option is chosen.
You must have access have access to the rulebase, and you must have FULL access
privilege with the OLS policy can assign labels for system-defined rules in the RDFS
rulebase.
There is no support for labels assigned to user-defined rules.
For information about support for OLS, see Fine-Grained Access Control for RDF
Data.
For information about semantic network types and options, see Semantic Networks.
Examples
The following example assigns a sensitivity label for an RDFS rule.
begin
sem_rdfsa.set_rule_label (rule_base => 'RDFS',
rule_name => 'RDF-AXIOMS',
label_string => 'SE:US_SPCL:');
end;
/
19-12
Part IV
Appendixes
The following appendixes are included.
A-1
Appendix A
Enabling RDF Semantic Graph Support
A-2
Appendix A
Enabling RDF Semantic Graph Support
If you want to migrate the RDF data and also convert existing empty literals to the new
format, call convert_old_rdf_data with the flags parameter set to
'CONVERT_ORARDF_NULL'. In addition, you can use an optional tablespace_name
parameter to specify the tablespace to use when creating intermediate tables during data
migration. For example, the following statement migrates old semantic data, converts
existing "orardf:null " values to "", and uses the MY_TBS tablespace for any
intermediate tables:
EXECUTE sdo_rdf_internal.convert_old_rdf_data(
flags=>'CONVERT_ORARDF_NULL',
tablespace_name=>'MY_TBS');
Note:
You may encounter the ORA-00904 (invalid identifier) error when executing a
SEM_MATCH query if the sdo_rdf_internal.convert_old_rdf_data procedure
and the semrelod.sql script were not run after the upgrade to Release 12.1 or later.
A-3
Appendix A
Enabling RDF Semantic Graph Support
• NAMESPACE: MDSYS
• ATTRIBUTE: SEM_VERSION
• VALUE: (string starting with 12.2)
• DESCRIPTION: INVALID
To perform data migration by populating new MDSYS.RDF_VALUE$ columns, follow
these steps:
1. 1. Connect to the database as the SYSTEM (not SYS .. AS SYSDBA) user or as
another non-SYS user with the DBA role.
2. Run the following statement:
EXECUTE sem_apis.migrate_data_to_current;
Moreover, additional data migration may be required if you are upgrading an existing
Release 11.1 or 11.2 RDF network containing triples that include typed literal values of
type xsd:float, xsd:double, xsd:boolean, or xsd:time.
To check if you need to perform this additional RDF data migration, connect to the
database as a user with DBA privileges and query the MDSYS.RDF_PARAMETER
table, as follows:
SELECT namespace, attribute, value FROM mdsys.rdf_parameter
WHERE namespace='MDSYS'
AND attribute IN ('FLOAT_DOUBLE_DECIMAL',
'XSD_TIME', 'XSD_BOOLEAN',
'DATA_CONVERSION_CHECK');
A-4
Appendix A
Enabling RDF Semantic Graph Support
If you want to migrate the RDF data and also convert existing empty literals to the new
format, call convert_old_rdf_data with the flags parameter set to
'CONVERT_ORARDF_NULL'. In addition, you can use an optional tablespace_name
parameter to specify the tablespace to use when creating intermediate tables during data
migration. For example, the following statement migrates old semantic data, converts
existing "orardf:null " values to "", and uses the MY_TBS tablespace for any
intermediate tables:
EXECUTE sdo_rdf_internal.convert_old_rdf_data(
flags=>'CONVERT_ORARDF_NULL',
tablespace_name=>'MY_TBS');
A-5
Appendix A
Enabling RDF Semantic Graph Support
Note:
You may encounter the ORA-00904 (invalid identifier) error when executing a
SEM_MATCH query if the sdo_rdf_internal.convert_old_rdf_data
procedure and the semrelod.sql script were not run after the upgrade to
Release 12.1 or later.
If the NULL_LITERAL attribute has the value EXISTS, then "orardf:null" values are
present in your semantic network.
A-6
Appendix A
Downgrading RDF Semantic Graph Support to a Previous Release
Note:
If you are in a multitenant environment, run the script with catcon.pl. See
“Running Oracle-Supplied SQL Scripts in a CDB” in Oracle Database
Administrator’s Guide.
EXECUTE mdsys.sem_rdfsa_dr.uninstall_vpd;
After performing the necessary uninstall operations, reset the network validity as follows:
1. Connect to the database as the SYS user with SYSDBA privileges (SYS AS SYSDBA,
and enter the SYS account password when prompted).
2. Start SQL*Plus, and enter the following statement:
• Linux: @$ORACLE_HOME/md/admin/semvalidate.sql
• Windows: @%ORACLE_HOME%\md\admin\semvalidate.sql
Note:
If you are in a multitenant environment, run the script with catcon.pl. See
“Running Oracle-Supplied SQL Scripts in a CDB” in Oracle Database
Administrator’s Guide.
A-7
Appendix A
Removing RDF Semantic Graph Support
To check if any Release 12.2 or later RDF data is incompatible with Release 12.1,
perform the following steps:
1. Connect to the database (Release 12.2 or later) as the SYS user with SYSDBA
privileges (SYS AS SYSDBA, and enter the SYS account password when
prompted).
2. Start SQL*Plus, and enter the following statements:
SET SERVEROUT ON
EXECUTE SDO_SEM_DOWNGRADE.CHECK_121_COMPATIBLE;
If any RDF data is incompatible with Release 12.1, the procedure generates an error
and displays a list of the incompatible data. In this case, you must perform the
following steps:
1. Remove any Release 12.2 or later release-specific RDF or OWL data if you have
not already done so, as explained earlier in this section.
2. Perform the database downgrade.
3. Connect to the Release 12.1 database as the SYS user with SYSDBA privileges
(SYS AS SYSDBA, and enter the SYS account password when prompted).
4. Start SQL*Plus, and enter the following statement:
• Linux: @$ORACLE_HOME/md/admin/catsem.sql
• Windows: @%ORACLE_HOME%\md\admin\catsem.sql
Note:
If you are in a multitenant environment, run the script with
catcon.pl. See “Running Oracle-Supplied SQL Scripts in a CDB” in
Oracle Database Administrator’s Guide.
If the script completes successfully, a row with the following column values is
inserted into the MDSYS.RDF_PARAMETER table:
• NAMESPACE: MDSYS
• ATTRIBUTE: SEM_VERSION
• VALUE: (string starting with 12.1)
• DESCRIPTION: VALID
After the catsem.sql script completes successfully, Oracle semantic technologies
support for Release 11.2 is enabled and ready to use, and all Release 12.1-
compatible data is preserved.
A-8
Appendix A
Removing RDF Semantic Graph Support
To remove the RDF Semantic Graph support from the database, perform the following steps:
1. Connect to the database as the SYS user with SYSDBA privileges (SYS AS SYSDBA,
and enter the SYS account password when prompted).
2. Start SQL*Plus, and enter the following statement:
• Linux: @$ORACLE_HOME/md/admin/semremov.sql
• Windows: @%ORACLE_HOME%\md\admin\semremov.sql
Note:
If you are in a multitenant environment, run the script with catcon.pl. See
“Running Oracle-Supplied SQL Scripts in a CDB” in Oracle Database
Administrator’s Guide.
The semremov.sql script drops the semantic network and removes any RDF Semantic Graph
types, tables, and PL/SQL packages.
A-9
B
SEM_MATCH Support for Spatial Queries
This appendix provides reference information for SPARQL extension functions for performing
spatial queries in SEM_MATCH.
To use these functions, you must understand the concepts explained in Spatial Support.
Note:
Throughout this appendix geomLiteral is used as a placeholder for
orageo:WKTLiteral, ogc:wktLiteral, ogc:gmlLiteral, ogc:geoJSONLiteral, and
ogc:kmlLiteral, which can be used interchangeably, in format representations and
parameter descriptions. (However, orageo:WKTLiteral or ogc:wktLiteral is used
in actual examples.)
This appendix includes the GeoSPARQL and Oracle-specific functions, which are explained
in the following sections:
• GeoSPARQL Functions for Spatial Support
• Oracle-Specific Functions for Spatial Support
B-1
Appendix B
GeoSPARQL Functions for Spatial Support
• ogcf:concaveHull
• ogcf:convexHull
• ogcf:coordinateDimension
• ogcf:difference
• ogcf:dimension
• ogcf:distance
• ogcf:envelope
• ogcf:geometryN
• ogcf:geometryType
• ogcf:getSRID
• ogcf:intersection
• ogcf:is3D
• ogcf:isEmpty
• ogcf:isMeasured
• ogcf:isSimple
• ogcf:length
• ogcf:maxX
• ogcf:maxY
• ogcf:maxZ
• ogcf:metricArea
• ogcf:metricBuffer
• ogcf:metricLength
• ogcf:metricPerimeter
• ogcf:minX
• ogcf:minY
• ogcf:minZ
• ogcf:numGeometries
• ogcf:perimeter
• ogcf:relate
• ogcf:sfContains
• ogcf:sfCrosses
• ogcf:sfDisjoint
• ogcf:sfEquals
• ogcf:sfIntersects
• ogcf:sfOverlaps
• ogcf:sfTouches
• ogcf:sfWithin
B-2
Appendix B
GeoSPARQL Functions for Spatial Support
• ogcf:spatialDimension
• ogcf:symDifference
• ogcf:transform
• ogcf:union
B.1.1 ogcf:aggBoundingBox
Format
Description
Aggregate that returns a single geometry object that is the minimum bounding box (rectangle)
of the input set of geometries.
Parameters
geom
Geometry object. Specified as a query variable or a constant geomLiteral value.
Usage Notes
See Spatial Support for information about representing, indexing, and querying spatial data in
RDF.
See also the OGC GeoSPARQL specification.
Example
The following example finds the aggregate bounding box of U.S. Congressional district
polygons.
SELECT bb
FROM table(sem_match(
'PREFIX ogc: <http://www.opengis.net/ont/geosparql#>
PREFIX ogcf: <http://www.opengis.net/def/function/geosparql/>
PREFIX orageo: <http://xmlns.oracle.com/rdf/geo/>
PREFIX pol: <http://www.rdfabout.com/rdf/schema/politico/>
PREFIX usgovt: <http://www.rdfabout.com/rdf/schema/usgovt/>
SELECT (ogcf:aggBoundingBox(?cgeom) AS ?bb)
WHERE
{ ?cdist orageo:hasExactGeometry ?cgeom }'
,sem_models('gov_all_vm'), null
, null ,null, null, ' ALLOW_DUP=T '));
B.1.2 ogcf:aggBoundingCircle
Format
B-3
Appendix B
GeoSPARQL Functions for Spatial Support
Description
Aggregate that returns a single geometry object that is the minimum bounding circle of
the input set of geometries.
Parameters
geom
Geometry object. Specified as a query variable or a constant geomLiteral value.
Usage Notes
See Spatial Support for information about representing, indexing, and querying spatial
data in RDF.
See also the OGC GeoSPARQL specification.
Example
The following example finds the aggregate bounding circle of U.S. Congressional
district polygons.
SELECT bc
FROM table(sem_match(
'PREFIX ogc: <http://www.opengis.net/ont/geosparql#>
PREFIX ogcf: <http://www.opengis.net/def/function/geosparql/>
PREFIX orageo: <http://xmlns.oracle.com/rdf/geo/>
PREFIX pol: <http://www.rdfabout.com/rdf/schema/politico/>
PREFIX usgovt: <http://www.rdfabout.com/rdf/schema/usgovt/>
SELECT (ogcf:aggBoundingCircle(?cgeom) AS ?bc)
WHERE
{ ?cdist orageo:hasExactGeometry ?cgeom }'
,sem_models('gov_all_vm'), null
, null ,null, null, ' ALLOW_DUP=T '));
B.1.3 ogcf:aggCentroid
Format
Description
Aggregate that returns a single geometry object that is the centroid (center point) of
the input set of geometries.
Parameters
geom
Geometry object. Specified as a query variable or a constant geomLiteral value.
Usage Notes
See Spatial Support for information about representing, indexing, and querying spatial
data in RDF.
B-4
Appendix B
GeoSPARQL Functions for Spatial Support
Example
The following example finds the aggregate centroid of U.S. Congressional district polygons.
SELECT c
FROM table(sem_match(
'PREFIX ogc: <http://www.opengis.net/ont/geosparql#>
PREFIX ogcf: <http://www.opengis.net/def/function/geosparql/>
PREFIX orageo: <http://xmlns.oracle.com/rdf/geo/>
PREFIX pol: <http://www.rdfabout.com/rdf/schema/politico/>
PREFIX usgovt: <http://www.rdfabout.com/rdf/schema/usgovt/>
SELECT (ogcf:aggCentroid(?cgeom) AS ?c)
WHERE
{ ?cdist orageo:hasExactGeometry ?cgeom }'
,sem_models('gov_all_vm'), null
, null ,null, null, ' ALLOW_DUP=T '));
B.1.4 ogcf:aggConcaveHull
Format
Description
Aggregate that returns a single geometry object that is the concave hull of the input set of
geometries. The concave hull is a polygon that represents the area of the input geometry,
such as a collection of points. With complex input geometries, the concave hull is typically
significantly smaller in area than the convex hull.
Parameters
geom
Geometry object. Specified as a query variable or a constant geomLiteral value.
Usage Notes
See Spatial Support for information about representing, indexing, and querying spatial data in
RDF.
See also the OGC GeoSPARQL specification.
Example
The following example finds the aggregate concave hull of U.S. Congressional district
polygons.
SELECT ch
FROM table(sem_match(
'PREFIX ogc: <http://www.opengis.net/ont/geosparql#>
PREFIX ogcf: <http://www.opengis.net/def/function/geosparql/>
PREFIX orageo: <http://xmlns.oracle.com/rdf/geo/>
PREFIX pol: <http://www.rdfabout.com/rdf/schema/politico/>
PREFIX usgovt: <http://www.rdfabout.com/rdf/schema/usgovt/>
B-5
Appendix B
GeoSPARQL Functions for Spatial Support
B.1.5 ogcf:aggConvexHull
Format
Description
Aggregate that returns a single geometry object that is the convex hull of the input set
of geometries. The convex hull is a simple convex polygon that completely encloses
the geometry object, using as few straight-line sides as possible to create the smallest
polygon that completely encloses the geometry object.
Parameters
geom
Geometry object. Specified as a query variable or a constant geomLiteral value.
Usage Notes
See Spatial Support for information about representing, indexing, and querying spatial
data in RDF.
See also the OGC GeoSPARQL specification.
Example
The following example finds the aggregate convex hull of U.S. Congressional district
polygons.
SELECT ch
FROM table(sem_match(
'PREFIX ogc: <http://www.opengis.net/ont/geosparql#>
PREFIX ogcf: <http://www.opengis.net/def/function/geosparql/>
PREFIX orageo: <http://xmlns.oracle.com/rdf/geo/>
PREFIX pol: <http://www.rdfabout.com/rdf/schema/politico/>
PREFIX usgovt: <http://www.rdfabout.com/rdf/schema/usgovt/>
SELECT (ogcf:aggConvexHull(?cgeom) AS ?ch)
WHERE
{ ?cdist orageo:hasExactGeometry ?cgeom }'
,sem_models('gov_all_vm'), null
, null ,null, null, ' ALLOW_DUP=T '));
B.1.6 ogcf:aggUnion
Format
B-6
Appendix B
GeoSPARQL Functions for Spatial Support
Description
Aggregate that returns a single geometry object that is the topological union of the input set
of geometries.
Parameters
geom
Geometry object. Specified as a query variable or a constant geomLiteral value.
Usage Notes
See Spatial Support for information about representing, indexing, and querying spatial data in
RDF.
See also the OGC GeoSPARQL specification.
Example
The following example finds the aggregate union of U.S. Congressional district polygons.
SELECT u
FROM table(sem_match(
'PREFIX ogc: <http://www.opengis.net/ont/geosparql#>
PREFIX ogcf: <http://www.opengis.net/def/function/geosparql/>
PREFIX orageo: <http://xmlns.oracle.com/rdf/geo/>
PREFIX pol: <http://www.rdfabout.com/rdf/schema/politico/>
PREFIX usgovt: <http://www.rdfabout.com/rdf/schema/usgovt/>
SELECT (ogcf:aggUnion(?cgeom) AS ?u)
WHERE
{ ?cdist orageo:hasExactGeometry ?cgeom }'
,sem_models('gov_all_vm'), null
, null ,null, null, ' ALLOW_DUP=T '));
B.1.7 ogcf:Area
Format
Description
Returns the area of a two-dimensional polygon.
Parameters
geom
Geometry object. Specified as a query variable or a constant geomLiteral value.
units
Unit of measurement:
B-7
Appendix B
GeoSPARQL Functions for Spatial Support
Usage Notes
See Spatial Support for information about representing, indexing, and querying spatial
data in RDF.
See also the OGC GeoSPARQL specification.
Example
The following example finds the area in square meters of each U.S. Congressional
district polygon.
SELECT name, ca
FROM table(sem_match(
'PREFIX ogc: <http://www.opengis.net/ont/geosparql#>
PREFIX ogcf: <http://www.opengis.net/def/function/geosparql/>
PREFIX orageo: <http://xmlns.oracle.com/rdf/geo/>
PREFIX pol: <http://www.rdfabout.com/rdf/schema/politico/>
PREFIX usgovt: <http://www.rdfabout.com/rdf/schema/usgovt/>
SELECT ?name (ogcf:area(?cgeom, <http://qudt.org/vocab/unit/M2>) AS ?
ca)
WHERE
{ ?person usgovt:name ?name .
?person pol:hasRole ?role .
?role pol:forOffice ?office .
?office pol:represents ?cdist .
?cdist orageo:hasExactGeometry ?cgeom }'
,sem_models('gov_all_vm'), null
, null ,null, null, ' ALLOW_DUP=T '));
B.1.8 ogcf:asGeoJSON
Format
Description
Converts geom to an equivalent GeoJSON representation.
Parameters
geom
Geometry object. Specified as a query variable or a constant geomLiteral value.
B-8
Appendix B
GeoSPARQL Functions for Spatial Support
Usage Notes
Converting a geometry to an ogc:geoJSONLiteral will result in a coordinate transformation to
CRS84 Longitude, Latitiude, which is the only coordinate reference system supported by
GeoJSON.
See Spatial Support for information about representing, indexing, and querying spatial data in
RDF.
See also the OGC GeoSPARQL specification.
Example
The following example returns each U.S. Congressional district polygon as an
ogc:geoJSONLiteral.
B.1.9 ogcf:asGML
Format
ogcf:asGML(geom : geomLiteral, gmlProfile : xsd:string) : ogc:gmlLiteral
Description
Converts geom to an equivalent GML representation.
Parameters
geom
Geometry object. Specified as a query variable or a constant geomLiteral value.
gmlProfile
This argument is ignored. GML 3.11 profile is used in all cases.
Usage Notes
See Spatial Support for information about representing, indexing, and querying spatial data in
RDF.
B-9
Appendix B
GeoSPARQL Functions for Spatial Support
Example
The following example returns each U.S. Congressional district polygon as an
ogc:GMLLiteral.
B.1.10 ogcf:asKML
Format
Description
Converts geom to an equivalent KML representation.
Parameters
geom
Geometry object. Specified as a query variable or a constant geomLiteral value.
Usage Notes
Converting a geometry to an ogc:kmlLiteral will result in a coordinate transformation
to CRS84 Longitude, Latitiude, which is the only coordinate reference system
supported by GML.
See Spatial Support for information about representing, indexing, and querying spatial
data in RDF.
See also the OGC GeoSPARQL specification.
B-10
Appendix B
GeoSPARQL Functions for Spatial Support
Example
The following example returns each U.S. Congressional district polygon as an
ogc:kmlLiteral.
B.1.11 ogcf:asWKT
Format
Description
Converts geom to an equivalent WKT representation.
Parameters
geom
Geometry object. Specified as a query variable or a constant geomLiteral value.
Usage Notes
See Spatial Support for information about representing, indexing, and querying spatial data in
RDF.
See also the OGC GeoSPARQL specification.
Example
The following example returns each U.S. Congressional district polygon as an
ogc:wktLiteral.
B-11
Appendix B
GeoSPARQL Functions for Spatial Support
B.1.12 ogcf:boundary
Format
Description
Returns a geometry object that is the closure of the boundary of geom.
Parameters
geom
Geometry object. Specified as a query variable or a constant geomLiteral value.
Usage Notes
See Spatial Support for information about representing, indexing, and querying spatial
data in RDF.
See also the OGC GeoSPARQL specification.
Example
The following example finds the boundaries of U.S. Congressional district polygons.
SELECT cb
FROM table(sem_match(
'PREFIX ogc: <http://www.opengis.net/ont/geosparql#>
PREFIX ogcf: <http://www.opengis.net/def/function/geosparql/>
PREFIX orageo: <http://xmlns.oracle.com/rdf/geo/>
PREFIX pol: <http://www.rdfabout.com/rdf/schema/politico/>
PREFIX usgovt: <http://www.rdfabout.com/rdf/schema/usgovt/>
SELECT (ogcf:boundary(?cgeom) AS ?cb)
WHERE
{ ?person usgovt:name ?name .
?person pol:hasRole ?role .
?role pol:forOffice ?office .
?office pol:represents ?cdist .
?cdist orageo:hasExactGeometry ?cgeom }'
,sem_models('gov_all_vm'), null
,null
,null, null, ' ALLOW_DUP=T '));
B-12
Appendix B
GeoSPARQL Functions for Spatial Support
B.1.13 ogcf:boundingCircle
Format
Description
Returns a geometric object that is the minimum bounding circle around geom.
Parameters
geom
Geometry object. Specified as a query variable or a constant geomLiteral value.
Usage Notes
See Spatial Support for information about representing, indexing, and querying spatial data in
RDF.
See also the OGC GeoSPARQL specification.
Example
The following example returns the minimum bounding circle around each U.S. Congressional
district polygon.
SELECT name, bc
FROM table(sem_match(
'PREFIX ogc: <http://www.opengis.net/ont/geosparql#>
PREFIX ogcf: <http://www.opengis.net/def/function/geosparql/>
PREFIX orageo: <http://xmlns.oracle.com/rdf/geo/>
PREFIX pol: <http://www.rdfabout.com/rdf/schema/politico/>
PREFIX usgovt: <http://www.rdfabout.com/rdf/schema/usgovt/>
SELECT ?name (ogcf:boundingCircle(?cgeom) AS ?bc)
WHERE
{ ?person usgovt:name ?name .
?person pol:hasRole ?role .
?role pol:forOffice ?office .
?office pol:represents ?cdist .
?cdist orageo:hasExactGeometry ?cgeom }'
,sem_models('gov_all_vm'), null
, null ,null, null, ' ALLOW_DUP=T '));
B.1.14 ogcf:buffer
Format
Description
Returns a buffer polygon the specified radius (measured in units) around a geometry.
B-13
Appendix B
GeoSPARQL Functions for Spatial Support
Parameters
geom
Geometry object. Specified as a query variable or a constant geomLiteral value.
radius
Radius value used to define the buffer.
units
Unit of measurement:
• A URI of the form <http://xmlns.oracle.com/rdf/geo/uom/{SDO_UNIT}> (for
example, <http://xmlns.oracle.com/rdf/geo/uom/M>). Any SDO_UNIT value
from the MDSYS.SDO_DIST_UNITS table will be recognized. See the section
about Unit Of Measurement Support in Oracle Spatial Developer's Guide for more
information about unit of measurement specification.
• A URI from the QUDT vocabulary of units that has an equivalent unit in
MDSYS.SDO_DIST_UNITS table. For example, <http://qudt.org/vocab/
unit/M> for meter.
Usage Notes
See Spatial Support for information about representing, indexing, and querying spatial
data in RDF.
See also the OGC GeoSPARQL specification.
Example
The following example finds the U.S. Congressional district polygons that are within a
100–kilometer buffer around a specified point.
B-14
Appendix B
GeoSPARQL Functions for Spatial Support
B.1.15 ogcf:concaveHull
Format
Description
Returns a geometric object that represents the concave hull of geom. The convex hull is a
simple convex polygon that completely encloses the geometry object. Spatial uses as few
straight-line sides as possible to create the smallest polygon that completely encloses the
specified object. A convex hull is a convenient way to get an approximation of a complex
geometry object.
Parameters
geom
Geometry object. Specified as a query variable or a constant geomLiteral value.
Usage Notes
See Spatial Support for information about representing, indexing, and querying spatial data in
RDF.
See also the OGC GeoSPARQL specification.
Example
The following example returns the concave hull of each U.S. Congressional district polygon.
SELECT name, ch
FROM table(sem_match(
'PREFIX ogc: <http://www.opengis.net/ont/geosparql#>
PREFIX ogcf: <http://www.opengis.net/def/function/geosparql/>
PREFIX orageo: <http://xmlns.oracle.com/rdf/geo/>
PREFIX pol: <http://www.rdfabout.com/rdf/schema/politico/>
PREFIX usgovt: <http://www.rdfabout.com/rdf/schema/usgovt/>
SELECT ?name (ogcf:concaveHull(?cgeom) AS ?ch)
WHERE
{ ?person usgovt:name ?name .
?person pol:hasRole ?role .
?role pol:forOffice ?office .
?office pol:represents ?cdist .
?cdist orageo:hasExactGeometry ?cgeom }'
,sem_models('gov_all_vm'), null
, null ,null, null, ' ALLOW_DUP=T '));
B.1.16 ogcf:convexHull
Format
B-15
Appendix B
GeoSPARQL Functions for Spatial Support
Description
Returns a polygon geometry that represents the convex hull of geom. (The convex hull
is a simple convex polygon that completely encloses the geometry object, using as few
straight-line sides as possible to create the smallest polygon that completely encloses
the geometry object.)
Parameters
geom
Geometry object. Specified as a query variable or a constant geomLiteral value.
Usage Notes
See Spatial Support for information about representing, indexing, and querying spatial
data in RDF.
See also the OGC GeoSPARQL specification.
Example
The following example finds the U.S. Congressional district polygons whose convex
hull contains a specified point.
B.1.17 ogcf:coordinateDimension
Format
Description
Returns the coordinate dimension of geom. The coordinate dimension is the number of
measurements or axes needed to describe a position in the coordinate reference
system of geom.
B-16
Appendix B
GeoSPARQL Functions for Spatial Support
Parameters
geom
Geometry object. Specified as a query variable or a constant geomLiteral value.
Usage Notes
See Spatial Support for information about representing, indexing, and querying spatial data in
RDF.
See also the OGC GeoSPARQL specification.
Example
The following example returns the coordinate dimension of each U.S. Congressional district
polygon.
SELECT cdist, cd
FROM table(sem_match(
'PREFIX ogc: <http://www.opengis.net/ont/geosparql#>
PREFIX ogcf: <http://www.opengis.net/def/function/geosparql/>
PREFIX orageo: <http://xmlns.oracle.com/rdf/geo/>
PREFIX pol: <http://www.rdfabout.com/rdf/schema/politico/>
PREFIX usgovt: <http://www.rdfabout.com/rdf/schema/usgovt/>
SELECT ?cdist (ogcf:coordinateDimension(?cgeom) AS ?cd)
WHERE
{ ?cdist orageo:hasExactGeometry ?cgeom }'
,sem_models('gov_all_vm'), null
, null ,null, null, ' ALLOW_DUP=T '));
B.1.18 ogcf:difference
Format
Description
Returns a geometry object that is the topological difference (MINUS operation) of geom1 and
geom2.
Parameters
geom1
Geometry object. Specified as a query variable or a constant geomLiteral value.
geom2
Geometry object. Specified as a query variable or a constant geomLiteral value.
Usage Notes
See Spatial Support for information about representing, indexing, and querying spatial data in
RDF.
See also the OGC GeoSPARQL specification.
B-17
Appendix B
GeoSPARQL Functions for Spatial Support
Example
The following example finds the U.S. Congressional district polygons whose centroid is
within the difference of two specified polygons.
SELECT name, cdist
FROM table(sem_match(
'PREFIX ogc: <http://www.opengis.net/ont/geosparql#>
PREFIX ogcf: <http://www.opengis.net/def/function/geosparql/>
PREFIX orageo: <http://xmlns.oracle.com/rdf/geo/>
PREFIX pol: <http://www.rdfabout.com/rdf/schema/politico/>
PREFIX usgovt: <http://www.rdfabout.com/rdf/schema/usgovt/>
SELECT ?name ?cdist
WHERE
{ ?person usgovt:name ?name .
?person pol:hasRole ?role .
?role pol:forOffice ?office .
?office pol:represents ?cdist .
?cdist orageo:hasExactGeometry ?cgeom
FILTER (ogcf:sfWithin(orageo:centroid(?cgeom),
ogcf:difference(
"Polygon((-83.6 34.1, -83.2 34.1, -83.2 34.5, -83.6 34.5, -83.6
34.1))"^^ogc:wktLiteral,
"Polygon((-83.2 34.3, -83.0 34.3, -83.0 34.5, -83.2 34.5, -83.2
34.3))"^^ogc:wktLiteral))) } '
,sem_models('gov_all_vm'), null
,null, null, null, ' ALLOW_DUP=T '));
B.1.19 ogcf:dimension
Format
Description
Returns the dimension of geom. For example, the dimension of a point is 0, a line is 1,
and a polygon is 2.
.
Parameters
geom
Geometry object. Specified as a query variable or a constant geomLiteral value.
Usage Notes
See Spatial Support for information about representing, indexing, and querying spatial
data in RDF.
See also the OGC GeoSPARQL specification.
B-18
Appendix B
GeoSPARQL Functions for Spatial Support
Example
The following example returns the dimension of each U.S. Congressional district polygon.
SELECT cdist, cd
FROM table(sem_match(
'PREFIX ogc: <http://www.opengis.net/ont/geosparql#>
PREFIX ogcf: <http://www.opengis.net/def/function/geosparql/>
PREFIX orageo: <http://xmlns.oracle.com/rdf/geo/>
PREFIX pol: <http://www.rdfabout.com/rdf/schema/politico/>
PREFIX usgovt: <http://www.rdfabout.com/rdf/schema/usgovt/>
SELECT ?cdist (ogcf:dimension(?cgeom) AS ?cd)
WHERE
{ ?cdist orageo:hasExactGeometry ?cgeom }'
,sem_models('gov_all_vm'), null
, null ,null, null, ' ALLOW_DUP=T '));
B.1.20 ogcf:distance
Format
Description
Returns the distance in units between the two closest points of geom1 and geom2.
Parameters
geom1
Geometry object. Specified as a query variable or a constant geomLiteral value.
geom2
Geometry object. Specified as a query variable or a constant geomLiteral value.
units
Unit of measurement:
• A URI of the form <http://xmlns.oracle.com/rdf/geo/uom/{SDO_UNIT}> (for example,
<http://xmlns.oracle.com/rdf/geo/uom/KM>). Any SDO_UNIT value from the
MDSYS.SDO_DIST_UNITS table will be recognized. See the section about unit of
measurement support in Oracle Spatial and Graph Developer's Guide for more
information about unit of measurement specification.
• A URI from the QUDT vocabulary of units that has an equivalent unit in
MDSYS.SDO_DIST_UNITS table. For example, <http://qudt.org/vocab/unit/M> for
meter.
Usage Notes
See Spatial Support for information about representing, indexing, and querying spatial data in
RDF.
See also the OGC GeoSPARQL specification.
B-19
Appendix B
GeoSPARQL Functions for Spatial Support
Example
The following example orders U.S. Congressional districts based on distance from a
specified point.
B.1.21 ogcf:envelope
Format
Description
Returns the minimum bounding rectangle (MBR) of geom, that is, the single rectangle
that minimally encloses geom.
Parameters
geom
Geometry object. Specified as a query variable or a constant geomLiteral value.
Usage Notes
See Spatial Support for information about representing, indexing, and querying spatial
data in RDF.
See also the OGC GeoSPARQL specification.
B-20
Appendix B
GeoSPARQL Functions for Spatial Support
Example
The following example finds the U.S. Congressional district polygons whose minimum
bounding rectangle contains a specified point.
B.1.22 ogcf:geometryN
Format
Description
Returns the nth geometry of geom if geom is a geometry collection or geom if geom is a single
geometry and n=1.
Parameters
geom
Geometry object. Specified as a query variable or a constant geomLiteral value.
geomindex
The position of the desired geometry in the collection. The first geometry has an index of 1.
Usage Notes
See Spatial Support for information about representing, indexing, and querying spatial data in
RDF.
See also the OGC GeoSPARQL specification.
B-21
Appendix B
GeoSPARQL Functions for Spatial Support
Example
The following example returns the second geometry in the input geometry collection.
SELECT g
FROM table(sem_match(
'PREFIX ogc: <http://www.opengis.net/ont/geosparql#>
PREFIX ogcf: <http://www.opengis.net/def/function/geosparql/>
PREFIX orageo: <http://xmlns.oracle.com/rdf/geo/>
PREFIX pol: <http://www.rdfabout.com/rdf/schema/politico/>
PREFIX usgovt: <http://www.rdfabout.com/rdf/schema/usgovt/>
SELECT (ogcf:geometryN("GEOMETRYCOLLECTION(POINT(-75 44),
LINESTRING(-75 44, -75 45),
POLYGON((-75 44, -75 43, -74 43, -74 44, -75
44)))"^^ogc:wktLiteral, 2) AS ?g)
WHERE
{ }'
,sem_models('gov_all_vm'), null
, null ,null, null, ' ALLOW_DUP=T '));
B.1.23 ogcf:geometryType
Format
Description
Returns the URI of the subtype of <http://www.opengis.net/ont/sf#Geometry> of
which geom is a member. Possible return values are:
• <http://www.opengis.net/ont/sf#Point>
• <http://www.opengis.net/ont/sf#LineString>
• <http://www.opengis.net/ont/sf#Polygon>
• <http://www.opengis.net/ont/sf#GeometryCollection>
• <http://www.opengis.net/ont/sf#MultiPoint>
• <http://www.opengis.net/ont/sf#MultiLineString>
• <http://www.opengis.net/ont/sf#MultiPolygon>
• <http://www.opengis.net/ont/sf#Solid>
• <http://www.opengis.net/ont/sf#MultiSolid>
• <http://www.opengis.net/ont/sf#Unknown>
Parameters
geom
Geometry object. Specified as a query variable or a constant geomLiteral value.
B-22
Appendix B
GeoSPARQL Functions for Spatial Support
Usage Notes
See Spatial Support for information about representing, indexing, and querying spatial data in
RDF.
See also the OGC GeoSPARQL specification.
Example
The following example returns the geometry type of each U.S. Congressional district polygon.
B.1.24 ogcf:getSRID
Format
Description
Returns the spatial reference system URI for geom.
Parameters
geom
Geometry object. Specified as a query variable or a constant geomLiteral value.
Usage Notes
The URI returned has the form <http://www.opengis.net/def/crs/EPSG/0/{srid}>, where
{srid} is a valid spatial reference system ID from the European Petroleum Survey Group
(EPSG).
For URIs that are not in the EPSG Geodetic Parameter Dataset, the URI returned has the
form <http://xmlns.oracle.com/rdf/geo/srid/{srid}> , where {srid} is a valid spatial
reference system ID from Oracle Spatial and Graph.
For the default spatial reference system, WGS84 Longitude-Latitude, the URI <http://
www.opengis.net/def/crs/OGC/1.3/CRS84> is returned.
See Spatial Support for information about representing, indexing, and querying spatial data in
RDF.
See also the OGC GeoSPARQL specification.
B-23
Appendix B
GeoSPARQL Functions for Spatial Support
Example
The following example finds spatial reference system URIs for U.S. Congressional
district polygons.
SELECT csrid
FROM table(sem_match(
'PREFIX ogc: <http://www.opengis.net/ont/geosparql#>
PREFIX ogcf: <http://www.opengis.net/def/function/geosparql/>
PREFIX orageo: <http://xmlns.oracle.com/rdf/geo/>
PREFIX pol: <http://www.rdfabout.com/rdf/schema/politico/>
PREFIX usgovt: <http://www.rdfabout.com/rdf/schema/usgovt/>
SELECT (ogcf:getSRID(?cgeom) AS ?csrid)
WHERE
{ ?person usgovt:name ?name .
?person pol:hasRole ?role .
?role pol:forOffice ?office .
?office pol:represents ?cdist .
?cdist orageo:hasExactGeometry ?cgeom }'
,sem_models('gov_all_vm'), null
,null, null, null, ' ALLOW_DUP=T '));
B.1.25 ogcf:intersection
Format
Description
Returns a geometry object that is the topological intersection (AND operation) of geom1
and geom2.
Parameters
geom1
Geometry object. Specified as a query variable or a constant geomLiteral value.
geom2
Geometry object. Specified as a query variable or a constant geomLiteral value.
Usage Notes
See Spatial Support for information about representing, indexing, and querying spatial
data in RDF.
See also the OGC GeoSPARQL specification.
Example
The following example finds the U.S. Congressional district polygons whose centroid is
within the intersection of two specified polygons.
B-24
Appendix B
GeoSPARQL Functions for Spatial Support
B.1.26 ogcf:is3D
Format
Description
Returns true if the spatial dimension of geom is 3.
Parameters
geom
Geometry object. Specified as a query variable or a constant geomLiteral value.
Usage Notes
See Spatial Support for information about representing, indexing, and querying spatial data in
RDF.
See also the OGC GeoSPARQL specification.
Example
The following example checks to see if there are any 3-dimensional U.S. Congressional
district polygons.
SELECT ask
FROM table(sem_match(
'PREFIX ogc: <http://www.opengis.net/ont/geosparql#>
PREFIX ogcf: <http://www.opengis.net/def/function/geosparql/>
PREFIX orageo: <http://xmlns.oracle.com/rdf/geo/>
PREFIX pol: <http://www.rdfabout.com/rdf/schema/politico/>
PREFIX usgovt: <http://www.rdfabout.com/rdf/schema/usgovt/>
B-25
Appendix B
GeoSPARQL Functions for Spatial Support
ASK
WHERE
{ ?cdist orageo:hasExactGeometry ?cgeom
FILTER(ogcf:is3D(?cgeom)) }'
,sem_models('gov_all_vm'), null
, null ,null, null, ' ALLOW_DUP=T '));
B.1.27 ogcf:isEmpty
Format
Description
Returns true if geom is an empty geometry.
Parameters
geom
Geometry object. Specified as a query variable or a constant geomLiteral value.
Usage Notes
See Spatial Support for information about representing, indexing, and querying spatial
data in RDF.
See also the OGC GeoSPARQL specification.
Example
The following example checks to see if there are any empty U.S. Congressional district
geometries.
SELECT ask
FROM table(sem_match(
'PREFIX ogc: <http://www.opengis.net/ont/geosparql#>
PREFIX ogcf: <http://www.opengis.net/def/function/geosparql/>
PREFIX orageo: <http://xmlns.oracle.com/rdf/geo/>
PREFIX pol: <http://www.rdfabout.com/rdf/schema/politico/>
PREFIX usgovt: <http://www.rdfabout.com/rdf/schema/usgovt/>
ASK
WHERE
{ ?cdist orageo:hasExactGeometry ?cgeom
FILTER(ogcf:isEmpty(?cgeom)) }'
,sem_models('gov_all_vm'), null
, null ,null, null, ' ALLOW_DUP=T '));
B.1.28 ogcf:isMeasured
Format
B-26
Appendix B
GeoSPARQL Functions for Spatial Support
Description
Returns true if geom has a measure value.
Parameters
geom
Geometry object. Specified as a query variable or a constant geomLiteral value.
Usage Notes
See Spatial Support for information about representing, indexing, and querying spatial data in
RDF.
See also the OGC GeoSPARQL specification.
Example
The following example checks to see if there are any U.S. Congressional district geometries
with measure values.
SELECT ask
FROM table(sem_match(
'PREFIX ogc: <http://www.opengis.net/ont/geosparql#>
PREFIX ogcf: <http://www.opengis.net/def/function/geosparql/>
PREFIX orageo: <http://xmlns.oracle.com/rdf/geo/>
PREFIX pol: <http://www.rdfabout.com/rdf/schema/politico/>
PREFIX usgovt: <http://www.rdfabout.com/rdf/schema/usgovt/>
ASK
WHERE
{ ?cdist orageo:hasExactGeometry ?cgeom
FILTER(ogcf:isMeasured(?cgeom)) }'
,sem_models('gov_all_vm'), null
, null ,null, null, ' ALLOW_DUP=T '));
B.1.29 ogcf:isSimple
Format
Description
Returns true if geom is a simple geometry. That is, the geometry has no inconsistent features
such as self intersection, identical consecutive vertices, and so on.
Parameters
geom
Geometry object. Specified as a query variable or a constant geomLiteral value.
Usage Notes
See Spatial Support for information about representing, indexing, and querying spatial data in
RDF.
B-27
Appendix B
GeoSPARQL Functions for Spatial Support
Example
The following example returns any non-simple Congressional district geometries.
B.1.30 ogcf:length
Format
Description
Returns the length of the geom. The length is the maximum distance between any two
points in the geom.
Parameters
geom
Geometry object. Specified as a query variable or a constant geomLiteral value.
units
Unit of measurement:
• A URI of the form <http://xmlns.oracle.com/rdf/geo/uom/{SDO_UNIT}> (for
example, <http://xmlns.oracle.com/rdf/geo/uom/M>). Any SDO_UNIT value
from the MDSYS.SDO_DISTANCE_UNITS table will be recognized. See the
section about Unit Of Measurement Support in Oracle Spatial Developer's Guide
for more information about unit of measurement specification.
• A URI from the QUDT vocabulary of units that has an equivalent unit in
MDSYS.SDO_DISTANCE_UNITS table. For example, <http://qudt.org/vocab/
unit/M> for meter.
B-28
Appendix B
GeoSPARQL Functions for Spatial Support
Usage Notes
See Spatial Support for information about representing, indexing, and querying spatial data in
RDF.
See also the OGC GeoSPARQL specification.
Example
The following example finds the maximum length in meters of the longest U.S. Congressional
district.
SELECT maxl
FROM table(sem_match(
'PREFIX ogc: <http://www.opengis.net/ont/geosparql#>
PREFIX ogcf: <http://www.opengis.net/def/function/geosparql/>
PREFIX orageo: <http://xmlns.oracle.com/rdf/geo/>
PREFIX pol: <http://www.rdfabout.com/rdf/schema/politico/>
PREFIX usgovt: <http://www.rdfabout.com/rdf/schema/usgovt/>
SELECT (max(ogcf:length(?cgeom, <http://qudt.org/vocab/unit/M>)) AS ?maxl)
WHERE
{ ?cdist orageo:hasExactGeometry ?cgeom }'
,sem_models('gov_all_vm'), null
, null ,null, null, ' ALLOW_DUP=T '));
B.1.31 ogcf:maxX
Format
Description
Returns the maximum X coordinate value for geom.
Parameters
geom
Geometry object. Specified as a query variable or a constant geomLiteral value.
Usage Notes
See Spatial Support for information about representing, indexing, and querying spatial data in
RDF.
See also the OGC GeoSPARQL specification.
Example
The following example finds the maximum X coordinate value for each U.S. Congressional
district.
B-29
Appendix B
GeoSPARQL Functions for Spatial Support
B.1.32 ogcf:maxY
Format
Description
Returns the maximum Y coordinate value for geom.
Parameters
geom
Geometry object. Specified as a query variable or a constant geomLiteral value.
Usage Notes
See Spatial Support for information about representing, indexing, and querying spatial
data in RDF.
See also the OGC GeoSPARQL specification.
Example
The following example finds the maximum Y coordinate value for each U.S.
Congressional district.
B-30
Appendix B
GeoSPARQL Functions for Spatial Support
B.1.33 ogcf:maxZ
Format
Description
Returns the maximum Z coordinate value for geom.
Parameters
geom
Geometry object. Specified as a query variable or a constant geomLiteral value.
Usage Notes
See Spatial Support for information about representing, indexing, and querying spatial data in
RDF.
See also the OGC GeoSPARQL specification.
Example
The following example finds the maximum Z coordinate value for a constant geometry.
SELECT maxZ
FROM table(sem_match(
'PREFIX ogc: <http://www.opengis.net/ont/geosparql#>
PREFIX ogcf: <http://www.opengis.net/def/function/geosparql/>
PREFIX orageo: <http://xmlns.oracle.com/rdf/geo/>
PREFIX pol: <http://www.rdfabout.com/rdf/schema/politico/>
PREFIX usgovt: <http://www.rdfabout.com/rdf/schema/usgovt/>
SELECT (ogcf:maxZ("<http://www.opengis.net/def/crs/EPSG/0/4327>
POLYGON((-75 44 10, -75 43 11,
-74 43 11, -74 44 11, -75 44 10))"^^ogc:wktLiteral) AS ?maxZ)
WHERE
{ }'
,sem_models('gov_all_vm'), null
, null ,null, null, ' ALLOW_DUP=T '));
B.1.34 ogcf:metricArea
Format
Description
Returns the area of geom in square meters.
B-31
Appendix B
GeoSPARQL Functions for Spatial Support
Parameters
geom
Geometry object. Specified as a query variable or a constant geomLiteral value.
Usage Notes
See Spatial Support for information about representing, indexing, and querying spatial
data in RDF.
See also the OGC GeoSPARQL specification.
Example
The following example finds the area in square meters for each U.S. Congressional
district.
SELECT name, ma
FROM table(sem_match(
'PREFIX ogc: <http://www.opengis.net/ont/geosparql#>
PREFIX ogcf: <http://www.opengis.net/def/function/geosparql/>
PREFIX orageo: <http://xmlns.oracle.com/rdf/geo/>
PREFIX pol: <http://www.rdfabout.com/rdf/schema/politico/>
PREFIX usgovt: <http://www.rdfabout.com/rdf/schema/usgovt/>
SELECT ?name (ogcf:metricArea(?cgeom) AS ?ma)
WHERE
{ ?person usgovt:name ?name .
?person pol:hasRole ?role .
?role pol:forOffice ?office .
?office pol:represents ?cdist .
?cdist orageo:hasExactGeometry ?cgeom }'
,sem_models('gov_all_vm'), null
, null ,null, null, ' ALLOW_DUP=T '));
B.1.35 ogcf:metricBuffer
Format
Description
Returns a buffer polygon with the specified radius in meters around a geometry.
Parameters
geom
Geometry object. Specified as a query variable or a constant geomLiteral value.
radius
Radius value in meters used to define the buffer.
B-32
Appendix B
GeoSPARQL Functions for Spatial Support
Usage Notes
See Spatial Support for information about representing, indexing, and querying spatial data in
RDF.
See also the OGC GeoSPARQL specification.
Example
The following example finds the U.S. Congressional district polygons that are within a 1000–
meter buffer around a specified point.
B.1.36 ogcf:metricLength
Format
Description
Returns the length of geom in meters. The length is the maximum distance between any two
points in geom.
Parameters
geom
Geometry object. Specified as a query variable or a constant geomLiteral value.
B-33
Appendix B
GeoSPARQL Functions for Spatial Support
Usage Notes
See Spatial Support for information about representing, indexing, and querying spatial
data in RDF.
See also the OGC GeoSPARQL specification.
Example
The following example finds the maximum length in meters of the longest U.S.
Congressional district.
B.1.37 ogcf:metricPerimeter
Format
Description
Returns the length of the outer boundary of geom in meters.
Parameters
geom
Geometry object. Specified as a query variable or a constant geomLiteral value.
Usage Notes
See Spatial Support for information about representing, indexing, and querying spatial
data in RDF.
See also the OGC GeoSPARQL specification.
Example
The following example finds the maximum perimeter in meters across the set of U.S.
Congressional districts.
B-34
Appendix B
GeoSPARQL Functions for Spatial Support
B.1.38 ogcf:minX
Format
Description
Returns the minimum X coordinate value for geom.
Parameters
geom
Geometry object. Specified as a query variable or a constant geomLiteral value.
Usage Notes
See Spatial Support for information about representing, indexing, and querying spatial data in
RDF.
See also the OGC GeoSPARQL specification.
Example
The following example finds the minimum X coordinate value for each U.S. Congressional
district.
B-35
Appendix B
GeoSPARQL Functions for Spatial Support
B.1.39 ogcf:minY
Format
Description
Returns the minimum Y coordinate value for geom.
Parameters
geom
Geometry object. Specified as a query variable or a constant geomLiteral value.
Usage Notes
See Spatial Support for information about representing, indexing, and querying spatial
data in RDF.
See also the OGC GeoSPARQL specification.
Example
The following example finds the minimum Y coordinate value for each U.S.
Congressional district.
B.1.40 ogcf:minZ
Format
Description
Returns the minimum Z coordinate value for geom.
B-36
Appendix B
GeoSPARQL Functions for Spatial Support
Parameters
geom
Geometry object. Specified as a query variable or a constant geomLiteral value.
Usage Notes
See Spatial Support for information about representing, indexing, and querying spatial data in
RDF.
See also the OGC GeoSPARQL specification.
Example
The following example finds the minimum Z coordinate value for a constant geometry.
SELECT minZ
FROM table(sem_match(
'PREFIX ogc: <http://www.opengis.net/ont/geosparql#>
PREFIX ogcf: <http://www.opengis.net/def/function/geosparql/>
PREFIX orageo: <http://xmlns.oracle.com/rdf/geo/>
PREFIX pol: <http://www.rdfabout.com/rdf/schema/politico/>
PREFIX usgovt: <http://www.rdfabout.com/rdf/schema/usgovt/>
SELECT (ogcf:minZ("<http://www.opengis.net/def/crs/EPSG/0/4327>
POLYGON((-75 44 10, -75 43 11, -74 43 11,
-74 44 11, -75 44 10))"^^ogc:wktLiteral) AS ?minZ)
WHERE
{ }'
,sem_models('gov_all_vm'), null
, null ,null, null, ' ALLOW_DUP=T '));
B.1.41 ogcf:numGeometries
Format
Description
Returns the number of geometries in geom.
Parameters
geom
Geometry object. Specified as a query variable or a constant geomLiteral value.
Usage Notes
See Spatial Support for information about representing, indexing, and querying spatial data in
RDF.
See also the OGC GeoSPARQL specification.
B-37
Appendix B
GeoSPARQL Functions for Spatial Support
Example
The following example finds the number of geometries in a constant geometry
collection.
SELECT ng
FROM table(sem_match(
'PREFIX ogc: <http://www.opengis.net/ont/geosparql#>
PREFIX ogcf: <http://www.opengis.net/def/function/geosparql/>
PREFIX orageo: <http://xmlns.oracle.com/rdf/geo/>
PREFIX pol: <http://www.rdfabout.com/rdf/schema/politico/>
PREFIX usgovt: <http://www.rdfabout.com/rdf/schema/usgovt/>
SELECT (ogcf:numGeometries("GEOMETRYCOLLECTION(POINT(-75 44),
LINESTRING(-75 44, -75 45), POLYGON((-75 44, -75 43, -74 43, -74 44,
-75 44)))"^^ogc:wktLiteral) AS ?ng)
WHERE
{ }'
,sem_models('gov_all_vm'), null
, null ,null, null, ' ALLOW_DUP=T '));
B.1.42 ogcf:perimeter
Format
Description
Returns the length of the outer boundary of geom measured in units.
Parameters
geom
Geometry object. Specified as a query variable or a constant geomLiteral value.
units
Unit of measurement:
• A URI of the form <http://xmlns.oracle.com/rdf/geo/uom/{SDO_UNIT}> (for
example, <http://xmlns.oracle.com/rdf/geo/uom/M>). Any SDO_UNIT value
from the MDSYS.SDO_DISTANCE_UNITS table will be recognized. See the
section about Unit Of Measurement Support in Oracle Spatial Developer's Guide
for more information about unit of measurement specification.
• A URI from the QUDT vocabulary of units that has an equivalent unit in
MDSYS.SDO_DISTANCE_UNITS table. For example, <http://qudt.org/vocab/
unit/M> for meter.
Usage Notes
See Spatial Support for information about representing, indexing, and querying spatial
data in RDF.
See also the OGC GeoSPARQL specification.
B-38
Appendix B
GeoSPARQL Functions for Spatial Support
Example
The following example finds the maximum perimeter in meters across the set of U.S.
Congressional districts.
SELECT maxp
FROM table(sem_match(
'PREFIX ogc: <http://www.opengis.net/ont/geosparql#>
PREFIX ogcf: <http://www.opengis.net/def/function/geosparql/>
PREFIX orageo: <http://xmlns.oracle.com/rdf/geo/>
PREFIX pol: <http://www.rdfabout.com/rdf/schema/politico/>
PREFIX usgovt: <http://www.rdfabout.com/rdf/schema/usgovt/>
SELECT (max(ogcf:perimeter(?cgeom, <http://qudt.org/vocab/unit/M>)) AS ?
maxp)
WHERE
{ ?cdist orageo:hasExactGeometry ?cgeom }'
,sem_models('gov_all_vm'), null
, null ,null, null, ' ALLOW_DUP=T '));
B.1.43 ogcf:relate
Format
Description
Returns true if the topological relationship between geom1 and geom2 satisfies the specified
DE-9IM pattern-matrix. Returns false otherwise.
Parameters
geom1
Geometry object. Specified as a query variable or a constant geomLiteral value.
geom2
Geometry object. Specified as a query variable or a constant geomLiteral value.
pattern-matrix
A dimensionally extended 9-intersection model (DE-9IM) intersection pattern string
consisting of T (true) and F (false) values. A DE-9IM pattern string describes the
intersections between the interiors, boundaries, and exteriors of two geometries.
Usage Notes
When invoking ogcf:relate with a query variable and a constant geometry, always use the
query variable as the first parameter and the constant geometry as the second parameter.
For best performance, geom1 should be a local variable (that is, a variable that appears in the
basic graph pattern that contains the ogcf:relate spatial filter).
It is recommended to use a LEADING(?var) HINT0 hint when the query involves a restrictive
ogcf:relate spatial filter on ?var.
B-39
Appendix B
GeoSPARQL Functions for Spatial Support
See Spatial Support for information about representing, indexing, and querying spatial
data in RDF.
See the OGC Simple Features Specification (OGC 06-103r3) for a detailed description
of DE-9IM intersection patterns. See also the OGC GeoSPARQL specification.
Example
The following example finds the U.S. Congressional district that contains a specified
point.
B.1.44 ogcf:sfContains
Format
ogcf:sfContains(geom1 : geomLiteral, geom2 : geomLiteral) : xsd:boolean
Description
Returns true if geom1 spatially contains geom2 as defined by the OGC Simple Features
specification (OGC 06-103r3). Returns false otherwise.
Parameters
geom1
Geometry object. Specified as a query variable or a constant geomLiteral value.
geom2
Geometry object. Specified as a query variable or a constant geomLiteral value.
B-40
Appendix B
GeoSPARQL Functions for Spatial Support
Usage Notes
When invoking this function with a query variable and a constant geometry, always use the
query variable as the first parameter and the constant geometry as the second parameter.
For best performance, geom1 should be a local variable (that is, a variable that appears in the
basic graph pattern that contains the ogcf:sfContains spatial filter).
It is recommended to use a LEADING(?var) HINT0 hint when the query involves a restrictive
ogcf:sfContains spatial filter on ?var.
See Spatial Support for information about representing, indexing, and querying spatial data in
RDF.
See also the OGC GeoSPARQL specification.
Example
The following example finds U.S. Congressional district polygons that spatially contain a
constant polygon.
B.1.45 ogcf:sfCrosses
Format
Description
Returns true if geom1 spatially crosses geom2 as defined by the OGC Simple Features
specification (OGC 06-103r3). Returns false otherwise.
B-41
Appendix B
GeoSPARQL Functions for Spatial Support
Parameters
geom1
Geometry object. Specified as a query variable or a constant geomLiteral value.
geom2
Geometry object. Specified as a query variable or a constant geomLiteral value.
Usage Notes
When invoking this function with a query variable and a constant geometry, always use
the query variable as the first parameter and the constant geometry as the second
parameter.
For best performance, geom1 should be a local variable (that is, a variable that appears
in the basic graph pattern that contains the ogcf:sfCrosses spatial filter).
See Spatial Support for information about representing, indexing, and querying spatial
data in RDF.
See also the OGC GeoSPARQL specification.
Example
The following example finds U.S. Congressional district polygons that spatially cross a
constant polygon.
B-42
Appendix B
GeoSPARQL Functions for Spatial Support
B.1.46 ogcf:sfDisjoint
Format
Description
Returns true if the two geometries are spatially disjoint as defined by the OGC Simple
Features specification (OGC 06-103r3). Returns false otherwise.
Parameters
geom1
Geometry object. Specified as a query variable or a constant geomLiteral value.
geom2
Geometry object. Specified as a query variable or a constant geomLiteral value.
Usage Notes
The ogcf:sfDisjoint filter cannot use a spatial index for evaluation, so performance will
probably be much worse than with other simple features spatial functions.
See also the OGC GeoSPARQL specification.
Example
The following example finds U.S. Congressional district polygons that are spatially disjoint
from a constant polygon.
B-43
Appendix B
GeoSPARQL Functions for Spatial Support
B.1.47 ogcf:sfEquals
Format
Description
Returns true if the two geometries are spatially equal as defined by the OGC Simple
Features specification (OGC 06-103r3). Returns false otherwise.
Parameters
geom1
Geometry object. Specified as a query variable or a constant geomLiteral value.
geom2
Geometry object. Specified as a query variable or a constant geomLiteral value.
Usage Notes
When invoking this function with a query variable and a constant geometry, always use
the query variable as the first parameter and the constant geometry as the second
parameter.
For best performance, geom1 should be a local variable (that is, a variable that appears
in the basic graph pattern that contains the ogcf:sfEquals spatial filter).
See Spatial Support for information about representing , indexing, and querying spatial
data in RDF.
See also the OGC GeoSPARQL specification.
Example
The following example finds U.S. Congressional district polygons that are spatially
equal to a constant polygon.
B-44
Appendix B
GeoSPARQL Functions for Spatial Support
FILTER (ogcf:sfEquals(?cgeom,
"Polygon((-83.6 34.1, -83.2 34.1, -83.2 34.5, -83.6 34.5, -83.6
34.1))"^^ogc:wktLiteral)) } '
,sem_models('gov_all_vm'), null
,null, null, null, ' ALLOW_DUP=T '));
B.1.48 ogcf:sfIntersects
Format
Description
Returns true if the two geometries are not disjoint as defined by the OGC Simple Features
specification (OGC 06-103r3). Returns false otherwise.
Parameters
geom1
Geometry object. Specified as a query variable or a constant geomLiteral value.
geom2
Geometry object. Specified as a query variable or a constant geomLiteral value.
Usage Notes
When invoking this function with a query variable and a constant geometry, always use the
query variable as the first parameter and the constant geometry as the second parameter.
For best performance, geom1 should be a local variable (that is, a variable that appears in the
basic graph pattern that contains the ogcf:sfIntersects spatial filter).
It is recommended to use a LEADING(?var) HINT0 hint when the query involves a restrictive
ogcf:sfIntersects spatial filter on ?var.
See Spatial Support for information about representing, indexing, and querying spatial data in
RDF.
See also the OGC GeoSPARQL specification.
Example
The following example finds U.S. Congressional district polygons that intersect a constant
polygon.
B-45
Appendix B
GeoSPARQL Functions for Spatial Support
B.1.49 ogcf:sfOverlaps
Format
Description
Returns true if geom1 spatially overlaps geom2 as defined by the OGC Simple Features
specification (OGC 06-103r3). Returns false otherwise.
Parameters
geom1
Geometry object. Specified as a query variable or a constant geomLiteral value.
geom2
Geometry object. Specified as a query variable or a constant geomLiteral value.
Usage Notes
When invoking this function with a query variable and a constant geometry, always use
the query variable as the first parameter and the constant geometry as the second
parameter.
For best performance, geom1 should be a local variable (that is, a variable that appears
in the basic graph pattern that contains the ogcf:sfOverlaps spatial filter).
See Spatial Support for information about representing, indexing, and querying spatial
data in RDF.
See also the OGC GeoSPARQL specification.
Example
The following example finds U.S. Congressional district polygons that spatially overlap
a constant polygon.
B-46
Appendix B
GeoSPARQL Functions for Spatial Support
B.1.50 ogcf:sfTouches
Format
ogcf:sfTouches(geom1 : geomLiteral, geom2 : geomLiteral) : xsd:boolean
Description
Returns true if the two geometries spatially touch as defined by the OGC Simple Features
specification (OGC 06-103r3). Returns false otherwise.
Parameters
geom1
Geometry object. Specified as a query variable or a constant geomLiteral value.
geom2
Geometry object. Specified as a query variable or a constant geomLiteral value.
Usage Notes
When invoking this function with a query variable and a constant geometry, always use the
query variable as the first parameter and the constant geometry as the second parameter.
For best performance, geom1 should be a local variable (that is, a variable that appears in the
basic graph pattern that contains the ogcf:sfTouches spatial filter).
It is recommended to use a LEADING(?var) HINT0 hint when the query involves a restrictive
ogcf:sfTouches spatial filter on ?var.
See Spatial Support for information about representing, indexing, and querying spatial data in
RDF.
See also the OGC GeoSPARQL specification.
B-47
Appendix B
GeoSPARQL Functions for Spatial Support
Example
The following example finds U.S. Congressional district polygons that spatially touch a
constant polygon.
B.1.51 ogcf:sfWithin
Format
Description
Returns true if geom1 is spatially within geom2 as defined by the OGC Simple Features
specification (OGC 06-103r3). Returns false otherwise.
Parameters
geom1
Geometry object. Specified as a query variable or a constant geomLiteral value.
geom2
Geometry object. Specified as a query variable or a constant geomLiteral value.
Usage Notes
When invoking this function with a query variable and a constant geometry, always use
the query variable as the first parameter and the constant geometry as the second
parameter.
For best performance, geom1 should be a local variable (that is, a variable that appears
in the basic graph pattern that contains the ogcf:sfWithin spatial filter).
B-48
Appendix B
GeoSPARQL Functions for Spatial Support
It is recommended to use a LEADING(?var) HINT0 hint when the query involves a restrictive
ogcf:sfWithin spatial filter on ?var.
See Spatial Support for information about representing, indexing, and querying spatial data in
RDF.
See also the OGC GeoSPARQL specification.
Example
The following example finds U.S. Congressional district polygons that are spatially within a
constant polygon.
B.1.52 ogcf:spatialDimension
Format
Description
Returns the spatial dimension of geom. That is, the number of dimensions used for the spatial
coordinates of geom. It does not include any dimensions used for measure values.
Parameters
geom
Geometry object. Specified as a query variable or a constant geomLiteral value.
Usage Notes
See Spatial Support for information about representing, indexing, and querying spatial data in
RDF.
See also the OGC GeoSPARQL specification.
B-49
Appendix B
GeoSPARQL Functions for Spatial Support
Example
The following example returns the spatial dimension of each U.S. Congressional
district polygon.
SELECT cdist, sd
FROM table(sem_match(
'PREFIX ogc: <http://www.opengis.net/ont/geosparql#>
PREFIX ogcf: <http://www.opengis.net/def/function/geosparql/>
PREFIX orageo: <http://xmlns.oracle.com/rdf/geo/>
PREFIX pol: <http://www.rdfabout.com/rdf/schema/politico/>
PREFIX usgovt: <http://www.rdfabout.com/rdf/schema/usgovt/>
SELECT ?cdist (ogcf:spatialDimension(?cgeom) AS ?sd)
WHERE
{ ?cdist orageo:hasExactGeometry ?cgeom }'
,sem_models('gov_all_vm'), null
, null ,null, null, ' ALLOW_DUP=T '));
B.1.53 ogcf:symDifference
Format
Description
Returns a geometry object that is the topological symmetric difference (XOR
operation) of geom1 and geom2.
Parameters
geom1
Geometry object. Specified as a query variable or a constant geomLiteral value.
geom2
Geometry object. Specified as a query variable or a constant geomLiteral value.
Usage Notes
See Spatial Support for information about representing, indexing, and querying spatial
data in RDF.
See also the OGC GeoSPARQL specification.
Example
The following example finds the U.S. Congressional district polygons that are within a
100-kilometer buffer around a specified point.
B-50
Appendix B
GeoSPARQL Functions for Spatial Support
B.1.54 ogcf:transform
Format
ogcf:transform(geom : geomLiteral, srsIRI xsd:anyURI) : ogc:wktLiteral
Description
Transforms geom to the spatial reference system defined by srsIRI.
Parameters
geom
Geometry object. Specified as a query variable or a constant geomLiteral value.
srsIRI
The target spatial reference system IRI.
Usage Notes
See Spatial Support for information about representing, indexing, and querying spatial data in
RDF.
See also the OGC GeoSPARQL specification.
Supported spatial reference system IRIs have the following form <http://
www.opengis.net/def/crs/EPSG/0/{srid}>, where {srid} is a valid spatial reference
system ID defined by the European Petroleum Survey Group (EPSG). For IRIs that are not in
the EPSG Geodetic Parameter Dataset, spatial reference system IRIs of the following form
are supported <http://xmlns.oracle.com/rdf/geo/srid/{srid}>, where {srid} is a valid
spatial reference system ID from Oracle Spatial.
Example
The following example projects each Congressional distinct polygon to the NH state plane
coordinate reference system (EPSG:3613).
B-51
Appendix B
GeoSPARQL Functions for Spatial Support
B.1.55 ogcf:union
Format
Description
Returns a geometry object that is the topological union (OR operation) of geom1 and
geom2.
Parameters
geom1
Geometry object. Specified as a query variable or a constant geomLiteral value.
geom2
Geometry object. Specified as a query variable or a constant geomLiteral value.
Usage Notes
See Spatial Support for information about representing, indexing, and querying spatial
data in RDF.
See also the OGC GeoSPARQL specification.
Example
The following example finds the U.S. Congressional district polygons whose centroid is
within the union of two specified polygons.
B-52
Appendix B
Oracle-Specific Functions for Spatial Support
B.2.1 orageo:aggrCentroid
Format
B-53
Appendix B
Oracle-Specific Functions for Spatial Support
Description
Returns a geometry literal that is the centroid of the group of specified geometry
objects. (The centroid is also known as the "center of gravity.")
Parameters
geom
Geometry objects. Specified as a query variable.
Usage Notes
See Spatial Support for information about representing, indexing, and querying spatial
data in RDF.
See also the SDO_AGGR_CENTROID function in Oracle Spatial and Graph
Developer's Guide.
Example
The following example finds the centroid of all the U.S. Congressional district
polygons.
SELECT centroid
FROM table(sem_match(
'select (orageo:aggrCentroid(?cgeom) as ?centroid)
{?cdist orageo:hasExactGeometry ?cgeom } '
,sem_models('gov_all_vm'), null
,sem_aliases(
sem_alias('usgovt','http://www.rdfabout.com/rdf/schema/usgovt/'),
sem_alias('pol','http://www.rdfabout.com/rdf/schema/politico/'))
,null, null, ' ALLOW_DUP=T '));
B.2.2 orageo:aggrConvexHull
Format
Description
Returns a geometry literal that is the convex hull of the group of specified geometry
objects.. (The convex hull is a simple convex polygon that, for this funciton,
completely encloses the group of geometry objects, using as few straight-line sides as
possible to create the smallest polygon that completely encloses the geometry
objects.)
Parameters
geom
Geometry objects. Specified as a query variable.
Usage Notes
See Spatial Support for information about representing, indexing, and querying spatial
data in RDF.
B-54
Appendix B
Oracle-Specific Functions for Spatial Support
See also the SDO_AGGR_CONVEXHULL function in Oracle Spatial and Graph Developer's
Guide.
Example
The following example finds the convex hull of all the U.S. Congressional district polygons.
SELECT chull
FROM table(sem_match(
'select (orageo:aggrConvexhull(?cgeom) as ?chull)
{
?cdist orageo:hasExactGeometry ?cgeom } '
,sem_models('gov_all_vm'), null
,sem_aliases(
sem_alias('usgovt','http://www.rdfabout.com/rdf/schema/usgovt/'),
sem_alias('pol','http://www.rdfabout.com/rdf/schema/politico/'))
,null, null, ' ALLOW_DUP=T '));
B.2.3 orageo:aggrMBR
Format
Description
Returns a geometry literal that is the minimum bounding rectangle (MBR) of the group of
specified geometry objects.
Parameters
geom
Geometry objects. Specified as a query variable.
Usage Notes
See Spatial Support for information about representing, indexing, and querying spatial data in
RDF.
See also the SDO_AGGR_MBR function in Oracle Spatial and Graph Developer's Guide.
Example
The following example finds the MBR of all the U.S. Congressional district polygons.
SELECT mbr
FROM table(sem_match(
'select (orageo:aggrMBR(?cgeom) as ?mbr)
{
?cdist orageo:hasExactGeometry ?cgeom } '
,sem_models('gov_all_vm'), null
,sem_aliases(
sem_alias('usgovt','http://www.rdfabout.com/rdf/schema/usgovt/'),
sem_alias('pol','http://www.rdfabout.com/rdf/schema/politico/'))
,null, null, ' ALLOW_DUP=T '));
B-55
Appendix B
Oracle-Specific Functions for Spatial Support
B.2.4 orageo:aggrUnion
Format
Description
Returns a geometry literal that is the topological union of the group of specified
geometry objects.
Parameters
geom
Geometry objects. Specified as a query variable.
Usage Notes
See Spatial Support for information about representing, indexing, and querying spatial
data in RDF.
See also the SDO_GEOM.SDO_UNION function in Oracle Spatial and Graph
Developer's Guide.
Example
The following example finds the union of all the U.S. Congressional district polygons.
SELECT u
FROM table(sem_match(
'select (orageo:aggrUnion(?cgeom) as ?u)
{
?cdist orageo:hasExactGeometry ?cgeom } '
,sem_models('gov_all_vm'), null
,sem_aliases(
sem_alias('usgovt','http://www.rdfabout.com/rdf/schema/usgovt/'),
sem_alias('pol','http://www.rdfabout.com/rdf/schema/politico/'))
,null, null, ' ALLOW_DUP=T '));
B.2.5 orageo:area
Format
Description
Returns the area of geom1 in terms of the specified unit of measure.
Parameters
geom1
Geometry object. Specified as a query variable or a constant geomLiteral value.
B-56
Appendix B
Oracle-Specific Functions for Spatial Support
unit
Unit of measurement: a quoted string with an SDO_UNIT value from the
MDSYS.SDO_DIST_UNITS table (for example, "unit=SQ_KM"). See the section about unit of
measurement support in Oracle Spatial and Graph Developer's Guide for more information
about unit of measurement specification.
Usage Notes
See Spatial Support for information about representing, indexing, and querying spatial data in
RDF.
See also the SDO_GEOM.SDO_AREA function in Oracle Spatial and Graph Developer's
Guide.
Example
The following example finds the U.S. Congressional district polygons with areas greater than
10,000 square kilometers.
SELECT name, cdist
FROM table(sem_match(
'{ ?person usgovt:name ?name .
?person pol:hasRole ?role .
?role pol:forOffice ?office .
?office pol:represents ?cdist .
?cdist orageo:hasExactGeometry ?cgeom
FILTER (orageo:area(?cgeom, "unit=SQ_KM") > 10000) }'
,sem_models('gov_all_vm'), null
,sem_aliases(
sem_alias('usgovt','http://www.rdfabout.com/rdf/schema/usgovt/'),
sem_alias('pol','http://www.rdfabout.com/rdf/schema/politico/'))
,null, null, ' ALLOW_DUP=T '));
B.2.6 orageo:buffer
Format
Description
Returns a buffer polygon at a specified distance around or inside a geometry.
Parameters
geom1
Geometry object. Specified as a query variable or a constant geomLiteral value.
distance
Distance value. Distance value. If the value is positive, the buffer is generated around geom1;
if the value is negative (valid only for polygons), the buffer is generated inside geom1.
unit
Unit of measurement: a quoted string with an SDO_UNIT value from the
MDSYS.SDO_DIST_UNITS table (for example, "unit=KM"). See the section about unit of
measurement support in Oracle Spatial and Graph Developer's Guide for more information
about unit of measurement specification.
B-57
Appendix B
Oracle-Specific Functions for Spatial Support
Usage Notes
See Spatial Support for information about representing, indexing, and querying spatial
data in RDF.
See also the SDO_GEOM.SDO_BUFFER function in Oracle Spatial and Graph
Developer's Guide.
Example
The following example finds the U.S. Congressional district polygons that are
completely inside a 100-kilometer buffer around a specified point.
SELECT name, cdist
FROM table(sem_match(
'{ # HINT0={LEADING(?cgeom)}
?person usgovt:name ?name .
?person pol:hasRole ?role .
?role pol:forOffice ?office .
?office pol:represents ?cdist .
?cdist orageo:hasExactGeometry ?cgeom
FILTER (
orageo:relate(?cgeom,
orageo:buffer("POINT(-71.46444 42.7575)"^^orageo:WKTLiteral,
100, "unit=KM"),
"mask=inside")) }'
,sem_models('gov_all_vm'), null
,sem_aliases(
sem_alias('usgovt','http://www.rdfabout.com/rdf/schema/usgovt/'),
sem_alias('pol','http://www.rdfabout.com/rdf/schema/politico/'))
,null, null, ' ALLOW_DUP=T '));
B.2.7 orageo:centroid
Format
Description
Returns a point geometry that is the centroid of geom1. (The centroid is also known as
the "center of gravity.")
Parameters
geom1
Geometry object. Specified as a query variable or a constant geomLiteral value.
Usage Notes
For an input geometry consisting of multiple objects, the result is weighted by the area
of each polygon in the geometry objects. If the geometry objects are a mixture of
polygons and points, the points are not used in the calculation of the centroid. If the
geometry objects are all points, the points have equal weight.
See Spatial Support for information about representing, indexing, and querying spatial
data in RDF.
B-58
Appendix B
Oracle-Specific Functions for Spatial Support
Example
The following example finds the U.S. Congressional district polygons with centroids within
200 kilometers of a specified point.
SELECT name, cdist
FROM table(sem_match(
'{ ?person usgovt:name ?name .
?person pol:hasRole ?role .
?role pol:forOffice ?office .
?office pol:represents ?cdist .
?cdist orageo:hasExactGeometry ?cgeom
FILTER (orageo:withinDistance(orageo:centroid(?cgeom),
"POINT(-71.46444 42.7575)"^^orageo:WKTLiteral,
"distance=200 unit=KM")) } '
,sem_models('gov_all_vm'), null
,sem_aliases(
sem_alias('usgovt','http://www.rdfabout.com/rdf/schema/usgovt/'),
sem_alias('pol','http://www.rdfabout.com/rdf/schema/politico/'))
,null, null, ' ALLOW_DUP=T '));
B.2.8 orageo:convexHull
Format
Description
Returns a polygon-type object that represents the convex hull of geom1. (The convex hull is a
simple convex polygon that completely encloses the geometry object, using as few straight-
line sides as possible to create the smallest polygon that completely encloses the geometry
object.)
Parameters
geom1
Geometry object. Specified as a query variable or a constant geomLiteral value.
Usage Notes
A convex hull is a convenient way to get an approximation of a complex geometry object.
See Spatial Support for information about representing, indexing, and querying spatial data in
RDF.
See also the SDO_GEOM.SDO_CONVEX_HULL function in Oracle Spatial and Graph
Developer's Guide.
Example
The following example finds the U.S. Congressional district polygons whose convex hull
contains a specified point.
SELECT name, cdist
FROM table(sem_match(
B-59
Appendix B
Oracle-Specific Functions for Spatial Support
B.2.9 orageo:difference
Format
Description
Returns a geometry object that is the topological difference (MINUS operation) of
geom1 and geom2.
Parameters
geom1
Geometry object. Specified as a query variable or a constant geomLiteral value.
geom2
Geometry object. Specified as a query variable or a constant geomLiteral value.
Usage Notes
See Spatial Support for information about representing, indexing, and querying spatial
data in RDF.
See also the SDO_GEOM.SDO_DIFFERENCE function in Oracle Spatial and Graph
Developer's Guide.
Example
The following example finds the U.S. Congressional district polygons whose centroid is
inside the difference of two specified polygons.
SELECT name, cdist
FROM table(sem_match(
'{ ?person usgovt:name ?name .
?person pol:hasRole ?role .
?role pol:forOffice ?office .
?office pol:represents ?cdist .
?cdist orageo:hasExactGeometry ?cgeom
FILTER (orageo:relate(orageo:centroid(?cgeom),
orageo:difference(
"Polygon((-83.6 34.1, -83.2 34.1, -83.2 34.5, -83.6
34.5, -83.6 34.1))"^^orageo:WKTLiteral,
"Polygon((-83.2 34.3, -83.0 34.3, -83.0 34.5, -83.2
34.5, -83.2 34.3))"^^orageo:WKTLiteral),
B-60
Appendix B
Oracle-Specific Functions for Spatial Support
"mask=inside")) } '
,sem_models('gov_all_vm'), null
,sem_aliases(
sem_alias('usgovt','http://www.rdfabout.com/rdf/schema/usgovt/'),
sem_alias('pol','http://www.rdfabout.com/rdf/schema/politico/'))
,null, null, ' ALLOW_DUP=T '));
B.2.10 orageo:distance
Format
Description
Returns the distance between the nearest pair of points or segments of geom1 and geom2 in
terms of the specified unit of measure.
Parameters
geom1
Geometry object. Specified as a query variable or a constant geomLiteral value.
geom2
Geometry object. Specified as a query variable or a constant geomLiteral value.
unit
Unit of measurement: a quoted string with an SDO_UNIT value from the
MDSYS.SDO_DIST_UNITS table (for example, "unit=KM"). See the section about unit of
measurement support in Oracle Spatial and Graph Developer's Guide for more information
about unit of measurement specification.
Usage Notes
Use orageo:withinDistance instead of orageo:distance whenever possible, because
orageo:withinDistance has a more efficient index-based implementation.
See Spatial Support for information about representing, indexing, and querying spatial data in
RDF.
See also the SDO_GEOM.SDO_DISTANCE function in Oracle Spatial and Graph
Developer's Guide.
Example
The following example finds the ten nearest U.S. Congressional districts to a specified point
and orders them by distance from the point.
SELECT name, cdist
FROM table(sem_match(
'SELECT ?name ?cdist
WHERE
{ # HINT0={LEADING(?cgeom)}
?person usgovt:name ?name .
?person pol:hasRole ?role .
?role pol:forOffice ?office .
?office pol:represents ?cdist .
?cdist orageo:hasExactGeometry ?cgeom
FILTER (orageo:nearestNeighbor(?cgeom,
B-61
Appendix B
Oracle-Specific Functions for Spatial Support
"POINT(-71.46444 42.7575)"^^orageo:WKTLiteral,
"sdo_num_res=10")) }
ORDER BY ASC(orageo:distance(?cgeom,
"POINT(-71.46444 42.7575)"^^orageo:WKTLiteral,
"unit=KM"))'
,sem_models('gov_all_vm'), null
,sem_aliases(
sem_alias('usgovt','http://www.rdfabout.com/rdf/schema/usgovt/'),
sem_alias('pol','http://www.rdfabout.com/rdf/schema/politico/'))
,null, null, ' ALLOW_DUP=T '))
ORDER BY sem$rownum;
B.2.11 orageo:getSRID
Format
Description
Returns the oracle spatial reference system (SRID) URI for geom.
Parameters
geom
Geometry object. Specified as a query variable or a constant geomLiteral value.
Usage Notes
See Spatial Support for information about representing, indexing, and querying spatial
data in RDF.
Example
The following example finds spatial reference system URIs for U.S. Congressional
district polygons.
SELECT csrid
FROM table(sem_match(
'SELECT (orageo:getSRID(?cgeom) AS ?csrid)
WHERE
{ ?person usgovt:name ?name .
?person pol:hasRole ?role .
?role pol:forOffice ?office .
?office pol:represents ?cdist .
?cdist orageo:hasExactGeometry ?cgeom }'
,sem_models('gov_all_vm'), null
,sem_aliases(
sem_alias('usgovt','http://www.rdfabout.com/rdf/schema/usgovt/'),
sem_alias('pol','http://www.rdfabout.com/rdf/schema/politico/')
)
,null, null, ' ALLOW_DUP=T '));
B.2.12 orageo:intersection
Format
B-62
Appendix B
Oracle-Specific Functions for Spatial Support
Description
Returns a geometry object that is the topological intersection (AND operation) of geom1 and
geom2.
Parameters
geom1
Geometry object. Specified as a query variable or a constant geomLiteral value.
geom2
Geometry object. Specified as a query variable or a constant geomLiteral value.
Usage Notes
See Spatial Support for information about representing, indexing, and querying spatial data in
RDF.
See also the SDO_GEOM.SDO_INTERSECTION function in Oracle Spatial and Graph
Developer's Guide.
Example
The following example finds the U.S. Congressional district polygons whose centroid is inside
the intersection of two specified polygons.
SELECT name, cdist
FROM table(sem_match(
'{ ?person usgovt:name ?name .
?person pol:hasRole ?role .
?role pol:forOffice ?office .
?office pol:represents ?cdist .
?cdist orageo:hasExactGeometry ?cgeom
FILTER (orageo:relate(orageo:centroid(?cgeom),
orageo:intersection(
"Polygon((-83.6 34.1, -83.2 34.1, -83.2 34.5, -83.6 34.5,
-83.6 34.1))"^^orageo:WKTLiteral,
"Polygon((-83.2 34.3, -83.0 34.3, -83.0 34.5, -83.2 34.5,
-83.2 34.3))"^^orageo:WKTLiteral),
"mask=inside")) } '
,sem_models('gov_all_vm'), null
,sem_aliases(
sem_alias('usgovt','http://www.rdfabout.com/rdf/schema/usgovt/'),
sem_alias('pol','http://www.rdfabout.com/rdf/schema/politico/'))
,null, null, ' ALLOW_DUP=T '));
B.2.13 orageo:length
Format
Description
Returns the length or perimeter of geom1 in terms of the specified unit of measure.
B-63
Appendix B
Oracle-Specific Functions for Spatial Support
Parameters
geom1
Geometry object. Specified as a query variable or a constant geomLiteral value.
unit
Unit of measurement: a quoted string with an SDO_UNIT value from the
MDSYS.SDO_DIST_UNITS table (for example, "unit=KM"). See the section about
unit of measurement support in Oracle Spatial and Graph Developer's Guide for more
information about unit of measurement specification.
Usage Notes
See Spatial Support for information about representing, indexing, and querying spatial
data in RDF.
See also the SDO_GEOM.SDO_LENGTH function in Oracle Spatial and Graph
Developer's Guide.
Example
The following example finds the U.S. Congressional district polygons with lengths
(perimeters) greater than 1000 kilometers.
SELECT name, cdist
FROM table(sem_match(
'{ ?person usgovt:name ?name .
?person pol:hasRole ?role .
?role pol:forOffice ?office .
?office pol:represents ?cdist .
?cdist orageo:hasExactGeometry ?cgeom
FILTER (orageo:legnth(?cgeom, "unit=KM") > 1000) }'
,sem_models('gov_all_vm'), null
,sem_aliases(
sem_alias('usgovt','http://www.rdfabout.com/rdf/schema/usgovt/'),
sem_alias('pol','http://www.rdfabout.com/rdf/schema/politico/'))
,null, null, ' ALLOW_DUP=T '));
B.2.14 orageo:mbr
Format
Description
Returns the minimum bounding rectangle of geom1, that is, the single rectangle that
minimally encloses geom1.
Parameters
geom1
Geometry object. Specified as a query variable or a constant geomLiteral value.
B-64
Appendix B
Oracle-Specific Functions for Spatial Support
Usage Notes
See Spatial Support for information about representing, indexing, and querying spatial data in
RDF.
See also the SDO_GEOM.SDO_MBR function in Oracle Spatial and Graph Developer's
Guide.
Example
The following example finds the U.S. Congressional district polygons whose minimum
bounding rectangle contains a specified point.
SELECT name, cdist
FROM table(sem_match(
'{ ?person usgovt:name ?name .
?person pol:hasRole ?role .
?role pol:forOffice ?office .
?office pol:represents ?cdist .
?cdist orageo:hasExactGeometry ?cgeom
FILTER (orageo:relate(orageo:mbr(?cgeom),
"POINT(-71.46444 42.7575)"^^orageo:WKTLiteral,
"mask=contains")) } '
,sem_models('gov_all_vm'), null
,sem_aliases(
sem_alias('usgovt','http://www.rdfabout.com/rdf/schema/usgovt/'),
sem_alias('pol','http://www.rdfabout.com/rdf/schema/politico/'))
,null, null, ' ALLOW_DUP=T '));
B.2.15 orageo:nearestNeighbor
Format
Description
Returns true if geom1 is a nearest neighbor of geom2, where the size of the nearest neighbors
set is specified by param; returns false otherwise.
Parameters
geom1
Geometry object. Specified as a query variable.
geom2
Geometry object. Specified as a query variable or a constant geomLiteral value.
param
Determines the behavior of the operator. See the Usage Notes for the available keyword-
value pairs.
Usage Notes
In the param parameter, the available keyword-value pairs are:
• distance=n specifies the maximum allowable distance for the nearest neighbor search.
B-65
Appendix B
Oracle-Specific Functions for Spatial Support
• sdo_num_res=n specifies the size of the set for the nearest neighbor search.
• unit=unit specifies the unit of measurement to use with distance value. If you do
not specify a value, the unit of measurement associated with the data is used.
geom1 must be a local variable (that is, a variable that appears in the basic graph
pattern that contains the orageo:nearestNeighbor spatial filter).
It is a good idea to use a 'LEADING(?var)' HINT0 hint when your query involves a
restrictive orageo:relate spatial filter on ?var.
See Spatial Support for information about representing, indexing, and querying spatial
data in RDF.
See also the SDO_NN operator in Oracle Spatial and Graph Developer's Guide.
Example
The following example finds the ten nearest U.S. Congressional districts to a specified
point.
SELECT name, cdist
FROM table(sem_match(
'{ # HINT0={LEADING(?cgeom)}
?person usgovt:name ?name .
?person pol:hasRole ?role .
?role pol:forOffice ?office .
?office pol:represents ?cdist .
?cdist orageo:hasExactGeometry ?cgeom
FILTER (orageo:nearestNeighbor(?cgeom,
"POINT(-71.46444 42.7575)"^^orageo:WKTLiteral,
"sdo_num_res=10")) } '
,sem_models('gov_all_vm'), null
,sem_aliases(
sem_alias('usgovt','http://www.rdfabout.com/rdf/schema/usgovt/'),
sem_alias('pol','http://www.rdfabout.com/rdf/schema/politico/'))
,null, null, ' ALLOW_DUP=T '));
B.2.16 orageo:relate
Format
Description
Returns true if geom1 and geom2 satisfy the topological spatial relation specified by the
param parameter; returns false otherwise.
Parameters
geom1
Geometry object. Specified as a query variable or a constant geomLiteral value.
geom2
Geometry object. Specified as a query variable or a constant geomLiteral value.
B-66
Appendix B
Oracle-Specific Functions for Spatial Support
param
Specifies a list of mask relationships to check. See the list of keywords in the Usage Notes.
Usage Notes
The following param values (mask relationships) can be tested:
It is a good idea to use a 'LEADING(?var)' HINT0 hint when your query involves a restrictive
orageo:relate spatial filter on ?var.
See Spatial Support for information about representing, indexing, and querying spatial data in
RDF.
See also the SDO_RELATE operator in Oracle Spatial and Graph Developer's Guide.
Example
The following example finds the U.S. Congressional district that contains a specified point.
B-67
Appendix B
Oracle-Specific Functions for Spatial Support
B.2.17 orageo:sdoDistJoin
Format
Description
Performs a spatial join based on distance between two geometries. Returns true if the
distance between geom1 and geom2 is within the given value specified in param; returns
false otherwise.
Parameters
geom1
Geometry object. Specified as a query variable or a constant geomLiteral value.
geom2
Geometry object. Specified as a query variable or a constant geomLiteral value.
param
Specifies a distance value and unit of measure to use for the distance-based spatial
join. The distance value is added to the tolerance value of the associated spatial
index. For example if "distance=100 and unit=m" is used with a tolerance value of
10 meters, then orageo:sdoDistJoin returns true if the distance between two
geometries is no more than 110 meters.
Usage Notes
orageo:sdoDistJoin should be used when performing a distance-based spatial join
between two large geometry collections. When performing a distance-based spatial
join between one small geometry collection and one large geometry collection,
invoking orageo:withinDistance with the small geometry collection as the first
argument will usually give better performance than orageo:sdoDistJoin.
See Spatial Support for information about representing, indexing, and querying spatial
data in RDF.
See also the SDO_JOIN operator in Oracle Spatial and Graph Developer's Guide.
B-68
Appendix B
Oracle-Specific Functions for Spatial Support
Example
The following example finds pairs of U.S. Congressional district polygons that are within 100
meters of each other.
SELECT cdist1, cdist2
FROM table(sem_match(
'{ ?cdist1 orageo:hasExactGeometry ?cgeom1 .
?cdist2 orageo:hasExactGeometry ?cgeom2
FILTER (orageo:sdoDistJoin(?cgeom1, ?cgeom2,
"distance=100 unit=m")) } '
,sem_models('gov_all_vm'), null
,sem_aliases(
sem_alias('usgovt','http://www.rdfabout.com/rdf/schema/usgovt/'),
sem_alias('pol','http://www.rdfabout.com/rdf/schema/politico/'))
,null, null, ' ALLOW_DUP=T '
));
B.2.18 orageo:sdoJoin
Format
Description
Performs a spatial join based on one or more topological relationships. Returns true if geom1
and geom2 satisfy the spatial relationship specified by param; returns false otherwise.
Parameters
geom1
Geometry object. Specified as a query variable or a constant geomLiteral value.
geom2
Geometry object. Specified as a query variable or a constant geomLiteral value.
param
Specifies a list of mask relationships to check. The topological relationship of interest.Valid
values are 'mask=<value>' where <value> is one or more of the mask values that are valid
for the SDO_RELATE operator (TOUCH, OVERLAPBDYDISJOINT,
OVERLAPBDYINTERSECT, EQUAL, INSIDE, COVEREDBY, CONTAINS, COVERS,
ANYINTERACT, ON). Multiple masks are combined with the logical Boolean operator OR
(for example, "mask=inside+touch").
Usage Notes
orageo:sdoJoin should be used when performing a spatial join between two large geometry
collections. When performing a spatial join between one small geometry collection and one
large geometry collection, invoking orageo:relate with the small geometry collection as the
first argument will usually give better performance than orageo:sdoJoin.
See Spatial Support for information about representing, indexing, and querying spatial data in
RDF.
See also the SDO_JOIN operator in Oracle Spatial and Graph Developer's Guide.
B-69
Appendix B
Oracle-Specific Functions for Spatial Support
Example
The following example finds pairs of U.S. Congressional district polygons that have
any spatial interaction.
SELECT cdist1, cdist2
FROM table(sem_match(
'{ ?cdist1 orageo:hasExactGeometry ?cgeom1 .
?cdist2 orageo:hasExactGeometry ?cgeom2
FILTER (orageo:sdoJoin(?cgeom1, ?cgeom2,
"mask=anyinteract")) } '
,sem_models('gov_all_vm'), null
,sem_aliases(
sem_alias('usgovt','http://www.rdfabout.com/rdf/schema/usgovt/'),
sem_alias('pol','http://www.rdfabout.com/rdf/schema/politico/'))
,null, null, ' ALLOW_DUP=T '
));
B.2.19 orageo:union
Format
Description
Returns a geometry object that is the topological union (OR operation) of geom1 and
geom2.
Parameters
geom1
Geometry object. Specified as a query variable or a constant geomLiteral value.
geom2
Geometry object. Specified as a query variable or a constant geomLiteral value.
Usage Notes
See Spatial Support for information about representing, indexing, and querying spatial
data in RDF.
See also the SDO_GEOM.SDO_UNION function in Oracle Spatial and Graph
Developer's Guide.
Example
The following example finds the U.S. Congressional district polygons whose centroid is
inside the union of two specified polygons.
SELECT name, cdist
FROM table(sem_match(
'{ ?person usgovt:name ?name .
?person pol:hasRole ?role .
?role pol:forOffice ?office .
?office pol:represents ?cdist .
?cdist orageo:hasExactGeometry ?cgeom
FILTER (orageo:relate(orageo:centroid(?cgeom),
B-70
Appendix B
Oracle-Specific Functions for Spatial Support
B.2.20 orageo:withinDistance
Format
Description
Returns true if the distance between geom1 and geom2 is less than or equal to distance when
measured in unit; returns false otherwise.
Parameters
geom1
Geometry object. Specified as a query variable or a constant geomLiteral value.
geom2
Geometry object. Specified as a query variable or a constant geomLiteral value.
distance
Distance value.
unit
Unit of measurement: a quoted string with an SDO_UNIT value from the
MDSYS.SDO_DIST_UNITS table (for example, "unit=KM"). See the section about unit of
measurement support in Oracle Spatial and Graph Developer's Guide for more information
about unit of measurement specification.
Usage Notes
When invoking this function with a query variable and a constant geometry, always use the
query variable as the first parameter and the constant geometry as the second parameter.
For best performance, geom1 should be a local variable (that is, a variable that appears in the
basic graph pattern that contains the orageo:withinDistance spatial filter).
It is a good idea to use a 'LEADING(?var)' HINT0 hint when your query involves a restrictive
orageo:withinDistance spatial filter on ?var.
See Spatial Support for information about representing, indexing, and querying spatial data in
RDF.
See also the SDO_WITHIN_DISTANCE operator in Oracle Spatial and Graph Developer's
Guide.
B-71
Appendix B
Oracle-Specific Functions for Spatial Support
Example
The following example finds the U.S. Congressional districts that are within 100
kilometers of a specified point.
SELECT name, cdist
FROM table(sem_match(
'{ # HINT0={LEADING(?cgeom)}
?person usgovt:name ?name .
?person pol:hasRole ?role .
?role pol:forOffice ?office .
?office pol:represents ?cdist .
?cdist orageo:hasExactGeometry ?cgeom
FILTER (orageo:withinDistance(?cgeom,
"POINT(-71.46444 42.7575)"^^orageo:WKTLiteral,
100, "KM")) } '
,sem_models('gov_all_vm'), null
,sem_aliases(
sem_alias('usgovt','http://www.rdfabout.com/rdf/schema/usgovt/'),
sem_alias('pol','http://www.rdfabout.com/rdf/schema/politico/'))
,null, null, ' ALLOW_DUP=T '));
B.2.21 orageo:xor
Format
Description
Returns a geometry object that is the topological symmetric difference (XOR
operation) of geom1 and geom2.
Parameters
geom1
Geometry object. Specified as a query variable or a constant geomLiteral value.
geom2
Geometry object. Specified as a query variable or a constant geomLiteral value.
Usage Notes
See Spatial Support for information about representing, indexing, and querying spatial
data in RDF.
See also the SDO_GEOM.SDO_XOR function in Oracle Spatial and Graph
Developer's Guide.
Example
The following example finds the U.S. Congressional district polygons whose centroid is
inside the symmetric difference of two specified polygons.
SELECT name, cdist
FROM table(sem_match(
'{ ?person usgovt:name ?name .
?person pol:hasRole ?role .
B-72
Appendix B
Oracle-Specific Functions for Spatial Support
B-73
C
RDF Support in SQL Developer
You can use Oracle SQL Developer to perform operations related to the RDF Graph feature
of Oracle Graph.
• About RDF Support in SQL Developer
The RDF support in SQL Developer is available through the Connections navigator.
• Setting Up the RDF Semantic Graph Support In SQL Developer
This section applies only if you are using Oracle Database 19c or later. You must execute
a setup procedure to enable RDF Semantic Graph support in SQL Developer for
schema-private networks only.
• Working with RDF Semantic Networks Using SQL Developer
You can create an RDF semantic network to work with RDF data using SQL Developer.
• Bulk Loading RDF Data Using SQL Developer
RDF Bulk load operations can be invoked from SQL Developer.
C-1
Appendix C
Setting Up the RDF Semantic Graph Support In SQL Developer
Note:
This setup is not required for semantic networks in MDSYS schema. Starting
from Oracle Database 19c, it is always recommended to create semantic
networks in database user schemas.
Running this setup creates helper functions that are needed to populate RDF network
dictionary information in SQL Developer.
Note:
If you do not perform this one-time setup procedure, you may encounter an
error when trying to expand RDF network metadata nodes (such as
REGULAR_MODELS, RDF_VIEWS, RULEBASES, and so on) in SQL Developer.
The following table helps you to determine if you require a DBA privilege to have
this option available.
Table C-1 RDF Semantic Graph Setup Specific To SQL Developer and
Oracle DB Version
C-2
Appendix C
Setting Up the RDF Semantic Graph Support In SQL Developer
Table C-1 (Cont.) RDF Semantic Graph Setup Specific To SQL Developer
and Oracle DB Version
Note:
If you have already set up
the RDF Semantic Graph
support in Oracle
Database Release 19c or
later with a SQL Developer
version earlier than 20.3,
but you have started using
SQL Developer Release
20.3 or later, then you will
need to perform the setup
again, because the
metadata functions are
different from previous
ones that were installed in
the MDSYS schema.
3. Click Apply.
Optionally, you can also click the SQL tab to view the procedure.
C-3
Appendix C
Working with RDF Semantic Networks Using SQL Developer
The required types and function are installed in the appropriate schema. Once this
setup is executed, the RDF Semantic Graph option appears grayed out.
C-4
Appendix C
Working with RDF Semantic Networks Using SQL Developer
2. Select a Network Owner, that is, the database schema that will be the owner of the
network.
• For release 18c and earlier, the owner is always MDSYS.
• For release 19c before 19.3, select the network owner.
• For release 19.3 and later, the network owner is always the connection user schema.
3. Enter a Network Name.
C-5
Appendix C
Working with RDF Semantic Networks Using SQL Developer
Note:
For release 18c and earlier, this field is blank and not editable.
C-6
Appendix C
Working with RDF Semantic Networks Using SQL Developer
C-7
Appendix C
Working with RDF Semantic Networks Using SQL Developer
Two indexes are created by default: PCSGM and PSCGM. However, you can use a
three-index setup to better cover more combinations of S, P, and C: PSCGM, SPCGM,
and CSPGM.
In the Connections navigator (not the DBA navigator), expand the system connection,
expand RDF Semantic Graph, then click Network Indexes (RDF_LINK).
1. Add the SPCGM index.
Right-click and select Create Semantic Index. Suggested Index code: SPCGM
Click OK.
2. Add the CSPGM index.
Right-click and select Create Semantic Index. Suggested Index code: CSPGM
Click OK.
3. Drop the PSCGM index.
Right-click RDF_LINK_PSCGM_IDX and select Drop Semantic Index.
The result will be these three indexes:
• RDF_LINK_PSCGM_IDX
• RDF_LINK_SPCGM_IDX
• RDF_LINK_CSPGM_IDX
C-8
Appendix C
Bulk Loading RDF Data Using SQL Developer
C-9
Appendix C
Bulk Loading RDF Data Using SQL Developer
Tip: you can use a named pipe to avoid having to store uncompressed data. For
example:
$ mkfifo named_pipe.nt
$ bzcat myRdfFile.nt.bz2 > named_pipe.nt
6. Expand the regular, non-DBA user (for example, RDFUSER) connection and click
RDF Semantic Graph.
7. Create a model to hold the RDF data.
Click Model, then New Model.
Model Name: Enter a model name (for example, MY_ONTOLOGY)
Application Table: * Create new <Model_Name>_TPL table * (that is, have an
application table with a triple column named TRIPLE automatically created)
C-10
Appendix C
Bulk Loading RDF Data Using SQL Developer
Model Tablespace: tablespace to hold the RDF data (for example, RDFTBS)
Click Apply.
To see the model, expand Models in the object hierarchy, and click the model name to
bring up the SPARQL editor for that model.
You can run a query and see that the model is empty.
Using the Models menu, perform a bulk load from the Models menu. Bulk load has two
phases:
• Loading data from the file system into a simple "staging" table in the database. This uses
an external table to read from the file system.
• Loading data from the staging table into the semantic network. Load from the staging
table into the model (for example, MY_ONTOLOGY).
To perform these two phases:
1. Load data into the staging table.
Right-click REGULAR_MODELS (under the network name) and select Load RDF Data into
Staging Table from External Table.
For Source External Table, Source Table: Desired table name (for example,
MY_ONTOLOGY_EXT).
Log File: Desired file name (for example, my_ontology.log)
Bad File: Desired file name (for example, my_ontology.bad)
Source Table Owner: Schema of the table with RDF data (for example, RDFUSER)
For Input Files, Input Files: Input file (for example, named_pipe.nt).
For Staging Table, Staging table: Name for the staging table (for example,
MY_ONTOLOGY_STAGE).
If the table does not exist, check Create Staging Table.
Input Format: Desired format (for example, N-QUAD)
Staging Table Owner: Schema for the staging table (for example, RDFUSER)
2. Load from the staging table into the model.
C-11
Appendix C
Bulk Loading RDF Data Using SQL Developer
Note:
Unicode data in the staging table should be escaped as specified in
WC3 N-Triples format (http://www.w3.org/TR/rdf-testcases/#ntriples).
You can use the SEM_APIS.ESCAPE_RDF_TERM function to escape
Unicode values in the staging table. For example:
Right-click REGULAR_MODELS (under the network name) and select Bulk Load into
Model from staging Table.
Model: Name for the model (for example, MY_ONTOLOGY).
(If the model does not exist, check Create Model. However, in this example, the
model does already exist.)
Staging Table Owner: Schema of the staging table (for example, RDFUSER)
Staging Table Name: Name of the staging table (for example,
MY_ONTOLOGY_STAGE)
Parallel: Degree of parallelism (for example, 2)
Suggestion: Check the following options: MBV_METHOD=SHADOW, Rebuild
application table indexes, Create event trace table
Click Apply.
Do the following after the bulk load operation.
1. Gather statistics for the whole semantic network.
In the Connections navigator for a DBA user, expand the RDF Semantic Graph
node for the connection and select Gather Statistics (DBA)).
2. Run some SPARQL queries on our model.
In the Connections navigator, expand the RDF Semantic Graph node for the
connection and select the model.
Use the SPARQL Query Editor to enter and execute desired SPARQL queries.
3. Optionally, check the bulk load trace to get information about each step.
Expand RDF Semantic Graph and then expand Bulk Load Traces to display a list
of bulk load traces. Clicking one of them will show useful information about the
execution time for the load, number of distinct values and triples, number of
duplicate triples, and other details.
C-12
Glossary
apply pattern
Part of a data access constraint defines additional graph patterns to be applied on the
resources that match the match pattern before they can be used to construct the query
results. See also: match pattern
clique
A graph in which every node of it is connected to, bidirectionally, every other node in the
same graph.
Cytoscape
An open source bioinformatics software platform for visualizing molecular interaction
networks and integrating these interactions with gene expression profiles and other state
data. (See http://www.cytoscape.org/.) An RDF viewer (available for download) is
provided as a Cytoscape plug-in.
entailment
An object containing precomputed triples that can be inferred from applying a specified set of
rulebases to a specified set of models. See also: rulebase
extractor policy
A named dictionary entity that determines the characteristics of a semantic index that is
created using the policy. Each extractor policy refers, directly or indirectly, to an instance of
an extractor type.
graph pattern
A combination of triples constructed by combining triple patterns in various ways, including
conjunction of triple patterns into groups, optionally using filter conditions, and then
Glossary-1
Glossary
combining such groups using connectors similar to disjunctions, outer-joins, and so on.
SPARQL querying is based around graph pattern matching.
inferencing
The ability to make logical deductions based on rules. Inferencing enables you to
construct queries that perform semantic matching based on meaningful relationships
among pieces of data, as opposed to just syntactic matching based on string or other
values. Inferencing involves the use of rules, either supplied by Oracle or user-defined,
placed in rulebases.
information extractor
An application that processes unstructured documents and extract meaningful
information from them, often using natural-language processing engines with the aid of
ontologies.
match pattern
Part of a constraint that determines the type of access restriction it enforces and binds
one or more variables to the corresponding data instances accessed in the user query.
See also: apply pattern
model
A user-created semantic structure that has a model name, and refers to triples stored
in a specified table column. Examples in this manual are the Articles and Family
models.
ontology
A shared conceptualization of knowledge in a particular domain. It consists of a
collection of classes, properties, and optionally instances. Classes are typically related
by class hierarchy (subclass/ superclass relationship). Similarly, the properties can be
related by property hierarchy (subproperty/ superproperty relationship). Properties can
be symmetric or transitive, or both. Properties can also have domain, ranges, and
cardinality constraints specified for them.
OWLPrime
An Oracle-defined subset of OWL capabilities; refers to the elements of the OWL
standard supported by the RDF Semantic Graph native inferencing engine.
Glossary-2
Glossary
reasoning
See inferencing
rule
An object that can be applied to draw inferences from semantic data.
rulebase
An object that can contain rules. See also: rule
rules index
See: entailment
semantic index
An index of type MDSYS.SEMCONTEXT, created on textual documents stored in a column of
a table, and used with information extractors to locate and extract meaningful information
from unstructured documents. See also: information extractor
triple pattern
Similar to an RDF triple, but allows use of a variable in place of any of the three components
(subject, predicate, or object). Triple patterns are basic elements in graph patterns used in
SPARQL queries. A triple pattern used in a query against an RDF graph is said to match if,
substitution of RDF terms for the variables present in the triple pattern, creates a triple that is
present in the RDF graph. See also: graph pattern
Glossary-3
Index
Symbols ANALYZE_ENTAILMENT procedure, 15-14
ANALYZE_MODEL procedure, 15-16
.gv files (DOT files) APPEND_SEM_NETWORK_DATA procedure,
outputting, 7-34 15-18
APPLY_OLS_POLICY procedure, 19-1
APPLY_POLICY_TO_APP_TAB procedure, 16-1
A AUTO_HINTS=T
ADD_DATATYPE_INDEX procedure, 15-4 query option for SEM_MATCH, 1-33
ADD_DEPENDENT_POLICY procedure, 18-1
ADD_SEM_INDEX procedure, 15-6 B
Advanced Compression, 7-7
aggregates BASE keyword
user-defined, 9-28 global prefix, 1-61
aliases basic graph pattern (BGP), 1-33
SEM_ALIASES and SEM_ALIAS data types, batch (bulk) loading, 15-25, 15-113
1-32, 5-7 best effort
ALL_AJ_HASH specifying for SPARQL query, 7-80
query option for SEM_MATCH, 1-33 BGP (basic graph pattern), 1-33
ALL_AJ_MERGE bind variables
query option for SEM_MATCH, 1-33 using with the SEM_APIS.SPARQL_TO_SQL
ALL_AJ_NL function, 1-143
query option for SEM_MATCH, 1-33 blank nodes, 1-17
ALL_BGP_HASH CLEANUP_BNODES procedure, 15-27
query option for SEM_MATCH, 1-33 SPARQL update considerations, 1-193
ALL_BGP_NL BUILD_PG_RDFVIEW_INDEXES procedure,
query option for SEM_MATCH, 1-33 15-19
ALL_LINK_HASH bulk loading, 15-25, 15-113
query option for SEM_MATCH, 1-33 bulk loading semantic data, 1-155
ALL_LINK_NL BULK_LOAD_FROM_STAGING_TABLE
query option for SEM_MATCH, 1-33 procedure, 15-25
ALL_MAX_PP_DEPTH(n)
query option for SEM_MATCH, 1-33
ALL_NO_MERGE
C
query option for SEM_MATCH, 1-33 Calais
ALLOW_DUP=T configuring the Calais extractor type, 5-12
query option for SEM_MATCH, 1-34 canonical forms, 1-16
ALTER_DATATYPE_INDEX procedure, 15-7 catsem.sql script, A-2
ALTER_ENTAILMENT procedure, 15-8 change tracking
ALTER_MODEL procedure, 15-9 disabling, 15-63
ALTER_SEM_INDEX_ON_ENTAILMENT enabling, 15-81
procedure, 15-10 getting information, 15-93
ALTER_SEM_INDEX_ON_MODEL procedure, CLEANUP_BNODES procedure, 15-27
15-11 CLEANUP_FAILED procedure, 15-28
ALTER_SEM_INDEXES procedure, 15-12 client identifiers, 7-7
ANALYZE_AUX_TABLES procedure, 17-1 cliques (sameAs), 3-12
Index-1
Index
Index-2
Index
ENABLE_INMEMORY_FOR_ENT procedure, G
15-84
ENABLE_INMEMORY_FOR_MODEL procedure, GATE (General Architecture for Text Engineering)
15-85 sample Java implementation, 5-14
ENABLE_NETWORK_SHARING procedure, using, 5-13
15-86 GATHER_STATS procedure, 17-5
ENABLE_OLS_POLICY procedure, 19-5 General Architecture for Text Engineering (GATE)
ENABLE_SYNTAX_CHECKING optimizer hint, sample Java implementation, 5-14
3-8 using, 5-13
entailment GET_CHANGE_TRACKING_INFO procedure,
invalid status, 1-33 15-93
entailment rules, 1-18 GET_INC_INF_INFO procedure, 15-95
entailments, 1-20 GET_MODEL_ID function, 15-96
altering, 15-8 GET_MODEL_NAME function, 15-96
deleting if in failed state, 15-28 GET_PLAN_COST function, 15-97
incomplete status, 1-33, 3-22 GET_SQL procedure, 15-98
invalid status, 3-22 GET_TRIPLE_ID function, 15-99
SEM_RULES_INDEX_DATASETS view, GETV$DATETIMETZVAL function, 15-100
1-21 GETV$DATETZVAL function, 15-101
SEM_RULES_INDEX_INFO view, 1-20 GETV$GEOMETRYVAL function, 15-102
ESCAPE_CLOB_TERM procedure, 15-86 GETV$NUMERICVAL function, 15-103
ESCAPE_CLOB_VALUE procedure, 15-87 GETV$STRINGVAL function, 15-104
ESCAPE_RDF_TERM procedure, 15-88 GETV$TIMETZVAL function, 15-105
ESCAPE_RDF_VALUE procedure, 15-89 global prefix (BASE keyword), 1-61
examples GRANT_MODEL_ACCESS_PRIV procedure,
PL/SQL, 1-200 15-106
EXPORT_ENTAILMENT_STATS procedure, GRANT_MODEL_ACCESS_PRIVS procedure,
15-89 15-107
EXPORT_MODEL_STATS procedure, 15-90 GRANT_NETWORK_ACCESS_PRIVS
EXPORT_NETWORK_STATS procedure, 17-4 procedure, 15-109
EXPORT_RDFVIEW_MODEL procedure, 15-91 GRANT_NETWORK_SHARING_PRIVS
exporting semantic data, 1-154 procedure, 15-110
external documents GRAPH_MATCH_UNNAMED=T
indexing, 5-11 query option for SEM_MATCH, 1-35
external table graphs
creating, 15-56 attribute of SEM_MATCH, 1-36
extractor policies, 5-5
RDFCTX_POLICIES view, 5-19
extractors
H
information, 5-3 HINT0
policies, 5-5 query option for SEM_MATCH, 1-35
HTTP_METHOD=POST_PAR
F query option for SEM_MATCH, 1-35
failed state
rulebase or entailment, 15-28
I
federated queries, 1-74, 7-20 IMPORT_ENTAILMENT_STATS procedure,
filter 15-110
attribute of SEM_MATCH, 1-32, 5-7 IMPORT_MODEL_STATS procedure, 15-111
FINAL_VALUE_HASH IMPORT_NETWORK_STATS procedure, 17-7
query option for SEM_MATCH, 1-35 in-memory column store support in RDF, 1-195
FINAL_VALUE_NL in-memory virtual columns with RDF, 1-196
query option for SEM_MATCH, 1-35 incremental inference, 3-14
functions disabling, 15-64
user-defined, 9-28 enabling, 15-82
Index-3
Index
Index-4
Index
Index-5
Index
Index-6
Index
Index-7
Index
Index-8
Index
Index-9
Index
Index-10
Index
Index-11
Index
Index-12