[转】sparql查询语言学习摘要

来源:互联网 发布:谭浩强c语言视频讲解 编辑:程序博客网 时间:2024/04/29 20:22

SPARQL Query Language for RDF

Contents

    * 1. Intoduction    * 2. Making Simple Queries    * 3. RDF Term Constraints    * 4. SPARQL Syntax (语法)          o 4.1 IRIs (URIs)          o 4.2 平凡文字的语法 Syntax for Literals          o 4.3 查询变量的Syntax          o 4.4 空白节点的语法          o 4.5 三元组模型语法          o 4.6 谓-宾列表          o 4.7 宾语列表          o 4.8 复合列表          o 4.9 RDF集合          o 4.10 当rdf:type是谓词时可用a代替    * 5. Graph Patterns (模式)          o 5.1 Group Graph Patterns          o 5.2 Empty Group Pattern          o 5.3 Scope of Filters 过滤范围    * 6. Including Optional Values (可选值)    * 7. 匹配两个中的一个 Matching Alternatives    * 8. RDF Dataset 数据集合    * 9. 结果排序和修改 Solution Sequences and Modifiers          o 重复结果 Duplicate Soulution    * 10. 查询形式 Query Forms    * 11. 测试值 Testing Values          o 操作数数据类型Openrand Data Types          o 过滤评价 Filter Evaluation    * 12. SPARQL定义 Definition of SPARQL          o RDF Terms(术语)

1. Intoduction

    * Turtle data format (Tutle数据格式)

2. Making Simple Queries

简单查询:

SELECT ?titleWHERE{ <http://example.org/book/book1> <http://purl.org/dc/elements/1.1/title> ?title .}

Building RDF Graphs, 用Construct代替Select:

CONSTRUCT { ?x foaf:name ?name }WHERE  { ?x org:employeeName ?name }

3. RDF Term Constraints

正则表达式过滤 FILTER regex():

PREFIX  dc:  <http://purl.org/dc/elements/1.1/>SELECT  ?titleWHERE   { ?x dc:title ?title          FILTER regex(?title, "web", "i" )        }

4. SPARQL Syntax (语法)4.1 IRIs (URIs)

同一个IRI的不同表示方式:

<http://example.org/book/book1>

BASE <http://example.org/book/><book1>

PREFIX book: <http://example.org/book/>book:book1

4.2 平凡文字的语法 Syntax for Literals4.3 查询变量的Syntax

    '?','$' 两者是等价的

4.4 空白节点的语法

[ :p "v" ] .[] :p "v" ._:b57 :p "v" . //前面加_:的标签[ :p "v" ] :q "w" . //空白节点的组合

简略空白节点:

[ foaf:name  ?name ;    foaf:mbox  <mailto:alice@example.org> ]

4.5 三元组模型语法

PREFIX  dc: <http://purl.org/dc/elements/1.1/>PREFIX  : <http://example.org/book/>

SELECT  $titleWHERE   { :book1  dc:title  $title }

4.6 谓-宾列表

?x  foaf:name  ?name ;       foaf:mbox  ?mbox .

4.7 宾语列表

?x foaf:nick  "Alice" , "Alice_" .

4.8 复合列表

?x  foaf:name ?name ; foaf:nick  "Alice" , "Alice_" .

等价于:

?x  foaf:name  ?name .?x  foaf:nick  "Alice" .?x  foaf:nick  "Alice_" .

4.9 RDF集合

(1 ?x 3 4) :p "w" .

4.10 当rdf:type是谓词时可用a代替

?x  a  :Class1 .

5. Graph Patterns (模式)5.1 Group Graph Patterns

PREFIX foaf:    <http://xmlns.com/foaf/0.1/>SELECT ?name ?mboxWHERE  {       ?x foaf:name ?name .       ?x foaf:mbox ?mbox .    }

5.2 Empty Group Pattern

    {}        SELECT ?x WHERE {}

5.3 Scope of Filters 过滤范围

    FILTER regex(?name, "Smith")

6. Including Optional Values (可选值)

Optional Pattern Matching

WHERE  { ?x foaf:name  ?name .       OPTIONAL { ?x  foaf:mbox  ?mbox }     }

Constraints in Optional Pattern Matching

SELECT  ?title ?priceWHERE   { ?x dc:title ?title .        OPTIONAL { ?x ns:price ?price . FILTER (?price < 30) }      }

Multiple Optional Graph Patterns

SELECT ?name ?mbox ?hpageWHERE  { ?x foaf:name  ?name .       OPTIONAL { ?x foaf:mbox ?mbox } .       OPTIONAL { ?x foaf:homepage ?hpage }     }

7. 匹配两个中的一个 Matching Alternatives

UNION:

SELECT ?x ?yWHERE  { { ?book dc10:title ?x } UNION { ?book dc11:title  ?y } }

8. RDF Dataset 数据集合

查询多个Graph中的信息9. 结果排序和修改 Solution Sequences and Modifiers

排序 ORDER BY:

SELECT ?nameWHERE { ?x foaf:name ?name }ORDER BY ?name

映射 Projection重复结果 Duplicate Soulution

唯一 DISTINCT:

PREFIX foaf:    <http://xmlns.com/foaf/0.1/>SELECT DISTINCT ?name WHERE { ?x foaf:name ?name }

简化 REDUCED:

PREFIX foaf:    <http://xmlns.com/foaf/0.1/>SELECT REDUCED ?name WHERE { ?x foaf:name ?name }

偏移 OFFSET, 限制 LIMIT:

SELECT  ?nameWHERE   { ?x foaf:name ?name }ORDER BY ?nameLIMIT   5OFFSET  10

10. 查询形式 Query Forms

    *

      SELECT

          Returns all, or a subset of, the variables bound in a query pattern match.

    *

      CONSTRUCT

          Returns an RDF graph constructed by substituting variables in a set of triple templates.

    *

      ASK

          Returns a boolean indicating whether a query pattern matches or not.

    *

      DESCRIBE

          Returns an RDF graph that describes the resources found.

11. 测试值 Testing Values操作数数据类型Openrand Data Types

        * xsd:integer        * xsd:decimal        * xsd:float        * xsd:double        * xsd:string        * xsd:boolean        * xsd:dateTime

过滤评价 Filter EvaluationA  B  A || B  A && BT  T  T  TT  F  T  FF  T  T  FF  F  F  FT  E  T  EE  T  T  EF  E  E  FE  F  E  FE  E  E  E12. SPARQL定义 Definition of SPARQLRDF Terms(术语)

RDF Term:

RDF    Let I be the set of all IRIs. Let RDF-L be the set of all RDF Literals Let RDF-B be the set of all blank nodes in RDF graphs

View document source. Generated on: 2008-04-17 09:54 UTC. Generated by Docutils from reStructuredText source.

原创粉丝点击