<commit_before>#
# Definitions for automatically building the atom_types files, given
# a master file "atom_types.script" that defines all of the type
# relationships.
#
IF (NOT SCRIPT_FILE)
	SET (SCRIPT_FILE "atom_types.script")
ENDIF (NOT SCRIPT_FILE)

IF (NOT HEADER_FILE)
	SET (HEADER_FILE "atom_types.h")
ENDIF (NOT HEADER_FILE)

IF (NOT DEFINITIONS_FILE)
	SET (DEFINITIONS_FILE "atom_types.definitions")
ENDIF (NOT DEFINITIONS_FILE)

IF (NOT INHERITANCE_FILE)
	SET (INHERITANCE_FILE "atom_types.inheritance")
ENDIF (NOT INHERITANCE_FILE)

IF (NOT SCM_FILE)
	SET (SCM_FILE "../scm/type_constructors.scm")
ENDIF (NOT SCM_FILE)

# Check if this is for opencog/atomspace directory. If so, do not reference opencog::classserver() 
# to avoid infinit recursivity in ClassServer constructor.
STRING(REGEX MATCH ".*/opencog/atomspace" OPENCOG_ATOMSPACE_MATCHED "${CMAKE_CURRENT_SOURCE_DIR}")
IF (OPENCOG_ATOMSPACE_MATCHED)
    SET(CLASSSERVER_REFERENCE "")
ELSE (OPENCOG_ATOMSPACE_MATCHED)
    SET(CLASSSERVER_REFERENCE "opencog::classserver().")
ENDIF (OPENCOG_ATOMSPACE_MATCHED)
#MESSAGE(STATUS "CLASSSERVER_REFERENCE=${CLASSSERVER_REFERENCE}")

FILE(WRITE "${HEADER_FILE}" "/* File automatically generated by the macro OPENCOG_ADD_ATOM_TYPES. Do not edit */\n")
FILE(APPEND "${HEADER_FILE}"  "#include <opencog/atomspace/types.h>\nnamespace opencog\n{\n")
FILE(WRITE "${DEFINITIONS_FILE}"  "/* File automatically generated by the macro OPENCOG_ADD_ATOM_TYPES. Do not edit */\n#include <opencog/atomspace/ClassServer.h>\n#include <opencog/atomspace/atom_types.h>\n#include <opencog/atomspace/types.h>\n#include \"atom_types.h\"\n")
FILE(WRITE "${INHERITANCE_FILE}"  "/* File automatically generated by the macro OPENCOG_ADD_ATOM_TYPES. Do not edit */\n")

FILE(WRITE "${SCM_FILE}" "\n")
FILE(APPEND "${SCM_FILE}" "; DO NOT EDIT THIS FILE! This file was automatically\n")
FILE(APPEND "${SCM_FILE}" "; generated from atom definitions in types.script by the macro OPENCOG_ADD_ATOM_TYPES\n")
FILE(APPEND "${SCM_FILE}" ";\n")
FILE(APPEND "${SCM_FILE}" "; This file contains basic scheme wrappers for atom creation.\n")
FILE(APPEND "${SCM_FILE}" ";\n")

FILE(STRINGS "${SCRIPT_FILE}" TYPE_SCRIPT_CONTENTS)
FOREACH (LINE ${TYPE_SCRIPT_CONTENTS})
    # this regular expression is more complex than required due to cmake's
    # regex engine bugs
    STRING(REGEX MATCH "^[ 	]*([A-Z_]+)?([ 	]*<-[ 	]*([A-Z_, 	]+))?[ 	]*(\"[A-Za-z]*\")?[ 	]*(//.*)?[ 	]*$" MATCHED "${LINE}")
    IF (MATCHED AND CMAKE_MATCH_1)
        SET(TYPE ${CMAKE_MATCH_1})
        SET(PARENT_TYPES ${CMAKE_MATCH_3})
        SET(TYPE_NAME "")
        IF (CMAKE_MATCH_4)
            MESSAGE(STATUS "Custom atom type name specified: ${CMAKE_MATCH_4}")
            STRING(REGEX MATCHALL "." CHARS ${CMAKE_MATCH_4})
            LIST(LENGTH CHARS LIST_LENGTH)
            MATH(EXPR LAST_INDEX "${LIST_LENGTH} - 1")
            FOREACH(I RANGE ${LAST_INDEX})
                LIST(GET CHARS ${I} C)
                IF (NOT ${C} STREQUAL "\"")
                    SET(TYPE_NAME "${TYPE_NAME}${C}")
                ENDIF (NOT ${C} STREQUAL "\"")
            ENDFOREACH(I RANGE ${LIST_LENGTH})
        ENDIF (CMAKE_MATCH_4)

        IF (NOT "${TYPE}" STREQUAL "NOTYPE")
            FILE(APPEND "${HEADER_FILE}" "extern opencog::Type ${TYPE};\n")
            FILE(APPEND "${DEFINITIONS_FILE}"  "opencog::Type opencog::${TYPE};\n")
        ELSE (NOT "${TYPE}" STREQUAL "NOTYPE")
            FILE(APPEND "${HEADER_FILE}"  "#ifndef _OPENCOG_NOTYPE_\n#define _OPENCOG_NOTYPE_\n")
            FILE(APPEND "${HEADER_FILE}"  "// set notype's code with the last possible Type code, which is\n")
            FILE(APPEND "${HEADER_FILE}"  "//    ((1 << (2 * sizeof(Type))) - 1) == 65535\n")
            FILE(APPEND "${HEADER_FILE}"  "// as Type == unsigned short int\n")
            FILE(APPEND "${HEADER_FILE}"  "static const opencog::Type ${TYPE}=((1 << (8 * sizeof(Type))) - 1);\n")
            FILE(APPEND "${HEADER_FILE}"  "#endif // _OPENCOG_NOTYPE_\n")
        ENDIF (NOT "${TYPE}" STREQUAL "NOTYPE")

        IF (TYPE_NAME STREQUAL "")
            # set type name using camel casing
            STRING(REGEX MATCHALL "." CHARS ${TYPE})
            LIST(LENGTH CHARS LIST_LENGTH)
            MATH(EXPR LAST_INDEX "${LIST_LENGTH} - 1")
            FOREACH(I RANGE ${LAST_INDEX})
                LIST(GET CHARS ${I} C)
                IF (NOT ${C} STREQUAL "_")
                    MATH(EXPR IP "${I} - 1")
                    LIST(GET CHARS ${IP} CP)
                    IF (${I} EQUAL 0)
                        SET(TYPE_NAME "${TYPE_NAME}${C}")
                    ELSE (${I} EQUAL 0)
                        IF (${CP} STREQUAL "_")
                            SET(TYPE_NAME "${TYPE_NAME}${C}")
                        ELSE (${CP} STREQUAL "_")
                            STRING(TOLOWER "${C}" CL)
                            SET(TYPE_NAME "${TYPE_NAME}${CL}")
                        ENDIF (${CP} STREQUAL "_")
                    ENDIF (${I} EQUAL 0)
                ENDIF (NOT ${C} STREQUAL "_")
            ENDFOREACH(I RANGE ${LIST_LENGTH})
        ENDIF (TYPE_NAME STREQUAL "")
        
        MESSAGE(STATUS "Atom type name: ${TYPE_NAME}")

        # Try to guess if the thing is a node or link based on its name
        STRING(REGEX MATCH "NODE$" ISNODE ${TYPE})
        STRING(REGEX MATCH "LINK$" ISLINK ${TYPE})

        # Print out the scheme definitions
        IF (ISNODE STREQUAL "NODE")
            FILE(APPEND "${SCM_FILE}" "(define (${TYPE_NAME} . x)\n")
            FILE(APPEND "${SCM_FILE}" "\t(apply cog-new-node (append (list '${TYPE_NAME}) x)))\n")
        ENDIF (ISNODE STREQUAL "NODE")
        IF (ISLINK STREQUAL "LINK")
            FILE(APPEND "${SCM_FILE}" "(define (${TYPE_NAME} . x)\n")
            FILE(APPEND "${SCM_FILE}" "\t(apply cog-new-link (append (list '${TYPE_NAME}) x)))\n")
        ENDIF (ISLINK STREQUAL "LINK")

        IF (PARENT_TYPES)
            STRING(REGEX REPLACE "[ 	]*,[ 	]*" ";" PARENT_TYPES "${PARENT_TYPES}")
            FOREACH (PARENT_TYPE ${PARENT_TYPES})
                # skip inheritance of the special "notype" class; we could move
                # this test up but it was left here for simplicity's sake
                IF (NOT "${TYPE}" STREQUAL "NOTYPE")
                    FILE(APPEND "${INHERITANCE_FILE}" "opencog::${TYPE} = ${CLASSSERVER_REFERENCE}addType(opencog::${PARENT_TYPE}, \"${TYPE_NAME}\");\n")
                ENDIF (NOT "${TYPE}" STREQUAL "NOTYPE")
            ENDFOREACH (PARENT_TYPE)
        ELSE (PARENT_TYPES)
            IF (NOT "${TYPE}" STREQUAL "NOTYPE")
                FILE(APPEND "${INHERITANCE_FILE}" "opencog::${TYPE} = ${CLASSSERVER_REFERENCE}addType(opencog::${TYPE}, \"${TYPE_NAME}\");\n")
            ENDIF (NOT "${TYPE}" STREQUAL "NOTYPE")
        ENDIF (PARENT_TYPES)<commit_msg>If atom type is not explicit, assume its a link.<commit_after>#
# Definitions for automatically building the atom_types files, given
# a master file "atom_types.script" that defines all of the type
# relationships.
#
IF (NOT SCRIPT_FILE)
	SET (SCRIPT_FILE "atom_types.script")
ENDIF (NOT SCRIPT_FILE)

IF (NOT HEADER_FILE)
	SET (HEADER_FILE "atom_types.h")
ENDIF (NOT HEADER_FILE)

IF (NOT DEFINITIONS_FILE)
	SET (DEFINITIONS_FILE "atom_types.definitions")
ENDIF (NOT DEFINITIONS_FILE)

IF (NOT INHERITANCE_FILE)
	SET (INHERITANCE_FILE "atom_types.inheritance")
ENDIF (NOT INHERITANCE_FILE)

IF (NOT SCM_FILE)
	SET (SCM_FILE "../scm/type_constructors.scm")
ENDIF (NOT SCM_FILE)

# Check if this is for opencog/atomspace directory. If so, do not reference opencog::classserver() 
# to avoid infinit recursivity in ClassServer constructor.
STRING(REGEX MATCH ".*/opencog/atomspace" OPENCOG_ATOMSPACE_MATCHED "${CMAKE_CURRENT_SOURCE_DIR}")
IF (OPENCOG_ATOMSPACE_MATCHED)
    SET(CLASSSERVER_REFERENCE "")
ELSE (OPENCOG_ATOMSPACE_MATCHED)
    SET(CLASSSERVER_REFERENCE "opencog::classserver().")
ENDIF (OPENCOG_ATOMSPACE_MATCHED)
#MESSAGE(STATUS "CLASSSERVER_REFERENCE=${CLASSSERVER_REFERENCE}")

FILE(WRITE "${HEADER_FILE}" "/* File automatically generated by the macro OPENCOG_ADD_ATOM_TYPES. Do not edit */\n")
FILE(APPEND "${HEADER_FILE}"  "#include <opencog/atomspace/types.h>\nnamespace opencog\n{\n")
FILE(WRITE "${DEFINITIONS_FILE}"  "/* File automatically generated by the macro OPENCOG_ADD_ATOM_TYPES. Do not edit */\n#include <opencog/atomspace/ClassServer.h>\n#include <opencog/atomspace/atom_types.h>\n#include <opencog/atomspace/types.h>\n#include \"atom_types.h\"\n")
FILE(WRITE "${INHERITANCE_FILE}"  "/* File automatically generated by the macro OPENCOG_ADD_ATOM_TYPES. Do not edit */\n")

FILE(WRITE "${SCM_FILE}" "\n")
FILE(APPEND "${SCM_FILE}" "; DO NOT EDIT THIS FILE! This file was automatically\n")
FILE(APPEND "${SCM_FILE}" "; generated from atom definitions in types.script by the macro OPENCOG_ADD_ATOM_TYPES\n")
FILE(APPEND "${SCM_FILE}" ";\n")
FILE(APPEND "${SCM_FILE}" "; This file contains basic scheme wrappers for atom creation.\n")
FILE(APPEND "${SCM_FILE}" ";\n")

FILE(STRINGS "${SCRIPT_FILE}" TYPE_SCRIPT_CONTENTS)
FOREACH (LINE ${TYPE_SCRIPT_CONTENTS})
    # this regular expression is more complex than required due to cmake's
    # regex engine bugs
    STRING(REGEX MATCH "^[ 	]*([A-Z_]+)?([ 	]*<-[ 	]*([A-Z_, 	]+))?[ 	]*(\"[A-Za-z]*\")?[ 	]*(//.*)?[ 	]*$" MATCHED "${LINE}")
    IF (MATCHED AND CMAKE_MATCH_1)
        SET(TYPE ${CMAKE_MATCH_1})
        SET(PARENT_TYPES ${CMAKE_MATCH_3})
        SET(TYPE_NAME "")
        IF (CMAKE_MATCH_4)
            MESSAGE(STATUS "Custom atom type name specified: ${CMAKE_MATCH_4}")
            STRING(REGEX MATCHALL "." CHARS ${CMAKE_MATCH_4})
            LIST(LENGTH CHARS LIST_LENGTH)
            MATH(EXPR LAST_INDEX "${LIST_LENGTH} - 1")
            FOREACH(I RANGE ${LAST_INDEX})
                LIST(GET CHARS ${I} C)
                IF (NOT ${C} STREQUAL "\"")
                    SET(TYPE_NAME "${TYPE_NAME}${C}")
                ENDIF (NOT ${C} STREQUAL "\"")
            ENDFOREACH(I RANGE ${LIST_LENGTH})
        ENDIF (CMAKE_MATCH_4)

        IF (NOT "${TYPE}" STREQUAL "NOTYPE")
            FILE(APPEND "${HEADER_FILE}" "extern opencog::Type ${TYPE};\n")
            FILE(APPEND "${DEFINITIONS_FILE}"  "opencog::Type opencog::${TYPE};\n")
        ELSE (NOT "${TYPE}" STREQUAL "NOTYPE")
            FILE(APPEND "${HEADER_FILE}"  "#ifndef _OPENCOG_NOTYPE_\n#define _OPENCOG_NOTYPE_\n")
            FILE(APPEND "${HEADER_FILE}"  "// set notype's code with the last possible Type code, which is\n")
            FILE(APPEND "${HEADER_FILE}"  "//    ((1 << (2 * sizeof(Type))) - 1) == 65535\n")
            FILE(APPEND "${HEADER_FILE}"  "// as Type == unsigned short int\n")
            FILE(APPEND "${HEADER_FILE}"  "static const opencog::Type ${TYPE}=((1 << (8 * sizeof(Type))) - 1);\n")
            FILE(APPEND "${HEADER_FILE}"  "#endif // _OPENCOG_NOTYPE_\n")
        ENDIF (NOT "${TYPE}" STREQUAL "NOTYPE")

        IF (TYPE_NAME STREQUAL "")
            # set type name using camel casing
            STRING(REGEX MATCHALL "." CHARS ${TYPE})
            LIST(LENGTH CHARS LIST_LENGTH)
            MATH(EXPR LAST_INDEX "${LIST_LENGTH} - 1")
            FOREACH(I RANGE ${LAST_INDEX})
                LIST(GET CHARS ${I} C)
                IF (NOT ${C} STREQUAL "_")
                    MATH(EXPR IP "${I} - 1")
                    LIST(GET CHARS ${IP} CP)
                    IF (${I} EQUAL 0)
                        SET(TYPE_NAME "${TYPE_NAME}${C}")
                    ELSE (${I} EQUAL 0)
                        IF (${CP} STREQUAL "_")
                            SET(TYPE_NAME "${TYPE_NAME}${C}")
                        ELSE (${CP} STREQUAL "_")
                            STRING(TOLOWER "${C}" CL)
                            SET(TYPE_NAME "${TYPE_NAME}${CL}")
                        ENDIF (${CP} STREQUAL "_")
                    ENDIF (${I} EQUAL 0)
                ENDIF (NOT ${C} STREQUAL "_")
            ENDFOREACH(I RANGE ${LIST_LENGTH})
        ENDIF (TYPE_NAME STREQUAL "")
        
        MESSAGE(STATUS "Atom type name: ${TYPE_NAME}")

        # Try to guess if the thing is a node or link based on its name
        STRING(REGEX MATCH "NODE$" ISNODE ${TYPE})
        STRING(REGEX MATCH "LINK$" ISLINK ${TYPE})

        # Print out the scheme definitions
        IF (ISNODE STREQUAL "NODE")
            FILE(APPEND "${SCM_FILE}" "(define (${TYPE_NAME} . x)\n")
            FILE(APPEND "${SCM_FILE}" "\t(apply cog-new-node (append (list '${TYPE_NAME}) x)))\n")
        ENDIF (ISNODE STREQUAL "NODE")
        IF (ISLINK STREQUAL "LINK")
            FILE(APPEND "${SCM_FILE}" "(define (${TYPE_NAME} . x)\n")
            FILE(APPEND "${SCM_FILE}" "\t(apply cog-new-link (append (list '${TYPE_NAME}) x)))\n")
        ENDIF (ISLINK STREQUAL "LINK")

        # If not named as a node or a link, assume its a link
        # This is kind of hacky, but I don't know what else to do ... 
        IF (NOT ISNODE STREQUAL "NODE" AND NOT ISLINK STREQUAL "LINK")
            FILE(APPEND "${SCM_FILE}" "(define (${TYPE_NAME} . x)\n")
            FILE(APPEND "${SCM_FILE}" "\t(apply cog-new-link (append (list '${TYPE_NAME}) x)))\n")
        ENDIF (NOT ISNODE STREQUAL "NODE" AND NOT ISLINK STREQUAL "LINK")

        IF (PARENT_TYPES)
            STRING(REGEX REPLACE "[ 	]*,[ 	]*" ";" PARENT_TYPES "${PARENT_TYPES}")
            FOREACH (PARENT_TYPE ${PARENT_TYPES})
                # skip inheritance of the special "notype" class; we could move
                # this test up but it was left here for simplicity's sake
                IF (NOT "${TYPE}" STREQUAL "NOTYPE")
                    FILE(APPEND "${INHERITANCE_FILE}" "opencog::${TYPE} = ${CLASSSERVER_REFERENCE}addType(opencog::${PARENT_TYPE}, \"${TYPE_NAME}\");\n")
                ENDIF (NOT "${TYPE}" STREQUAL "NOTYPE")
            ENDFOREACH (PARENT_TYPE)
        ELSE (PARENT_TYPES)
            IF (NOT "${TYPE}" STREQUAL "NOTYPE")
                FILE(APPEND "${INHERITANCE_FILE}" "opencog::${TYPE} = ${CLASSSERVER_REFERENCE}addType(opencog::${TYPE}, \"${TYPE_NAME}\");\n")
            ENDIF (NOT "${TYPE}" STREQUAL "NOTYPE")
        ENDIF (PARENT_TYPES)
{'fraction_non_alphanumeric': 0.14926111857455984, 'fraction_numerical': 0.003393905112069575, 'mean_word_length': 2.7250460890176456, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 11, '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': '1848929', 'n_tokens_mistral': 5017, 'n_tokens_neox': 4737, 'n_words': 1189}