ILIAS  release_8 Revision v8.19-1-g4e8f2f9140c
All Data Structures Namespaces Files Functions Variables Modules Pages
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 27 of file ilAssLacConditionParser.php.

Constructor & Destructor Documentation

◆ __construct()

ilAssLacConditionParser::__construct ( )

Construct requirements.

Definition at line 69 of file ilAssLacConditionParser.php.

70  {
71  include_once 'Modules/TestQuestionPool/classes/questions/LogicalAnswerCompare/Factory/ilAssLacExpressionManufacturer.php';
72  include_once 'Modules/TestQuestionPool/classes/questions/LogicalAnswerCompare/Factory/ilAssLacOperationManufacturer.php';
73  include_once "Modules/TestQuestionPool/classes/questions/LogicalAnswerCompare/ilAssLacCompositeBuilder.php";
74  }

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 130 of file ilAssLacConditionParser.php.

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

Referenced by parse().

130  : void
131  {
133  $this->condition = preg_replace($manufacturer->getPattern(), 'n', $this->condition);
135  $this->condition = preg_replace($manufacturer->getPattern(), 'o', $this->condition);
136  $this->condition = preg_replace("/no/", "n o", $this->condition);
137  $this->condition = preg_replace("/on/", "o n", $this->condition);
138 
139  for ($i = 0; $i < strlen($this->condition); $i++) {
140  if ($this->condition[$i] == "!" && !$this->isNegationSurroundedByBrackets($i)) {
142  }
143  }
144  }
static _getInstance()
Get an Instance of ExpressionManufacturer.
static _getInstance()
Get an Instance of OperationManufacturer.
$i
Definition: metadata.php:41
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ checkBrackets()

ilAssLacConditionParser::checkBrackets ( )
protected

Definition at line 146 of file ilAssLacConditionParser.php.

Referenced by parse().

146  : void
147  {
148  $num_brackets_open = substr_count($this->condition, "(");
149  $num_brackets_close = substr_count($this->condition, ")");
150 
151  if ($num_brackets_open > $num_brackets_close) {
152  throw new ilAssLacMissingBracket(")");
153  }
154  if ($num_brackets_open < $num_brackets_close) {
155  throw new ilAssLacMissingBracket("(");
156  }
157  }
+ 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 181 of file ilAssLacConditionParser.php.

References Vendor\Package\$a, and $index.

Referenced by parse().

181  : array
182  {
183  $expected = array("n", "(", "!");
184  $group = array();
185  $negation = false;
186 
187  while ($this->index < strlen($this->condition)) {
188  $a = $this->condition[$this->index];
189  if (trim($this->condition[$this->index]) != "" && in_array($this->condition[$this->index], $expected)) {
190  if ($this->condition[$this->index] == ')') {
191  return $group;
192  } elseif ($this->condition[$this->index] == 'n') {
193  $group[] = array('type' => 'expression', 'value' => array_shift($this->expressions));
194  $expected = array("o", ")");
195  } elseif ($this->condition[$this->index] == 'o') {
196  $group[] = array('type' => 'operator', 'value' => array_shift($this->operators));
197  $expected = array("n", "(", "!");
198  } elseif ($this->condition[$this->index] == '(') {
199  $this->index++;
200  $elements = $this->createNodeArray();
201  $group[] = array('type' => "group", "negated" => $negation, 'nodes' => $elements);
202  $negation = false;
203  $expected = array("o",")");
204  } elseif ($this->condition[$this->index] == "!") {
205  $negation = true;
206  }
207  } elseif (trim($this->condition[$this->index]) != "") {
208  throw new ilAssLacConditionParserException($this->index - $this->spaces + 1);
209  } else {
210  $this->spaces++;
211  }
212 
213  $this->index++;
214  }
215  return array('type' => 'group', "negated" => $negation, 'nodes' => $group);
216  }
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
createNodeArray()
Creates an array representing all Nodes in a condition based on the fetched expressions and operators...
$a
thx to https://mlocati.github.io/php-cs-fixer-configurator for the examples
+ 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 104 of file ilAssLacConditionParser.php.

References ilAssLacExpressionManufacturer\_getInstance().

Referenced by parse().

104  : void
105  {
107  $this->expressions = $manufacturer->match($this->condition);
108  }
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 117 of file ilAssLacConditionParser.php.

References ilAssLacOperationManufacturer\_getInstance().

Referenced by parse().

117  : void
118  {
120  $this->operators = $manufacturer->match($this->condition);
121  }
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.

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

◆ isNegationSurroundedByBrackets()

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

Definition at line 248 of file ilAssLacConditionParser.php.

References $index.

Referenced by cannonicalizeCondition().

249  {
250  $next_bracket = strpos($this->condition, "(", $index + 1);
251  $next_expression = strpos($this->condition, "n", $index + 1);
252 
253  return $next_bracket !== false && $next_bracket < $next_expression;
254  }
+ 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
ilAssLacAbstractComposite

Definition at line 84 of file ilAssLacConditionParser.php.

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

85  {
86  $this->condition = $condition;
87  $this->index = 0;
88  $this->checkBrackets();
89  $this->fetchExpressions();
90  $this->fetchOperators();
91  $this->cannonicalizeCondition();
92  $nodes = $this->createNodeArray();
93  $compositeBuilder = new ilAssLacCompositeBuilder();
94  return $compositeBuilder->create($nodes);
95  }
cannonicalizeCondition()
Cannonicalize the condition into a more general form.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
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...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
+ 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.

Referenced by cannonicalizeCondition().

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

Field Documentation

◆ $condition

ilAssLacConditionParser::$condition
protected

Definition at line 34 of file ilAssLacConditionParser.php.

Referenced by cannonicalizeCondition(), and parse().

◆ $expressions

ilAssLacConditionParser::$expressions
protected

Definition at line 42 of file ilAssLacConditionParser.php.

Referenced by getExpressions().

◆ $index

ilAssLacConditionParser::$index
protected

◆ $operators

ilAssLacConditionParser::$operators
protected

Definition at line 50 of file ilAssLacConditionParser.php.

◆ $spaces

ilAssLacConditionParser::$spaces
protected

Definition at line 64 of file ilAssLacConditionParser.php.


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