我发现语义web是动态类型的!例如,我一直在查询生日,直到现在我已经找到了xsd:Integer
s。但是,现在我在查询另一个人时收到了xsd:date
。当从静态类型语言中使用时,如何处理此问题?
根据DBpedia wiki的4.3 Infobox数据,使用dbpprop
命名空间(http://dbpedia.org/property/
)属性的三元组要脏得多:
因此,只有当您的应用程序需要完全覆盖所有Wikipeda属性并且您准备接受相对嘈杂的数据时,您才应该使用infobox数据集。
您将从dbpedia-owl
(http://dbpedia.org/ontology/
)名称空间获得更一致的属性数据:
infobox本体中的实例数据比infobox Dataset更干净,结构更好
例如,如果您使用dbprop:dateOfBirth
抓取20个生日日期,您将获得整数和日期:
SELECT distinct ?date WHERE {
?x dbpprop:dateOfBirth ?date
}
LIMIT 10
SPARQL结果date
"1908"^^<http://www.w3.org/2001/XMLSchema#int>
1946-03-14
1951-06-15
"1984"^^<http://www.w3.org/2001/XMLSchema#int>
1878-11-09
"24"^^<http://www.w3.org/2001/XMLSchema#int>
"21"^^<http://www.w3.org/2001/XMLSchema#int>
"2"^^<http://www.w3.org/2001/XMLSchema#int>
"14"^^<http://www.w3.org/2001/XMLSchema#int>
1922-02-10
使用dbpedia-owl:birthDate
会得到更一致的结果:
SELECT distinct ?date WHERE {
?x dbpedia-owl:birthDate ?date
}
LIMIT 10
SPARQL结果date
0001-01-01
0001-03-12
0005-02-27
0012-08-31
0012-12-07
0015-09-24
0016-09-16
0019-05-26
0019-11-25
0030-11-08
也就是说,数据中仍然存在一些噪声。例如,这里有一个查询,它告诉我们dbpedia-owl:birthDate
的对象具有什么数据类型,以及对于每种类型,dbpedia-owl:birthDate
具有该类型对象的次数,以及该类型的示例对象作为dbpedia-owl:birthDate
的对象出现的次数。
SELECT ?datetype (COUNT(?date) as ?numberOfType ) (SAMPLE(?date) as ?exampleDate )WHERE {
[] dbpedia-owl:birthDate ?date .
BIND ( datatype( ?date ) as ?datetype )
}
GROUP BY ?datetype
ORDER BY DESC(?numberOfType)
SPARQL结果datetype numberOfType exampleDate
http://www.w3.org/2001/XMLSchema#date 608771 0001-01-01
http://www.w3.org/2001/XMLSchema#gMonthDay 1185 "--02-29"^^<http://www.w3.org/2001/XMLSchema#gMonthDay>
http://www.w3.org/2001/XMLSchema#string 246 "--01-01"^^<http://www.w3.org/2001/XMLSchema#gMonthDay>
大部分日期为xsd:date
s。我不知道为什么xsd:gMonthDay
出现一个xsd:string
的例子。