Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/agents/link_creation_agent/link_creators/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ cc_library(
"//agents/query_engine:pattern_matching_query_proxy",
"//agents/query_engine:query_answer",
"//atomdb:atomdb_singleton",
"//atomdb:atomdbutils",
"//attention_broker:attention_broker_lib",
"//commons:commons_lib",
"//hasher:hasher_lib",
Expand Down
4 changes: 2 additions & 2 deletions src/agents/link_creation_agent/link_creators/LinkCreator.cc
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ LinkCreator::AddLinkStatus LinkCreator::add_or_update_link(const vector<string>&
this->newly_created_links.push_back(handle);
if (log_new_links()) {
LOG_INFO("ADD LINK: [" + std::to_string(strength) + "] " +
new_link->metta_representation(*decoder()));
new_link->metta_representation(decoder));
}
vector<string> determiners = {handle};
determiners.insert(determiners.end(), targets.begin(), targets.end());
Expand Down Expand Up @@ -83,7 +83,7 @@ void LinkCreator::save_link_metta(shared_ptr<Link> link) {
file.open(get_log_file(), ios::app);
if (file.is_open()) {
file << link->custom_attributes.get_or<double>("strength", 1.0) << ","
<< link->metta_representation(*decoder()) << endl;
<< link->metta_representation(decoder) << endl;
file.close();
} else {
RAISE_ERROR("Couldn't open file for writing: " + get_log_file());
Expand Down
4 changes: 3 additions & 1 deletion src/agents/link_creation_agent/link_creators/LinkCreator.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include <string>

#include "AtomDBSingleton.h"
#include "AtomDBUtils.h"
#include "QueryAnswer.h"
#include "tags.h"

Expand Down Expand Up @@ -162,11 +163,12 @@ class LinkCreator {
vector<string> newly_created_links;

protected:
AtomDBUtils decoder;

inline void visit(const string& key) { this->_visited.insert(key); }
inline bool visited(const string& key) { return (this->_visited.find(key) != this->_visited.end()); }
inline double strength_threshold() { return this->_strength_threshold; }
inline shared_ptr<AtomDB> atomdb() { return AtomDBSingleton::get_instance(); }
inline HandleDecoder* decoder() { return static_pointer_cast<HandleDecoder>(atomdb()).get(); }
inline void add_determiners(vector<string>& entry) { this->_buffer_determiners.push_back(entry); }

AddLinkStatus add_or_update_link(const vector<string>& targets, double strength);
Expand Down
2 changes: 1 addition & 1 deletion src/agents/query_engine/query_element/Chain.cc
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,7 @@ bool Chain::thread_one_step() {
}
{
#if LOG_LEVEL >= DEBUG_LEVEL
lock_guard<mutex> semaphore(this->thread_debug_mutex);
lock_guard<mutex> semaphore_debug(this->thread_debug_mutex);
#endif
lock_guard<mutex> semaphore(this->feeding_mutex);
if ((answer = dynamic_cast<QueryAnswer*>(this->input_buffer[0]->pop_query_answer())) != NULL) {
Expand Down
5 changes: 2 additions & 3 deletions src/atomdb/AtomDB.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
#include <vector>

#include "AtomDBAPITypes.h"
#include "HandleDecoder.h"
#include "LinkSchema.h"
#include "Merger.h"
#include "Properties.h"
Expand All @@ -19,7 +18,7 @@ namespace atomdb {

enum class AtomDBType { RedisMongoDB, MorkDB, InMemoryDB, RemoteAtomDB, AdapterDB };

class AtomDB : public HandleDecoder {
class AtomDB {
public:
AtomDB() = default;
explicit AtomDB(const string& uid) : uid_(uid) {}
Expand Down Expand Up @@ -61,7 +60,7 @@ class AtomDB : public HandleDecoder {
virtual bool composite_type_enabled() const = 0;
virtual atomdb_api_types::ProtectionMode get_protection_mode() const = 0;

virtual shared_ptr<Atom> get_atom(const string& handle) = 0; // HandleDecoder interface
virtual shared_ptr<Atom> get_atom(const string& handle) = 0;
virtual shared_ptr<Node> get_node(const string& handle) = 0;
virtual shared_ptr<Link> get_link(const string& handle) = 0;

Expand Down
6 changes: 6 additions & 0 deletions src/atomdb/AtomDBAPITypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include <map>
#include <vector>

#include "HandleDecoder.h"
#include "Link.h"
#include "LinkSchema.h"
#include "Node.h"
Expand Down Expand Up @@ -42,7 +43,11 @@ class HandleList {

class HandleSetIterator {
public:
HandleSetIterator() : decoder(NULL) {}
virtual char* next() = 0;

protected:
HandleDecoder* decoder;
};

class HandleSet {
Expand All @@ -53,6 +58,7 @@ class HandleSet {
virtual unsigned int size() = 0;
virtual void append(shared_ptr<HandleSet> other) = 0;
virtual shared_ptr<HandleSetIterator> get_iterator() = 0;
virtual shared_ptr<HandleSetIterator> get_iterator(HandleDecoder* decoder) = 0;

virtual map<string, string> get_metta_expressions_by_handle(const string& handle) = 0;
virtual Assignment get_assignments_by_handle(const string& handle) = 0;
Expand Down
5 changes: 4 additions & 1 deletion src/atomdb/AtomDBFactory.cc
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include "AtomDBFactory.h"

#include "AdapterDB.h"
#include "AtomDBSingleton.h"
#include "InMemoryDB.h"
#include "MorkDB.h"
#include "ProtectedAtomDB.h"
Expand Down Expand Up @@ -103,7 +104,9 @@ shared_ptr<AtomDB> AtomDBFactory::create_composite_atomdb(const JsonConfig& conf
RAISE_ERROR("AtomDBFactory: adapterdb backend requires a nonempty uid");
}
auto basic_atomdb = create_basic_atomdb(atomdb_backend_config);
AtomDBSingleton::provide(basic_atomdb);
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved
atomdb = make_shared<AdapterDB>(config, basic_atomdb);
AtomDBSingleton::provide(nullptr, true);
} else {
RAISE_ERROR("AtomDBFactory: '" + atomdb_type + "' is not a composite AtomDB type");
}
Expand All @@ -127,4 +130,4 @@ shared_ptr<AtomDB> AtomDBFactory::wrap_if_protected(shared_ptr<AtomDB> atomdb) {
} else {
RAISE_ERROR("AtomDBFactory::wrap_if_protected() encountered unknown protection mode");
}
}
}
4 changes: 2 additions & 2 deletions src/atomdb/AtomDBSingleton.cc
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ shared_ptr<AtomDB> AtomDBSingleton::get_instance() {
}
}

void AtomDBSingleton::provide(shared_ptr<AtomDB> atom_db) {
if (AtomDBSingleton::initialized) {
void AtomDBSingleton::provide(shared_ptr<AtomDB> atom_db, bool unit_test) {
if (AtomDBSingleton::initialized && !unit_test) {
RAISE_ERROR(
"AtomDBSingleton already initialized. AtomDBInitializer::init() should be called only "
"once.");
Expand Down
10 changes: 1 addition & 9 deletions src/atomdb/AtomDBSingleton.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,6 @@ using namespace std;

namespace atomdb {

// -------------------------------------------------------------------------------------------------
// NOTE TO REVIEWER:
//
// This class will be replaced/integrated by/with classes already implemented in das-atom-db.
//
// I think it's pointless to make any further documentation while we don't make this integration.
// -------------------------------------------------------------------------------------------------

class AtomDBSingleton {
public:
~AtomDBSingleton() {}
Expand All @@ -27,7 +19,7 @@ class AtomDBSingleton {
*
* Fails if the singleton is already initialized.
*/
static void provide(shared_ptr<AtomDB> atom_db);
static void provide(shared_ptr<AtomDB> atom_db, bool unit_test = false);

private:
AtomDBSingleton() {}
Expand Down
Loading
Loading