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 版

第 1 章.直接进入:一些数据和一些查询

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

第 2 章提供了一些关于 RDF、语义网和 SPARQL 的背景知识,但在介绍这些知识之前,让我们先从编写和运行 SPARQL 查询的实践经验开始,以免背景知识部分显得过于理论化。

首先,什么是 SPARQL ?这个名字是 SPARQL 协议和 RDF 查询语言的递归首字母缩写,由 W3C 的一套规范描述。

注释

W3C ,即万维网联盟,是负责 HTML、XML 和 CSS 的同一标准机构。

从其名称中的 "RQL "部分可以看出,SPARQL 是为查询 RDF 而设计的,但您并不局限于查询以 RDF 格式之一存储的数据。商业和开源实用程序可将关系数据、XML、JSON、电子表格和其他格式的数据视为 RDF,因此您可以针对这些格式的数据或这些数据源的组合发出 SPARQL 查询,这是 SPARQL/RDF 组合最强大的方面之一。

SPARQL 名称中的 "协议"部分指的是客户端程序和 SPARQL 处理服务器之间交换 SPARQL 查询和结果的规则。这些规则在查询规范文档之外的另一份文档中规定,主要是 SPARQL 处理器开发人员的问题。使用查询语言可以走得很远,无需担心协议问题,因此本书不对其进行详细介绍。

要查询的数据

第 2 章将介绍更多有关 RDF 的内容以及人们使用 RDF 所做的各种事情,但我们可以总结一下:RDF 不是一种数据格式,而是一种数据模型,有多种语法可供选择,用于存储数据文件。在这种数据模型中,你可以用三部分语句来表达事实,这些语句被称为三元组 。每个三元组就像一个陈述事实的小句子。我们将三元组的三个部分分别称为主语谓语宾语 ,但您也可以将它们视为被描述事物("资源";RDF 是 "资源描述框架"的缩写)的标识符、属性 名称和属性值:

主题(资源标识符)谓词(属性名称)对象(属性值)
理查德家庭电话(229) 276-5135
辛迪电子邮件cindym@gmail.com

下面的 ex002.ttl 文件使用Turtle RDF 格式表达了一些三元组。(我们将在第 2 章中学习 Turtle 和其他格式。)该文件使用三元组存储地址簿数据,这些三元组的语句包括 "richard 的 homeTel 值是 (229) 276-5135 "和 "cindy 的 email 值是 cindym@gmail.com"。RDF 对给定资源的给定属性分配多个值没有问题,正如您在此文件中看到的,该文件显示 Craig 有两个电子邮件地址:

# filename: ex002.ttl

@prefix ab: <http://learningsparql.com/ns/addressbook#> .

ab:richard ab:homeTel "(229) 276-5135" . 
ab:richard ab:email   "richard49@hotmail.com" . 

ab:cindy ab:homeTel "(245) 646-5488" . 
ab:cindy ab:email   "cindym@gmail.com" . 

ab:craig ab:homeTel "(194) 966-1505" . 
ab:craig ab:email   "craigellis@yahoo.com" . 
ab:craig ab:email   "c.ellis@usairwaysgroup.com" .

与英文句子一样,Turtle(和 ...

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