ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
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 57 of file ilAssLacConditionParser.php.

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

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

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

Referenced by parse().

118  {
120  $this->condition = preg_replace($manufacturer->getPattern(), 'n', $this->condition);
122  $this->condition = preg_replace($manufacturer->getPattern(), 'o', $this->condition);
123  $this->condition = preg_replace("/no/", "n o", $this->condition);
124  $this->condition = preg_replace("/on/", "o n", $this->condition);
125 
126  for ($i = 0; $i < strlen($this->condition); $i++) {
127  if ($this->condition[$i] == "!" && !$this->isNegationSurroundedByBrackets($i)) {
129  }
130  }
131  }
static _getInstance()
Get an Instance of ExpressionManufacturer.
static _getInstance()
Get an Instance of OperationManufacturer.
$i
Definition: disco.tpl.php:19
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ checkBrackets()

ilAssLacConditionParser::checkBrackets ( )
protected

Definition at line 133 of file ilAssLacConditionParser.php.

Referenced by parse().

134  {
135  $num_brackets_open = substr_count($this->condition, "(");
136  $num_brackets_close = substr_count($this->condition, ")");
137 
138  if ($num_brackets_open > $num_brackets_close) {
139  throw new ilAssLacMissingBracket(")");
140  }
141  if ($num_brackets_open < $num_brackets_close) {
142  throw new ilAssLacMissingBracket("(");
143  }
144  }
+ 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 168 of file ilAssLacConditionParser.php.

References $index.

Referenced by parse().

169  {
170  $expected = array("n", "(", "!");
171  $group = array();
172  $negation = false;
173 
174  while ($this->index < strlen($this->condition)) {
175  $a = $this->condition[$this->index];
176  if (trim($this->condition[$this->index]) != "" && in_array($this->condition[$this->index], $expected)) {
177  if ($this->condition[$this->index] == ')') {
178  return $group;
179  } elseif ($this->condition[$this->index] == 'n') {
180  $group[] = array('type' => 'expression', 'value' => array_shift($this->expressions));
181  $expected = array("o", ")");
182  } elseif ($this->condition[$this->index] == 'o') {
183  $group[] = array('type' => 'operator', 'value' => array_shift($this->operators));
184  $expected = array("n", "(", "!");
185  } elseif ($this->condition[$this->index] == '(') {
186  $this->index++;
187  $elements = $this->createNodeArray();
188  $group[] = array('type' => "group", "negated" => $negation, 'nodes' => $elements);
189  $negation = false;
190  $expected = array("o",")");
191  } elseif ($this->condition[$this->index] == "!") {
192  $negation = true;
193  }
194  } elseif (trim($this->condition[$this->index]) != "") {
195  throw new ilAssLacConditionParserException($this->index - $this->spaces + 1);
196  } else {
197  $this->spaces++;
198  }
199 
200  $this->index++;
201  }
202  return array('type' => 'group', "negated" => $negation, 'nodes' => $group);
203  }
createNodeArray()
Creates an array representing all Nodes in a condition based on the fetched expressions and operators...
+ 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 91 of file ilAssLacConditionParser.php.

References ilAssLacExpressionManufacturer\_getInstance().

Referenced by parse().

92  {
94  $this->expressions = $manufacturer->match($this->condition);
95  }
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 104 of file ilAssLacConditionParser.php.

References ilAssLacOperationManufacturer\_getInstance().

Referenced by parse().

105  {
107  $this->operators = $manufacturer->match($this->condition);
108  }
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 208 of file ilAssLacConditionParser.php.

References $expressions.

209  {
210  return $this->expressions;
211  }

◆ isNegationSurroundedByBrackets()

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

Definition at line 235 of file ilAssLacConditionParser.php.

References $index.

Referenced by cannonicalizeCondition().

236  {
237  $next_bracket = strpos($this->condition, "(", $index + 1);
238  $next_expression = strpos($this->condition, "n", $index + 1);
239 
240  return $next_bracket !== false & $next_bracket < $next_expression;
241  }
+ 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 72 of file ilAssLacConditionParser.php.

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

73  {
74  $this->condition = $condition;
75  $this->checkBrackets();
76  $this->fetchExpressions();
77  $this->fetchOperators();
78  $this->cannonicalizeCondition();
79  $nodes = $this->createNodeArray();
80  $compositeBuilder = new ilAssLacCompositeBuilder();
81  return $compositeBuilder->create($nodes);
82  }
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 216 of file ilAssLacConditionParser.php.

References $end, $index, and $start.

Referenced by cannonicalizeCondition().

217  {
218  $start = strpos($this->condition, "n", $index + 1);
219  $end = false;
220 
221  if ($start !== false) {
222  $end = strpos($this->condition, "n", $start + 1);
223  }
224 
225  if ($start !== false && $end !== false) {
226  $this->condition = substr_replace($this->condition, "(n o n)", $start, $end - $start + 1);
227  }
228  }
$start
Definition: bench.php:8
+ Here is the caller graph for this function:

Field Documentation

◆ $condition

ilAssLacConditionParser::$condition
protected

Definition at line 22 of file ilAssLacConditionParser.php.

Referenced by cannonicalizeCondition(), and parse().

◆ $expressions

ilAssLacConditionParser::$expressions
protected

Definition at line 30 of file ilAssLacConditionParser.php.

Referenced by getExpressions().

◆ $index

ilAssLacConditionParser::$index
protected

◆ $operators

ilAssLacConditionParser::$operators
protected

Definition at line 38 of file ilAssLacConditionParser.php.

◆ $spaces

ilAssLacConditionParser::$spaces
protected

Definition at line 52 of file ilAssLacConditionParser.php.


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