-
Notifications
You must be signed in to change notification settings - Fork 9
[#1102] Implementation of the MORK type AdapterDB 2 #1125
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 3 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
f34d69f
Refactor Metta2AtomsMapper and MorkWrapper to use queues for atom out…
marcocapozzoli 03f8397
Implement load_metta_queries in ContextLoader and create_tasks and ex…
marcocapozzoli 8d95054
Add Metta library dependency and enhance MorkWrapper tests
marcocapozzoli 5bec467
Merge branch 'master' into masc/1102-adapterdb-mork-3
marcocapozzoli 13fddfd
Refactor DatabaseWrapper and its subclasses to use shared_ptr for Dat…
marcocapozzoli 50cbd10
improve connection handling
marcocapozzoli 5a2bbe7
Merge branch 'masc/1102-adapterdb-mork-3' into masc/1102-adapterdb-mo…
marcocapozzoli 57311dc
Merge pull request #1128 from singnet/masc/1102-adapterdb-mork-conn
marcocapozzoli cce6636
Refactor MorkWrapper constructor to remove redundant member initializ…
marcocapozzoli cd23890
Add data loading steps to MapSuccess test in MorkWrapperTest
marcocapozzoli File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,24 +1,79 @@ | ||
| #include "Metta2AtomsMapper.h" | ||
|
|
||
| #include "Link.h" | ||
| #include "MettaParser.h" | ||
| #include "MettaParserActions.h" | ||
|
|
||
| #define LOG_LEVEL INFO_LEVEL | ||
| #include "Logger.h" | ||
|
|
||
| using namespace db_adapter; | ||
| using namespace commons; | ||
| using namespace atoms; | ||
|
|
||
| // ============================== | ||
| // --------------------------------------------------------------------------------------------- | ||
| // Construction / destruction | ||
| // ============================== | ||
|
|
||
| Metta2AtomsMapper::Metta2AtomsMapper() {} | ||
|
|
||
| Metta2AtomsMapper::~Metta2AtomsMapper() {} | ||
|
|
||
| // ============================== | ||
| // --------------------------------------------------------------------------------------------- | ||
| // Public | ||
| // ============================== | ||
|
|
||
| vector<shared_ptr<Atom>> Metta2AtomsMapper::map(const DbInput& data) { | ||
| return vector<shared_ptr<Atom>>{}; | ||
| void Metta2AtomsMapper::map(const DbInput& data, std::queue<shared_ptr<Atom>>& output) { | ||
| MettaExpression metta_expression = get<MettaExpression>(data); | ||
|
|
||
| LOG_DEBUG("[Metta2AtomsMapper::map] Parsing MORK expression: " << metta_expression.expression); | ||
|
|
||
| auto parser_actions = make_shared<MettaParserActions>(); | ||
| MettaParser parser(metta_expression.expression, parser_actions); | ||
| parser.parse(); | ||
|
|
||
| stack<shared_ptr<Atom>> element_stack = parser_actions->element_stack; | ||
| shared_ptr<Atom> atom = element_stack.top(); | ||
| auto link_toplevel = dynamic_pointer_cast<Link>(atom); | ||
|
|
||
| this->collect_atoms(output, link_toplevel->handle(), parser_actions); | ||
|
|
||
| #if LOG_LEVEL >= DEBUG_LEVEL | ||
| LOG_DEBUG("The expression " << metta_expression.expression | ||
| << " has been mapped to the following atoms:"); | ||
|
|
||
| for (const auto& atom : this->atoms) { | ||
| LOG_DEBUG("-> " << atom->to_string()); | ||
| } | ||
| #endif | ||
| } | ||
|
|
||
| void Metta2AtomsMapper::collect_atoms(std::queue<shared_ptr<Atom>>& output, | ||
| const string& handle, | ||
| shared_ptr<MettaParserActions> parser_actions) { | ||
| shared_ptr<Atom> atom = parser_actions->handle_to_atom[handle]; | ||
| if (atom != nullptr) { | ||
| if (Atom::is_node(*atom)) { | ||
| output.push(atom); | ||
| } else { | ||
| this->collect_atoms_recursive(output, dynamic_pointer_cast<Link>(atom), parser_actions); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| // --------------------------------------------------------------------------------------------- | ||
| // Private | ||
|
|
||
| void Metta2AtomsMapper::collect_atoms_recursive(std::queue<shared_ptr<Atom>>& output, | ||
| shared_ptr<Link> link, | ||
| shared_ptr<MettaParserActions> parser_actions) { | ||
| for (string& target_handle : link->targets) { | ||
| shared_ptr<Atom> atom = parser_actions->handle_to_atom[target_handle]; | ||
| if (atom != nullptr) { | ||
| if (Atom::is_node(*atom)) { | ||
| output.push(atom); | ||
| } else { | ||
| this->collect_atoms_recursive(output, dynamic_pointer_cast<Link>(atom), parser_actions); | ||
| } | ||
| } | ||
| } | ||
| output.push(link); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.