fixed bug refered to texts inside parenthesis, for attributes
Esse commit está contido em:
@@ -0,0 +1,18 @@
|
||||
<?php
|
||||
/**
|
||||
* A facade to deal with attributes/properties and methods
|
||||
* related to an entity
|
||||
*
|
||||
* @author felipe
|
||||
*/
|
||||
class MindEntity {
|
||||
|
||||
public static function isEntity($definition)
|
||||
{
|
||||
return strpos($definition, ":")? false: true;
|
||||
}
|
||||
|
||||
public function MindEntity()
|
||||
{
|
||||
}
|
||||
}
|
||||
@@ -75,5 +75,4 @@ class MindProject {
|
||||
Mind::write('projectOpened', true, $p['name']);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
?>
|
||||
}
|
||||
@@ -0,0 +1,101 @@
|
||||
<?php
|
||||
/**
|
||||
* Description of MindProperty
|
||||
*
|
||||
* @author felipe
|
||||
*/
|
||||
class MindProperty {
|
||||
|
||||
public $definition= "";
|
||||
public $name= false;
|
||||
public $type= "text";
|
||||
public $size= 0;
|
||||
public $default= "";
|
||||
public $required= false;
|
||||
public $refTo= false;
|
||||
public $refBy= Array();
|
||||
public $key= false;
|
||||
|
||||
public static function isProperty($definition)
|
||||
{
|
||||
return strpos($definition, ":");
|
||||
}
|
||||
|
||||
public static function isKnown($type)
|
||||
{
|
||||
foreach(Tokenizer::$dataTypes as $k=>$validTypes)
|
||||
if(in_array($type, $validTypes))
|
||||
return $k;
|
||||
return false;
|
||||
}
|
||||
|
||||
public static function isRequired($expression)
|
||||
{
|
||||
$rx= "/".implode('|', Tokenizer::$qualifiers['notnull'])."/i";
|
||||
return (preg_match($rx, $expression))? true: false;
|
||||
}
|
||||
|
||||
public static function isKey($expression)
|
||||
{
|
||||
$rx= "/".implode('|', Tokenizer::$qualifiers['key'])."/i";
|
||||
return (preg_match($rx, $expression))? true: false;
|
||||
}
|
||||
|
||||
private function parse()
|
||||
{
|
||||
$str= $this->definition;
|
||||
$one= 1;
|
||||
|
||||
// identifying the data type
|
||||
$typeStart= strpos($str, ':')+1;
|
||||
$typeEnd= strpos($str, '(');
|
||||
$typeEnd= $typeEnd? $typeEnd- $typeStart: strLen($str);
|
||||
$type= substr($str, $typeStart, $typeEnd);
|
||||
$this->type= $type;
|
||||
if(!self::isKnown($this->type))
|
||||
{
|
||||
//TODO: Darwin::add($this->type);
|
||||
echo "UNKNOWN TYPE...for a while";
|
||||
return false;
|
||||
}
|
||||
|
||||
// identifying the name
|
||||
$this->name= substr($str, 0, $typeStart);
|
||||
|
||||
// identifying details
|
||||
if(preg_match("/\(.*/", $str, $details))
|
||||
{
|
||||
$details= $details[0];
|
||||
|
||||
// identifying the default value
|
||||
if(preg_match("/\".*\"/", $details, $default))
|
||||
{
|
||||
$default= $default[0];
|
||||
$details= str_replace($default, "", $str, $one);
|
||||
|
||||
// checking if the default value isn't a value or a function call
|
||||
if($default[1]=='=' || strtolower(substr($default, 1, 5)) == 'exec:')
|
||||
{
|
||||
$default= preg_replace("/(^(\"=)|(\"exec\:))|(\"$)/i", "", $default);
|
||||
}
|
||||
//$default= preg_replace("/(^\")|(\"$)/", "", $default);
|
||||
$this->default= $default;
|
||||
}
|
||||
|
||||
// identifying if it is required
|
||||
if(self::isRequired($details))
|
||||
$this->required= true;
|
||||
|
||||
// identifying if it is a forced key
|
||||
if(self::isKey($details))
|
||||
$this->key= true;
|
||||
}
|
||||
}
|
||||
|
||||
public function MindProperty($definition)
|
||||
{
|
||||
$this->definition= $definition;
|
||||
$this->parse();
|
||||
echo json_encode($this)."\n";
|
||||
}
|
||||
}
|
||||
@@ -101,13 +101,31 @@ class Lexer
|
||||
|
||||
// the fixed content;
|
||||
$fixed= "";
|
||||
|
||||
// for each charactere on the content
|
||||
// let's remove the invalid ones
|
||||
$inside= 0;
|
||||
for($i=0, $j=sizeof($this->content); $i<$j; ++$i)
|
||||
{
|
||||
$letter= $this->content[$i];
|
||||
if($this->isValidChar($letter))
|
||||
{
|
||||
if($letter == '(')
|
||||
$inside++;
|
||||
if($letter == ')' && $inside>0)
|
||||
$inside--;
|
||||
if($inside > 0)
|
||||
{
|
||||
if($letter == ' ')
|
||||
$letter= $this->tmpSpace;
|
||||
if($letter == ',')
|
||||
$letter= $this->tmpComma;
|
||||
if($letter == '.')
|
||||
$letter= $this->tmpPeriod;
|
||||
}
|
||||
|
||||
$fixed.= $letter;
|
||||
}
|
||||
}
|
||||
|
||||
// preparing the tokens
|
||||
@@ -118,17 +136,10 @@ class Lexer
|
||||
|
||||
// but content between parentheses should be left with
|
||||
// normal spaces, instead of the space token
|
||||
//preg_match_all('/(\(.+?\))|(".+?")/', $fixed, $matches);
|
||||
|
||||
// todo: fix: when the default value, between " has a ) it ends the expression
|
||||
preg_match_all('/(\(.+?\))|(".+?")/', $fixed, $matches);
|
||||
$i= 1;
|
||||
$matches= $matches[0];
|
||||
foreach($matches as $match)
|
||||
{
|
||||
$fixedMatch= str_replace($this->tokens[' '], ' ', $match);
|
||||
$fixed= str_replace($match, $fixedMatch, $fixed, $i);
|
||||
}
|
||||
// restoring the inition format for attribute details
|
||||
$fixed= str_replace($this->tmpSpace, " ", $fixed);
|
||||
$fixed= str_replace($this->tmpComma, ",", $fixed);
|
||||
$fixed= str_replace($this->tmpPeriod, ".", $fixed);
|
||||
|
||||
// let's deal with the \n and multiline comments
|
||||
$fixed= preg_replace("/\n/", $this->tokens[' '], $fixed);
|
||||
@@ -160,9 +171,11 @@ class Lexer
|
||||
{
|
||||
GLOBAL $_MIND;
|
||||
$this->glue= chr('176');
|
||||
$this->tmpSpace = "__MINDTMPSPACEGLUEFORSPACESBETWEENPARENTHESES__";
|
||||
$this->tmpComma = "__MINDTMPCOMAGLUEFORSPACESBETWEENPARENTHESES__";
|
||||
$this->tmpPeriod = "__MINDTMPPERIODGLUEFORSPACESBETWEENPARENTHESES__";
|
||||
$this->lang= Mind::$currentProject['idiom'];
|
||||
$xml= simplexml_load_file(Mind::$langPath.$this->lang.'/lexics.xml');
|
||||
//include(Mind::$langPath.$this->lang.'/Inflect.php');
|
||||
|
||||
$this->validChars = (string)$xml->validchars->lower;
|
||||
$this->validChars.= (string)$xml->validchars->upper;
|
||||
|
||||
@@ -3,6 +3,22 @@
|
||||
* This class is responsable to the analisys 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
|
||||
*/
|
||||
class Analyst {
|
||||
@@ -19,9 +35,28 @@ class Analyst {
|
||||
*/
|
||||
public static function analize($expression, $structure, $structureKeys){
|
||||
|
||||
// let's simply print it as a message, by now
|
||||
//echo implode(' ', $expression).'-'.$structure.'-'.implode('|', $structureKeys)."<br/>\n";
|
||||
|
||||
// foreach token
|
||||
$i= 0;
|
||||
foreach($structureKeys as $token)
|
||||
{
|
||||
//echo $expression[$i]."<hr>";
|
||||
$word= $expression[$i];
|
||||
|
||||
// if it is a substantive
|
||||
if($token==Tokenizer::MT_SUBST)
|
||||
{
|
||||
// if it is an entity
|
||||
if(MindEntity::isEntity($word))
|
||||
{
|
||||
//echo "it is an entity!\n";
|
||||
}else{ // otherwise, it must be a property
|
||||
$tmpProperty= new MindProperty($word);
|
||||
//echo " is a property\n";
|
||||
}
|
||||
}
|
||||
|
||||
$i++;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -189,7 +189,6 @@ class Tokenizer extends Token{
|
||||
{
|
||||
$cont= &Mind::$content;
|
||||
|
||||
|
||||
// seek for data types
|
||||
foreach(self::$dataTypes as $type=>$options)
|
||||
{
|
||||
|
||||
@@ -12,6 +12,6 @@
|
||||
<notnull>not null,notnull,required,needed</notnull>
|
||||
<of>of</of>
|
||||
<be>is,are</be>
|
||||
<key>key,pk,indice</key>
|
||||
<key>key,pk,index</key>
|
||||
<coma>and</coma>
|
||||
</root>
|
||||
@@ -1,8 +1,14 @@
|
||||
include.path=${php.global.include.path}
|
||||
ignore.path=
|
||||
include.path=\
|
||||
${php.global.include.path}
|
||||
php.version=PHP_53
|
||||
phpunit.bootstrap=
|
||||
phpunit.bootstrap.create.tests=false
|
||||
phpunit.configuration=
|
||||
phpunit.suite=
|
||||
source.encoding=UTF-8
|
||||
src.dir=.
|
||||
tags.asp=false
|
||||
tags.short=true
|
||||
tags.short=false
|
||||
test.src.dir=Tests
|
||||
web.root=.
|
||||
|
||||
Referência em uma Nova Issue
Bloquear um usuário