Skip to content

Commit

Permalink
Merge pull request #1448 from linas/atomese-misc
Browse files Browse the repository at this point in the history
Atomese misc changes
  • Loading branch information
linas authored Feb 21, 2023
2 parents f78377e + ada28c5 commit 01b836d
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 14 deletions.
37 changes: 34 additions & 3 deletions link-grammar/dict-atomese/link-names.cc
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,8 @@
#ifdef HAVE_ATOMESE

#include <cstdlib>
//#include <opencog/util/oc_assert.h>
#include <opencog/atoms/truthvalue/CountTruthValue.h>
#include <opencog/atomspace/AtomSpace.h>
//#include <opencog/persist/api/StorageNode.h>
#include <opencog/nlp/types/atom_types.h>

#undef STRINGIFY
Expand Down Expand Up @@ -104,11 +103,43 @@ std::string cached_linkname(Local* local, const Handle& lnk)

// idtostr(1064) is "ANY" and we want to reserve "ANY"
if (1064 == local->last_id) local->last_id++;
std::string slnk = idtostr(local->last_id++);
store_link_id(local);

std::string slnk = idtostr(local->last_id++);
lgc = createNode(BOND_NODE, slnk);
local->asp->add_link(EDGE_LINK, lgc, lnk);
return slnk;
}

// ===============================================================

// Get the last issued link ID from the data store.
void fetch_link_id(Local* local)
{
if (not local->using_external_as) return;

// Location where issued link ID's are stored.
if (local->stnp)
local->stnp->fetch_atom(local->idanch);

const TruthValuePtr& tv = local->idanch->getTruthValue();
const CountTruthValuePtr ctv(CountTruthValueCast(tv));
if (ctv)
local->last_id = std::round(ctv->get_count());
}

// Record the last unissued id.
void store_link_id(Local* local)
{
if (not local->using_external_as) return;

TruthValuePtr tvp(createCountTruthValue(1, 0, local->last_id));
local->asp->set_truthvalue(local->idanch, tvp);

// Store, if there is storage.
if (local->stnp)
local->stnp->store_atom(local->idanch);
}

// ===============================================================
#endif /* HAVE_ATOMESE */
3 changes: 3 additions & 0 deletions link-grammar/dict-atomese/local-as.h
Original file line number Diff line number Diff line change
Expand Up @@ -80,5 +80,8 @@ void and_enchain_right(Pool_desc*, Exp* &orhead, Exp* &ortail, Exp*);

Handle get_lg_conn(Local*, const Handle& pair);
std::string cached_linkname(Local*, const Handle& pair);
void fetch_link_id(Local*);
void store_link_id(Local*);


//----
14 changes: 3 additions & 11 deletions link-grammar/dict-atomese/lookup-atomese.cc
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@

#include <cstdlib>
#include <opencog/atomspace/AtomSpace.h>
#include <opencog/atoms/truthvalue/CountTruthValue.h>
#include <opencog/persist/api/StorageNode.h>
#include <opencog/persist/cog-simple/CogSimpleStorage.h>
#include <opencog/persist/cog-storage/CogStorage.h>
Expand Down Expand Up @@ -330,12 +329,8 @@ bool as_open(Dictionary dict)
local->stnp->barrier();
}

// Used to hold issued link ID's.
local->stnp->fetch_atom(local->idanch);
const TruthValuePtr& tv = local->idanch->getTruthValue();
const CountTruthValuePtr ctv(CountTruthValueCast(tv));
if (ctv)
local->last_id = std::round(ctv->get_count());
// Get last issued link ID.
fetch_link_id(local);

return true;
}
Expand All @@ -352,10 +347,7 @@ void as_storage_close(Dictionary dict)
Local* local = (Local*) (dict->as_server);

// Record the last unissued id.
TruthValuePtr tvp(createCountTruthValue(1, 0, local->last_id));
local->asp->set_truthvalue(local->idanch, tvp);
if (local->stnp)
local->stnp->store_atom(local->idanch);
store_link_id(local);

if (not local->using_external_as and local->stnp)
local->stnp->close();
Expand Down

0 comments on commit 01b836d

Please sign in to comment.