如何使用SPARQL将新实例插入OWL本体
我想使用SPARQL insert语句将一个新实例插入到我的本体中。 示例实例:如何使用SPARQL将新实例插入OWL本体,sparql,owl,ontology,Sparql,Owl,Ontology,我想使用SPARQL insert语句将一个新实例插入到我的本体中。 示例实例: <owl:NamedIndividual rdf:about="http://www.test123.com/test123-ontology.owl#cap_123"> <rdf:type rdf:resource="http://www.test123.com/test123-ontology.owl#HealthBeauty"/> <description>Test tes
<owl:NamedIndividual rdf:about="http://www.test123.com/test123-ontology.owl#cap_123">
<rdf:type rdf:resource="http://www.test123.com/test123-ontology.owl#HealthBeauty"/>
<description>Test test test</description>
<hasPrice rdf:datatype="http://www.w3.org/2001/XMLSchema#integer">49</hasPrice>
<id rdf:datatype="http://www.w3.org/2001/XMLSchema#integer">123</id>
</owl:NamedIndividual>
我不知道如何完成查询的插入部分:
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX owl: <http://www.test123.com/test123-ontology.owl#>
PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
PREFIX oo: <http://www.w3.org/2002/07/owl#>
INSERT "
{
//...
}
前缀rdf:
前缀owl:
前缀xsd:
前缀oo:
插入“
{
//...
}
解决方案如下:
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX owl: <http://www.test123.com/test123-ontology.owl#>
PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
PREFIX oo: <http://www.w3.org/2002/07/owl#>
INSERT
{
owl:cap_456 rdf:type owl:HealthBeauty .
owl:cap_456 owl:id 456 .
owl:cap_456 owl:hasPrice 15 .
owl:cap_456 owl:description 'Test2 test2 test2' . }
WHERE
{
FILTER NOT EXISTS
{
owl:cap_456 rdf:type owl:HealthBeauty .
}
}
前缀rdf:
前缀owl:
前缀xsd:
前缀oo:
插入
{
猫头鹰:cap_456 rdf:type猫头鹰:HealthBeauty。
猫头鹰:cap_456猫头鹰:id 456。
猫头鹰:cap_456猫头鹰:价格15。
owl:cap_456 owl:description'test2test2test2'
哪里
{
筛选器不存在
{
猫头鹰:cap_456 rdf:type猫头鹰:HealthBeauty。
}
}
前缀rdf:
前缀owl:
前缀xsd:
前缀oo:
插入数据
{
猫头鹰:cap_456 rdf:type猫头鹰:HealthBeauty;
rdf:type oo:NamedIndividual;
猫头鹰:ID456;
猫头鹰:价格15;
owl:description'test2test2test2'。
}
这在W3C规范中记录得非常清楚:@AKSW:I不理解如何指定此部分rdf:type rdf:resource=”http://www.test123.com/test123-ontology.owl#HealthBeauty“/>
我不明白。一切都是一个三元组,因此,它只是rdf:type。
我真的建议您使用TURTLE或N-Triples语法查看数据。这接近SPARQL三元组模式,当然也接近三元组。如果您使用的是Protégé,SPARQL更新没有在那里实现。我不明白为什么您需要一个WHERE
子句,而不是像我在前面的评论中提到的那样简单地使用INSERT DATA
。你没有任何三重模式,也就是说,没有变量-只是三重模式。WHERE
子句用于匹配数据中的模式,插入中不需要额外的三元组吗<代码>owl:cap_456 rdf:type oo:NamedIndividual
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX owl: <http://www.test123.com/test123-ontology.owl#>
PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
PREFIX oo: <http://www.w3.org/2002/07/owl#>
INSERT
{
owl:cap_456 rdf:type owl:HealthBeauty .
owl:cap_456 owl:id 456 .
owl:cap_456 owl:hasPrice 15 .
owl:cap_456 owl:description 'Test2 test2 test2' . }
WHERE
{
FILTER NOT EXISTS
{
owl:cap_456 rdf:type owl:HealthBeauty .
}
}
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX owl: <http://www.test123.com/test123-ontology.owl#>
PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
PREFIX oo: <http://www.w3.org/2002/07/owl#>
INSERT DATA
{
owl:cap_456 rdf:type owl:HealthBeauty;
rdf:type oo:NamedIndividual;
owl:id 456 ;
owl:hasPrice 15;
owl:description 'Test2 test2 test2' .
}