<commit_before><?php

namespace Neoxygen\Neogen\Processor;

use Neoxygen\Neogen\Exception\SchemaException;

class VertEdgeProcessor
{
    private $labels = [];

    private $nodes = [];

    private $edges = [];

    private $nodesByTypes = [];

    /**
     * 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 SchemaException('You need to define at least one node to generate');
        }

        foreach ($schema['nodes'] as $node) {
            if (!in_array($node['label'], $this->labels)) {
                $this->labels[] = $node['label'];
            }
            $count = isset($node['count']) ? $node['count'] : range(10, 50);
            $x = 1;
            while ($x <= $count) {
                $id = sha1(microtime(true) . rand(0, 100000000000));
                $inode = [];
                $inode['neogen_id'] = $id;
                $inode['label'] = $node['label'];
                $np = isset($node['properties']) ? $node['properties'] : [];
                $inode['properties'] = $np;
                $this->nodes[] = $inode;
                $this->nodesByTypes[$node['label']][] = $id;
                $x++;

            }
        }

        foreach ($schema['relationships'] as $k => $rel) {
            $start = $rel['start'];
            $end = $rel['end'];
            $type = $rel['type'];
            $mode = $rel['mode'];
            $props = isset($rel['properties']) ? $rel['properties'] : null;

            if (!in_array($start, $this->labels) || !in_array($end, $this->labels)) {
                throw new SchemaException(sprintf('The start or end node of relationship "%s" is not defined', $k));
            }

            // Currently only these modes supported
            $allowedModes = array('n..1', '1..n', 'n..n');
            if (!in_array($mode, $allowedModes)) {
                throw new SchemaException(sprintf('The cardinality "%s" for the relationship %s is not suppored', array($mode, $type)));
            }

            switch ($mode) {
                case 'n..1':
                    foreach ($this->nodesByTypes[$start] as $node) {
                        $endNodes = $this->nodesByTypes[$end];
                        shuffle($endNodes);
                        $endNode = current($endNodes);
                        $this->setEdge($node, $endNode, $type, $props, $start, $end);
                    }
                    break;

                case 'n..n':
                    $endNodes = $this->nodesByTypes[$end];
                    $max = count($endNodes);
                    $pct = $max <= 20 ? 0.3 : 0.1;
                    $maxi = round($max * $pct);
                    $random = rand(1, $maxi);
                    foreach ($this->nodesByTypes[$start] as $node) {
                        for ($i = 1; $i <= $random; $i++) {
                            reset($endNodes);
                            shuffle($endNodes);
                            $endNode = current($endNodes);
                            next($endNodes);
                            if ($endNode !== $node) {
                                $this->setEdge($node, $endNode, $type, $props, $start, $end);
                            }

                        }
                    }
                    break;
                case '1..n':
                    foreach ($this->nodesByTypes[$end] as $node) {
                        $endNodes = $this->nodesByTypes[$start];
                        shuffle($endNodes);<commit_msg>increased avg pct of end nodes for n..n edges<commit_after><?php

namespace Neoxygen\Neogen\Processor;

use Neoxygen\Neogen\Exception\SchemaException;

class VertEdgeProcessor
{
    private $labels = [];

    private $nodes = [];

    private $edges = [];

    private $nodesByTypes = [];

    /**
     * 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 SchemaException('You need to define at least one node to generate');
        }

        foreach ($schema['nodes'] as $node) {
            if (!in_array($node['label'], $this->labels)) {
                $this->labels[] = $node['label'];
            }
            $count = isset($node['count']) ? $node['count'] : range(10, 50);
            $x = 1;
            while ($x <= $count) {
                $id = sha1(microtime(true) . rand(0, 100000000000));
                $inode = [];
                $inode['neogen_id'] = $id;
                $inode['label'] = $node['label'];
                $np = isset($node['properties']) ? $node['properties'] : [];
                $inode['properties'] = $np;
                $this->nodes[] = $inode;
                $this->nodesByTypes[$node['label']][] = $id;
                $x++;

            }
        }

        foreach ($schema['relationships'] as $k => $rel) {
            $start = $rel['start'];
            $end = $rel['end'];
            $type = $rel['type'];
            $mode = $rel['mode'];
            $props = isset($rel['properties']) ? $rel['properties'] : null;

            if (!in_array($start, $this->labels) || !in_array($end, $this->labels)) {
                throw new SchemaException(sprintf('The start or end node of relationship "%s" is not defined', $k));
            }

            // Currently only these modes supported
            $allowedModes = array('n..1', '1..n', 'n..n');
            if (!in_array($mode, $allowedModes)) {
                throw new SchemaException(sprintf('The cardinality "%s" for the relationship %s is not suppored', array($mode, $type)));
            }

            switch ($mode) {
                case 'n..1':
                    foreach ($this->nodesByTypes[$start] as $node) {
                        $endNodes = $this->nodesByTypes[$end];
                        shuffle($endNodes);
                        $endNode = current($endNodes);
                        $this->setEdge($node, $endNode, $type, $props, $start, $end);
                    }
                    break;

                case 'n..n':
                    $endNodes = $this->nodesByTypes[$end];
                    $max = count($endNodes);
                    $pct = $max <= 100 ? 0.8 : 0.55;
                    $maxi = round($max * $pct);
                    $random = rand(1, $maxi);
                    foreach ($this->nodesByTypes[$start] as $node) {
                        for ($i = 1; $i <= $random; $i++) {
                            reset($endNodes);
                            shuffle($endNodes);
                            $endNode = current($endNodes);
                            next($endNodes);
                            if ($endNode !== $node) {
                                $this->setEdge($node, $endNode, $type, $props, $start, $end);
                            }

                        }
                    }
                    break;
                case '1..n':
                    foreach ($this->nodesByTypes[$end] as $node) {
                        $endNodes = $this->nodesByTypes[$start];
                        shuffle($endNodes);
{'fraction_non_alphanumeric': 0.1522086216072379, 'fraction_numerical': 0.008515167642362959, 'mean_word_length': 1.3840786552489692, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 33, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 2, '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': '4314724', 'n_tokens_mistral': 2077, 'n_tokens_neox': 1939, 'n_words': 477}