<commit_before><?php


/*
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License as published by
 * the Free Software Foundation; either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU Affero General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *
 */

require_once './config.php';

if (isset($argv)) {
	if (array_key_exists(1, $argv) && $argv[1] == "--validate") {
		$p = new Parser();
		if (!(array_key_exists(2, $argv) && get_path($argv[2]))) die("Path not exists.");
		$p->processDir(get_path($argv[2]), null, true);
		echo "\n".report($p)."\n";
	}
	else if (array_key_exists(1, $argv) && $argv[1] == "--export") {
		$p = new Parser();
		if (!(array_key_exists(2, $argv) && get_path($argv[2]))) die("Path not exists.");
		$p->processDir(get_path($argv[2]), null, true);
		echo "\n".report($p)."\n";

		$i = new Injector($p->areas, $p->locations);
		$i->inject();
	}
	else if (array_key_exists(1, $argv) && $argv[1] == "--help") die(help());
}

function report($p) {
	return
		"found areas: ".count($p->areas)."\n".
		"found locations: ".count($p->locations->locations);
}

function get_path($p) {
	if (is_dir($p) && is_dir(__DIR__."/".$p)) return $p;
	else if (is_dir(__DIR__."/".$p)) return __DIR__."/".$p;
	else if (is_dir($p)) return $p;
	else return false;
}

function help() {
	return
	"[ --validate | --export ] path";
}

class Area {
	public $label, $name, $description, $id;

	public function &__construct($label = "", $name = "", $description = "") {
		if (!$this->label) $this->label = $label;
		if (!$this->name) $this->name = $name;
		if (!$this->description) $this->description = $description;
		if (!$this->id) $this->id = abs(crc32($label))/2;
		return $this;
	}
}

class Location {
	public $label, $name, $description = "", $actions, $area, $id;

	public function &__construct($label = "", $name = "", $area = null, $description = "", $actions = "") {
		if (!$this->label) $this->label = $label;
		if (!$this->name) $this->name = $name;
		if (!$this->description) $this->description = $description;
		if (!$this->actions) $this->actions = $actions;
		if (!$this->area) $this->area = $area;
		if (!$this->id) $this->id = abs(crc32($label))/2;
		return $this;
	}
}
<commit_msg>references #107<commit_after><?php


/*
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License as published by
 * the Free Software Foundation; either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU Affero General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *
 */

require_once './config.php';

if (isset($argv)) {
	if (array_key_exists(1, $argv) && $argv[1] == "--validate") {
		$p = new Parser();
		if (!(array_key_exists(2, $argv) && get_path($argv[2]))) die("Path not exists.");
		$p->processDir(get_path($argv[2]), null, true);
		echo "\n".report($p)."\n";
	}
	else if (array_key_exists(1, $argv) && $argv[1] == "--export") {
		$p = new Parser();
		if (!(array_key_exists(2, $argv) && get_path($argv[2]))) die("Path not exists.");
		$p->processDir(get_path($argv[2]), null, true);
		echo "\n".report($p)."\n";

		$i = new Injector($p->areas, $p->locations);
		$i->inject();
	}
	else if (array_key_exists(1, $argv) && $argv[1] == "--help") die(help());
}

function report($p) {
	return
		"found areas: ".count($p->areas)."\n".
		"found locations: ".count($p->locations->locations);
}

function get_path($p) {
	if (is_dir($p) && is_dir(__DIR__."/".$p)) return $p;
	else if (is_dir(__DIR__."/".$p)) return __DIR__."/".$p;
	else if (is_dir($p)) return $p;
	else return false;
}

function help() {
	return
	"[ --validate | --export ] path";
}

class Area {
	public $label, $name, $description, $id;

	public function &__construct($label = "", $name = "", $description = "") {
		if (!$this->label) $this->label = $label;
		if (!$this->name) $this->name = $name;
		if (!$this->description) $this->description = $description;
		if (!$this->id) $this->id = round(abs(crc32($label))/2);
		return $this;
	}
}

class Location {
	public $label, $name, $description = "", $actions, $area, $id;

	public function &__construct($label = "", $name = "", $area = null, $description = "", $actions = "") {
		if (!$this->label) $this->label = $label;
		if (!$this->name) $this->name = $name;
		if (!$this->description) $this->description = $description;
		if (!$this->actions) $this->actions = $actions;
		if (!$this->area) $this->area = $area;
		if (!$this->id) $this->id = round(abs(crc32($label))/2);
		return $this;
	}
}

{'fraction_non_alphanumeric': 0.204803328290469, 'fraction_numerical': 0.007753403933434191, 'mean_word_length': 4.085576923076923, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 61, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '3249026', 'n_tokens_mistral': 1884, 'n_tokens_neox': 1827, 'n_words': 535}