Пример #1
0
 /**
  * Adds Type label to list.
  *
  * @param \EasyRdf_Resource $type
  *   An EasyRdf_Resource which is a type.
  */
 private function addType(\EasyRdf_Resource $type) {
   if ($type != NULL) {
     // Omit deprecated types.
     if ($type->get("schema:supersededBy")) {
       return;
     }
     $this->listTypes[$type->shorten()] = $type->label();
   }
 }
Пример #2
0
 public function testShortenUnknown()
 {
     $unknown = new EasyRdf_Resource('http://example.com/foo');
     $this->assertSame(null, $unknown->shorten());
 }
Пример #3
0
 /**
  * Transform the concept search query results into the skosmos desired return format.
  * @param EasyRdf_Sparql_Result $results
  * @param array $vocabs array of Vocabulary objects to search; empty for global search
  * @return array query result object
  */
 private function transformConceptSearchResults($results, $vocabs)
 {
     $ret = array();
     $qnamecache = array();
     // optimization to avoid expensive shorten() calls
     foreach ($results as $row) {
         if (!isset($row->s)) {
             continue;
         }
         // don't break if query returns a single dummy result
         $hit = array();
         $hit['uri'] = $row->s->getUri();
         if (isset($row->graph)) {
             $hit['graph'] = $row->graph->getUri();
         }
         foreach (explode(" ", $row->types->getValue()) as $typeuri) {
             if (!array_key_exists($typeuri, $qnamecache)) {
                 $res = new EasyRdf_Resource($typeuri);
                 $qname = $res->shorten();
                 // returns null on failure
                 $qnamecache[$typeuri] = $qname !== null ? $qname : $typeuri;
             }
             $hit['type'][] = $qnamecache[$typeuri];
         }
         if (isset($row->broaders)) {
             foreach (explode("\n", $row->broaders->getValue()) as $line) {
                 $brdata = str_getcsv($line, ',', '"', '"');
                 $broader = array('uri' => $brdata[0]);
                 if ($brdata[1] != '') {
                     $broader['prefLabel'] = $brdata[1];
                 }
                 $hit['broader'][] = $broader;
             }
         }
         foreach ($vocabs as $vocab) {
             // looping the vocabulary objects and asking these for a localname for the concept.
             $localname = $vocab->getLocalName($hit['uri']);
             if ($localname !== $hit['uri']) {
                 // only passing the result forward if the uri didn't boomerang right back.
                 $hit['localname'] = $localname;
                 break;
                 // stopping the search when we find one that returns something valid.
             }
         }
         if (isset($row->label)) {
             $hit['prefLabel'] = $row->label->getValue();
         }
         if (isset($row->label)) {
             $hit['lang'] = $row->label->getLang();
         }
         if (isset($row->plabel)) {
             $hit['matchedPrefLabel'] = $row->plabel->getValue();
             $hit['lang'] = $row->plabel->getLang();
         } elseif (isset($row->alabel)) {
             $hit['altLabel'] = $row->alabel->getValue();
             $hit['lang'] = $row->alabel->getLang();
         } elseif (isset($row->hlabel)) {
             $hit['hiddenLabel'] = $row->hlabel->getValue();
             $hit['lang'] = $row->hlabel->getLang();
         }
         $ret[] = $hit;
     }
     return $ret;
 }