<commit_before>"""
Scheme wrapper for Python

Before using the scheme_wrapper, you will need to import any atom type
definitions that you require. For a detailed example of how to use this
functionality, see:

    tests/cython/guile/test_pattern.py

Also refer to the list of .scm type definition files in opencog.conf
"""

from cython.operator cimport dereference as deref
from opencog.atomspace cimport cAtomSpace, Atom, AtomSpace, cAtom, cHandle, AtomSpace_factory, void_from_candle


# basic wrapping for std::string conversion
cdef extern from "<string>" namespace "std":
    cdef cppclass string:
        string()
        string(char *)
        char * c_str()
        int size()

cdef extern from "opencog/cython/opencog/PyScheme.h" namespace "opencog":
    string eval_scheme(cAtomSpace* as, const string& s) except +

def scheme_eval(AtomSpace a, str pys):
    """
    Returns a string value
    """
    cdef string ret
    cdef string expr
    expr = pys.encode('UTF-8')
    # print "Debug: called scheme eval with atomspace {0:x}".format(<unsigned long int>a.atomspace)
    ret = eval_scheme(a.atomspace, expr)
    return ret.c_str()

cdef extern from "opencog/cython/opencog/PyScheme.h" namespace "opencog":
    cHandle eval_scheme_h(cAtomSpace* as, const string& s) except +

def scheme_eval_h(AtomSpace a, str pys):
    """
    Returns a Handle
    """
    cdef cHandle ret
    cdef string expr
    expr = pys.encode('UTF-8')
    ret = eval_scheme_h(a.atomspace, expr)
    return Atom(void_from_candle(ret), a)

cdef extern from "opencog/cython/opencog/PyScheme.h" namespace "opencog":
    cAtomSpace* eval_scheme_as(const string& s) except +

def scheme_eval_as(str pys):
    """
    Returns an AtomSpace<commit_msg>Update scheme_eval...() Python functions docs<commit_after>"""
Scheme wrapper for Python

Before using the scheme_wrapper, you will need to import any atom type
definitions that you require. For a detailed example of how to use this
functionality, see:

    tests/cython/guile/test_pattern.py

Also refer to the list of .scm type definition files in opencog.conf
"""

from cython.operator cimport dereference as deref
from opencog.atomspace cimport cAtomSpace, Atom, AtomSpace, cAtom, cHandle, AtomSpace_factory, void_from_candle


# basic wrapping for std::string conversion
cdef extern from "<string>" namespace "std":
    cdef cppclass string:
        string()
        string(char *)
        char * c_str()
        int size()

cdef extern from "opencog/cython/opencog/PyScheme.h" namespace "opencog":
    string eval_scheme(cAtomSpace* as, const string& s) except +

def scheme_eval(AtomSpace a, str pys):
    """Evaluate Scheme program and return string.
    Args:
        a (AtomSpace): atomspace to work on
        pys (str): Scheme program to evaluate
    Returns:
        str: result of a evaluation
    Raises:
        RuntimeError: in case of evaluation error
    """
    cdef string ret
    cdef string expr
    expr = pys.encode('UTF-8')
    # print "Debug: called scheme eval with atomspace {0:x}".format(<unsigned long int>a.atomspace)
    ret = eval_scheme(a.atomspace, expr)
    return ret.c_str()

cdef extern from "opencog/cython/opencog/PyScheme.h" namespace "opencog":
    cHandle eval_scheme_h(cAtomSpace* as, const string& s) except +

def scheme_eval_h(AtomSpace a, str pys):
    """Evaluate Scheme program when expected result is Handle.
    Args:
        a (AtomSpace): atomspace to work on
        pys (str): Scheme program to evaluate
    Returns:
        Handle: result of a evaluation
    Raises:
        RuntimeError: in case of evaluation error
    """
    cdef cHandle ret
    cdef string expr
    expr = pys.encode('UTF-8')
    ret = eval_scheme_h(a.atomspace, expr)
    return Atom(void_from_candle(ret), a)

cdef extern from "opencog/cython/opencog/PyScheme.h" namespace "opencog":
    cAtomSpace* eval_scheme_as(const string& s) except +

def scheme_eval_as(str pys):
    """Evaluate Scheme program when expected result is AtomSpace.
    Args:
        pys (str): Scheme program to evaluate
    Returns:
        AtomSpace: atomspace result
    Raises:
        RuntimeError: if result of Scheme program is not AtomSpace or
            in case of evaluation error
{'fraction_non_alphanumeric': 0.08613345953620445, 'fraction_numerical': 0.001419782300047326, 'mean_word_length': 3.444794952681388, 'pattern_counts': {'":': 8, '<': 7, '<?xml version=': 0, '>': 7, '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': '661285', 'n_tokens_mistral': 1349, 'n_tokens_neox': 1327, 'n_words': 450}