QQ群:三人行(语义有你) 150461365 SPARQL 陈 涛 2016/4/1
提纲 SPARQL语法分析 SPARQL Endpoint案例分享 以家谱知识库为例 Data Mashup
SPARQL语法分析
SPARQL SPARQL Protocol And Rdf Query Language SPARQL for triple store SQL for relationship database
Triple Store Oracle NoSQL AllegroGraph OpenLink Virtuoso Stardog Others 4store | BigData | TDB | MarcLogic
RDF Benefits RDF-based solutions, have benefits such as the following: A simple and uniform standard data model.. A powerful standard query language. Standardized data interchange formats. JSON-LD RDF/XML N-Triples Turtle
SPARQL Form
查询模式 SELECT - 返回全部或者部分查询结果中的变量; ASK - 返回TRUE或FALSE,判断查询结果是否存在; DESCRIBE - 返回查询结果中资源的RDF Graph; CONSTRUCT - 依据查询结果中的三元组变量,返回 新的RDF Graph。
查询所有人 fn Becky smith John Smith Matt Jones PREFIX vcard: <http://www.w3.org/2001/vcard-rdf/3.0#> SELECT ?fn WHERE { ?s vcard:FN ?fn. } ORDER BY ?fn fn Becky smith John Smith Matt Jones Sarah Jones
查询Family为Jones的人 fn Matt Jones Sarah Jones PREFIX vcard: <http://www.w3.org/2001/vcard-rdf/3.0#> SELECT ?fn WHERE { ?s vcard:FN ?fn ; vcard:N ?n . ?n vcard:Family ‘Jones’ . } ORDER BY ?fn fn Matt Jones Sarah Jones
图模式 Basic Graph Patterns, where a set of triple patterns must match Group Graph Pattern, where a set of graph patterns must all match Optional Graph patterns, where additional patterns may extend the solution Alternative Graph Pattern, where two or more possible patterns are tried Patterns on Named Graphs, where patterns are matched against named graphs
http://www.w3.org/2001/vcard-rdf/3.0#AGE 29
查询所有人及年龄 PREFIX vcard: <http://www.w3.org/2001/vcard-rdf/3.0#> SELECT ?fn ?age WHERE { ?s vcard:FN ?fn. ?s vcard:AGE ?age . } ORDER BY ?fn fn age Sarah Jones 29
查询所有人及年龄 PREFIX vcard: <http://www.w3.org/2001/vcard-rdf/3.0#> SELECT ?fn ?age WHERE { ?s vcard:FN ?fn. OPTIONAL {?s vcard:AGE ?age .} } ORDER BY ?fn fn age Becky smith John Smith Matt Jones Sarah Jones 29
结果修饰 结果修饰符能够影响查询的返回结果,从而使查 询在作用范围的广度和作用效果的程度上都有显 著地增强。结果修饰符主要包含以下几种: DISTINCT REDUCED ORDER BY OFFSET 和 LIMIT
Syntax for Literals “chat” 'chat'@fr with language tag "fr" "xyz"^^<http://example.org/ns/userDatatype> 1, which is the same as "1"^^xsd:integer 1.3, which is the same as "1.3"^^xsd:decimal 1.0e6, which is the same as "1.0e6"^^xsd:double true, which is the same as "true"^^xsd:boolean
ASK PREFIX vcard: <http://www.w3.org/2001/vcard-rdf/3.0#> ASK { ?s vcard:FN ‘John Smith’. } ?s vcard:FN ‘Jack Smith’. true false
DESCRIBE PREFIX bibo: <http://purl.org/ontology/bibo/> DESCRIBE ?s WHERE { ?s bibo:issn ‘0419-5992’ . } 0419-5992 ?s 美国 Trends in … WOS:000350…
CONSTRUCT PREFIX bibo: <http://purl.org/ontology/bibo/> CONSTRUCT {?s dc:author ‘John Smith’ .} WHERE { ?s bibo:issn ‘0419-5992’ . } 0419-5992 ?s John Smith 美国 Trends in … WOS:000350…
不会返回资源的所有信息 只返回Construct中要求的信息
SPARQL Endpoint案例分享
SPARQL Endpoint SPARQL Endpoint in the semantic web world - and is the way in which the data on the semantic web is published to the outside world in a query enabled form. A SPARQL endpoint enables users (human or other) to query a knowledge base via the SPARQL language.
家谱知识库 SPARQL Endpoint http://data.library.sh.cn:8890/sparql
RESTful调用 http://data.library.sh.cn:8890/sparql Client需要提交的参数: default-graph-uri=http://gen.library.sh.cn/graph/person query=select * where {?s bf:label ?name. filter contains(str(?name), ‘陈’)} format=json
Data Mashup
Leucovorin亚叶酸
Leucovorin亚叶酸
独立 开放 关联
Give a little, Get a little!