本文整理汇总了PHP中ARC2::getSPARQLParser方法的典型用法代码示例。如果您正苦于以下问题:PHP ARC2::getSPARQLParser方法的具体用法?PHP ARC2::getSPARQLParser怎么用?PHP ARC2::getSPARQLParser使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ARC2
的用法示例。
在下文中一共展示了ARC2::getSPARQLParser方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: queryFile
public static function queryFile($modelFile, $e, &$rPointer, &$fPointer)
{
global $conf;
global $lodspk;
global $results;
global $firstResults;
global $uri;
$data = array();
$strippedModelFile = str_replace('endpoint.', '', str_replace('.query', '', $modelFile));
if (!is_dir($modelFile)) {
require_once $conf['home'] . 'lib/Haanga/lib/Haanga.php';
Haanga::configure(array('cache_dir' => $conf['home'] . 'cache/', 'autoescape' => FALSE));
//Haanga supports the dot (.) convention only for objects
if (is_array($lodspk)) {
$lodspkObj = Convert::array_to_object($lodspk);
$lodspk = $lodspkObj;
}
$r2 = Convert::array_copy($results);
$models = Convert::array_to_object($r2);
$f2 = Convert::array_copy($firstResults);
$first = Convert::array_to_object($f2);
$vars = compact('uri', 'lodspk', 'conf', 'models', 'first');
$q = file_get_contents($modelFile);
if ($q == false) {
HTTPStatus::send500("<br/>I can't load " . $modelFile . " in " . getcwd());
}
$fnc = Haanga::compile($q);
$query = $fnc($vars, TRUE);
if (is_object($lodspk)) {
$lodspkObj = Convert::object_to_array($lodspk);
$lodspk = $lodspkObj;
}
$query = Utils::addPrefixes($query);
if ($lodspk['transform_select_query'] == true) {
include_once $conf['home'] . 'lib/arc2/ARC2.php';
$parser = ARC2::getSPARQLParser();
$parser->parse($query);
$sparqlConstruct = array();
if (!$parser->getErrors()) {
$resultVars = array();
$q_infos = $parser->getQueryInfos();
foreach ($q_infos['query']['result_vars'] as $v) {
if ($v['type'] == 'var') {
$resultVars[$v['value']] = 1;
}
}
$x = Utils::extractObj($q_infos['query']['pattern']);
foreach ($x as $v) {
if ($resultVars[$v['s']] && $v['s_type'] == 'var' || $resultVars[$v['p']] && $v['p_type'] == 'var' || $resultVars[$v['o']] && $v['o_type'] == 'var') {
array_push($sparqlConstruct, $v);
}
}
$construct = "";
foreach ($sparqlConstruct as $v) {
if ($v['s_type'] == 'uri') {
$construct .= "<" . $v['s'] . "> ";
} elseif ($v['s_type'] == 'var') {
$construct .= '?' . $v['s'] . ' ';
} else {
$construct .= $v['s'] . " ";
}
if ($v['p_type'] == 'uri') {
$construct .= "<" . $v['p'] . "> ";
} elseif ($v['p_type'] == 'var') {
$construct .= '?' . $v['p'] . ' ';
} else {
$construct .= $v['p'] . " ";
}
if ($v['o_type'] == 'uri') {
$construct .= "<" . $v['o'] . "> ";
} elseif ($v['o_type'] == 'literal') {
$construct .= '"' . $v['o'] . '" ';
} elseif ($v['o_type'] == 'var') {
$construct .= '?' . $v['o'] . ' ';
} else {
$construct .= $v['o'] . " ";
}
$construct .= ".\n";
}
if ($construct == "") {
if (sizeof($q_infos['query']['result_vars']) > 0) {
//For now, assuming variables are in the GRAPH ?g
$query = "CONSTRUCT {?g ?x ?y} WHERE{GRAPH ?g{?g ?x ?y}}";
} else {
if (!preg_match('/construct/i', $query)) {
HTTPStatus::send500();
}
}
} else {
$query = preg_replace('/select\\s*[^{]*\\s*(where)?\\s*{/i', 'CONSTRUCT {' . $construct . '} WHERE{', $query);
}
} else {
return;
//HTTPStatus::send500("invalid query: " . var_export($parser->getErrors(), true)."\n\nQUERY:\n".$query);
}
}
if ($conf['debug']) {
Logging::log($modelFile . " against " . $e->getSparqlUrl());
Logging::log($query);
Logging::log("Running query from " . $modelFile . " on endpoint " . $e->getSparqlURL(), E_USER_NOTICE);
//.........这里部分代码省略.........
示例2: getSPARQLQueryParts
private function getSPARQLQueryParts($query)
{
//todo:deal with categories
$properties = array();
$categories = array();
$description = $query->getDescription();
$extraPrintOuts = $query->getExtraPrintouts();
if (!$description instanceof SMWSPARQLDescription) {
//echo('<pre>'.print_r($description, true).'</pre>');
//echo('<pre>'.print_r($extraPrintOuts, true).'</pre>');
list($properties, $categories) = $this->getQueryParts($description);
} else {
if (!class_exists('ARC2')) {
global $smwgHaloIP;
require_once "{$smwgHaloIP}/libs/arc/ARC2.php";
}
$prefixes = str_replace(':<', ': <', TSNamespaces::getAllPrefixes());
$queryString = $prefixes . $query->getQueryString();
$parser = ARC2::getSPARQLParser();
$parser->parse($queryString);
$queryInfo = $parser->getQueryInfos();
if (array_key_exists('query', $queryInfo)) {
if ($queryInfo['query']['type'] == 'select') {
list($properties, $categories) = $this->getPropertiesInSPARQLPattern($queryInfo['query']['pattern'], $queryInfo['prefixes']['prop:'], $queryInfo['prefixes']['rdf:'] . 'type', $queryInfo['prefixes']['cat:']);
}
}
}
//deal with extra printouts
$properties = array_merge($properties, $this->getPrintRequestsProperties($extraPrintOuts));
return array($properties, $categories);
}