<commit_before>/*
 * SchemeSmobAtom.c
 *
 * Scheme small objects (SMOBS) for opencog atom properties
 *
 * Copyright (c) 2008,2009 <NAME> <<EMAIL>>
 */

#ifdef HAVE_GUILE

#include <vector>

#include <libguile.h>

#include <opencog/atomspace/ClassServer.h>
#include <opencog/atomspace/TruthValue.h>
#include <opencog/guile/SchemeSmob.h>

using namespace opencog;

/* ============================================================== */
/**
 * Verify that SCM arg is an actual opencog Handle; returning Handle
 *
 * This routine is meant for validating arguments passed into
 * guile-wrapped C++ code.
 *
 * This routine takes an SCM arg and a string subroutine name. It
 * verifies that the arg is actually a handle (and not, for example,
 * an int, string, etc.)  If its not a handle, it throws an SCM error,
 * using the subroutine name in the error message.  (Such an error is
 * caught by the shell, and printed as a stack trace at the shell
 * prompt).  If the arg is a handle, then the actual opencog handle
 * is returned.
 */

Handle SchemeSmob::verify_handle (SCM satom, const char * subrname, int pos)
{
	Handle h(scm_to_handle(satom));
	if (Handle::UNDEFINED == h)
		scm_wrong_type_arg_msg(subrname, pos, satom, "opencog atom");

	return h;
}

/* ============================================================== */
/**
 * Return the string name of the atom
 */
SCM SchemeSmob::ss_name (SCM satom)
{
	std::string name;
	Handle h = verify_handle(satom, "cog-name");
	NodePtr nnn(NodeCast(h));
	if (nnn) name = nnn->getName();
	SCM str = scm_from_locale_string(name.c_str());
	return str;
}

SCM SchemeSmob::ss_type (SCM satom)
{
	Handle h = verify_handle(satom, "cog-type");
	Type t = h->getType();
	const std::string &tname = classserver().getTypeName(t);
	SCM str = scm_from_locale_string(tname.c_str());
	SCM sym = scm_string_to_symbol(str);

	return sym;
}

SCM SchemeSmob::ss_arity (SCM satom)
{
	Handle h = verify_handle(satom, "cog-arity");
	Arity ari = 0;
	LinkPtr lll(LinkCast(h));
	if (lll) ari = lll->getArity();

	/* Arity is currently an unsigned short */
	SCM sari = scm_from_ushort(ari);
	return sari;
}

SCM SchemeSmob::ss_tv (SCM satom)
{
	Handle h = verify_handle(satom, "cog-tv");
	TruthValuePtr tv(h->getTruthValue());
	TruthValue *stv = tv->rawclone();
	return take_tv(stv);
}

SCM SchemeSmob::ss_set_tv (SCM satom, SCM stv)
{
	Handle h = verify_handle(satom, "cog-set-tv!");
	TruthValue *tv = verify_tv(stv, "cog-set-tv!", 2);

	h->setTruthValue(tv->clone());
	return satom;
}

SCM SchemeSmob::ss_av (SCM satom)
{
	Handle h = verify_handle(satom, "cog-av");
	AttentionValue *sav = h->getAttentionValue()->rawclone();
	return take_av(sav);
}

SCM SchemeSmob::ss_set_av (SCM satom, SCM sav)
{
	Handle h = verify_handle(satom, "cog-set-av!");
	AttentionValue *av = verify_av(sav, "cog-set-av!", 2);

	h->setAttentionValue(av->clone());
	return satom;
}

SCM SchemeSmob::ss_inc_vlti (SCM satom)
{
	Handle h = verify_handle(satom, "cog-inc-vlti!");

	atomspace->incVLTI(h);
	return satom;
}

SCM SchemeSmob::ss_dec_vlti (SCM satom)
{
	Handle h = verify_handle(satom, "cog-dec-vlti!");

	atomspace->decVLTI(h);
	return satom;
}

/* ============================================================== */
/**
 * Convert the outgoing set of an atom into a list; return the list.
 */
SCM SchemeSmob::ss_outgoing_set (SCM satom)
{
	Handle h = verify_handle(satom, "cog-outgoping-set");

	LinkPtr lll(LinkCast(h));<commit_msg>More API cleanup-related work.<commit_after>/*
 * SchemeSmobAtom.c
 *
 * Scheme small objects (SMOBS) for opencog atom properties
 *
 * Copyright (c) 2008,2009 <NAME> <<EMAIL>>
 */

#ifdef HAVE_GUILE

#include <vector>

#include <libguile.h>

#include <opencog/atomspace/ClassServer.h>
#include <opencog/atomspace/TruthValue.h>
#include <opencog/guile/SchemeSmob.h>

using namespace opencog;

/* ============================================================== */
/**
 * Verify that SCM arg is an actual opencog Handle; returning Handle
 *
 * This routine is meant for validating arguments passed into
 * guile-wrapped C++ code.
 *
 * This routine takes an SCM arg and a string subroutine name. It
 * verifies that the arg is actually a handle (and not, for example,
 * an int, string, etc.)  If its not a handle, it throws an SCM error,
 * using the subroutine name in the error message.  (Such an error is
 * caught by the shell, and printed as a stack trace at the shell
 * prompt).  If the arg is a handle, then the actual opencog handle
 * is returned.
 */

Handle SchemeSmob::verify_handle (SCM satom, const char * subrname, int pos)
{
	Handle h(scm_to_handle(satom));
	if (Handle::UNDEFINED == h)
		scm_wrong_type_arg_msg(subrname, pos, satom, "opencog atom");

	return h;
}

/* ============================================================== */
/**
 * Return the string name of the atom
 */
SCM SchemeSmob::ss_name (SCM satom)
{
	std::string name;
	Handle h = verify_handle(satom, "cog-name");
	NodePtr nnn(NodeCast(h));
	if (nnn) name = nnn->getName();
	SCM str = scm_from_locale_string(name.c_str());
	return str;
}

SCM SchemeSmob::ss_type (SCM satom)
{
	Handle h = verify_handle(satom, "cog-type");
	Type t = h->getType();
	const std::string &tname = classserver().getTypeName(t);
	SCM str = scm_from_locale_string(tname.c_str());
	SCM sym = scm_string_to_symbol(str);

	return sym;
}

SCM SchemeSmob::ss_arity (SCM satom)
{
	Handle h = verify_handle(satom, "cog-arity");
	Arity ari = 0;
	LinkPtr lll(LinkCast(h));
	if (lll) ari = lll->getArity();

	/* Arity is currently an unsigned short */
	SCM sari = scm_from_ushort(ari);
	return sari;
}

SCM SchemeSmob::ss_tv (SCM satom)
{
	Handle h = verify_handle(satom, "cog-tv");
	TruthValuePtr tv(h->getTruthValue());
	TruthValue *stv = tv->rawclone();
	return take_tv(stv);
}

SCM SchemeSmob::ss_set_tv (SCM satom, SCM stv)
{
	Handle h = verify_handle(satom, "cog-set-tv!");
	TruthValue *tv = verify_tv(stv, "cog-set-tv!", 2);

	h->setTruthValue(tv->clone());
	return satom;
}

SCM SchemeSmob::ss_av (SCM satom)
{
	Handle h = verify_handle(satom, "cog-av");
	AttentionValue *sav = h->getAttentionValue()->rawclone();
	return take_av(sav);
}

SCM SchemeSmob::ss_set_av (SCM satom, SCM sav)
{
	Handle h = verify_handle(satom, "cog-set-av!");
	AttentionValue *av = verify_av(sav, "cog-set-av!", 2);

	h->setAttentionValue(av->clone());
	return satom;
}

SCM SchemeSmob::ss_inc_vlti (SCM satom)
{
	Handle h = verify_handle(satom, "cog-inc-vlti!");

	h->incVLTI();
	return satom;
}

SCM SchemeSmob::ss_dec_vlti (SCM satom)
{
	Handle h = verify_handle(satom, "cog-dec-vlti!");

	h->decVLTI();
	return satom;
}

/* ============================================================== */
/**
 * Convert the outgoing set of an atom into a list; return the list.
 */
SCM SchemeSmob::ss_outgoing_set (SCM satom)
{
	Handle h = verify_handle(satom, "cog-outgoping-set");

	LinkPtr lll(LinkCast(h));
{'fraction_non_alphanumeric': 0.1892560780317368, 'fraction_numerical': 0.00320279516669093, 'mean_word_length': 4.802364864864865, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 45, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7197665', 'n_tokens_mistral': 2656, 'n_tokens_neox': 2567, 'n_words': 680}