-
Notifications
You must be signed in to change notification settings - Fork 0
/
DatalogProgram.cpp
61 lines (43 loc) · 1.49 KB
/
DatalogProgram.cpp
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
#include "DatalogProgram.h"
#include <sstream>
void DatalogProgram::AddScheme(Predicate* scheme) {
schemes.push_back(scheme);
}
void DatalogProgram::AddFact(Predicate* fact) {
facts.push_back(fact);
for (unsigned int i = 0; i < fact->NumParameters(); i++) {
Parameter* parameter = fact->GetParameter(i);
domain.insert(parameter->ToString());
}
}
void DatalogProgram::AddRule(Rule* rule) {
rules.push_back(rule);
}
void DatalogProgram::AddQuery(Predicate* query) {
queries.push_back(query);
}
// Generates a string representation of the DatalogProgram
std::string DatalogProgram::ToString() {
std::stringstream ss;
ss << "Schemes(" << schemes.size() << "):" << std::endl;
for(Predicate* scheme : schemes) {
ss << " " << scheme->ToString() << std::endl;
}
ss << "Facts(" << facts.size() << "):" << std::endl;
for(Predicate* fact : facts) {
ss << " " << fact->ToString() << "." << std::endl;
}
ss << "Rules(" << rules.size() << "):" << std::endl;
for(Rule* rule : rules) {
ss << " " << rule->ToString() << std::endl;
}
ss << "Queries(" << queries.size() << "):" << std::endl;
for(Predicate* query : queries) {
ss << " " << query->ToString() << "?" << std::endl;
}
ss << "Domain(" << domain.size() << "):" << std::endl;
for(auto elem : domain) {
ss << " " << elem << std::endl;
}
return ss.str();
}