-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDataReader.cpp
More file actions
81 lines (74 loc) · 2.37 KB
/
DataReader.cpp
File metadata and controls
81 lines (74 loc) · 2.37 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
#include "DataReader.h"
#include <algorithm>
using namespace std;
/**
* Eliminates multiple negations from symbol.
* If symbol is prepended with odd number of negation
* signs returned symbol contains 1 negation symbol.
* Otherwise returned symbol hasn't got any negation symbol.
* @param s Symbol to be examinated (r-value)
* @return symbol with reduced number of negations
*/
string eliminateNegation(string&& s)
{
char neg = '~';
int counter = count(s.begin(), s.end(), neg);
if(counter%2==0)
return s.substr(s.rfind(neg) + 1, s.size());
else
return s.substr(s.rfind(neg), s.size());
}
void DataReader::readData(istream& is, Agenda& agenda, list<CrossOutImplication>& knowledge)
{
string str, sbstr;
string ifThen = "=>";
string conj = "&";
set<string> conditions, statements;
while(is.good() && getline(is, str))
{
if(str.empty())
break;
auto start = 0U;
auto end = str.find(ifThen);
if(end!=string::npos)
{
sbstr = str.substr(start, end-start);
auto sbstart = 0U;
auto sbend = sbstr.find(conj);
while(sbend!=string::npos)
{
conditions.insert(eliminateNegation(sbstr.substr(sbstart, sbend-sbstart)));
sbstart = sbend + conj.length();
sbend = sbstr.find(conj, sbstart);
}
conditions.insert(eliminateNegation(sbstr.substr(sbstart, sbend)));
start = end + ifThen.length();
end = string::npos;
}
sbstr = str.substr(start, end);
start = 0U;
end = sbstr.find(conj);
while(end!=string::npos)
{
statements.insert(eliminateNegation(sbstr.substr(start, end-start)));
start = end + conj.length();
end = sbstr.find(conj, start);
}
statements.insert(eliminateNegation(sbstr.substr(start, end)));
if(conditions.empty())
{
for(auto i:statements)
{
if(agenda.add(i) < 0)
cout << "Uwaga: wykryto sprzeczność: " << i << " & " << Agenda::negated(i) << endl;
}
}
else
{
for(auto i:statements)
knowledge.push_back(CrossOutImplication(conditions, i));
}
conditions.clear();
statements.clear();
}
}