-
Notifications
You must be signed in to change notification settings - Fork 0
/
DatalogProgram.cpp
108 lines (95 loc) · 3.21 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
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
#include "DatalogProgram.h"
#include <iostream>
#include <algorithm>
DatalogProgram::DatalogProgram() {
}
DatalogProgram::~DatalogProgram() {
// for (unsigned int i = 0; i < schemes.size(); i++) {
// delete schemes.at(i);
// }
// schemes.clear();
// for (unsigned int i = 0; i < facts.size(); i++) {
// delete facts.at(i);
// }
// facts.clear();
// for (unsigned int i = 0; i < queries.size(); i++) {
// delete queries.at(i);
// }
// queries.clear();
// for (unsigned int i = 0; i < rules.size(); i++) {
// delete rules.at(i);
// }
// rules.clear();
}
void DatalogProgram::toString() {
std::cout << "Schemes(" << std::to_string(schemes.size()) << "):\n";
if (!schemes.empty()) {
for (unsigned int i = 0; i < schemes.size(); i++) {
std::cout << " ";
schemes.at(i)->toString();
std::cout << "\n";
}
}
std::cout << "Facts(" << std::to_string(facts.size()) << "):\n";
if (!facts.empty()) {
for (unsigned int i = 0; i < facts.size(); i++) {
std::cout << " ";
facts.at(i)->toString();
std::cout << ".\n";
}
}
std::cout << "Rules(" << std::to_string(rules.size()) << "):\n";
if (!rules.empty()) {
for (unsigned int i = 0; i < rules.size(); i++) {
std::cout << " ";
rules.at(i)->toString();
std::cout << ".\n";
}
}
std::cout << "Queries(" << std::to_string(queries.size()) << "):\n";
if (!queries.empty()) {
for (unsigned int i = 0; i < queries.size(); i++) {
std::cout << " ";
queries.at(i)->toString();
std::cout << "?\n";
}
}
std::cout << "Domain(" << std::to_string(domain.size()) << "):";
if (!domain.empty()) {
std::sort(domain.begin(), domain.end());
for (unsigned int i = 0; i < domain.size(); i++) {
std::cout << "\n " << domain.at(i);
}
}
}
void DatalogProgram::addPredicateSchemes(std::string id, std::vector<Parameter*> parameters) {
Predicate* inPredicate = new Predicate(id, parameters);
schemes.push_back(inPredicate);
}
void DatalogProgram::setDomain(std::vector<std::string> inputDomain) {
domain = inputDomain;
}
void DatalogProgram::addPredicateFacts(std::string id, std::vector<Parameter*> parameters) {
Predicate* inPredicate = new Predicate(id, parameters);
facts.push_back(inPredicate);
}
void DatalogProgram::addPredicateQueries(std::string id, std::vector<Parameter*> parameters) {
Predicate* inPredicate = new Predicate(id, parameters);
queries.push_back(inPredicate);
}
void DatalogProgram::addRuleRules(Predicate* hPredicate, std::vector<Predicate*>bPredicates) {
Rule* inRule = new Rule(hPredicate, bPredicates);
rules.push_back(inRule);
}
std::vector<Predicate *> DatalogProgram::getSchemes() {
return schemes;
}
std::vector<Predicate *> DatalogProgram::getFacts() {
return facts;
}
std::vector<Predicate *> DatalogProgram::getQueries() {
return queries;
}
std::vector<Rule *> DatalogProgram::getRules() {
return rules;
}