-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathatomese-interpreter
More file actions
100 lines (68 loc) · 2.37 KB
/
atomese-interpreter
File metadata and controls
100 lines (68 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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
/** atomese_interpreter.cc ---
*
* Copyright (C) 2018 OpenCog Foundation
*
* Author: Yidnekachew Wondimu,Bitseat Tadesse and Yenatfanta Shifferaw
*
*/
#include <opencog/atoms/base/Link.h>
#include <opencog/atoms/base/Node.h>
#include <opencog/atomspace/AtomSpace.h>
#include "atomese_representation.h"
#include <opencog/guile/SchemeEval.h>
using namespace opencog;
using namespace std;
AtomSpace *as;
SchemeEval *eval;
Handle interpreter(const Handle &repr){
Handle check = repr->getOutgoingSet()[1];
HandleSeq result = check->getOutgoingSet();
HandleSeq rowseq;
for(const Handle &h : result){
Handle nextresult = h->getOutgoingSet()[0];
rowseq.push_back(nextresult);
}
Handle inner_set_link = repr->getOutgoingSet()[1];
HandleSeq inner_list_link;
HandleSeq outputs;
for (const Handle &h : inner_set_link->getOutgoingSet()){
inner_list_link.push_back(h->getOutgoingSet()[1]);
}
unsigned long j=0;
for(const Handle &handle : inner_list_link){
unsigned long i = handle->getOutgoingSet().size();
HandleSeq inputs;
for(Handle h : handle->getOutgoingSet()){
if(i!=1){
inputs.push_back(h);
}
i--;
}
as = new AtomSpace();
eval = new SchemeEval(as);
eval->eval("(use-modules (opencog exec))");
SchemeEval evaluator;
Handle plus_linked = createLink(inputs, PLUS_LINK);
Handle plus_linked_atom = as->add_atom(plus_linked);
Handle answer = evaluator.apply("cog-execute!", plus_linked_atom);
Handle ss = createLink(LIST_LINK,
rowseq[j++],
answer);
outputs.push_back(ss);
}
Handle final_output = createLink(outputs, SET_LINK);
cout << final_output->to_short_string();
}
int main() {
Handle repr = atomese::load_atomese("/home/bitseat/as-moses/moses/comboreduct/atomese_representation/test1.csv");
SchemeEval evaluator;
try {
throw evaluator.apply("cog-execute!", createLink(PLUS_LINK, createNode(SCHEMA_NODE, "i1"),
createNode(SCHEMA_NODE, "i2")));
}
catch (const opencog::SyntaxException &e) {
Handle h = interpreter(repr);
//cout << "Caught exception \"" << e.what() << "\n";
}
return 0;
}