Skip to Content
学习 SPARQL,第 2 版
book

学习 SPARQL,第 2 版

by Bob DuCharme
July 2025
Beginner to intermediate
386 pages
5h 25m
Chinese
O'Reilly Media, Inc.
Content preview from 学习 SPARQL,第 2 版

第 6 章 使用 SPARQL 更新数据使用 SPARQL 更新数据

本作品已使用人工智能进行翻译。欢迎您提供反馈和意见:translation-feedback@oreilly.com

从集合中提取数据并以任何方式重新排列和交叉引用固然很好,但如果能使用标准查询语言向集合中添加数据、删除和更新数据,就可以围绕 RDF 灵活的数据模型构建成熟的应用程序了。SPARQL 1.1 Update 规范描述了实现这一功能的语法和选项,虽然它是 SPARQL 的最新补充,但已有多个实现支持它。本章使用最简单的 SPARQL Update 实现之一 Fuseki 来演示各种示例。

注意

大多数 SPARQL Update 语言的实现都内置在 triplestore 中,让你可以对 triplestore 中的数据采取行动。作为一个本质上的数据库管理程序(如果不是关系型数据库管理程序的话),triplestore 应该允许你使用 SPARQL 查询语言查询数据,并使用更新语言管理数据。

在本章中,我们将学习以下内容:

开始使用 Fuseki

只需了解 Fuseki,就能尝试 SPARQL 更新的所有关键部分

向数据集添加数据

如何将查询中指定的三元组和远程来源的三元组添加到数据集的默认图中

删除数据

如何从默认图中删除数据

更改现有数据

如何替换数据集默认图中的现有三元组

命名图表

如何创建命名图、向其中添加三元组、从中删除三元组以及替换三元组和整个图

Fuseki 入门

Fuseki 是 Jena 项目的一部分。它自称为 "SPARQL 服务器",是一个网络服务器 triplestore,可接受在网络表单上输入的 SPARQL 查询,以及以 HTTP 请求形式发送的 SPARQL 查询。在本章中,我们将使用网络表单;在SPARQL 和 HTTP 中,我们将学习如何使用其 HTTP 接口。

警告

截至本文撰写之时,Fuseki 的最新正式版本为 0.2.6。Fuseki 的各种功能和随附文档已令人印象深刻,但如果您使用的是后续版本,可能会发现与本章所述内容有一些差异。

要下载 Fuseki,请点击主页上的下载链接,获取二进制 ZIP 文件,文件名格式为 jena-fuseki-*-distribution.zip。解压缩后,您就可以开始使用了。它包含一个名为fuseki-server的 shell 脚本,可以在 Linux 或 Mac 上启动它,还包含一个fuseki-server.bat 批处理文件,可以在 Windows 下启动它。你可以通过以下命令了解 Fuseki 的命令行选项:

fuseki-server --help

在启动 Fuseki 服务器之前,我在发行版的根目录下创建了一个子目录,并将其命名为dataDir 。然后,为了在 Windows 或 Linux 机器上将 Fuseki 作为服务器启动,我使用这些参数运行了 fuseki-server 脚本:

fuseki-server --update --loc=dataDir /myDataset

该命令行包含以下参数:

--update

告诉 Fuseki 允许更新存储的数据。否则,它将默认为只读模式。

--loc=dataDir

告诉它将数据存储在 TDB 数据库 中,并将其存储在我刚刚创建的 ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.

Read now

Unlock full access

More than 5,000 organizations count on O’Reilly

AirBnbBlueOriginElectronic ArtsHomeDepotNasdaqRakutenTata Consultancy Services

QuotationMarkO’Reilly covers everything we've got, with content to help us build a world-class technology community, upgrade the capabilities and competencies of our teams, and improve overall team performance as well as their engagement.
Julian F.
Head of Cybersecurity
QuotationMarkI wanted to learn C and C++, but it didn't click for me until I picked up an O'Reilly book. When I went on the O’Reilly platform, I was astonished to find all the books there, plus live events and sandboxes so you could play around with the technology.
Addison B.
Field Engineer
QuotationMarkI’ve been on the O’Reilly platform for more than eight years. I use a couple of learning platforms, but I'm on O'Reilly more than anybody else. When you're there, you start learning. I'm never disappointed.
Amir M.
Data Platform Tech Lead
QuotationMarkI'm always learning. So when I got on to O'Reilly, I was like a kid in a candy store. There are playlists. There are answers. There's on-demand training. It's worth its weight in gold, in terms of what it allows me to do.
Mark W.
Embedded Software Engineer

You might also like

向量数据库 (Chinese Edition)

向量数据库 (Chinese Edition)

Nitin Borwankar
Python文本分析

Python文本分析

Jens Albrecht, Sidharth Ramachandran, Christian Winkler

Publisher Resources

ISBN: 9798341663039