Adjusts to cortex classes

Added a few more comments
created the Normalizer class...next step is to normalize the contextualized data
Esse commit está contido em:
Felipe Nascimento de Moura
2011-02-17 02:43:26 -02:00
commit bd1ca9b03a
5 arquivos alterados com 120 adições e 21 exclusões
+23
Ver Arquivo
@@ -8,26 +8,49 @@
class MindEntity {
public $name;
public $relevance;
public $properties= Array();
public $relations= Array();
/**
* 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
*
* @param MindProperty $property
* @return MindEntity
*/
public function addProperty(MindProperty $property)
{
$this->properties[$property->name]= $property;
return $this;
}
/**
* Adds a reference to the current entity
*
* @param MindRelation $rel
* @return MindEntity
*/
public function addRef(MindRelation &$rel)
{
$this->relations[]= &$rel;
return $this;
}
/**
* Constructor. It receives the name of the new entity
* @param string $word
*/
public function MindEntity($word)
{
$this->name= (string)$word;
+36 -4
Ver Arquivo
@@ -30,6 +30,11 @@
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))
@@ -40,32 +45,55 @@
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 != 'n' && in_array($min, $this->quantifiers))
{
$this->min= $min;
return $this;
}
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 !== 0 && in_array($max, $this->quantifiers))
{
$this->max= $max;
return $this;
}
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;
@@ -73,6 +101,10 @@
return $this;
}
/**
* The constructor, receiving the name of the relation
* @param string $relName
*/
public function MindRelation($relName)
{
$this->name= (string)$relName;
+41 -3
Ver Arquivo
@@ -26,6 +26,11 @@ class Analyst {
public static $entities= Array();
public static $relations= Array();
/**
* Gets the whole interpreted context, with all the
* analysed information
* @return Array
*/
public static function getUniverse()
{
return Array(
@@ -34,9 +39,12 @@ class Analyst {
);
}
/**
* Prints out the analysed content
* @param boolean $detailed
*/
public static function printWhatYouGet($detailed=true)
{
echo "<hr/>";
$props= 0;
echo "Entities: ".sizeof(self::$entities)."\n";
foreach(self::$entities as $entity)
@@ -59,6 +67,14 @@ class Analyst {
echo "Relations: ".sizeof(self::$relations)."\n";
}
public static function normalizeIt()
{
Normalizer::normalize();
}
/**
* Reset the properties of the analyst itself
*/
public static function reset()
{
self::$entities= Array();
@@ -76,6 +92,9 @@ 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
// get it easier for me and for you to understand
// and follow the thoughts
// setting up
$tmpProperties= Array();
@@ -179,12 +198,10 @@ class Analyst {
self::$entities[$focus->name],
self::$entities[$rel->name]);
// now, both entities will POINT to the same relation
//echo $focus->name."-".$rel->name."\n";
$focus->addRef($curRelation);
$rel->addRef($curRelation);
// and let's use the relation name as index, as said before
echo $relationName."--\n";
self::$relations[$relationName]= $curRelation;
}
}else{
@@ -204,4 +221,25 @@ class Analyst {
$focus->addProperty($prop);
}
}
public static function sweep($matches)
{
// let's clear the Analyst memory as it uses static properties
self::reset();
// now we gotta analyse 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::normalizeIt();
}
}
+19
Ver Arquivo
@@ -0,0 +1,19 @@
<?php
/**
* Will normalize the data and entities structure applying
* rules and patterns
*
*
*
* @author felipe
*/
class Normalizer {
public static $tmpEntities= Array();
public static $tmpRelations= Array();
public static function normalize()
{
}
}
+1 -14
Ver Arquivo
@@ -62,21 +62,8 @@ class Syntaxer {
// as we know it's only one block, we can use it straightly
$matches= $matches[0];
// let's clear the Analyst memory as it uses static properties
Analyst::reset();
Analyst::sweep($matches);
// now we gotta analyse 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);
}
return $this;
}
}