asString() public static method

public static asString ( $uri )
示例#1
0
 function __toString()
 {
     return isset($this->triple["v"]) ? Graphite::asString($this->triple['v']) : "";
 }
示例#2
0
 /**
  * Create a new resource list with containing only the resources which are in $resourcelist but not in the list being passed in. Only returns one instance of each resource no matter how many duplicates   were in either list.
  *
  * $new_resourcelist = $resourcelist->except( $resource );
  * $new_resourcelist = $resourcelist->except( *resource list* );
  */
 function except()
 {
     $args = func_get_args();
     if (isset($args[0]) && $args[0] instanceof Graphite_ResourceList) {
         $args = $args[0];
     }
     if (isset($args[0]) && is_array($args[0])) {
         $args = func_get_arg(0);
     }
     $list = new Graphite_ResourceList($this->g, array());
     $exclude = array();
     foreach ($args as $arg) {
         if (!$arg instanceof Graphite_Resource) {
             $arg = $this->g->resource($arg);
         }
         $exclude[Graphite::asString($arg)] = 1;
     }
     foreach ($this as $arg) {
         if (!$arg instanceof Graphite_Resource) {
             $arg = $this->g->resource($arg);
         }
         if (isset($exclude[Graphite::asString($arg)])) {
             continue;
         }
         $list[] = $arg;
     }
     return $list;
 }
示例#3
0
 /**
  * Translate a URI from the short form to any long version known.
  * IE:  foaf:knows => http://xmlns.com/foaf/0.1/knows
  * also expands "a" => http://www.w3.org/1999/02/22-rdf-syntax-ns#type
  */
 public function expandURI($uri)
 {
     # allow "a" as even shorter cut for rdf:type. This doesn't get applied
     # in inverse if you use shrinkURI
     if ($uri == "a") {
         return "http://www.w3.org/1999/02/22-rdf-syntax-ns#type";
     }
     if (preg_match('/:/', Graphite::asString($uri))) {
         list($ns, $tag) = preg_split("/:/", Graphite::asString($uri), 2);
         if (isset($this->ns[$ns])) {
             return $this->ns[$ns] . $tag;
         }
     }
     return Graphite::asString($uri);
 }
示例#4
0
 function _toSPARQL($tree, $suffix, $in_dangler = null, $sparqlprefix = "")
 {
     $bits = array();
     if (!isset($in_dangler)) {
         $in_dangler = "<" . Graphite::asString($this->resource) . ">";
     }
     $i = 0;
     foreach ($tree as $dir => $routes) {
         if (sizeof($routes) == 0) {
             continue;
         }
         $pres = array();
         if (isset($routes["*"])) {
             $sub = "?s" . $suffix . "_" . $i;
             $pre = "?p" . $suffix . "_" . $i;
             $obj = "?o" . $suffix . "_" . $i;
             if ($dir == "+") {
                 $out_dangler = $obj;
                 $sub = $in_dangler;
             } else {
                 $out_dangler = $sub;
                 $obj = $in_dangler;
             }
             $construct = "{$sub} {$pre} {$obj} . ";
             $where = "{$sparqlprefix} {$sub} {$pre} {$obj} .";
             if (isset($routes["*"])) {
                 $bits_from_routes = $this->_toSPARQL($routes["*"], $suffix . "_" . $i, $out_dangler, "");
                 $i++;
                 foreach ($bits_from_routes as $bit) {
                     $construct .= $bit["construct"];
                     $where .= " OPTIONAL { " . $bit["where"] . " }";
                 }
             }
             $bits[] = array("where" => $where, "construct" => $construct);
             foreach ($routes as $pred => $route) {
                 if ($pred == "*") {
                     continue;
                 }
                 $pre = "<" . $this->graph->expandURI($pred) . ">";
                 $bits_from_routes = $this->_toSPARQL($route, $suffix . "_" . $i, $out_dangler, "{$sparqlprefix} {$sub} {$pre} {$obj} .");
                 $i++;
                 foreach ($bits_from_routes as $bit) {
                     $bits[] = $bit;
                 }
             }
         } else {
             foreach (array_keys($routes) as $pred) {
                 $sub = "?s" . $suffix . "_" . $i;
                 $pre = "<" . $this->graph->expandURI($pred) . ">";
                 $obj = "?o" . $suffix . "_" . $i;
                 if ($dir == "+") {
                     $out_dangler = $obj;
                     $sub = $in_dangler;
                 } else {
                     $out_dangler = $sub;
                     $obj = $in_dangler;
                 }
                 $bits_from_routes = $this->_toSPARQL($routes[$pred], $suffix . "_" . $i, $out_dangler, "");
                 $i++;
                 $construct = "{$sub} {$pre} {$obj} . ";
                 $where = "{$sparqlprefix} {$sub} {$pre} {$obj} .";
                 foreach ($bits_from_routes as $bit) {
                     $construct .= $bit["construct"];
                     $where .= " OPTIONAL { " . $bit["where"] . " }";
                 }
                 $bits[] = array("where" => $where, "construct" => $construct);
             }
         }
     }
     return $bits;
 }
示例#5
0
 protected function parsePropertyArg($arg)
 {
     if (is_a($arg, "Graphite_Resource")) {
         if (is_a($arg, "Graphite_InverseRelation")) {
             return array("op", Graphite::asString($arg));
         }
         return array("sp", Graphite::asString($arg));
     }
     $set = "sp";
     if (substr($arg, 0, 1) == "-") {
         $set = "op";
         $arg = substr($arg, 1);
     }
     return array($set, $this->g->expandURI("{$arg}"));
 }