本文整理汇总了PHP中Query::getResultForm方法的典型用法代码示例。如果您正苦于以下问题:PHP Query::getResultForm方法的具体用法?PHP Query::getResultForm怎么用?PHP Query::getResultForm使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Query
的用法示例。
在下文中一共展示了Query::getResultForm方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: queryModel
/**
* The query engine's main method.
*
* @param Dataset $dataset the RDF Dataset
* @param mixed $query the parsed SPARQL query
* @param String $resultform the result form. If set to 'xml' the result will be
* SPARQL Query Results XML Format as described in http://www.w3.org/TR/rdf-sparql-XMLres/ .
* @return Array/String Type of the result depends on $resultform.
*/
public function queryModel($dataset, Query $query, $resultform = false)
{
$this->query = $query;
$this->dataset = $dataset;
if ($this->query->isEmpty) {
$vartable[0]['patternResult'] = null;
return SparqlEngine_ResultConverter::convertFromResult($vartable, $this, $resultform);
}
$graphlist = $this->preselectGraphs();
/// match graph patterns against the RDF Dataset
$patternlist = $this->matchPatterns($graphlist);
// filter results- apply inner filters
$patternlist = $this->filterPatterns($patternlist, false);
// join pattern results
$vartable = $this->joinResults($patternlist);
// filter results- apply outer filters
$vartable = $this->filterPatterns($vartable, true);
if ($vartable[0]['patternResult'] != null) {
// sort vars (ORDER BY, LIMIT, OFFSET)
$vartable = $this->sortVars($vartable[0]['patternResult']);
$qrf = $this->query->getResultForm();
if ($qrf == 'select' || $qrf == 'select distinct') {
$vars = $this->query->getResultVars();
$vartable = $this->selectVars($vartable, $vars);
if ($qrf == 'select distinct') {
$vartable = $this->distinct($vartable);
}
}
} else {
$vartable = null;
}
return SparqlEngine_ResultConverter::convertFromResult($vartable, $this, $resultform);
}
示例2: convertFromResult
/**
* Converts the database results into the output format
* and returns the result.
*
* @param array $arVartable Variable table
* @param Query $query SPARQL query object
* @param SparqlEngine $engine Sparql Engine to query the database
* @return string HTML result
*/
public function convertFromResult($arVartable, Query $query, SparqlEngine $engine)
{
$this->query = $query;
$this->engine = $engine;
$this->dataset = $engine->getDataset();
$strCode = '';
$strResultForm = $query->getResultForm();
switch ($strResultForm) {
case 'select':
case 'select distinct':
$strCode = $this->createTableFromRecords($arVartable);
break;
case 'construct':
case 'describe':
throw new Exception('Construct and describe are currently not supported by the' . ' HTML renderer');
case 'count':
case 'ask':
$nCount = count($arVartable);
if ($strResultForm == 'ask') {
$strCode = 'There were results.';
} else {
$strCode = 'There are ' . $nCount . ' results.';
}
break;
default:
throw new Exception('Unsupported result form: ' . $strResultForm);
}
return $this->wrapCode($strCode);
}
示例3: getSelect
public static function getSelect(Query $query, $arSqls, $strAdditional = '')
{
if (count($arSqls) == 1) {
return implode('', $arSqls[0]) . $strAdditional;
}
//union
$strUnion = 'UNION' . ($query->getResultForm() == 'select distinct' ? '' : ' ALL');
$ar = array();
foreach ($arSqls as $arSql) {
$ar[] = implode('', $arSql) . $strAdditional;
}
return '(' . implode(') ' . $strUnion . ' (', $ar) . ')';
}
示例4: parseDescribe
/**
* Adds a new variable to the query and sets result form to 'DESCRIBE'.
*
* @return void
*/
protected function parseDescribe()
{
while (strtolower(current($this->tokens)) != 'from' & strtolower(current($this->tokens)) != 'where') {
$this->_fastForward();
if ($this->varCheck(current($this->tokens)) | $this->iriCheck(current($this->tokens))) {
$this->query->addResultVar(current($this->tokens));
if (!$this->query->getResultForm()) {
$this->query->setResultForm('describe');
}
}
if (!current($this->tokens)) {
break;
}
}
prev($this->tokens);
}
示例5: convertFromDbResults
/**
* Converts the database results into JSON Format
*
* @param array $arRecordSets Array of (possibly several) SQL query results.
* @param Query $query SPARQL query object
* @param SparqlEngineDb $engine Sparql Engine to query the database
* @return mixed HTML code
*/
public function convertFromDbResults($arRecordSets, Query $query, SparqlEngineDb $engine)
{
$this->query = $query;
$this->sg = $engine->getSqlGenerator();
$strResultForm = $query->getResultForm();
foreach ($this->getResultVars() as $var) {
$ResultVarsTemp[] = substr($var, 1);
}
switch ($strResultForm) {
case 'select':
case 'select distinct':
$results = $this->createFromRecords($arRecordSets, $strResultForm);
$strCode = json_encode(array('head' => array('vars' => $ResultVarsTemp), 'results' => array('bindings' => $results)));
//$strCode = str_replace(',{',','.PHP_EOL.'{',$strCode);
break;
case 'construct':
case 'describe':
throw new Exception('Construct and describe are not supported by the' . ' JSON renderer');
case 'count':
case 'ask':
if (count($arRecordSets) > 1) {
throw new Exception('More than one result set for a ' . $strResultForm . ' query not supported by JSON Renderer');
}
$nCount = 0;
$dbRecordSet = reset($arRecordSets);
foreach ($dbRecordSet as $row) {
$nCount += intval($row['count']);
break;
}
if ($strResultForm == 'ask') {
$strcode = json_encode(array('boolean' => $nCount > 0));
} else {
$strcode = json_encode(array('int' => $nCount));
}
break;
default:
throw new Exception('Error');
}
return $strCode;
}
示例6: convertFromDbResults
/**
* Converts the database results into nice HTML.
*
* @param array $arRecordSets Array of (possibly several) SQL query results.
* @param Query $query SPARQL query object
* @param SparqlEngineDb $engine Sparql Engine to query the database
* @return mixed HTML code
*/
public function convertFromDbResults($arRecordSets, Query $query, SparqlEngineDb $engine)
{
$this->query = $query;
$this->sg = $engine->getSqlGenerator();
$strCode = '';
$strResultForm = $query->getResultForm();
switch ($strResultForm) {
case 'select':
case 'select distinct':
$strCode = $this->createTableFromRecords($arRecordSets);
break;
case 'construct':
case 'describe':
throw new Exception('Construct and describe are currently not supported by the' . ' HTML renderer');
case 'count':
case 'ask':
if (count($arRecordSets) > 1) {
throw new Exception('More than one result set for a ' . $strResultForm . ' query!');
}
$nCount = 0;
$dbRecordSet = reset($arRecordSets);
foreach ($dbRecordSet as $row) {
$nCount += intval($row['count']);
break;
}
if ($strResultForm == 'ask') {
$strCode = 'There were results.';
} else {
$strCode = 'There are ' . $nCount . ' results.';
}
break;
default:
throw new Exception('Unsupported result form: ' . $strResultForm);
}
return $this->wrapCode($strCode);
}