Convert dot lemmas to structured lemmas.

@param array $structured

@return array
546803
protected function getLemmasStructured(array $structured = [])
    {
        foreach ($this->getLemmas() as $key => $value) {
            // Get the lemma family
            $family = substr($key, 0, strpos($key, '.'));

            // Check key against the ignore list
            if (in_array($family, $this->config('ignore_lang_files', []))) {
                if ($this->option('verbose')) {
                    $this->line('');
                    $this->info("    ! Skip lang file '{$family}' !");
                }

                continue;
            }

            // Sanity check
            if (strpos($key, '.') === false) {
                $this->line('    <error>' . $key . '</error> in file <comment>' . $this->getShortPath($value) . '</comment> <error>will not be included because it has no parent</error>');
            }
            else {
                Arr::set(
                    $structured, $this->encodeKey($key), $value
                );
            }
        }

        return $structured;
    }
1246713
protected function getLemmas(array $lemmas = [])
    {
        // Get folders
        $folders = $this->getPath($this->config('folders', []));

        foreach ($folders as $path) {
            if ($this->option('verbose')) {
                $this->line('    <info>' . $path . '</info>');
            }

            foreach ($this->getPhpFiles($path) as $php_file_path => $dumb) {
                $lemma = [];

                foreach ($this->extractTranslationFromFile($php_file_path) as $k => $v) {
                    $real_value = eval("return $k;");
                    $lemma[$real_value] = $php_file_path;
                }

                $lemmas = array_merge($lemmas, $lemma);
            }
        }

        if (count($lemmas) === 0) {
            $this->comment("No lemma have been found in the code.");
            $this->line("In these directories:");

            foreach ($this->config('folders', []) as $path) {
                $path = $this->getPath($path);
                $this->line("    {$path}");
            }

            $this->line("For these functions/methods:");

            foreach ($this->config('trans_methods', []) as $k => $v) {
                $this->line("    {$k}");
            }

            die();
        }

        $this->line((count($lemmas) > 1) ? count($lemmas)
            . " lemmas have been found in the code"
            : "1 lemma has been found in the code");

        if ($this->option('verbose')) {
            foreach ($lemmas as $key => $value) {
                if (strpos($key, '.') !== false) {
                    $this->line('    <info>' . $key . '</info> in file <comment>'
                        . $this->getShortPath($value) . '</comment>');
                }
            }
        }

        return $lemmas;
    }
1132218
protected function dumpLemmas(array $lemmas)
    {
        // Create a dumpy-dump
        $content = var_export($lemmas, true);

        // Decode all keys
        $content = $this->decodeKey($content);

        return $this->dumpLangArray("<?php\n\nreturn {$content};");
    }
1110324
public static function simplifyCNF(array $clauses)
    {
        $cloned_clauses = [];

        // avoid strict duplicates
        foreach ($clauses as $clause) {
            $unique_clause = clone $clause;
            foreach ($unique_clause->possibilities as $var_id => $possibilities) {
                if (count($possibilities)) {
                    $unique_clause->possibilities[$var_id] = array_unique($possibilities);
                }
            }
            $cloned_clauses[$clause->getHash()] = $unique_clause;
        }

        // remove impossible types
        foreach ($cloned_clauses as $clause_a) {
            if (count($clause_a->possibilities) !== 1 || count(array_values($clause_a->possibilities)[0]) !== 1) {
                continue;
            }

            if (!$clause_a->reconcilable || $clause_a->wedge) {
                continue;
            }

            $clause_var = array_keys($clause_a->possibilities)[0];
            $only_type = array_pop(array_values($clause_a->possibilities)[0]);
            $negated_clause_type = self::negateType($only_type);

            foreach ($cloned_clauses as $clause_b) {
                if ($clause_a === $clause_b || !$clause_b->reconcilable || $clause_b->wedge) {
                    continue;
                }

                if (isset($clause_b->possibilities[$clause_var]) &&
                    in_array($negated_clause_type, $clause_b->possibilities[$clause_var], true)
                ) {
                    $clause_b->possibilities[$clause_var] = array_filter(
                        $clause_b->possibilities[$clause_var],
                        /**
                         * @param string $possible_type
                         *
                         * @return bool
                         */
                        function ($possible_type) use ($negated_clause_type) {
                            return $possible_type !== $negated_clause_type;
                        }
                    );

                    if (count($clause_b->possibilities[$clause_var]) === 0) {
                        unset($clause_b->possibilities[$clause_var]);
                        $clause_b->impossibilities = null;
                    }
                }
            }
        }

        $deduped_clauses = [];

        // avoid strict duplicates
        foreach ($cloned_clauses as $clause) {
            $deduped_clauses[$clause->getHash()] = clone $clause;
        }

        $deduped_clauses = array_filter(
            $deduped_clauses,
            /**
             * @return bool
             */
            function (Clause $clause) {
                return count($clause->possibilities) || $clause->wedge;
            }
        );

        $simplified_clauses = [];

        foreach ($deduped_clauses as $clause_a) {
            $is_redundant = false;

            foreach ($deduped_clauses as $clause_b) {
                if ($clause_a === $clause_b
                    || !$clause_b->reconcilable
                    || $clause_b->wedge
                    || $clause_a->wedge
                ) {
                    continue;
                }

                if ($clause_a->contains($clause_b)) {
                    $is_redundant = true;
                    break;
                }
            }

            if (!$is_redundant) {
                $simplified_clauses[] = $clause_a;
            }
        }

        return $simplified_clauses;
    }
1254924
def massage_structured(get_args, ref)
      # Nothing to do unless nxapi_structured.
      return [get_args, ref] unless
        ref.hash['get_data_format'] == :nxapi_structured

      # The CmdRef object will contain a get_value Array with 2 values.
      # The first value is the key to identify the correct row in the table
      # of structured output and the second is the key to identify the data
      # to retrieve.
      #
      # Example: Get vlanshowbr-vlanname in the row that contains a specific
      #  vlan_id.
      # "get_value"=>["vlanshowbr-vlanid-utf <vlan_id>", "vlanshowbr-vlanname"]
      #
      # TBD: Why do we need to check is_a?(Array) here?
      if ref.hash['get_value'].is_a?(Array) && ref.hash['get_value'].size >= 2
        # Replace the get_value hash entry with the value after any tokens
        # specified in the yaml file have been replaced and set get_args[:value]
        # to nil so that the structured table data can be retrieved properly.
        ref.hash['get_value'] = get_args[:value]
        ref.hash['drill_down'] = true
        get_args[:value] = nil
        cache_flush
      end
      [get_args, ref]
    end
690303
public static function buildStructure($array, Structure $structure)
    {
        switch ($structure->getType()) {
            case Structure::TYPE_LIST:
                $result = self::buildList($array, $structure);
                break;
            case Structure::TYPE_ARRAY:
                $result = self::buildArray($array, $structure);
                break;
            default:
                throw new Exception('Unknown structure type ' . $structure->getType());
        }

        return $result;
    }
859110
private function relationsFromExpand(array $relations, array $expandPrefixes)
    {
        $valid = [];
        foreach ($expandPrefixes as $prefix) {
            foreach ($relations as $relation) {
                if (StringHelper::startsWith($relation, $prefix)) {
                    $valid[] = $relation;
                }
            }
        }
        return $valid;
    }
1240728
private function preProcessTags($tags): array
    {
        if (!$tags) {
            return $this->getRegistered();
        }

        if (is_string($tags)) {
            $tags = explode('|', $tags);
        }

        return array_filter($tags, [$this, 'isRegistered']);
    }
649012
public function getAdditionalNodeMetadataAction(array $nodes)
    {
        $result = [];
        /** @var NodeInterface $node */
        foreach ($nodes as $node) {
            $otherNodeVariants = array_values(array_filter(array_map(function ($node) {
                return $this->getCurrentDimensionPresetIdentifiersForNode($node);
            }, $node->getOtherNodeVariants())));
            $result[$node->getContextPath()] = [
                'policy' => $this->nodePolicyService->getNodePolicyInformation($node),
                'dimensions' => $this->getCurrentDimensionPresetIdentifiersForNode($node),
                'otherNodeVariants' => $otherNodeVariants
            ];
        }

        $this->view->assign('value', $result);
    }
179155
public final function getValidateRules(...$fileds) {
		if ($fileds) {
			$rules = [];
			foreach ($fileds as $f) {
				if (isset($this->rules[ $f ])) {
					$rules[ $f ] = $this->rules[ $f ];
				}
			}

			return $rules;
		}

		return $this->rules;
	}
511146
public static function getAllPatternCacheSubkeys() : array
    {
        $subkeys = [];
        $chars = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f'];

        foreach ($chars as $charOne) {
            foreach ($chars as $charTwo) {
                $subkeys[$charOne . $charTwo] = '';
            }
        }

        return $subkeys;
    }
754454
protected function formatScopes($unformated = [])
    {
        $scopes = [];
        foreach ($unformated as $scope) {
            if ($scope instanceof ScopeEntity) {
                $scopes[$scope->getId()] = $scope;
            }
        }

        return $scopes;
    }
937803
protected function structure_charset($structure)
    {
        while (is_array($structure)) {
            if (is_array($structure[2]) && $structure[2][0] == 'charset') {
                return $structure[2][1];
            }
            $structure = $structure[0];
        }
    }
1295173
public function convertArrayToDotNotation(array $array)
    {
        $recursiveIterator = new \RecursiveIteratorIterator(new \RecursiveArrayIterator($array));

        $newArray = [];

        foreach ($recursiveIterator as $leafValue) {
            $keys = [];

            foreach (range(0, $recursiveIterator->getDepth()) as $depth) {
                $keys[] = $recursiveIterator->getSubIterator($depth)->key();
            }

            $newArray[implode('.', $keys)] = $leafValue;
        }

        return $newArray;
    }
1298710
protected function convertKeys(array $meta) {
        $return = [];
        foreach ($meta as $key => $value) {
            if (is_array($value)) {
                $value = $this->convertKeys($value);
            }
            $newKey = strtolower($key);
            $newKey = preg_replace('/[^\w+]/', '_', $newKey);
            $return[$newKey] = $value;
        }
        return $return;
    }
224952
private function getStatementLexingMethods() : array
    {
        $statements = [
            $this->directiveDelimiters[0] => 'lexDirectiveStatement',
            $this->sanitizedTagDelimiters[0] => 'lexSanitizedTagStatement',
            $this->unsanitizedTagDelimiters[0] => 'lexUnsanitizedTagStatement',
            $this->commentDelimiters[0] => 'lexCommentStatement',
            '<?php' => 'lexPhpStatement',
            '<?' => 'lexPhpStatement'
        ];

        /**
         * In case one delimiter is a substring of the other ("{{" and "{{!"), we want to sort the delimiters
         * so that the longest delimiters come first
         */
        uksort($statements, function ($a, $b) {
            if (strlen($a) > strlen($b)) {
                return -1;
            } else {
                return 1;
            }
        });

        return $statements;
    }
869375
public static function parse($rules)
    {
        if ($rules instanceof RuleContract) {
            return [$rules, []];
        }

        if (is_array($rules)) {
            $rules = static::parseArrayRule($rules);
        } else {
            $rules = static::parseStringRule($rules);
        }

        $rules[0] = static::normalizeRule($rules[0]);

        return $rules;
    }