protected function doFormatFinalOutputFor($type, $linker)
 {
     $text = $this->dataValue->getDataItem()->getString();
     $length = mb_strlen($text);
     // Make a possibly shortened printout string for displaying the value.
     // The result is only escaped to be HTML-safe if this is requested
     // explicitly. The result will contain mark-up that must not be escaped
     // again.
     $abbreviate = $type === self::WIKI_LONG || $type === self::HTML_LONG;
     $requestedLength = intval($this->dataValue->getOutputFormat());
     // Appease the MW parser to correctly apply formatting on the
     // first indent
     if ($text !== '' && ($text[0] === '*' || $text[0] === '#' || $text[0] === ':')) {
         $text = "\n" . $text . "\n";
     }
     if ($requestedLength > 0 && $requestedLength < $length) {
         // Reduces the length and finish it with a whole word
         return Normalizer::reduceLengthTo($text, $requestedLength) . ' …';
     }
     if ($type === self::HTML_SHORT || $type === self::HTML_LONG) {
         $text = smwfXMLContentEncode($text);
     }
     return $abbreviate && $length > 255 ? $this->getAbbreviatedText($text, $length, $linker) : $text;
 }
 private function predictLanguage($text)
 {
     if ($this->languageDetection === array()) {
         return null;
     }
     $languageDetector = $this->sanitizerFactory->newNullLanguageDetector();
     if (isset($this->languageDetection['TextCatLanguageDetector'])) {
         $languageDetector = $this->sanitizerFactory->newTextCatLanguageDetector();
         $languageDetector->setLanguageCandidates($this->languageDetection['TextCatLanguageDetector']);
     }
     return $languageDetector->detect(Normalizer::reduceLengthTo($text, 200));
 }
Example #3
0
 /**
  * @since 0.1
  *
  * @param integer $length
  */
 public function reduceLengthTo($length)
 {
     $this->string = Normalizer::reduceLengthTo($this->string, $length);
 }
Example #4
0
 public function testToLowercase()
 {
     $this->assertEquals('abcdef', Normalizer::toLowercase('ABCDEF'));
 }