zoukankan      html  css  js  c++  java
  • sparql查询语言学习摘要

    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 ?title
    WHERE
    {
    <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  ?title
    WHERE   { ?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 Literals
    4.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  $title
    WHERE   { :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 ?mbox
    WHERE  {
           ?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 ?price
    WHERE   { ?x dc:title ?title .
            OPTIONAL { ?x ns:price ?price . FILTER (?price < 30) }
          }

    Multiple Optional Graph Patterns

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

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

    UNION:

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

    8. RDF Dataset 数据集合

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

    排序 ORDER BY:

    SELECT ?name
    WHERE { ?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  ?name
    WHERE   { ?x foaf:name ?name }
    ORDER BY ?name
    LIMIT   5
    OFFSET  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 Evaluation
    A  B  A || B  A && B
    T  T  T  T
    T  F  T  F
    F  T  T  F
    F  F  F  F
    T  E  T  E
    E  T  T  E
    F  E  E  F
    E  F  E  F
    E  E  E  E
    12. SPARQL定义 Definition of SPARQL
    RDF 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.

  • 相关阅读:
    Mybatis学习笔记2:第一个Mybatis使用实例
    Mybatis学习笔记1:Mybatis简介
    springcloud Eureka 服务注册与发现
    springcloud rest微服务案例
    springmvc返回json
    springboot 集成mybatisplus
    vue axios使用
    vue前后端交互方式
    day3
    D. Count the Arrays
  • 原文地址:https://www.cnblogs.com/bluejoe/p/5116028.html
Copyright © 2011-2022 走看看