本文整理汇总了PHP中ARC2::getMITSPARQLParser方法的典型用法代码示例。如果您正苦于以下问题:PHP ARC2::getMITSPARQLParser方法的具体用法?PHP ARC2::getMITSPARQLParser怎么用?PHP ARC2::getMITSPARQLParser使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ARC2
的用法示例。
在下文中一共展示了ARC2::getMITSPARQLParser方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: queryExecute
function queryExecute($query, $g)
{
$parser = ARC2::getMITSPARQLParser();
$parser->parse($query);
if (isset($parser->errors) && count($parser->errors)) {
queryError(implode("\n", $parser->errors));
}
$info = $parser->getQueryInfos();
$query = $info['query'];
$assure_strings = array('type', 'target_graph');
$assure_arrays = array('dataset', 'target_graphs', 'construct_triples');
foreach ($assure_strings as $k => $v) {
if (!isset($query[$v])) {
$query[$v] = '';
}
}
foreach ($assure_arrays as $k => $v) {
if (!isset($query[$v])) {
$query[$v] = array();
}
}
foreach ($query as $k => $v) {
if (!in_array($k, $assure_arrays) && !in_array($k, $assure_strings)) {
queryError('unsupported query feature: ' . $k);
}
}
if (!in_array($query['type'], array('insert', 'delete'))) {
queryError('valid query types: insert');
}
if (strlen($_base) && strlen($query['target_graph'])) {
if ($query['target_graph'] != $_base) {
queryError('query must target request URI graph (only)');
}
if (count($query['target_graphs']) && $query['target_graphs'][0] != $_base) {
queryError('query must target request URI graph (only)');
}
}
foreach ($query['construct_triples'] as $elt) {
foreach (array('s', 'p', 'o') as $k) {
if (!in_array($elt["{$k}_type"], array('uri', 'literal'))) {
queryError('unsupported node type: ' . $elt[$k] . ' (' . $elt["{$k}_type"] . ')');
}
}
}
$n = 0;
switch ($query['type']) {
case 'insert':
foreach ($query['construct_triples'] as $elt) {
$g->append_objects($elt['s'], $elt['p'], array(array('type' => $elt['o_type'], 'value' => $elt['o'])));
$n += 1;
}
break;
case 'delete':
foreach ($query['construct_triples'] as $elt) {
$g->remove_triple($elt);
$n += 1;
}
break;
}
return $n;
}