ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
ilAssLacConditionParser Class Reference
+ Collaboration diagram for ilAssLacConditionParser:

Public Member Functions

 __construct ()
 Construct requirements. More...
 
 parse ($condition)
 Parses the delivered condition and creates a composite tree Structure. More...
 
 getExpressions ()
 

Protected Member Functions

 fetchExpressions ()
 Matches all expressions in the current condition and assign these to the class attribute ConditionParser::$expressions. More...
 
 fetchOperators ()
 Matches all operators in the current condition and assign these to the class attribute ConditionParser::$operators. More...
 
 cannonicalizeCondition ()
 Cannonicalize the condition into a more general form. More...
 
 checkBrackets ()
 
 createNodeArray ()
 Creates an array representing all Nodes in a condition based on the fetched expressions and operators. More...
 
 surroundNegationExpression ($index)
 
 isNegationSurroundedByBrackets ($index)
 

Protected Attributes

 $condition
 
 $expressions
 
 $operators
 
 $index
 
 $spaces
 

Detailed Description

Definition at line 14 of file ilAssLacConditionParser.php.

Constructor & Destructor Documentation

◆ __construct()

ilAssLacConditionParser::__construct ( )

Construct requirements.

Definition at line 56 of file ilAssLacConditionParser.php.

56  {
57  include_once 'Modules/TestQuestionPool/classes/questions/LogicalAnswerCompare/Factory/ilAssLacExpressionManufacturer.php';
58  include_once 'Modules/TestQuestionPool/classes/questions/LogicalAnswerCompare/Factory/ilAssLacOperationManufacturer.php';
59  include_once "Modules/TestQuestionPool/classes/questions/LogicalAnswerCompare/ilAssLacCompositeBuilder.php";
60  }

Member Function Documentation

◆ cannonicalizeCondition()

ilAssLacConditionParser::cannonicalizeCondition ( )
protected

Cannonicalize the condition into a more general form.


It replaces all expression with "n" and all orperators with "o"
so that the result of an condition after cannonicalization could be:

(n o n) o (n o n) o n

Definition at line 112 of file ilAssLacConditionParser.php.

References $condition, ilAssLacExpressionManufacturer\_getInstance(), ilAssLacOperationManufacturer\_getInstance(), isNegationSurroundedByBrackets(), and surroundNegationExpression().

Referenced by parse().

112  {
114  $this->condition = preg_replace($manufacturer->getPattern(), 'n', $this->condition);
116  $this->condition = preg_replace($manufacturer->getPattern(), 'o', $this->condition);
117  $this->condition = preg_replace("/no/", "n o", $this->condition);
118  $this->condition = preg_replace("/on/", "o n", $this->condition);
119 
120  for($i = 0; $i < strlen($this->condition); $i++)
121  {
122  if($this->condition[$i] == "!" && !$this->isNegationSurroundedByBrackets($i))
123  {
124  $this->surroundNegationExpression($i);
125  }
126  }
127  }
static _getInstance()
Get an Instance of ExpressionManufacturer.
static _getInstance()
Get an Instance of OperationManufacturer.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ checkBrackets()

ilAssLacConditionParser::checkBrackets ( )
protected

Definition at line 129 of file ilAssLacConditionParser.php.

Referenced by parse().

130  {
131  $num_brackets_open = substr_count($this->condition, "(");
132  $num_brackets_close = substr_count($this->condition, ")");
133 
134  if($num_brackets_open > $num_brackets_close)
135  {
136  throw new ilAssLacMissingBracket(")");
137  }
138  if($num_brackets_open < $num_brackets_close)
139  {
140  throw new ilAssLacMissingBracket("(");
141  }
142  }
+ Here is the caller graph for this function:

◆ createNodeArray()

ilAssLacConditionParser::createNodeArray ( )
protected

Creates an array representing all Nodes in a condition based on the fetched expressions and operators.


The array has a tree representation which depth is dependent to the bracketing in the condition
The array contains of four main keys to identify the elements:

KeyValuesDescription
type"group", "expression", "operator"The type of the node - Group is used to introduce the next tree depth
valuemixedContains an extracted expression or operation from a condition
nodesarrayContains an node array
Returns
array

Definition at line 166 of file ilAssLacConditionParser.php.

References $index, and array.

Referenced by parse().

167  {
168  $expected = array("n", "(", "!");
169  $group = array();
170  $negation = false;
171 
172  while($this->index < strlen($this->condition))
173  {
174  $a = $this->condition[$this->index];
175  if(trim($this->condition[$this->index]) != "" && in_array($this->condition[$this->index], $expected))
176  {
177  if ($this->condition[$this->index] == ')')
178  {
179  return $group;
180  }
181  else if ($this->condition[$this->index] == 'n')
182  {
183  $group[] = array('type' => 'expression', 'value' => array_shift($this->expressions));
184  $expected = array("o", ")");
185  }
186  else if ($this->condition[$this->index] == 'o')
187  {
188  $group[] = array('type' => 'operator', 'value' => array_shift($this->operators));
189  $expected = array("n", "(", "!");
190  }
191  else if ($this->condition[$this->index] == '(')
192  {
193  $this->index++;
194  $elements = $this->createNodeArray();
195  $group[] = array('type' => "group", "negated" => $negation, 'nodes' => $elements);
196  $negation = false;
197  $expected = array("o",")");
198  }
199  else if($this->condition[$this->index] == "!")
200  {
201  $negation = true;
202  }
203  }
204  elseif(trim($this->condition[$this->index]) != "")
205  {
206  throw new ilAssLacConditionParserException($this->index-$this->spaces+1);
207  }
208  else
209  {
210  $this->spaces++;
211  }
212 
213  $this->index++;
214  }
215  return array('type' => 'group', "negated" => $negation, 'nodes' => $group);
216  }
createNodeArray()
Creates an array representing all Nodes in a condition based on the fetched expressions and operators...
Create styles array
The data for the language used.
+ Here is the caller graph for this function:

◆ fetchExpressions()

ilAssLacConditionParser::fetchExpressions ( )
protected

Matches all expressions in the current condition and assign these to the class attribute ConditionParser::$expressions.

See also
AbstractManufacturer::match()
ExpressionManufacturer::getPattern()
Parser::$expressions

Definition at line 88 of file ilAssLacConditionParser.php.

References ilAssLacExpressionManufacturer\_getInstance().

Referenced by parse().

88  {
90  $this->expressions = $manufacturer->match($this->condition);
91  }
static _getInstance()
Get an Instance of ExpressionManufacturer.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ fetchOperators()

ilAssLacConditionParser::fetchOperators ( )
protected

Matches all operators in the current condition and assign these to the class attribute ConditionParser::$operators.

See also
AbstractManufacturer::match()
OperationManufacturer::getPattern()
Parser::$operators

Definition at line 100 of file ilAssLacConditionParser.php.

References ilAssLacOperationManufacturer\_getInstance().

Referenced by parse().

100  {
102  $this->operators = $manufacturer->match($this->condition);
103  }
static _getInstance()
Get an Instance of OperationManufacturer.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getExpressions()

ilAssLacConditionParser::getExpressions ( )
Returns
array

Definition at line 221 of file ilAssLacConditionParser.php.

References $expressions.

222  {
223  return $this->expressions;
224  }

◆ isNegationSurroundedByBrackets()

ilAssLacConditionParser::isNegationSurroundedByBrackets (   $index)
protected
Parameters
int$index
Returns
boolean

Definition at line 250 of file ilAssLacConditionParser.php.

References $index.

Referenced by cannonicalizeCondition().

251  {
252  $next_bracket = strpos($this->condition, "(", $index+1);
253  $next_expression = strpos($this->condition, "n", $index+1);
254 
255  return $next_bracket !== false & $next_bracket < $next_expression;
256  }
+ Here is the caller graph for this function:

◆ parse()

ilAssLacConditionParser::parse (   $condition)

Parses the delivered condition and creates a composite tree Structure.

Parameters
$condition
See also
CompositeBuilder::create()
Returns
array

Definition at line 70 of file ilAssLacConditionParser.php.

References $condition, cannonicalizeCondition(), checkBrackets(), createNodeArray(), fetchExpressions(), and fetchOperators().

70  {
71  $this->condition = $condition;
72  $this->checkBrackets();
73  $this->fetchExpressions();
74  $this->fetchOperators();
75  $this->cannonicalizeCondition();
76  $nodes = $this->createNodeArray();
77  $compositeBuilder = new ilAssLacCompositeBuilder();
78  return $compositeBuilder->create($nodes);
79  }
cannonicalizeCondition()
Cannonicalize the condition into a more general form.
createNodeArray()
Creates an array representing all Nodes in a condition based on the fetched expressions and operators...
fetchOperators()
Matches all operators in the current condition and assign these to the class attribute ConditionParse...
fetchExpressions()
Matches all expressions in the current condition and assign these to the class attribute ConditionPar...
+ Here is the call graph for this function:

◆ surroundNegationExpression()

ilAssLacConditionParser::surroundNegationExpression (   $index)
protected
Parameters
int$index

Definition at line 229 of file ilAssLacConditionParser.php.

References $index, and $start.

Referenced by cannonicalizeCondition().

230  {
231  $start = strpos($this->condition, "n", $index + 1);
232  $end = false;
233 
234  if($start !== false)
235  {
236  $end = strpos($this->condition, "n", $start + 1);
237  }
238 
239  if($start !== false && $end !== false)
240  {
241  $this->condition = substr_replace($this->condition, "(n o n)", $start, $end - $start + 1);
242  }
243  }
+ Here is the caller graph for this function:

Field Documentation

◆ $condition

ilAssLacConditionParser::$condition
protected

Definition at line 21 of file ilAssLacConditionParser.php.

Referenced by cannonicalizeCondition(), and parse().

◆ $expressions

ilAssLacConditionParser::$expressions
protected

Definition at line 29 of file ilAssLacConditionParser.php.

Referenced by getExpressions().

◆ $index

ilAssLacConditionParser::$index
protected

◆ $operators

ilAssLacConditionParser::$operators
protected

Definition at line 37 of file ilAssLacConditionParser.php.

◆ $spaces

ilAssLacConditionParser::$spaces
protected

Definition at line 51 of file ilAssLacConditionParser.php.


The documentation for this class was generated from the following file: