added useful comments and removed the useless ones

Esse commit está contido em:
Felipe Nascimento de Moura
2011-03-07 02:44:55 -03:00
commit a0d96e0824
4 arquivos alterados com 75 adições e 82 exclusões
+9 -11
Ver Arquivo
@@ -35,8 +35,6 @@ class Analyst {
public static function removeEntity($entity)
{
unset(self::$entities[$entity]);
//self::$entities[$entity]= false;
//self::$entities= array_filter(self::$entities);
unset($entity);
}
@@ -86,8 +84,8 @@ class Analyst {
{
if($detailed)
{
echo " (".$entity->relevance.")".$entity->name;
echo "[".$k."]\n";
echo " (".$entity->relevance.")".$entity->name."\n";
//echo "[".$k."]\n";
}
foreach($entity->properties as $prop)
{
@@ -187,7 +185,7 @@ class Analyst {
$focus->addRef($curRelation);
$rel->addRef($curRelation);
$curRelation->uniqueRef= $uniqueRef;
//echo $curRelation->name.' - '.$rel->name.'->'.$focus->name."\n";
// and let's use the relation name as index, as said before
self::$relations[$relationName]= $curRelation;
$arRet[]= &$curRelation;
@@ -231,7 +229,7 @@ class Analyst {
* @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
// 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
@@ -314,9 +312,9 @@ class Analyst {
/*
* 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
* 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],
@@ -326,7 +324,7 @@ class Analyst {
$max);
}
}else{
// ok, after that, this is just easy, now :)
// ok, after that, this is just easy :)
// let's store all the properties to a temporary array
$tmpProperties[]= new MindProperty($word);
}
@@ -378,4 +376,4 @@ class Analyst {
self::clearFocused();
self::normalizeIt();
}
}
}
+1
Ver Arquivo
@@ -82,6 +82,7 @@ abstract class Normal {
// 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;
+64 -59
Ver Arquivo
@@ -48,15 +48,13 @@
return true;
reset(self::$oneByOne);
$rel= current(self::$oneByOne);
//do
//{
foreach(self::$oneByOne as &$rel)
{
$rel= &Analyst::$relations[$rel->name];
if(is_null($rel) || is_null($rel->focus) || is_null($rel->rel))
continue;
echo $rel->name.' - '.$rel->focus->name.' - '.$rel->rel->name."\n";
// defining the focus
$entities= self::setByRelevance($rel->focus, $rel->rel);
self::$focus= $entities[0];
@@ -84,10 +82,16 @@
self::$predicate,
$rel);
}
//}while($rel= next(self::$oneByOne));
}
}
/**
* Creates the entity to be used as a link between other two
* entities due to an N:N relation
*
* @param MindRelation $rel
* @return MindEntity
*/
public static function &createNByNEntity(MindRelation &$rel)
{
$linkTable= false;
@@ -109,6 +113,18 @@
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,
@@ -145,6 +161,12 @@
}
}
/**
* Adds all the foreign keys to all the entities that
* may need it.
*
* @global type $_MIND
*/
public static function addFks()
{
GLOBAL $_MIND;
@@ -171,6 +193,10 @@
}
}
/**
* Adds all the primary keys the entities will need.
* @global type $_MIND
*/
public static function addPks()
{
GLOBAL $_MIND;
@@ -196,6 +222,11 @@
}
}
/**
* Will set the primary and foreign keys to entities.
*
* @global Mind $_MIND
*/
public static function setUpKeys()
{
GLOBAL $_MIND;
@@ -204,58 +235,12 @@
self::addFks();
self::addPks();
return;
foreach(Analyst::$entities as &$entity)
{
$pkPrefix= $_MIND->defaults['pk_prefix'];
$fkPrefix= $_MIND->defaults['fk_prefix'];
// checking for foreign keys, first
foreach($entity->relations as &$rel)
{
if(!$rel || $rel->treatedKeys) continue;
if($rel->rel->name == $entity->name)
{
$propName= $fkPrefix.$rel->focus->name;
if(!$entity->hasProperty($propName))
{
$fk= new MindProperty();
$fk ->setName($propName)
->setDefault(AUTOINCREMENT_DEFVAL)
->setRequired(true)
//->setAsKey()
->setType('int')
->setRefTo($rel->focus);
$entity->addProperty($fk);
}else{
$entity ->properties[$propName]
->setRefTo($rel->focus);
}
$rel->treatedKeys= true;
}
}
// now we'll see the primary keys
if(sizeof($entity->properties) != sizeof($entity->pks))
{
$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, true);
}else{
$entity->properties[$propName]->setAsKey();
}
}
}
}
/**
* 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;
@@ -271,14 +256,34 @@
}
/**
* Normalizes the known structure
* 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:
* 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.
*/
public static function normalize()
{
self::reset();
self::separateByRelationQuantifiers(); // ok
self::fixOneByOneRel(); // ok
self::fixNByNRel(); // ok
self::setUpKeys(); // ok
self::separateByRelationQuantifiers();
self::fixOneByOneRel();
self::fixNByNRel();
self::setUpKeys();
}
}
+1 -12
Ver Arquivo
@@ -1,20 +1,9 @@
aluno tem muitos professores.
professores tem muitos alunos
colegas tem muitos irmaos.
irmãos tem vários colegas.
irmao_colega tem data de criação:date;
//aluno_professor tem data:date.
//filho tem vários pais.
//cada pai tem muitas filho.
/*
A universidade tem muitos alunos. Aluno tem nome:varchar, matrícula:int,
cpf:int e identidade:int, endereço:varchar,
telefone:int, data de nascimento:date, sexo:char, graduação:int.
Cada aluno pode estar matriculado em vários cursos sendo que cada curso pode ter muitos alunos matriculados.
Aluno também tem as disciplinas em que está matriculado, lembrando que cada disciplina terá diversos alunos inscritos.
*/
/*
registro tem uma id.
id tem um registro.