sparql操作数据

近期工作使用到了sparql。对于sparql就是用来增删改成RDF数据的,至于RDF如果不太明白可以上网查阅一下,这里就不进行阐述了。
以下是sparql语句的增删改查,大家可以分别对比下sql进行了解。
最常用的查询语句:

prefix fxbase: <http://dcpf/term/3.0/>
prefix dcpf: <http://dcpf3d123/>
prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#>
prefix dcterms: <http://purl.org/dc/terms/>
prefix vcard: <http://www.w3.org/2001/vcard-rdf/3.0#>
prefix foaf: <http://xmlns.com/foaf/0.1/>
prefix solrs: <http://nosuchdomain/SolrSearch/property#>
select *
where
{
?student fxbase:student_name ?name.
filter(eric=?name)
optional
{
?student fxbase:student_sex ?sex.
}
}

?student fxbase:student_name ?name. //在student_name表中查找所有名字。
stuName fxbase:student_name ?name. //在student_name表中查找行为stuName的名字。
filter一个过滤器,大家都应该明白。
optional是说如果optional中查询有值则显示,没有就不显示。
增加语句:

prefix fxbase: <http://dcpf/term/3.0/>
prefix dcpf: <http://dcpf3d123/>
prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#>
prefix dcterms: <http://purl.org/dc/terms/>
prefix vcard: <http://www.w3.org/2001/vcard-rdf/3.0#>
prefix foaf: <http://xmlns.com/foaf/0.1/>
prefix solrs: <http://nosuchdomain/SolrSearch/property#>
insert
{
stuEric rdf:type fxbase:student_name.
stuEric fxbase:student_name "eric".
}
where
{}

修改语句:

prefix fxbase: <http://dcpf/term/3.0/>
prefix dcpf: <http://dcpf3d123/>
prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#>
prefix dcterms: <http://purl.org/dc/terms/>
prefix vcard: <http://www.w3.org/2001/vcard-rdf/3.0#>
prefix foaf: <http://xmlns.com/foaf/0.1/>
prefix solrs: <http://nosuchdomain/SolrSearch/property#>
delete
{
stuEric fxbase:student_name "eric".
}
insert
{
stuEric fxbase:student_name "will".
}
where{}
  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值