byjg / sparqllib
用于从PHP查询SPARQL的简单库
2.0.0
2021-10-31 05:20 UTC
Requires
- ext-curl: *
- byjg/webrequest: 2.0.*
Requires (Dev)
- phpunit/phpunit: 5.7.*|7.4.*
README
版权所有 2010,2011,2012 Christopher Gutteridge & 南安普顿大学。许可协议为LGPL
信息
- 由Joao Gilberto Magalhaes分叉的代码。
- 重构代码以支持PHP 5.x命名空间、composer、自动加载类和单元测试;
- 完整文档: http://graphite.ecs.soton.ac.uk/sparqllib/
示例
$db = new \SparQL\Connection( "http://rdf.ecs.soton.ac.uk/sparql/" ); $db->ns( "foaf","http://xmlns.com/foaf/0.1/" ); $sparql = "SELECT * WHERE { ?person a foaf:Person . ?person foaf:name ?name } LIMIT 5"; $result = $db->query( $sparql ); $fields = $result->fieldArray(); print "<p>Number of rows: " . $result->numRows() . " results.</p>"; print "<table class='example_table'>"; print "<tr>"; foreach( $fields as $field ) { print "<th>$field</th>"; }
简化调用
$results = new \SparQL\Connection::get( "http://rdf.ecs.soton.ac.uk/sparql/" ) ->withNamespace( "foaf","http://xmlns.com/foaf/0.1/" ) ->fetch("SELECT * WHERE { ?person a foaf:Person . ?person foaf:name ?name } LIMIT 5"); foreach ($results as $item) { print "<th>" . $item["person"] }
运行测试
只需输入
phpunit