Semantics Developer's Guide
Total Page:16
File Type:pdf, Size:1020Kb
MarkLogic Server Semantic Graph Developer’s Guide 2 MarkLogic 10 May, 2019 Last Revised: 10.0-8, October, 2021 Copyright © 2021 MarkLogic Corporation. All rights reserved. MarkLogic Server MarkLogic 10—May, 2019 Semantic Graph Developer’s Guide—Page 2 MarkLogic Server Table of Contents Table of Contents Semantic Graph Developer’s Guide 1.0 Introduction to Semantic Graphs in MarkLogic ..........................................11 1.1 Terminology ..........................................................................................................12 1.2 Linked Open Data .................................................................................................13 1.3 RDF Implementation in MarkLogic .....................................................................14 1.3.1 Using RDF in MarkLogic .........................................................................15 1.3.1.1 Storing RDF Triples in MarkLogic ...........................................17 1.3.1.2 Querying Triples .......................................................................18 1.3.2 RDF Data Model .......................................................................................20 1.3.3 Blank Node Identifiers ..............................................................................21 1.3.4 RDF Datatypes ..........................................................................................21 1.3.5 IRIs and Prefixes .......................................................................................22 1.3.5.1 IRIs ............................................................................................22 1.3.5.2 Prefixes ......................................................................................23 1.3.6 RDF Vocabulary .......................................................................................24 1.4 Example Datasets ..................................................................................................25 2.0 Getting Started with Semantic Graphs in MarkLogic ..................................27 2.1 Setting up MarkLogic Server ................................................................................27 2.1.1 Configuring the Database to Work with Triples .......................................27 2.1.2 Setting Up Additional Servers ..................................................................28 2.2 Loading Triples .....................................................................................................28 2.2.1 Downloading the Dataset ..........................................................................28 2.2.2 Importing Triples with mlcp .....................................................................29 2.2.3 Verifying the Import .................................................................................30 2.3 Querying Triples ...................................................................................................32 2.3.1 Querying with Native SPARQL ...............................................................32 2.3.2 Querying with the sem:sparql Functions ..................................................34 3.0 Loading Semantic Triples ............................................................................37 3.1 Loading Embedded RDF Triples ..........................................................................37 3.2 Loading Triples .....................................................................................................37 3.2.1 Supported RDF Triple Formats ................................................................38 3.2.2 Example RDF Formats .............................................................................39 3.2.2.1 RDF/XML .................................................................................39 3.2.2.2 Turtle .........................................................................................40 3.2.2.3 RDF/JSON ................................................................................40 3.2.2.4 N3 ..............................................................................................41 3.2.2.5 N-Triples ...................................................................................41 MarkLogic 10—May, 2019 Semantic Graph Developer’s Guide—Page 3 MarkLogic Server Table of Contents 3.2.2.6 N-Quads ....................................................................................43 3.2.2.7 TriG ...........................................................................................44 3.2.3 Loading Triples with mlcp ........................................................................44 3.2.3.1 Preparation ................................................................................45 3.2.3.2 Import Command Syntax ..........................................................46 3.2.3.3 Loading Triples and Quads .......................................................46 3.2.3.4 Import Options ..........................................................................47 3.2.3.5 Specifying Collections and a Directory ....................................49 3.2.4 Loading Triples with XQuery ...................................................................51 3.2.4.1 sem:rdf-insert ............................................................................52 3.2.4.2 sem:rdf-load ..............................................................................53 3.2.4.3 sem:rdf-get ................................................................................53 3.2.5 Loading Triples with JavaScript ...............................................................54 3.2.5.1 sem.rdfInsert ..............................................................................55 3.2.5.2 sem.rdfLoad ...............................................................................56 3.2.5.3 sem.rdfGet .................................................................................56 3.2.6 Loading Triples Using the REST API ......................................................56 3.2.6.1 Preparation ................................................................................57 3.2.6.2 Addressing the Graph Store ......................................................57 3.2.6.3 Specifying Parameters ...............................................................58 3.2.6.4 Supported Verbs ........................................................................58 3.2.6.5 Supported Media Formats .........................................................59 3.2.6.6 Loading Triples .........................................................................59 3.2.6.7 Response Errors .........................................................................60 3.2.7 Loading Triples Using the Java API .........................................................61 3.2.8 Loading Triples Using the Node.js API ....................................................61 4.0 Triple Index Overview ................................................................................63 4.1 Understanding the Triple Index and How It’s Used .............................................63 4.1.1 Triple Data and Value Caches ..................................................................63 4.1.1.1 Triple Cache and Triple Value Cache .......................................64 4.1.2 Triple Values and Type Information ........................................................64 4.1.3 Triple Positions .........................................................................................64 4.1.4 Index Files .................................................................................................65 4.1.5 Permutations .............................................................................................66 4.2 Enabling the Triple Index .....................................................................................66 4.2.1 Using the Database Configuration Pages ..................................................66 4.2.2 Using the Admin API ...............................................................................68 4.3 Other Considerations ............................................................................................69 4.3.1 Sizing Caches ............................................................................................69 4.3.2 Unused Values and Types .........................................................................70 4.3.3 Scaling and Monitoring ............................................................................71 5.0 Unmanaged Triples ......................................................................................73 5.1 Uses for Triples in XML Documents ...................................................................76 MarkLogic 10—May, 2019 Semantic Graph Developer’s Guide—Page 4 MarkLogic Server Table of Contents 5.1.1 Context from the Document .....................................................................76 5.1.2 Combination Queries ................................................................................77 5.1.3 Security with Unmanaged Triples ............................................................78 5.2 Bitemporal Triples ................................................................................................78 6.0 Semantic Queries .........................................................................................81 6.1 Querying Triples with SPARQL ...........................................................................82 6.1.1 Types of SPARQL Queries .......................................................................82