Source for file SparqlEngine.php

Documentation is available at SparqlEngine.php

  1. <?php
  2.  
  3. // ----------------------------------------------------------------------------------
  4. // Class: SparqlEngine
  5. // ----------------------------------------------------------------------------------
  6.  
  7. /**
  8. * This engine executes SPARQL queries against an RDF Datatset.
  9. *
  10. * <BR><BR>History:<UL>
  11. * <LI>10-10-2005 : First version of this class</LI>
  12. *
  13. * @version V0.9.3
  14. * @author Tobias Gauß <tobias.gauss@web.de>
  15. *
  16. * @package sparql
  17. */
  18.  
  19. Class SparqlEngine extends Object{
  20.  
  21.  
  22. /**
  23. * @var Query The query object.
  24. */
  25. private $query;
  26.  
  27. /**
  28. * @var Dataset The RDF Dataset.
  29. */
  30. private $dataset;
  31.  
  32.  
  33.  
  34. /**
  35. * The query engines main method.
  36. *
  37. * @param Dataset $dataset the RDF Dataset
  38. * @param Query $query the parsed SPARQL query
  39. * @param String $resultform the result form. If set to ''xml'' the result will be
  40. * SPARQL Query Results XML Format as described in http://www.w3.org/TR/rdf-sparql-XMLres/ .
  41. * @return Array/String Type of the result depends on $resultform.
  42. */
  43. public function queryModel($dataset,$query,$resultform = false){
  44. $this->query = $query;
  45. $this->dataset = $dataset;
  46.  
  47. if($this->query->isEmpty){
  48. $vartable[0][''patternResult''] = null;
  49. return $this->returnResult($vartable,$resultform);
  50. }
  51.  
  52. $graphlist = $this->preselectGraphs();
  53. /// match graph patterns against the RDF Dataset
  54. $patternlist = $this->matchPatterns($graphlist);
  55. // filter results- apply inner filters
  56. $patternlist = $this->filterPatterns($patternlist,false);
  57. // join pattern results
  58. $vartable = $this->joinResults($patternlist);
  59. // filter results- apply outer filters
  60. $vartable = $this->filterPatterns($vartable,true);
  61.  
  62. return $this->returnResult($vartable,$resultform);
  63.  
  64. }
  65.  
  66. /**
  67. * Matches all graph Patterns against the dataset and generates an array which
  68. * contains the result sets for every given GraphPattern.
  69. *
  70. * @param Array $graphlist the graphlist which contains the names of the named
  71. * graphs which has to be queried.
  72. * @return Array
  73. */
  74. protected function matchPatterns($graphlist){
  75. $patternlist = array();
  76. // get the result part from the query
  77. $resultPart = $this->query->getResultPart();
  78. // for each GrapPattern in the result part
  79. if($resultPart)
  80. foreach($resultPart as $graphPattern){
  81. $this->matchPattern($patternlist, $graphlist, $graphPattern);
  82. }
  83. return $patternlist;
  84. }
  85.  
  86.  
  87. /**
  88. * Finds tuples that match one graph pattern.
  89. *
  90. * @param Array $patternlist list that contains the graphPatterns
  91. * @param array $graphlist the graphlist
  92. * @param GraphPattern $graphPattern the pattern which has to be matched
  93. * @return void
  94. */
  95. protected function matchPattern(&$patternlist, $graphlist, &$graphPattern) {
  96. // generate an empty result set
  97. $finalRes = null;
  98. // if the GraphPattern has triple patterns
  99. if($graphPattern->getTriplePattern()>0){
  100. // check if the pattern has a GRAPH clause and if this Iri is in $graphlist
  101. $newGraphList = $this->_checkGraphs($graphPattern,$graphlist);
  102. if($newGraphList){
  103. $qt = $graphPattern->getTriplePattern();
  104. $resultSet = $this->findTuplesMatchingOnePattern($qt[0], $newGraphList);
  105. for ($i=1; $i<count($qt); $i++) {
  106. $rs = $this->findTuplesMatchingOnePattern($qt[$i], $newGraphList);
  107. $resultSet = $this->joinTuples($resultSet, $rs);
  108. if(!$resultSet)
  109. break;
  110. }
  111. if($finalRes != null){
  112. $finalRes = $this->joinTuples($finalRes,$resultSet);
  113. }else{
  114. $finalRes = $resultSet;
  115. }
  116. }
  117. }
  118. // dependencies between pattern results
  119. $patternlist[$graphPattern->getId()][''hasOptional''] = 0;
  120. $patternlist[$graphPattern->getId()][''hasUnion''] = 0;
  121. $patternlist[$graphPattern->getId()][''patternResult''] = $finalRes;
  122.  
  123. $op = $graphPattern->getOptional();
  124. $un = $graphPattern->getUnion();
  125.  
  126. $patternlist[$graphPattern->getId()][''optionalTo''] = $op;
  127. if(is_int($op))
  128. $patternlist[$op][''hasOptional'']++;
  129.  
  130. $patternlist[$graphPattern->getId()][''unionWith''] = $un;
  131. if(is_int($un))
  132. $patternlist[$un][''hasUnion'']++;
  133.  
  134. $constraint = $graphPattern->getConstraint();
  135. if($constraint != null){
  136. foreach($constraint as $constr){
  137. if($constr->isOuterFilter()){
  138. $patternlist[$graphPattern->getId()][''outerFilter''][] = $constr;
  139. $patternlist[$graphPattern->getId()][''innerFilter''][] = null;
  140. }else{
  141. $patternlist[$graphPattern->getId()][''innerFilter''][] = $constr;
  142. $patternlist[$graphPattern->getId()][''outerFilter''][] = null;
  143. }
  144. }
  145. }else{
  146. $patternlist[$graphPattern->getId()][''innerFilter''] = null;
  147. $patternlist[$graphPattern->getId()][''outerFilter''] = null;
  148. }
  149. }
  150.  
  151.  
  152. /**
  153. * Finds Tuples matching one TriplePattern.
  154. *
  155. * @param TriplePattern $pattern
  156. * @param Array $graphlist
  157. * @return Array
  158. */
  159. protected function findTuplesMatchingOnePattern($pattern, $graphlist){
  160. $var = null;
  161. $sub = $pattern->getSubject();
  162. $pred = $pattern->getPredicate();
  163. $obj = $pattern->getObject();
  164.  
  165. if(is_string($sub)||$sub instanceof BlankNode){
  166. if(is_string($sub))
  167. $var[''sub''] = $sub;
  168. $sub = null;
  169. }
  170. if(is_string($pred)||$pred instanceof BlankNode ){
  171. if(is_string($pred))
  172. $var[''pred''] = $pred;
  173. $pred = null;
  174. }
  175. if(is_string($obj)||$obj instanceof BlankNode){
  176. if(is_string($obj))
  177. $var[''obj''] = $obj;
  178. $obj = null;
  179. }
  180. $intBindings = $this->_buildIntBindings($var);
  181. $k = 0;
  182.  
  183. $key = 0;
  184. // search in named graphs
  185. if($graphlist[''var''][0] != null||$graphlist[''list''][0] != null){
  186. foreach($graphlist[''list''] as $key => $graphnode){
  187.  
  188.  
  189. // query the dataset
  190. $it = $this->dataset->findInNamedGraphs($graphnode,$sub,$pred,$obj,false);
  191. if($it->valid()){
  192. // add statements to the result list
  193. while($it->valid()){
  194. if($graphnode == null){
  195. $element = $it->current()->getStatement();
  196. $grname = $it->current()->getGraphname();
  197. }else{
  198. $element = $it->current();
  199. $grname = $graphnode;
  200. }
  201. if($this->checkIntBindings($element,$intBindings)){
  202. $resmodel[''trip''][$k] = $element;
  203. $resmodel[''graph''][$k] = $grname;
  204. // $resmodel[''graphvar''][$k] = $graphlist[''var''][$key];
  205. $resmodel[''graphvar''][$k] = $graphlist[''var''][0];
  206. $k++;
  207.  
  208. }
  209. $it->next();
  210. }
  211. }
  212.  
  213. }
  214. }
  215. // search in the default graph
  216. if($graphlist[''list''][0] == null && $graphlist[''var''][0] == null){
  217. $it = $this->dataset->findInDefaultGraph($sub,$pred,$obj);
  218. // add statements to the result list
  219. if($it->valid()){
  220. while($it->valid()){
  221. $element = $it->current();
  222. //$grname = $graphnode;
  223. if($this->checkIntBindings($element,$intBindings)){
  224. $resmodel[''trip''][$k] = $element;
  225. $resmodel[''graph''][$k] = null;
  226. $resmodel[''graphvar''][$k] = $graphlist[''var''][$key];
  227. $k++;
  228. }
  229. $it->next();
  230. }
  231. }
  232. }
  233. if($k == 0)
  234. return false;
  235. return $this->_buildResultSet($pattern,$resmodel);
  236. }
  237.  
  238. /**
  239. * Checks it there are internal bindings between variables.
  240. *
  241. * @param Triple $trip
  242. * @param Array $intBindings
  243. * @return boolean
  244. */
  245. protected function checkIntBindings($trip, $intBindings){
  246. switch($intBindings){
  247. case -1:
  248. return true;
  249. break;
  250. case 0:
  251. if($trip->subj != $trip->pred)
  252. return false;
  253. break;
  254. case 1:
  255. if(is_a($trip->obj,''Literal''))
  256. return false;
  257. if($trip->subj != $trip->obj)
  258. return false;
  259. break;
  260. case 2:
  261. if(is_a($trip->obj,''Literal''))
  262. return false;
  263. if($trip->pred != $trip->obj)
  264. return false;
  265. break;
  266. case 3:
  267. if(is_a($trip->obj,''Literal''))
  268. return false;
  269. if($trip->pred != $trip->obj || $trip->pred != $trip->subj )
  270. return false;
  271. break;
  272. }
  273. return true;
  274. }
  275.  
  276.  
  277. /**
  278. * Perform an SQL-like inner join on two resultSets.
  279. *
  280. * @param Array &$finalRes
  281. * @param Array &$res
  282. * @return Array
  283. */
  284. protected function joinTuples(&$finalRes, &$res) {
  285.  
  286. if (!$finalRes || !$res)
  287. return array();
  288.  
  289. // find joint variables and new variables to be added to $finalRes
  290. $jointVars = array();
  291. $newVars = array();
  292. $k = key($res);
  293.  
  294. foreach ($res[$k] as $varname => $node) {
  295. if (array_key_exists($varname, $finalRes[0]))
  296. $jointVars[] = $varname;
  297. else
  298. $newVars[] = $varname;
  299. }
  300.  
  301. // eliminate rows of $finalRes in which the values of $jointVars do not have
  302. // a corresponding row in $res.
  303. foreach ($finalRes as $n => $fRes) {
  304. foreach ($res as $i => $r) {
  305. $ok = TRUE;
  306. foreach ($jointVars as $j_varname)
  307. if ($r[$j_varname] != $fRes[$j_varname]) {
  308. $ok = FALSE;
  309. break;
  310. }
  311. if ($ok)
  312. break;
  313. }
  314. if (!$ok)
  315. unset($finalRes[$n]);
  316. }
  317.  
  318. // join $res and $finalRes
  319. $joinedRes = array();
  320. foreach ($res as $r) {
  321. foreach ($finalRes as $n => $fRes) {
  322. $ok = TRUE;
  323. foreach ($jointVars as $j_varname)
  324. if ($r[$j_varname] != $fRes[$j_varname]) {
  325. $ok = FALSE;
  326. break;
  327. }
  328. if ($ok) {
  329. $joinedRow = $finalRes[$n];
  330. foreach($newVars as $n_varname)
  331. $joinedRow[$n_varname] = $r[$n_varname];
  332. $joinedRes[] = $joinedRow;
  333. }
  334. }
  335. }
  336. return $joinedRes;
  337. }
  338.  
  339.  
  340. /**
  341. * Joins OPTIONAL pattern results.
  342. *
  343. * @param Array &$finalRes
  344. * @param Array &$res
  345. * @return Array the joined Array
  346. */
  347. protected function joinOptionalTuples(&$finalRes, &$res) {
  348.  
  349. if(!$finalRes && !$res)
  350. return array();
  351.  
  352. if(!$finalRes)
  353. return $res;
  354.  
  355. if(!$res)
  356. return $finalRes;
  357.  
  358. // find joint variables and new variables to be added to $finalRes
  359. $jointVars = array();
  360. $newVars = array();
  361. $result = array();
  362.  
  363. $k = key($res);
  364.  
  365. foreach ($res[$k] as $varname => $node) {
  366. if (array_key_exists($varname, $finalRes[0])){
  367. $jointVars[] = $varname;
  368. }else{
  369. $newVars[] = $varname;
  370. }
  371. }
  372. $joined = array();
  373. foreach($finalRes as $i =>$fRes){
  374. foreach($res as $n =>$r){
  375. $join = false;
  376. foreach($jointVars as $j_varname){
  377. if($r[$j_varname]==$fRes[$j_varname]){
  378. $join = true;
  379. break;
  380. }
  381. }
  382. if($join){
  383. $result[$i] = $fRes;
  384. foreach($newVars as $n_varname)
  385. $result[$i][$n_varname] = $r[$n_varname];
  386. $joined[]=$n;
  387. }
  388.  
  389. }
  390. }
  391.  
  392. $count = count($result);
  393. foreach($res as $k =>$val){
  394. if(!in_array($k,$joined)){
  395. $result[$count] = $finalRes[0];
  396. foreach($result[$count] as $varname => $varVal){
  397. $result[$count][$varname]='''';
  398. }
  399.  
  400. foreach($val as $varname2 => $varVal2){
  401. $result[$count][$varname2]=$varVal2;
  402. }
  403. $count++;
  404. }
  405. }
  406. return $result;
  407. }
  408.  
  409.  
  410.  
  411. /**
  412. * Looks in from and from named part of the query and
  413. * adds the graphs to the graphlist.
  414. *
  415. * @return Array
  416. */
  417. protected function preselectGraphs(){
  418. $fromNamed = $this->query->getFromNamedPart();
  419. if($fromNamed == null)
  420. $fromNamed[] = null;
  421. return $fromNamed;
  422. }
  423.  
  424.  
  425. /**
  426. * Evaluates the GRPAH clause if there is one. Checks if
  427. * the GRAPH clause contains an IRI, variable or nothing.
  428. * Returns an array which contains the graphs that has to be matched.
  429. *
  430. * @param GraphPattern $pattern
  431. * @param Array $graphlist
  432. * @return Array
  433. */
  434. protected function _checkGraphs(&$pattern,$graphlist){
  435.  
  436. $gr = $pattern->getGraphname();
  437. if($gr instanceof Resource ){
  438. if($graphlist[0]==null){
  439. $newGraphList[''list''][] = $gr;
  440. $newGraphList[''var''][] = null;
  441. }else{
  442. return false;
  443. }
  444. }elseif (is_string($gr)){
  445. $newGraphList[''list''] = $graphlist;
  446. $newGraphList[''var''][] = $gr;
  447. }else{
  448. $newGraphList[''list''] = $graphlist;
  449. $newGraphList[''var''][] = null;
  450. }
  451. return $newGraphList;
  452. }
  453.  
  454. /**
  455. * Marks triples with internal bindings.
  456. * int bindings -1 :none 0:sub=pred 1:sub=obj 2:pred=obj 3:sub=pred=obj.
  457. *
  458. * @param Array $var
  459. * @return Array
  460. */
  461. protected function _buildIntBindings($var){
  462. $intBindings = -1;
  463. if(!$var)
  464. return $intBindings;
  465.  
  466. if(isset($var[''sub''])){
  467. if(isset($var[''pred'']))
  468. if($var[''sub''] == $var[''pred''])
  469. $intBindings = 0;
  470. if(isset($var[''obj'']))
  471. if($var[''sub''] == $var[''obj'']){
  472. if( $intBindings == 0){
  473. $intBindings = 3;
  474. }else{
  475. $intBindings = 1;
  476. }
  477. }
  478. }
  479. if(isset($var[''pred''])){
  480. if(isset($var[''obj'']))
  481. if($var[''pred'']==$var[''obj'']&&$intBindings!=3)
  482. $intBindings = 2;
  483. }
  484. return $intBindings;
  485. }
  486.  
  487. /**
  488. * Builds the resultset.
  489. *
  490. * @param GraphPattern $pattern
  491. * @param Array $resmodel
  492. * @return Array
  493. */
  494. protected function _buildResultSet($pattern,$resmodel){
  495. // determine variables and their corresponding values
  496. $result = null;
  497. if(is_string($pattern->getSubject())){
  498. $n = 0;
  499. foreach($resmodel[''trip''] as $key => $triple){
  500. if(isset($resmodel[''graphvar''][$key]))
  501. $result[$n][$resmodel[''graphvar''][$key]] = $resmodel[''graph''][$key];
  502. $result[$n++][$pattern->getSubject()] = $triple->subj;
  503. }
  504. }
  505. if(is_string($pattern->getPredicate())){
  506. $n = 0;
  507. foreach($resmodel[''trip''] as $key => $triple){
  508. if(isset($resmodel[''graphvar''][$key]))
  509. $result[$n][$resmodel[''graphvar''][$key]] = $resmodel[''graph''][$key];
  510. $result[$n++][$pattern->getPredicate()] = $triple->pred;
  511. }
  512. }
  513. if(is_string($pattern->getObject())){
  514. $n = 0;
  515. foreach($resmodel[''trip''] as $key => $triple){
  516. if(isset($resmodel[''graphvar''][$key]))
  517. $result[$n][$resmodel[''graphvar''][$key]] = $resmodel[''graph''][$key];
  518. $result[$n++][$pattern->getObject()] = $triple->obj;
  519. }
  520. }
  521. return $result;
  522. }
  523.  
  524. /**
  525. * Selects the result variables and builds a result table.
  526. *
  527. * @param Array $table the result table
  528. * @param Array $vars the result variables
  529. * @return Array
  530. */
  531. protected function selectVars($table,$vars){
  532. if($vars[0]==''*'')
  533. $vars = $this->query->getAllVars();
  534. $resTable = array();
  535. $hits = 0;
  536. foreach($table as $val){
  537. foreach($vars as $var){
  538. if(isset($val[$var])){
  539. $resTable[$hits][$var]=$val[$var];
  540. }else{
  541. $resTable[$hits][$var]="";
  542. }
  543. }
  544. $hits++;
  545. }
  546. return $resTable;
  547. }
  548.  
  549. /**
  550. * Joins the results of the different Graphpatterns.
  551. *
  552. * @param Array $patternlist
  553. * @return Array
  554. */
  555. protected function joinResults($patternlist){
  556. $joined[0][''patternResult''] = null;
  557. $joined[0][''outerFilter''] = null;
  558.  
  559. while(count($patternlist)>0){
  560. foreach($patternlist as $key => $pattern){
  561. if($pattern[''hasOptional''] == 0 && $pattern[''hasUnion''] == 0){
  562. if(is_int($pattern[''optionalTo''])){
  563. $patternlist[$pattern[''optionalTo'']][''hasOptional'']--;
  564. $patternlist[$pattern[''optionalTo'']][''patternResult''] = $this->joinOptionalTuples($pattern[''patternResult''],$patternlist[$pattern[''optionalTo'']][''patternResult'']);
  565. unset($patternlist[$key]);
  566. break;
  567. }
  568. else if(is_int($pattern[''unionWith''])){
  569. $patternlist[$pattern[''unionWith'']][''hasUnion'']--;
  570. foreach($pattern[''patternResult''] as $value)
  571. array_push($patternlist[$pattern[''unionWith'']][''patternResult''],$value);
  572. unset($patternlist[$key]);
  573. break;
  574. }else{
  575. if($joined[0][''patternResult''] == null){
  576. $joined[0][''patternResult''] = $pattern[''patternResult''];
  577. if($joined[0][''outerFilter''] == null )
  578. $joined[0][''outerFilter''] = $pattern[''outerFilter''];
  579. unset($patternlist[$key]);
  580. break;
  581. }
  582. if($pattern[''patternResult''] !=null ){
  583. $joined[0][''patternResult''] = $this->joinTuples($joined[0][''patternResult''],$pattern[''patternResult'']);
  584. $joined[0][''outerFilter''] = $pattern[''outerFilter''];
  585. unset($patternlist[$key]);
  586. break;
  587. }
  588. }
  589. }
  590. }
  591. }
  592. return $joined;
  593. }
  594.  
  595. /**
  596. * Filters the pattern results.
  597. *
  598. * @param Array $patternlist list containing the results of the GraphPatterns
  599. * @param boolean $outer TRUE if its an outer filter FALSE if not
  600. * @return Array the filtered patternlist
  601. */
  602. protected function filterPatterns($patternlist,$outer){
  603. if($outer)
  604. $filter = ''outerFilter'';
  605. else
  606. $filter = ''innerFilter'';
  607. foreach($patternlist as $patkey => $pattern){
  608. // get constraints
  609. $constraint = $pattern[$filter];
  610.  
  611. if(count($constraint)>0){
  612. foreach($constraint as $constr){
  613. if($constr != null){
  614. // extract Vars and function calls
  615. $evalString = $constr->getExpression();
  616. preg_match_all("/\?.[^\s\)\,]*/",$evalString,$vars);
  617. preg_match_all("/bound\((.[^\)]*)\)/i",$evalString,$boundcalls);
  618. preg_match_all("/isuri\((.[^\)]*)\)/i",$evalString,$isUricalls);
  619. preg_match_all("/isblank\((.[^\)]*)\)/i",$evalString,$isBlankcalls);
  620. preg_match_all("/isLiteral\((.[^\)]*)\)/i",$evalString,$isLiteralcalls);
  621. preg_match_all("/lang\((.[^\)]*)\)/i",$evalString,$langcalls);
  622. preg_match_all("/datatype\((.[^\)]*)\)/i",$evalString,$datatypecalls);
  623. preg_match_all("/str\((.[^\)]*)\)/i",$evalString,$stringcalls);
  624.  
  625. // is Bound
  626. if(count($boundcalls[1])>0)
  627. $function[''bound''] = $boundcalls[1];
  628. else
  629. $function[''bound''] = false;
  630.  
  631. // is URI
  632. if(count($isUricalls[1])>0)
  633. $function[''isUri''] = $isUricalls[1];
  634. else
  635. $function[''isUri''] = false;
  636.  
  637. // is Blank
  638. if(count($isBlankcalls[1])>0)
  639. $function[''isBlank''] = $isBlankcalls[1];
  640. else
  641. $function[''isBlank''] = false;
  642.  
  643. // is Literal
  644. if(count($isLiteralcalls[1])>0)
  645. $function[''isLiteral''] = $isLiteralcalls[1];
  646. else
  647. $function[''isLiteral''] = false;
  648.  
  649. // lang
  650. if(count($langcalls[1])>0)
  651. $function[''lang''] = $langcalls[1];
  652. else
  653. $function[''lang''] = false;
  654.  
  655. // datatype
  656. if(count($datatypecalls[1])>0)
  657. $function[''datatype''] = $datatypecalls[1];
  658. else
  659. $function[''datatype''] = false;
  660.  
  661. // string
  662. if(count($stringcalls[1])>0)
  663. $function[''string''] = $stringcalls[1];
  664. else
  665. $function[''string''] = false;
  666.  
  667.  
  668. foreach($pattern[''patternResult''] as $key => $res){
  669. $result = false;
  670. $evalString = $this->fillConstraintString($vars,$res,$constr,$function);
  671. $evalString = ''$result =(''.$evalString.'');'';
  672. // evaluate Constraint
  673. @eval($evalString);
  674.  
  675. if(!$result)
  676. unset($patternlist[$patkey][''patternResult''][$key]);
  677.  
  678. }
  679. }
  680. }
  681. }
  682. }
  683. return $patternlist;
  684. }
  685.  
  686. /**
  687. * Builds an evaluation string to determine wether the result passes
  688. * the filter or not. This string is evaluatet by the php buildin eval() function
  689. *
  690. * @param Array $vars a list which contains the used variables
  691. * @param Array $res the result part which have to be evaluated
  692. * @param Constraint $constraint the Constrain object
  693. * @param Array $function an Array which contains the used functions
  694. * @return String
  695. */
  696.  
  697. protected function fillConstraintString($vars,$res,$constraint,$function){
  698.  
  699. $boundExpr = false;
  700. $evalString = $constraint->getExpression();
  701.  
  702. // extract Literals
  703. $pattern1 = "/\".[^\"]*\"[^\^\@]/";
  704. $pattern2 = "/\''.[^\'']*\''[^\^\@]/";
  705. preg_match_all($pattern1,$evalString,$hits1);
  706. preg_match_all($pattern2,$evalString,$hits2);
  707.  
  708. foreach($hits1[0] as $k => $val){
  709. $evalString = preg_replace(''/".[^\"]*\"[^\^]/'',''_REPLACED1_''.$k++,$evalString,1);
  710. }
  711. foreach($hits2[0] as $k => $val){
  712. $evalString = preg_replace(''/\".[^\"]*\"[^\^]/'',''_REPLACED2_''.$k++,$evalString,1);
  713. }
  714.  
  715. // replace namespaces
  716. $prefs = $this->query->getPrefixes();
  717. foreach($prefs as $key => $val){
  718. if($key == '''')
  719. $key = '' '';
  720. $evalString = preg_replace("/^(".$key.":)(.[^s]*)|([s(]?[^^])(".$key.":)(.[^s)]*)([s)]?)/","$3''<".$val."$2$5>''$6",$evalString);
  721.  
  722. $evalString = preg_replace("/(^)(".$key.":)(.[^s]*)/","$1<".$val."$3>",$evalString);
  723. }
  724.  
  725. $xsd = "http://www.w3.org/2001/XMLSchema#";
  726.  
  727. // evaluate bound calls
  728. if($function[''bound'']){
  729. $boundExpr = true;
  730. foreach($function[''bound''] as $var){
  731. if(isset($res[$var]) && $res[$var]!="")
  732. $replacement = ''true'';
  733. else
  734. $replacement = ''false'';
  735. $evalString = preg_replace("/bound\(\\".$var."\)/i",$replacement,$evalString);
  736. }
  737.  
  738. }
  739. // evaluate isBlank calls
  740. if($function[''isBlank'']){
  741. foreach($function[''isBlank''] as $var){
  742. if(isset($res[$var]) && $res[$var]!="" && $res[$var] instanceof BlankNode )
  743. $replacement = ''true'';
  744. else
  745. $replacement = ''false'';
  746. $evalString = preg_replace("/isBlank\(\\".$var."\)/i",$replacement,$evalString);
  747. }
  748.  
  749. }
  750. // evaluate isLiteral calls
  751. if($function[''isLiteral'']){
  752. foreach($function[''isLiteral''] as $var){
  753. if(isset($res[$var]) && $res[$var]!="" && $res[$var] instanceof Literal )
  754. $replacement = ''true'';
  755. else
  756. $replacement = ''false'';
  757. $evalString = preg_replace("/isLiteral\(\\".$var."\)/i",$replacement,$evalString);
  758. }
  759.  
  760. }
  761. // evaluate isUri calls
  762. if($function[''isUri'']){
  763. foreach($function[''isUri''] as $var){
  764. if(isset($res[$var]) && $res[$var]!="" && $res[$var] instanceof Resource && $res[$var]->getUri() && !$res[$var] instanceof BlankNode )
  765. $replacement = ''true'';
  766. else
  767. $replacement = ''false'';
  768. $evalString = preg_replace("/isUri\(\\".$var."\)/i",$replacement,$evalString);
  769. }
  770. }
  771. // evaluate lang calls
  772. if($function[''lang'']){
  773. foreach($function[''lang''] as $var){
  774. if(isset($res[$var]) && $res[$var]!="" && $res[$var] instanceof Literal && $res[$var]->getLanguage() )
  775. $replacement = ''"''.$res[$var]->getLanguage().''"'';
  776. else
  777. $replacement = ''null'';
  778. $evalString = preg_replace("/lang\(\\".$var."\)/i",$replacement,$evalString);
  779. }
  780. }
  781. // evaluate datatype calls
  782. if($function[''datatype'']){
  783. foreach($function[''datatype''] as $var){
  784. if(isset($res[$var]) && $res[$var]!="" && $res[$var] instanceof Literal && $res[$var]->getDatatype() )
  785. $replacement = ''''<''.$res[$var]->getDatatype().''>'''';
  786. else
  787. $replacement = ''false'';
  788. $evalString = preg_replace("/datatype\(\\".$var."\)/i",$replacement,$evalString);
  789. }
  790. }
  791. // evaluate string calls
  792. if($function[''string'']){
  793. foreach($function[''string''] as $var){
  794. if($var{0}==''?'' || $var{0}==''$''){
  795. if(isset($res[$var]) && $res[$var]!=""){
  796. $replacement = "''str_".$res[$var]->getLabel()."''";
  797. if($res[$var] instanceof BlankNode)
  798. $replacement = "''''";
  799. }else{
  800. $replacement = ''false'';
  801. }
  802. $evalString = preg_replace("/str\(\\".$var."\)/i",$replacement,$evalString);
  803. }else{
  804. if($var{0}==''<''){
  805. $evalString = preg_replace("/str\(\s*\<(.[^\>]*)\>\s*\)/i","''str_$1''",$evalString);
  806. }
  807. if($var{0}==''"''){
  808. $evalString = preg_replace("/str(s*"(.[^\>]*)\"\@[a-z]*\s*\)/i","''str_$1''",$evalString);
  809. }
  810. }
  811.  
  812. }
  813. }
  814. // evaluate VARS
  815. foreach($vars[0] as $var){
  816. if(isset($res[$var])&&$res[$var]!= ""){
  817. //$replacement = "''".$res[$var]->getLabel()."''";
  818. $replacement = ''" "'';
  819. if($res[$var] instanceof Literal){
  820. if($res[$var]->getDatatype()!= null){
  821. if($res[$var]->getDatatype() == XML_SCHEMA.''boolean'')
  822. $replacement = $res[$var]->getLabel();
  823. if($res[$var]->getDatatype() == XML_SCHEMA.''double'')
  824. $replacement = $res[$var]->getLabel();
  825. if($res[$var]->getDatatype() == XML_SCHEMA.''integer'')
  826. $replacement = $res[$var]->getLabel();
  827. if($res[$var]->getDatatype() == XML_SCHEMA.''dateTime'')
  828. $replacement = strtotime($res[$var]->getLabel());
  829. }else{
  830. if($res[$var]->getLabel()=="")
  831. $replacement = ''false'';
  832. else
  833. $replacement = "''str_".$res[$var]->getLabel()."''";
  834. }
  835. }else{
  836. if($res[$var] instanceof Resource){
  837. $replacement = "''<".$res[$var]->getLabel().">''";
  838. }
  839. }
  840. $evalString = preg_replace("/\\".$var."/",$replacement,$evalString);
  841. }
  842.  
  843. // problem with PHP: false < 13 is true
  844. if(isset($res[$var])){
  845. if($res[$var] == ""){
  846. if($boundExpr)
  847. $evalString = preg_replace("/\\".$var."/","false",$evalString);
  848. else
  849. $evalString = ''false'';
  850. }
  851. }else{
  852. $evalString = preg_replace("/\\".$var."/","false",$evalString);
  853. }
  854.  
  855. }
  856.  
  857. // replace ''='' with ''==''
  858. $evalString = preg_replace("/(.[^\=])(\=)(.[^\=])/","$1==$3",$evalString);
  859.  
  860.  
  861. // rewrite Literals
  862. foreach($hits1[0] as $k => $val){
  863. $pattern = ''/_REPLACED1_''.$k.''/'';
  864. $evalString = preg_replace($pattern,$hits1[0][$k],$evalString,1);
  865. }
  866.  
  867. foreach($hits2[0] as $k => $val){
  868. $pattern = ''/_REPLACED2_''.$k.''/'';
  869. $evalString = preg_replace($pattern,$hits2[0][$k],$evalString,1);
  870. }
  871.  
  872. // replace xsd:boolean expressions
  873. $pattern = $pattern = ''/"\s?true\s?\"\^\^\<''.$xsd.''boolean\>|\''\s?true\s?\''\^\^xsd:boolean/'';
  874. $evalString = preg_replace($pattern,"true",$evalString);
  875.  
  876. $pattern = $pattern = ''/\"\s?false\s?\"\^\^\<''.$xsd.''boolean\>|\''\s?false\s?\''\^\^xsd:boolean/'';
  877. $evalString = preg_replace($pattern,"false",$evalString);
  878.  
  879. // replace xsd:date expressions
  880. $pattern = "/"(.[^\"]*)\"\^\^".$xsd."dateTime/";
  881. preg_match_all($pattern,$evalString,$hits);
  882.  
  883. foreach($hits[1] as $dummy)
  884. $evalString = preg_replace("/\".[^\"]*\"\^\^".$xsd."dateTime/",strtotime($dummy),$evalString,1);
  885.  
  886.  
  887. $evalString = preg_replace("/(\''\<".$xsd."dateTime\()(.[^\)]*\))\>\''/","dateTime($2",$evalString);
  888.  
  889. $evalString = preg_replace("/(\''\<".$xsd."integer\()(.[^\)]*\))\>\''/","integer($2",$evalString);
  890.  
  891. // tag plain literals
  892. $evalString = preg_replace("/\"(.[^\"]*)\"([^\^])|\"(.[^\"]*)\"$/","''str_$1$3''$2",$evalString);
  893.  
  894. return $evalString;
  895. }
  896.  
  897. /**
  898. * Sorts the results.
  899. *
  900. * @param Array $vartable List containing the unsorted result vars
  901. * @return Array List containing the sorted result vars
  902. */
  903. protected function sortVars($vartable){
  904. $newTable = array();
  905. $mod = $this->query->getSolutionModifier();
  906. // if no ORDER BY solution modifier return vartable
  907. if($mod[''order by'']!= null){
  908. $order = $mod[''order by''];
  909. $map = $this->buildVarmap($order,$vartable);
  910. foreach($map as $val){
  911. $newTable[] = $vartable[$val];
  912. }
  913. }else{
  914. $newTable = $vartable;
  915. }
  916.  
  917. if($mod[''offset''] != null){
  918. $newTable = array_slice ($newTable, $mod[''offset'']);
  919. }
  920. if($mod[''limit''] != null){
  921. $newTable = array_slice($newTable,0,$mod[''limit'']);
  922. }
  923.  
  924. return $newTable;
  925. }
  926.  
  927. /**
  928. * Sorts the result table.
  929. *
  930. * @param String $order (ASC/DESC)
  931. * @param Array $vartable the vartable
  932. * @return Array A map that contains the new order of the result vars
  933. */
  934. protected function buildVarmap($order, $vartable){
  935. $n= 0;
  936. $result = array();
  937. $num_var = array();
  938. foreach($order as $variable)
  939. $num_var[$variable[''val'']] = 0;
  940.  
  941. foreach($vartable as $k => $x){
  942. foreach($order as $value){
  943. // if the value is a typed Literal try to determine if it
  944. // a numeric datatype
  945. if($x[$value[''val'']] instanceof Literal){
  946. $dtype = $x[$value[''val'']]->getDatatype();
  947. if($dtype){
  948. switch($dtype){
  949. case XML_SCHEMA."integer":
  950. $num_var[$value[''val'']]++;
  951. break;
  952. case XML_SCHEMA."double":
  953. $num_var[$value[''val'']]++;
  954. break;
  955.  
  956. }
  957. }
  958. }
  959. if($x[$value[''val'']]){
  960. if($x[$value[''val'']]instanceof Literal){
  961. $pref = "2";
  962. }
  963. if($x[$value[''val'']]instanceof Resource){
  964. $pref = "1";
  965. }
  966. if($x[$value[''val'']]instanceof BlankNode){
  967. $pref = "0";
  968. }
  969. $result[$value[''val'']][$n] = $pref.$x[$value[''val'']]->getLabel();
  970. }else{
  971. $result[$value[''val'']][$n] = "";
  972. }
  973. }
  974. $result[''oldKey''][$n] = $k;
  975. $n++;
  976. }
  977. $sortString = "";
  978. foreach($order as $value){
  979. if($num_var[$value[''val'']] == $n)
  980. $sort = SORT_NUMERIC;
  981. else
  982. $sort = SORT_STRING;
  983.  
  984. if($value[''type''] == ''asc'')
  985. $type = SORT_ASC;
  986. else
  987. $type = SORT_DESC;
  988.  
  989. $sortString = $sortString.''$result["''.$value[''val''].''"],''.$type.'',''.$sort.'','';
  990. }
  991. $sortString = "array_multisort(".$sortString.''$result["oldKey"]);'';
  992.  
  993. @eval($sortString);
  994. return $result[''oldKey''];
  995. }
  996.  
  997.  
  998. /**
  999. * Constructs a result graph.
  1000. *
  1001. * @param Array $vartable a table containing the result vars and their bindings
  1002. * @param GraphPattern $constructPattern the CONSTRUCT pattern
  1003. * @return MemModel the result graph which matches the CONSTRUCT pattern
  1004. */
  1005. protected function constructGraph($vartable,$constructPattern){
  1006.  
  1007. $resultGraph = new MemModel();
  1008.  
  1009. if(!$vartable)
  1010. return $resultGraph;
  1011.  
  1012. $tp = $constructPattern->getTriplePattern();
  1013.  
  1014. $bnode = 0;
  1015. foreach($vartable as $value){
  1016. foreach($tp as $triple){
  1017. $sub = $triple->getSubject();
  1018. $pred = $triple->getPredicate();
  1019. $obj = $triple->getObject();
  1020.  
  1021. if(is_string($sub) && $sub{1}==''_'' )
  1022. $sub = new BlankNode("_bN".$bnode);
  1023. if(is_string($pred) && $pred{1}==''_'')
  1024. $pred = new BlankNode("_bN".$bnode);
  1025. if(is_string($obj) && $obj{1}==''_'')
  1026. $obj = new BlankNode("_bN".$bnode);
  1027.  
  1028.  
  1029. if(is_string($sub))
  1030. $sub = $value[$sub];
  1031. if(is_string($pred))
  1032. $pred = $value[$pred];
  1033. if(is_string($obj))
  1034. $obj = $value[$obj];
  1035.  
  1036. if($sub != "" && $pred != "" && $obj != "")
  1037. $resultGraph->add(new Statement($sub,$pred,$obj));
  1038.  
  1039. }
  1040. $bnode++;
  1041. }
  1042. return $resultGraph;
  1043. }
  1044.  
  1045. /**
  1046. * Builds a describing named graph. To define an attribute list for a
  1047. * several rdf:type look at constants.php
  1048. *
  1049. * @param Array $vartable
  1050. * @return MemModel
  1051. */
  1052. protected function describeGraph($vartable){
  1053. // build empty named graph
  1054. $resultGraph = new MemModel();
  1055. // if no where clause fill $vartable
  1056. $vars = $this->query->getResultVars();
  1057. if($vartable == null){
  1058. if($vars){
  1059. $vartable[0] = array(''?x'' => new Resource(substr($vars[0],1,-1)));
  1060. $vars[0] = ''?x'';
  1061. }
  1062. }
  1063. // fetch attribute list from constants.php
  1064. global $sparql_describe;
  1065. // for each resultset
  1066. foreach($vartable as $resultset){
  1067. foreach($vars as $varname){
  1068. $varvalue = $resultset[$varname];
  1069. // try to determine rdf:type of the variable
  1070. $type = $this->_determineType($varvalue,$resultGraph);
  1071. // search attribute list defined in constants.php
  1072. $list = null;
  1073. if($type){
  1074. if(isset($sparql_describe[strtolower($type->getUri())]))
  1075. $list = $sparql_describe[strtolower($type->getUri())] ;
  1076. }
  1077. // search in dataset
  1078. $this->_getAttributes($list, $resultGraph, $varvalue);
  1079. }
  1080. }
  1081.  
  1082. return $resultGraph;
  1083. }
  1084.  
  1085. /**
  1086. * Tries to determine the rdf:type of the variable.
  1087. *
  1088. * @param Node $var The variable
  1089. * @param MemModel $resultGraph The result graph which describes the Resource
  1090. * @return String Uri of the rdf:type
  1091. */
  1092. protected function _determineType($var ,$resultGraph ){
  1093. $type = null;
  1094. // find in namedGraphs
  1095. if(!$var instanceof Literal){
  1096. $iter = $this->dataset->findInNamedGraphs(null,$var,new Resource(RDF_NAMESPACE_URI.''type''),null,true);
  1097. while($iter->valid()){
  1098. $statement = $iter->current();
  1099. $type = $statement->getObject();
  1100. $resultGraph->add($iter->current());
  1101. break;
  1102. }
  1103. }
  1104. // if no type information found find in default graph
  1105. if(!$type){
  1106. if(!$var instanceof Literal){
  1107. $iter1 = $this->dataset->findInDefaultGraph($var,new Resource(RDF_NAMESPACE_URI.''type''),null);
  1108. $type = null;
  1109. while($iter1->valid()){
  1110. $statement = $iter1->current();
  1111. $type = $statement->getObject();
  1112. $resultGraph->add($iter1->current());
  1113. break;
  1114. }
  1115. }
  1116. }
  1117. return $type;
  1118. }
  1119.  
  1120. /**
  1121. * Search the attributes listed in $list in the dataset.
  1122. *
  1123. * @param Array $list List containing the attributes
  1124. * @param MemModel $resultGraph The result graph which describes the Resource
  1125. * @return void
  1126. */
  1127. protected function _getAttributes($list,$resultGraph, $varvalue){
  1128. if($list){
  1129. foreach($list as $attribute){
  1130. if(!$varvalue instanceof Literal){
  1131. $iter2 = $this->dataset->findInNamedGraphs(null,$varvalue,new Resource($attribute),null,true);
  1132. while($iter2->valid()){
  1133. $resultGraph->add($iter2->current());
  1134. $iter2->next();
  1135. }
  1136. $iter3 = $this->dataset->findInDefaultGraph($varvalue,new Resource($attribute),null);
  1137. while($iter3->valid()){
  1138. $resultGraph->add($iter3->current());
  1139. $iter3->next();
  1140. }
  1141. }
  1142. }
  1143. }
  1144.  
  1145.  
  1146. }
  1147.  
  1148. /**
  1149. * Eliminates duplicate results.
  1150. *
  1151. * @param Array $vartable a table that contains the result vars and their bindings
  1152. * @return Array the result table without duplicate results
  1153. */
  1154. protected function distinct($vartable){
  1155. $index = array();
  1156. foreach($vartable as $key => $value){
  1157. $key_index="";
  1158. foreach($value as $k => $v)
  1159. $key_index = $key_index.$k.$v->toString();
  1160. if(isset($index[$key_index]))
  1161. unset($vartable[$key]);
  1162. else
  1163. $index[$key_index]= 1;
  1164. }
  1165. return $vartable;
  1166. }
  1167.  
  1168. /**
  1169. * Generates the result object.
  1170. *
  1171. * @param Array $vartable The result table
  1172. * @param String/boolean $resultform If set to ''xml'' the result will be
  1173. * SPARQL Query Results XML Format as described in http://www.w3.org/TR/rdf-sparql-XMLres/
  1174. * @return Array/String The result
  1175. */
  1176. protected function returnResult($vartable,$resultform = false){
  1177. $result = "false";
  1178. if($vartable[0][''patternResult'']!=null){
  1179. // sort vars (ORDER BY, LIMIT, OFFSET)
  1180. $vartable = $this->sortVars($vartable[0][''patternResult'']);
  1181.  
  1182. // CONSTRUCT, ASK, DESCRIBE, SELECT
  1183. if( strtolower($this->query->getResultForm()) == ''ask''){
  1184. if(count($vartable)>0)
  1185. $result = "true";
  1186. else
  1187. $result = "false";
  1188. }else if(strtolower($this->query->getResultForm()) == ''construct''){
  1189. $result = $this->constructGraph($vartable,$this->query->getConstructPattern());
  1190. }else if(strtolower($this->query->getResultForm()) == ''describe''){
  1191. $result = $this->describeGraph($vartable);
  1192. }else{
  1193. // get result vars
  1194. $vars = $this->query->getResultVars();
  1195. // select result vars and return a result table
  1196. $vartable = $this->selectVars($vartable,$vars);
  1197. if($this->query->getResultForm()==''select distinct'')
  1198. $result = $this->distinct($vartable);
  1199. else
  1200. $result = $vartable;
  1201. }
  1202. }else if(strtolower($this->query->getResultForm()) == ''describe''){
  1203. $result = $this->describeGraph(null);
  1204. }else if(strtolower($this->query->getResultForm()) == ''construct''){
  1205. $result = $this->constructGraph(false,$this->query->getConstructPattern());
  1206. }
  1207. if($resultform == ''xml'' && $this->query->getResultForm()!=''construct'' && $this->query->getResultForm()!=''describe'')
  1208. $result = $this->buildXmlResult($result);
  1209.  
  1210. return $result;
  1211. }
  1212.  
  1213. /**
  1214. * Generates an xml string from a given result table.
  1215. *
  1216. * @param $vartable The result table
  1217. * @return String The xml result string
  1218. */
  1219. protected function buildXmlResult($vartable){
  1220.  
  1221. if($vartable instanceof NamedGraphMem )
  1222. return $vartable->writeRdfToString();
  1223.  
  1224. $result = ''<sparql xmlns="http://www.w3.org/2005/sparql-results#">'';
  1225. $header = ''<head>'';
  1226.  
  1227. // build header
  1228. if(is_array($vartable)){
  1229. $vars = $this->query->getResultVars();
  1230. $header = ''<head>'';
  1231. foreach($vars as $value){
  1232. $header = $header.''<variable name="''.substr($value,1).''"/>'';
  1233. }
  1234. $header = $header.''</head>'';
  1235.  
  1236. // build results
  1237. $solm = $this->query->getSolutionModifier();
  1238. $sel = $this->query->getResultForm();
  1239.  
  1240. $distinct = ''false'';
  1241. if($sel == ''select distinct'')
  1242. $distinct = ''true'';
  1243.  
  1244. $ordered = ''false'';
  1245. if($solm[''order by''] != 0)
  1246. $ordered = ''true'';
  1247.  
  1248. $results = ''<results ordered="''.$ordered.''" distinct="''.$distinct.''">'';
  1249. foreach($vartable as $value){
  1250. $results = $results.''<result>'';
  1251. foreach($value as $varname => $varvalue)
  1252. $results = $results.$this->_getBindindString(substr($varname,1),$varvalue);
  1253. $results = $results.''</result>'';
  1254. }
  1255. $results = $results.''</results>'';
  1256. }else{
  1257. $results = ''</head><boolean>''.$vartable.''</boolean>'';
  1258. }
  1259. $result = $result.$header.$results.''</sparql>'';
  1260. $result = simplexml_load_string($result);
  1261. return $result->asXML();
  1262.  
  1263. }
  1264.  
  1265. /**
  1266. * Helper Function for function buildXmlResult($vartable). Generates
  1267. * an xml string for a single variable an their corresponding value.
  1268. *
  1269. * @param String $varname The variables name
  1270. * @param Node $varvalue The value of the variable
  1271. * @return String The xml string
  1272. */
  1273. protected function _getBindindString($varname,$varvalue){
  1274. $binding = ''<binding name="''.$varname.''">'';
  1275. $value = ''<unbound/>'';
  1276.  
  1277. if($varvalue instanceof BlankNode ){
  1278. $value = ''<bnode>''.$varvalue->getLabel().''</bnode>'';
  1279. }elseif ($varvalue instanceof Resource){
  1280. $value = ''<uri>''.$varvalue->getUri().''</uri>'';
  1281. }elseif ($varvalue instanceof Literal){
  1282. $label = htmlentities($varvalue->getLabel());
  1283. $value = ''<literal>''.$label.''</literal>'';
  1284. if($varvalue->getDatatype() != null)
  1285. $value = ''<literal datatype="''.$varvalue->getDatatype().''">''.$label.''</literal>'';
  1286. if($varvalue->getLanguage() != null)
  1287. $value = ''<literal xml:lang="''.$varvalue->getLanguage().''">''.$label.''</literal>'';
  1288. }
  1289. $binding = $binding.$value.''</binding>'';
  1290.  
  1291. return $binding;
  1292. }
  1293.  
  1294.  
  1295. /**
  1296. * Prints a query result as HTML table.
  1297. * You can change the colors in the configuration file.
  1298. *
  1299. * @param array $queryResult [][?VARNAME] = object Node
  1300. * @return void
  1301. */
  1302. public function writeQueryResultAsHtmlTable($queryResult) {
  1303. // Import Package Utility
  1304. include_once(RDFAPI_INCLUDE_DIR.PACKAGE_UTILITY);
  1305.  
  1306. if ($queryResult[0] == null) {
  1307. echo ''no match<br>'';
  1308. return;
  1309. }
  1310.  
  1311. echo ''<table border="1" cellpadding="3" cellspacing="0"><tr><td><b>No.</b></td>'';
  1312. foreach ($queryResult[0] as $varName => $value)
  1313. echo "<td align=''center''><b>$varName</b></td>";
  1314. echo ''</tr>'';
  1315.  
  1316. foreach ($queryResult as $n => $var) {
  1317.  
  1318.  
  1319. echo ''<tr><td width="20" align="right">'' .($n + 1) .''.</td>'';
  1320. foreach ($var as $varName => $value) {
  1321. if($value !=''''){
  1322. echo INDENTATION . INDENTATION . ''<td bgcolor="'';
  1323. echo RDFUtil::chooseColor($value);
  1324. echo ''">'';
  1325. echo ''<p>'';
  1326.  
  1327. $lang = NULL;
  1328. $dtype = NULL;
  1329. if (is_a($value, ''Literal'')) {
  1330. if ($value->getLanguage() != NULL)
  1331. $lang = '' <b>(xml:lang="'' . $value->getLanguage() . ''") </b> '';
  1332. if ($value->getDatatype() != NULL)
  1333. $dtype = '' <b>(rdf:datatype="'' . $value->getDatatype() . ''") </b> '';
  1334. }
  1335. echo RDFUtil::getNodeTypeName($value) .$value->getLabel() . $lang . $dtype .''</p>'';
  1336. }else{
  1337. echo "<td bgcolor=''white''>unbound";
  1338. }
  1339. }
  1340. echo ''</tr>'';
  1341. }
  1342. echo ''</table>'';
  1343. }
  1344.  
  1345. } // end: Class SparqlEngine
  1346.  
  1347. ?>

Documentation generated on Fri, 13 Jan 2006 07:49:40 +0100 by phpDocumentor 1.3.0RC4