使用 ARC2 使 ontology 对 PHP 网页可见?在线发布?
Make ontology visible to PHP web page using ARC2? Publish online?
我有一些 PHP 代码,用于根据 SPARQL 查询的结果创建动态网页。它现在不起作用,我认为那是因为我的 ontology 尚未在线发布。我如何做发布部分?
<html>
<body>
<?php
include_once('semsol/ARC2.php'); /* ARC2 static class inclusion */
$dbpconfig = array
(
"remote_store_endpoint" => "http://dbpedia.org/sparql",
);
$store = ARC2::getRemoteStore($dbpconfig);
if ($errs = $store->getErrors())
{
echo "<h1>getRemoteSotre error<h1>" ;
}
$query = '
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX owl: <http://www.w3.org/2002/07/owl#>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
PREFIX uni: <http://www.semanticweb.org/admin/ontologies/2017/4/untitled-ontology-19#>
SELECT ?property ?subject ?prop ?object
WHERE
{
uni:Product ?property ?subject .
OPTIONAL {?subject ?prop ?object }
}
';
$rows = $store->query($query, 'rows'); /* execute the query */
if ($errs = $store->getErrors())
{
echo "Query errors" ;
print_r($errs);
}
/* display the results in an HTML table */
echo "<table border='1'>" ;
foreach( $rows as $row )
{
/* loop for each returned row */
print "<tr><td>" .$row['l'] . "</td><td>" . $row['c']. "</td></tr>";
}
echo "</table>"
?>
</body>
</html>
<html>
<body>
<?php
include_once('semsol/ARC2.php'); /* ARC2 static class inclusion */
$dbpconfig = array
(
"remote_store_endpoint" => "http://dbpedia.org/sparql",
);
$store = ARC2::getRemoteStore($dbpconfig);
if ($errs = $store->getErrors())
{
echo "<h1>getRemoteSotre error<h1>" ;
}
$query = '
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX owl: <http://www.w3.org/2002/07/owl#>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
PREFIX uni: <http://www.semanticweb.org/admin/ontologies/2017/4/untitled-ontology-19#>
SELECT ?property ?subject ?prop ?object
WHERE
{
uni:Product ?property ?subject .
OPTIONAL {?subject ?prop ?object }
}
';
$rows = $store->query($query, 'rows'); /* execute the query */
if ($errs = $store->getErrors())
{
echo "Query errors" ;
print_r($errs);
}
/* display the results in an HTML table */
echo "<table border='1'>" ;
foreach( $rows as $row )
{
/* loop for each returned row */
print "<tr><td>" .$row['l'] . "</td><td>" . $row['c']. "</td></tr>";
}
echo "</table>"
?>
</body>
</html>
你还对这个感兴趣吗?以下对我有用。我试图说明如何 测试多部分系统的各个组件 ,而不是仅仅构建所有内容,测试最终产品然后说 "it doesn't work."
背景:我在 AWS 中使用 Ubuntu 16 服务器 运行ning。看来您可能对 Fuseki 作为后端有一些经验。稍作修改后,这些说明应该适用于 Ubuntu Linux、运行ning 以外的不同物理或虚拟环境中的操作系统,以及访问 Fuseki 以外的 sparql 端点。您可以 运行 PHP 脚本和 Fuseki 进程在同一台服务器或两台不同的服务器上。
您的先决条件职责:工作网络服务器和 php 解释器。默认的 Ubuntu apache2 和 php7 包对我来说只需要最少或零的额外配置。 You could follow instructions like these,跳过 MySQL 步骤。同一篇文章提供了一些配置防火墙的技巧。您有责任确定适当的世界可访问性级别。
- 下载(例如,http://www-eu.apache.org/dist/jena/binaries/apache-jena-fuseki-2.6.0.tar.gz)并解压其中一个 Fuseki 2 归档文件
- 如果您要 access the Fuseki dataset manager remotely,请编辑
run/shiro.ini
文件以启用适当的远程访问策略
- 对于 testing/proof-of-concept,cd 进入 Fuseki 目录并像这样启动 Fuseki
./fuseki-server --mem /default
不要关闭此终端会话! 您将需要打开其他任务的另一个会话。如果您希望流程和数据持续存在,则需要另一种启动 Fuseki 的方法。
- 使用网络浏览器访问 Fuseki 页面,地址如下:
http://server.domain:3030
- 单击 添加数据 按钮并上传一些数据。我之前在我的本地文件系统上将 pizza ontology 下载为
pizza.owl
,所以我单击 select files...
按钮,导航到我的 pizza.owl
文件,单击打开,然后单击 立即上传。如果您使用披萨 ontology,您应该会看到大约插入了 1980 个三元组。
- 现在,在 运行 编写任何脚本之前,请在 Fuseki 网络界面中进行现实检查和 运行 查询。 (单击左上角的查询 按钮选项卡。)
有哪些浇头,它们属于什么类?
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX pizza: <http://www.co-ode.org/ontologies/pizza/pizza.owl#>
SELECT *
WHERE {
?recursiveTopping rdfs:subClassOf+ pizza:PizzaTopping .
?recursiveTopping rdfs:label ?toppingLabel .
?recursiveTopping rdfs:subClassOf ?immediateParent .
filter(!isBlank(?immediateParent))
filter( ?immediateParent != pizza:PizzaTopping )
}
order by ?immediateParent ?recursiveTopping
如果 SPARQL 查询在 Fuseki Web 界面中有效,您就可以将其嵌入 php script/page.
- 在您的网络服务器的根目录中创建一个新文件夹。我在 Ubuntu 上使用 Apache httpd,所以那是
/var/www/html
。您可能需要以 root 身份执行此操作,如下所示:sudo mkdir /var/www/html/ARC2_pizza
- cd 进入新目录
- 复制本邮件底部的源代码
- 告诉计算机您要将一些文本粘贴到文件中:
cat > index.php
然后粘贴剪贴板中的文本。所需的操作将取决于您使用的界面。在 Ubuntu 终端中,使用 Shift-Control-v。在腻子中,单击鼠标右键。或者你可以使用像 nano 或 gedit 这样的文本编辑器来创建 index.php
... 请记住,编辑 /var/www/html 中的文件通常需要 root 权限,除非你更改了目录的所有权或访问权限,您的网络服务器可能不喜欢它。
脚本尚未准备好 运行!
您需要确保安装了 ARC2 库,您的脚本知道在哪里可以找到它,并且 remote_store_endpoint
参数设置为正确的地址。
可能有多种安装方式ARC2. I used composer,反过来又可以有多种安装方式,包括apt-get
sudo apt-get install composer
或卷曲
sudo apt-get install curl
curl -sS https://getcomposer.org/installer | sudo php -- --install-dir=/usr/local/bin --filename=composer
接着是
cd /var/www/html/ARC2_pizza
composer require "semsol/arc2": "dev-master"
关于 remote_store_endpoint
:如果您 运行 在与 Fuseki 服务器相同的服务器上运行 php 脚本(就像我一样),您可以使用 localhost
.否则,使用 Fuseki 服务器的完全限定 public IP 地址或名称。
根据您的情况自定义脚本后,从命令行对其进行测试(而不是使用 Web 浏览器访问它。)
php /var/www/html/ARC2_pizza/index.php
结果看起来不太好,但如果仔细观察,您应该会看到几种披萨配料的名称,用 HTML table 标签分隔,例如 ...<td><tr>...
如果成功了,您终于可以通过网络浏览器对其进行测试了。如果您使用过像我这样的设置,请将浏览器指向 http://server.domain/ARC2_pizza
这样的地址
如果您在网络浏览器中没有看到 table 披萨配料,那么您的网络服务器或防火墙设置有问题,而不是 Fuseki、查询、PHP和 ARC2 安装,或脚本。
这是 ARC2_pizza/index.php
的源代码。
这基于与您的问题相同的教程。不要忘记配置您的 ARC2 位置和端点地址
<html>
<body>
<?php
// customize your ARC2 location
include_once("/var/www/html/phprdftest/arc2-master/ARC2.php");
$dbpconfig = array
(
// customize your endpoint address
"remote_store_endpoint" => "http://localhost:3030/default/query",
);
$store = ARC2::getRemoteStore($dbpconfig);
if ($errs = $store->getErrors())
{
echo "<h1>getRemoteSotre error<h1>" ;
}
$query = '
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX pizza: <http://www.co-ode.org/ontologies/pizza/pizza.owl#>
SELECT *
WHERE {
?recursiveTopping rdfs:subClassOf+ pizza:PizzaTopping .
?recursiveTopping rdfs:label ?toppingLabel .
?recursiveTopping rdfs:subClassOf ?immediateParent .
filter(!isBlank(?immediateParent))
filter( ?immediateParent != pizza:PizzaTopping )
}
order by ?immediateParent ?recursiveTopping
';
$rows = $store->query($query, 'rows'); /* execute the query */
if ($errs = $store->getErrors())
{
echo "Query errors" ;
print_r($errs);
}
/* display the results in an HTML table */
echo "<table border='1'>" ;
foreach( $rows as $row )
{
/* loop for each returned row */
print "<tr><td>" .$row['recursiveTopping'] . "</td><td>" .
$row['toppingLabel']. "</td><td>" .
$row['immediateParent']. "</td></tr>";
}
echo "</table>"
?>
</body>
</html>
如果您正在使用 windows 那么您需要一个 mysql 备份所以首先安装 wamp 服务器然后 phpmyAdmin 数据库然后在存储查询命令添加中设置配置
存储 store->query('http://localhost/filename.owl').然后 运行 php 文件使用 wamp 服务器。您将在数据库中看到 rdf/xml 值 不要忘记在执行
之前在 www 文件夹中添加 ARC.php 文件和您的文件
我有一些 PHP 代码,用于根据 SPARQL 查询的结果创建动态网页。它现在不起作用,我认为那是因为我的 ontology 尚未在线发布。我如何做发布部分?
<html>
<body>
<?php
include_once('semsol/ARC2.php'); /* ARC2 static class inclusion */
$dbpconfig = array
(
"remote_store_endpoint" => "http://dbpedia.org/sparql",
);
$store = ARC2::getRemoteStore($dbpconfig);
if ($errs = $store->getErrors())
{
echo "<h1>getRemoteSotre error<h1>" ;
}
$query = '
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX owl: <http://www.w3.org/2002/07/owl#>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
PREFIX uni: <http://www.semanticweb.org/admin/ontologies/2017/4/untitled-ontology-19#>
SELECT ?property ?subject ?prop ?object
WHERE
{
uni:Product ?property ?subject .
OPTIONAL {?subject ?prop ?object }
}
';
$rows = $store->query($query, 'rows'); /* execute the query */
if ($errs = $store->getErrors())
{
echo "Query errors" ;
print_r($errs);
}
/* display the results in an HTML table */
echo "<table border='1'>" ;
foreach( $rows as $row )
{
/* loop for each returned row */
print "<tr><td>" .$row['l'] . "</td><td>" . $row['c']. "</td></tr>";
}
echo "</table>"
?>
</body>
</html>
<html>
<body>
<?php
include_once('semsol/ARC2.php'); /* ARC2 static class inclusion */
$dbpconfig = array
(
"remote_store_endpoint" => "http://dbpedia.org/sparql",
);
$store = ARC2::getRemoteStore($dbpconfig);
if ($errs = $store->getErrors())
{
echo "<h1>getRemoteSotre error<h1>" ;
}
$query = '
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX owl: <http://www.w3.org/2002/07/owl#>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
PREFIX uni: <http://www.semanticweb.org/admin/ontologies/2017/4/untitled-ontology-19#>
SELECT ?property ?subject ?prop ?object
WHERE
{
uni:Product ?property ?subject .
OPTIONAL {?subject ?prop ?object }
}
';
$rows = $store->query($query, 'rows'); /* execute the query */
if ($errs = $store->getErrors())
{
echo "Query errors" ;
print_r($errs);
}
/* display the results in an HTML table */
echo "<table border='1'>" ;
foreach( $rows as $row )
{
/* loop for each returned row */
print "<tr><td>" .$row['l'] . "</td><td>" . $row['c']. "</td></tr>";
}
echo "</table>"
?>
</body>
</html>
你还对这个感兴趣吗?以下对我有用。我试图说明如何 测试多部分系统的各个组件 ,而不是仅仅构建所有内容,测试最终产品然后说 "it doesn't work."
背景:我在 AWS 中使用 Ubuntu 16 服务器 运行ning。看来您可能对 Fuseki 作为后端有一些经验。稍作修改后,这些说明应该适用于 Ubuntu Linux、运行ning 以外的不同物理或虚拟环境中的操作系统,以及访问 Fuseki 以外的 sparql 端点。您可以 运行 PHP 脚本和 Fuseki 进程在同一台服务器或两台不同的服务器上。
您的先决条件职责:工作网络服务器和 php 解释器。默认的 Ubuntu apache2 和 php7 包对我来说只需要最少或零的额外配置。 You could follow instructions like these,跳过 MySQL 步骤。同一篇文章提供了一些配置防火墙的技巧。您有责任确定适当的世界可访问性级别。
- 下载(例如,http://www-eu.apache.org/dist/jena/binaries/apache-jena-fuseki-2.6.0.tar.gz)并解压其中一个 Fuseki 2 归档文件
- 如果您要 access the Fuseki dataset manager remotely,请编辑
run/shiro.ini
文件以启用适当的远程访问策略 - 对于 testing/proof-of-concept,cd 进入 Fuseki 目录并像这样启动 Fuseki
./fuseki-server --mem /default
不要关闭此终端会话! 您将需要打开其他任务的另一个会话。如果您希望流程和数据持续存在,则需要另一种启动 Fuseki 的方法。 - 使用网络浏览器访问 Fuseki 页面,地址如下:
http://server.domain:3030
- 单击 添加数据 按钮并上传一些数据。我之前在我的本地文件系统上将 pizza ontology 下载为
pizza.owl
,所以我单击select files...
按钮,导航到我的pizza.owl
文件,单击打开,然后单击 立即上传。如果您使用披萨 ontology,您应该会看到大约插入了 1980 个三元组。 - 现在,在 运行 编写任何脚本之前,请在 Fuseki 网络界面中进行现实检查和 运行 查询。 (单击左上角的查询 按钮选项卡。)
有哪些浇头,它们属于什么类?
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX pizza: <http://www.co-ode.org/ontologies/pizza/pizza.owl#>
SELECT *
WHERE {
?recursiveTopping rdfs:subClassOf+ pizza:PizzaTopping .
?recursiveTopping rdfs:label ?toppingLabel .
?recursiveTopping rdfs:subClassOf ?immediateParent .
filter(!isBlank(?immediateParent))
filter( ?immediateParent != pizza:PizzaTopping )
}
order by ?immediateParent ?recursiveTopping
如果 SPARQL 查询在 Fuseki Web 界面中有效,您就可以将其嵌入 php script/page.
- 在您的网络服务器的根目录中创建一个新文件夹。我在 Ubuntu 上使用 Apache httpd,所以那是
/var/www/html
。您可能需要以 root 身份执行此操作,如下所示:sudo mkdir /var/www/html/ARC2_pizza
- cd 进入新目录
- 复制本邮件底部的源代码
- 告诉计算机您要将一些文本粘贴到文件中:
cat > index.php
然后粘贴剪贴板中的文本。所需的操作将取决于您使用的界面。在 Ubuntu 终端中,使用 Shift-Control-v。在腻子中,单击鼠标右键。或者你可以使用像 nano 或 gedit 这样的文本编辑器来创建index.php
... 请记住,编辑 /var/www/html 中的文件通常需要 root 权限,除非你更改了目录的所有权或访问权限,您的网络服务器可能不喜欢它。
脚本尚未准备好 运行!
您需要确保安装了 ARC2 库,您的脚本知道在哪里可以找到它,并且 remote_store_endpoint
参数设置为正确的地址。
可能有多种安装方式ARC2. I used composer,反过来又可以有多种安装方式,包括apt-get
sudo apt-get install composer
或卷曲
sudo apt-get install curl
curl -sS https://getcomposer.org/installer | sudo php -- --install-dir=/usr/local/bin --filename=composer
接着是
cd /var/www/html/ARC2_pizza
composer require "semsol/arc2": "dev-master"
关于 remote_store_endpoint
:如果您 运行 在与 Fuseki 服务器相同的服务器上运行 php 脚本(就像我一样),您可以使用 localhost
.否则,使用 Fuseki 服务器的完全限定 public IP 地址或名称。
根据您的情况自定义脚本后,从命令行对其进行测试(而不是使用 Web 浏览器访问它。)
php /var/www/html/ARC2_pizza/index.php
结果看起来不太好,但如果仔细观察,您应该会看到几种披萨配料的名称,用 HTML table 标签分隔,例如 ...<td><tr>...
如果成功了,您终于可以通过网络浏览器对其进行测试了。如果您使用过像我这样的设置,请将浏览器指向 http://server.domain/ARC2_pizza
这样的地址如果您在网络浏览器中没有看到 table 披萨配料,那么您的网络服务器或防火墙设置有问题,而不是 Fuseki、查询、PHP和 ARC2 安装,或脚本。
这是 ARC2_pizza/index.php
的源代码。
这基于与您的问题相同的教程。不要忘记配置您的 ARC2 位置和端点地址
<html>
<body>
<?php
// customize your ARC2 location
include_once("/var/www/html/phprdftest/arc2-master/ARC2.php");
$dbpconfig = array
(
// customize your endpoint address
"remote_store_endpoint" => "http://localhost:3030/default/query",
);
$store = ARC2::getRemoteStore($dbpconfig);
if ($errs = $store->getErrors())
{
echo "<h1>getRemoteSotre error<h1>" ;
}
$query = '
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX pizza: <http://www.co-ode.org/ontologies/pizza/pizza.owl#>
SELECT *
WHERE {
?recursiveTopping rdfs:subClassOf+ pizza:PizzaTopping .
?recursiveTopping rdfs:label ?toppingLabel .
?recursiveTopping rdfs:subClassOf ?immediateParent .
filter(!isBlank(?immediateParent))
filter( ?immediateParent != pizza:PizzaTopping )
}
order by ?immediateParent ?recursiveTopping
';
$rows = $store->query($query, 'rows'); /* execute the query */
if ($errs = $store->getErrors())
{
echo "Query errors" ;
print_r($errs);
}
/* display the results in an HTML table */
echo "<table border='1'>" ;
foreach( $rows as $row )
{
/* loop for each returned row */
print "<tr><td>" .$row['recursiveTopping'] . "</td><td>" .
$row['toppingLabel']. "</td><td>" .
$row['immediateParent']. "</td></tr>";
}
echo "</table>"
?>
</body>
</html>
如果您正在使用 windows 那么您需要一个 mysql 备份所以首先安装 wamp 服务器然后 phpmyAdmin 数据库然后在存储查询命令添加中设置配置 存储 store->query('http://localhost/filename.owl').然后 运行 php 文件使用 wamp 服务器。您将在数据库中看到 rdf/xml 值 不要忘记在执行
之前在 www 文件夹中添加 ARC.php 文件和您的文件