<commit_before><?php

use Everyman\Neo4j\Client;
use Everyman\Neo4j\Cypher\Query;
use App\Models\ProductionClassification;
use Illuminate\Database\Migrations\Migration;

class AddMainTypeToProductionClassifications extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        $neo4j_config = \Config::get('database.connections.neo4j');

        // Create a new client with user and password
        $this->client = new Client($neo4j_config['host'], $neo4j_config['port']);
        $this->client->getTransport()->setAuth($neo4j_config['username'], $neo4j_config['password']);

        $queryString = 'MATCH (n:E17) return n';

        $query = new Query($this->client, $queryString);

        $results = $query->getResultSet();

        foreach ($results as $result) {
            $classificationNode = $result['value'];

            // Check if the node has a connection with a main type
            // if not, add a default main type
            if (! $this->doesClassificationHasMainType($classificationNode->getId())) {
                $productionClassification = new ProductionClassification();
                $productionClassification->setNode($classificationNode);

                $mainTypeNode = $this->makeMainTypeNode($productionClassification->getGeneralId());

                $classificationNode->relateTo($mainTypeNode, 'P2')->save();
            }
        }
    }

    /**
     * Create a productionClassificationMainTypeNode based on a number of relevant labels
     *
     * @param  string $generalId
     * @return Node
     */
    private function makeMainTypeNode(string $generalId)
    {
        $node = $this->client->makeNode();
        $node->setProperty('name', 'productionClassificationMainType');
        $node->save();

        $node->setProperty('value', 'Typologie');
        $node->save();

        // Set the proper labels to the objectDimensionType
        $node->addLabels([$this->makeLabel('E55'), $this->makeLabel('productionClassificationMainType'), $this->makeLabel($generalId)]);

        return $node;
    }

    /**
     * Create and return a label
     *<commit_msg>Small tweak for PHP versions < 5.6<commit_after><?php

use Everyman\Neo4j\Client;
use Everyman\Neo4j\Cypher\Query;
use App\Models\ProductionClassification;
use Illuminate\Database\Migrations\Migration;

class AddMainTypeToProductionClassifications extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        $neo4j_config = \Config::get('database.connections.neo4j');

        // Create a new client with user and password
        $this->client = new Client($neo4j_config['host'], $neo4j_config['port']);
        $this->client->getTransport()->setAuth($neo4j_config['username'], $neo4j_config['password']);

        $queryString = 'MATCH (n:E17) return n';

        $query = new Query($this->client, $queryString);

        $results = $query->getResultSet();

        foreach ($results as $result) {
            $classificationNode = $result['value'];

            // Check if the node has a connection with a main type
            // if not, add a default main type
            if (! $this->doesClassificationHasMainType($classificationNode->getId())) {
                $productionClassification = new ProductionClassification();
                $productionClassification->setNode($classificationNode);

                $mainTypeNode = $this->makeMainTypeNode($productionClassification->getGeneralId());

                $classificationNode->relateTo($mainTypeNode, 'P2')->save();
            }
        }
    }

    /**
     * Create a productionClassificationMainTypeNode based on a number of relevant labels
     *
     * @param  string $generalId
     * @return Node
     */
    private function makeMainTypeNode($generalId)
    {
        $node = $this->client->makeNode();
        $node->setProperty('name', 'productionClassificationMainType');
        $node->save();

        $node->setProperty('value', 'Typologie');
        $node->save();

        // Set the proper labels to the objectDimensionType
        $node->addLabels([$this->makeLabel('E55'), $this->makeLabel('productionClassificationMainType'), $this->makeLabel($generalId)]);

        return $node;
    }

    /**
     * Create and return a label
     *
{'fraction_non_alphanumeric': 0.13232600732600733, 'fraction_numerical': 0.00641025641025641, 'mean_word_length': 2.750214592274678, 'pattern_counts': {'":': 0, '<': 6, '<?xml version=': 0, '>': 49, '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': '1797363', 'n_tokens_mistral': 1215, 'n_tokens_neox': 1170, 'n_words': 256}