78 std::vector<std::string> command =
split(commandLine,
' ', 1);
80 if (command.empty()) {
84 if (command[0] ==
"setdepth") {
85 if (command.size() != 2) {
91 }
catch (std::exception&
e) {
92 printError(
"<" + command[1] +
"> is not a valid depth\n");
96 }
else if (command[0] ==
"explain") {
97 std::pair<std::string, std::vector<std::string>> query;
98 if (command.size() != 2) {
99 printError(
"Usage: explain relation_name(\"<string element1>\", <number element2>, ...)\n");
104 }
else if (command[0] ==
"subproof") {
105 std::pair<std::string, std::vector<std::string>> query;
107 if (command.size() <= 1) {
108 printError(
"Usage: subproof relation_name(<label>)\n");
112 label = std::stoi(query.second[0]);
114 }
else if (command[0] ==
"explainnegation") {
115 std::pair<std::string, std::vector<std::string>> query;
116 if (command.size() != 2) {
118 "Usage: explainnegation relation_name(\"<string element1>\", <number element2>, "
130 printInfo(
"The tuple would be an input fact!\n");
135 rules += std::to_string(
i) +
": ";
148 if (variables.size() == 1 && variables[0] ==
"@") {
149 printInfo(
"The tuple exists, cannot explain negation of it!\n");
151 }
else if (variables.size() == 1 && variables[0] ==
"@non_matching") {
152 printInfo(
"The variable bindings don't match, cannot explain!\n");
154 }
else if (variables.size() == 1 && variables[0] ==
"@fact") {
159 std::map<std::string, std::string> varValues;
160 for (
auto var : variables) {
166 }
else if (command[0] ==
"rule" && command.size() == 2) {
167 auto query =
split(command[1],
' ');
168 if (query.size() != 2) {
169 printError(
"Usage: rule <relation name> <rule number>\n");
174 }
catch (std::exception&
e) {
175 printError(
"Usage: rule <relation name> <rule number>\n");
177 }
else if (command[0] ==
"measure") {
180 }
catch (std::exception&
e) {
181 printError(
"Usage: measure <relation name>\n");
183 }
else if (command[0] ==
"output") {
184 if (command.size() == 2) {
187 }
else if (command.size() == 1) {
192 }
else if (command[0] ==
"format") {
193 if (command.size() == 2 && command[1] ==
"json") {
195 }
else if (command.size() == 2 && command[1] ==
"proof") {
200 }
else if (command[0] ==
"exit" || command[0] ==
"q" || command[0] ==
"quit") {
204 }
else if (command[0] ==
"query") {
206 if (command.size() != 2) {
208 "Usage: query <relation1>(<element1>, <element2>, ...), "
209 "<relation2>(<element1>, <element2>, ...), ...\n");
213 std::vector<std::pair<std::string, std::vector<std::string>>>
relations;
215 std::regex relationRegex(
216 "([a-zA-Z0-9_.-]*)[[:blank:]]*\\(([[:blank:]]*([0-9]+|\"[^\"]*\"|[a-zA-Z_][a-zA-Z_0-9]*)("
217 "[[:blank:]]*,[[:blank:]]*(["
219 "9]+|\"[^\"]*\"|[a-zA-Z_][a-zA-Z_0-9]*))*)?\\)",
220 std::regex_constants::extended);
221 std::smatch relationMatcher;
222 std::string relationStr = command[1];
225 while (std::regex_search(relationStr, relationMatcher, relationRegex)) {
226 relations.push_back(parseQueryTuple(relationMatcher[0]));
232 "Usage: query <relation1>(<element1>, <element2>, ...), "
233 "<relation2>(<element1>, <element2>, ...), ...\n");
236 relationStr = relationMatcher.suffix().str();
242 "Usage: query <relation1>(<element1>, <element2>, ...), "
243 "<relation2>(<element1>, <element2>, ...), ...\n");
254 "setdepth <depth>: Set a limit for printed derivation tree height\n"
255 "explain <relation>(<element1>, <element2>, ...): Prints derivation tree\n"
256 "explainnegation <relation>(<element1>, <element2>, ...): Enters an interactive\n"
257 " interface where the non-existence of a tuple can be explained\n"
258 "subproof <relation>(<label>): Prints derivation tree for a subproof, label is\n"
259 " generated if a derivation tree exceeds height limit\n"
260 "rule <relation name> <rule number>: Prints a rule\n"
261 "output <filename>: Write output into a file, or provide empty filename to\n"
263 "format <json|proof>: switch format between json and proof-trees\n"
264 "query <relation1>(<element1>, <element2>, ...), <relation2>(<element1>, <element2>), "
266 "check existence of constant tuples or find solutions for parameterised tuples\n"
267 "for parameterised query, use semicolon to find next solution and dot to break from "
269 "exit: Exits this interface\n\n");