### CMake Project Structure Setup Source: https://github.com/opencog/lg-atomese/blob/master/opencog/nlp/cython/CMakeLists.txt Demonstrates CMake commands for creating directories and copying files to establish the project's directory structure and initialize modules. ```CMake ADD_SUBDIRECTORY (opencog) file(MAKE_DIRECTORY opencog) file(MAKE_DIRECTORY opencog/nlp) file(COPY opencog/__init__.py DESTINATION opencog/nlp) ``` -------------------------------- ### CMake: Install lg-atomese Libraries and Headers Source: https://github.com/opencog/lg-atomese/blob/master/opencog/nlp/lg-dict/CMakeLists.txt Configures the installation process for the lg-atomese component. It specifies the destination directories for the shared libraries ('lg-dict-entry', 'lg-dict') and header files, ensuring they are placed correctly within the project's installation structure. ```cmake INSTALL (TARGETS lg-dict-entry EXPORT LGAtomeseTargets DESTINATION "lib${LIB_DIR_SUFFIX}/opencog" ) INSTALL (TARGETS lg-dict EXPORT LGAtomeseTargets DESTINATION "lib${LIB_DIR_SUFFIX}/opencog" ) INSTALL (FILES LGDictEntry.h LGDictNode.h LGDictUtils.h DESTINATION "include/${PROJECT_NAME}/nlp/lg-dict" ) ``` -------------------------------- ### Build LG-Atomese Project Source: https://github.com/opencog/lg-atomese/blob/master/README.md Steps to build and install the LG-Atomese project using CMake and Make. This involves creating a build directory, configuring with CMake, compiling, and installing the libraries. ```shell cd to project root dir mkdir build cd build cmake .. make sudo make install ``` -------------------------------- ### Example: Executing LgParseLink in Scheme Source: https://github.com/opencog/lg-atomese/blob/master/opencog/nlp/lg-parse/README.md A practical example demonstrating how to use the `LgParseLink` function within a Scheme environment in OpenCog to parse a sentence and print the AtomSpace. ```Scheme (use-modules (opencog) (opencog nlp) (opencog nlp lg-parse) (opencog exec)) (cog-execute! (LgParseLink (PhraseNode "this is a test.") (LgDictNode "en") (NumberNode 1))) (cog-prt-atomspace) ``` -------------------------------- ### CMake Build Configuration Source: https://github.com/opencog/lg-atomese/blob/master/opencog/CMakeLists.txt Core CMake commands used to configure the build process. This includes setting include directories, adding subdirectories for modular builds, and managing file installations. ```cmake INCLUDE_DIRECTORIES(${CMAKE_BINARY_DIR}) ``` ```cmake ADD_SUBDIRECTORY (nlp) ``` ```cmake INSTALL(FILES ${GUILE_BIN_DIR}/opencog/lg-config.scm DESTINATION ${GUILE_SITE_DIR}/opencog RENAME lg-config.scm) ``` -------------------------------- ### Install NLP Types Library and Headers Source: https://github.com/opencog/lg-atomese/blob/master/opencog/nlp/types/CMakeLists.txt Installs the 'nlp-types' shared library to the appropriate destination within the installation directory and copies the 'atom_types.h' header file to the include path for external use. ```cmake INSTALL (TARGETS nlp-types EXPORT LGAtomeseTargets LIBRARY DESTINATION "lib${LIB_DIR_SUFFIX}/opencog" ) INSTALL (FILES ${CMAKE_CURRENT_BINARY_DIR}/atom_types.h DESTINATION "include/${PROJECT_NAME}/nlp/types" ) ``` -------------------------------- ### Get Debian Architecture with dpkg Source: https://github.com/opencog/lg-atomese/blob/master/CMakeLists.txt Retrieves the system's architecture using the `dpkg --print-architecture` command. This command is typically used on Debian-based systems to determine the correct architecture for package installation or building. ```shell dpkg --print-architecture ``` -------------------------------- ### Enable Testing and Include CxxTest Source: https://github.com/opencog/lg-atomese/blob/master/tests/CMakeLists.txt Enables the testing framework for the project and includes the CxxTest testing framework. This is a common setup for C++ projects using CMake for testing. ```cmake ENABLE_TESTING() INCLUDE(AddCxxtest) ``` -------------------------------- ### LG-Atomese CMake Build Configuration Source: https://github.com/opencog/lg-atomese/blob/master/opencog/nlp/lg-parse/CMakeLists.txt This CMakeLists.txt file configures the build process for the LG-Atomese library. It specifies include directories, defines the SHARED library target 'lg-parse', sets up dependencies and library linking, handles installation, and registers Guile modules and extensions. ```cmake INCLUDE_DIRECTORIES ( ${LINK_GRAMMAR_INCLUDE_DIRS} # for LinkGrammar dictionary ${UUID_INCLUDE_DIRS} ${CMAKE_BINARY_DIR} # for the NLP atom types ) ADD_LIBRARY (lg-parse SHARED LGParseLink.cc ) ADD_DEPENDENCIES (lg-parse nlp_atom_types) TARGET_LINK_LIBRARIES (lg-parse lg-dict-entry nlp-types ${ATOMSPACE_STORAGE_LIBRARIES} ${ATOMSPACE_LIBRARIES} ${LINK_GRAMMAR_LIBRARY} ${UUID_LIBRARIES} ) INSTALL (TARGETS lg-parse EXPORT LGAtomeseTargets DESTINATION "lib${LIB_DIR_SUFFIX}/opencog" ) ADD_GUILE_MODULE (FILES lg-parse.scm lg-parse-utils.scm MODULE_DESTINATION "${GUILE_SITE_DIR}/opencog/nlp/lg-parse" ) ADD_GUILE_EXTENSION(SCM_CONFIG lg-parse "opencog-ext-path-lg-parse") ``` -------------------------------- ### Install Dependencies Source: https://github.com/opencog/lg-atomese/blob/master/opencog/nlp/cython/README.md Installs Cython and Nosetests, which are required dependencies for the Python bindings, using the easy_install package manager. Cython allows writing Pythonic code compiled to C. ```shell sudo easy_install cython nose ``` -------------------------------- ### CMake Cython Module Build Source: https://github.com/opencog/lg-atomese/blob/master/opencog/nlp/cython/opencog/CMakeLists.txt Defines the build process for a Cython module named 'nlp_types'. It generates the C++ source from the '.pyx' file, creates a shared library, links it with necessary dependencies (nlp-types, AtomSpace, Python), sets output properties, and installs it into the Python site-packages directory. ```CMake CYTHON_ADD_MODULE_PYX(nlp_types "nlp_types.pyx" ) list(APPEND ADDITIONAL_MAKE_CLEAN_FILES "nlp_types.cpp") # opencog.nlp_types Python bindings INCLUDE_DIRECTORIES(${CMAKE_BINARY_DIR}) ADD_LIBRARY(nlp_types_cython SHARED nlp_types.cpp ) ADD_DEPENDENCIES(nlp_types_cython nlp-types) TARGET_LINK_LIBRARIES(nlp_types_cython nlp-types ${ATOMSPACE_LIBRARIES} ${Python3_LIBRARIES} ) SET_TARGET_PROPERTIES(nlp_types_cython PROPERTIES PREFIX "" OUTPUT_NAME nlp_types) INSTALL (TARGETS nlp_types_cython DESTINATION "${PYTHON_DEST}") ``` -------------------------------- ### Guile: lg-dict Module and Extension Configuration Source: https://github.com/opencog/lg-atomese/blob/master/opencog/nlp/lg-dict/CMakeLists.txt Sets up the Guile Scheme integration for the lg-dict component. This includes defining the Guile module 'lg-dict.scm' and registering a Guile extension, specifying their installation paths for use within the OpenCog environment. ```guile ADD_GUILE_MODULE (FILES lg-dict.scm MODULE_DESTINATION "${GUILE_SITE_DIR}/opencog/nlp/lg-dict" ) ADD_GUILE_EXTENSION(SCM_CONFIG lg-dict "opencog-ext-path-lg-dict") ``` -------------------------------- ### CMake Configuration for OpenCog Project Source: https://github.com/opencog/lg-atomese/blob/master/CMakeLists.txt This CMake script sets up the build environment for the OpenCog project. It checks for required libraries such as CogUtil, AtomSpace, and UUID, defines build types (Release, Debug, etc.), and configures project-specific options and definitions. ```CMake # # Master Opencog CMake file. # # General organization: # -- check for different compilers, OS'es # -- search for various required & optional libraries/tools # -- decide what to build based on above results. # -- configure various config files. # -- print pretty summary # # cogutils already requires 2.8.12.2, so may as well ask for that. CMAKE_MINIMUM_REQUIRED(VERSION 2.8.12.2) IF (COMMAND CMAKE_POLICY) CMAKE_POLICY(SET CMP0003 NEW) ENDIF (COMMAND CMAKE_POLICY) IF(CMAKE_VERSION VERSION_GREATER 3.0.2) CMAKE_POLICY(SET CMP0037 OLD) ENDIF(CMAKE_VERSION VERSION_GREATER 3.0.2) PROJECT(opencog) # ---------------------------------------------------------- # User-modifiable options. Feel free to change these! # # uncomment to be in Release mode [default] # SET(CMAKE_BUILD_TYPE Release) # uncomment to build in debug mode # SET(CMAKE_BUILD_TYPE Debug) # uncomment to be in coverage testing mode # SET(CMAKE_BUILD_TYPE Coverage) # uncomment to build in profile mode # SET(CMAKE_BUILD_TYPE Profile) # uncomment to build in release mode with debug information # SET(CMAKE_BUILD_TYPE RelWithDebInfo) # default build type IF (CMAKE_BUILD_TYPE STREQUAL "") SET(CMAKE_BUILD_TYPE Release) ENDIF (CMAKE_BUILD_TYPE STREQUAL "") MESSAGE(STATUS "Build type: ${CMAKE_BUILD_TYPE}") ADD_DEFINITIONS(-DPROJECT_SOURCE_DIR="${CMAKE_SOURCE_DIR}" -DPROJECT_BINARY_DIR="${CMAKE_BINARY_DIR}") # =============================================================== # Check for existance of various required, optional packages. # Listed in alphabetical order, more or less. # CogUtil must come first, because it supplies various FindXXX macros. # Add the 'lib' dir to cmake's module search path list(APPEND CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/lib/") # Cogutil FIND_PACKAGE(CogUtil 2.0.1 CONFIG REQUIRED) IF (COGUTIL_FOUND) MESSAGE(STATUS "CogUtil found.") ADD_DEFINITIONS(-DHAVE_COGUTIL) SET(HAVE_COGUTIL 1) ELSE (COGUTIL_FOUND) MESSAGE(FATAL_ERROR "CogUtil missing: it is needed!") ENDIF (COGUTIL_FOUND) # Add the 'cmake' directory from cogutil to search path LIST(APPEND CMAKE_MODULE_PATH ${COGUTIL_DATA_DIR}/cmake) INCLUDE(OpenCogGccOptions) INCLUDE(OpenCogLibOptions) INCLUDE(OpenCogInstallOptions) INCLUDE(Summary) # =================================================================== # Check for existance of various required, optional packages. # AtomSpace FIND_PACKAGE(AtomSpace 5.0.3 CONFIG REQUIRED) IF (ATOMSPACE_FOUND) MESSAGE(STATUS "AtomSpace found.") ADD_DEFINITIONS(-DHAVE_ATOMSPACE) SET(HAVE_ATOMSPACE 1) ELSE (ATOMSPACE_FOUND) MESSAGE(FATAL_ERROR "AtomSpace missing: it is needed!") ENDIF (ATOMSPACE_FOUND) FIND_PACKAGE(AtomSpaceStorage CONFIG REQUIRED) IF (ATOMSPACE_STORAGE_FOUND) MESSAGE(STATUS "AtomSpace Storage found.") ADD_DEFINITIONS(-DHAVE_ATOMSPACE_STORAGE) SET(HAVE_ATOMSPACE_STORAGE 1) ELSE (ATOMSPACE_STORAGE_FOUND) MESSAGE(FATAL_ERROR "AtomSpace Storage missing: it is needed!") ENDIF (ATOMSPACE_STORAGE_FOUND) # ---------------------------------------------------------- # Needed for unit tests FIND_PACKAGE(Cxxtest) IF (NOT CXXTEST_FOUND) MESSAGE(STATUS "CxxTest missing: needed for unit tests.") ENDIF (NOT CXXTEST_FOUND) # ---------------------------------------------------------- # Link-Grammar is needed for several NLP subsystems # Only 5.6.2 or newer has the required API in it. FIND_PACKAGE(LinkGrammar 5.6.2) IF (LINK_GRAMMAR_FOUND) SET(HAVE_LINK_GRAMMAR 1) INCLUDE_DIRECTORIES(${LINK_GRAMMAR_INCLUDE_DIRS}) ELSE (LINK_GRAMMAR_FOUND) MESSAGE(STATUS "Link Grammar missing: needed for NLP.") ENDIF (LINK_GRAMMAR_FOUND) # UUID's are needed to create unique parse results FIND_PACKAGE(UUID) IF (UUID_FOUND) SET(HAVE_UUID 1) INCLUDE_DIRECTORIES(${UUID_INCLUDE_DIRS}) ADD_DEFINITIONS(${UUID_DEFINITIONS}) ELSE (UUID_FOUND) MESSAGE(FATAL_ERROR "UUID library missing: needed for NLP.\nDid you forget to install `uuid-dev`?") ENDIF (UUID_FOUND) # ---------------------------------------------------------- # This is required for Guile, Python and Cython include(OpenCogFindGuile) include(OpenCogFindPython) # =================================================================== # Include configuration. # Set default include paths. INCLUDE_DIRECTORIES(${PROJECT_SOURCE_DIR} ${COGUTIL_INCLUDE_DIR} ${ATOMSPACE_INCLUDE_DIR}) # Macros that define how atom types get declared. IF (NOT DEFINED ATOMSPACE_DATA_DIR) SET (ATOMSPACE_DATA_DIR "${COGUTIL_DATA_DIR}") ENDIF (NOT DEFINED ATOMSPACE_DATA_DIR) # Add the 'cmake' directory from atomspace to search path (should be # the same as cogutil, but we add it just in case) LIST(APPEND CMAKE_MODULE_PATH ${ATOMSPACE_DATA_DIR}/cmake) INCLUDE(OpenCogMacros) INCLUDE(OpenCogGuile) INCLUDE(OpenCogCython) # ========================================================== ``` -------------------------------- ### Run Unit Tests Source: https://github.com/opencog/lg-atomese/blob/master/README.md Command to build and run unit tests for the LG-Atomese project from the build directory. Note: The project currently states there are no unit tests. ```shell make test ``` -------------------------------- ### Configure OpenCog LG-Atomese Build with CMake Source: https://github.com/opencog/lg-atomese/blob/master/CMakeLists.txt Configures the build process for the OpenCog LG-Atomese project using CMake. It checks for dependencies like Atomspace, Guile, Link Grammar, and UUID, enabling NLP features. It also sets up unit tests using CXXTEST and handles build type specific configurations. ```cmake IF(HAVE_ATOMSPACE AND HAVE_GUILE AND HAVE_LINK_GRAMMAR AND HAVE_UUID) SET(HAVE_NLP 1) ENDIF(HAVE_ATOMSPACE AND HAVE_GUILE AND HAVE_LINK_GRAMMAR AND HAVE_UUID) ADD_SUBDIRECTORY(lib) ADD_SUBDIRECTORY(opencog) IF (CXXTEST_FOUND) ADD_CUSTOM_TARGET(tests) ADD_SUBDIRECTORY(tests EXCLUDE_FROM_ALL) IF (CMAKE_BUILD_TYPE STREQUAL "Coverage") ADD_CUSTOM_TARGET(check WORKING_DIRECTORY tests COMMAND ${CMAKE_CTEST_COMMAND} --force-new-ctest-process --output-on-failure $(ARGS) COMMENT "Running tests with coverage..." ) ELSE (CMAKE_BUILD_TYPE STREQUAL "Coverage") ADD_CUSTOM_TARGET(check DEPENDS tests WORKING_DIRECTORY tests COMMAND ${CMAKE_CTEST_COMMAND} --force-new-ctest-process --output-on-failure $(ARGS) COMMENT "Running tests..." ) ENDIF (CMAKE_BUILD_TYPE STREQUAL "Coverage") ADD_CUSTOM_TARGET(test) ADD_DEPENDENCIES(test check) ENDIF (CXXTEST_FOUND) FIND_PACKAGE(Doxygen) ``` -------------------------------- ### Configure Debian Packaging with CPack Source: https://github.com/opencog/lg-atomese/blob/master/CMakeLists.txt Configures the packaging process for Debian (`.deb` format) using CPack. It defines package metadata, dependencies, and build information, generating a Debian package for the OpenCog framework. It also sets the package name, version, and contact information. ```cmake EXECUTE_PROCESS(COMMAND dpkg --print-architecture OUTPUT_VARIABLE PACKAGE_ARCHITECTURE OUTPUT_STRIP_TRAILING_WHITESPACE) STRING(TIMESTAMP UTC_DATE "%Y%m%d" UTC) FILE(WRITE "${PROJECT_BINARY_DIR}/install_manifest.txt") SET(SEMANTIC_VERSION "0.1.4") SET(CPACK_GENERATOR "DEB") SET(CPACK_PACKAGE_CONTACT "opencog@googlegroups.com") SET(CPACK_PACKAGE_DESCRIPTION_FILE "${CMAKE_CURRENT_SOURCE_DIR}/README.md") SET(CPACK_PACKAGE_DIRECTORY "${CMAKE_BINARY_DIR}/packages") SET(CPACK_PACKAGE_DESCRIPTION_SUMMARY "The Open Cognition Framework") SET(CPACK_PACKAGE_NAME "opencog-dev") SET(CPACK_PACKAGE_VENDOR "opencog.org") SET(CPACK_PACKAGE_VERSION "${SEMANTIC_VERSION}-${UTC_DATE}") SET(CPACK_RESOURCE_FILE_LICENSE "${CMAKE_CURRENT_SOURCE_DIR}/LICENSE") SET(CPACK_PACKAGE_FILE_NAME "${CPACK_PACKAGE_NAME}_${CPACK_PACKAGE_VERSION}_${PACKAGE_ARCHITECTURE}") SET(CPACK_PACKAGING_INSTALL_PREFIX "/usr/local") SET(CPACK_PACKAGE_EXECUTABLES "cogserver" "The Open Cognition Framework") SET(DEPENDENCY_LIST "guile-2.2-dev (>= 2.2.2)" "python3-dev (>= 3.6.7)" "libstdc++6 (>= 4.7)" "libcogutil-dev (>= 2.0.2)" "atomspace-dev (>= 5.0.3)" ) STRING(REPLACE ";" ", " MAIN_DEPENDENCIES "${DEPENDENCY_LIST}") SET(CPACK_DEBIAN_PACKAGE_DEPENDS "${MAIN_DEPENDENCIES}") SET(CPACK_DEBIAN_PACKAGE_SECTION "libdevel") SET(CPACK_DEBIAN_PACKAGE_HOMEPAGE "http://opencog.org") INCLUDE(CPack) ``` -------------------------------- ### Define Project Source and Binary Directories Source: https://github.com/opencog/lg-atomese/blob/master/tests/CMakeLists.txt Adds preprocessor definitions for PROJECT_SOURCE_DIR and PROJECT_BINARY_DIR, making these paths available within the C++ source code during compilation. These are essential for referencing project-specific files and directories. ```cmake ADD_DEFINITIONS(-DPROJECT_SOURCE_DIR="${CMAKE_SOURCE_DIR}" -DPROJECT_BINARY_DIR="${CMAKE_BINARY_DIR}") ``` -------------------------------- ### CMake Include Directories Source: https://github.com/opencog/lg-atomese/blob/master/opencog/nlp/cython/opencog/CMakeLists.txt Configures the include directories for the C++ compiler. This ensures that header files from AtomSpace, Python, and the current source/binary directories are accessible during the build process. ```CMake INCLUDE_DIRECTORIES( ${ATOMSPACE_INCLUDE_DIR} ${Python3_INCLUDE_DIRS} ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_BINARY_DIR} ) ``` -------------------------------- ### LGAtomese CMake Package Configuration Source: https://github.com/opencog/lg-atomese/blob/master/lib/CMakeLists.txt This CMake script configures the LGAtomese package. It sets up export targets, generates configuration files (LGAtomeseConfig.cmake, LGAtomeseConfigVersion.cmake), and defines the semantic version. ```cmake include(CMakePackageConfigHelpers) #export(EXPORT LGAtomeseTargets # FILE "${CMAKE_CURRENT_BINARY_DIR}/LGAtomese/LGAtomeseTargets.cmake" #) set(ConfigPackageLocation lib/cmake/LGAtomese) install(EXPORT LGAtomeseTargets FILE LGAtomeseTargets.cmake DESTINATION ${ConfigPackageLocation} ) configure_package_config_file(LGAtomeseConfig.cmake.in ${CMAKE_CURRENT_BINARY_DIR}/LGAtomeseConfig.cmake INSTALL_DESTINATION ${ConfigPackageLocation} PATH_VARS CMAKE_INSTALL_PREFIX ) SET(SEMANTIC_VERSION 1.0.0) write_basic_package_version_file( "${CMAKE_CURRENT_BINARY_DIR}/LGAtomeseConfigVersion.cmake" VERSION ${SEMANTIC_VERSION} COMPATIBILITY SameMajorVersion ) INSTALL(FILES ${CMAKE_CURRENT_BINARY_DIR}/LGAtomeseConfigVersion.cmake ${CMAKE_CURRENT_BINARY_DIR}/LGAtomeseConfig.cmake DESTINATION ${ConfigPackageLocation} ) ``` -------------------------------- ### LgParseLink API Documentation Source: https://github.com/opencog/lg-atomese/blob/master/opencog/nlp/lg-parse/README.md Describes the LgParseLink function for performing a Link Grammar parse and inserting results into the AtomSpace. It details the expected input format, optional parameters for controlling the number of parses and dictionary lookup context, and the return value. ```APIDOC LgParseLink: Executes a Link Grammar parse and inserts results into the AtomSpace. Signature: LgParseLink(PhraseNode, LgDictNode, NumberNode, AtomSpace, StorageNode) Parameters: - PhraseNode: The text phrase to parse. - LgDictNode: The Link Grammar dictionary to use (e.g., "en"). - NumberNode (optional): The maximum number of parses to capture. Defaults to 4 if not provided. - AtomSpace (optional): An AtomSpace to hold dictionary information and create EvaluationLinks. - StorageNode (optional): A StorageNode to perform dictionary word lookups from. If not provided but AtomSpace is, uses AtomSpace contents only. Returns: A SentenceNode pointing to the parse results in the AtomSpace. Notes: - Compatible with the RelEx format. - When an AtomSpace is specified, EvaluationLinks are created to tie LG connector types to AtomSpace connector types. - The C++ class is `LgParseLink`, callable via `cog-execute!` in Scheme. ``` -------------------------------- ### Guile Configuration Directives Source: https://github.com/opencog/lg-atomese/blob/master/opencog/CMakeLists.txt Custom macros or commands used to manage Guile configuration targets and write Guile configuration files. These are essential for integrating Guile modules into the project build. ```guile DECLARE_GUILE_CONFIG_TARGET(SCM_CONFIG "opencog lg-config" "OPENCOG_TEST") ``` ```guile WRITE_GUILE_CONFIG(${GUILE_BIN_DIR}/opencog/lg-config.scm SCM_CONFIG TRUE) ``` ```guile WRITE_GUILE_CONFIG(${GUILE_BIN_DIR}/opencog/lg-config-installable.scm SCM_CONFIG FALSE) ``` -------------------------------- ### Add Guile Module Source: https://github.com/opencog/lg-atomese/blob/master/opencog/nlp/scm/CMakeLists.txt Configures the addition of a Guile module, specifying the source file and its destination directory within the Guile site path. ```Guile ADD_GUILE_MODULE (FILES nlp.scm MODULE_DESTINATION "${GUILE_SITE_DIR}/opencog/nlp" ) ``` -------------------------------- ### CMake Build Configuration for NLP Subdirectories Source: https://github.com/opencog/lg-atomese/blob/master/opencog/nlp/CMakeLists.txt Configures the build process by adding subdirectories and conditionally including them based on feature flags like HAVE_UUID and HAVE_CYTHON. This is a standard CMake approach to modularize build targets. ```CMake # Build C++ code in assorted NLP subdirectories ADD_SUBDIRECTORY (types) ADD_SUBDIRECTORY (lg-dict) IF (HAVE_UUID) ADD_SUBDIRECTORY (lg-parse) ENDIF (HAVE_UUID) IF (HAVE_CYTHON) ADD_SUBDIRECTORY (cython) ENDIF (HAVE_CYTHON) ADD_SUBDIRECTORY (scm) ``` -------------------------------- ### CMake: Library Dependencies and Linking Source: https://github.com/opencog/lg-atomese/blob/master/opencog/nlp/lg-dict/CMakeLists.txt Manages library dependencies and linking for the lg-atomese CMake build. It establishes a dependency on 'nlp_atom_types' for 'lg-dict-entry' and links necessary external libraries such as 'nlp-types', 'ATOMSPACE_smob_LIBRARY', and 'LINK_GRAMMAR_LIBRARY'. ```cmake ADD_DEPENDENCIES (lg-dict-entry nlp_atom_types) TARGET_LINK_LIBRARIES (lg-dict-entry nlp-types ${ATOMSPACE_smob_LIBRARY} ${LINK_GRAMMAR_LIBRARY} ) TARGET_LINK_LIBRARIES (lg-dict lg-dict-entry ${ATOMSPACE_smob_LIBRARY} ) ``` -------------------------------- ### CMake: Define lg-atomese Libraries Source: https://github.com/opencog/lg-atomese/blob/master/opencog/nlp/lg-dict/CMakeLists.txt Defines shared libraries for the lg-atomese component using CMake. It specifies the source files for the 'lg-dict-entry' and 'lg-dict' libraries, which are essential for the component's functionality. ```cmake ADD_LIBRARY (lg-dict-entry SHARED LGDictExpContainer.cc LGDictReader.cc LGDictUtils.cc LGDictNode.cc LGDictEntry.cc ) ADD_LIBRARY (lg-dict SHARED LGDictSCM.cc ) ``` -------------------------------- ### Dictionary Entry Retrieval Methods Source: https://github.com/opencog/lg-atomese/blob/master/opencog/nlp/lg-dict/README.md Details on the lg-get-dict-entry and lg-dict-entry methods, their current behavior, and identified issues. These methods are central to retrieving dictionary entries but suffer from problems with regex lookup and handling of words with non-trivial morphology. ```APIDOC lg-get-dict-entry(word: str) - Returns a SetLink (deprecated). - Issues: - Fails to perform regex lookup of the word. - Invalid/inappropriate if the word has non-trivial morphology (multiple morphemes). - Does not indicate the dictionary source of disjuncts, preventing multi-dictionary use. lg-dict-entry(word: str) - Suggested replacement for lg-get-dict-entry. - Issues: - Fails to perform regex lookup of the word. - Invalid/inappropriate if the word has non-trivial morphology (multiple morphemes). - Does not indicate the dictionary source of disjuncts, preventing multi-dictionary use. Potential Redesign for lg-get-dict-entry: - Redesign to return a LinkValue instead of a SetLink. - Implement morphology handling by splitting words into morphemes, recombining them, and returning disjuncts for the recombined splits. ``` -------------------------------- ### Set Guile Load Path Source: https://github.com/opencog/lg-atomese/blob/master/tests/CMakeLists.txt Configures the GUILE_LOAD_PATH variable, which is used by the CxxTest framework to locate Scheme files. This ensures that tests can correctly load the atomspace SCM from the build directory. ```cmake SET(GUILE_LOAD_PATH "${PROJECT_BINARY_DIR}/opencog/scm") ``` -------------------------------- ### Add Subdirectory for lg-parse Source: https://github.com/opencog/lg-atomese/blob/master/tests/CMakeLists.txt Includes the 'lg-parse' subdirectory into the build. This command tells CMake to process the CMakeLists.txt file within the 'lg-parse' directory, managing its build targets and dependencies. ```cmake ADD_SUBDIRECTORY (lg-parse) ``` -------------------------------- ### Optional Links Handling Source: https://github.com/opencog/lg-atomese/blob/master/opencog/nlp/lg-dict/README.md Description of a critical bug in the lg-atomese module related to the handling of optional links. ```APIDOC Optional Links Handling - Status: Currently broken. - Impact: Affects core design and functionality of the module. ``` -------------------------------- ### LG Dictionary Utility Functions Source: https://github.com/opencog/lg-atomese/blob/master/opencog/nlp/lg-dict/README.md A set of convenience Scheme utilities for interacting with the Link Grammar dictionary. These include wrappers for common operations and helper functions for connector comparisons. ```scheme ;; Wraps (cog-execute (LgDictEntry ...)) (lg-dict-entry (WordNode "...")) ``` ```scheme ;; Deprecated: Identical to calling (SetLink (lg-dict-entry (WordNode "..."))) ;; (lg-get-dict-entry (WordNode "...")) ``` ```scheme ;; Checks if two LgConnector links have the same type (connector name). ;; Handles subscripts & head/tail correctly. (lg-conn-type-match? (LgConnector ...) (LgConnector ...)) ``` ```scheme ;; Checks if two LgConnector links can be linked. ;; Requires different directions and matching types. (lg-conn-linkable? (LgConnector ...) (LgConnector ...)) ``` -------------------------------- ### CMake Cython Flags Configuration Source: https://github.com/opencog/lg-atomese/blob/master/opencog/nlp/cython/opencog/CMakeLists.txt Defines specific flags for the Cython compiler. These flags include Python 3 compatibility ('-3'), enabling extra warnings ('-Wextra'), and specifying include paths for Cython modules. ```CMake SET(CYTHON_FLAGS "-3" "-f" "-Wextra" "-I" "${ATOMSPACE_INCLUDE_DIR}/opencog/cython" "-I" "${ATOMSPACE_INCLUDE_DIR}/opencog/cython/opencog") ``` -------------------------------- ### Link Grammar Connector Details Source: https://github.com/opencog/lg-atomese/blob/master/opencog/nlp/lg-dict/README.md Describes the structure and properties of Link Grammar connectors as represented in the AtomSpace. Each `LgConnector` link contains the connector name, direction, and multi-connect property. ```APIDOC LgConnector: Represents a Link Grammar connector. Contains: - LgConnNode: The connector name (e.g., "Sp", "dWV"). - LgConnDirNode: The connector direction ('+' or '-'). - LgConnMultiNode: The multi-connect property (if applicable). Connector Ordering: The order of connectors within a disjunct is preserved. Connector Documentation: Refer to Link Grammar documentation, section 1.2.1 for detailed meanings and usage. Related Concepts: - Disjunctive Normal Form (DNF): Disjuncts are structured using LgOr (menu choice) and LgAnd. - Atom Types: See nlp/types/atom_types.script for Node & Link details. ``` -------------------------------- ### Create and Link NLP Types Library Source: https://github.com/opencog/lg-atomese/blob/master/opencog/nlp/types/CMakeLists.txt Defines a shared library named 'nlp-types' using C++ source files and headers. It links against the ATOMSPACE atomtypes library, ensuring necessary dependencies are met for the NLP type system. ```cmake ADD_LIBRARY (nlp-types SHARED atom_types.h NLPTypes.cc ) TARGET_LINK_LIBRARIES(nlp-types ${ATOMSPACE_atomtypes_LIBRARY} ) # Without this, parallel make will race and crap up the generated files. ADD_DEPENDENCIES(nlp-types nlp_atom_types) ``` -------------------------------- ### Add Guile Module and Extension Source: https://github.com/opencog/lg-atomese/blob/master/opencog/nlp/types/CMakeLists.txt Configures the build to generate a Guile Scheme module ('nlp_types.scm') and registers it as a Guile extension. This allows the NLP types to be used within the Guile interpreter, depending on the 'nlp_atom_types' target. ```cmake ADD_GUILE_MODULE (FILES ${CMAKE_CURRENT_BINARY_DIR}/nlp_types.scm MODULE_DESTINATION "${GUILE_SITE_DIR}/opencog/nlp/types" DEPENDS nlp_atom_types ) ADD_GUILE_EXTENSION(SCM_CONFIG nlp-types "opencog-ext-path-nlp-types") ``` -------------------------------- ### Include Build Directory for Headers Source: https://github.com/opencog/lg-atomese/blob/master/tests/CMakeLists.txt Adds the build directory to the include path for the compiler. This is necessary because header files like atom_types.h are generated in the build directory. ```cmake INCLUDE_DIRECTORIES(${CMAKE_BINARY_DIR}) ``` -------------------------------- ### Lookup Link Grammar Entry (LgDictEntry) Source: https://github.com/opencog/lg-atomese/blob/master/opencog/nlp/lg-dict/README.md This snippet demonstrates how to use `LgDictEntry` to look up a word in the Link Grammar dictionary for a specified language (e.g., English 'en'). It places the resulting disjuncts into the AtomSpace. The structure of the disjuncts, represented using `LgDisjunct`, `LgConnector`, `LgConnNode`, `LgConnDirNode`, `LgAnd`, and `LgOr`, is also illustrated. ```scheme (use-modules (opencog) (opencog nlp) (opencog nlp lg-dict)) (use-modules (opencog exec)) (cog-execute! (LgDictEntry (WordNode "...") (LgDictNode "en"))) ``` ```scheme ;; Example structure of disjuncts placed in AtomSpace: ;; (LgDisjunct ;; (WordNode "...") ;; (LgConnector ;; (LgConnNode "Sp") ;; (LgConnDirNode "-") ;; ) ;; ) ;; (LgDisjunct ;; (WordNode "...") ;; (LgAnd ;; (LgConnector ;; (LgConnNode "Sp") ;; (LgConnDirNode "-") ;; ) ;; (LgConnector ;; (LgConnNode "dWV") ;; (LgConnDirNode "-") ;; ) ;; ... ;; ) ;; ) ``` -------------------------------- ### CMake C++ Compiler Flags Source: https://github.com/opencog/lg-atomese/blob/master/opencog/nlp/cython/opencog/CMakeLists.txt Sets C++ compiler flags for the project. Specifically, it adds '-fno-strict-aliasing' which is required for compiling Cython code to avoid aliasing warnings and ensure correct emulation of Python object inheritance. ```CMake SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-strict-aliasing") ``` -------------------------------- ### Add Guile Test Source: https://github.com/opencog/lg-atomese/blob/master/tests/lg-parse/CMakeLists.txt This snippet shows how to register a Guile test case within the project. The `ADD_GUILE_TEST` macro is used to associate a test suite name with its corresponding Scheme source file. ```Guile ADD_GUILE_TEST(TestDisjuncts test-disjuncts.scm) ``` -------------------------------- ### AtomSpace Word-Disjunct Association Format Source: https://github.com/opencog/lg-atomese/blob/master/opencog/nlp/lg-dict/README.md Details on the format of word-disjunct associations in the AtomSpace and its limitations for multi-dictionary and multi-language operations. ```APIDOC AtomSpace Word-Disjunct Association Format - Issue: Does not indicate the dictionary source of the disjuncts. - Consequences: - Prevents multi-dictionary use. - Makes multi-language operation impossible. - Current Status: Low priority as Russian (the only language with non-trivial morphology handled) is not supported, and primary users (SuReal, MicroPlanning) are unaware of morphology. ``` -------------------------------- ### Configure OpenCog LG Atomese Build Source: https://github.com/opencog/lg-atomese/blob/master/opencog/nlp/types/CMakeLists.txt Sets CMake directory properties and defines custom atom types for the project. It specifies which file types are considered custom and adds them to the atom type definitions, including C++ headers, definitions, and Guile Scheme files. ```cmake #SET_DIRECTORY_PROPERTIES(PROPERTIES CLEAN_NO_CUSTOM true) OPENCOG_ADD_ATOM_TYPES( atom_types.script atom_types.h atom_types.definitions atom_types.inheritance nlp_types.scm nlp_types.pyx ) ADD_CUSTOM_TARGET(nlp_atom_types DEPENDS atom_types.h) # The atom_types.h file is written to the build directory INCLUDE_DIRECTORIES(${CMAKE_BINARY_DIR}) ``` -------------------------------- ### LgParseSections API Documentation Source: https://github.com/opencog/lg-atomese/blob/master/opencog/nlp/lg-parse/README.md Describes LgParseSections, which is similar to LgParseDisjuncts but creates Sections instead of disjuncts for the parse results. ```APIDOC LgParseSections: Returns LinkValues for different parses, creating Sections instead of disjuncts. Functionality: Similar to `LgParseDisjuncts`, but the output structure uses Sections instead of disjuncts. ``` -------------------------------- ### LgParseDisjuncts API Documentation Source: https://github.com/opencog/lg-atomese/blob/master/opencog/nlp/lg-parse/README.md Explains LgParseDisjuncts, which returns LinkValues representing parses and their disjuncts, offering an easier-to-use alternative to the RelEx format and avoiding WordInstance atom creation. ```APIDOC LgParseDisjuncts: Returns LinkValues for different parses and their sequential disjuncts. Functionality: Provides parses as LinkValues, where each parse is a LinkValue of disjuncts. This format is easier to use than RelEx and avoids creating `WordInstance` atoms. Output: A LinkValue holding the different parses; each parse is a LinkValue for the disjuncts in sequence. ``` -------------------------------- ### Check Dictionary Entry Existence (LgHaveDictEntry) Source: https://github.com/opencog/lg-atomese/blob/master/opencog/nlp/lg-dict/README.md This function provides a fast way to check if a Link Grammar dictionary entry exists for a given word and language without loading the full entry. It evaluates to true or false, making it efficient for existence checks. ```scheme (cog-evaluate! (LgHaveDictEntry (WordNode "blorgel-bargel") (LgDictNode "en"))) ``` -------------------------------- ### LgParseMinimal API Documentation Source: https://github.com/opencog/lg-atomese/blob/master/opencog/nlp/lg-parse/README.md Details the LgParseMinimal function, which performs a Link Grammar parse similar to LgParseLink but avoids inserting verbose disjuncts into the AtomSpace, thus reducing atom count. ```APIDOC LgParseMinimal: Performs a Link Grammar parse without inserting disjuncts into the AtomSpace. Functionality: Identical parse to `LgParseLink` but significantly reduces the number of atoms created by omitting disjuncts. Compatibility: Backwards-compatible with the RelEx format. ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.