【发布时间】:2016-09-28 23:48:40
【问题描述】:
我正在使用这种艺术本体:http://spraakdata.gu.se/svedd/painting-ontology/painting.owl 使用 SPARQL 和 PHP 库 ARC2 进行语义 Web 项目(我完全是该主题的新手)。我正在使用以下代码。它有效,但结果不完整:
<?php
include_once("arc2/ARC2.php");
$config = array(
/* db */
'db_name' => 'ontologia',
'db_user' => 'root',
'db_pwd' => '',
/* store */
'store_name' => 'arc_tests',
/* stop after 100 errors */
'max_errors' => 100,
);
$store = ARC2::getStore($config);
if (!$store->isSetUp()) {
$store->setUp();
}
/* LOAD will call the Web reader, which will call the
format detector, which in turn triggers the inclusion of an
appropriate parser, etc. until the triples end up in the store. */
//$store->query('LOAD <http://localhost/ontologia/painting2.owl.xml>');
$q = '
PREFIX painting: <http://spraakbanken.gu.se/rdf/owl/painting.owl#>
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
SELECT *
WHERE {
?subject painting:createdBy ?object;
rdfs:label ?title.
}';
$r = '';
$id = 0;
if ($rows = $store->query($q, 'rows')) {
/* display the results in an HTML table */
echo "<table border='1'>
<thead>
<th>#</th>
<th>(Subject)</th>
<th>title</th>
</thead>";
/* loop for each returned row */
foreach( $rows as $row ) {
print "<tr><td>".++$id. "</td>
<td>" . $row['subject']. "</td>".
"<td>" . $row['title']. "</td>";
}
echo "</table>" ;
}
else{
echo "No hay resultados";
}
//$rs = $store->query('...');
$p='';
if ($errs = $store->getErrors()) {
/* $errs contains errors from the store and any called
sub-component such as the query processor, parsers, or
the web reader */
foreach ($errs as $err) {
$p .= '<li>' . $err. '</li>';
}
echo $p;
}
?>
在这种情况下,查询会查找所有带有谓词“createdBy”的三元组。 我只得到两个结果:
但我可以在本体中看到有很多画有那个谓词 noy 只有那些。但是它们没有“标签”属性,例如“格尔尼卡”:
<owl:NamedIndividual rdf:about="http://spraakbanken.gu.se/rdf/owl/painting.owl#GuernicaObj">
<rdf:type rdf:resource="http://spraakbanken.gu.se/rdf/owl/painting.owl#Painting"/>
<rdf:type rdf:resource="http://spraakbanken.gu.se/rdf/owl/painting.owl#Reference"/>
<hasIntendedUse rdf:resource="http://spraakbanken.gu.se/rdf/owl/painting.owl#Attention"/>
<hasColor rdf:resource="http://spraakbanken.gu.se/rdf/owl/painting.owl#Black"/>
<hasColor rdf:resource="http://spraakbanken.gu.se/rdf/owl/painting.owl#Gray"/>
<hasCreationDate rdf:resource="http://spraakbanken.gu.se/rdf/owl/painting.owl#GuernicaCreationDate"/>
<hasDimension rdf:resource="http://spraakbanken.gu.se/rdf/owl/painting.owl#GuernicaHeight"/>
<hasRepresentation rdf:resource="http://spraakbanken.gu.se/rdf/owl/painting.owl#GuernicaJPG"/>
<hasTitle rdf:resource="http://spraakbanken.gu.se/rdf/owl/painting.owl#GuernicaTitle"/>
<displayedAt rdf:resource="http://spraakbanken.gu.se/rdf/owl/painting.owl#InternationalExposition"/>
<hasCurrentLocation rdf:resource="http://spraakbanken.gu.se/rdf/owl/painting.owl#MuseoReinaSofía"/>
<createdBy rdf:resource="http://spraakbanken.gu.se/rdf/owl/painting.owl#PabloPicasso"/>
<hasPaintType rdf:resource="http://spraakbanken.gu.se/rdf/owl/painting.owl#StandOil"/>
<hasColor rdf:resource="http://spraakbanken.gu.se/rdf/owl/painting.owl#White"/>
</owl:NamedIndividual>
有些绘画具有某些结构和一些重要属性(如 label 或 createdBy),但有些则没有,这使得处理变得更加困难。如何搜索这样的本体?难道我做错了什么?。本体构造不好?
【问题讨论】: