假设您正在通过SPARQL端点查询数据源,并且您想知道此数据源的基础表示是OWL还是RDF / XML。无论如何,您是否可以通过SPARQL查询执行此操作? 我个人的想法是编写一个使用其中一个OWL属性的查询,看看是否返回任何结果,但是使用这种方法的缺点是如果你使用的OWL属性甚至没有出现在数据源中如果基础表示是OWL,则不会得到响应。这里的假设是您无权访问架构。
答案 0 :(得分:1)
我认为一个有趣的方法是编写一个查询来获取所有三元组,这些三元组涉及您关注的模式语言的一些保留URI,这应该有希望为您提供模式或本体。例如,来自OWL规范的§2.4 IRIs给出了OWL的保留IRI列表。像这样的查询有望为您提供大多数所需的信息:
prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#>
prefix xsd: <http://www.w3.org/2001/XMLSchema#>
prefix owl: <http://www.w3.org/2002/07/owl#>
construct { ?s ?p ?o }
where {
values ?res {
owl:backwardCompatibleWith owl:bottomDataProperty owl:bottomObjectProperty owl:deprecated owl:incompatibleWith
owl:Nothing owl:priorVersion owl:rational owl:real owl:versionInfo
owl:Thing owl:topDataProperty owl:topObjectProperty rdf:langRange rdf:PlainLiteral
rdf:XMLLiteral rdfs:comment rdfs:isDefinedBy rdfs:label rdfs:Literal
rdfs:seeAlso xsd:anyURI xsd:base64Binary xsd:boolean xsd:byte
xsd:dateTime xsd:dateTimeStamp xsd:decimal xsd:double xsd:float
xsd:hexBinary xsd:int xsd:integer xsd:language xsd:length
xsd:long xsd:maxExclusive xsd:maxInclusive xsd:maxLength xsd:minExclusive
xsd:minInclusive xsd:minLength xsd:Name xsd:NCName xsd:negativeInteger
xsd:NMTOKEN xsd:nonNegativeInteger xsd:nonPositiveInteger xsd:normalizedString xsd:pattern
xsd:positiveInteger xsd:short xsd:string xsd:token xsd:unsignedByte
xsd:unsignedInt xsd:unsignedLong xsd:unsignedShort
}
{ ?res ?p ?o . bind( ?res as ?s ) } union
{ ?s ?res ?o . bind( ?res as ?p ) } union
{ ?s ?p ?res . bind( ?res as ?o ) }
}
同样,您可以使用以下内容来提取RDFS模式。此处的保留属性列表基于RDFS建议中的§6. RDF Schema summary (Informative)。我删除了rdf:type
,因为它总是有很多。
prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#>
prefix xsd: <http://www.w3.org/2001/XMLSchema#>
prefix owl: <http://www.w3.org/2002/07/owl#>
construct { ?s ?p ?o }
where {
values ?res {
rdfs:Resource rdfs:Literal rdf:XMLLiteral rdfs:Class rdf:Property
rdfs:Datatype rdf:Statement rdf:Bag rdf:Seq rdf:Alt rdfs:Container
rdfs:ContainerMembershipProperty rdf:List rdfs:subClassOf
rdfs:subPropertyOf rdfs:domain rdfs:range rdfs:label rdfs:comment
rdfs:member rdf:first rdf:rest rdfs:seeAlso rdfs:isDefinedBy
rdf:value rdf:subject rdf:predicate rdf:object
}
{ ?res ?p ?o . bind( ?res as ?s ) } union
{ ?s ?res ?o . bind( ?res as ?p ) } union
{ ?s ?p ?res . bind( ?res as ?o ) }
}
如果针对数据集运行这两个查询,您可能会对数据的结构进行有根据的猜测。请注意,许多RDFS属性也被OWL使用,因此粗略的启发式可能是: