<commit_before><?php

namespace Polylang_CLI\Commands;

/**
 * Class Term
 *
 * @package Polylang_CLI
 */
class Term extends BaseCommand {

    /**
     * Get details about a translated term.
     *
     * ## OPTIONS
     *
     * <taxonomy>
     * : Taxonomy of the term to get
     *
     * <term-id>
     * : ID of the term to get
     *
     * [--field=<field>]
     * : Instead of returning the whole term, returns the value of a single field.
     *
     * [--fields=<fields>]
     * : Limit the output to specific fields. Defaults to all fields.
     *
     * [--format=<format>]
     * : Render output in a particular format.
     * ---
     * default: table
     * options:
     *   - table
     *   - csv
     *   - json
     *   - yaml
     * ---
     *
     * [--api]
     * : Use the Polylang API function pll_get_term_translations()
     *
     * ## EXAMPLES
     *
     *     # Get details about a category with term ID 18.
     *     $ wp pll term get category 18
     */
    public function get( $args, $assoc_args ) {

        list( $taxonomy, $term_id ) = $args;

        $term = get_term_by( 'id', $term_id, $taxonomy );

        if ( ! $term ) {
            $this->cli->error( "Term doesn't exist." );
        }

        $terms = $this->api->get_term_translations( $term_id );

        $obj_array = array();

        if ( $this->get_flag_value( $assoc_args, 'api' ) ) {
        if ( $this->cli->get_flag_value( $assoc_args, 'api' ) ) {

            foreach ( $terms as $slug => $term_id ) {
                $obj = new \stdClass();
                $obj->slug = $slug;
                $obj->term_id = $term_id;
                $obj_array[$term_id] = $obj;
            }

            $formatter = $this->cli->get_formatter( $assoc_args, array( 'slug', 'term_id' ), 'ID' );

        } else {

            foreach ( $terms as $term_id ) {

                $term = get_term_by( 'id', $term_id, $taxonomy );

                if ( empty( $assoc_args['fields'] ) ) {

                    $term_array = get_object_vars( $term );
                    $assoc_args['fields'] = array_keys( $term_array );
                }

                $term->count = (int) $term->count;
                $term->parent = (int) $term->parent;

                $obj_array[$term_id] = $term;
            }

            $formatter = $this->cli->get_formatter( $assoc_args, $this->fields_term, 'term' );
        }

        $formatter->display_items( $obj_array );
    }

    /**
     * Generate some taxonomy terms and their translations.
     *
     * Creates a specified number of sets of new terms and their translations with dummy data.
     *
     * ## OPTIONS
     *
     * <taxonomy>
     * : The taxonomy for the generated terms.
     *
     * [--count=<number>]
     * : How many sets of terms to generate?
     * ---
     * default: 5
     * ---
     *
     * [--max_depth=<number>]
     * : Generate child terms down to a certain depth.
     * ---
     * default: 1
     * ---
     *
     * [--format=<format>]
     * : Render output in a particular format.
     * ---
     * default: table
     * options:
     *   - table
     *   - csv
     *   - json
     *   - yaml
     *   - ids
     * ---
     *
     * ## EXAMPLES
     *
     *     # Generate some post categories, and translations.
     *     $ wp pll term generate category --count=3 --format=ids
     *     115 116 117 118 119 120
     */
    public function generate( $args, $assoc_args ) {

        list ( $taxonomy ) = $args;

        if ( ! $this->api->is_translated_taxonomy( $taxonomy ) ) {
            $this->cli->error( 'Polylang does not manage languages and translations for this taxonomy.' );
        }

        $languages = $this->api->languages_list();

        $count = $this->cli->get_flag_value( $assoc_args, 'count' );
        $count = ( $count < 1 ) ? 1 : absint( $count );
        $count = $count * count( $languages );

        ob_start();

        \WP_CLI::run_command(
            array( 'term', 'generate', $taxonomy ),
            array_merge( $assoc_args, array( 'count' => $count, 'format' => 'ids' ) )
        );

        $ids = ob_get_contents();

        ob_get_clean();

        $term_ids = wp_parse_id_list( $ids );

        $terms = array_chunk( $term_ids, count( $languages ) );

        foreach ( $terms as $i => $chunk ) {

            $terms[$i] = array_combine( $languages, $chunk );
<commit_msg>cleanup<commit_after><?php

namespace Polylang_CLI\Commands;

/**
 * Class Term
 *
 * @package Polylang_CLI
 */
class Term extends BaseCommand {

    /**
     * Get details about a translated term.
     *
     * ## OPTIONS
     *
     * <taxonomy>
     * : Taxonomy of the term to get
     *
     * <term-id>
     * : ID of the term to get
     *
     * [--field=<field>]
     * : Instead of returning the whole term, returns the value of a single field.
     *
     * [--fields=<fields>]
     * : Limit the output to specific fields. Defaults to all fields.
     *
     * [--format=<format>]
     * : Render output in a particular format.
     * ---
     * default: table
     * options:
     *   - table
     *   - csv
     *   - json
     *   - yaml
     * ---
     *
     * [--api]
     * : Use the Polylang API function pll_get_term_translations()
     *
     * ## EXAMPLES
     *
     *     # Get details about a category with term ID 18.
     *     $ wp pll term get category 18
     */
    public function get( $args, $assoc_args ) {

        list( $taxonomy, $term_id ) = $args;

        $term = get_term_by( 'id', $term_id, $taxonomy );

        if ( ! $term ) {
            $this->cli->error( "Term doesn't exist." );
        }

        $terms = $this->api->get_term_translations( $term_id );

        $obj_array = array();

        if ( $this->cli->get_flag_value( $assoc_args, 'api' ) ) {

            foreach ( $terms as $slug => $term_id ) {
                $obj = new \stdClass();
                $obj->slug = $slug;
                $obj->term_id = $term_id;
                $obj_array[$term_id] = $obj;
            }

            $formatter = $this->cli->get_formatter( $assoc_args, array( 'slug', 'term_id' ), 'ID' );

        } else {

            foreach ( $terms as $term_id ) {

                $term = get_term_by( 'id', $term_id, $taxonomy );

                if ( empty( $assoc_args['fields'] ) ) {

                    $term_array = get_object_vars( $term );
                    $assoc_args['fields'] = array_keys( $term_array );
                }

                $term->count = (int) $term->count;
                $term->parent = (int) $term->parent;

                $obj_array[$term_id] = $term;
            }

            $formatter = $this->cli->get_formatter( $assoc_args, $this->fields_term, 'term' );
        }

        $formatter->display_items( $obj_array );
    }

    /**
     * Generate some taxonomy terms and their translations.
     *
     * Creates a specified number of sets of new terms and their translations with dummy data.
     *
     * ## OPTIONS
     *
     * <taxonomy>
     * : The taxonomy for the generated terms.
     *
     * [--count=<number>]
     * : How many sets of terms to generate?
     * ---
     * default: 5
     * ---
     *
     * [--max_depth=<number>]
     * : Generate child terms down to a certain depth.
     * ---
     * default: 1
     * ---
     *
     * [--format=<format>]
     * : Render output in a particular format.
     * ---
     * default: table
     * options:
     *   - table
     *   - csv
     *   - json
     *   - yaml
     *   - ids
     * ---
     *
     * ## EXAMPLES
     *
     *     # Generate some post categories, and translations.
     *     $ wp pll term generate category --count=3 --format=ids
     *     115 116 117 118 119 120
     */
    public function generate( $args, $assoc_args ) {

        list ( $taxonomy ) = $args;

        if ( ! $this->api->is_translated_taxonomy( $taxonomy ) ) {
            $this->cli->error( 'Polylang does not manage languages and translations for this taxonomy.' );
        }

        $languages = $this->api->languages_list();

        $count = $this->cli->get_flag_value( $assoc_args, 'count' );
        $count = ( $count < 1 ) ? 1 : absint( $count );
        $count = $count * count( $languages );

        ob_start();

        \WP_CLI::run_command(
            array( 'term', 'generate', $taxonomy ),
            array_merge( $assoc_args, array( 'count' => $count, 'format' => 'ids' ) )
        );

        $ids = ob_get_clean();

        $term_ids = wp_parse_id_list( $ids );

        $terms = array_chunk( $term_ids, count( $languages ) );

        foreach ( $terms as $i => $chunk ) {

            $terms[$i] = array_combine( $languages, $chunk );

{'fraction_non_alphanumeric': 0.14486250143826948, 'fraction_numerical': 0.006213324128408699, 'mean_word_length': 1.6291591046581972, 'pattern_counts': {'":': 0, '<': 25, '<?xml version=': 0, '>': 82, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7519172', 'n_tokens_mistral': 2913, 'n_tokens_neox': 2737, 'n_words': 673}