-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexpert.class.php
More file actions
112 lines (107 loc) · 2.44 KB
/
expert.class.php
File metadata and controls
112 lines (107 loc) · 2.44 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
<?PHP
class expert
{
public $facts;
public $query;
public $operations = array();
public $vars = array('A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z');
public $vars_value = array(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0);
public $rules = array();
public function __construct($file)
{
foreach ($file as $line)
{
$j = 0;
$this->read_line($line);
$line = trim($line);
$arr1 = array_filter(str_split($line));
if($arr1[$j] === '=')
{
$i = 0;
for ($j=0;$j < count($arr1);$j++)
{
for ($i = 0; $i < 26; $i++)
{
if ($arr1[$j] === $this->vars[$i])
{
$this->vars_value[$i] = 1;
}
}
}
}
}
//$this->change_rules();
}
public function perfomOp($opp)
{
}
public function getvars()
{
$counter = 0;
//facts have been modified in initial status of alphabet.
//done-> echo $this->facts."<br>";
//query alphabet states are displayed in red.
//done-> echo $this->query."<br>";
//echo count($this->operations[2]).'<br>';
foreach ($this->rules as $i)
{
echo '<pre>';
print_r($i);
echo '</pre>';
}
$aaaa = str_split(trim($this->query));
echo '<table><tr><td>Fact</td><td>State</td></tr>';
for($counter = 0; $counter < 26; $counter++)
{
foreach ($aaaa as $item) {
if ($item === $this->vars[$counter]) {
echo '<tr bgcolor="red"><td>' . $this->vars[$counter] . '</td><td>' . $this->vars_value[$counter] . "</td><tr>";
$counter++;
}
}
echo '<tr><td>'.$this->vars[$counter].'</td><td>'.$this->vars_value[$counter]."</td><tr>";
}
echo '</table>';
}
private function read_line($line)
{
$line = trim($line);
if($line[0] != '#')
{
if(preg_match('/^(.*?)#/',$line, $ret))
{
$ret = preg_replace("/#/" , "\0" , $ret);
$ret[0] = preg_replace('/\s\s+/', '', $ret[0]);
$ret[0] = str_replace(' ', '', $ret[0]);
$this->show($ret[0]);
}
else
{
$line = preg_replace('/\s\s+/', '', $line);
$line = str_replace(' ', '' , $line);
$this->show($line);
}
}
}
private function show($line)
{
if($line[0] === '=')
{
$this->facts = $line;
}
else if($line[0] === '?')
$this->query = $line;
else
array_push($this->rules, $line);
}
public function change_rules()
{
$i = 0;
while ($this->rules[$i]) {
$this->rules[$i] = preg_replace('/=>/', '=', $this->rules[$i]);
$this->rules[$i] = preg_replace('/<=/', '_', $this->rules[$i]);
$i++;
}
}
}
?>