<commit_before><?php

namespace Neoxygen\Neogen\Schema;

use Neoxygen\Neogen\Helper\CypherHelper;
use Faker\Factory;

class Processor
{
    private $labels = [];

    private $faker;

    private $queries = [];

    private $nodes = [];

    private $edges = [];

    private $graphNodes = [];

    private $labelColors = [];

    public function __construct()
    {
        $this->faker = Factory::create();
    }

    /**
     * Generate the queries for the creation of the nodes and relationships based on a schema file
     * It also add constraints for all node labels on the "neogen_id" property
     *
     *
     * @param array $schema
     */
    public function process(array $schema)
    {
        if (!isset($schema['nodes'])) {
            throw new \InvalidArgumentException('You need to define at least one node to generate');
        }
        $helper = new CypherHelper();


        foreach ($schema['nodes'] as $node) {
            if (!in_array($node['label'], $this->labels)) {
                $this->labels[] = $node['label'];
            }
            if (!isset($this->labelColors[$node['label']])) {
                $this->labelColors[$node['label']] = $this->faker->hexcolor;
            }
            $count = isset($node['count']) ? $node['count'] : 1;
            $x = 1;
            while ($x <= $count) {
                $graphNode = [];
                $graphNode['type'] = $node['label'];
                $graphNode['neogen_color'] = $this->faker->rgbCssColor;
                $alias = $alias = str_replace('.', '', 'n' . microtime(true) . rand(0, 100000000000));
                $this->nodes[$node['label']][$alias] = $alias;
                $graphNode['id'] = $alias;
                $q = $helper->openMerge();
                $q .= $helper->addNodeLabel($alias, $node['label']);

                if (isset($node['properties'])) {
                    $c = count($node['properties']);
                    $i = 0;
                    $q .= $helper->openNodePropertiesBracket();
                    if ($c !== 0) {

                        foreach ($node['properties'] as $key => $type) {
                            if (is_array($type)) {
                                $value = call_user_func_array(array($this->faker, $type['type']), $type['params']);
                                if ($value instanceof \DateTime) {
                                    $value = $value->format('Y-m-d H:i:s');
                                }
                            } else {
                                $value = $this->faker->$type;
                            }
                            $q .= $helper->addNodeProperty($key, $value);
                            $graphNode[$key] = $value;
                            if ($i < $c - 1) {
                                $q .= ', ';
                            }
                            $i++;
                        }
                        $q .= ', ' . $helper->addNodeProperty('neogen_id', $alias);
                        $q .= $helper->closeNodePropertiesBracket();
                    }
                }
                $this->graphNodes[] = $graphNode;

<commit_msg>nodes without props do not have id fixed<commit_after><?php

namespace Neoxygen\Neogen\Schema;

use Neoxygen\Neogen\Helper\CypherHelper;
use Faker\Factory;

class Processor
{
    private $labels = [];

    private $faker;

    private $queries = [];

    private $nodes = [];

    private $edges = [];

    private $graphNodes = [];

    private $labelColors = [];

    public function __construct()
    {
        $this->faker = Factory::create();
    }

    /**
     * Generate the queries for the creation of the nodes and relationships based on a schema file
     * It also add constraints for all node labels on the "neogen_id" property
     *
     *
     * @param array $schema
     */
    public function process(array $schema)
    {
        if (!isset($schema['nodes'])) {
            throw new \InvalidArgumentException('You need to define at least one node to generate');
        }
        $helper = new CypherHelper();


        foreach ($schema['nodes'] as $node) {
            if (!in_array($node['label'], $this->labels)) {
                $this->labels[] = $node['label'];
            }
            if (!isset($this->labelColors[$node['label']])) {
                $this->labelColors[$node['label']] = $this->faker->hexcolor;
            }
            $count = isset($node['count']) ? $node['count'] : 1;
            $x = 1;
            while ($x <= $count) {
                $graphNode = [];
                $graphNode['type'] = $node['label'];
                $graphNode['neogen_color'] = $this->faker->rgbCssColor;
                $alias = $alias = str_replace('.', '', 'n' . microtime(true) . rand(0, 100000000000));
                $this->nodes[$node['label']][$alias] = $alias;
                $graphNode['id'] = $alias;
                $q = $helper->openMerge();
                $q .= $helper->addNodeLabel($alias, $node['label']);
                $q .= $helper->openNodePropertiesBracket();

                if (isset($node['properties'])) {
                    $c = count($node['properties']);
                    $i = 0;
                    if ($c !== 0) {

                        foreach ($node['properties'] as $key => $type) {
                            if (is_array($type)) {
                                $value = call_user_func_array(array($this->faker, $type['type']), $type['params']);
                                if ($value instanceof \DateTime) {
                                    $value = $value->format('Y-m-d H:i:s');
                                }
                            } else {
                                $value = $this->faker->$type;
                            }
                            $q .= $helper->addNodeProperty($key, $value);
                            $graphNode[$key] = $value;
                            if ($i < $c - 1) {
                                $q .= ', ';
                            }
                            $i++;
                        }

                    }
                }

                $this->graphNodes[] = $graphNode;

                $q .= ', ' . $helper->addNodeProperty('neogen_id', $alias);
                $q .= $helper->closeNodePropertiesBracket();
{'fraction_non_alphanumeric': 0.1533354410369902, 'fraction_numerical': 0.00569079987353778, 'mean_word_length': 1.3303867403314917, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 47, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 2, 'word_list_counts': {'cursed_substrings.json': 8, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1274862', 'n_tokens_mistral': 1735, 'n_tokens_neox': 1623, 'n_words': 353}