<commit_before>
# Atom wrapper object
cdef class Atom(object):

    def __cinit__(self, PATOM lptr, AtomSpace a):
        atomo = atom_from_the_void(lptr)
        self.handle = new cHandle(atomo)

    def __dealloc__(self):
        del self.handle

    def value(self):
        return void_from_cptr(self.handle)

    def __init__(self, PATOM lptr, AtomSpace a):
        # self.handle = h is set in __cinit__ above

        # cache the results after first retrieval of
        # immutable properties
        self._atom_type = None
        self._name = None
        self._outgoing = None
        self.atomspace = a

    def __nonzero__(self):
        """ Allows boolean comparison, return false is handle is
        UNDEFINED or doesn't exist in AtomSpace """
        if self.handle:
            return self.atomspace.is_valid(self)
        else: return False

    property atomspace:
        def __get__(self):
            return self.atomspace

    property uuid:
        def __get__(self):
            return void_from_cptr(self.handle)

    property name:
        def __get__(self):
            cdef cAtom* atom_ptr
            if self._name is None:
                atom_ptr = self.handle.atom_ptr()
                if atom_ptr == NULL:   # avoid null-pointer deref
                    return None
                if atom_ptr.isNode():
                    self._name = atom_ptr.getName()
                else:
                    self._name = ""
            return self._name

    property tv:
        def __get__(self):
            cdef cAtom* atom_ptr = self.handle.atom_ptr()
            cdef tv_ptr tvp
            if atom_ptr == NULL:   # avoid null-pointer deref
                return None
            tvp = atom_ptr.getTruthValue()
            if (not tvp.get() or tvp.get().isNullTv()):
                pytv = TruthValue()
                pytv.cobj = new tv_ptr(tvp) # make copy of smart pointer
                return pytv
            return TruthValue(tvp.get().getMean(), tvp.get().getConfidence())

        def __set__(self, truth_value):
            try:
                assert isinstance(truth_value, TruthValue)
            except AssertionError:
                raise TypeError("atom.av property needs a TruthValue object")
            cdef cAtom* atom_ptr = self.handle.atom_ptr()
            if atom_ptr == NULL:   # avoid null-pointer deref
                return
            atom_ptr.setTruthValue(deref((<TruthValue>truth_value)._tvptr()))

    property av:
        def __get__(self):
            cdef cAtom* atom_ptr = self.handle.atom_ptr()
            if atom_ptr == NULL:   # avoid null-pointer deref
                return None
            sti = atom_ptr.getSTI()
            lti = atom_ptr.getLTI()
            vlti = atom_ptr.getVLTI()
            return { "sti": sti, "lti": lti, "vlti": vlti }
        def __set__(self, av_dict):
            try:
                assert isinstance(av_dict, dict)
            except AssertionError:
                raise TypeError("atom.av property needs a dictionary object")
            cdef cAtom* atom_ptr = self.handle.atom_ptr()
            if atom_ptr == NULL:   # avoid null-pointer deref
                return
            if av_dict:
                if "sti" in av_dict: sti = av_dict["sti"]
                if "lti" in av_dict: lti = av_dict["lti"]
                if "vlti" in av_dict: vlti = av_dict["vlti"]
            if sti: atom_ptr.setSTI(sti)
            if lti: atom_ptr.setLTI(lti)
            if vlti: atom_ptr.setVLTI(vlti)

    property sti:
        def __get__(self):
            cdef cAtom* atom_ptr = self.handle.atom_ptr()
            if atom_ptr == NULL:   # avoid null-pointer deref
                return None
            return atom_ptr.getSTI()
        def __set__(self,val):
            cdef cAtom* atom_ptr = self.handle.atom_ptr()
            if atom_ptr == NULL:   # avoid null-pointer deref
                return
            atom_ptr.setSTI(val)

    property lti:
        def __get__(self):
            cdef cAtom* atom_ptr = self.handle.atom_ptr()
            if atom_ptr == NULL:   # avoid null-pointer deref
                return None
            return atom_ptr.getLTI()
        def __set__(self,val):
            cdef cAtom* atom_ptr = self.handle.atom_ptr()
            if atom_ptr == NULL:   # avoid null-pointer deref
                return
            atom_ptr.setLTI(val)

    property vlti:
        def __get__(self):
            cdef cAtom* atom_ptr = self.handle.atom_ptr()
            if atom_ptr == NULL:   # avoid null-pointer deref
                return None
            return atom_ptr.getVLTI()
        def __set__(self,val):
            cdef cAtom* atom_ptr = self.handle.atom_ptr()
            if atom_ptr == NULL:   # avoid null-pointer deref
                return
            atom_ptr.setVLTI(val)

    def increment_vlti(self):
        cdef cAtom* atom_ptr = self.handle.atom_ptr()
        if atom_ptr == NULL:   # avoid null-pointer deref
            return
        atom_ptr.incVLTI()

    def decrement_vlti(self):
        cdef cAtom* atom_ptr = self.handle.atom_ptr()
        if atom_ptr == NULL:   # avoid null-pointer deref
            return
        atom_ptr.decVLTI()

    def get_out(self):
        cdef cAtom* atom_ptr = self.handle.atom_ptr()
        if atom_ptr == NULL:   # avoid null-pointer deref
            return None
        cdef vector[cHandle] handle_vector = atom_ptr.getOutgoingSet()
        return convert_handle_seq_to_python_list(handle_vector, self.atomspace)

    property out:
        def __get__(self):            
            if self._outgoing is None:
                atom_ptr = self.handle.atom_ptr()
                if atom_ptr == NULL:   # avoid null-pointer deref
                    return None
                if atom_ptr.isLink():
                    self._outgoing = self.get_out()
                else:
                    self._outgoing = []
            return self._outgoing

    property arity:
        def __get__(self):
            return len(self.out)

    property incoming:
        def __get__(self):
            cdef vector[cHandle] handle_vector
            cdef cAtom* atom_ptr = self.handle.atom_ptr()
            if atom_ptr == NULL:   # avoid null-pointer deref
                return None
            atom_ptr.getIncomingSet(back_inserter(handle_vector))
            return convert_handle_seq_to_python_list(handle_vector, self.atomspace)

    property xincoming:
        def __get__(self):
            cdef vector[cHandle] handle_vector
            cdef cAtom* atom_ptr = self.handle.atom_ptr()
            if atom_ptr == NULL:   # avoid null-pointer deref
                return None
            atom_ptr.getIncomingSet(back_inserter(handle_vector))

            # This code is the same for all the x iterators but there is no
            # way in Cython to yield out of a cdef function and no way to pass a 
            # vector into a Python def function, so we have to repeat code. ARGGG!
            cdef vector[cHandle].iterator c_handle_iter
            cdef cHandle current_c_handle
            c_handle_iter = handle_vector.begin()
            while c_handle_iter != handle_vector.end():
                current_c_handle = deref(c_handle_iter)
                yield Atom(void_from_candle(current_c_handle),self)
                inc(c_handle_iter)

    def incoming_by_type(self, Type type, subtype = True):
        cdef vector[cHandle] handle_vector
        cdef bint subt = subtype
        cdef cAtom* atom_ptr = self.handle.atom_ptr()
        if atom_ptr == NULL:   # avoid null-pointer deref
            return None
        atom_ptr.getIncomingSetByType(back_inserter(handle_vector), type, subt)
        return convert_handle_seq_to_python_list(handle_vector, self.atomspace)

    def xincoming_by_type(self, Type type, subtype = True):
        cdef vector[cHandle] handle_vector
        cdef bint subt = subtype
        cdef cAtom* atom_ptr = self.handle.atom_ptr()
        if atom_ptr == NULL:   # avoid null-pointer deref
            return None
        atom_ptr.getIncomingSetByType(back_inserter(handle_vector), type, subt)

        # This code is the same for all the x iterators but there is no
        # way in Cython to yield out of a cdef function and no way to pass a 
        # vector into a Python def function, so we have to repeat code. ARGGG!
        cdef vector[cHandle].iterator c_handle_iter
        cdef cHandle current_c_handle
        c_handle_iter = handle_vector.begin()
        while c_handle_iter != handle_vector.end():
            current_c_handle = deref(c_handle_iter)
            yield Atom(void_from_candle(current_c_handle), self.atomspace)
            inc(c_handle_iter)

    property type:
        def __get__(self):
            cdef cAtom* atom_ptr
            if self._atom_type is None:
                atom_ptr = self.handle.atom_ptr()
                if atom_ptr == NULL:   # avoid null-pointer deref
                    return None
                self._atom_type = atom_ptr.getType()
            return self._atom_type

    property type_name:
        def __get__(self):
            return get_type_name(self.type)

    property t:
        def __get__(self):
            return self.type

    def truth_value(self, mean, count):
        self.tv = TruthValue(mean, count)
        return self
    
    def handle_ptr(self):
        return PyLong_FromVoidPtr(self.handle)

    def is_node(self):
        return is_a(self.t, types.Node)

    def is_link(self):
        return is_a(self.t, types.Link)

    def is_a(self,t):
        return is_a(self.t, t)

    def long_string(self):
        cdef cAtom* atom_ptr = self.handle.atom_ptr()
        if atom_ptr != NULL:
            return atom_ptr.toString()
        return ""

    def __str__(self):
        cdef cAtom* atom_ptr = self.handle.atom_ptr()
        if atom_ptr != NULL:
            return atom_ptr.toShortString()
        return ""

    def __repr__(self):
        return self.long_string()

    def __richcmp__(a1_, a2_, int op):
        if not isinstance(a1_, Atom) or not isinstance(a2_, Atom):
            return NotImplemented
        cdef Atom a1 = a1_
        cdef Atom a2 = a2_
        
        is_equal = (a1.atomspace == a2.atomspace and
                     deref(a1.handle) == deref(a2.handle))
        if op == 2: # ==
            return is_equal
        elif op == 3: # !=
            return not is_equal

    # Necessary to prevent weirdness with RPyC
    def __cmp__(a1_, a2_):
        if not isinstance(a1_, Atom) or not isinstance(a2_, Atom):
            return NotImplemented
        cdef Atom a1 = a1_
        cdef Atom a2 = a2_
        is_equal = (a1.atomspace == a2.atomspace and
                     deref(a1.handle) == deref(a2.handle))
        if is_equal:
            return 0
        else:
            return -1

    def __hash__(a1):
        return hash(a1.value())
<commit_msg>No use of uuid allowed<commit_after>
# Atom wrapper object
cdef class Atom(object):

    def __cinit__(self, PATOM lptr, AtomSpace a):
        atomo = atom_from_the_void(lptr)
        self.handle = new cHandle(atomo)

    def __dealloc__(self):
        del self.handle

    def value(self):
        return void_from_cptr(self.handle)

    def __init__(self, PATOM lptr, AtomSpace a):
        # self.handle = h is set in __cinit__ above

        # cache the results after first retrieval of
        # immutable properties
        self._atom_type = None
        self._name = None
        self._outgoing = None
        self.atomspace = a

    def __nonzero__(self):
        """ Allows boolean comparison, return false is handle is
        UNDEFINED or doesn't exist in AtomSpace """
        if self.handle:
            return self.atomspace.is_valid(self)
        else: return False

    property atomspace:
        def __get__(self):
            return self.atomspace

    property name:
        def __get__(self):
            cdef cAtom* atom_ptr
            if self._name is None:
                atom_ptr = self.handle.atom_ptr()
                if atom_ptr == NULL:   # avoid null-pointer deref
                    return None
                if atom_ptr.isNode():
                    self._name = atom_ptr.getName()
                else:
                    self._name = ""
            return self._name

    property tv:
        def __get__(self):
            cdef cAtom* atom_ptr = self.handle.atom_ptr()
            cdef tv_ptr tvp
            if atom_ptr == NULL:   # avoid null-pointer deref
                return None
            tvp = atom_ptr.getTruthValue()
            if (not tvp.get() or tvp.get().isNullTv()):
                pytv = TruthValue()
                pytv.cobj = new tv_ptr(tvp) # make copy of smart pointer
                return pytv
            return TruthValue(tvp.get().getMean(), tvp.get().getConfidence())

        def __set__(self, truth_value):
            try:
                assert isinstance(truth_value, TruthValue)
            except AssertionError:
                raise TypeError("atom.av property needs a TruthValue object")
            cdef cAtom* atom_ptr = self.handle.atom_ptr()
            if atom_ptr == NULL:   # avoid null-pointer deref
                return
            atom_ptr.setTruthValue(deref((<TruthValue>truth_value)._tvptr()))

    property av:
        def __get__(self):
            cdef cAtom* atom_ptr = self.handle.atom_ptr()
            if atom_ptr == NULL:   # avoid null-pointer deref
                return None
            sti = atom_ptr.getSTI()
            lti = atom_ptr.getLTI()
            vlti = atom_ptr.getVLTI()
            return { "sti": sti, "lti": lti, "vlti": vlti }
        def __set__(self, av_dict):
            try:
                assert isinstance(av_dict, dict)
            except AssertionError:
                raise TypeError("atom.av property needs a dictionary object")
            cdef cAtom* atom_ptr = self.handle.atom_ptr()
            if atom_ptr == NULL:   # avoid null-pointer deref
                return
            if av_dict:
                if "sti" in av_dict: sti = av_dict["sti"]
                if "lti" in av_dict: lti = av_dict["lti"]
                if "vlti" in av_dict: vlti = av_dict["vlti"]
            if sti: atom_ptr.setSTI(sti)
            if lti: atom_ptr.setLTI(lti)
            if vlti: atom_ptr.setVLTI(vlti)

    property sti:
        def __get__(self):
            cdef cAtom* atom_ptr = self.handle.atom_ptr()
            if atom_ptr == NULL:   # avoid null-pointer deref
                return None
            return atom_ptr.getSTI()
        def __set__(self,val):
            cdef cAtom* atom_ptr = self.handle.atom_ptr()
            if atom_ptr == NULL:   # avoid null-pointer deref
                return
            atom_ptr.setSTI(val)

    property lti:
        def __get__(self):
            cdef cAtom* atom_ptr = self.handle.atom_ptr()
            if atom_ptr == NULL:   # avoid null-pointer deref
                return None
            return atom_ptr.getLTI()
        def __set__(self,val):
            cdef cAtom* atom_ptr = self.handle.atom_ptr()
            if atom_ptr == NULL:   # avoid null-pointer deref
                return
            atom_ptr.setLTI(val)

    property vlti:
        def __get__(self):
            cdef cAtom* atom_ptr = self.handle.atom_ptr()
            if atom_ptr == NULL:   # avoid null-pointer deref
                return None
            return atom_ptr.getVLTI()
        def __set__(self,val):
            cdef cAtom* atom_ptr = self.handle.atom_ptr()
            if atom_ptr == NULL:   # avoid null-pointer deref
                return
            atom_ptr.setVLTI(val)

    def increment_vlti(self):
        cdef cAtom* atom_ptr = self.handle.atom_ptr()
        if atom_ptr == NULL:   # avoid null-pointer deref
            return
        atom_ptr.incVLTI()

    def decrement_vlti(self):
        cdef cAtom* atom_ptr = self.handle.atom_ptr()
        if atom_ptr == NULL:   # avoid null-pointer deref
            return
        atom_ptr.decVLTI()

    def get_out(self):
        cdef cAtom* atom_ptr = self.handle.atom_ptr()
        if atom_ptr == NULL:   # avoid null-pointer deref
            return None
        cdef vector[cHandle] handle_vector = atom_ptr.getOutgoingSet()
        return convert_handle_seq_to_python_list(handle_vector, self.atomspace)

    property out:
        def __get__(self):            
            if self._outgoing is None:
                atom_ptr = self.handle.atom_ptr()
                if atom_ptr == NULL:   # avoid null-pointer deref
                    return None
                if atom_ptr.isLink():
                    self._outgoing = self.get_out()
                else:
                    self._outgoing = []
            return self._outgoing

    property arity:
        def __get__(self):
            return len(self.out)

    property incoming:
        def __get__(self):
            cdef vector[cHandle] handle_vector
            cdef cAtom* atom_ptr = self.handle.atom_ptr()
            if atom_ptr == NULL:   # avoid null-pointer deref
                return None
            atom_ptr.getIncomingSet(back_inserter(handle_vector))
            return convert_handle_seq_to_python_list(handle_vector, self.atomspace)

    property xincoming:
        def __get__(self):
            cdef vector[cHandle] handle_vector
            cdef cAtom* atom_ptr = self.handle.atom_ptr()
            if atom_ptr == NULL:   # avoid null-pointer deref
                return None
            atom_ptr.getIncomingSet(back_inserter(handle_vector))

            # This code is the same for all the x iterators but there is no
            # way in Cython to yield out of a cdef function and no way to pass a 
            # vector into a Python def function, so we have to repeat code. ARGGG!
            cdef vector[cHandle].iterator c_handle_iter
            cdef cHandle current_c_handle
            c_handle_iter = handle_vector.begin()
            while c_handle_iter != handle_vector.end():
                current_c_handle = deref(c_handle_iter)
                yield Atom(void_from_candle(current_c_handle),self)
                inc(c_handle_iter)

    def incoming_by_type(self, Type type, subtype = True):
        cdef vector[cHandle] handle_vector
        cdef bint subt = subtype
        cdef cAtom* atom_ptr = self.handle.atom_ptr()
        if atom_ptr == NULL:   # avoid null-pointer deref
            return None
        atom_ptr.getIncomingSetByType(back_inserter(handle_vector), type, subt)
        return convert_handle_seq_to_python_list(handle_vector, self.atomspace)

    def xincoming_by_type(self, Type type, subtype = True):
        cdef vector[cHandle] handle_vector
        cdef bint subt = subtype
        cdef cAtom* atom_ptr = self.handle.atom_ptr()
        if atom_ptr == NULL:   # avoid null-pointer deref
            return None
        atom_ptr.getIncomingSetByType(back_inserter(handle_vector), type, subt)

        # This code is the same for all the x iterators but there is no
        # way in Cython to yield out of a cdef function and no way to pass a 
        # vector into a Python def function, so we have to repeat code. ARGGG!
        cdef vector[cHandle].iterator c_handle_iter
        cdef cHandle current_c_handle
        c_handle_iter = handle_vector.begin()
        while c_handle_iter != handle_vector.end():
            current_c_handle = deref(c_handle_iter)
            yield Atom(void_from_candle(current_c_handle), self.atomspace)
            inc(c_handle_iter)

    property type:
        def __get__(self):
            cdef cAtom* atom_ptr
            if self._atom_type is None:
                atom_ptr = self.handle.atom_ptr()
                if atom_ptr == NULL:   # avoid null-pointer deref
                    return None
                self._atom_type = atom_ptr.getType()
            return self._atom_type

    property type_name:
        def __get__(self):
            return get_type_name(self.type)

    property t:
        def __get__(self):
            return self.type

    def truth_value(self, mean, count):
        self.tv = TruthValue(mean, count)
        return self
    
    def handle_ptr(self):
        return PyLong_FromVoidPtr(self.handle)

    def is_node(self):
        return is_a(self.t, types.Node)

    def is_link(self):
        return is_a(self.t, types.Link)

    def is_a(self,t):
        return is_a(self.t, t)

    def long_string(self):
        cdef cAtom* atom_ptr = self.handle.atom_ptr()
        if atom_ptr != NULL:
            return atom_ptr.toString()
        return ""

    def __str__(self):
        cdef cAtom* atom_ptr = self.handle.atom_ptr()
        if atom_ptr != NULL:
            return atom_ptr.toShortString()
        return ""

    def __repr__(self):
        return self.long_string()

    def __richcmp__(a1_, a2_, int op):
        if not isinstance(a1_, Atom) or not isinstance(a2_, Atom):
            return NotImplemented
        cdef Atom a1 = a1_
        cdef Atom a2 = a2_
        
        is_equal = (a1.atomspace == a2.atomspace and
                     deref(a1.handle) == deref(a2.handle))
        if op == 2: # ==
            return is_equal
        elif op == 3: # !=
            return not is_equal

    # Necessary to prevent weirdness with RPyC
    def __cmp__(a1_, a2_):
        if not isinstance(a1_, Atom) or not isinstance(a2_, Atom):
            return NotImplemented
        cdef Atom a1 = a1_
        cdef Atom a2 = a2_
        is_equal = (a1.atomspace == a2.atomspace and
                     deref(a1.handle) == deref(a2.handle))
        if is_equal:
            return 0
        else:
            return -1

    def __hash__(a1):
        return hash(a1.value())

{'fraction_non_alphanumeric': 0.07948635338518893, 'fraction_numerical': 0.002761540939844433, 'mean_word_length': 1.7703684814484253, 'pattern_counts': {'":': 6, '<': 5, '<?xml version=': 0, '>': 5, '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': '4602891', 'n_tokens_mistral': 6603, 'n_tokens_neox': 6385, 'n_words': 1696}