php-task-runner / sparql-robo-tasks
为 Robo 提供SPARQL命令
dev-master
2020-06-22 07:54 UTC
Requires
- php: ~7.1
- consolidation/robo: ^1 || ^2
Requires (Dev)
- easyrdf/easyrdf: dev-master
- phpunit/phpunit: ~7 || ~8 || ~9
- slevomat/coding-standard: ~6
- squizlabs/php_codesniffer: ~3
This package is auto-updated.
Last update: 2024-09-09 10:48:01 UTC
README
此仓库为Robo提供SPARQL任务。
安装说明
在easyrdf/easyrdf
包稳定到1.0.0版本之前,根Composer文件必须显式要求easyrdf/easyrdf
。有关详细信息,请参阅此问题:easyrdf/easyrdf#320。EasyRDF稳定后,库将重新移回require
部分。
任务
查询
$query1 = 'SELECT ?s ?p ?o WHERE { ?s ?p ?o } LIMIT 100'; $query2 = '...'; $result = $this->taskSparqlQuery() ->setEndpointUrl('http://example.com/sparql') ->addQuery($query1) ->addQuery($query2) ->run(); // Result of $query1. $res1 = $result->getData()['result'][$query1]; // Result of $query2. $res2 = $result->getData()['result'][$query2];
从字符串导入三元组
$triples1 = <<<TRIPLES <?xml version="1.0"?> <rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:si="https://w3schools.org.cn/rdf/"> <rdf:Description rdf:about="https://w3schools.org.cn"> <si:title>W3Schools</si:title> <si:author>Jan Egil Refsnes</si:author> </rdf:Description> </rdf:RDF> TRIPLES; $triples2 = <<<TRIPLES <?xml version="1.0"?> <RDF> <Description about="https://w3schools.org.cn/rdf"> <author>Jan Egil Refsnes</author> <homepage>https://w3schools.org.cn</homepage> </Description> </RDF> TRIPLES; $this->taskSparqlImportFromString() ->setEndpointUrl('http://example.com/sparql-graph-crud') ->addTriples('http://example.com/graph1', $triples1) ->addTriples('http://example.com/graph2', $triples2) ->run();
从文件导入三元组
$this->taskSparqlImportFromFile() ->setEndpointUrl('http://example.com/sparql-graph-crud') ->addTriples('http://example.com/graph1', '/path/to/file.rdf') ->addTriples('http://example.com/graph2', '/other/path/to/file2.rdf') ->run();