本文整理匯總了PHP中URI::toNTriples方法的典型用法代碼示例。如果您正苦於以下問題:PHP URI::toNTriples方法的具體用法?PHP URI::toNTriples怎麽用?PHP URI::toNTriples使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類URI
的用法示例。
在下文中一共展示了URI::toNTriples方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: getRDFTriples
/**
* sub,pred,obj, must be an array, either:
* [action] = "fix"
* [value] = "http://dbpedia.org/resource/subject"
* or a sparql variable ?o like:
* [action] = "variable"
* [value] = "o"
* * or use $this->subject:
* [action] = "classattribute"
* [value] = null
* */
public function getRDFTriples($query, $subject, $predicate, $object, $filterlanguage = true)
{
if ($subject['action'] == 'fix') {
$s = new URI($subject['value'], false);
} else {
if ($subject['action'] == 'classattribute') {
$s = $this->subject;
}
}
if ($predicate['action'] == 'fix') {
$p = new URI($predicate['value'], false);
}
if ($object['action'] == 'fix') {
try {
$o = new URI($object['value'], false);
} catch (Exception $e) {
$this->log(WARN, 'object = fix only for uris currently');
return array();
}
}
$result = array();
$pass = false;
if ($this->use == 'odbc') {
Timer::start(get_class($this) . ':odbc_request');
$jarr = $this->odbc->execAsJson($query, 'SPARQLToRDFTriple');
Timer::stop(get_class($this) . ':odbc_request');
} else {
Timer::start(get_class($this) . ':http_request');
$json = $this->sparqlEndpoint->executeQuery($query, 'SPARQLToRDFTriple');
$jarr = json_decode($json, true);
if (isset($jarr['results'])) {
$jarr = $jarr['results'];
}
Timer::stop(get_class($this) . ':http_request');
}
//print_r($result);
if (isset($jarr['bindings'])) {
$bindings = $jarr['bindings'];
foreach ($bindings as $one) {
try {
switch ($subject['action']) {
case 'fix':
//$s is already set
break;
case 'variable':
$s = new URI($one[$subject['value']]['value']);
break;
case 'classattribute':
//$s is already set
break;
}
switch ($predicate['action']) {
case 'fix':
//$p is already set
break;
case 'variable':
$p = new URI($one[$predicate['value']]['value']);
break;
}
switch ($object['action']) {
case 'fix':
//$o is already set
break;
case 'variable':
$unknown = $one[$object['value']];
$o = $this->toObject($unknown, $filterlanguage);
if ($o === false) {
continue;
}
break;
}
$this->log(DEBUG, "*******************");
$this->log(DEBUG, $s->toNTriples());
$this->log(DEBUG, $p->toNTriples());
$this->log(DEBUG, $o->toNTriples());
$result[] = new RDFtriple($s, $p, $o);
//$this->log(DEBUG, $t->getObject()->toNTriples());
} catch (Exception $ex) {
$this->log(WARN, 'found invalid URI: ' . $ex->getMessage());
}
}
} else {
$this->log(WARN, $json);
}
return $result;
}