knowrob  2.1.0
A Knowledge Base System for Cognition-enabled Robots
OntologyParser.h
Go to the documentation of this file.
1 /*
2  * This file is part of KnowRob, please consult
3  * https://github.com/knowrob/knowrob for license details.
4  */
5 
6 #ifndef KNOWROB_ONTOLOGY_PARSER_H
7 #define KNOWROB_ONTOLOGY_PARSER_H
8 
9 #include <functional>
10 #include <string>
11 #include <raptor.h>
12 #include "knowrob/semweb/TripleContainer.h"
13 #include "knowrob/semweb/TripleFormat.h"
14 #include "knowrob/semweb/Triple.h"
15 #include "knowrob/semweb/GraphSelector.h"
16 #include "knowrob/storage/redland/RaptorContainer.h"
17 
18 namespace knowrob {
22  class OntologyParser {
23  public:
28  OntologyParser(const std::string_view &fileURI, semweb::TripleFormat format);
29 
31 
35  void setFrame(const GraphSelectorPtr &frame) { frame_ = frame; }
36 
40  void setOrigin(std::string_view origin) { origin_ = origin; }
41 
45  void setBlankPrefix(const std::string_view &blankPrefix) { blankPrefix_ = blankPrefix; }
46 
50  void setFilter(const TripleFilter &filter) { filter_ = filter; }
51 
56  bool run(const TripleHandler &callback);
57 
62  void add(raptor_statement *statement, const TripleHandler &callback);
63 
67  void flush(const TripleHandler &callback);
68 
72  auto &imports() const { return imports_; }
73 
74  protected:
75  raptor_uri *uri_;
76  raptor_uri *uriBase_;
77  raptor_parser *parser_;
78  raptor_world *world_;
83  std::vector<std::string> imports_;
84  std::function<int()> doParse_;
85 
87 
88  static raptor_world *createWorld();
89 
90  void applyFrame(Triple *triple);
91 
92  std::shared_ptr<RaptorContainer> currentBatch_;
93  };
94 
95 } // knowrob
96 
97 #endif //KNOWROB_ONTOLOGY_PARSER_H
raptor_parser * parser_
auto & imports() const
void setFrame(const GraphSelectorPtr &frame)
std::function< int()> doParse_
static raptor_world * createWorld()
void setOrigin(std::string_view origin)
OntologyParser(const std::string_view &fileURI, semweb::TripleFormat format)
void setBlankPrefix(const std::string_view &blankPrefix)
raptor_parser * createParser(knowrob::semweb::TripleFormat format)
GraphSelectorPtr frame_
void applyFrame(Triple *triple)
void setFilter(const TripleFilter &filter)
bool run(const TripleHandler &callback)
void add(raptor_statement *statement, const TripleHandler &callback)
std::vector< std::string > imports_
void flush(const TripleHandler &callback)
std::shared_ptr< RaptorContainer > currentBatch_
FunctionRule & function()
Definition: terms.cpp:140
TermRule & string()
Definition: terms.cpp:63
std::function< bool(const Triple &)> TripleFilter
std::shared_ptr< const GraphSelector > GraphSelectorPtr
Definition: GraphSelector.h:76
std::function< void(const TripleContainerPtr &)> TripleHandler