20 using namespace opencog;
53 if (NULL == h)
return "#<Invalid handle>";
58 for (
int i=0; i< indent; i++) ret +=
" ";
65 ret += nnn->getName();
70 if (!
tv->isDefaultTV()) {
87 if (!
tv->isDefaultTV()) {
101 std::vector<Handle> oset = lll->getOutgoingSet();
102 unsigned int arity = oset.size();
103 for (
unsigned int i=0; i<arity; i++) {
109 for (
int i=0; i < indent; i++) ret +=
" ";
135 scm_gc_register_collectable_memory (hp,
136 sizeof(h),
"opencog handle");
149 scm_t_bits misctype = SCM_SMOB_FLAGS(sh);
154 scm_remember_upto_here_1(sh);
164 if (scm_is_false(scm_integer_p(suuid)))
165 scm_wrong_type_arg_msg(
"cog-atom", 1, suuid,
"integer opencog uuid");
168 UUID uuid = scm_to_ulong(suuid);
180 scm_wrong_type_arg_msg(
"cog-handle", 1, satom,
"opencog atom");
182 return scm_from_ulong(h.
value());
202 scm_t_bits misctype = SCM_SMOB_FLAGS(s);
244 if (scm_is_integer(stype))
245 return scm_to_ushort(stype);
247 if (scm_is_true(scm_symbol_p(stype)))
248 stype = scm_symbol_to_string(stype);
250 if (scm_is_false(scm_string_p(stype)))
251 scm_wrong_type_arg_msg(subrname, pos, stype,
"name of opencog atom type");
253 const char * ct = scm_i_string_chars(stype);
258 scm_wrong_type_arg_msg(subrname, pos, stype,
"name of opencog atom type");
269 int pos,
const char * msg)
271 if (scm_is_false(scm_string_p(sname)))
272 scm_wrong_type_arg_msg(subrname, pos, sname, msg);
274 char * cname = scm_to_utf8_string(sname);
275 std::string name(cname);
285 int pos,
const char * msg)
287 if (scm_is_false(scm_integer_p(sint)))
288 scm_wrong_type_arg_msg(subrname, pos, sint, msg);
290 return scm_to_int(sint);
301 if (NUMBER_NODE == t and scm_is_number(sname)) {
302 sname = scm_number_to_string(sname,
_radix_ten);
307 "string name for the node"));
310 if (NULL == atomspace) atomspace =
ss_get_env_as(
"cog-new-node");
334 catch (
const std::exception& ex)
339 scm_remember_upto_here_1(kv_pairs);
353 "string name for the node");
356 if (NULL == atomspace) atomspace =
ss_get_env_as(
"cog-node");
361 if (NULL == h)
return SCM_EOL;
366 h->setTruthValue(tv->
clone());
372 h->setAttentionValue(av->
clone());
374 scm_remember_upto_here_1(kv_pairs);
389 if (!scm_is_pair(satom_list) and !scm_is_null(satom_list))
390 scm_wrong_type_arg_msg(subrname, pos, satom_list,
"a list of atoms");
392 std::vector<Handle> outgoing_set;
395 while (scm_is_pair(sl)) {
396 SCM satom = SCM_CAR(sl);
401 outgoing_set.push_back(h);
403 else if (scm_is_pair(satom) and !scm_is_null(satom_list)) {
408 const std::vector<Handle> &oset =
410 std::vector<Handle>::const_iterator it;
411 for (it = oset.begin(); it != oset.end(); ++it) {
412 outgoing_set.push_back(*it);
415 else if (scm_is_null(satom)) {
424 scm_wrong_type_arg_msg(subrname, pos, satom,
"opencog atom");
442 std::vector<Handle> outgoing_set;
446 if (NULL == atomspace) atomspace =
ss_get_env_as(
"cog-new-link");
451 h = atomspace->
add_link(t, outgoing_set);
466 catch (
const std::exception& ex)
470 scm_remember_upto_here_1(satom_list);
483 std::vector<Handle> outgoing_set;
487 if (NULL == atomspace) atomspace =
ss_get_env_as(
"cog-link");
492 if (NULL == h)
return SCM_EOL;
496 if (tv) h->setTruthValue(tv->
clone());
500 if (av) h->setAttentionValue(av->
clone());
502 scm_remember_upto_here_1(satom_list);
520 if (NULL == h.operator->())
return SCM_BOOL_F;
526 if (NULL == atomspace) atomspace =
ss_get_env_as(
"cog-delete");
534 scm_remember_upto_here_1(satom);
537 if (rc)
return SCM_BOOL_T;
552 if (NULL == atomspace) atomspace =
ss_get_env_as(
"cog-delete-recursive");
558 scm_remember_upto_here_1(satom);
560 if (rc)
return SCM_BOOL_T;
578 if (NULL == h.operator->())
return SCM_BOOL_F;
584 if (NULL == atomspace) atomspace =
ss_get_env_as(
"cog-purge");
592 scm_remember_upto_here_1(satom);
595 if (rc)
return SCM_BOOL_T;
610 if (NULL == atomspace) atomspace =
ss_get_env_as(
"cog-purge-recursive");
616 scm_remember_upto_here_1(satom);
618 if (rc)
return SCM_BOOL_T;
AttentionValuePtr getAttentionValue()
bool purge_atom(Handle h, bool recursive=false)
static SCM ss_purge_recursive(SCM, SCM)
static std::string av_to_string(const AttentionValue *)
Handle add_node(Type t, const std::string &name="", bool async=false)
static SCM ss_node(SCM, SCM, SCM)
static std::string to_string(SCM)
static AttentionValue * get_av_from_list(SCM)
std::shared_ptr< TruthValue > TruthValuePtr
std::shared_ptr< AttentionValue > AttentionValuePtr
virtual TruthValuePtr clone() const =0
static void throw_exception(const char *, const char *)
static AtomSpace * get_as_from_list(SCM)
static scm_t_bits cog_misc_tag
static SCM ss_purge(SCM, SCM)
static SCM ss_delete(SCM, SCM)
static std::string tv_to_string(const TruthValue *)
static int verify_int(SCM, const char *, int pos=1, const char *msg="expecting integer")
static SCM ss_node_p(SCM)
std::shared_ptr< Link > LinkPtr
void setTruthValue(TruthValuePtr)
Sets the TruthValue object of the atom.
ClassServer & classserver(ClassServerFactory *=ClassServer::createInstance)
static std::string handle_to_string(SCM)
static NodePtr NodeCast(const Handle &h)
void setAttentionValue(AttentionValuePtr)
Sets the AttentionValue object of the atom.
static SCM ss_new_link(SCM, SCM)
static const Handle UNDEFINED
unsigned long UUID
UUID == Universally Unique Identifier.
static SCM ss_undefined_handle(void)
static Type verify_atom_type(SCM, const char *, int pos=1)
static Handle scm_to_handle(SCM)
bool remove_atom(Handle h, bool recursive=false)
static SCM ss_atom_p(SCM)
Handle get_handle(Type t, const std::string &str)
const std::string & getTypeName(Type type)
static std::vector< Handle > verify_handle_list(SCM, const char *, int pos=1)
AttentionValuePtr clone() const
Returns An AttentionValue* cloned from this AttentionValue.
static SCM ss_link_p(SCM)
static LinkPtr LinkCast(const Handle &h)
static AttentionValuePtr DEFAULT_AV()
to be used as default attention value
std::shared_ptr< Node > NodePtr
TruthValuePtr getTruthValue()
Type getType(const std::string &typeName)
static std::string verify_string(SCM, const char *, int pos=1, const char *msg="expecting string")
static SCM ss_delete_recursive(SCM, SCM)
unsigned short Type
type of Atoms, represented as short integer (16 bits)
static Handle verify_handle(SCM, const char *, int pos=1)
size_t getIncomingSetSize()
Get the size of the incoming set.
static SCM handle_to_scm(Handle)
static SCM ss_handle(SCM)
Handle add_link(Type t, const HandleSeq &outgoing, bool async=false)
static SCM ss_new_node(SCM, SCM, SCM)
static AtomSpace * ss_get_env_as(const char *)
static SCM ss_link(SCM, SCM)
static std::string misc_to_string(SCM)
static TruthValue * get_tv_from_list(SCM)