RAPP Platform API
 All Classes Namespaces Files Functions Variables Typedefs
ontology.hpp
Go to the documentation of this file.
1 #ifndef RAPP_CLOUD_ONTOLOGY
2 #define RAPP_CLOUD_ONTOLOGY
3 #include "includes.ihh"
4 namespace rapp {
5 namespace cloud {
14 {
15 public:
23  std::string ontology_class,
24  bool recursive,
25  std::function<void(std::vector<std::string>)> callback,
26  std::string token
27  )
28  : asio_service_http(token), delegate__(callback)
29  {
30  boost::property_tree::ptree tree;
31  tree.put("ontology_class", ontology_class);
32  tree.put("recursive", boost::lexical_cast<std::string>(recursive));
33  std::stringstream ss;
34  boost::property_tree::write_json(ss, tree, false);
35  post_ = ss.str();
36  header_ = "POST /hop/ontology_subclasses_of HTTP/1.1\r\n";
37  callback_ = std::bind(&ontology_subclasses_of::handle_reply, this, std::placeholders::_1);
38  }
39 private:
43  void handle_reply(std::string json)
44  {
45  std::vector<std::string> classes;
46  std::stringstream ss(json);
47  try {
48  boost::property_tree::ptree tree;
49  boost::property_tree::read_json(ss, tree);
50  // JSON reply is: { results: [], error: '' }
51  for (auto child : tree.get_child("results")) {
52  classes.push_back(child.second.get_value<std::string>());
53  }
54  // Check for Errors returned by the platform
55  for (auto child : tree.get_child("error")) {
56  const std::string value = child.second.get_value<std::string>();
57  if (!value.empty()) {
58  std::cerr << "ontology_subclasses_of JSON error: " << value << std::endl;
59  }
60  }
61  }
62  catch (boost::property_tree::json_parser::json_parser_error & je) {
63  std::cerr << "ontology_subclasses_of::handle_reply Error parsing: " << je.filename()
64  << " on line: " << je.line() << std::endl;
65  std::cerr << je.message() << std::endl;
66  }
67  delegate__(classes);
68  }
70  std::function<void(std::vector<std::string> classes)> delegate__;
71 };
80 {
81 public:
88  const std::string ontology_class,
89  bool recursive,
90  std::function<void(std::vector<std::string>)> callback,
91  std::string token
92  )
93  : asio_service_http(token), delegate__(callback)
94  {
95  boost::property_tree::ptree tree;
96  tree.put("ontology_class", ontology_class);
97  tree.put("recursive", boost::lexical_cast<std::string>(recursive));
98  std::stringstream ss;
99  boost::property_tree::write_json(ss, tree, false);
100  post_ = ss.str();
101  header_ = "POST /hop/ontology_superclasses_of HTTP/1.1\r\n";
102  callback_ = std::bind(&ontology_superclasses_of::handle_reply, this, std::placeholders::_1);
103  }
104 private:
108  void handle_reply(std::string json)
109  {
110  std::vector<std::string> classes;
111  std::stringstream ss(json);
112  try {
113  boost::property_tree::ptree tree;
114  boost::property_tree::read_json(ss, tree);
115  // JSON reply is: { results: [], error: '' }
116  for (auto child : tree.get_child("results")) {
117  classes.push_back(child.second.get_value<std::string>());
118  }
119  // Check for Errors returned by the platform
120  for (auto child : tree.get_child("error")) {
121  const std::string value = child.second.get_value<std::string>();
122  if (!value.empty()) {
123  std::cerr << "ontology_superclasses_of JSON error: " << value << std::endl;
124  }
125  }
126  }
127  catch (boost::property_tree::json_parser::json_parser_error & je) {
128  std::cerr << "ontology_superclasses_of::handle_reply Error parsing: " << je.filename()
129  << " on line: " << je.line() << std::endl;
130  std::cerr << je.message() << std::endl;
131  }
132  delegate__(classes);
133  }
135  std::function<void(std::vector<std::string> classes)> delegate__;
136 };
145 {
146 public:
156  const std::string parent_class,
157  const std::string child_class,
158  bool recursive,
159  std::function<void(bool result)> callback,
160  const std::string token
161  )
162  : asio_service_http(token), delegate__(callback)
163  {
164  boost::property_tree::ptree tree;
165  tree.put("parent_class", parent_class);
166  tree.put("child_class", child_class);
167  tree.put("recursive", boost::lexical_cast<std::string>(recursive));
168  std::stringstream ss;
169  boost::property_tree::write_json(ss, tree, false);
170  post_ = ss.str();
171  header_ = "POST /hop/ontology_is_subsuperclass_of HTTP/1.1\r\n";
172  callback_ = std::bind(&ontology_is_subsuperclass_of::handle_reply, this, std::placeholders::_1);
173  }
174 private:
178  void handle_reply(std::string json)
179  {
180  std::vector<std::string> classes;
181  std::stringstream ss(json);
182  bool result;
183  try {
184  boost::property_tree::ptree tree;
185  boost::property_tree::read_json(ss, tree);
186  // JSON reply is: { results: [], trace: [], error: '' }
187  for (auto child : tree.get_child( "result")) {
188  result = child.second.get_value<bool>();
189  }
190  // Check for Errors returned by the platform
191  for (auto child : tree.get_child("error")) {
192  const std::string value = child.second.get_value<std::string>();
193  if (!value.empty()) {
194  std::cerr << "ontology_is_subsuperclass_of JSON error: " << value << std::endl;
195  }
196  }
197  }
198  catch (boost::property_tree::json_parser::json_parser_error & je) {
199  std::cerr << "ontology_is_subsuperclass_of::handle_reply Error parsing: " << je.filename()
200  << " on line: " << je.line() << std::endl;
201  std::cerr << je.message() << std::endl;
202  }
203  delegate__(result);
204  }
206  std::function<void(bool result)> delegate__;
207 };
208 }
209 }
210 #endif
ontology_superclasses_of(const std::string ontology_class, bool recursive, std::function< void(std::vector< std::string >)> callback, std::string token)
Definition: ontology.hpp:87
std::string header_
Header that will be used.
query if sub class is a super class of param
Definition: ontology.hpp:144
get ontology super-classes of query
Definition: ontology.hpp:79
std::string post_
Actual post Data.
get ontology subclass of a query
Definition: ontology.hpp:13
std::function< void(std::vector< std::string > classes)> delegate__
The callback called upon completion of receiving the detected faces.
Definition: ontology.hpp:135
void handle_reply(std::string json)
handle and parse JSON reply
Definition: ontology.hpp:178
std::function< void(std::string)> callback_
Callback Handler - use with std::bind or boost variant.
ontology_is_subsuperclass_of(const std::string parent_class, const std::string child_class, bool recursive, std::function< void(bool result)> callback, const std::string token)
query if a class is the superclass of a subclass
Definition: ontology.hpp:155
void handle_reply(std::string json)
handle and parse JSON reply
Definition: ontology.hpp:108
ontology_subclasses_of(std::string ontology_class, bool recursive, std::function< void(std::vector< std::string >)> callback, std::string token)
constructor for this handler
Definition: ontology.hpp:22
base class for asynchronous http websockets used for connecting to cloud services ...
std::function< void(std::vector< std::string > classes)> delegate__
The callback called upon completion of receiving the detected faces.
Definition: ontology.hpp:70
std::function< void(bool result)> delegate__
The callback called upon completion of receiving the detected faces.
Definition: ontology.hpp:206
void handle_reply(std::string json)
handle and parse JSON reply
Definition: ontology.hpp:43