@param string  $keywords
@param boolean $asString

@return mixed

@throws NotFoundedKeywordException
556699
protected function partialReverseTransform($keywords, $asString = true)
    {
        $keywordArray = $this->getKeywordAsArray($keywords);
        $referenceKeywords = new ArrayCollection();

        foreach ($keywordArray as $keyword) {
            if ($keyword != '') {
                $keywordDocument = $this->keywordRepository->find($keyword);
                if (is_null($keywordDocument)) {
                    $keywordDocument = $this->keywordToDocumentManager->getDocument($keyword);
                }
                if (!is_null($keywordDocument)) {
                    $keywords = str_replace($keyword, $keywordDocument->getId(), $keywords);
                    $referenceKeywords->add($keywordDocument);
                } else {
                    throw new NotFoundedKeywordException();
                }
            }
        }

        return $asString ? $keywords : $referenceKeywords;
    }
776911
public function isActionMessage($keys = null) {
        $messages = $this->getAttribute(ACTION_MESSAGES_KEY);
        if (!$messages)
            return $this->isActionError($keys);

        if (is_string($keys))
            $keys = [$keys];

        if (is_array($keys)) {
            foreach ($keys as $key) {
                if (key_exists($key, $messages)) return true;
            }
            if ($keys)
                return $this->isActionError($keys);
            $keys = null;
        }

        if (is_null($keys))
            return true;
        throw new IllegalTypeException('Illegal type of parameter $keys: '.gettype($keys));
    }
263432
public function addKeyword($keyword, $action)
    {
        if ($this->hasKeyword($keyword)) {
            throw new InvalidArgumentException("The keyword $keyword is already set.", 31);
        }

        $this->setKeyword($keyword, $action);
    }
406545
public function filterByKeywords($keywords)
    {
        $expressions = [
            $this->query->expr()->like('g.gName', ':keywords'),
            $this->query->expr()->like('g.gDescription', ':keywords'),
        ];

        $expr = $this->query->expr();
        $this->query->andWhere(call_user_func_array([$expr, 'orX'], $expressions));
        $this->query->setParameter('keywords', '%' . $keywords . '%');
    }
1176865
public static function purify($keywords){

		$keywords	= filter_var($keywords, FILTER_SANITIZE_STRING,
			FILTER_FLAG_NO_ENCODE_QUOTES);
		$keywords	= preg_replace('/\s\s+/', ' ', $keywords);
		$keywords	= trim($keywords);

		$dirty_tokens = explode(' ', $keywords);
		$clean_tokens = [];

		foreach($dirty_tokens as $token){

			// Check whether a string has at least 3 alphanumeric characters
			$pattern = "/[\w'\"`-]{3,}/i";
			if(preg_match($pattern, $token)){

				if(strlen($token) < 64){

					$clean_tokens[] = $token;
				}
			}
		}

		return [
			'dirty' => $dirty_tokens,
			'clean' => $clean_tokens,
			'stems' => $clean_tokens
		];
	}
909819
public static function fireEvent($event, $args = array(), $resultAsString = false)
    {
        $results = array();
        
        if (isset(self::$events[$event])) {
            $keys = array_keys(self::$events[$event]); 
            sort($keys);
            foreach ($keys as $key) {
                $callback = self::$events[$event][$key];
                $results[$key] = call_user_func_array($callback, $args);
            }
        }
        
        if ($resultAsString) {
            return implode('', $results);
        }
        return $results;
    }
246910
private function decode($string, $fieldName, $assoc = false)
    {
        $jsonError = false;
        $result    = json_decode($string, $assoc);
        switch (json_last_error()) {
            case JSON_ERROR_NONE:
                break;
            case JSON_ERROR_DEPTH:
                $jsonError = 'Maximum stack depth exceeded';
                break;
            case JSON_ERROR_STATE_MISMATCH:
                $jsonError = 'Underflow or the modes mismatch';
                break;
            case JSON_ERROR_CTRL_CHAR:
                $jsonError = 'Unexpected control character found';
                break;
            case JSON_ERROR_SYNTAX:
                $jsonError = 'Syntax error, malformed JSON';
                break;
            case JSON_ERROR_UTF8:
                $jsonError = 'Malformed UTF-8 characters, possibly incorrectly encoded';
                break;
            default:
                $jsonError = 'Unknown error';
                break;
        }
        if ($jsonError) {
            throw new \Exception('JSON is invalid in field '.$fieldName.' JSON error: '.$jsonError);
        }

        return $result;
    }
384476
public static function keywords($string = '', $count = 1000, $dict = '', $attr = null) {
        $keywords = [];
        if (extension_loaded('scws') && $string) {
            $scws1 = scws_new();
            $scws1->set_charset('utf8');
            $dict = $dict ? $dict : self::$dict;
            if ($dict && is_file($dict)) {
                @$scws1->set_dict($dict, SCWS_XDICT_XDB);
            }
            $scws1->set_multi(15);
            $keywords = self::doit($scws1, $string, $count, $attr);
            $scws1->close();
        }

        return $keywords;
    }
883326
public function replaceKeyword($keyword, $action)
    {
        if (!$this->hasKeyword($keyword)) {
            throw new InvalidArgumentException("The keyword $keyword is not set.", 32);
        }

        $this->setKeyword($keyword, $action);
    }
1278114
public function get_last_updated($asstring = false) {
        $data = $this->data;
        $time = null;

        if (isset($data[Parser::INDEX_LISTS_LIST_UPDATED])) {
            $time = $data[Parser::INDEX_LISTS_LIST_UPDATED][0]['value'];
            $time = strtotime($time);
        }

        if ($asstring && $time) {
            return $this->contextual_time($time);
        }

        return $time;
    }
708392
public function keywords($keywords = [])
    {
        $args = func_get_args();

        $this->mergeKeywords = (is_bool(end($args)) || is_int(end($args))) ? array_pop($args) : false;

        $keywords = is_array($keywords) ? $keywords : $args;

        array_walk($keywords, function (&$value) {
            $value = is_object($value) ? get_class($value) : $value;
        });

        $this->keywords = array_unique($keywords);

        return $this;
    }
1370561
public function addKeywordsFilter($keywords)
    {
        $contentIds = $this->_em->getRepository('BackBee\NestedNode\KeyWord')
                                ->getContentsIdByKeyWords($keywords);
        if (is_array($contentIds) && !empty($contentIds)) {
            $this->andWhere('cc._uid in(:keywords)')->setParameter('keywords', $contentIds);
        }
    }
282556
public function getRealRoute($asString = false)
    {
        return ($asString === true) ? implode('/', $this->realRoute) : $this->realRoute;
    }
939829
public function execute($url, $postString = '', array $headers = [])
    {
        return $this
            ->init($url, $postString, $headers)
            ->callCurl();
    }
709414
public function detectKeyword(?string $speech,
                                  string $callback_url,
                                  array $key_words,
                                  int $format = 2,
                                  string $speech_url = null
    ) {
        $speech = self::encode($speech);

        $key_words = implode('|', $key_words);

        return Request::exec('aai/aai_detectkeyword', array_filter(compact('format', 'callback_url', 'key_words', 'speech', 'speech_url')));
    }
132336
public function setKeywords(array $keywords)
    {
        foreach ($keywords as $query) {
            $keyword    = $query[0];
            $properties = (isset($query[1]) ? (array)$query[1] : null);
            $this->addKeyword($keyword, $properties);
        }

        return $this;
    }
562901
public function paramsToString(array $params, $assoc = true)
    {
        $string = [];
        foreach ($params as $key => $param) {
            if (is_array($param)) {
                $string[] = $assoc
                    ? $key . '=' . $this->paramsToString($param, isAssocArray($param))
                    : $this->paramsToString($param, isAssocArray($param));
            } else {
                $string[] = $assoc ? $key . '=' . $param : $param;
            }
        }
        return join('&', $string);
    }