/** * @see ValueFormatter::format * * @param string $conceptUri * * @throws InvalidArgumentException * @return string|null Null if the concept URI refers to a unitless unit. Otherwise a label or * an entity ID or the original concept URI. */ public function format($conceptUri) { if (!is_string($conceptUri)) { throw new InvalidArgumentException('$conceptUri must be a string'); } if (array_key_exists($conceptUri, $this->unitlessUnitIds)) { return null; } try { $entityId = $this->externalEntityIdParser->parse($conceptUri); try { // TODO: Ideally we would show unit *symbols*, taking from a config file, // a system message, or a statement on the unit's item. $term = $this->labelLookup->getLabel($entityId); } catch (LabelDescriptionLookupException $ex) { $term = null; } if ($term !== null) { return $term->getText(); } else { // Fall back to the entity ID. return $entityId->getSerialization(); } } catch (EntityIdParsingException $ex) { // Fall back to the raw concept URI. return $conceptUri; } }
/** * Lookup a label for an entity * * @param EntityId $entityId * * @return Term|null Null if no label was found or the entity does not exist */ protected function lookupEntityLabel(EntityId $entityId) { try { return $this->labelDescriptionLookup->getLabel($entityId); } catch (LabelDescriptionLookupException $e) { return null; } }
/** * @param EntityId $entityId * * @return Term[] array with keys 'label' and 'description' */ private function getDisplayTerms(EntityId $entityId) { $displayTerms = array(); $displayTerms['label'] = $this->labelDescriptionLookup->getLabel($entityId); $displayTerms['description'] = $this->labelDescriptionLookup->getDescription($entityId); return $displayTerms; }
/** * @param string $prefixedEntityId * * @since 0.5 * @return string|null Null if entity couldn't be found/ no label present */ public function getLabel($prefixedEntityId) { try { $entityId = $this->entityIdParser->parse($prefixedEntityId); } catch (EntityIdParsingException $e) { return null; } try { $term = $this->labelDescriptionLookup->getLabel($entityId); } catch (StorageException $ex) { // TODO: verify this catch is still needed return null; } catch (LabelDescriptionLookupException $ex) { return null; } if ($term === null) { return null; } // NOTE: This tracks a label usage in the wiki's content language. return $term->getText(); }