Ejemplo n.º 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();
   }
 }
Ejemplo n.º 2
0
 /**
  * Get the label for a resource, preferring 1. the given language 2. configured languages 3. any language.
  * @param EasyRdf_Resource $res resource whose label to return
  * @param string $lang preferred language
  * @return EasyRdf_Literal label as an EasyRdf_Literal object, or null if not found
  */
 public function getResourceLabel($res, $lang)
 {
     $langs = array_merge(array($lang), array_keys($this->config->getLanguages()));
     foreach ($langs as $l) {
         $label = $res->label($l);
         if ($label !== null) {
             return $label;
         }
     }
     return $res->label();
     // desperate check for label in any language; will return null if even this fails
 }
Ejemplo n.º 3
0
 /**
  * Iterates over all the properties of the concept and returns those in an array.
  * @return array
  */
 public function getProperties()
 {
     $properties = array();
     $narrowers_by_uri = array();
     $in_a_collection = array();
     $members_array = array();
     $long_uris = $this->resource->propertyUris();
     $duplicates = array();
     $ret = array();
     // looking for collections and linking those with their narrower concepts
     if ($this->vocab->getConfig()->getArrayClassURI() !== null) {
         $collections = $this->graph->allOfType($this->vocab->getConfig()->getArrayClassURI());
         if (sizeof($collections) > 0) {
             // indexing the narrowers once to avoid iterating all of them with every collection
             foreach ($this->resource->allResources('skos:narrower') as $narrower) {
                 $narrowers_by_uri[$narrower->getUri()] = $narrower;
             }
             foreach ($collections as $coll) {
                 $curr_coll_members = $this->getCollectionMembers($coll, $narrowers_by_uri);
                 foreach ($curr_coll_members as $collection) {
                     if ($collection->getSubMembers()) {
                         $submembers = $collection->getSubMembers();
                         foreach ($submembers as $member) {
                             $in_a_collection[$member->getUri()] = true;
                         }
                     }
                 }
                 if (isset($collection) && $collection->getSubMembers()) {
                     $members_array = array_merge($curr_coll_members, $members_array);
                 }
             }
             $properties['skos:narrower'] = $members_array;
         }
     }
     foreach ($long_uris as &$prop) {
         if (EasyRdf_Namespace::shorten($prop) !== null) {
             // shortening property labels if possible
             $prop = $sprop = EasyRdf_Namespace::shorten($prop);
         } else {
             $sprop = "<{$prop}>";
         }
         // EasyRdf requires full URIs to be in angle brackets
         if (!in_array($prop, $this->DELETED_PROPERTIES)) {
             $propres = new EasyRdf_Resource($prop, $this->graph);
             $proplabel = $propres->label($this->getEnvLang()) ? $propres->label($this->getEnvLang()) : $propres->label();
             $propobj = new ConceptProperty($prop, $proplabel);
             if ($propobj->getLabel() !== null) {
                 // only display properties for which we have a label
                 $ret[$prop] = $propobj;
             }
             // searching for subproperties of literals too
             foreach ($this->graph->allResources($prop, 'rdfs:subPropertyOf') as $subi) {
                 $suburi = EasyRdf_Namespace::shorten($subi->getUri()) ? EasyRdf_Namespace::shorten($subi->getUri()) : $subi->getUri();
                 $duplicates[$suburi] = $prop;
             }
             // Iterating through every literal and adding these to the data object.
             foreach ($this->resource->allLiterals($sprop) as $val) {
                 $literal = new ConceptPropertyValueLiteral($val, $prop);
                 // only add literals when they match the content/hit language or have no language defined
                 if (isset($ret[$prop]) && ($literal->getLang() === $this->clang || $literal->getLang() === null)) {
                     $ret[$prop]->addValue($literal);
                 }
             }
             // Iterating through every resource and adding these to the data object.
             foreach ($this->resource->allResources($sprop) as $val) {
                 // skipping narrower concepts which are already shown in a collection
                 if ($sprop === 'skos:narrower' && array_key_exists($val->getUri(), $in_a_collection)) {
                     continue;
                 }
                 // hiding rdf:type property if it's just skos:Concept
                 if ($sprop === 'rdf:type' && $val->shorten() === 'skos:Concept') {
                     continue;
                 }
                 // handled by getMappingProperties()
                 if (in_array($sprop, $this->MAPPING_PROPERTIES)) {
                     continue;
                 }
                 if (isset($ret[$prop])) {
                     $ret[$prop]->addValue(new ConceptPropertyValue($this->model, $this->vocab, $val, $prop, $this->clang), $this->clang);
                 }
             }
         }
     }
     // adding narrowers part of a collection
     foreach ($properties as $prop => $values) {
         foreach ($values as $value) {
             $ret[$prop]->addValue($value, $this->clang);
         }
     }
     foreach ($ret as $key => $prop) {
         if (sizeof($prop->getValues()) === 0) {
             unset($ret[$key]);
         }
     }
     $ret = $this->removeDuplicatePropertyValues($ret, $duplicates);
     // sorting the properties to the order preferred in the Skosmos concept page.
     $ret = $this->arbitrarySort($ret);
     return $ret;
 }