本文整理汇总了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;
}