Comparar commits
67 Commits
| Autor | SHA1 | Data | |
|---|---|---|---|
| 6f3cb02964 | |||
| ed35d5e1e0 | |||
| da117f57ef | |||
| e8ce2ebfb4 | |||
| b8159b9c79 | |||
| 7d934c0bc8 | |||
| 3d1329e442 | |||
| b98ee88a3f | |||
| 90987bbc28 | |||
| 9e6d50becb | |||
| 156e6cbd7e | |||
| 73e5d8110b | |||
| a0d96e0824 | |||
| b2296a6f26 | |||
| 058d3aa0f1 | |||
| c038113947 | |||
| 02ac4722b1 | |||
| b66af6da77 | |||
| 6e9179a518 | |||
| a5f806b54a | |||
| c0514d2499 | |||
| 47523ca411 | |||
| 0a80cb904c | |||
| 623eba95f1 | |||
| 4618c35c79 | |||
| a7ff4fd99c | |||
| 2d94cc2e26 | |||
| 77cc6e4631 | |||
| 8517abe185 | |||
| 5f04f28132 | |||
| 1f287d041a | |||
| 54bb7d6201 | |||
| 5b37276a17 | |||
| 3c09f88f4a | |||
| 38512ec204 | |||
| 9b8fbcd90b | |||
| a012e0a41d | |||
| 9b90b2c893 | |||
| a4ba5eb637 | |||
| 010daccdca | |||
| 950b116188 | |||
| bd1ca9b03a | |||
| 2151886f39 | |||
| 6fe620e966 | |||
| 157a655cd4 | |||
| 91b0281b00 | |||
| 2d213e1e4a | |||
| 79fd5762f9 | |||
| 9fb1495599 | |||
| 3ba04ff3a8 | |||
| 9fe39f37e0 | |||
| 9d031fb770 | |||
| b8761c793e | |||
| 72876b0c74 | |||
| 4932ed5b36 | |||
| c3e77b00a4 | |||
| af795101a7 | |||
| a0ae63dbdb | |||
| acf12cead3 | |||
| 143b1a722f | |||
| efc961f804 | |||
| 62b85d379f | |||
| 6de5b1f868 | |||
| 145b0a69de | |||
| f938ae6a0a | |||
| 67460c5e91 | |||
| 0ff1e64bfa |
@@ -3,6 +3,12 @@
|
||||
##
|
||||
mind3rd/projects/*
|
||||
|
||||
##
|
||||
## PHPDocs
|
||||
##
|
||||
docs/PHPDoc/*
|
||||
docs/PHPDOCS/*
|
||||
|
||||
##
|
||||
## SQLite
|
||||
##
|
||||
@@ -16,7 +22,9 @@ mind3rd/API/temp/*
|
||||
##
|
||||
## Development meta files
|
||||
##
|
||||
*~
|
||||
*.*~
|
||||
.project
|
||||
.DS_Store
|
||||
./nbproject
|
||||
nbproject
|
||||
nbproject/*
|
||||
|
||||
@@ -1,40 +0,0 @@
|
||||
Requires:
|
||||
PHP 5.3+
|
||||
PHP-cli
|
||||
PHP-SQLite
|
||||
|
||||
Installation
|
||||
**For now, only working on mac and Linux...sorry bill!**
|
||||
Your HTTPServer's user must have permission to read and write on its folder
|
||||
In your console, run the following command into this directory:
|
||||
$sudo php mind install
|
||||
|
||||
Great! Now you're good to go
|
||||
|
||||
To perform some examples and tests, access in your browser
|
||||
the IDE demo
|
||||
http://[yourMindDir]/docs/ide
|
||||
|
||||
For graphics, diagrams, examples of code, help and documentation, see
|
||||
the docs directory
|
||||
[yourMindDir]/docs/
|
||||
|
||||
Your projects are stored at:
|
||||
[yourMindDir]/projects/[projectName]
|
||||
You can write your codes directly in sources/main.mnd in your
|
||||
project's source directory
|
||||
You can see the generated documentation and source code on 'docs' and
|
||||
'app' directories, into the project's directory
|
||||
|
||||
Please, check/change the data and options as you need, on
|
||||
[yourMindDir]/env/defaults.ini
|
||||
|
||||
Unit tests are on Tests directory, run it with PHPUnit
|
||||
[yourMindDir]/Tests
|
||||
|
||||
Useful/interesting links:
|
||||
http://thewebmind.org
|
||||
http://docs.thewebmind.org
|
||||
contact@thewebmind.org
|
||||
http://twitter.com/thewebmind
|
||||
http://twitter.com/felipenmoura
|
||||
@@ -0,0 +1,51 @@
|
||||
TheWebMind
|
||||
===============================================
|
||||
This is the source code for theWebMind project.
|
||||
|
||||
Requirements:
|
||||
---------
|
||||
* PHP 5.3+
|
||||
* PHP-cli
|
||||
* PHP-SQLite
|
||||
|
||||
Installation:
|
||||
-------------
|
||||
For now, only working on mac and Linux...sorry bill!
|
||||
Your HTTPServer's user must have permission to read and write on its folder
|
||||
In your console, run the following command into this directory:
|
||||
$sudo php mind install
|
||||
|
||||
Great! Now you're good to go
|
||||
|
||||
* * *
|
||||
|
||||
Examples and tests:
|
||||
-------------
|
||||
To perform some examples and tests, access in your browser
|
||||
the IDE demo
|
||||
http://[yourMindDir]/docs/ide
|
||||
|
||||
For graphics, diagrams, examples of code, help and documentation, see
|
||||
the docs directory
|
||||
[yourMindDir]/docs/
|
||||
|
||||
Your projects are stored at:
|
||||
[yourMindDir]/projects/[projectName]
|
||||
You can write your codes directly in sources/main.mnd in your
|
||||
project's source directory.
|
||||
You can see the generated documentation and source code on 'docs' and
|
||||
'app' directories, into the project's directory.
|
||||
|
||||
Please, check/change the data and options as you need, on
|
||||
[yourMindDir]/env/defaults.ini
|
||||
|
||||
Unit tests are on Tests directory, run it with PHPUnit
|
||||
[yourMindDir]/Tests
|
||||
|
||||
Useful/interesting links:
|
||||
[Official website](http://thewebmind.org "theWebMind") |
|
||||
[Licenses](https://github.com/felipenmoura/theWebMind/blob/master/licenses/mind3rd.license, "Licenses") |
|
||||
[Documentation](http://docs.thewebmind.org "documentation") |
|
||||
[Contact](mailto:contact@thewebmind.org "contact") |
|
||||
[Twitter](http://twitter.com/thewebmind "twitter") |
|
||||
[Contribute](http://thewebmind.org/contribute "Contribute")
|
||||
@@ -0,0 +1,6 @@
|
||||
mind3rd/API/languages/en/IgnoreFormsTest.php en\IgnoreFormsTest
|
||||
mind3rd/API/languages/en/InflectTest.php en\InflectTest
|
||||
mind3rd/API/languages/en/VerbalizerTest.php en\VerbalizerTest
|
||||
mind3rd/API/languages/pt/IgnoreFormsTest.php pt\IgnoreFormsTest
|
||||
mind3rd/API/languages/pt/InflectTest.php pt\InflectTest
|
||||
mind3rd/API/languages/pt/VerbalizerTest.php pt\VerbalizerTest
|
||||
@@ -0,0 +1,43 @@
|
||||
<?php
|
||||
require_once dirname(__FILE__) . '/../mind3rd/API/classes/Mind.php';
|
||||
require_once dirname(__FILE__) . '/../mind3rd/API/classes/MindSpeaker.php';
|
||||
require_once dirname(__FILE__) . '/../mind3rd/API/cortex/Darwin/Darwin.php';
|
||||
require_once dirname(__FILE__) . '/../mind3rd/API/cortex/Lexer/Lexer.php';
|
||||
require_once dirname(__FILE__) . '/../mind3rd/API/cortex/canonic/Canonic.php';
|
||||
require_once dirname(__FILE__) . '/../mind3rd/API/cortex/syntaxer/Syntaxer.php';
|
||||
|
||||
require_once dirname(__FILE__) . '/../mind3rd/API/classes/MindEntity.php';
|
||||
require_once dirname(__FILE__) . '/../mind3rd/API/utils/constants.php';
|
||||
require_once dirname(__FILE__) . '/../mind3rd/API/classes/VersionManager.php';
|
||||
require_once dirname(__FILE__) . '/../mind3rd/API/classes/MindProject.php';
|
||||
require_once dirname(__FILE__) . '/../mind3rd/API/classes/MindRelation.php';
|
||||
require_once dirname(__FILE__) . '/../mind3rd/API/classes/MindEntity.php';
|
||||
require_once dirname(__FILE__) . '/../mind3rd/API/classes/MindProperty.php';
|
||||
|
||||
require_once dirname(__FILE__) . '/../mind3rd/API/cortex/analyst/Normal.php';
|
||||
require_once dirname(__FILE__) . '/../mind3rd/API/cortex/analyst/Analysis.php';
|
||||
require_once dirname(__FILE__) . '/../mind3rd/API/cortex/analyst/Normalizer.php';
|
||||
require_once dirname(__FILE__) . '/../mind3rd/API/cortex/analyst/Analyst.php';
|
||||
require_once dirname(__FILE__) . '/../mind3rd/API/cortex/tokenizer/Token.php';
|
||||
require_once dirname(__FILE__) . '/../mind3rd/API/cortex/tokenizer/Tokenizer.php';
|
||||
|
||||
if(!class_exists('MindForUnitTest'))
|
||||
{
|
||||
class MindForUnitTest
|
||||
{
|
||||
public function __construct()
|
||||
{
|
||||
$this->defaults= Array(
|
||||
'pk_prefix'=>'pk_',
|
||||
'fk_prefix'=>'fk_'
|
||||
);
|
||||
}
|
||||
}
|
||||
$_MIND= new MindForUnitTest();
|
||||
}
|
||||
|
||||
/*if(!defined('_MINDSRC_'))
|
||||
define('_MINDSRC_', dirname(__FILE__).'/..');
|
||||
if(!defined('_CONSOLE_LINE_LENGTH_'))
|
||||
define('_CONSOLE_LINE_LENGTH_', 80);
|
||||
$_MIND= new Mind();*/
|
||||
@@ -0,0 +1,181 @@
|
||||
<?php
|
||||
require(dirname(__FILE__) . '/../../../../../Tests/config.php');
|
||||
|
||||
/**
|
||||
* Test class for Analyst.
|
||||
* Generated by PHPUnit on 2011-02-21 at 01:40:36.
|
||||
*/
|
||||
class AnalystPtTest extends PHPUnit_Framework_TestCase {
|
||||
|
||||
/**
|
||||
* @var Analyst
|
||||
*/
|
||||
protected $object;
|
||||
|
||||
/**
|
||||
* Sets up the fixture, for example, opens a network connection.
|
||||
* This method is called before a test is executed.
|
||||
*/
|
||||
protected function setUp() {
|
||||
// you gotta set the idiom simply to start some required variables
|
||||
// once these tests wont use the idiom as a key subject
|
||||
MindProject::loadIdiom('en');
|
||||
Mind::$langPath= dirname(__FILE__) . '/../../../../../mind3rd/API/languages/en/';
|
||||
Mind::$lexer= new Lexer();
|
||||
$this->object = new Analyst;
|
||||
}
|
||||
|
||||
/**
|
||||
* Tears down the fixture, for example, closes a network connection.
|
||||
* This method is called afhas a test is executed.
|
||||
*/
|
||||
protected function tearDown() {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* the used words doesn't metter here, the main spine is the keys group,
|
||||
* so, it doesn't metter what language is set
|
||||
*/
|
||||
public function testAnalize1() {
|
||||
$this->assertEquals($this->object->analize(
|
||||
Array
|
||||
('teacher', '', 'has', '', '', '', 'student'),
|
||||
'SQVNONS',
|
||||
Array
|
||||
(2, 128, 1, 8, 16, 32, 2)),
|
||||
Array('min'=>1,
|
||||
'max'=>'n',
|
||||
'linkType'=>'possibility',
|
||||
'linkVerb'=>'has',
|
||||
'rel'=>'student',
|
||||
'focus'=>'teacher'));
|
||||
}
|
||||
public function testAnalize2() {
|
||||
$this->assertEquals($this->object->analize(
|
||||
Array
|
||||
('teacher', '', 'has', '', '', '', 'student'),
|
||||
'SQVNONS',
|
||||
Array
|
||||
(2, 64, 1, 8, 16, 32, 2)),
|
||||
Array('min'=>1,
|
||||
'max'=>'n',
|
||||
'linkType'=>'must',
|
||||
'linkVerb'=>'has',
|
||||
'rel'=>'student',
|
||||
'focus'=>'teacher'));
|
||||
}
|
||||
public function testAnalize3() {
|
||||
$this->assertEquals($this->object->analize(
|
||||
Array
|
||||
('teacher', '', 'have', '', '', '', 'student'),
|
||||
'SQVNONS',
|
||||
Array
|
||||
(2, 128, 1, 4, 16, 8, 2)),
|
||||
Array('min'=>0,
|
||||
'max'=>1,
|
||||
'linkType'=>'possibility',
|
||||
'linkVerb'=>'have',
|
||||
'rel'=>'student',
|
||||
'focus'=>'teacher'));
|
||||
}
|
||||
public function testAnalize4() {
|
||||
$this->assertEquals($this->object->analize(
|
||||
Array
|
||||
('teacher', 'have', '', '', '', 'student'),
|
||||
'SQVNONS',
|
||||
Array
|
||||
(2, 1, 4, 16, 8, 2)),
|
||||
Array('min'=>0,
|
||||
'max'=>1,
|
||||
'linkType'=>'action',
|
||||
'linkVerb'=>'have',
|
||||
'rel'=>'student',
|
||||
'focus'=>'teacher'));
|
||||
}
|
||||
public function testAnalize5() {
|
||||
$this->assertEquals($this->object->analize(
|
||||
Array
|
||||
('teacher', 'has', '', '', '', 'student'),
|
||||
'SQVNONS',
|
||||
Array
|
||||
(2, 1, 8, 16, 32, 2)),
|
||||
Array('min'=>1,
|
||||
'max'=>'n',
|
||||
'linkType'=>'action',
|
||||
'linkVerb'=>'has',
|
||||
'rel'=>'student',
|
||||
'focus'=>'teacher'));
|
||||
}
|
||||
public function testAnalize6() {
|
||||
$this->assertEquals($this->object->analize(
|
||||
Array
|
||||
('teachera', 'has', '', '', '', 'aluna'),
|
||||
'SQVNONS',
|
||||
Array
|
||||
(2, 1, 4, 16, 32, 2)),
|
||||
Array('min'=>0,
|
||||
'max'=>'n',
|
||||
'linkType'=>'action',
|
||||
'linkVerb'=>'has',
|
||||
'rel'=>'aluna',
|
||||
'focus'=>'teachera'));
|
||||
}
|
||||
public function testAnalize7() {
|
||||
$this->assertEquals($this->object->analize(
|
||||
Array
|
||||
('teacher', 'has', '', 'student'),
|
||||
'SQVNONS',
|
||||
Array
|
||||
(2, 1, 32, 2)),
|
||||
Array('min'=>0,
|
||||
'max'=>'n',
|
||||
'linkType'=>'action',
|
||||
'linkVerb'=>'has',
|
||||
'rel'=>'student',
|
||||
'focus'=>'teacher'));
|
||||
}
|
||||
public function testAnalize8() {
|
||||
$this->assertEquals($this->object->analize(
|
||||
Array
|
||||
('teacher', 'has', '', 'student'),
|
||||
'SQVNONS',
|
||||
Array
|
||||
(2, 1, 8, 2)),
|
||||
Array('min'=>0,
|
||||
'max'=>1,
|
||||
'linkType'=>'action',
|
||||
'linkVerb'=>'has',
|
||||
'rel'=>'student',
|
||||
'focus'=>'teacher'));
|
||||
}
|
||||
public function testAnalize9() {
|
||||
$this->assertEquals($this->object->analize(
|
||||
Array
|
||||
('teacher', '', 'has', '', 'student'),
|
||||
'SQVNONS',
|
||||
Array
|
||||
(2, 64, 1, 8, 2)),
|
||||
Array('min'=>1,
|
||||
'max'=>1,
|
||||
'linkType'=>'must',
|
||||
'linkVerb'=>'has',
|
||||
'rel'=>'student',
|
||||
'focus'=>'teacher'));
|
||||
}
|
||||
public function testAnalize10() {
|
||||
$this->assertEquals($this->object->analize(
|
||||
Array
|
||||
('teacher', '', 'has', '', 'student'),
|
||||
'SQVNONS',
|
||||
Array
|
||||
(2, 128, 1, 32, 2)),
|
||||
Array('min'=>0,
|
||||
'max'=>'n',
|
||||
'linkType'=>'possibility',
|
||||
'linkVerb'=>'has',
|
||||
'rel'=>'student',
|
||||
'focus'=>'teacher'));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,220 @@
|
||||
<?php
|
||||
|
||||
require_once dirname(__FILE__) . '/../../../../../Tests/config.php';
|
||||
|
||||
/**
|
||||
* Test class for Syntaxer.
|
||||
* Generated by PHPUnit on 2011-02-25 at 09:21:58.
|
||||
*/
|
||||
class SyntaxerTest extends PHPUnit_Framework_TestCase {
|
||||
|
||||
/**
|
||||
* @var Syntaxer
|
||||
*/
|
||||
public $object;
|
||||
|
||||
/**
|
||||
* Sets up the fixture, for example, opens a network connection.
|
||||
* This method is called before a test is executed.
|
||||
*/
|
||||
protected function setUp() {
|
||||
$this->setIdiom();
|
||||
}
|
||||
|
||||
/**
|
||||
* Tears down the fixture, for example, closes a network connection.
|
||||
* This method is called after a test is executed.
|
||||
*/
|
||||
protected function tearDown() {
|
||||
}
|
||||
|
||||
public function setIdiom($idiom='en')
|
||||
{
|
||||
Mind::$currentProject['idiom']= $idiom;
|
||||
Mind::$langPath= dirname(__FILE__) . '/../../../../../mind3rd/API/languages/';
|
||||
require_once dirname(__FILE__) . '/../../../../../mind3rd/API/languages/'.$idiom.'/IgnoreForms.php';
|
||||
require_once dirname(__FILE__) . '/../../../../../mind3rd/API/languages/'.$idiom.'/Verbalizer.php';
|
||||
Tokenizer::loadModifiers(dirname(__FILE__) . '/../../../../../mind3rd/API/languages/'.$idiom.'/');
|
||||
Mind::$tokenizer= new Tokenizer;
|
||||
Mind::$lexer= new Lexer;
|
||||
$this->object = new Syntaxer();
|
||||
}
|
||||
|
||||
public function testSweepWords1() {
|
||||
$this->setIdiom();
|
||||
Mind::$tokenizer->sweep(Array('child', 'of', 'heart', 'has', 'parent', 'of', 'family'));
|
||||
|
||||
$this->object->sweep();
|
||||
|
||||
$this->assertEquals(Tokenizer::$words,
|
||||
Array(
|
||||
'child_heart',
|
||||
'has',
|
||||
'parent_family',
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
public function testSweepWords2() {
|
||||
Mind::$tokenizer->sweep(Array('child',
|
||||
'of',
|
||||
'heart',
|
||||
'and',
|
||||
'friend',
|
||||
'of',
|
||||
'child',
|
||||
'of',
|
||||
'heart',
|
||||
'has',
|
||||
'parent',
|
||||
'of',
|
||||
'family'));
|
||||
$this->object->sweep();
|
||||
$this->assertEquals(Tokenizer::$words,
|
||||
Array(
|
||||
'child_heart',
|
||||
',',
|
||||
'friend_child_heart',
|
||||
'has',
|
||||
'parent_family'
|
||||
)
|
||||
);
|
||||
}
|
||||
public function testSweepWords3() {
|
||||
Mind::$tokenizer->sweep(Array('child',
|
||||
'of',
|
||||
'heart',
|
||||
',',
|
||||
'friend',
|
||||
'of',
|
||||
'kid',
|
||||
'of',
|
||||
'heart',
|
||||
'has',
|
||||
'parent',
|
||||
'of',
|
||||
'family'));
|
||||
$this->object->sweep();
|
||||
$this->assertEquals(Tokenizer::$words,
|
||||
Array(
|
||||
'child_heart',
|
||||
',',
|
||||
'friend_kid_heart',
|
||||
'has',
|
||||
'parent_family'
|
||||
)
|
||||
);
|
||||
}
|
||||
public function testSweepWords4() {
|
||||
Mind::$tokenizer->sweep(Array('child',
|
||||
'of',
|
||||
'heart',
|
||||
',',
|
||||
'friend',
|
||||
'of',
|
||||
'kid',
|
||||
'of',
|
||||
'heart',
|
||||
'has',
|
||||
'parent',
|
||||
'of',
|
||||
'family',
|
||||
',',
|
||||
'mother',
|
||||
'of',
|
||||
'parent'));
|
||||
$this->object->sweep();
|
||||
$this->assertEquals(Tokenizer::$words,
|
||||
Array(
|
||||
'child_heart',
|
||||
',',
|
||||
'friend_kid_heart',
|
||||
'has',
|
||||
'parent_family',
|
||||
',',
|
||||
'mother_parent'
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
public function testSweepWords5() {
|
||||
Mind::$tokenizer->sweep(Array('child',
|
||||
'has',
|
||||
'parent'
|
||||
));
|
||||
$this->object->sweep();
|
||||
$this->assertEquals(Tokenizer::$words,
|
||||
Array(
|
||||
'child',
|
||||
'has',
|
||||
'parent'
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
public function testSweepWords6() {
|
||||
Mind::$tokenizer->sweep(Array('child',
|
||||
'of',
|
||||
'heart',
|
||||
',',
|
||||
'friend',
|
||||
'of',
|
||||
'kid',
|
||||
'of',
|
||||
'heart',
|
||||
'has',
|
||||
'name of origin:varchar(250)',
|
||||
',',
|
||||
'age:int'));
|
||||
$this->object->sweep();
|
||||
$this->assertEquals(Tokenizer::$words,
|
||||
Array(
|
||||
'child_heart',
|
||||
',',
|
||||
'friend_kid_heart',
|
||||
'has',
|
||||
'name of origin:varchar(250)',
|
||||
',',
|
||||
'age:int'
|
||||
)
|
||||
);
|
||||
}
|
||||
public function testSweepWords7() {
|
||||
Mind::$tokenizer->sweep(Array('child',
|
||||
',',
|
||||
'friend',
|
||||
'has',
|
||||
'name of origin:varchar(250)',
|
||||
',',
|
||||
'age:int'));
|
||||
$this->object->sweep();
|
||||
$this->assertEquals(Tokenizer::$words,
|
||||
Array(
|
||||
'child',
|
||||
',',
|
||||
'friend',
|
||||
'has',
|
||||
'name of origin:varchar(250)',
|
||||
',',
|
||||
'age:int'
|
||||
)
|
||||
);
|
||||
}
|
||||
public function testSweepWords8() {
|
||||
Mind::$tokenizer->sweep(Array('child',
|
||||
'has',
|
||||
'name of origin:varchar(250)',
|
||||
',',
|
||||
'age:int'));
|
||||
$this->object->sweep();
|
||||
$this->assertEquals(Tokenizer::$words,
|
||||
Array(
|
||||
'child',
|
||||
'has',
|
||||
'name of origin:varchar(250)',
|
||||
',',
|
||||
'age:int'
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,103 @@
|
||||
<?php
|
||||
require(dirname(__FILE__) . '/../../../../../Tests/config.php');
|
||||
|
||||
/**
|
||||
* Test class for Tokenizer.
|
||||
* Generated by PHPUnit on 2011-02-21 at 11:46:35.
|
||||
*/
|
||||
class TokenizerTest extends PHPUnit_Framework_TestCase {
|
||||
|
||||
/**
|
||||
* @var Tokenizer
|
||||
*/
|
||||
protected $object;
|
||||
|
||||
protected $idiom= 'en';
|
||||
|
||||
|
||||
/**
|
||||
* Sets up the fixture, for example, opens a network connection.
|
||||
* This method is called before a test is executed.
|
||||
*/
|
||||
protected function setUp() {
|
||||
$this->setIdiom();
|
||||
}
|
||||
|
||||
public function setIdiom($idiom='en')
|
||||
{
|
||||
Mind::$currentProject['idiom']= $idiom;
|
||||
Mind::$langPath= dirname(__FILE__) . '/../../../../../mind3rd/API/languages/';
|
||||
require_once dirname(__FILE__) . '/../../../../../mind3rd/API/languages/'.$idiom.'/IgnoreForms.php';
|
||||
require_once dirname(__FILE__) . '/../../../../../mind3rd/API/languages/'.$idiom.'/Verbalizer.php';
|
||||
Tokenizer::loadModifiers(dirname(__FILE__) . '/../../../../../mind3rd/API/languages/'.$idiom.'/');
|
||||
$this->object = new Tokenizer;
|
||||
}
|
||||
|
||||
/**
|
||||
* Tears down the fixture, for example, closes a network connection.
|
||||
* This method is called after a test is executed.
|
||||
*/
|
||||
protected function tearDown() {
|
||||
|
||||
}
|
||||
|
||||
// these are the tests in Portuguese, that's why we're setting
|
||||
// the idiom to PT in the first line on each test
|
||||
public function testSweep1() {
|
||||
$this->setIdiom('pt');
|
||||
$ar= Array('cada','professor','dever', 'ter', 'um','ou','muitos','aluno','.');
|
||||
$exp= Array(-4, 2, 64, 1, 8, 16, 32, 2, -2);
|
||||
$this->assertEquals($this->object->sweep($ar), $exp);
|
||||
}
|
||||
public function testSweep2() {
|
||||
$this->setIdiom('pt');
|
||||
$ar= Array('professor', 'ter', 'um','aluno','.');
|
||||
$exp= Array(2, 1, 8, 2, -2);
|
||||
$this->assertEquals($this->object->sweep($ar), $exp);
|
||||
}
|
||||
public function testSweep3() {
|
||||
$this->setIdiom('pt');
|
||||
$ar= Array('professor', 'poder', 'ter', 'um','aluno','.');
|
||||
$exp= Array(2, 128, 1, 8, 2, -2);
|
||||
$this->assertEquals($exp, $this->object->sweep($ar));
|
||||
}
|
||||
public function testSweep4() {
|
||||
$this->setIdiom('pt');
|
||||
$ar= Array('professor', 'poder', 'ter', 'um', 'ou', 'muitos','aluno','.');
|
||||
$exp= Array(2, Token::MT_QMAY, 1, 8, Token::MT_OR, Token::MT_MANY, 2, -2);
|
||||
$this->assertEquals($this->object->sweep($ar), $exp);
|
||||
}
|
||||
public function testSweep5() {
|
||||
$this->setIdiom('pt');
|
||||
$ar= Array('cada','professor','dever', 'ter', 'muitos','aluno','.');
|
||||
$exp= Array(-4, 2, 64, 1, 32, 2, -2);
|
||||
$this->assertEquals($this->object->sweep($ar), $exp);
|
||||
}
|
||||
|
||||
// here are the tests in english
|
||||
public function testSweep6() {
|
||||
$ar= Array('each','teacher','must', 'have', 'one','or','many','student','.');
|
||||
$exp= Array(-4, 2, 64, 1, 8, 16, 32, 2, -2);
|
||||
$this->assertEquals($this->object->sweep($ar), $exp);
|
||||
}
|
||||
public function testSweep7() {
|
||||
$ar= Array('teacher', 'have', 'one','student','.');
|
||||
$exp= Array(2, 1, 8, 2, -2);
|
||||
$this->assertEquals($this->object->sweep($ar), $exp);
|
||||
}
|
||||
public function testSweep8() {
|
||||
$ar= Array('teacher', 'may', 'have', 'one','student','.');
|
||||
$exp= Array(2, Token::MT_QMAY, 1, 8, 2, -2);
|
||||
$this->assertEquals($this->object->sweep($ar), $exp);
|
||||
}
|
||||
public function testSweep9() {
|
||||
$ar= Array('teacher', 'must', 'have', 'one','student','.');
|
||||
$exp= Array(2, Token::MT_QMUST, 1, 8, 2, -2);
|
||||
$this->assertEquals($this->object->sweep($ar), $exp);
|
||||
}
|
||||
public function testSweep10() {
|
||||
$ar= Array('each','teacher','may', 'have', 'one','or','many','student','.');
|
||||
$exp= Array(-4, 2, Token::MT_QMAY, 1, 8, 16, 32, 2, -2);
|
||||
$this->assertEquals($this->object->sweep($ar), $exp);
|
||||
}
|
||||
}
|
||||
@@ -5,4 +5,6 @@ which
|
||||
whom
|
||||
whose
|
||||
well
|
||||
too
|
||||
too
|
||||
another
|
||||
also
|
||||
@@ -0,0 +1,6 @@
|
||||
SVS
|
||||
SQVS
|
||||
SVNONS
|
||||
SVNS
|
||||
SQVNONS
|
||||
SQVNS
|
||||
@@ -30,6 +30,11 @@ class VerbalizerTest extends PHPUnit_Framework_TestCase {
|
||||
|
||||
}
|
||||
|
||||
/* NOTE: we wont be testing any first person verb flection
|
||||
* because such rules are commented on the main class as
|
||||
* mind3rd wont treat such sentences
|
||||
*/
|
||||
|
||||
public function testIsVerb() {
|
||||
$this->assertTrue(pt\Verbalizer::isVerb('correr'));
|
||||
}
|
||||
@@ -46,40 +51,40 @@ class VerbalizerTest extends PHPUnit_Framework_TestCase {
|
||||
$this->assertTrue(pt\Verbalizer::isVerb('apresentar'));
|
||||
}
|
||||
public function testIsVerb5() {
|
||||
$this->assertTrue(pt\Verbalizer::isVerb('coloco'));
|
||||
$this->assertTrue(pt\Verbalizer::isVerb('sobrescreve'));
|
||||
}
|
||||
public function testIsVerb6() {
|
||||
$this->assertTrue(pt\Verbalizer::isVerb('lemos'));
|
||||
$this->assertTrue(pt\Verbalizer::isVerb('lerão'));
|
||||
}
|
||||
public function testIsVerb7() {
|
||||
$this->assertTrue(pt\Verbalizer::isVerb('correremos'));
|
||||
$this->assertTrue(pt\Verbalizer::isVerb('correm'));
|
||||
}
|
||||
public function testIsVerb8() {
|
||||
$this->assertTrue(pt\Verbalizer::isVerb('ministrarão'));
|
||||
}
|
||||
public function testIsVerb9() {
|
||||
$this->assertTrue(pt\Verbalizer::isVerb('tomamos'));
|
||||
$this->assertTrue(pt\Verbalizer::isVerb('tomarão'));
|
||||
}
|
||||
public function testIsVerb10() {
|
||||
$this->assertTrue(pt\Verbalizer::isVerb('comemos'));
|
||||
$this->assertTrue(pt\Verbalizer::isVerb('comerá'));
|
||||
}
|
||||
public function testIsVerb11() {
|
||||
$this->assertTrue(pt\Verbalizer::isVerb('beberemos'));
|
||||
$this->assertTrue(pt\Verbalizer::isVerb('bebe'));
|
||||
}
|
||||
public function testIsVerb12() {
|
||||
$this->assertTrue(pt\Verbalizer::isVerb('tomo'));
|
||||
}
|
||||
public function testIsVerb13() {
|
||||
$this->assertTrue(pt\Verbalizer::isVerb('como'));
|
||||
}
|
||||
public function testIsVerb14() {
|
||||
$this->assertTrue(pt\Verbalizer::isVerb('toma'));
|
||||
}
|
||||
public function testIsVerb13() {
|
||||
$this->assertTrue(pt\Verbalizer::isVerb('come'));
|
||||
}
|
||||
public function testIsVerb14() {
|
||||
$this->assertTrue(pt\Verbalizer::isVerb('tomará'));
|
||||
}
|
||||
public function testIsVerb15() {
|
||||
$this->assertTrue(pt\Verbalizer::isVerb('coma'));
|
||||
$this->assertTrue(pt\Verbalizer::isVerb('comerá'));
|
||||
}
|
||||
public function testIsVerb17() {
|
||||
$this->assertTrue(pt\Verbalizer::isVerb('levantaremos'));
|
||||
$this->assertTrue(pt\Verbalizer::isVerb('levantar'));
|
||||
}
|
||||
public function testIsVerb18() {
|
||||
$this->assertFalse(pt\Verbalizer::isVerb('abajur'));
|
||||
@@ -94,22 +99,22 @@ class VerbalizerTest extends PHPUnit_Framework_TestCase {
|
||||
$this->assertTrue(pt\Verbalizer::isVerb('falhar'));
|
||||
}
|
||||
public function testIsVerb22() {
|
||||
$this->assertTrue(pt\Verbalizer::isVerb('falhei'));
|
||||
$this->assertTrue(pt\Verbalizer::isVerb('falharão'));
|
||||
}
|
||||
public function testIsVerb23() {
|
||||
$this->assertTrue(pt\Verbalizer::isVerb('falharei'));
|
||||
$this->assertTrue(pt\Verbalizer::isVerb('falhar'));
|
||||
}
|
||||
public function testIsVerb24() {
|
||||
$this->assertTrue(pt\Verbalizer::isVerb('falhou'));
|
||||
}
|
||||
public function testIsVerb25() {
|
||||
$this->assertTrue(pt\Verbalizer::isVerb('falhamos'));
|
||||
$this->assertTrue(pt\Verbalizer::isVerb('comenta'));
|
||||
}
|
||||
public function testIsVerb26() {
|
||||
$this->assertTrue(pt\Verbalizer::isVerb('falharei'));
|
||||
$this->assertTrue(pt\Verbalizer::isVerb('comentará'));
|
||||
}
|
||||
public function testIsVerb27() {
|
||||
$this->assertTrue(pt\Verbalizer::isVerb('falharemos'));
|
||||
$this->assertTrue(pt\Verbalizer::isVerb('comentarão'));
|
||||
}
|
||||
public function testIsVerb28() {
|
||||
$this->assertTrue(pt\Verbalizer::isVerb('correu'));
|
||||
@@ -170,9 +175,6 @@ class VerbalizerTest extends PHPUnit_Framework_TestCase {
|
||||
$this->assertEquals('poder', pt\Verbalizer::toInfinitive('pode'));
|
||||
}
|
||||
|
||||
public function testLoadVerbs() {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
||||
|
||||
@@ -1,4 +1,11 @@
|
||||
de
|
||||
a
|
||||
o
|
||||
as
|
||||
os
|
||||
aos
|
||||
que
|
||||
da
|
||||
do
|
||||
bem
|
||||
também
|
||||
tanto
|
||||
todo
|
||||
cada
|
||||
@@ -0,0 +1,6 @@
|
||||
SVS
|
||||
SQVS
|
||||
SVNONS
|
||||
SVNS
|
||||
SQVNONS
|
||||
SQVNS
|
||||
|
Antes Largura: | Altura: | Tamanho: 144 KiB Depois Largura: | Altura: | Tamanho: 144 KiB |
|
Antes Largura: | Altura: | Tamanho: 34 KiB Depois Largura: | Altura: | Tamanho: 34 KiB |
|
Antes Largura: | Altura: | Tamanho: 22 KiB Depois Largura: | Altura: | Tamanho: 22 KiB |
|
Antes Largura: | Altura: | Tamanho: 133 KiB Depois Largura: | Altura: | Tamanho: 133 KiB |
|
Antes Largura: | Altura: | Tamanho: 159 KiB Depois Largura: | Altura: | Tamanho: 159 KiB |
|
Antes Largura: | Altura: | Tamanho: 106 KiB Depois Largura: | Altura: | Tamanho: 106 KiB |
|
Antes Largura: | Altura: | Tamanho: 36 KiB Depois Largura: | Altura: | Tamanho: 36 KiB |
|
Antes Largura: | Altura: | Tamanho: 40 KiB Depois Largura: | Altura: | Tamanho: 40 KiB |
|
Antes Largura: | Altura: | Tamanho: 204 KiB Depois Largura: | Altura: | Tamanho: 204 KiB |
@@ -0,0 +1,35 @@
|
||||
{
|
||||
define a mais e a menos relevantes()
|
||||
ter maior relevancia, 3pt
|
||||
pega demais pontuações(entidade)
|
||||
|
||||
pega demais pontuações(entidade)
|
||||
se a entidade tiver poucos campos, 1pt
|
||||
se a entidade tiver apenas campos pequenos, 1pt
|
||||
se a menos da metade dos campos da entidade for not null, 1pt
|
||||
retorna a pontuação adiquirida
|
||||
|
||||
vale a pena mesclar?()
|
||||
pega demais pontuações(menos relevante)
|
||||
vale a pena se tiver atingido 3 pontos
|
||||
|
||||
corrige entidades()
|
||||
exclui relação entre menos relevante e mais relevante
|
||||
adiciona chave da mais relevante na menos relevante como fk E pk para que sejam unicas
|
||||
|
||||
mescla entidades()
|
||||
coloca todas as propriedades da entidade mais fraca, na mais forte
|
||||
altera todas as relações entre a tabela mais fraca e demais tabelas, para que apontem para a mais forte
|
||||
}
|
||||
|
||||
define a mais e a menos relevantes()
|
||||
|
||||
se for 1:1 / 1:1
|
||||
mescla entidades()
|
||||
se 0:1 / 0:1
|
||||
se vale a pena mesclar
|
||||
mescla entidades()
|
||||
senao
|
||||
corrige entidades()
|
||||
Se 0:1 / 1:1
|
||||
corrige entidades()
|
||||
|
Depois Largura: | Altura: | Tamanho: 1.2 KiB |
@@ -1,7 +1,5 @@
|
||||
<script src='scripts/jquery.js'></script>
|
||||
<body>
|
||||
<div id='result' style='white-space:pre;'></div>
|
||||
<br/>
|
||||
<input type='button' value='autenticate' onclick="autenticate()"/>
|
||||
<input type='button' value='run test' onclick="runTest()"/>
|
||||
<input type='button' value='run info' onclick="runInfo()"/>
|
||||
@@ -10,12 +8,19 @@
|
||||
<input type='button' value='analyze project x' onclick="analyzeX()"/>
|
||||
<input type='button' value='analyze project y' onclick="analyzeY()"/>
|
||||
<input type='button' value='logoff' onclick="logoff()"/>
|
||||
<pre><div id='result' style='white-space:pre;'></div></pre>
|
||||
</body>
|
||||
<script>
|
||||
function setLoading()
|
||||
{
|
||||
document.getElementById('result').innerHTML= " <img src='loading_animation.gif' /><br/>Loading...";
|
||||
}
|
||||
|
||||
function autenticate(){
|
||||
setLoading();
|
||||
$.ajax({
|
||||
type:'POST',
|
||||
url:'http://localhost/mind/',
|
||||
url:'../../',
|
||||
data:{
|
||||
program:'auth',
|
||||
login:"admin",
|
||||
@@ -28,11 +33,13 @@
|
||||
}
|
||||
function runTest()
|
||||
{
|
||||
setLoading();
|
||||
$.ajax({
|
||||
type:'POST',
|
||||
url:'http://localhost/mind/',
|
||||
url:'../../',
|
||||
data:{
|
||||
program:'test'
|
||||
program:'test',
|
||||
unit: true
|
||||
},
|
||||
success: function(ret){
|
||||
document.getElementById('result').innerHTML= ret
|
||||
@@ -41,9 +48,10 @@
|
||||
}
|
||||
function runInfo()
|
||||
{
|
||||
setLoading();
|
||||
$.ajax({
|
||||
type:'POST',
|
||||
url:'http://localhost/mind/',
|
||||
url:'../../',
|
||||
data:{
|
||||
program: 'info'
|
||||
},
|
||||
@@ -55,9 +63,10 @@
|
||||
|
||||
function showProjects()
|
||||
{
|
||||
setLoading();
|
||||
$.ajax({
|
||||
type:'POST',
|
||||
url:'http://localhost/mind/',
|
||||
url:'../../',
|
||||
data:{
|
||||
program:'show',
|
||||
what:'projects',
|
||||
@@ -71,9 +80,10 @@
|
||||
|
||||
function showUsers()
|
||||
{
|
||||
setLoading();
|
||||
$.ajax({
|
||||
type:'POST',
|
||||
url:'http://localhost/mind/',
|
||||
url:'../../',
|
||||
data:{
|
||||
program:'show',
|
||||
what:'users',
|
||||
@@ -87,20 +97,19 @@
|
||||
|
||||
function analyzeX()
|
||||
{
|
||||
|
||||
setLoading();
|
||||
$.ajax({
|
||||
type:'POST',
|
||||
url:'http://localhost/mind/',
|
||||
url:'../../',
|
||||
data:{
|
||||
program:'use',
|
||||
what:'project',
|
||||
name:'x'
|
||||
},
|
||||
success: function(ret){
|
||||
document.getElementById('result').innerHTML= "";
|
||||
$.ajax({
|
||||
type:'POST',
|
||||
url:'http://localhost/mind/',
|
||||
url:'../../',
|
||||
data:{
|
||||
program:'analyze'
|
||||
},
|
||||
@@ -114,20 +123,19 @@
|
||||
|
||||
function analyzeY()
|
||||
{
|
||||
|
||||
setLoading();
|
||||
$.ajax({
|
||||
type:'POST',
|
||||
url:'http://localhost/mind/',
|
||||
url:'../../',
|
||||
data:{
|
||||
program:'use',
|
||||
what:'project',
|
||||
name:'y'
|
||||
},
|
||||
success: function(ret){
|
||||
document.getElementById('result').innerHTML= "";
|
||||
$.ajax({
|
||||
type:'POST',
|
||||
url:'http://localhost/mind/',
|
||||
url:'../../',
|
||||
data:{
|
||||
program:'analyze'
|
||||
},
|
||||
@@ -141,9 +149,10 @@
|
||||
|
||||
function logoff()
|
||||
{
|
||||
setLoading();
|
||||
$.ajax({
|
||||
type:'POST',
|
||||
url:'http://localhost/mind/',
|
||||
url:'../../',
|
||||
data:{
|
||||
program:'exit'
|
||||
},
|
||||
|
||||
|
Depois Largura: | Altura: | Tamanho: 12 KiB |
@@ -1,6 +1,6 @@
|
||||
The MIT License
|
||||
|
||||
Copyright (c) 2010 TheWebMind.org
|
||||
Copyright (c) 2011 TheWebMind.org, Felipe Nascimento de Moura
|
||||
|
||||
Permission is hereby granted, free of charge, to any person
|
||||
obtaining a copy of this software and associated documentation
|
||||
@@ -22,3 +22,7 @@ HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
||||
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
||||
OTHER DEALINGS IN THE SOFTWARE.
|
||||
|
||||
Main contacts:
|
||||
felipe@thewebmind.org // http://felipenmoura.org // twitter: @felipenmoura
|
||||
jaydson@thewebmind.org // http://jaydson.org // twitter: @jaydson
|
||||
@@ -8,10 +8,6 @@
|
||||
* mind, in your console
|
||||
*/
|
||||
|
||||
/**
|
||||
* @var _MIND
|
||||
* @global mixed $_GLOBALS['_MIND'] This variable contains many information about the proect, the system and also have some methods an attributes to deal with such data
|
||||
*/
|
||||
$_MIND= Array();
|
||||
$_MIND['env']= 'shell';
|
||||
|
||||
|
||||
@@ -33,6 +33,7 @@ class En {
|
||||
$this->messages['no_such_file'] = Mind::message("\nMain: No such command '%s'", "[Fail]", false);
|
||||
$this->messages['auth_fail'] = Mind::message("\nAuth: Wrong user or password", "[Fail]", false);
|
||||
$this->messages['bye'] = "Logging out...\n";
|
||||
$this->messages['thinking'] = "Please wait while I'm thinking...\n";
|
||||
$this->messages['invalidCreateParams'] = Mind::message("Main: Invalid parameters", "[Fail]", false);
|
||||
$this->messages['invalidOption'] = Mind::message("Invalid option '%s'", '[Fail]', false);
|
||||
$this->messages['projectAlreadyExists'] = Mind::message("There is, already, another project with the same name", '[Fail]', false);
|
||||
@@ -41,8 +42,12 @@ class En {
|
||||
$this->messages['noProject'] = Mind::message("Project '%s' doesn't exist or you have no access", '[Fail]', false);
|
||||
$this->messages['projectOpened'] = Mind::message("Project '%s' opened", '[Ok]', false);
|
||||
$this->messages['currentProjectRequired'] = Mind::message("You must open a project first", '[Fail]', false);
|
||||
$this->messages['sourceFileNotFound'] = Mind::message("The source '%s' was not found for the current project.", '[Fail]', false);
|
||||
$this->messages['currentProjectRequiredTip']= "You can use the command\n use project <projectName>\n";
|
||||
|
||||
$this->messages['analyseFirst'] = "You will need to analyze the project. It has not been analyzed yet.Execute the 'analyze' command.\n";
|
||||
$this->messages['permissionDenied'] = Mind::message("Permission denied to change/create/delete files.\nPlease, allow the system to change files in mind's root directory", '[Fail]', false);;
|
||||
$this->messages['additionalCounterCol'] = "This field was automatically added to allow an insertion of a new tuple using repeated values for the other keys.";
|
||||
|
||||
$this->messages['http_invalid_requisition'] = <<<MESSAGE
|
||||
Invalid HTTP requisition.
|
||||
You *must* send some POST data acoording your request, and also a variable "program" by post, with the name of the program you want to run.
|
||||
@@ -31,28 +31,33 @@ class pt {
|
||||
public function __construct()
|
||||
{
|
||||
//header('Content-type: text/html; charset=iso-8859-1');
|
||||
$this->messages['programRequired'] = Mind::message("API: You must send the program name, to execute", '[Fail]', false);
|
||||
$this->messages['loginRequired'] = Mind::message("Auth: Both login and password are required", '[Fail]', false);
|
||||
$this->messages['passwordRequired'] = "I need a password for this user, please: ";
|
||||
$this->messages['autenticated'] = Mind::message("\nMain: %s autenticated", "[OK]", false);//"\n[OK] %s autenticated\n";
|
||||
$this->messages['not_allowed'] = Mind::message("\nMain: You have not autenticated your credentials yet", '[Fail]', false);
|
||||
$this->messages['not_allowed_tip'] = "Try calling the command\n auth < login >\nA password will be required.\n";
|
||||
$this->messages['no_such_file'] = Mind::message("\nMain: No such command '%s'", "[Fail]", false);
|
||||
$this->messages['auth_fail'] = Mind::message("\nAuth: Wrong user or password", "[Fail]", false);
|
||||
$this->messages['bye'] = "Logging out...\n";
|
||||
$this->messages['invalidCreateParams'] = Mind::message("Main: Invalid parameters", "[Fail]", false);
|
||||
$this->messages['invalidOption'] = Mind::message("Invalid option '%s'", '[Fail]', false);
|
||||
$this->messages['projectAlreadyExists'] = Mind::message("There is, already, another project with the same name", '[Fail]', false);
|
||||
$this->messages['projectCreated'] = Mind::message("Created project '%s'", '[Ok]', false);
|
||||
$this->messages['userCreated'] = Mind::message("Created user '%s'", '[Ok]', false);
|
||||
$this->messages['noProject'] = Mind::message("Project '%s' doesn't exist or you have no access", '[Fail]', false);
|
||||
$this->messages['projectOpened'] = Mind::message("Project '%s' opened", '[Ok]', false);
|
||||
$this->messages['currentProjectRequired'] = Mind::message("You must open a project first", '[Fail]', false);
|
||||
$this->messages['currentProjectRequiredTip']= "You can use the command\n use project <projectName>\n";
|
||||
$this->messages['programRequired'] = Mind::message("API: Você precisa passar o nome do programa a ser executado.", '[Fail]', false);
|
||||
$this->messages['loginRequired'] = Mind::message("Auth: Tanto login quanto senha são obrigatórios.", '[Fail]', false);
|
||||
$this->messages['passwordRequired'] = "Precisarei do password para este usuário, por favor: ";
|
||||
$this->messages['autenticated'] = Mind::message("\nMain: %s autenticado", "[OK]", false);//"\n[OK] %s autenticated\n";
|
||||
$this->messages['not_allowed'] = Mind::message("\nMain: Você ainda não autenticou suas credenciais.", '[Fail]', false);
|
||||
$this->messages['not_allowed_tip'] = "Tente executar o comando\n auth < login >\nUma senha será solicitada.\n";
|
||||
$this->messages['no_such_file'] = Mind::message("\nMain: Não conheço tal comando: '%s'", "[Fail]", false);
|
||||
$this->messages['auth_fail'] = Mind::message("\nAuth: Usuário ou senha inválidos", "[Fail]", false);
|
||||
$this->messages['bye'] = "Saindo, até logo...\n";
|
||||
$this->messages['thinking'] = "Por favor aguarde, enquanto eu penso...\n";
|
||||
$this->messages['invalidCreateParams'] = Mind::message("Main: Parâmetros inválidos", "[Fail]", false);
|
||||
$this->messages['invalidOption'] = Mind::message("Opção inválida '%s'", '[Fail]', false);
|
||||
$this->messages['projectAlreadyExists'] = Mind::message("Lamento mas já existe um projeto de mesmo nome.", '[Fail]', false);
|
||||
$this->messages['projectCreated'] = Mind::message("Projeto '%s' criado.", '[Ok]', false);
|
||||
$this->messages['userCreated'] = Mind::message("Usuário '%s' criado", '[Ok]', false);
|
||||
$this->messages['noProject'] = Mind::message("Projeto '%s' não existe ou você não tem acesso ao mesmo.", '[Fail]', false);
|
||||
$this->messages['projectOpened'] = Mind::message("Acessando projeto '%s'", '[Ok]', false);
|
||||
$this->messages['currentProjectRequired'] = Mind::message("Primeiro você precisará abrir um projeto.", '[Fail]', false);
|
||||
$this->messages['currentProjectRequiredTip']= "Tente com o comando\n use project <projectName>\n";
|
||||
$this->messages['analyseFirst'] = "Você precisará analisar o projeto, primeiro. O projeto ainda não foi analizado. Execute o comando 'analyze'.\n";
|
||||
$this->messages['sourceFileNotFound'] = Mind::message("O arquivo fonte '%s' não foi encontrado para o projeto atual.", '[Fail]', false);
|
||||
$this->messages['permissionDenied'] = Mind::message("Permissão negada pra acessar, criar, alterar ou excluir um arquivo.\nPor favor, libere acesso ao sistema para o diretório raíz do Mind.\n", '[Fail]', false);
|
||||
$this->messages['additionalCounterCol'] = "Campo adicionado automaticamente, a ser usado como diferencial para cada tupla, a fim de possibilizar um novo registro utilizando as mesmas demais chaves.";
|
||||
|
||||
$this->messages['http_invalid_requisition'] = <<<MESSAGE
|
||||
Invalid HTTP requisition.
|
||||
You *must* send some POST data acoording your request, and also a variable "program" by post, with the name of the program you want to run.
|
||||
Requisição HTTP inválida.
|
||||
Você *deve* enviar alguma informação via POST juntamente com o parâmetro "program" com o nome do programa que deseja rodar e seus parâmetros.
|
||||
MESSAGE;
|
||||
}
|
||||
}
|
||||
@@ -13,6 +13,7 @@
|
||||
public $defaults= null;
|
||||
public $conf= null;
|
||||
|
||||
public static $autoloadPaths= Array();
|
||||
public static $currentProject= null;
|
||||
public static $ref= Array();
|
||||
public static $projectsDir= '';
|
||||
@@ -148,23 +149,37 @@
|
||||
return MindProject::openProject($p);
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a directory to the autoload source paths list
|
||||
* @param String $path
|
||||
*/
|
||||
public static function autoloadRegisterPath($path)
|
||||
{
|
||||
if(is_string($path) && !in_array($path, Mind::$autoloadPaths))
|
||||
Mind::$autoloadPaths[]= $path;
|
||||
else
|
||||
foreach($path as $p)
|
||||
if(!in_array($p, Mind::$autoloadPaths))
|
||||
Mind::$autoloadPaths[]= $p;
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*/
|
||||
public function Mind(){
|
||||
$path= _MINDSRC_;
|
||||
Mind::$projectsDir= $path.'/mind3rd/projects/';
|
||||
Mind::$modelsDir= $path.'/mind3rd/API/models/';
|
||||
$this->about= parse_ini_file($path.'/mind3rd/env/about.ini');
|
||||
$this->defaults= parse_ini_file($path.'/mind3rd/env/defaults.ini');
|
||||
$this->conf= parse_ini_file($path.'/mind3rd/env/mind.ini');
|
||||
include($path.'/mind3rd/API/L10N/'.$this->defaults['default_human_language'].'.php');
|
||||
Mind::$projectsDir= $path.PROJECTS_DIR;
|
||||
Mind::$modelsDir= $path.MODELS_DIR;
|
||||
$this->about= parse_ini_file($path.ABOUT_INI);
|
||||
$this->defaults= parse_ini_file($path.DEFAULTS_INI);
|
||||
$this->conf= parse_ini_file($path.MIND_CONF);
|
||||
require_once($path.L10N_DIR.$this->defaults['default_human_language'].'.php');
|
||||
Mind::$curLang= $this->defaults['default_human_languageName'];
|
||||
Mind::$l10n= new $this->defaults['default_human_language']();
|
||||
Mind::$langPath= $path.'/mind3rd/API/languages/';
|
||||
Mind::$langPath= $path.LANG_PATH;
|
||||
Mind::$curLang= $this->defaults['default_human_language'];
|
||||
|
||||
$langPath= $path.'/mind3rd/API/languages/';//.$this->defaults['default_human_languageName'].'/';
|
||||
$langPath= $path.LANG_PATH;
|
||||
set_include_path(get_include_path() . PATH_SEPARATOR . $langPath);
|
||||
}
|
||||
}
|
||||
@@ -7,27 +7,204 @@
|
||||
*/
|
||||
class MindEntity {
|
||||
|
||||
public $name;
|
||||
public $properties= Array();
|
||||
public $relations= Array();
|
||||
public $name;
|
||||
public $pks= Array();
|
||||
public $relevance= 0;
|
||||
public $properties= Array();
|
||||
public $relations= Array();
|
||||
public $linkTable= false;
|
||||
private $refTo= Array();
|
||||
private $refBy= Array();
|
||||
public $selfRef= false;
|
||||
|
||||
public function addAutoPk($unique=false)
|
||||
{
|
||||
GLOBAL $_MIND;
|
||||
$pkPrefix= $_MIND->defaults['pk_prefix'];
|
||||
$propName= $pkPrefix.$this->name;
|
||||
|
||||
$pk= new MindProperty();
|
||||
$pk ->setAsKey()
|
||||
->setName($propName)
|
||||
->setDefault(AUTOINCREMENT_DEFVAL)
|
||||
->setRequired(true)
|
||||
->setType('int')
|
||||
->setUnique($unique);
|
||||
$this->addProperty($pk);
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the entity as a self referred entity.
|
||||
* It uses the $how to know if it is a multiple or a single reference.
|
||||
*
|
||||
* @param mixed $how 0, 1 or n
|
||||
* @return MindEntity
|
||||
*/
|
||||
public function setSelfReferred($how)
|
||||
{
|
||||
$this->selfRef= $how;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the array of entities which are referred by this entity.
|
||||
* @return Array
|
||||
*/
|
||||
public function &getRefTo()
|
||||
{
|
||||
return $this->refTo;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the array of the entities which point to this entity.
|
||||
* @return Array
|
||||
*/
|
||||
public function &getRefBy()
|
||||
{
|
||||
return $this->refBy;
|
||||
}
|
||||
|
||||
/**
|
||||
* Verifies if the entity has a hardKey, or only weakKeys.
|
||||
* @return boolean
|
||||
*/
|
||||
public function hasHardKey()
|
||||
{
|
||||
foreach($this->pks as &$pk)
|
||||
{
|
||||
if($pk->key === true)
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Verifies if the definition describes an entity or not
|
||||
*
|
||||
* @param string $definition
|
||||
* @return boolean
|
||||
*/
|
||||
public static function isEntity($definition)
|
||||
{
|
||||
return strpos($definition, ":")? false: true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a property to the current entity
|
||||
*
|
||||
* @global $_MIND
|
||||
* @param MindProperty $property
|
||||
* @return MindEntity
|
||||
*/
|
||||
public function addProperty(MindProperty $property)
|
||||
{
|
||||
GLOBAL $_MIND;
|
||||
$this->properties[$property->name]= $property;
|
||||
if($property->key)
|
||||
$this->pks[$property->name]= $property;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Verifies if the current entity has a specified property
|
||||
*
|
||||
* @param string $propName
|
||||
* @return boolean
|
||||
*/
|
||||
public function hasProperty($propName)
|
||||
{
|
||||
return isset($this->properties[$propName]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes a property from the current entity
|
||||
*
|
||||
* @param string $propName
|
||||
* @return boolean
|
||||
*/
|
||||
public function removeProperty($propName)
|
||||
{
|
||||
if(isset($this->properties[$propName]))
|
||||
unset($this->properties[$propName]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Defines another entity pointed/refered by this entity
|
||||
* @param MindEntity $ref
|
||||
* @return MindEntity
|
||||
*/
|
||||
public function addRefTo(MindEntity &$ref)
|
||||
{
|
||||
$this->refTo[$ref->name]= &$ref;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes a reference TO
|
||||
* @param type $refName
|
||||
* @return MindEntity
|
||||
*/
|
||||
public function removeRefTo($refName)
|
||||
{
|
||||
unset($this->refTo[$refName]);
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Specifies that another entity is pointing to this one
|
||||
* @param MindEntity $ref
|
||||
* @return MindEntity
|
||||
*/
|
||||
public function addRefBy(MindEntity &$ref)
|
||||
{
|
||||
$this->refBy[$ref->name]= &$ref;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes a reference BY
|
||||
* @param type $refName
|
||||
* @return MindEntity
|
||||
*/
|
||||
public function removeRefBy($refName)
|
||||
{
|
||||
unset($this->refBy[$refName]);
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a reference to the current entity
|
||||
*
|
||||
* @param MindRelation $rel
|
||||
* @return MindEntity
|
||||
*/
|
||||
public function addRef(MindRelation &$rel)
|
||||
{
|
||||
$this->relations[]= &$rel;
|
||||
$this->relations[$rel->name]= &$rel;
|
||||
if($rel->focus->name == $this->name)
|
||||
{
|
||||
if($rel->max == QUANTIFIER_MAX_MAX)
|
||||
{
|
||||
$this->relevance++;
|
||||
$this->addRefBy($rel->rel);
|
||||
}else
|
||||
$this->addRefTo($rel->rel);
|
||||
}else{
|
||||
if($rel->max == QUANTIFIER_MAX_MIN)
|
||||
{
|
||||
$this->relevance++;
|
||||
$this->addRefBy($rel->focus);
|
||||
}else
|
||||
$this->addRefTo($rel->focus);
|
||||
}
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor. It receives the name of the new entity
|
||||
* @param string $word
|
||||
*/
|
||||
public function MindEntity($word)
|
||||
{
|
||||
$this->name= (string)$word;
|
||||
|
||||
@@ -4,7 +4,11 @@
|
||||
*
|
||||
* @author felipe
|
||||
*/
|
||||
class MindProject {
|
||||
class MindProject extends VersionManager{
|
||||
|
||||
public static $sourceContent= Array();
|
||||
public static $currentSource= null;
|
||||
|
||||
/**
|
||||
* Returns true if the project already exists,
|
||||
* false, otherwise
|
||||
@@ -47,7 +51,7 @@ class MindProject {
|
||||
public static function loadIdiom($idiom)
|
||||
{
|
||||
$idiom= str_replace('\\', DIRECTORY_SEPARATOR, $idiom);
|
||||
$langPath= $path.'/mind3rd/API/languages/'.$idiom.'/';
|
||||
$langPath= LANG_PATH.$idiom.'/';
|
||||
|
||||
set_include_path(get_include_path() . PATH_SEPARATOR . $langPath);
|
||||
}
|
||||
@@ -60,6 +64,7 @@ class MindProject {
|
||||
*/
|
||||
public static function openProject($p)
|
||||
{
|
||||
GLOBAL $_REQ;
|
||||
$_SESSION['currentProject']= $p['pk_project'];
|
||||
$_SESSION['currentProjectName']= $p['name'];
|
||||
$_SESSION['currentProjectDir']= Mind::$projectsDir.$p['name'];
|
||||
@@ -71,8 +76,117 @@ class MindProject {
|
||||
Mind::$currentProject= $p;
|
||||
Mind::$curLang= Mind::$currentProject['idiom'];
|
||||
Mind::$content= '';
|
||||
//Mind::$
|
||||
|
||||
// loading entities and relations from cache
|
||||
$path= Mind::$currentProject['path']."/temp/";
|
||||
$entities= $path."entities~";
|
||||
$relations= $path."relations~";
|
||||
if($_REQ['env']=='shell')
|
||||
{
|
||||
if(file_exists($entities) && $f= fopen($entities, 'r'))
|
||||
{
|
||||
while (($buffer = fgets($f, 51200)) !== false)
|
||||
{
|
||||
if($tmpObj= @unserialize($buffer))
|
||||
Analyst::$entities[$tmpObj->name]= $tmpObj;
|
||||
}
|
||||
$f= fopen($relations, 'r');
|
||||
while (($buffer = fgets($f, 51200)) !== false)
|
||||
{
|
||||
if($tmpObj= @unserialize($buffer))
|
||||
Analyst::$relations[$tmpObj->name]= $tmpObj;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Mind::write('projectOpened', true, $p['name']);
|
||||
return true;
|
||||
}
|
||||
|
||||
public static function loadSource($source='main')
|
||||
{
|
||||
$srcs= Mind::$currentProject['sources'];
|
||||
if(file_exists($srcs.'/'.$source.'.mnd'))
|
||||
{
|
||||
$main= file_get_contents($srcs.'/'.$source.'.mnd');
|
||||
return $main;
|
||||
}
|
||||
Mind::write('sourceFileNotFound', true, $source);
|
||||
return false;
|
||||
}
|
||||
|
||||
public static function import($src)
|
||||
{
|
||||
self::$sourceContent[$src]= $src;
|
||||
$extraFiles[]= preg_match_all(IMPORT_SOURCE, $src, $matches);
|
||||
$matches= $matches[0];
|
||||
foreach($matches as &$import)
|
||||
{
|
||||
$import= substr($import, 8);
|
||||
$extraContent= self::loadSource($import);
|
||||
self::import($extraContent);
|
||||
}
|
||||
}
|
||||
|
||||
public static function loadSources()
|
||||
{
|
||||
$main= self::loadSource();
|
||||
self::import($main);
|
||||
}
|
||||
|
||||
public static function setUp()
|
||||
{
|
||||
parent::setUp();
|
||||
self::$sourceContent= false;
|
||||
self::$currentSource= null;
|
||||
self::$sourceContent= Array();
|
||||
Analyst::reset();
|
||||
|
||||
MindTimer::init();
|
||||
Mind::$lexer= new Lexer();
|
||||
self::loadSources();
|
||||
}
|
||||
public static function analyze($autoCommit=false)
|
||||
{
|
||||
self::setUp();
|
||||
|
||||
foreach(self::$sourceContent as $k=>&$content)
|
||||
{
|
||||
$currentSource= $k;
|
||||
// search for special/unknown characters
|
||||
if(!Mind::$lexer->sweep($content))
|
||||
return false;
|
||||
// keep substantives and verbs on their canonical form
|
||||
if(!Mind::$canonic->sweep())
|
||||
return false;
|
||||
// mark specific tokens
|
||||
if(!Mind::$tokenizer->sweep())
|
||||
return false;
|
||||
// prepares the model to be used to process data
|
||||
// it transforms the original text into the mind code
|
||||
// itself
|
||||
if(!Mind::$syntaxer->sweep())
|
||||
return false;
|
||||
|
||||
if($autoCommit)
|
||||
{
|
||||
MindProject::commit();
|
||||
}
|
||||
}
|
||||
|
||||
MindTimer::end();
|
||||
|
||||
// do NOT print it if you have MANY entities, the webbrowser freezes
|
||||
//print_r(Analyst::getUniverse());
|
||||
echo Analyst::printWhatYouGet();
|
||||
echo "--------------------\n";
|
||||
echo "Time: ".
|
||||
MindTimer::getElapsedTime().
|
||||
"s\n";
|
||||
$memory= ((memory_get_usage() / 1024)/1024);
|
||||
$memory= number_format($memory, 2);
|
||||
echo "Memory: ".$memory."MBs\n";
|
||||
|
||||
self::cleanUp();
|
||||
}
|
||||
}
|
||||
@@ -6,16 +6,147 @@
|
||||
*/
|
||||
class MindProperty {
|
||||
|
||||
public $definition= "";
|
||||
public $name= false;
|
||||
public $type= "text";
|
||||
public $size= 0;
|
||||
public $default= null;
|
||||
public $required= false;
|
||||
public $refTo= false;
|
||||
public $refBy= Array();
|
||||
public $key= false;
|
||||
public $definition= "";
|
||||
private $name = false;
|
||||
private $type = "text";
|
||||
private $size = 0;
|
||||
private $options = Array();
|
||||
private $default = null;
|
||||
private $unique = false;
|
||||
private $required = false;
|
||||
public $refTo = false;
|
||||
public $refBy = Array();
|
||||
public $key = false;
|
||||
public $comment = false;
|
||||
|
||||
/**
|
||||
* Sets the entity and property the current property is referred to.
|
||||
* @param MindEntity $entity
|
||||
* @param MindProperty $prop
|
||||
* @return MindProperty
|
||||
*/
|
||||
public function setRefTo(MindEntity $entity, MindProperty $prop)
|
||||
{
|
||||
$this->refTo= Array($entity, $prop);
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return all the properties
|
||||
* @param string $what
|
||||
* @return mixed
|
||||
*/
|
||||
public function __get($what)
|
||||
{
|
||||
if(isset($this->$what))
|
||||
return $this->$what;
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set name
|
||||
* @param string $val
|
||||
* @return MindProperty
|
||||
*/
|
||||
public function setName($val)
|
||||
{
|
||||
$this->name= (string)$val;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set size
|
||||
* @param int/float $val
|
||||
* @return MindProperty
|
||||
*/
|
||||
public function setSize($val)
|
||||
{
|
||||
$this->size= $val;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set Options
|
||||
* @param Array $val
|
||||
* @return MindProperty
|
||||
*/
|
||||
public function setOptions($val)
|
||||
{
|
||||
$this->options= $val;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set type
|
||||
* @param string $val
|
||||
* @return MindProperty
|
||||
*/
|
||||
public function setType($val)
|
||||
{
|
||||
$this->type= (string)$val;
|
||||
$tmpType= self::isKnown($this->type);
|
||||
if(!$tmpType)
|
||||
{
|
||||
//TODO: Darwin::add($this->type);
|
||||
Darwin::addDoubt($this->type, 'dataType');
|
||||
return false;
|
||||
}
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set Default value
|
||||
* @param string $val
|
||||
* @return MindProperty
|
||||
*/
|
||||
public function setDefault($val)
|
||||
{
|
||||
$this->default= (string)$val;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set as unique or not
|
||||
* @param boolean $val
|
||||
* @return MindProperty
|
||||
*/
|
||||
public function setUnique($val)
|
||||
{
|
||||
$this->unique= $val? true: false;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set wheter the property is required(not null) or not
|
||||
* @param boolean $val
|
||||
* @return MindProperty
|
||||
*/
|
||||
public function setRequired($val)
|
||||
{
|
||||
$this->required= $val? true: false;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the property as a key
|
||||
* @return MindProperty
|
||||
*/
|
||||
public function setAsKey()
|
||||
{
|
||||
$this->key= true;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the property as a weak key
|
||||
* @return MindProperty
|
||||
*/
|
||||
public function setAsWeakKey()
|
||||
{
|
||||
$this->key= 'weak';
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if the string sent indicates that it is about a property
|
||||
* @param String $definition
|
||||
@@ -53,6 +184,19 @@
|
||||
$rx= "/".implode('|', Tokenizer::$qualifiers['notnull'])."/i";
|
||||
return (preg_match($rx, $expression))? true: false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Verifies on the passed string if it indicates that the current
|
||||
* property definition should be unique or not
|
||||
*
|
||||
* @param String $expression
|
||||
* @return boolean
|
||||
*/
|
||||
public static function isUnique($expression)
|
||||
{
|
||||
$rx= "/".implode('|', Tokenizer::$qualifiers['unique'])."/i";
|
||||
return (preg_match($rx, $expression))? true: false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true in case the passed expression represent a property
|
||||
@@ -85,18 +229,10 @@
|
||||
$typeEnd= strpos($str, '(');
|
||||
$typeEnd= $typeEnd? $typeEnd- $typeStart: strLen($str);
|
||||
$type= substr($str, $typeStart, $typeEnd);
|
||||
$this->type= $type;
|
||||
$tmpType= self::isKnown($this->type);
|
||||
if(!$tmpType)
|
||||
{
|
||||
//TODO: Darwin::add($this->type);
|
||||
echo "UNKNOWN TYPE...for a while";
|
||||
return false;
|
||||
}else
|
||||
$type= $tmpType;
|
||||
$this->setType($type);
|
||||
|
||||
// identifying the name
|
||||
$this->name= substr($str, 0, $typeStart);
|
||||
$this->setName(Mind::$lexer->fixWordChars(substr($str, 0, $typeStart-1)));
|
||||
|
||||
// identifying details
|
||||
if(preg_match(PROP_DETAILS, $str, $details))
|
||||
@@ -115,20 +251,41 @@
|
||||
$default= preg_replace(PROP_DEFEXEC, "", $default);
|
||||
}
|
||||
|
||||
$this->default= $default;
|
||||
$this->setDefault($default);
|
||||
}
|
||||
|
||||
// identifying if it is required
|
||||
if(self::isRequired($details))
|
||||
$this->required= true;
|
||||
$this->setRequired(true);
|
||||
|
||||
// identifying if it is a forced key
|
||||
if(self::isKey($details))
|
||||
$this->key= true;
|
||||
$this->setAsKey();
|
||||
|
||||
// identifying its size
|
||||
if(preg_match(PROP_SIZE, $details, $size))
|
||||
$this->size= $size[0];
|
||||
$this->setSize($size[0]);
|
||||
|
||||
// identifying the options
|
||||
if(preg_match(PROP_OPTIONS, $details, $options))
|
||||
{
|
||||
$options= explode('|',
|
||||
preg_replace(PROP_OPTIONS_CLEAR,
|
||||
'',
|
||||
$options[0])
|
||||
);
|
||||
foreach($options as &$opt)
|
||||
{
|
||||
$opt= explode('=', $opt, 2);
|
||||
}
|
||||
$this->setOptions($options);
|
||||
}
|
||||
|
||||
// checking if it is unique
|
||||
if(self::isUnique($details))
|
||||
{
|
||||
$this->setUnique(true);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
@@ -140,10 +297,12 @@
|
||||
*
|
||||
* @param String $definition
|
||||
*/
|
||||
public function MindProperty($definition)
|
||||
public function MindProperty($definition=false)
|
||||
{
|
||||
$this->definition= $definition;
|
||||
$this->parse();
|
||||
//echo json_encode($this)."\n";
|
||||
if($definition)
|
||||
{
|
||||
$this->definition= $definition;
|
||||
$this->parse();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -6,7 +6,7 @@
|
||||
*/
|
||||
class MindRelation {
|
||||
|
||||
public $name;
|
||||
public $name;
|
||||
private $linkTypes = Array('possibility', 'must', 'action');
|
||||
private $linkType = 'action';
|
||||
private $quantifiers = Array(0, 1, 'n');
|
||||
@@ -15,7 +15,67 @@
|
||||
private $verb = '';
|
||||
private $focus = null;
|
||||
private $rel = null;
|
||||
public $opposite = null;
|
||||
public $uniqueRef = false;
|
||||
public $treated = false; //to be used by Normalizer
|
||||
|
||||
/**
|
||||
* Renames a relation, replacing it into the Analyst relations list
|
||||
*
|
||||
* @param string $newName
|
||||
* @return MindRelation
|
||||
*/
|
||||
public function rename($newName)
|
||||
{
|
||||
Analyst::$relations[$newName]= Analyst::$relations[$this->name];
|
||||
Analyst::$relations[$this->name]= false;
|
||||
$this->name= (string)$newName;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Specifies the relative entity
|
||||
*
|
||||
* @param MindEntity $rel
|
||||
* @return MindRelation
|
||||
*/
|
||||
public function setRel(MindEntity &$rel)
|
||||
{
|
||||
$this->rel= &$rel;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Specifies the focused entity
|
||||
*
|
||||
* @param MindEntity $focus
|
||||
* @return MindRelation
|
||||
*/
|
||||
public function setFocus(MindEntity &$focus)
|
||||
{
|
||||
$this->focus= &$focus;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return properties from the current relation
|
||||
* These properties were set to private due to set limitations
|
||||
* but they may be open for get operations
|
||||
*
|
||||
* @param String $what
|
||||
* @return Mixed
|
||||
*/
|
||||
public function __get($what)
|
||||
{
|
||||
if(isset($this->$what))
|
||||
return $this->$what;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the type of link(possibility, action or must)
|
||||
* @param string $linkType
|
||||
* @return MindRelation
|
||||
*/
|
||||
public function setLinkType($linkType)
|
||||
{
|
||||
if(in_array($linkType, $this->linkTypes))
|
||||
@@ -26,32 +86,57 @@
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the minimun value of the relation(0 or 1)
|
||||
* @param Mixed $min
|
||||
* @return MindRelation
|
||||
*/
|
||||
public function setMin($min)
|
||||
{
|
||||
if(in_array($min, $this->quantifiers))
|
||||
if($min === 0 || $min === 1)
|
||||
{
|
||||
$this->min= $min;
|
||||
return $this;
|
||||
}
|
||||
throw new Exception("Invalid minimum quantifier: ".$min, 0);
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Sets the maximun value for the relation(1 or n)
|
||||
* @param mixed $max
|
||||
* @return MindRelation
|
||||
*/
|
||||
public function setMax($max)
|
||||
{
|
||||
if(in_array($max, $this->quantifiers))
|
||||
if($max == 1 || $max == 'n')
|
||||
{
|
||||
$this->max= $max;
|
||||
return $this;
|
||||
}
|
||||
throw new Exception("Invalid maximum quantifier: ".$max, 0);
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Defines which verb was used to define the current instruction
|
||||
*
|
||||
* @param string $verb
|
||||
* @return MindRelation
|
||||
*/
|
||||
public function setUsedVerb($verb)
|
||||
{
|
||||
$this->verb= (string)$verb;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Specifies which entities are envolved in this relation
|
||||
*
|
||||
* @param MindEntity $focus
|
||||
* @param MindEntity $rel
|
||||
* @return MindRelation
|
||||
*/
|
||||
public function setEntities(MindEntity &$focus, MindEntity &$rel)
|
||||
{
|
||||
$this->focus= &$focus;
|
||||
@@ -59,6 +144,10 @@
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* The constructor, receiving the name of the relation
|
||||
* @param string $relName
|
||||
*/
|
||||
public function MindRelation($relName)
|
||||
{
|
||||
$this->name= (string)$relName;
|
||||
|
||||
@@ -0,0 +1,32 @@
|
||||
<?php
|
||||
/**
|
||||
* Description of MindTimer
|
||||
*
|
||||
* @author felipe
|
||||
*
|
||||
*/
|
||||
abstract class MindTimer {
|
||||
|
||||
public static $startingTime= 0;
|
||||
public static $endingTime = 0;
|
||||
|
||||
public static function getElapsedTime()
|
||||
{
|
||||
return number_format(((float)self::$endingTime) - ((float)self::$startingTime), 4);
|
||||
}
|
||||
|
||||
public static function init()
|
||||
{
|
||||
$startingTime= microtime();
|
||||
$startingTime= explode(' ', $startingTime);
|
||||
$startingTime= $startingTime[1] + $startingTime[0];
|
||||
self::$startingTime= $startingTime;
|
||||
}
|
||||
public static function end()
|
||||
{
|
||||
$endingTime= microtime();
|
||||
$endingTime= explode(' ', $endingTime);
|
||||
$endingTime= $endingTime[1] + $endingTime[0];
|
||||
self::$endingTime= $endingTime;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
<?php
|
||||
/**
|
||||
* This class takes care of the version control methods
|
||||
*
|
||||
* @author felipe
|
||||
*/
|
||||
class VersionManager {
|
||||
public static function commit()
|
||||
{
|
||||
// TODO: commiting a project should save the current
|
||||
// situation of the current project
|
||||
echo "COMMITING";
|
||||
}
|
||||
|
||||
public static function setUp()
|
||||
{
|
||||
}
|
||||
|
||||
public static function cleanUp()
|
||||
{
|
||||
$path= Mind::$currentProject['path']."/temp/";
|
||||
$entities= $path."entities~";
|
||||
$relations= $path."relations~";
|
||||
|
||||
$fEnt= fopen($entities, "w+");
|
||||
$fRel= fopen($relations, "w+");
|
||||
if(!$fEnt)
|
||||
{
|
||||
Mind::write('permissionDenied');
|
||||
return;
|
||||
}
|
||||
ftruncate($fEnt, 0);
|
||||
ftruncate($fRel, 0);
|
||||
@chmod($entities, 0777);
|
||||
@chmod($relations, 0777);
|
||||
|
||||
|
||||
foreach(Analyst::$entities as &$entity)
|
||||
{
|
||||
file_put_contents($entities, serialize($entity)."\n", FILE_APPEND);
|
||||
}
|
||||
|
||||
foreach(Analyst::$relations as &$relation)
|
||||
{
|
||||
file_put_contents($relations, serialize($relation)."\n", FILE_APPEND);
|
||||
}
|
||||
fclose($fEnt);
|
||||
fclose($fRel);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
<?php
|
||||
/**
|
||||
* Description of Darwin
|
||||
*
|
||||
* @author felipe
|
||||
*/
|
||||
class Darwin {
|
||||
public static function addDoubt($context, $type)
|
||||
{
|
||||
echo "DUVIDAAAA";
|
||||
}
|
||||
}
|
||||
@@ -1,9 +1,21 @@
|
||||
<?php
|
||||
/**
|
||||
* This file is part of TheWebMind 3rd generation.
|
||||
*
|
||||
* Lexer, within the Cortex/Lexer packages.<br/>
|
||||
* Notice that, these packages are being used only for documentation,
|
||||
* not to organize the classes.
|
||||
*
|
||||
* @author Felipe Nascimento de Moura <felipenmoura@gmail.com>
|
||||
* @license licenses/mind3rd.license
|
||||
*/
|
||||
/**
|
||||
* This class sweeps the passed words and validates if
|
||||
* its content matches with the valid chars
|
||||
*
|
||||
* @author felipe
|
||||
* @package Cortex
|
||||
* @subpackage Lexer
|
||||
* @author Felipe Nascimento de Moura <felipenmoura@gmail.com>
|
||||
*/
|
||||
class Lexer
|
||||
{
|
||||
@@ -16,7 +28,10 @@ class Lexer
|
||||
private $glue= '';
|
||||
|
||||
/**
|
||||
* Thanks to saeedco (no more information found about him!)
|
||||
* Splits a string using utf8 format.
|
||||
*
|
||||
* Thanks to saeedco (no more information found about him!) I had to
|
||||
* change only a few things on this method.
|
||||
* Source: http://br2.php.net/manual/en/function.str-split.php#83331
|
||||
* Idioms it is supposed to work properly
|
||||
* English
|
||||
@@ -28,14 +43,25 @@ class Lexer
|
||||
* Russian
|
||||
* Persian
|
||||
* Portuguese
|
||||
*
|
||||
* Of course, if you find any problem, report it to us :)
|
||||
*
|
||||
* @param String $str
|
||||
* @param String $str The string to be splitted.
|
||||
* @return array
|
||||
*/
|
||||
private function str_split_utf8($str) {
|
||||
// place each character of the string into and array
|
||||
$split=1;
|
||||
$array = array();
|
||||
|
||||
/*
|
||||
* SOMEONE HERE, PLEASE! Explain that for me!
|
||||
* ONLY the 'ó' char isnt working when treated...even 'Ó' is!
|
||||
* ALL the other characteres are working just fine!
|
||||
* Someone who could fix it in a better way, please
|
||||
*/
|
||||
$str= str_replace('ó', 'o', $str);
|
||||
|
||||
for ( $i=0; $i < strlen( $str ); ){
|
||||
$value = ord($str[$i]);
|
||||
if($value > 127){
|
||||
@@ -58,7 +84,11 @@ class Lexer
|
||||
}
|
||||
|
||||
/**
|
||||
* Validates the sent char
|
||||
* Validates the sent char.
|
||||
*
|
||||
* Verifies wether the passed char is a valid char for
|
||||
* that idiom or not.
|
||||
*
|
||||
* @param char $letter
|
||||
* @return boolean
|
||||
*/
|
||||
@@ -79,6 +109,46 @@ class Lexer
|
||||
}
|
||||
|
||||
/**
|
||||
* Prepares names for their use.
|
||||
*
|
||||
* Parses the string encoding and returns a valid name
|
||||
* to be used on databases or restricted names
|
||||
*
|
||||
* @param String $word
|
||||
* @return String
|
||||
*/
|
||||
public function fixWordChars($word)
|
||||
{
|
||||
$word= preg_replace(FIX_PROP_NAME, '', strtolower($word));
|
||||
|
||||
$word= $this->str_split_utf8($word);
|
||||
$str= "";
|
||||
for($i=0, $j=sizeof($word); $i<$j; $i++)
|
||||
{
|
||||
$str.= $this->translateChars($word[$i]);
|
||||
}
|
||||
return strtolower($str);
|
||||
}
|
||||
|
||||
/**
|
||||
* Fixes the passed string replacing special chars.
|
||||
*
|
||||
* This method takes each special char and replaces it with
|
||||
* the respective char specified in the choosen idiom.
|
||||
*
|
||||
* @param string $str
|
||||
* @return string
|
||||
*/
|
||||
public function translateChars($str)
|
||||
{
|
||||
$from = $this->replacements[0];
|
||||
$to = $this->replacements[1];
|
||||
return strtr(utf8_decode($str), utf8_decode($from), $to);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sweeps through the content and apply the lexer rules.
|
||||
*
|
||||
* Performs a sweep over the sent content and replace any
|
||||
* special char, also removing any invalid char.
|
||||
* @param string $content
|
||||
@@ -137,7 +207,7 @@ class Lexer
|
||||
|
||||
// but content between parentheses should be left with
|
||||
// normal spaces, instead of the space token
|
||||
// restoring the inition format for attribute details
|
||||
// restoring the initial format for attribute details
|
||||
$fixed= str_replace($this->tmpSpace, " ", $fixed);
|
||||
$fixed= str_replace($this->tmpComa, ",", $fixed);
|
||||
$fixed= str_replace($this->tmpPeriod, ".", $fixed);
|
||||
@@ -147,7 +217,7 @@ class Lexer
|
||||
$fixed= preg_replace(MULTILINE_COMMENT, '', $fixed);
|
||||
|
||||
$exploded= explode($this->tokens[' '], $fixed);
|
||||
|
||||
|
||||
$fixed= array_filter($exploded);
|
||||
|
||||
Mind::$content= $fixed;
|
||||
@@ -157,17 +227,8 @@ class Lexer
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the fixed char to the sent char
|
||||
* @param string $char
|
||||
* @return string
|
||||
* The constructor
|
||||
*/
|
||||
public function translateChars($str)
|
||||
{
|
||||
$from = $this->replacements[0];
|
||||
$to = $this->replacements[1];
|
||||
return strtr($str, $from, $to);
|
||||
}
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
GLOBAL $_MIND;
|
||||
|
||||
@@ -0,0 +1,272 @@
|
||||
<?php
|
||||
/**
|
||||
* This file is part of theWebMind 3rd generation.
|
||||
*
|
||||
* Analyst components, within the Cortex/Analyst packages.<br/>
|
||||
* Notice that, these packages are being used only for documentation,
|
||||
* not to organize the classes.
|
||||
*
|
||||
* @author Felipe Nascimento de Moura <felipenmoura@gmail.com>
|
||||
* @license licenses/mind3rd.license
|
||||
* @filesource
|
||||
*/
|
||||
/**
|
||||
* This is an abstract class to be used to analyze the project.
|
||||
*
|
||||
* @package Cortex
|
||||
* @subpackage Analyst
|
||||
* @author Felipe Nascimento de Moura <felipenmoura@gmail.com>
|
||||
*/
|
||||
abstract class Analysis {
|
||||
|
||||
public static $entities = Array();
|
||||
public static $relations= Array();
|
||||
public static $focused = Array();
|
||||
|
||||
/**
|
||||
* Returns an array with the names of all entities.
|
||||
*
|
||||
* Gets an Array of the names of all the focused entities on
|
||||
* the current expression.
|
||||
* @return Array
|
||||
*/
|
||||
public static function getFocusedNames()
|
||||
{
|
||||
$focused= Array();
|
||||
foreach(self::$focused as $focus)
|
||||
$focused[]= $focus->name;
|
||||
return $focused;
|
||||
}
|
||||
|
||||
/**
|
||||
* Clears the current focused entities.
|
||||
*/
|
||||
public static function clearFocused()
|
||||
{
|
||||
self::$focused = false;
|
||||
self::$focused = Array();
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds an entity to the focused entities list.
|
||||
* @param MindEntity &$entity The entity to be added to focus
|
||||
*/
|
||||
public static function addToFocus(MindEntity &$entity)
|
||||
{
|
||||
self::$focused[$entity->name]= $entity;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a relation to the focused list.
|
||||
*
|
||||
* Adds a relation between all the focused entities specified in the
|
||||
* current expression and the passed $rel entity
|
||||
*
|
||||
* @param MindEntity &$rel The entity to be added
|
||||
* @param String $linkType The type of like(action, possibility or must)
|
||||
* @param String $linkVerb The verb used to identify the relation
|
||||
* @param Mixed $min The minimun quantifier
|
||||
* @param Mixed $max The maximun quantifier
|
||||
* @param boolean [$uniqueRef] If it should be an unique referation
|
||||
* @return MindRelationCollection An array of all the created relations
|
||||
*/
|
||||
public static function &addRelationToFocused(MindEntity &$rel, $linkType,
|
||||
$linkVerb, $min, $max,
|
||||
$uniqueRef=false)
|
||||
{
|
||||
// for each focused entity
|
||||
foreach(self::$focused as &$focus)
|
||||
{
|
||||
$curRelation= self::addRelationBetween($focus, $rel, $linkType, $linkVerb, $min, $max);
|
||||
$arRet[]= &$curRelation;
|
||||
}
|
||||
return $arRet;
|
||||
}
|
||||
|
||||
public static function &addRelationBetween (MindEntity $focus,
|
||||
MindEntity &$rel, $linkType,
|
||||
$linkVerb, $min, $max,
|
||||
$uniqueRef=false)
|
||||
{
|
||||
$arRet= Array();
|
||||
/*
|
||||
* we will use this relationName as index on an
|
||||
* indexed array to speed up the search for
|
||||
* relations in the future
|
||||
*/
|
||||
$relationName= $focus->name."_".$rel->name;
|
||||
|
||||
// let's create the relation itself
|
||||
$curRelation= new MindRelation($relationName);
|
||||
|
||||
$curRelation->setLinkType($linkType)
|
||||
->setMin($min)
|
||||
->setMax($max)
|
||||
->setUsedVerb($linkVerb)
|
||||
->setEntities(
|
||||
self::$entities[$focus->name],
|
||||
self::$entities[$rel->name]);
|
||||
// now, both entities will POINT to the same relation
|
||||
$focus->addRef($curRelation);
|
||||
$rel->addRef($curRelation);
|
||||
$curRelation->uniqueRef= $uniqueRef;
|
||||
|
||||
// and let's use the relation name as index, as said before
|
||||
self::$relations[$relationName]= $curRelation;
|
||||
return $curRelation;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds the passed property to all the focused entities.
|
||||
*
|
||||
* @param MindProperty &$prop The property to be added to the focused entities.
|
||||
*/
|
||||
public static function addPropertyToFocused(MindProperty &$prop)
|
||||
{
|
||||
// for each focused entity
|
||||
foreach(self::$focused as $focus)
|
||||
$focus->addProperty($prop);
|
||||
}
|
||||
|
||||
/**
|
||||
* Analyzes the project.
|
||||
*
|
||||
* This method receives each expression and analizes
|
||||
* the best way to act and to store the understood
|
||||
* structure
|
||||
*
|
||||
* @param String $expression
|
||||
* @param String $structure
|
||||
* @param Array $structureKeys
|
||||
* @return Boolean True if everything went ok, false when any error occurred
|
||||
*/
|
||||
public static function analize($expression, $structure, Array $structureKeys){
|
||||
// I'm gonna try to put it in stepByStep style, to
|
||||
// get it easier for me and for you to understand
|
||||
// and follow the thoughts
|
||||
|
||||
// setting up
|
||||
self::clearFocused();
|
||||
$tmpProperties= Array();
|
||||
$i = 0;
|
||||
$linkVerb = null;
|
||||
$min = null;
|
||||
$max = null;
|
||||
$linkType = 'action';
|
||||
$relation = false;
|
||||
$posVerb = false;
|
||||
|
||||
// foreach token
|
||||
foreach($structureKeys as $token)
|
||||
{
|
||||
$word= $expression[$i];
|
||||
$i++;
|
||||
// storing the current used verb
|
||||
if($token==Tokenizer::MT_VERB || $token==Tokenizer::MT_QBE)
|
||||
{
|
||||
$linkVerb= $word;
|
||||
$posVerb= true;
|
||||
continue;
|
||||
}
|
||||
|
||||
// setting quantifiers
|
||||
if($token == Tokenizer::MT_NONE)
|
||||
{
|
||||
$min= 0;
|
||||
continue;
|
||||
}
|
||||
if($token == Tokenizer::MT_ONE || $token == Tokenizer::MT_MANY)
|
||||
{
|
||||
if(!is_null($max))
|
||||
$min= $max;
|
||||
$max= ($token == Tokenizer::MT_ONE)? 1: 'n';
|
||||
}
|
||||
|
||||
// verifying the way the entities will be linked
|
||||
if($token==Tokenizer::MT_QMAY)
|
||||
{
|
||||
$linkType= 'possibility';
|
||||
continue;
|
||||
}
|
||||
if($token==Tokenizer::MT_QMUST)
|
||||
{
|
||||
$linkType= 'must';
|
||||
continue;
|
||||
}
|
||||
|
||||
// if it is a substantive
|
||||
if($token==Tokenizer::MT_SUBST)
|
||||
{
|
||||
// if it is an entity
|
||||
if(MindEntity::isEntity($word))
|
||||
{
|
||||
// fixing any special char
|
||||
$word= Mind::$lexer->fixWordChars($word);
|
||||
|
||||
// yeah, I know it looks crazy, but try to follow my thoughts
|
||||
// let's instantiate a new Entity in case it has not been
|
||||
// instantiated before
|
||||
if(!isset(self::$entities[$word]))
|
||||
self::$entities[$word]= new MindEntity($word);
|
||||
|
||||
// each instruction *should* have one focused entity
|
||||
// we will use the first entity on each expression as focus
|
||||
if(!$posVerb)
|
||||
{
|
||||
self::addToFocus(self::$entities[$word]);
|
||||
}else{
|
||||
$relation= true;
|
||||
// if min or max quantifier have not been set
|
||||
if(is_null($min))
|
||||
$min= ($linkType == 'must')? 1: 0;
|
||||
if(is_null($max))
|
||||
$max= 'n';
|
||||
|
||||
if(in_array($word, array_keys(self::$focused)))
|
||||
{
|
||||
/*if($max != QUANTIFIER_MAX_MAX)
|
||||
continue;*/
|
||||
self::$entities[$word]->setSelfReferred($max);
|
||||
//continue;
|
||||
}
|
||||
/*
|
||||
* here, if it is an entity and the focused
|
||||
* entities have already been selected(post verb),
|
||||
* it means it is the second entity on the
|
||||
* instruction, so, it is a relation between entities
|
||||
*/
|
||||
self::addRelationToFocused(self::$entities[$word],
|
||||
$linkType,
|
||||
$linkVerb,
|
||||
$min,
|
||||
$max);
|
||||
}
|
||||
}else{
|
||||
// ok, after that, this is just easy :)
|
||||
// let's store all the properties to a temporary array
|
||||
$tmpProperties[]= new MindProperty($word);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// adding the properties to the focused entity
|
||||
// we're doing it now, because according to the selected idiom
|
||||
// the sequence of focused entity and properties may vary
|
||||
if(sizeof($tmpProperties)>0 && $posVerb)
|
||||
{
|
||||
foreach($tmpProperties as $prop)
|
||||
self::addPropertyToFocused($prop);
|
||||
}
|
||||
|
||||
// if there was a relation, we will return some details about it
|
||||
if($relation && isset(self::$entities[$word]))
|
||||
return Array('min' =>$min,
|
||||
'max' =>$max,
|
||||
'linkVerb' =>$linkVerb,
|
||||
'linkType' =>$linkType,
|
||||
'focus' =>implode(', ', self::getFocusedNames()),
|
||||
'rel' =>self::$entities[$word]->name);
|
||||
// otherwise, we return the focused entities
|
||||
return self::$focused;
|
||||
}
|
||||
}
|
||||
@@ -1,167 +1,220 @@
|
||||
<?php
|
||||
/**
|
||||
* This class is responsable to the analisys of the system
|
||||
* This file is part of theWebMind 3rd generation.
|
||||
*
|
||||
* Analyst components, within the Cortex/Analyst packages.<br/>
|
||||
* Notice that, these packages are being used only for documentation,
|
||||
* not to organize the classes.
|
||||
*
|
||||
* @author Felipe Nascimento de Moura <felipenmoura@gmail.com>
|
||||
* @license licenses/mind3rd.license
|
||||
* @filesource
|
||||
*/
|
||||
/**
|
||||
* This class is responsible for the analysis of the system
|
||||
* preparing the relations and apply the first rules
|
||||
*
|
||||
* foreach token
|
||||
* if isSubst & MindProp.isProperty
|
||||
* if !prop
|
||||
* if !evidencedEntity
|
||||
* setEvidencedEntity
|
||||
* else
|
||||
* MindEntity.addRelation
|
||||
* else
|
||||
* if !mindProp.isValid
|
||||
* echo ERROR
|
||||
* if !mindProp.isKnown
|
||||
* MindDarwin.addToDoubts
|
||||
* return
|
||||
* MindEntity.addProp
|
||||
* return
|
||||
*
|
||||
* @author felipe
|
||||
* @package Cortex
|
||||
* @subpackage Analyst
|
||||
* @author Felipe Nascimento de Moura <felipenmoura@gmail.com>
|
||||
*/
|
||||
class Analyst {
|
||||
|
||||
public static $entities= Array();
|
||||
public static $relations= Array();
|
||||
class Analyst extends Analysis {
|
||||
|
||||
/**
|
||||
* Returns true if the entity is worth mergin with another, or not.
|
||||
* It takes the relevance as parameter to determine wheter the entity
|
||||
* should be merged(stop existing) or not.
|
||||
*
|
||||
* @param MindEntity $en The entity to be analyzed
|
||||
* @return boolean
|
||||
*/
|
||||
public static function isItWorthMerging(MindEntity $en)
|
||||
{
|
||||
GLOBAL $_MIND;
|
||||
if(Normalizer::relevanceAmount($en) < $_MIND->conf['merging_amount_pts'])
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes an entity from the entities list.
|
||||
* @param type $entity The entity to be removed
|
||||
*/
|
||||
public static function removeEntity($entity)
|
||||
{
|
||||
unset(self::$entities[$entity]);
|
||||
unset($entity);
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes a relation between two entities.
|
||||
* But it will NOT remove the refBy or refTo properties of each entity.
|
||||
* It is most often, useful to be used for relations that may have
|
||||
* been represented twice, as the same idea.
|
||||
* It also decreases the relevance of the focused entity.
|
||||
*
|
||||
* @param MindRelation &$rel The relation which will be droped
|
||||
*/
|
||||
public static function unsetRelation(MindRelation &$rel)
|
||||
{
|
||||
if($rel->focus)
|
||||
{
|
||||
$rel->focus->relations[$rel->name]= false;
|
||||
$rel->focus->relevance--;
|
||||
}
|
||||
if($rel->rel)
|
||||
{
|
||||
$rel->focus->removeRefTo($rel->rel->name);
|
||||
$rel->focus->removeRefBy($rel->rel->name);
|
||||
$rel->rel->removeRefTo($rel->focus->name);
|
||||
$rel->rel->removeRefBy($rel->focus->name);
|
||||
$rel->rel->relations[$rel->name]= false;
|
||||
}
|
||||
unset(self::$relations[$rel->name]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the whole interpreted context, with all the
|
||||
* analyzed information
|
||||
* @return Array An array with both entities and relations
|
||||
*/
|
||||
public static function getUniverse()
|
||||
{
|
||||
return Array(
|
||||
'entities'=>self::$entities,
|
||||
'relations'=>self::$relations
|
||||
'entities'=>&self::$entities,
|
||||
'relations'=>&self::$relations
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* This method receives each expression and analizes
|
||||
* the best way to act and to store the understood
|
||||
* structure
|
||||
*
|
||||
* @param String $expression
|
||||
* @param String $structure
|
||||
* @param Array $structureKeys
|
||||
* @return Boolean True if everything went ok, false when any error occurred
|
||||
* Prints out the analyzed content
|
||||
* @param boolean $detailed Pass true if it should show detailed
|
||||
* information about the entities and properties.
|
||||
* @param boolean $showEntities=true
|
||||
* @param boolean $showRelations=true
|
||||
*/
|
||||
public static function analize($expression, $structure, $structureKeys){
|
||||
|
||||
// setting up
|
||||
$tmpProperties= Array();
|
||||
$i= 0;
|
||||
$focus= null;
|
||||
$linkVerb= null;
|
||||
$min= null;
|
||||
$max= 'n';
|
||||
$linkType= 'action';
|
||||
|
||||
// foreach token
|
||||
foreach($structureKeys as $token)
|
||||
public static function printWhatYouGet($detailed=true,
|
||||
$showEntities=true,
|
||||
$showRelations=true)
|
||||
{
|
||||
$props= 0;
|
||||
if($showEntities)
|
||||
{
|
||||
$word= $expression[$i];
|
||||
$i++;
|
||||
// storing the current used verb
|
||||
if($token==Tokenizer::MT_VERB)
|
||||
echo "ENTITIES: ".sizeof(self::$entities)."\n";
|
||||
foreach(self::$entities as $k=>$entity)
|
||||
{
|
||||
$linkVerb= $word;
|
||||
continue;
|
||||
}
|
||||
|
||||
if(
|
||||
$min == null &&
|
||||
(
|
||||
$token == Tokenizer::MT_NONE ||
|
||||
$token == Tokenizer::MT_ONE
|
||||
)
|
||||
)
|
||||
{
|
||||
$min= ($token == Tokenizer::MT_ONE)? 1: 0;
|
||||
continue;
|
||||
}
|
||||
if(
|
||||
$min != null &&
|
||||
(
|
||||
$token == Tokenizer::MT_MANY ||
|
||||
$token == Tokenizer::MT_ONE
|
||||
)
|
||||
)
|
||||
{
|
||||
$max= ($token == Tokenizer::MT_ONE)? 1: 'n';
|
||||
}
|
||||
|
||||
// verifying the way the entities will be linked
|
||||
if($token==Tokenizer::MT_QMAY)
|
||||
{
|
||||
$linkType= 'possibility';
|
||||
continue;
|
||||
}
|
||||
if($token==Tokenizer::MT_QMUST)
|
||||
{
|
||||
$linkType= 'must';
|
||||
continue;
|
||||
}
|
||||
|
||||
// if it is a substantive
|
||||
if($token==Tokenizer::MT_SUBST)
|
||||
{
|
||||
// if it is an entity
|
||||
if(MindEntity::isEntity($word))
|
||||
if(!$detailed)
|
||||
{
|
||||
// yeah, I know it looks crazy, but try to follow my thoughts
|
||||
// let's instantiate a new Entity in case it has not been
|
||||
// instantiated before
|
||||
if(!isset(self::$entities[$word]))
|
||||
self::$entities[$word]= new MindEntity($word);
|
||||
|
||||
// each instruction *should* have one focused entity
|
||||
// we will use the first entity on each expression as focus
|
||||
if(!$focus)
|
||||
{
|
||||
$focus= self::$entities[$word];
|
||||
}else{
|
||||
/*
|
||||
* here, if it is an entity and the focused
|
||||
* entity has already been selected, it means
|
||||
* it is the second entity on the instruction, so,
|
||||
* it is a relation between entities(or should be)
|
||||
*/
|
||||
$rel= self::$entities[$word];
|
||||
/*
|
||||
* we will use this relationName as index on an
|
||||
* indexed array to speed up the search for
|
||||
* relations in the future
|
||||
*/
|
||||
$relationName= $focus->name."_".$rel->name;
|
||||
|
||||
// let's create the relation itself
|
||||
$curRelation= new MindRelation($relationName);
|
||||
$curRelation->setLinkType($linkType)
|
||||
->setMin($min)
|
||||
->setMax($max)
|
||||
->setUsedVerb($linkVerb)
|
||||
->setEntities($focus, $rel);
|
||||
// now, both entities will POINT to the same relation
|
||||
$focus->addRef($curRelation);
|
||||
$rel->addRef($curRelation);
|
||||
|
||||
// and let's use the relation name as index, as said before
|
||||
self::$relations[$relationName]= &$curRelation;
|
||||
}
|
||||
echo " ".$entity->name.
|
||||
"\n";
|
||||
}else{
|
||||
// ok, after that, this is just easy, now :)
|
||||
// let's store all the properties to a temporary array
|
||||
$tmpProperties[]= new MindProperty($word);
|
||||
echo " ".$entity->name.
|
||||
"\n";
|
||||
foreach($entity->properties as $prop)
|
||||
{
|
||||
$details= false;
|
||||
$details= Array();
|
||||
if($prop->size)
|
||||
$details[]= $prop->size;
|
||||
if($prop->unique)
|
||||
$details[]= "unique";
|
||||
if($prop->key)
|
||||
$details[]= "key";
|
||||
if($prop->required)
|
||||
$details[]= "not null";
|
||||
if(!is_null($prop->default) && trim($prop->default) != '')
|
||||
$details[]= ($prop->default!= AUTOINCREMENT_DEFVAL)?
|
||||
'"'.$prop->default.'"':
|
||||
"AUTO_INCREMENT";
|
||||
if(sizeof($prop->options) > 0)
|
||||
{
|
||||
$opts= "{".implode("|", array_keys($prop->default))."}";
|
||||
$details[]= $opts;
|
||||
}
|
||||
|
||||
$props++;
|
||||
echo " ".$prop->name.
|
||||
":".$prop->type.
|
||||
"(".
|
||||
implode(", ", $details).
|
||||
")".
|
||||
($prop->refTo? " => ". $prop->refTo[0]->name.
|
||||
".".
|
||||
$prop->refTo[1]->name
|
||||
: "");
|
||||
if($prop->comment)
|
||||
echo "// ".$prop->comment;
|
||||
echo "\n";
|
||||
}
|
||||
}
|
||||
}
|
||||
if($detailed)
|
||||
echo "PROPERTIES: ".$props."\n";
|
||||
}
|
||||
if($showRelations)
|
||||
{
|
||||
echo "RELATIONS:".sizeof(self::$relations)."\n";
|
||||
foreach(self::$relations as $k=>$rel)
|
||||
{
|
||||
if(!$rel)
|
||||
continue;
|
||||
echo " ".$rel->name;
|
||||
if($detailed)
|
||||
{
|
||||
echo ': '.
|
||||
$rel->rel->name.' -> '.
|
||||
$rel->focus->name.
|
||||
($rel->uniqueRef? "[pk]": "").
|
||||
"\n";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// adding the properties to the focused entity
|
||||
// we're doing it now, because according to the selected idiom
|
||||
// the sequence of focused entity and properties may vary
|
||||
if(sizeof($tmpProperties)>0 && $focus)
|
||||
{
|
||||
foreach($tmpProperties as $prop)
|
||||
$focus->addProperty($prop);
|
||||
echo "Relations: ".sizeof(self::$relations)."\n";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Applies normalization rules to the currently analized structure.
|
||||
* This method uses the Normalizer methods and properties to apply
|
||||
* the required rules.
|
||||
*/
|
||||
public static function normalizeIt()
|
||||
{
|
||||
Normalizer::normalize();
|
||||
self::$relations= array_filter(self::$relations);
|
||||
self::$entities= array_filter(self::$entities);
|
||||
}
|
||||
|
||||
/**
|
||||
* Reset the properties of the analyst itself.
|
||||
*/
|
||||
public static function reset()
|
||||
{
|
||||
self::$entities = false;
|
||||
self::$relations= false;
|
||||
self::$entities = Array();
|
||||
self::$relations= Array();
|
||||
self::clearFocused();
|
||||
}
|
||||
|
||||
/**
|
||||
* Sweeps through all the matched expressions.
|
||||
* @param Array $matches
|
||||
*/
|
||||
public static function sweep($matches)
|
||||
{
|
||||
// now we gotta analyze each valid expression
|
||||
foreach($matches as $found)
|
||||
{
|
||||
$len= strlen($found[0]);
|
||||
$expression= array_slice(Token::$words, $found[1], $len);
|
||||
$tokens= array_slice(Token::$spine, $found[1], $len);
|
||||
$struct= $found[0];
|
||||
|
||||
// let's analize it, now
|
||||
// Analyst will store it on its own static structure
|
||||
Analyst::analize($expression, $struct, $tokens);
|
||||
}
|
||||
self::clearFocused();
|
||||
self::normalizeIt();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,220 @@
|
||||
<?php
|
||||
/**
|
||||
* This file is part of theWebMind 3rd generation.
|
||||
* Under Cortex/Analyst structure
|
||||
*
|
||||
* @filesource
|
||||
* @author Felipe Nascimento de Moura <felipenmoura@gmail.com>
|
||||
*/
|
||||
/**
|
||||
* Generic methods to be used by the Normalizer.
|
||||
*
|
||||
* @abstract Normal
|
||||
* @package Cortex
|
||||
* @subpackage Analyst
|
||||
* @author Felipe Nascimento de Moura <felipenmoura@gmail.com>
|
||||
*/
|
||||
abstract class Normal {
|
||||
|
||||
public static $oneByOne = Array();
|
||||
public static $nByN = Array();
|
||||
public static $oneByN = Array();
|
||||
public static $focus = Array();
|
||||
public static $predicate = Array();
|
||||
|
||||
/**
|
||||
* Merges all the poperties from the $rel into the $focus
|
||||
*
|
||||
* @param MindEntity $focus The entity that will receive the other's properties
|
||||
* @param MindEntity $rel The entity which will lose its properties
|
||||
*/
|
||||
public static function mergeProperties(MindEntity &$focus, MindEntity &$rel)
|
||||
{
|
||||
GLOBAL $_MIND;
|
||||
if($_MIND->conf['use_prefix_on_merged_entities'])
|
||||
{
|
||||
$propList= Array();
|
||||
foreach($rel->properties as $prop)
|
||||
{
|
||||
$name= $rel->name.PROPERTY_SEPARATOR.$prop->name;
|
||||
$propList[$name]= $prop;
|
||||
$propList[$name]->setName($name);
|
||||
}
|
||||
$rel->properties= $propList;
|
||||
}
|
||||
$focus->properties= array_merge($focus->properties, $rel->properties);
|
||||
}
|
||||
|
||||
/**
|
||||
* Merges the passed entities.
|
||||
*
|
||||
* Merges the $rel entity into the $focus entity, merging
|
||||
* the properties and relations
|
||||
*
|
||||
* @param MindEntity $focus The main entity
|
||||
* @param MindEntity $rel The weaker entity
|
||||
* @return MindEntity
|
||||
*/
|
||||
public static function mergeEntities(MindEntity &$focus,
|
||||
MindEntity &$rel,
|
||||
MindRelation &$relation)
|
||||
{
|
||||
self::mergeProperties($focus, $rel);
|
||||
Analyst::unsetRelation($relation->opposite);
|
||||
Analyst::unsetRelation($relation);
|
||||
Normalizer::redirectRelations($rel, $focus);
|
||||
Analyst::removeEntity($rel->name);
|
||||
return $focus;
|
||||
}
|
||||
|
||||
/**
|
||||
* Fixes 1:1 relations.
|
||||
* It will fix the relations between the passed entities, as they
|
||||
* will not be merged.
|
||||
*
|
||||
* @param MindEntity $focus The pointed entity
|
||||
* @param MindEntity $rel The weaker entity
|
||||
* @param MindRelation $relation The relation between
|
||||
*/
|
||||
public static function fixOneByOneRelation(MindEntity &$focus,
|
||||
MindEntity &$rel,
|
||||
MindRelation &$relation)
|
||||
{
|
||||
/*
|
||||
* excluir a relação entre a mais forte e a mais fraca
|
||||
* marcar a fk como pk
|
||||
*/
|
||||
Analyst::unsetRelation( Analyst::$relations[$rel->name.
|
||||
PROPERTY_SEPARATOR.
|
||||
$focus->name]);
|
||||
Analyst::$relations[$focus->name.
|
||||
PROPERTY_SEPARATOR.
|
||||
$rel->name]->uniqueRef= true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the relevance amount for the passed entity.
|
||||
*
|
||||
* Gets the pontuation amount for the relevance an entity may have.
|
||||
* It takes many directrizes to define how relevant an entity is.
|
||||
* New parameters for such decision can be added here.
|
||||
*
|
||||
* @param MindEntity $entity The entity to be analysed
|
||||
* @return int The relevance the entity has
|
||||
*/
|
||||
public static function relevanceAmount(MindEntity $entity)
|
||||
{
|
||||
GLOBAL $_MIND;
|
||||
$pts= 0;
|
||||
// if the entity has many properties, it might be important
|
||||
if(sizeof($entity->properties) > $_MIND->conf['big_entities_length'])
|
||||
$pts++;
|
||||
// if the entity has many big fields
|
||||
if(self::hasBigProperties($entity) > $_MIND->conf['big_fields_in_entity'])
|
||||
$pts++;
|
||||
// if it has many relations
|
||||
if(sizeof($entity->relations) >= $_MIND->conf['relations_length'])
|
||||
$pts++;
|
||||
return $pts;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the most and less relevant entities.
|
||||
* Returns an array with the most relevant entity in the first position
|
||||
* and the other entity in the second position
|
||||
*
|
||||
* @param MindEntity $en1
|
||||
* @param MindEntity $en2
|
||||
* @return Array
|
||||
*/
|
||||
public static function setByRelevance(MindEntity &$en1, MindEntity &$en2)
|
||||
{
|
||||
$en1Rlv= $en1->relevance;
|
||||
$en2Rlv= $en2->relevance;
|
||||
$en1Rlv+= self::relevanceAmount($en1);
|
||||
$en2Rlv+= self::relevanceAmount($en2);
|
||||
if($en1Rlv == $en2Rlv)
|
||||
if(strlen($en1->name) > strlen($en2->name))
|
||||
$en1Rlv++;
|
||||
else
|
||||
$en2Rlv++;
|
||||
if($en1Rlv > $en2Rlv)
|
||||
return Array($en1, $en2);
|
||||
else
|
||||
return Array($en2, $en1);
|
||||
}
|
||||
|
||||
/**
|
||||
* Verifies wether the entity has big properties or not.
|
||||
*
|
||||
* Verifies if the entity has properties classified as big.<br/>
|
||||
* If yes, returns the number of big properties found, or
|
||||
* false(0) if no big property has been found
|
||||
*
|
||||
* @param MindEntity $entity
|
||||
* @return boolean|int The number of big properties, or false when none
|
||||
*/
|
||||
public static function hasBigProperties(MindEntity $entity)
|
||||
{
|
||||
GLOBAL $_MIND;
|
||||
$bigFields= 0;
|
||||
foreach($entity->properties as $prop)
|
||||
if( $prop->size > $_MIND->conf['big_fields_size'] ||
|
||||
$prop->type=='text')
|
||||
$bigFields++;
|
||||
return $bigFields;
|
||||
}
|
||||
|
||||
/**
|
||||
* Organizes the relations by its cardinalities.
|
||||
*
|
||||
* Organizes the relations between entities to each group,
|
||||
* separating by n:n, 1:1 or 1:n
|
||||
*
|
||||
*/
|
||||
public static function separateByRelationQuantifiers()
|
||||
{
|
||||
reset(Analyst::$relations);
|
||||
while($rel= current(Analyst::$relations))
|
||||
{
|
||||
next(Analyst::$relations);
|
||||
$relName = $rel->name;
|
||||
$relOtherName= $rel->rel->name.
|
||||
PROPERTY_SEPARATOR.
|
||||
$rel->focus->name;
|
||||
|
||||
if(isset(Analyst::$relations[$relOtherName]))
|
||||
{
|
||||
$otherRel= &Analyst::$relations[$relOtherName];
|
||||
|
||||
Analyst::$relations[$rel->name]->opposite=
|
||||
&Analyst::$relations[$otherRel->name];
|
||||
Analyst::$relations[$otherRel->name]->opposite=
|
||||
&Analyst::$relations[$rel->name];
|
||||
|
||||
// let's look for n/n relations
|
||||
if($otherRel->max=='n' && $rel->max=='n')
|
||||
{
|
||||
self::$nByN[]= &Analyst::$relations[$rel->name];
|
||||
}elseif($otherRel->max==1 && $rel->max==1)
|
||||
{ // 1:1 relation
|
||||
self::$oneByOne[]= &Analyst::$relations[$rel->name];
|
||||
}else{
|
||||
// useless re-definition
|
||||
// if the relation was already specified as 1:n it doesn't
|
||||
// need to be re-specified as n:1
|
||||
Analyst::unsetRelation($otherRel);
|
||||
}
|
||||
}else{
|
||||
if($rel->max == 1)
|
||||
{
|
||||
$tmpFocus= $rel->focus;
|
||||
$rel->setFocus($rel->rel);
|
||||
$rel->setRel($tmpFocus);
|
||||
self::$oneByN[]= &Analyst::$relations[$rel->name];
|
||||
}else
|
||||
self::$oneByN[]= &Analyst::$relations[$rel->name];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,422 @@
|
||||
<?php
|
||||
/**
|
||||
* This file is part of TheWebMind 3rd generation.
|
||||
*
|
||||
* Normalizer components, within the Cortex/Analyst packages.<br/>
|
||||
* Notice that, these packages are being used only for documentation,
|
||||
* not to organize the classes.
|
||||
*
|
||||
* @author Felipe Nascimento de Moura <felipenmoura@gmail.com>
|
||||
* @license licenses/mind3rd.license
|
||||
*/
|
||||
|
||||
/**
|
||||
* Normalizes the data structure.
|
||||
*
|
||||
* Will normalize the data and entities structure
|
||||
* applying rules and patterns. Thanks for
|
||||
* Edgar F. Codd for all he created and wondered
|
||||
* for the Relational Model
|
||||
*
|
||||
* @package Cortex
|
||||
* @subpackage Analyst
|
||||
* @author Felipe Nascimento de Moura <felipenmoura@gmail.com>
|
||||
* @filesource
|
||||
*/
|
||||
class Normalizer extends Normal{
|
||||
|
||||
public static $tmpEntities = Array();
|
||||
public static $tmpRelations = Array();
|
||||
public static $linkedTables = Array();
|
||||
|
||||
/**
|
||||
* Redirects all the relations between entities.
|
||||
*
|
||||
* Redirects all the relations that point to, or are pointed by the
|
||||
* $from entity, to the $to entity.
|
||||
*
|
||||
* @param MindEntity $from Entity which will lose its references
|
||||
* @param MindEntity $to Entity which will be reffered instead
|
||||
*/
|
||||
public static function redirectRelations(MindEntity &$from, MindEntity &$to)
|
||||
{
|
||||
foreach($from->relations as &$rel)
|
||||
{
|
||||
if(!$rel)
|
||||
continue;
|
||||
if($rel->focus->name == $from->name)
|
||||
{
|
||||
$rel->setFocus($to);
|
||||
$rel->rename($rel->rel->name.
|
||||
PROPERTY_SEPARATOR.
|
||||
$rel->focus->name);
|
||||
}else{
|
||||
$rel->setRel($to);
|
||||
$rel->rename($rel->focus->name.
|
||||
PROPERTY_SEPARATOR.
|
||||
$rel->rel->name);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Fixes the 1:1 relations, normalizing them
|
||||
*/
|
||||
public static function fixOneByOneRel()
|
||||
{
|
||||
if(sizeof(self::$oneByOne) == 0)
|
||||
return true;
|
||||
reset(self::$oneByOne);
|
||||
$rel= current(self::$oneByOne);
|
||||
|
||||
foreach(self::$oneByOne as &$rel)
|
||||
{
|
||||
$rel= &Analyst::$relations[$rel->name];
|
||||
|
||||
if($rel->focus === $rel->rel)
|
||||
{
|
||||
// self referred (1)
|
||||
$rel->focus->addAutoPk(true);
|
||||
continue;
|
||||
}
|
||||
|
||||
if(is_null($rel) || is_null($rel->focus) || is_null($rel->rel))
|
||||
continue;
|
||||
// defining the focus
|
||||
$entities= self::setByRelevance($rel->focus, $rel->rel);
|
||||
self::$focus= $entities[0];
|
||||
self::$predicate= $entities[1];
|
||||
|
||||
// let's check the minimun quantifiers
|
||||
if($rel->min== 1 && $rel->opposite->min == 1)
|
||||
{
|
||||
// for 1:1 / 1:1 relations
|
||||
self::mergeEntities(self::$focus, self::$predicate, $rel);
|
||||
}elseif($rel->min== 0 && $rel->opposite->min == 0)
|
||||
{
|
||||
// for 0:1 / 0:1 relations
|
||||
if(Analyst::isItWorthMerging(self::$predicate))
|
||||
{
|
||||
self::mergeEntities(self::$focus, self::$predicate, $rel);
|
||||
}else{
|
||||
self::fixOneByOneRelation(self::$focus,
|
||||
self::$predicate,
|
||||
$rel);
|
||||
}
|
||||
}else{
|
||||
// for 0:1 / 1:1 relations
|
||||
self::fixOneByOneRelation(self::$focus,
|
||||
self::$predicate,
|
||||
$rel);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates an extra entity to link multiple relations.
|
||||
*
|
||||
* Creates the entity to be used as a link between the
|
||||
* other two entities due to an N:N relation
|
||||
*
|
||||
* @param MindRelation $rel
|
||||
* @return MindEntity
|
||||
*/
|
||||
public static function &createNByNEntity(MindRelation &$rel)
|
||||
{
|
||||
$linkTable= false;
|
||||
$relName= $rel->focus->name.
|
||||
PROPERTY_SEPARATOR.
|
||||
$rel->rel->name;
|
||||
$relOtherName= $rel->rel->name.
|
||||
PROPERTY_SEPARATOR.
|
||||
$rel->focus->name;
|
||||
if(isset(Analyst::$entities[$relName]))
|
||||
$linkTable= &Analyst::$entities[$relName];
|
||||
if(isset(Analyst::$entities[$relOtherName]))
|
||||
$linkTable= &Analyst::$entities[$relOtherName];
|
||||
if(!$linkTable)
|
||||
{
|
||||
$linkTable= new MindEntity($relName);
|
||||
Analyst::$entities[$linkTable->name]= $linkTable;
|
||||
}
|
||||
Analyst::$entities[$linkTable->name]->linkTable= Array($rel->focus->name,
|
||||
$rel->rel->name);
|
||||
return Analyst::$entities[$linkTable->name];
|
||||
}
|
||||
|
||||
/**
|
||||
* Create all the relations needed to fix n:n relations.
|
||||
*
|
||||
* It takes the $left and $right entities and set the
|
||||
* $center to reffer to it. The $rel parameter is used
|
||||
* to identifies characteristics from an original
|
||||
* relation, like linkVerb or linkType.
|
||||
*
|
||||
* @param MindEntity $left
|
||||
* @param MindEntity $center
|
||||
* @param MindEntity $right
|
||||
* @param MindRelation $rel
|
||||
*/
|
||||
public static function createNbyNRelations( MindEntity &$left,
|
||||
MindEntity &$center,
|
||||
MindEntity &$right,
|
||||
MindRelation &$rel)
|
||||
{
|
||||
Analyst::addToFocus($left);
|
||||
Analyst::addToFocus($right);
|
||||
$relations= Analyst::addRelationToFocused( $center,
|
||||
$rel->linkType,
|
||||
$rel->linkVerb,
|
||||
0,
|
||||
'n',
|
||||
true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Fixes all the n:n relations
|
||||
*/
|
||||
public static function fixNByNRel()
|
||||
{
|
||||
GLOBAL $_MIND;
|
||||
foreach(self::$nByN as &$rel)
|
||||
{
|
||||
if(!$rel->treated)
|
||||
{
|
||||
if($rel->focus === $rel->rel)
|
||||
{
|
||||
// it is self referred (n)
|
||||
$inflect= Mind::$currentProject['idiom']."\Inflect";
|
||||
$name= $inflect::toPlural($rel->rel->name);
|
||||
$name.= PROPERTY_SEPARATOR.$rel->rel->name;
|
||||
|
||||
if(!isset(Analyst::$entities[$name]))
|
||||
{
|
||||
$tmpEnt= new MindEntity($name);
|
||||
Analyst::$entities[$tmpEnt->name]= $tmpEnt;
|
||||
Analyst::$entities[$tmpEnt->name]->linkTable= true;
|
||||
}
|
||||
$rel->setRel(Analyst::$entities[$name]);
|
||||
|
||||
Analyst::addRelationBetween($rel->focus,
|
||||
$rel->rel,
|
||||
'action',
|
||||
$rel->linkVerb,
|
||||
0,
|
||||
'n',
|
||||
true);
|
||||
|
||||
$rel->focus->addAutoPk(true);
|
||||
$pkName= $_MIND->defaults['pk_prefix'].
|
||||
$rel->focus->name;
|
||||
$fakeFk= new MindProperty();
|
||||
$fakeFk ->setAsKey()
|
||||
->setName($pkName)
|
||||
->setRequired(true)
|
||||
->setType('int')
|
||||
->setRefTo($rel->focus,
|
||||
$rel->focus->pks[$pkName]);
|
||||
$rel->rel->addProperty($fakeFk);
|
||||
|
||||
}else{
|
||||
$entity= self::createNByNEntity($rel);
|
||||
$rel->opposite->treated= true;
|
||||
self::createNbyNRelations($rel->focus,
|
||||
$entity,
|
||||
$rel->rel,
|
||||
$rel);
|
||||
}
|
||||
}
|
||||
Analyst::unsetRelation($rel);
|
||||
Analyst::clearFocused();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds all the foreign keys to all the entities that
|
||||
* may need it.
|
||||
*/
|
||||
public static function addFks()
|
||||
{
|
||||
GLOBAL $_MIND;
|
||||
$fkPrefix= $_MIND->defaults['fk_prefix'];
|
||||
$pkPrefix= $_MIND->defaults['pk_prefix'];
|
||||
foreach(Analyst::$relations as &$relation)
|
||||
{
|
||||
$pointed= $relation->focus;
|
||||
$defaultPkName= $pkPrefix.$pointed->name;
|
||||
if($pointed->hasProperty($defaultPkName)
|
||||
&&
|
||||
$pointed->pks[$defaultPkName]->default==AUTOINCREMENT_DEFVAL)
|
||||
$pks= Array($pointed->pks[$defaultPkName]);
|
||||
else
|
||||
$pks= &$pointed->pks;
|
||||
|
||||
foreach($pks as &$pk)
|
||||
{
|
||||
if($pk->key !== true)
|
||||
continue;
|
||||
$tmpName= $pk->name;
|
||||
$propName= $fkPrefix.preg_replace("/^".$pkPrefix."|".$fkPrefix."/",
|
||||
'',
|
||||
$tmpName);
|
||||
$entity= &$relation->rel;
|
||||
|
||||
// we will mark the linkTables
|
||||
if($pointed->linkTable)
|
||||
{
|
||||
self::$linkedTables[$pointed->name]= &$pointed;
|
||||
}elseif($entity->linkTable)
|
||||
{
|
||||
self::$linkedTables[$entity->name]= &$entity;
|
||||
}
|
||||
|
||||
// we've got to treat the repeated properties
|
||||
if($entity->hasProperty($propName)
|
||||
&&
|
||||
$entity->properties[$propName]->refTo)
|
||||
{
|
||||
$propName= $fkPrefix.$pointed->name.
|
||||
PROPERTY_SEPARATOR.
|
||||
$pk->name;
|
||||
}
|
||||
|
||||
// if there ain't not property with that name already
|
||||
if(!$entity->hasProperty($propName))
|
||||
{
|
||||
// let's create it
|
||||
$fk= new MindProperty();
|
||||
$fk ->setName($propName)
|
||||
->setType('int')
|
||||
->setRefTo($relation->focus, $pk);
|
||||
if(!$entity->selfRef)
|
||||
$fk->setRequired(true);
|
||||
if($relation->uniqueRef)
|
||||
{
|
||||
if(!$entity->linkTable||
|
||||
($entity->linkTable && $entity->hasHardKey())
|
||||
||
|
||||
($entity->linkTable && sizeof($entity->getRefBy())==0)
|
||||
)
|
||||
{
|
||||
$fk->setAsWeakKey();
|
||||
}else{
|
||||
$fk->setAsKey();
|
||||
}
|
||||
}
|
||||
$entity->addProperty($fk);
|
||||
}else{
|
||||
// otherwise, we simply use/change the existing one
|
||||
$entity ->properties[$propName]
|
||||
->setRefTo($relation->focus, $pk);
|
||||
if($relation->uniqueRef)
|
||||
$entity ->properties[$propName]->setAsKey();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds all the primary keys the entities will need.
|
||||
*/
|
||||
public static function addPks()
|
||||
{
|
||||
GLOBAL $_MIND;
|
||||
$pkPrefix= $_MIND->defaults['pk_prefix'];
|
||||
foreach(Analyst::$entities as &$entity)
|
||||
{
|
||||
if( sizeof($entity->pks) == 0
|
||||
&&
|
||||
(!$entity->linkTable || sizeof($entity->getRefBy())>0 ))
|
||||
{
|
||||
$propName= $pkPrefix.$entity->name;
|
||||
if(!$entity->hasProperty($propName))
|
||||
{
|
||||
$pk= new MindProperty();
|
||||
$pk ->setAsKey()
|
||||
->setName($propName)
|
||||
->setDefault(AUTOINCREMENT_DEFVAL)
|
||||
->setRequired(true)
|
||||
->setType('int');
|
||||
$entity->addProperty($pk);
|
||||
}else{
|
||||
$entity->properties[$propName]->setAsKey();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* This method is calledto execute any needed adjust.
|
||||
*/
|
||||
public static function fixOneByNRel()
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Will set the primary and foreign keys to entities.
|
||||
*/
|
||||
public static function setUpKeys()
|
||||
{
|
||||
GLOBAL $_MIND;
|
||||
Analyst::$entities= array_filter(Analyst::$entities);
|
||||
Analyst::$relations= array_filter(Analyst::$relations);
|
||||
|
||||
self::addPks(); // OK
|
||||
self::addFks(); // OK
|
||||
}
|
||||
|
||||
/**
|
||||
* Clears static properties setting them to their default value.
|
||||
* Quite useful when used through a command line single session.
|
||||
*/
|
||||
public static function reset()
|
||||
{
|
||||
self::$oneByOne = false;
|
||||
self::$oneByOne = Array();
|
||||
self::$nByN = false;
|
||||
self::$nByN = Array();
|
||||
self::$oneByN = false;
|
||||
self::$oneByN = Array();
|
||||
self::$focus = false;
|
||||
self::$focus = Array();
|
||||
self::$predicate = false;
|
||||
self::$predicate = Array();
|
||||
self::$linkedTables= false;
|
||||
self::$linkedTables= Array();
|
||||
}
|
||||
|
||||
/**
|
||||
* Normalizes the known structure.
|
||||
*
|
||||
* It will apply the n:n and 1:1 rules, plus setting the
|
||||
* foreign and primary keys to all the entities.
|
||||
* Please, notice that there are rules to be followed here,
|
||||
* such as:<pre>
|
||||
* 1:1 to 1:1 relations will always merge entities
|
||||
* 0:1 to 0:1 relations will always try to identify the less
|
||||
* important and set it to point to the other entity
|
||||
* setting its foreign key as a primary key
|
||||
* 0:1 to 1:1 will decide if it should wether merge or fix the
|
||||
* relation. It will decide it using the following
|
||||
* parameters of decision:
|
||||
* - number of properties: as many, less mergeable
|
||||
* - number of relations: as less reffered,
|
||||
* more mergeable
|
||||
* - big properties: as many big properties,
|
||||
* less mergeable
|
||||
* n:n relations will generate an extra entity, altough,
|
||||
* if the entity with that name already exists, it
|
||||
* takes the existing one.
|
||||
* If the antity ONLY has keys, no pk will be added.
|
||||
* </pre>
|
||||
*/
|
||||
public static function normalize()
|
||||
{
|
||||
self::reset();
|
||||
self::separateByRelationQuantifiers();
|
||||
self::fixOneByOneRel();
|
||||
self::fixNByNRel();
|
||||
self::fixOneByNRel();
|
||||
self::setUpKeys();
|
||||
}
|
||||
}
|
||||
@@ -1,59 +1,79 @@
|
||||
<?php
|
||||
/**
|
||||
* This file is part of TheWebMind 3rd generation.
|
||||
*
|
||||
* Canonic, within the Cortex/Canonic packages.<br/>
|
||||
* Notice that, these packages are being used only for documentation,
|
||||
* not to organize the classes.
|
||||
*
|
||||
* @author Felipe Nascimento de Moura <felipenmoura@gmail.com>
|
||||
* @license licenses/mind3rd.license
|
||||
*/
|
||||
/**
|
||||
* This class will take the content to be used, and take
|
||||
* it to its canonical form.
|
||||
* It extends the Inflect class, from the selected language
|
||||
*
|
||||
* @package cortex.analyst
|
||||
* @author felipe
|
||||
* @author Felipe Nascimento de Moura <felipenmoura@gmail.com>
|
||||
* @package Cortex
|
||||
* @subpackage Canonic
|
||||
*/
|
||||
class Canonic{
|
||||
|
||||
public static $substantives= Array();
|
||||
|
||||
/**
|
||||
* Takes a word to its canonic form(singular/male form)
|
||||
* @param string$word
|
||||
* Takes a word to its canonic form(singular/male form).
|
||||
* @param string $word
|
||||
* @return string
|
||||
*/
|
||||
public static function canonize($word)
|
||||
{
|
||||
$inflec= Mind::$currentProject['idiom']."\Inflect";
|
||||
if(!$inflec::isSingular($word)) /* TODO: fix it*/
|
||||
if(!$inflec::isSingular($word))
|
||||
$word= $inflec::toSingular($word);
|
||||
/*if(self::isFemale($word)) // demands more tests
|
||||
// apparently, female substantives are brought to a wrong male form
|
||||
$word= self::toMale($word);*/
|
||||
return $word;
|
||||
}
|
||||
|
||||
/**
|
||||
* Brings all the words in the Array to their canonical form
|
||||
* @param array $content
|
||||
* Sweeps all the content and take all the substantives
|
||||
* to their canonical form.
|
||||
*
|
||||
* @return Array
|
||||
*/
|
||||
public function sweep()
|
||||
{
|
||||
self::$substantives= false;
|
||||
self::$substantives= Array();
|
||||
$content= Mind::$content;
|
||||
$newContent= Array();
|
||||
|
||||
// PAREI AQUI
|
||||
//print_r(Mind::$content);
|
||||
//echo "\ncanonic--------------------------\n";
|
||||
|
||||
Mind::$tokenizer= new Tokenizer();
|
||||
$ignoreForms= Mind::$currentProject['idiom'].'\IgnoreForms';
|
||||
$verbalizer= Mind::$currentProject['idiom'].'\Verbalizer';
|
||||
|
||||
$posVerb= false;
|
||||
|
||||
foreach($content as $word)
|
||||
{
|
||||
if($ignoreForms::shouldBeIgnored($word))
|
||||
continue;
|
||||
if(!Tokenizer::isQualifier($word) && !Tokenizer::isQuantifier($word))
|
||||
{
|
||||
if(strlen($word) > 1 && ($isVerb= $verbalizer::isVerb($word)))
|
||||
if( strlen($word) > 1
|
||||
&&
|
||||
!isset(self::$substantives[$word])
|
||||
&&
|
||||
($isVerb= $verbalizer::isVerb($word))
|
||||
)
|
||||
{
|
||||
// is a verb
|
||||
$word= $verbalizer::toInfinitive($word);
|
||||
}
|
||||
else{
|
||||
// is a substantive
|
||||
$word= explode(':', $word);
|
||||
$word[0]= Canonic::canonize($word[0]);
|
||||
self::$substantives[$word[0]]= true;
|
||||
$word= implode(':', $word);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,26 +1,40 @@
|
||||
<?php
|
||||
/**
|
||||
* This file is part of TheWebMind 3rd generation.
|
||||
*
|
||||
* Syntaxer, within the Cortex/Syntaxer packages.<br/>
|
||||
* Notice that, these packages are being used only for documentation,
|
||||
* not to organize the classes.
|
||||
*
|
||||
* @author Felipe Nascimento de Moura <felipenmoura@gmail.com>
|
||||
* @license licenses/mind3rd.license
|
||||
*/
|
||||
/**
|
||||
* Identifies and organizes the valid syntaxes on the content.
|
||||
*
|
||||
* This class will work with the tokenized strucure and
|
||||
* the original code, due to identify patterns and apply
|
||||
* any needed rules
|
||||
* any needed rules.
|
||||
* <pre>
|
||||
* Legend:
|
||||
* Q=May have, Must have
|
||||
* S=Substantive
|
||||
* V=Verb
|
||||
* 0,N=Quantifiers
|
||||
* O=Or
|
||||
* C=Complement(like "of", or "de")
|
||||
* C=Complement/Composite(like "of", or "de")
|
||||
* A=Addition(like "," or "and"
|
||||
*
|
||||
* @author felipe
|
||||
*</pre>
|
||||
* @author Felipe Nascimento de Moura <felipenmoura@gmail.com>
|
||||
* @package Cortex
|
||||
* @subpackage Syntaxer
|
||||
*/
|
||||
class Syntaxer {
|
||||
|
||||
public static $sintatics= Array();
|
||||
|
||||
/**
|
||||
* Loads the file which has the list of avaliable sintaxes
|
||||
* @static loadSintaticList
|
||||
* Loads the file which has the list of avaliable sintaxes.
|
||||
*/
|
||||
public static function loadSintaticList()
|
||||
{
|
||||
@@ -36,11 +50,35 @@ class Syntaxer {
|
||||
}
|
||||
|
||||
/**
|
||||
* Sweeps the content to apply the rules and identify patterns
|
||||
* @name sweep
|
||||
* Fetches the identified composed substantives.
|
||||
*
|
||||
* Fixes the composed substantives(defined by the use of
|
||||
* the "of" tokens defined into the qualifiers.xml of the current idiom)
|
||||
*/
|
||||
public function fetchComposedSubstantives()
|
||||
{
|
||||
while(preg_match(COMPOSED_SUBST,
|
||||
Token::$string,
|
||||
$matches,
|
||||
PREG_OFFSET_CAPTURE))
|
||||
{
|
||||
$matches= $matches[0];
|
||||
array_splice(Token::$spine, $matches[1], 3, Token::MT_SUBST);
|
||||
array_splice(Token::$words, $matches[1], 3,
|
||||
Token::$words[$matches[1]].
|
||||
'_'.
|
||||
Token::$words[$matches[1]+2]);
|
||||
Token::$string= preg_replace(COMPOSED_SUBST, 'S', Token::$string, 1);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Sweeps the content to apply the rules and identify patterns.
|
||||
*/
|
||||
public function sweep()
|
||||
{
|
||||
// loading stintatic list: all the avaliable, allowed syntaxes
|
||||
// formats, specified by the selected idiom
|
||||
self::loadSintaticList();
|
||||
|
||||
// mounting the regular expression
|
||||
@@ -48,25 +86,20 @@ class Syntaxer {
|
||||
|
||||
// let's find all the patterns that match
|
||||
// that means that we'll find only expressions with valid syntax
|
||||
$pattern= str_replace('S', 'S((( )?\,( )?S)?)+', $pattern);
|
||||
// reminding that the pattern was dynamicaly created before
|
||||
$pattern= str_replace('S', VALID_SUBST_SYNTAX, $pattern);
|
||||
|
||||
$this->fetchComposedSubstantives();
|
||||
|
||||
// finding the valid syntaxes
|
||||
preg_match_all('/'.$pattern.'/',
|
||||
Token::$string,
|
||||
$matches,
|
||||
PREG_OFFSET_CAPTURE);
|
||||
// as we know it's only one block, we can use it straight
|
||||
// as we know it's only one block, we can use it straightly
|
||||
$matches= $matches[0];
|
||||
|
||||
foreach($matches as $found)
|
||||
{
|
||||
$len= strlen($found[0]);
|
||||
$expression= array_slice(Token::$words, $found[1], $len);
|
||||
$tokens= array_slice(Token::$spine, $found[1], $len);
|
||||
$struct= $found[0];
|
||||
|
||||
// let's analize it, now
|
||||
Analyst::analize($expression, $struct, $tokens);
|
||||
}
|
||||
return $this;
|
||||
Analyst::sweep($matches);
|
||||
return $matches;
|
||||
}
|
||||
}
|
||||
@@ -1,43 +1,68 @@
|
||||
<?php
|
||||
/**
|
||||
* This file is part of TheWebMind 3rd generation.
|
||||
*
|
||||
* Token, within the Cortex/Tokenizer packages.<br/>
|
||||
* Notice that, these packages are being used only for documentation,
|
||||
* not to organize the classes.
|
||||
*
|
||||
* @author Felipe Nascimento de Moura <felipenmoura@gmail.com>
|
||||
* @license licenses/mind3rd.license
|
||||
*/
|
||||
/**
|
||||
* The Token itself.
|
||||
* @author Felipe Nascimento de Moura <felipenmoura@gmail.com>
|
||||
* @package Cortex
|
||||
* @subpackage Tokenizer
|
||||
*/
|
||||
class Token
|
||||
{
|
||||
// Tokens to be used
|
||||
// MT stands for MindTokenizer
|
||||
// MS stands for MindSyntaxer
|
||||
const MT_PERIOD = -2;
|
||||
const MT_PERIOD = -2;
|
||||
const MS_PERIOD = '.';
|
||||
const MT_COMA = -1;
|
||||
const MS_COMA = ',';
|
||||
const MT_VOID = 0;
|
||||
const MS_COMA = ',';
|
||||
const MT_VOID = 0;
|
||||
const MS_VOID = '';
|
||||
const MT_VERB = 1;
|
||||
const MS_VERB = 'V';
|
||||
const MT_SUBST = 2;
|
||||
const MS_SUBST = 'S';
|
||||
const MT_NONE = 4;
|
||||
const MS_NONE = 'N';
|
||||
const MT_ONE = 8;
|
||||
const MT_VERB = 1;
|
||||
const MS_VERB = 'V';
|
||||
const MT_SUBST = 2;
|
||||
const MS_SUBST = 'S';
|
||||
const MT_NONE = 4;
|
||||
const MS_NONE = 'N';
|
||||
const MT_ONE = 8;
|
||||
const MS_ONE = 'N';
|
||||
const MT_OR = 16;
|
||||
const MS_OR = 'O';
|
||||
const MS_OR = 'O';
|
||||
const MT_MANY = 32;
|
||||
const MS_MANY = 'N';
|
||||
const MT_QMUST = 64;
|
||||
const MS_MANY = 'N';
|
||||
const MT_QMUST = 64;
|
||||
const MS_QMUST = 'Q';
|
||||
const MT_QMAY = 128;
|
||||
const MS_QMAY = 'Q';
|
||||
const MT_QMAY = 128;
|
||||
const MS_QMAY = 'Q';
|
||||
const MT_QNOTNULL= 254;
|
||||
const MT_QKEY = 564;
|
||||
const MT_QOF = 1024;
|
||||
const MS_QOF = 'C';
|
||||
const MT_QBE = 2048;
|
||||
const MT_ANY = 4096;
|
||||
const MS_ANY = '*';
|
||||
const MT_QKEY = 564;
|
||||
const MT_QOF =1024;
|
||||
const MS_QOF = 'C';
|
||||
const MT_QBE =2048;
|
||||
const MS_QBE = 'B';
|
||||
const MT_QBRAKE = -4;
|
||||
const MS_QBRAKE = 'b';
|
||||
const MT_ANY =4096;
|
||||
const MS_ANY = '*';
|
||||
|
||||
public static $spine= Array();
|
||||
public static $words= Array();
|
||||
public static $string= '';
|
||||
|
||||
/**
|
||||
* Identifies the word type and adds it to the structure.
|
||||
* As the identified type, the word represents an assumed token.
|
||||
* @param string $word
|
||||
* @return string
|
||||
*/
|
||||
public function add($word)
|
||||
{
|
||||
$ignoreForms= Mind::$currentProject['idiom'].'\IgnoreForms';
|
||||
@@ -123,6 +148,7 @@ class Token
|
||||
if(Tokenizer::isQualifier('be', $word))
|
||||
{
|
||||
self::$spine[]= Token::MT_QBE;
|
||||
self::$string.= Token::MS_QBE;
|
||||
return;
|
||||
}
|
||||
if(Tokenizer::isQualifier('key', $word))
|
||||
@@ -130,6 +156,12 @@ class Token
|
||||
self::$spine[]= Token::MT_QKEY;
|
||||
return;
|
||||
}
|
||||
if(Tokenizer::isQualifier('brake', $word))
|
||||
{
|
||||
self::$spine[]= Token::MT_QBRAKE;
|
||||
self::$string.= Token::MS_QBRAKE;
|
||||
return;
|
||||
}
|
||||
// we know these words are already on its
|
||||
// canonic form, so, we can simply look for
|
||||
// it on the list
|
||||
|
||||
@@ -1,10 +1,22 @@
|
||||
<?php
|
||||
/**
|
||||
* This file is part of TheWebMind 3rd generation.
|
||||
*
|
||||
* Tokenizer, within the Cortex/Tokenizer packages.<br/>
|
||||
* Notice that, these packages are being used only for documentation,
|
||||
* not to organize the classes.
|
||||
*
|
||||
* @author Felipe Nascimento de Moura <felipenmoura@gmail.com>
|
||||
* @license licenses/mind3rd.license
|
||||
*/
|
||||
/**
|
||||
* This class will apply the most important tokens to be used.
|
||||
* It also builds the main structure to compare it to avaliable
|
||||
* sintatics. This structure is called SPINE
|
||||
*
|
||||
* @author felipe
|
||||
* @author Felipe Nascimento de Moura <felipenmoura@gmail.com>
|
||||
* @package Cortex
|
||||
* @subpackage Tokenizer
|
||||
*/
|
||||
class Tokenizer extends Token{
|
||||
|
||||
@@ -16,7 +28,7 @@ class Tokenizer extends Token{
|
||||
public static $dataTypes= Array();
|
||||
|
||||
/**
|
||||
* Parses a string into an array, splited by comas
|
||||
* Parses a string into an array, splited by comas.
|
||||
* @param Mixed $str
|
||||
* @return Array The string splited by comas, ignoring a space after each coma
|
||||
*/
|
||||
@@ -62,6 +74,7 @@ class Tokenizer extends Token{
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads the qualifiers into the class properties.
|
||||
* This method loads and builds the structure required
|
||||
* to use and identify the qualifiers, from a passed XML
|
||||
*
|
||||
@@ -80,17 +93,20 @@ class Tokenizer extends Token{
|
||||
self::$qualifiers['of'] = self::parseByComa($xml->of);
|
||||
self::$qualifiers['be'] = self::parseByComa($xml->be);
|
||||
self::$qualifiers['coma'] = self::parseByComa($xml->coma);
|
||||
self::$qualifiers['unique'] = self::parseByComa($xml->unique);
|
||||
self::$qualifiers['brake'] = self::parseByComa($xml->brake);
|
||||
return self::$qualifiers;
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads the possible types to be accepted
|
||||
* Loads the possible types to be accepted.
|
||||
* @param SimpleXML $xml
|
||||
* @return Array The parsed avaliable types
|
||||
*/
|
||||
public static function loadTypes($xml)
|
||||
{
|
||||
self::$dataTypes['varchar'] = self::parseByComa($xml->varchar);
|
||||
self::$dataTypes['text'] = self::parseByComa($xml->text);
|
||||
self::$dataTypes['char'] = self::parseByComa($xml->char);
|
||||
self::$dataTypes['int'] = self::parseByComa($xml->int);
|
||||
self::$dataTypes['float'] = self::parseByComa($xml->float);
|
||||
@@ -102,6 +118,8 @@ class Tokenizer extends Token{
|
||||
}
|
||||
|
||||
/**
|
||||
* Identifies if the passed word is a quantifier.
|
||||
*
|
||||
* This method verifies whether the passed word is
|
||||
* a valid quantifier in the passed list of quantifiers
|
||||
* or if it is a quantifier, in case a list is not sent
|
||||
@@ -124,6 +142,8 @@ class Tokenizer extends Token{
|
||||
}
|
||||
|
||||
/**
|
||||
* Verifies if the passed word is a qualifier.
|
||||
*
|
||||
* This method verifies whether the passed word is
|
||||
* a valid quantifier in the passed list of qualifiers
|
||||
* or if it is a qualifier, in case a list is not sent
|
||||
@@ -149,9 +169,9 @@ class Tokenizer extends Token{
|
||||
/**
|
||||
* This method is called to load each possible modifier
|
||||
*/
|
||||
public static function loadModifiers()
|
||||
public static function loadModifiers($modifiersSrc= false)
|
||||
{
|
||||
if(!file_exists('sintatics.list'))
|
||||
if(!$modifiersSrc && !file_exists('sintatics.list'))
|
||||
{
|
||||
self::loadSintatics(fopen(Mind::$langPath.Mind::$currentProject['idiom'].
|
||||
'/sintatics.list', 'rb'));
|
||||
@@ -168,10 +188,10 @@ class Tokenizer extends Token{
|
||||
self::loadQualifiers($qlf);
|
||||
self::loadTypes($tps);
|
||||
}else{
|
||||
self::loadSintatics(fopen('sintatics.list', 'rb'));
|
||||
$qnt= simplexml_load_file('quantifiers.xml');
|
||||
$qlf= simplexml_load_file('qualifiers.xml');
|
||||
$tps= simplexml_load_file('datatypes.xml');
|
||||
self::loadSintatics(fopen($modifiersSrc.'sintatics.list', 'rb'));
|
||||
$qnt= simplexml_load_file($modifiersSrc.'quantifiers.xml');
|
||||
$qlf= simplexml_load_file($modifiersSrc.'qualifiers.xml');
|
||||
$tps= simplexml_load_file($modifiersSrc.'datatypes.xml');
|
||||
self::loadQuantifiers($qnt);
|
||||
self::loadQualifiers($qlf);
|
||||
self::loadTypes($tps);
|
||||
@@ -180,15 +200,20 @@ class Tokenizer extends Token{
|
||||
}
|
||||
|
||||
/**
|
||||
* Sweeps the content.
|
||||
*
|
||||
* This method runs through all the words within Mind::$content
|
||||
* and perform all verifications
|
||||
*
|
||||
* @return Array the spine, the whole structure of the abstracted text
|
||||
*/
|
||||
public function sweep()
|
||||
public function sweep($content=false)
|
||||
{
|
||||
$cont= &Mind::$content;
|
||||
|
||||
if($content)
|
||||
$cont= $content;
|
||||
else
|
||||
$cont= &Mind::$content;
|
||||
|
||||
// seek for data types
|
||||
foreach(self::$dataTypes as $type=>$options)
|
||||
{
|
||||
@@ -199,9 +224,10 @@ class Tokenizer extends Token{
|
||||
);
|
||||
}
|
||||
|
||||
foreach($cont as $word)
|
||||
// adding each word as its token
|
||||
for($i=0, $j=sizeof($cont); $i<$j; $i++)
|
||||
{
|
||||
$word= strtolower($word);
|
||||
$word= strtolower($cont[$i]);
|
||||
$this->add($word);
|
||||
}
|
||||
|
||||
|
||||
@@ -70,7 +70,6 @@ class Shell
|
||||
if (false === $command)
|
||||
{
|
||||
$this->output->writeln("\n");
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -133,7 +132,6 @@ class Shell
|
||||
protected function getHeader()
|
||||
{
|
||||
return <<<EOF
|
||||
ZZZZZZZZZZZZZZZZZZZZZ
|
||||
Welcome to the <info>{$this->application->getName()}</info> shell (<comment>{$this->application->getVersion()}</comment>).
|
||||
|
||||
At the prompt, type <comment>help</comment> for some help,
|
||||
|
||||
@@ -7,7 +7,6 @@
|
||||
* the program you want to execute, and the parameters you want
|
||||
* to pass
|
||||
*/
|
||||
|
||||
header('Content-type: text/html; charset=utf-8');
|
||||
if(!isset($_REQ))
|
||||
{
|
||||
|
||||
@@ -34,7 +34,7 @@
|
||||
public static function loadIgnoreList()
|
||||
{
|
||||
if(!file_exists('ignore.list'))
|
||||
$fR= fopen(\Mind::$langPath.\Mind::$l10n->name.'/ignore.list', 'rb');
|
||||
$fR= fopen(\Mind::$langPath.\Mind::$currentProject['idiom'].'/ignore.list', 'rb');
|
||||
else
|
||||
$fR= fopen('ignore.list', 'rb');
|
||||
self::$ignoreList= Array();
|
||||
|
||||
@@ -38,7 +38,10 @@ class Inflect implements \inflection
|
||||
static $singular = array(
|
||||
'/rs$/' => 'r',
|
||||
'/ies$/' => 'y',
|
||||
'/sses$/' => 'ss', // for classes, for example
|
||||
'/ses$/' => 'se', // for cases, for example
|
||||
'/shes$/' => 'sh',
|
||||
'/ss$/' => 'ss',
|
||||
'/s$/' => ''
|
||||
);
|
||||
/*
|
||||
|
||||
@@ -11,6 +11,7 @@
|
||||
-->
|
||||
<root>
|
||||
<varchar>string,characters,chars,varchar,description,desc,obs,observation</varchar>
|
||||
<text>text,desc,description,obs,observation</text>
|
||||
<char>char,character,c,letter,digit</char>
|
||||
<int>int,integer,number</int>
|
||||
<float>float,real,double,money,percentage,perc,precision</float>
|
||||
|
||||
@@ -5,4 +5,5 @@ which
|
||||
whom
|
||||
whose
|
||||
well
|
||||
too
|
||||
too
|
||||
also
|
||||
@@ -12,10 +12,10 @@
|
||||
<upper>ABCDEFGHIJKLMNOPQRSTUVXYZW</upper>
|
||||
<special>."</special>
|
||||
<numbers>1234567890</numbers>
|
||||
<symbols>\/!@#$%*()_-+=,.'":>&<</symbols>
|
||||
<symbols>\/!@#$%*()_-+=,.'":>&<|{}[]</symbols>
|
||||
</validchars>
|
||||
<replacements>
|
||||
<from></from>
|
||||
<to ></to>
|
||||
<from>-</from>
|
||||
<to >_</to>
|
||||
</replacements>
|
||||
</root>
|
||||
|
||||
@@ -14,4 +14,7 @@
|
||||
<be>is,are</be>
|
||||
<key>key,pk,index</key>
|
||||
<coma>and</coma>
|
||||
<unique>unique,single,only,alone</unique>
|
||||
<!-- indicates a change of subject in the middle of a sentence -->
|
||||
<brake>all,each,while,when,but</brake>
|
||||
</root>
|
||||
@@ -1,6 +1,15 @@
|
||||
SVS
|
||||
SBVS
|
||||
SQBVS
|
||||
SQBVNONS
|
||||
SQBVNS
|
||||
SBVNONS
|
||||
SBVNS
|
||||
SQVS
|
||||
SVNONS
|
||||
SVNS
|
||||
SQVNONS
|
||||
SQVNS
|
||||
SQVNS
|
||||
SBS
|
||||
SBNS
|
||||
SBNONS
|
||||
@@ -36,7 +36,7 @@
|
||||
public static function loadIgnoreList()
|
||||
{
|
||||
if(!file_exists('ignore.list'))
|
||||
$fR= fopen(\Mind::$langPath.\Mind::$l10n->name.'/ignore.list', 'rb');
|
||||
$fR= fopen(\Mind::$langPath.\Mind::$currentProject['idiom'].'/ignore.list', 'rb');
|
||||
else
|
||||
$fR= fopen('ignore.list', 'rb');
|
||||
self::$ignoreList= Array();
|
||||
|
||||
@@ -38,16 +38,20 @@ class Verbalizer {
|
||||
'/vo$/' => 'ver',
|
||||
'/i$/' => 'er',
|
||||
'/am$/' => 'ar',
|
||||
'/o$/' => 'ar',
|
||||
'/ndo$/' => 'r',
|
||||
// these rules below are commented on theWebMind because
|
||||
// we wont treat first person sentenses
|
||||
/*'/o$/' => 'ar',
|
||||
'/(ado|ados|ada|adas)$/' => 'ar',
|
||||
'/(.+)o$/' => '$1er',
|
||||
'/(.+)a$/' => '$1er',
|
||||
'/em$/' => 'er',
|
||||
'/remos$/' => 'r',
|
||||
'/emos$/' => 'er',
|
||||
'/mos$/' => 'r',
|
||||
'/ei$/' => '',
|
||||
'/.ei$/' => 'ar',
|
||||
'/(.)ei$/' => '$1er',
|
||||
'/(.)ei$/' => '$1er',*/
|
||||
'/(.+)a$/' => '$1er',
|
||||
'/em$/' => 'er',
|
||||
'/ou$/' => 'ar',
|
||||
'/eu$/' => 'er',
|
||||
'/ás$/' => '',
|
||||
@@ -67,11 +71,14 @@ class Verbalizer {
|
||||
'dei' => 'dar',
|
||||
'dou' => 'dar',
|
||||
'deu' => 'dar',
|
||||
'farão' => 'fazer',
|
||||
'fará' => 'fazer',
|
||||
'dão' => 'dar',
|
||||
'dará' => 'dar',
|
||||
'darão' => 'dar',
|
||||
'terem' => 'ter',
|
||||
'terão' => 'ter'
|
||||
'terão' => 'ter',
|
||||
'amigo' => 'amigo'
|
||||
);
|
||||
|
||||
/**
|
||||
@@ -172,7 +179,7 @@ class Verbalizer {
|
||||
public static function loadVerbs()
|
||||
{
|
||||
if(!file_exists('verbs.list'))
|
||||
$fR= fopen(\Mind::$langPath.\Mind::$l10n->name.'/verbs.list', 'rb');
|
||||
$fR= fopen(\Mind::$langPath.\Mind::$currentProject['idiom'].'/verbs.list', 'rb');
|
||||
else
|
||||
$fR= fopen('verbs.list', 'rb');
|
||||
self::$verbs= Array();
|
||||
|
||||
@@ -11,6 +11,7 @@
|
||||
-->
|
||||
<root>
|
||||
<varchar>string,characteres,varchar,descrição,desc,obs</varchar>
|
||||
<text>text,texto,obs,observação,desc,descrição</text>
|
||||
<char>char,caracter,caractere,letra,digito</char>
|
||||
<int>int,integer,inteiro,dígito,número</int>
|
||||
<float>float,real,double,dinheiro,percentagem,perc,porcentagem,precisão</float>
|
||||
|
||||
@@ -5,4 +5,8 @@ os
|
||||
aos
|
||||
que
|
||||
bem
|
||||
também
|
||||
também
|
||||
tanto
|
||||
somente
|
||||
por
|
||||
em
|
||||
@@ -12,11 +12,10 @@
|
||||
<upper>ABCDEFGHIJKLMNOPQRSTUVXYZW</upper>
|
||||
<special>áéíóúÁÉÍÓÚ"."ÀàÂâêÊîÎôÔûÛãÃõÕẽẼüÜçÇ</special>
|
||||
<numbers>1234567890</numbers>
|
||||
<symbols>\/!@#$%*()_-+=,.'":>&<</symbols>
|
||||
<!--<symbols>\/!@#$%&*()_-+=[]{},.'"</symbols>-->
|
||||
<symbols>\/!@#$%*()_-+=,.'":>&<|{}[]</symbols>
|
||||
</validchars>
|
||||
<replacements>
|
||||
<from>áéíóúÁÉÍÓÚÀàÂâêÊîÎôÔûÛãÃõÕẽẼüÜçÇ</from>
|
||||
<to >aeiouAEIOUAaAaeEiIoOuUaAoOeEuUcC</to>
|
||||
<from>áéíóúÁÉÍÓÚÀàÂâêÊîÎôÔûÛãÃõÕẽẼüÜçÇ-</from>
|
||||
<to >aeiouAEIOUAaAaeEiIoOuUaAoOeEuUcC_</to>
|
||||
</replacements>
|
||||
</root>
|
||||
|
||||
@@ -7,11 +7,13 @@
|
||||
This file describes the words that may be used as qualifiers
|
||||
-->
|
||||
<root>
|
||||
<must>dever,precisar,demandar,necessitar</must>
|
||||
<must>precisa,dever,precisar,demandar,necessitar</must>
|
||||
<may>poder</may>
|
||||
<notnull>obrigatório,not null,notnull,não nulo,requerido,required,necessário</notnull>
|
||||
<of>de,do,da,dos,das</of>
|
||||
<be>é,são,será,serão</be>
|
||||
<be>é,são,será,serão,está,estar,estão,estarão,estará</be>
|
||||
<key>chave,key,pk,indice,índice</key>
|
||||
<coma>e</coma>
|
||||
<coma>e,quanto</coma>
|
||||
<unique>unico,único,isolado,isolada,isoladamente</unique>
|
||||
<brake>todo,cada,qualquer,enquanto</brake>
|
||||
</root>
|
||||
@@ -8,7 +8,7 @@
|
||||
-->
|
||||
<root>
|
||||
<none>nada,nenhum,zero,0,nenhuma</none>
|
||||
<one>um,uma,1,algum,alguma</one>
|
||||
<one>um,uma,1,algum,alguma,único,única,unico,unica</one>
|
||||
<many>uns,alguns,umas,algumas,muito,muita,muitos,vários,muitas,várias,diversos,diversas,n,m,x</many>
|
||||
<or>ou,até,/</or>
|
||||
</root>
|
||||
@@ -1,6 +1,15 @@
|
||||
SVS
|
||||
SBVS
|
||||
SQBVS
|
||||
SQBVNONS
|
||||
SQBVNS
|
||||
SBVNONS
|
||||
SBVNS
|
||||
SQVS
|
||||
SVNONS
|
||||
SVNS
|
||||
SQVNONS
|
||||
SQVNS
|
||||
SQVNS
|
||||
SBS
|
||||
SBNS
|
||||
SBNONS
|
||||
@@ -1143,7 +1143,6 @@ danificar
|
||||
dançar
|
||||
dar
|
||||
dardejar
|
||||
datar
|
||||
datilografar
|
||||
debandar
|
||||
debater
|
||||
|
||||
@@ -13,13 +13,16 @@
|
||||
class Analyze extends MindCommand implements program
|
||||
{
|
||||
private $nameSpace= false;
|
||||
public $autoCommit= false;
|
||||
|
||||
public function configure()
|
||||
{
|
||||
$this->setName('analyze')
|
||||
->setDescription('Analyze the the code for your application')
|
||||
->setRestrict(true)
|
||||
->setDefinition(Array(
|
||||
new InputArgument('namespace', InputArgument::OPTIONAL, 'Analyze an specific namespace')
|
||||
new InputArgument('namespace', InputArgument::OPTIONAL, 'Analyze an specific namespace'),
|
||||
new InputOption('commit', false, InputOption::PARAMETER_NONE, "Commit the result after analisys")
|
||||
))
|
||||
->setHelp(<<<EOT
|
||||
This program will analyze your code, typed on your application directory, on all the files .mnd starting for the main.mnd
|
||||
@@ -34,6 +37,8 @@ EOT
|
||||
if(!parent::execute($input, $output))
|
||||
return false;
|
||||
$this->nameSpace= $input->getArgument('namespace');
|
||||
$this->autoCommit= $input->getOption('commit');
|
||||
Mind::write('thinking');
|
||||
$this->runAction();
|
||||
}
|
||||
|
||||
@@ -44,6 +49,8 @@ EOT
|
||||
return false;
|
||||
if(isset($_REQ['data']['namespace']))
|
||||
$this->nameSpace= $_REQ['data']['namespace'];
|
||||
if(isset($_REQ['data']['commit']))
|
||||
$this->autoCommit= $_REQ['data']['commit'];
|
||||
$this->runAction();
|
||||
}
|
||||
|
||||
@@ -56,34 +63,7 @@ EOT
|
||||
return false;
|
||||
}
|
||||
|
||||
$startingTime= microtime();
|
||||
Mind::$lexer= new Lexer();
|
||||
|
||||
$srcs= Mind::$currentProject['sources'];
|
||||
$main= file_get_contents($srcs.'/main.mnd');
|
||||
|
||||
// search for special/unknown characters
|
||||
if(!Mind::$lexer->sweep($main))
|
||||
return false;
|
||||
// keep substantives and verbs on their canonical form
|
||||
if(!Mind::$canonic->sweep())
|
||||
return false;
|
||||
// mark specific tokens
|
||||
if(!Mind::$tokenizer->sweep())
|
||||
return false;
|
||||
// prepares the model to be used to process data
|
||||
// it transforms the original text into the mind code
|
||||
// itself
|
||||
if(!Mind::$syntaxer->sweep())
|
||||
return false;
|
||||
|
||||
$endingTime= microtime();
|
||||
|
||||
// do NOT print it if you have MANY entities, the webbrowser freezes
|
||||
//print_r(Analyst::getUniverse());
|
||||
echo "Time: ".
|
||||
number_format(((float)$endingTime) - ((float)$startingTime), 4).
|
||||
"s\n";
|
||||
MindProject::analyze();
|
||||
return $this;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,68 +0,0 @@
|
||||
<?php
|
||||
use Symfony\Component\Console\Input\InputArgument,
|
||||
Symfony\Component\Console\Input\InputOption,
|
||||
Symfony\Component\Console;
|
||||
|
||||
class Auth extends Symfony\Component\Console\Command\Command
|
||||
{
|
||||
public function configure()
|
||||
{
|
||||
$this->setName('auth')
|
||||
->setDescription('Autenticate a user')
|
||||
->setDefinition(Array(
|
||||
new InputArgument('login', InputArgument::REQUIRED, 'Login to access')
|
||||
))
|
||||
->setHelp(<<<EOT
|
||||
Sets the user with a password.
|
||||
It is required to run most of the commands
|
||||
EOT
|
||||
);
|
||||
}
|
||||
public function execute(Console\Input\InputInterface $input, Console\Output\OutputInterface $output)
|
||||
{
|
||||
$pw= $this->getPassword(true);
|
||||
echo "\n[OK] ".$input->getArgument('login')." autenticated\n";
|
||||
}
|
||||
|
||||
/**
|
||||
* function taken from: http://www.dasprids.de/blog/2008/08/22/getting-a-password-hidden-from-stdin-with-php-cli
|
||||
* this method should read the user's password not showing any character of their password
|
||||
* @param Booladn $stars if true, show an * for each typed char
|
||||
* @return String password
|
||||
*/
|
||||
private function getPassword($stars = false)
|
||||
{
|
||||
// Get current style
|
||||
$oldStyle = shell_exec('stty -g');
|
||||
|
||||
if ($stars === false) {
|
||||
shell_exec('stty -echo');
|
||||
$password = rtrim(fgets(STDIN), "\n");
|
||||
} else {
|
||||
shell_exec('stty -icanon -echo min 1 time 0');
|
||||
|
||||
$password = '';
|
||||
while (true) {
|
||||
$char = fgetc(STDIN);
|
||||
|
||||
if ($char === "\n") {
|
||||
break;
|
||||
} else if (ord($char) === 127) {
|
||||
if (strlen($password) > 0) {
|
||||
fwrite(STDOUT, "\x08 \x08");
|
||||
$password = substr($password, 0, -1);
|
||||
}
|
||||
} else {
|
||||
fwrite(STDOUT, "*");
|
||||
$password .= $char;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Reset old style
|
||||
shell_exec('stty ' . $oldStyle);
|
||||
|
||||
// Return the password
|
||||
return $password;
|
||||
}
|
||||
}
|
||||
@@ -115,6 +115,7 @@ EOT
|
||||
}
|
||||
|
||||
Mind::copyDir(Mind::$modelsDir.'mind/', $this->projectfile);
|
||||
chmod($this->projectfile, 0777);
|
||||
|
||||
$db= new MindDB();
|
||||
$qr_newProj= "INSERT into project
|
||||
|
||||
@@ -1,22 +0,0 @@
|
||||
<?php
|
||||
use Symfony\Component\Console\Input\InputArgument,
|
||||
Symfony\Component\Console\Input\InputOption,
|
||||
Symfony\Component\Console;
|
||||
|
||||
class Quit extends Symfony\Component\Console\Command\Command
|
||||
{
|
||||
public function configure()
|
||||
{
|
||||
$this->setName('Mind:exit')
|
||||
->setDescription('Finishes the application')
|
||||
->setDefinition(null)
|
||||
->setHelp(<<<EOT
|
||||
Finishes the application, leaving the console;
|
||||
EOT
|
||||
);
|
||||
}
|
||||
public function execute(Console\Input\InputInterface $input, Console\Output\OutputInterface $output)
|
||||
{
|
||||
//exit;
|
||||
}
|
||||
}
|
||||
@@ -1,23 +0,0 @@
|
||||
<?php
|
||||
use Symfony\Component\Console\Input\InputArgument,
|
||||
Symfony\Component\Console\Input\InputOption,
|
||||
Symfony\Component\Console;
|
||||
|
||||
class Quit extends Symfony\Component\Console\Command\Command
|
||||
{
|
||||
public function configure()
|
||||
{
|
||||
$this->setName('quit')
|
||||
->setDescription('Finishes the application')
|
||||
->setDefinition(Array())
|
||||
->setHelp(<<<EOT
|
||||
Finishes the application, leaving the console;
|
||||
EOT
|
||||
);
|
||||
}
|
||||
public function execute(Console\Input\InputInterface $input, Console\Output\OutputInterface $output)
|
||||
{
|
||||
echo "Logging out...\n";
|
||||
exit;
|
||||
}
|
||||
}
|
||||
@@ -13,8 +13,10 @@
|
||||
$this
|
||||
->setName('test')
|
||||
->setDescription('Performs some tests on theWebMind')
|
||||
->setDefinition(array())
|
||||
->setRestrict(false)
|
||||
->setDefinition(Array(
|
||||
new InputOption('unit', '-u', InputOption::PARAMETER_NONE, 'Execute unit tests, also')
|
||||
))
|
||||
->setFileName('RunTest')
|
||||
->setHelp(<<<EOT
|
||||
Executes specific tests and report their results, about the system itself
|
||||
@@ -24,9 +26,44 @@ EOT
|
||||
|
||||
private function action()
|
||||
{
|
||||
GLOBAL $_MIND;
|
||||
$this->runStep1();
|
||||
$this->runStep2();
|
||||
$this->runStep3();
|
||||
if($this->unitTestsAlso)
|
||||
{
|
||||
if(file_exists(_MINDSRC_."/Tests/bundle.list"))
|
||||
{
|
||||
if(!isset($_MIND->conf['phpunit-src']))
|
||||
{
|
||||
// TODO: put it into speaker classes, to use l10n messages
|
||||
echo " You must specify where to find phpUnit classes\n";
|
||||
echo " You can configure it on mind3rd/env/mind.ini ini file\n";
|
||||
echo " changing the phpunit-src ini property\n";
|
||||
return false;
|
||||
}
|
||||
// TODO: it doesn't work yet
|
||||
/*
|
||||
$unitTestsFolder= _MINDSRC_."/Tests/";
|
||||
$unitTestsList= file_get_contents($unitTestsFolder."bundle.list");
|
||||
$unitTestsList= explode("\n", $unitTestsList);
|
||||
|
||||
foreach($unitTestsList as $unitTests)
|
||||
{
|
||||
$unitTests= explode(' ', $unitTests);
|
||||
echo "Applying Unit tests to ".$unitTests[1]."\n";
|
||||
//include_once $unitTestsFolder.$unitTests[0];
|
||||
echo shell_exec("phpunit ".$unitTestsFolder.$unitTests[0]);
|
||||
break;
|
||||
}
|
||||
*/
|
||||
}else
|
||||
{
|
||||
// TODO: send it to the speaker
|
||||
echo "[Error] Unit Tests not fount in [root]/Tests\n";
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function runAction()
|
||||
@@ -40,13 +77,23 @@ EOT
|
||||
{
|
||||
if(!parent::execute($input, $output))
|
||||
return false;
|
||||
|
||||
$this->unitTestsAlso= $input->getOption('unit')? true: false;
|
||||
|
||||
return $this->runAction();
|
||||
}
|
||||
|
||||
public function HTTPExecute()
|
||||
{
|
||||
GLOBAL $_REQ;
|
||||
if(!parent::HTTPExecute())
|
||||
return false;
|
||||
|
||||
$this->unitTestsAlso= (isset($_REQ['data'])
|
||||
&&
|
||||
isset($_REQ['data']['unit']))?
|
||||
true: false;
|
||||
|
||||
return $this->runAction();
|
||||
}
|
||||
|
||||
|
||||
@@ -1,30 +0,0 @@
|
||||
<?php
|
||||
|
||||
use Symfony\Component\Console\Input\InputArgument,
|
||||
Symfony\Component\Console\Input\InputOption,
|
||||
Symfony\Component\Console;
|
||||
|
||||
class RunTest extends Symfony\Component\Console\Command\Command
|
||||
{
|
||||
public function configure()
|
||||
{
|
||||
$this
|
||||
->setName('test')
|
||||
->setDescription('Executes arbitrary DQL directly from the command line.')
|
||||
->setDefinition(array())
|
||||
->setHelp(<<<EOT
|
||||
Executes arbitrary DQL directly from the command line.
|
||||
EOT
|
||||
);
|
||||
}
|
||||
public function execute(Console\Input\InputInterface $input, Console\Output\OutputInterface $output)
|
||||
{
|
||||
$this->runStep1();
|
||||
}
|
||||
|
||||
private function runStep1()
|
||||
{
|
||||
Mind::message('Autoloader', '[OK]');
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -78,6 +78,30 @@ EOT
|
||||
$this->printMatrix($userList);
|
||||
}
|
||||
break;
|
||||
case 'entities':
|
||||
$entities= Analyst::getUniverse();
|
||||
$entities= $entities['entities'];
|
||||
if(sizeof($entities) >0)
|
||||
if($this->detailed)
|
||||
Analyst::printWhatYouGet(true, true, false);
|
||||
else
|
||||
echo " ".implode("\n ", array_keys($entities));
|
||||
else
|
||||
echo " No entities to show";
|
||||
echo "\n";
|
||||
break;
|
||||
case 'relations':
|
||||
$relations= Analyst::getUniverse();
|
||||
$relations= $relations['relations'];
|
||||
if(sizeof($relations) >0)
|
||||
if($this->detailed)
|
||||
Analyst::printWhatYouGet(true, false, true);
|
||||
else
|
||||
echo " ".implode("\n ", array_keys($relations));
|
||||
else
|
||||
echo " No relations to show";
|
||||
echo "\n";
|
||||
break;
|
||||
default:
|
||||
Mind::write('invalidOption', true, $this->whatToShow);
|
||||
return false;
|
||||
|
||||
@@ -1,22 +0,0 @@
|
||||
<?php
|
||||
use Symfony\Component\Console\Input\InputArgument,
|
||||
Symfony\Component\Console\Input\InputOption,
|
||||
Symfony\Component\Console;
|
||||
|
||||
class Clear extends Symfony\Component\Console\Command\Command
|
||||
{
|
||||
public function configure()
|
||||
{
|
||||
$this->setName('clear')
|
||||
->setDescription('Clears the console')
|
||||
->setDefinition(array())
|
||||
->setHelp(<<<EOT
|
||||
Clears the console
|
||||
EOT
|
||||
);
|
||||
}
|
||||
public function execute(Console\Input\InputInterface $input, Console\Output\OutputInterface $output)
|
||||
{
|
||||
system('clear');
|
||||
}
|
||||
}
|
||||
@@ -1,32 +0,0 @@
|
||||
<?php
|
||||
use Symfony\Component\Console\Input\InputArgument,
|
||||
Symfony\Component\Console\Input\InputOption,
|
||||
Symfony\Component\Console;
|
||||
|
||||
class CommandName extends Symfony\Component\Console\Command\Command
|
||||
{
|
||||
public function configure()
|
||||
{
|
||||
$this->setName('Mind:commandName')
|
||||
->setDescription('CommandDescription')
|
||||
->setDefinition(array(
|
||||
new InputArgument('arg1', InputArgument::REQUIRED, 'ArgDescription.'),
|
||||
new InputOption(
|
||||
'Option', null, InputOption::PARAMETER_REQUIRED,
|
||||
'Description of the option',
|
||||
'object'
|
||||
),
|
||||
new InputOption(
|
||||
'first-result', null, InputOption::PARAMETER_REQUIRED,
|
||||
'The first result in the result set.'
|
||||
)
|
||||
))
|
||||
->setHelp(<<<EOT
|
||||
Executes arbitrary DQL directly from the command line.
|
||||
EOT
|
||||
);
|
||||
}
|
||||
public function execute(Console\Input\InputInterface $input, Console\Output\OutputInterface $output)
|
||||
{
|
||||
}
|
||||
}
|
||||
@@ -1,3 +1,19 @@
|
||||
<?php
|
||||
|
||||
// setting the general helperSet
|
||||
$helperSet= false;
|
||||
$helperSet= ($helperSet) ?: new Symfony\Component\Console\Helper\HelperSet();
|
||||
$app->setHelperSet($helperSet);
|
||||
|
||||
if(isset($_SERVER['argv']))
|
||||
{
|
||||
$params= $_SERVER['argv'];
|
||||
array_shift($params);
|
||||
}
|
||||
|
||||
|
||||
/* let's load the plugins, if they are allowed */
|
||||
Mind::$triggers= array_keys($app->getCommands());
|
||||
|
||||
$sh= new Symfony\Component\Console\Shell($app);
|
||||
$sh->run();
|
||||
@@ -1,89 +0,0 @@
|
||||
<?php
|
||||
require(_MINDSRC_.'/mind3rd/API/external/Symfony/Component/Console/Shell.php');
|
||||
require(_MINDSRC_.'/mind3rd/API/external/Symfony/Component/Console/Application.php');
|
||||
|
||||
require(_MINDSRC_.'/mind3rd/API/external/Symfony/Component/Console/Command/Command.php');
|
||||
|
||||
use Symfony\Component\Console\Application;
|
||||
use Symfony\Component\Console\Helper\HelperSet;
|
||||
|
||||
$app= new Symfony\Component\Console\Application('teste');
|
||||
$app->addCommands(Array(
|
||||
new RunTest(),
|
||||
new Quit(),
|
||||
new Auth(),
|
||||
new Clear()
|
||||
));
|
||||
|
||||
$helperSet= false;
|
||||
$helperSet = ($helperSet) ?: new Symfony\Component\Console\Helper\HelperSet();
|
||||
$app->setHelperSet($helperSet);
|
||||
|
||||
include_once('external/Symfony/Component/Console/Shell.php');
|
||||
$sh= new external\Symfony\Component\Console\Shell($app);
|
||||
$sh->run();
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* This file receives the shell call for a program,
|
||||
* and parses its parameters, calling the program from the API
|
||||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
|
||||
function shellExecute($command)
|
||||
{
|
||||
GLOBAL $_MIND;
|
||||
readline_completion_function('mmindAutoComplete');
|
||||
if(!is_array($command))
|
||||
$command= explode(' ', $command);
|
||||
$program= array_shift($command); // the first parameter is the program itself
|
||||
try
|
||||
{
|
||||
$program= new $program($command);
|
||||
//echo "\n";
|
||||
}catch(Exception $e){
|
||||
print_r($e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
$fp = fopen("php://stdin", "r");
|
||||
$in = '';
|
||||
if(isset($params[0]))
|
||||
{
|
||||
if($params[0]== 'help' || $params[0]== '-h' || $params[0]== '--help')
|
||||
{
|
||||
new help();
|
||||
exit;
|
||||
}elseif($params[0]== '-u' && isset($params[1]))
|
||||
{
|
||||
new autenticate(Array($params[1]));
|
||||
}
|
||||
}else
|
||||
new clear();
|
||||
echo "Welcome to mind3rd:\nType help to see the help content\n";
|
||||
while($in != "exit")
|
||||
{
|
||||
if(!isset($_SESSION['login']))
|
||||
echo "mind > ";
|
||||
else
|
||||
echo $_SESSION['login'].'@mind > ';
|
||||
$in=trim(fgets($fp));
|
||||
if($in!='exit' && trim($in)!='')
|
||||
{
|
||||
shellExecute($in);
|
||||
}
|
||||
}
|
||||
new clear();
|
||||
exit;
|
||||
*/
|
||||
@@ -9,35 +9,12 @@
|
||||
require(_MINDSRC_.'/mind3rd/API/utils/header.php');
|
||||
include(_MINDSRC_.'/mind3rd/API/utils/constants.php');
|
||||
|
||||
$app= new Symfony\Component\Console\Application('mind');
|
||||
$app->addCommands(Array(
|
||||
new RunTest(),
|
||||
new Quit(),
|
||||
new Auth(),
|
||||
new Clear(),
|
||||
new Info(),
|
||||
new Create(),
|
||||
new Show(),
|
||||
new Analyze(),
|
||||
new SetUse()
|
||||
));
|
||||
|
||||
// setting the general helperSet
|
||||
$helperSet= false;
|
||||
$helperSet= ($helperSet) ?: new Symfony\Component\Console\Helper\HelperSet();
|
||||
$app->setHelperSet($helperSet);
|
||||
|
||||
if(isset($_SERVER['argv']))
|
||||
{
|
||||
$params= $_SERVER['argv'];
|
||||
array_shift($params);
|
||||
}
|
||||
|
||||
// Instantiating the main Mind class
|
||||
/**
|
||||
* @global Mind $_MIND This variable contains many information about the proect, the system and also have some methods an attributes to deal with such data
|
||||
*/
|
||||
$_MIND= new Mind();
|
||||
|
||||
/* let's load the plugins, if they are allowed */
|
||||
Mind::$triggers= array_keys($app->getCommands());
|
||||
if($_MIND->defaults['plugins']==1)
|
||||
{
|
||||
require(_MINDSRC_.'/mind3rd/API/interfaces/plugin.php');
|
||||
@@ -53,6 +30,23 @@
|
||||
$d->close();
|
||||
}
|
||||
|
||||
|
||||
define('SYSTEM_NAME', 'mind');
|
||||
|
||||
|
||||
$app= new Symfony\Component\Console\Application(SYSTEM_NAME);
|
||||
$app->addCommands(Array(
|
||||
new RunTest(),
|
||||
new Quit(),
|
||||
new Auth(),
|
||||
new Clear(),
|
||||
new Info(),
|
||||
new Create(),
|
||||
new Show(),
|
||||
new Analyze(),
|
||||
new SetUse()
|
||||
));
|
||||
|
||||
if($_REQ['env']=='shell')
|
||||
include('shell.php');
|
||||
else
|
||||
|
||||
@@ -1,78 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* This file corresponds to the bootstrap.
|
||||
* Every requisition should pass here
|
||||
* This file decides which environment will be used
|
||||
* and also some permissions, starting some environmental
|
||||
* variables, such as language for localization
|
||||
*/
|
||||
session_start();
|
||||
function __autoload($what)
|
||||
{
|
||||
GLOBAL $_MIND;
|
||||
$what= preg_replace("/[ '\"\.\/]/", '', $what);
|
||||
if(file_exists(_MINDSRC_.'/mind3rd/API/programs/'.$what.'.php'))
|
||||
{
|
||||
include(_MINDSRC_.'/mind3rd/API/programs/'.$what.'.php');
|
||||
return true;
|
||||
}
|
||||
if(strpos($what, '\\')>=0)
|
||||
{
|
||||
$what= explode('\\', $what);
|
||||
$what= array_pop($what);
|
||||
}
|
||||
$dirs= Array(
|
||||
_MINDSRC_.'/mind3rd/API/external/Symfony/Component/Console/Input/',
|
||||
_MINDSRC_.'/mind3rd/API/external/Symfony/Component/Console/Output/',
|
||||
_MINDSRC_.'/mind3rd/API/external/Symfony/Component/Console/Command/',
|
||||
_MINDSRC_.'/mind3rd/API/external/Symfony/Component/Console/Helper/'
|
||||
);
|
||||
for($i=0; $i<sizeof($dirs); $i++)
|
||||
{
|
||||
if(file_exists($dirs[$i].$what.'.php'))
|
||||
{
|
||||
require_once($dirs[$i].$what.'.php');
|
||||
return true;
|
||||
}
|
||||
}
|
||||
echo " [ERROR] Class not found: ".$what."\n";
|
||||
exit;
|
||||
return false;
|
||||
}
|
||||
/*
|
||||
function __autoload($class)
|
||||
{
|
||||
GLOBAL $_MIND;
|
||||
$class= preg_replace("/[ '\"\\\.\/]/", '', $class);
|
||||
if(!isset($_SESSION['auth']) && $class != 'autenticate' && $class != 'help' && $class != 'clear')
|
||||
{
|
||||
$_MIND->write('not_allowed');
|
||||
throw new Exception('');
|
||||
return false;
|
||||
}
|
||||
$f= _MINDSRC_.'/mind3rd/API/programs/'.$class.'.php';
|
||||
if(file_exists($f) && !class_exists($class))
|
||||
require $f;
|
||||
else{
|
||||
$f= _MINDSRC_.'/'.$class.'.php';
|
||||
if(file_exists($f) && !class_exists($class))
|
||||
require $f;
|
||||
else{
|
||||
throw new Exception($_MIND->write('shell_no_such_file', false));
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}*/
|
||||
require('interfaces/program.php');
|
||||
require('classes/Mind.php');
|
||||
if(isset($_SERVER['argv']))
|
||||
{
|
||||
$params= $_SERVER['argv'];
|
||||
array_shift($params);
|
||||
}
|
||||
$_MIND= new Mind();
|
||||
if($_REQ['env']=='shell')
|
||||
include('shell.php');
|
||||
else
|
||||
include('http.php');
|
||||