From 9db5c6fcf9dbfac178e52914b984da032d3c286b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Linas=20Vep=C5=A1tas?= Date: Wed, 27 Mar 2024 11:54:29 -0500 Subject: [PATCH 1/4] Move Parse_Options to it's own file. --- link-grammar/Makefile.am | 1 + link-grammar/api.c | 375 +------------------------------------ link-grammar/options.c | 393 +++++++++++++++++++++++++++++++++++++++ 3 files changed, 397 insertions(+), 372 deletions(-) create mode 100644 link-grammar/options.c diff --git a/link-grammar/Makefile.am b/link-grammar/Makefile.am index c120922e0..8f2ccae5b 100644 --- a/link-grammar/Makefile.am +++ b/link-grammar/Makefile.am @@ -122,6 +122,7 @@ liblink_grammar_la_SOURCES = \ linkage/sane.c \ linkage/score.c \ memory-pool.c \ + options.c \ parse/count.c \ parse/extract-links.c \ parse/fast-match.c \ diff --git a/link-grammar/api.c b/link-grammar/api.c index a55fed9ed..5bea4b0a7 100644 --- a/link-grammar/api.c +++ b/link-grammar/api.c @@ -33,384 +33,15 @@ #include "tokenize/word-structures.h" // Word_struct #include "utilities.h" -/* Its OK if this is racey across threads. Any mild shuffling is enough. */ -static unsigned int global_rand_state = 0; - -int verbosity = D_USER_BASIC; -/* debug and test should not be NULL since they can be used before they - * are assigned a value by parse_options_get_...() */ -char * debug = (char *)""; -char * test = (char *)""; - -/*************************************************************** -* -* Routines for setting Parse_Options -* -****************************************************************/ - -/** - * Create and initialize a Parse_Options object - */ -Parse_Options parse_options_create(void) -{ - Parse_Options po; - - init_memusage(); - po = (Parse_Options) malloc(sizeof(struct Parse_Options_s)); - - /* Here's where the values are initialized */ - - /* The parse_options_set_(verbosity|debug|test) functions also - * set the corresponding global variables. Set them here, also. - * Note that this is usally called *after* dictionary creation! */ - verbosity = po->verbosity = D_USER_BASIC; - debug = po->debug = (char *)""; - test = po->test = (char *)""; - - /* Set dijunct_cost to a bogus value of -10000. The dict-common - * code will set this to a more reasonable default. */ - po->disjunct_cost = UNINITIALIZED_MAX_DISJUNCT_COST; - po->min_null_count = 0; - po->max_null_count = 0; - po->islands_ok = false; -#if USE_SAT_SOLVER - po->use_sat_solver = false; -#endif - po->linkage_limit = 100; - - // Disable spell-guessing by default. Aspell 0.60.8 and possibly - // others leak memory. - po->use_spell_guess = 0; - - po->cost_model.compare_fn = &VDAL_compare_linkages; - po->cost_model.type = VDAL; - po->short_length = 16; - po->all_short = false; - po->perform_pp_prune = true; - po->twopass_length = 30; - po->repeatable_rand = true; - po->resources = resources_create(); - po->display_morphology = true; - po->dialect = (dialect_info){ .conf = strdup("") }; - - return po; -} - -static void free_dialect_info(dialect_info *); -int parse_options_delete(Parse_Options opts) -{ - resources_delete(opts->resources); - free_dialect_info(&opts->dialect); - free(opts); - return 0; -} - -void parse_options_set_cost_model_type(Parse_Options opts, Cost_Model_type cm) -{ - switch(cm) { - case VDAL: - opts->cost_model.type = VDAL; - opts->cost_model.compare_fn = &VDAL_compare_linkages; - break; - default: - prt_error("Error: Illegal cost model: %d\n", (int)cm); - } -} - -Cost_Model_type parse_options_get_cost_model_type(Parse_Options opts) -{ - return opts->cost_model.type; -} - -void parse_options_set_perform_pp_prune(Parse_Options opts, bool dummy) -{ - opts->perform_pp_prune = dummy; -} - -bool parse_options_get_perform_pp_prune(Parse_Options opts) { - return opts->perform_pp_prune; -} - -void parse_options_set_verbosity(Parse_Options opts, int dummy) -{ - opts->verbosity = dummy; - verbosity = opts->verbosity; - /* this is one of the only global variables. */ -} - -int parse_options_get_verbosity(Parse_Options opts) { - return opts->verbosity; -} - -void parse_options_set_debug(Parse_Options opts, const char * dummy) -{ - /* The comma-separated list of functions is limited to this size. - * Can be easily dynamically allocated. In any case it is not reentrant - * because the "debug" variable is static. */ - static char buff[256]; - size_t len = strlen(dummy); - - if (0 == strcmp(dummy, opts->debug)) return; - - if (0 == len) - { - buff[0] = '\0'; - } - else - { - buff[0] = ','; - strncpy(buff+1, dummy, sizeof(buff)-2); - if (len < sizeof(buff)-2) - { - buff[len+1] = ','; - buff[len+2] = '\0'; - } - else - { - buff[sizeof(buff)-1] = '\0'; - } - } - opts->debug = buff; - debug = opts->debug; - /* this is one of the only global variables. */ -} - -char * parse_options_get_debug(Parse_Options opts) { - static char buff[256]; /* see parse_options_set_debug() */ - char *buffp = buff; - - /* Remove the added commas. */ - strcpy(buff, opts->debug); - if (buffp[0] == ',') - buffp++; - if ((buffp[0] != '\0') && buffp[strlen(buffp)-1] == ',') - buffp[strlen(buffp)-1] = '\0'; - - return buffp; -} - -void parse_options_set_test(Parse_Options opts, const char * dummy) -{ - /* The comma-separated test features is limited to this size. - * Can be easily dynamically allocated. In any case it is not reentrant - * because the "test" variable is static. */ - static char buff[256]; - size_t len = strlen(dummy); - - if (0 == strcmp(dummy, opts->test)) return; - - if (0 == len) - { - buff[0] = '\0'; - } - else - { - buff[0] = ','; - strncpy(buff+1, dummy, sizeof(buff)-2); - if (len < sizeof(buff)-2) - { - buff[len+1] = ','; - buff[len+2] = '\0'; - } - else - { - buff[sizeof(buff)-1] = '\0'; - } - } - opts->test = buff; - test = opts->test; - /* this is one of the only global variables. */ -} - -char * parse_options_get_test(Parse_Options opts) { - static char buff[256]; /* see parse_options_set_test() */ - char *buffp = buff; - - /* Remove the added commas. */ - strcpy(buff, opts->test); - if (buffp[0] == ',') - buffp++; - if ((buffp[0] != '\0') && buffp[strlen(buffp)-1] == ',') - buffp[strlen(buffp)-1] = '\0'; - - return buffp; -} - -void parse_options_set_use_sat_parser(Parse_Options opts, bool dummy) { -#ifdef USE_SAT_SOLVER - opts->use_sat_solver = dummy; -#else - if (dummy && (verbosity > D_USER_BASIC)) - { - prt_error("Error: Cannot enable the Boolean SAT parser; " - "this library was built without SAT solver support.\n"); - } -#endif -} - -bool parse_options_get_use_sat_parser(Parse_Options opts) { -#if USE_SAT_SOLVER - return opts->use_sat_solver; -#else - return false; -#endif -} - -void parse_options_set_linkage_limit(Parse_Options opts, int dummy) -{ - opts->linkage_limit = dummy; -} -int parse_options_get_linkage_limit(Parse_Options opts) -{ - return opts->linkage_limit; -} - -void parse_options_set_disjunct_cost(Parse_Options opts, float dummy) -{ - opts->disjunct_cost = dummy; -} -float parse_options_get_disjunct_cost(Parse_Options opts) -{ - return opts->disjunct_cost; -} - -void parse_options_set_min_null_count(Parse_Options opts, int val) { - opts->min_null_count = val; -} -int parse_options_get_min_null_count(Parse_Options opts) { - return opts->min_null_count; -} - -void parse_options_set_max_null_count(Parse_Options opts, int val) { - opts->max_null_count = val; -} -int parse_options_get_max_null_count(Parse_Options opts) { - return opts->max_null_count; -} - -void parse_options_set_islands_ok(Parse_Options opts, bool dummy) { - opts->islands_ok = dummy; -} - -bool parse_options_get_islands_ok(Parse_Options opts) { - return opts->islands_ok; -} - -void parse_options_set_spell_guess(Parse_Options opts, int dummy) { -#if defined HAVE_HUNSPELL || defined HAVE_ASPELL - opts->use_spell_guess = dummy; -#else - if (dummy && (verbosity > D_USER_BASIC)) - { - prt_error("Error: Cannot enable spell guess; " - "this library was built without spell guess support.\n"); - } - -#endif /* defined HAVE_HUNSPELL || defined HAVE_ASPELL */ -} - -int parse_options_get_spell_guess(Parse_Options opts) { - return opts->use_spell_guess; -} - -void parse_options_set_short_length(Parse_Options opts, int short_length) { - opts->short_length = MIN(short_length, UNLIMITED_LEN); -} - -int parse_options_get_short_length(Parse_Options opts) { - return opts->short_length; -} - -void parse_options_set_all_short_connectors(Parse_Options opts, bool val) { - opts->all_short = val; -} - -bool parse_options_get_all_short_connectors(Parse_Options opts) { - return opts->all_short; -} - -/** True means "make it repeatable.". False means "make it random". */ -void parse_options_set_repeatable_rand(Parse_Options opts, bool val) -{ - opts->repeatable_rand = val; - - /* Zero is used to indicate repeatability. */ - if (val) global_rand_state = 0; - else if (0 == global_rand_state) global_rand_state = 42; -} - -bool parse_options_get_repeatable_rand(Parse_Options opts) { - return opts->repeatable_rand; -} - -void parse_options_set_max_parse_time(Parse_Options opts, int dummy) { - opts->resources->max_parse_time = dummy; -} - -int parse_options_get_max_parse_time(Parse_Options opts) { - return opts->resources->max_parse_time; -} - -void parse_options_set_max_memory(Parse_Options opts, int dummy) { - opts->resources->max_memory = dummy; -} - -int parse_options_get_max_memory(Parse_Options opts) { - return opts->resources->max_memory; -} - -int parse_options_get_display_morphology(Parse_Options opts) { - return opts->display_morphology; -} - -void parse_options_set_display_morphology(Parse_Options opts, int dummy) { - opts->display_morphology = dummy; -} - -bool parse_options_timer_expired(Parse_Options opts) { - return resources_timer_expired(opts->resources); -} - -bool parse_options_memory_exhausted(Parse_Options opts) { - return resources_memory_exhausted(opts->resources); -} - -bool parse_options_resources_exhausted(Parse_Options opts) { - return (resources_exhausted(opts->resources)); -} - -void parse_options_reset_resources(Parse_Options opts) { - resources_reset(opts->resources); -} - -/* Dialect. */ - -static void free_dialect_info(dialect_info *dinfo) -{ - if (dinfo == NULL) return; - - free(dinfo->cost_table); - dinfo->cost_table = NULL; - free((void *)dinfo->conf); -} - -char * parse_options_get_dialect(Parse_Options opts) -{ - return opts->dialect.conf; -} - -void parse_options_set_dialect(Parse_Options opts, const char *dconf) -{ - if (0 == strcmp(dconf, opts->dialect.conf)) return; - free_dialect_info(&opts->dialect); - opts->dialect.conf = strdup(dconf); -} /*************************************************************** * * Routines for creating destroying and processing Sentences * ****************************************************************/ +/* From options.c */ +extern unsigned int global_rand_state; + Sentence sentence_create(const char *input_string, Dictionary dict) { Sentence sent; diff --git a/link-grammar/options.c b/link-grammar/options.c new file mode 100644 index 000000000..9df86968e --- /dev/null +++ b/link-grammar/options.c @@ -0,0 +1,393 @@ +/*************************************************************************/ +/* Copyright (c) 2004 */ +/* Daniel Sleator, David Temperley, and John Lafferty */ +/* Copyright 2008, 2009, 2013, 2014 Linas Vepstas */ +/* All rights reserved */ +/* */ +/* Use of the link grammar parsing system is subject to the terms of the */ +/* license set forth in the LICENSE file included with this software. */ +/* This license allows free redistribution and use in source and binary */ +/* forms, with or without modification, subject to certain conditions. */ +/* */ +/*************************************************************************/ + +#include + +#include "api-structures.h" +#include "connectors.h" +#include "dict-common/dict-common.h" +#include "parse/parse.h" +#include "resources.h" + +/* Its OK if this is racey across threads. Any mild shuffling is enough. */ +unsigned int global_rand_state = 0; + +int verbosity = D_USER_BASIC; +/* debug and test should not be NULL since they can be used before they + * are assigned a value by parse_options_get_...() */ +char * debug = (char *)""; +char * test = (char *)""; + +/*************************************************************** +* +* Routines for setting Parse_Options +* +****************************************************************/ + +/** + * Create and initialize a Parse_Options object + */ +Parse_Options parse_options_create(void) +{ + Parse_Options po; + + init_memusage(); + po = (Parse_Options) malloc(sizeof(struct Parse_Options_s)); + + /* Here's where the values are initialized */ + + /* The parse_options_set_(verbosity|debug|test) functions also + * set the corresponding global variables. Set them here, also. + * Note that this is usally called *after* dictionary creation! */ + verbosity = po->verbosity = D_USER_BASIC; + debug = po->debug = (char *)""; + test = po->test = (char *)""; + + /* Set dijunct_cost to a bogus value of -10000. The dict-common + * code will set this to a more reasonable default. */ + po->disjunct_cost = UNINITIALIZED_MAX_DISJUNCT_COST; + po->min_null_count = 0; + po->max_null_count = 0; + po->islands_ok = false; +#if USE_SAT_SOLVER + po->use_sat_solver = false; +#endif + po->linkage_limit = 100; + + // Disable spell-guessing by default. Aspell 0.60.8 and possibly + // others leak memory. + po->use_spell_guess = 0; + + po->cost_model.compare_fn = &VDAL_compare_linkages; + po->cost_model.type = VDAL; + po->short_length = 16; + po->all_short = false; + po->perform_pp_prune = true; + po->twopass_length = 30; + po->repeatable_rand = true; + po->resources = resources_create(); + po->display_morphology = true; + po->dialect = (dialect_info){ .conf = strdup("") }; + + return po; +} + +static void free_dialect_info(dialect_info *); +int parse_options_delete(Parse_Options opts) +{ + resources_delete(opts->resources); + free_dialect_info(&opts->dialect); + free(opts); + return 0; +} + +void parse_options_set_cost_model_type(Parse_Options opts, Cost_Model_type cm) +{ + switch(cm) { + case VDAL: + opts->cost_model.type = VDAL; + opts->cost_model.compare_fn = &VDAL_compare_linkages; + break; + default: + prt_error("Error: Illegal cost model: %d\n", (int)cm); + } +} + +Cost_Model_type parse_options_get_cost_model_type(Parse_Options opts) +{ + return opts->cost_model.type; +} + +void parse_options_set_perform_pp_prune(Parse_Options opts, bool dummy) +{ + opts->perform_pp_prune = dummy; +} + +bool parse_options_get_perform_pp_prune(Parse_Options opts) { + return opts->perform_pp_prune; +} + +void parse_options_set_verbosity(Parse_Options opts, int dummy) +{ + opts->verbosity = dummy; + verbosity = opts->verbosity; + /* this is one of the only global variables. */ +} + +int parse_options_get_verbosity(Parse_Options opts) { + return opts->verbosity; +} + +void parse_options_set_debug(Parse_Options opts, const char * dummy) +{ + /* The comma-separated list of functions is limited to this size. + * Can be easily dynamically allocated. In any case it is not reentrant + * because the "debug" variable is static. */ + static char buff[256]; + size_t len = strlen(dummy); + + if (0 == strcmp(dummy, opts->debug)) return; + + if (0 == len) + { + buff[0] = '\0'; + } + else + { + buff[0] = ','; + strncpy(buff+1, dummy, sizeof(buff)-2); + if (len < sizeof(buff)-2) + { + buff[len+1] = ','; + buff[len+2] = '\0'; + } + else + { + buff[sizeof(buff)-1] = '\0'; + } + } + opts->debug = buff; + debug = opts->debug; + /* this is one of the only global variables. */ +} + +char * parse_options_get_debug(Parse_Options opts) { + static char buff[256]; /* see parse_options_set_debug() */ + char *buffp = buff; + + /* Remove the added commas. */ + strcpy(buff, opts->debug); + if (buffp[0] == ',') + buffp++; + if ((buffp[0] != '\0') && buffp[strlen(buffp)-1] == ',') + buffp[strlen(buffp)-1] = '\0'; + + return buffp; +} + +void parse_options_set_test(Parse_Options opts, const char * dummy) +{ + /* The comma-separated test features is limited to this size. + * Can be easily dynamically allocated. In any case it is not reentrant + * because the "test" variable is static. */ + static char buff[256]; + size_t len = strlen(dummy); + + if (0 == strcmp(dummy, opts->test)) return; + + if (0 == len) + { + buff[0] = '\0'; + } + else + { + buff[0] = ','; + strncpy(buff+1, dummy, sizeof(buff)-2); + if (len < sizeof(buff)-2) + { + buff[len+1] = ','; + buff[len+2] = '\0'; + } + else + { + buff[sizeof(buff)-1] = '\0'; + } + } + opts->test = buff; + test = opts->test; + /* this is one of the only global variables. */ +} + +char * parse_options_get_test(Parse_Options opts) { + static char buff[256]; /* see parse_options_set_test() */ + char *buffp = buff; + + /* Remove the added commas. */ + strcpy(buff, opts->test); + if (buffp[0] == ',') + buffp++; + if ((buffp[0] != '\0') && buffp[strlen(buffp)-1] == ',') + buffp[strlen(buffp)-1] = '\0'; + + return buffp; +} + +void parse_options_set_use_sat_parser(Parse_Options opts, bool dummy) { +#ifdef USE_SAT_SOLVER + opts->use_sat_solver = dummy; +#else + if (dummy && (verbosity > D_USER_BASIC)) + { + prt_error("Error: Cannot enable the Boolean SAT parser; " + "this library was built without SAT solver support.\n"); + } +#endif +} + +bool parse_options_get_use_sat_parser(Parse_Options opts) { +#if USE_SAT_SOLVER + return opts->use_sat_solver; +#else + return false; +#endif +} + +void parse_options_set_linkage_limit(Parse_Options opts, int dummy) +{ + opts->linkage_limit = dummy; +} +int parse_options_get_linkage_limit(Parse_Options opts) +{ + return opts->linkage_limit; +} + +void parse_options_set_disjunct_cost(Parse_Options opts, float dummy) +{ + opts->disjunct_cost = dummy; +} +float parse_options_get_disjunct_cost(Parse_Options opts) +{ + return opts->disjunct_cost; +} + +void parse_options_set_min_null_count(Parse_Options opts, int val) { + opts->min_null_count = val; +} +int parse_options_get_min_null_count(Parse_Options opts) { + return opts->min_null_count; +} + +void parse_options_set_max_null_count(Parse_Options opts, int val) { + opts->max_null_count = val; +} +int parse_options_get_max_null_count(Parse_Options opts) { + return opts->max_null_count; +} + +void parse_options_set_islands_ok(Parse_Options opts, bool dummy) { + opts->islands_ok = dummy; +} + +bool parse_options_get_islands_ok(Parse_Options opts) { + return opts->islands_ok; +} + +void parse_options_set_spell_guess(Parse_Options opts, int dummy) { +#if defined HAVE_HUNSPELL || defined HAVE_ASPELL + opts->use_spell_guess = dummy; +#else + if (dummy && (verbosity > D_USER_BASIC)) + { + prt_error("Error: Cannot enable spell guess; " + "this library was built without spell guess support.\n"); + } + +#endif /* defined HAVE_HUNSPELL || defined HAVE_ASPELL */ +} + +int parse_options_get_spell_guess(Parse_Options opts) { + return opts->use_spell_guess; +} + +void parse_options_set_short_length(Parse_Options opts, int short_length) { + opts->short_length = MIN(short_length, UNLIMITED_LEN); +} + +int parse_options_get_short_length(Parse_Options opts) { + return opts->short_length; +} + +void parse_options_set_all_short_connectors(Parse_Options opts, bool val) { + opts->all_short = val; +} + +bool parse_options_get_all_short_connectors(Parse_Options opts) { + return opts->all_short; +} + +/** True means "make it repeatable.". False means "make it random". */ +void parse_options_set_repeatable_rand(Parse_Options opts, bool val) +{ + opts->repeatable_rand = val; + + /* Zero is used to indicate repeatability. */ + if (val) global_rand_state = 0; + else if (0 == global_rand_state) global_rand_state = 42; +} + +bool parse_options_get_repeatable_rand(Parse_Options opts) { + return opts->repeatable_rand; +} + +void parse_options_set_max_parse_time(Parse_Options opts, int dummy) { + opts->resources->max_parse_time = dummy; +} + +int parse_options_get_max_parse_time(Parse_Options opts) { + return opts->resources->max_parse_time; +} + +void parse_options_set_max_memory(Parse_Options opts, int dummy) { + opts->resources->max_memory = dummy; +} + +int parse_options_get_max_memory(Parse_Options opts) { + return opts->resources->max_memory; +} + +int parse_options_get_display_morphology(Parse_Options opts) { + return opts->display_morphology; +} + +void parse_options_set_display_morphology(Parse_Options opts, int dummy) { + opts->display_morphology = dummy; +} + +bool parse_options_timer_expired(Parse_Options opts) { + return resources_timer_expired(opts->resources); +} + +bool parse_options_memory_exhausted(Parse_Options opts) { + return resources_memory_exhausted(opts->resources); +} + +bool parse_options_resources_exhausted(Parse_Options opts) { + return (resources_exhausted(opts->resources)); +} + +void parse_options_reset_resources(Parse_Options opts) { + resources_reset(opts->resources); +} + +/* Dialect. */ + +static void free_dialect_info(dialect_info *dinfo) +{ + if (dinfo == NULL) return; + + free(dinfo->cost_table); + dinfo->cost_table = NULL; + free((void *)dinfo->conf); +} + +char * parse_options_get_dialect(Parse_Options opts) +{ + return opts->dialect.conf; +} + +void parse_options_set_dialect(Parse_Options opts, const char *dconf) +{ + if (0 == strcmp(dconf, opts->dialect.conf)) return; + free_dialect_info(&opts->dialect); + opts->dialect.conf = strdup(dconf); +} From 1563f01da73713d395393c30f5c888cb017997c9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Linas=20Vep=C5=A1tas?= Date: Wed, 27 Mar 2024 12:03:45 -0500 Subject: [PATCH 2/4] Split out config into it's own file --- link-grammar/Makefile.am | 1 + link-grammar/api.c | 124 ----------------------------------- link-grammar/config.c | 136 +++++++++++++++++++++++++++++++++++++++ 3 files changed, 137 insertions(+), 124 deletions(-) create mode 100644 link-grammar/config.c diff --git a/link-grammar/Makefile.am b/link-grammar/Makefile.am index 8f2ccae5b..895394990 100644 --- a/link-grammar/Makefile.am +++ b/link-grammar/Makefile.am @@ -88,6 +88,7 @@ endif liblink_grammar_la_SOURCES = \ api.c \ + config.c \ connectors.c \ dict-common/dialect.c \ dict-common/dict-affix-impl.c \ diff --git a/link-grammar/api.c b/link-grammar/api.c index 5bea4b0a7..49a7d4afe 100644 --- a/link-grammar/api.c +++ b/link-grammar/api.c @@ -319,127 +319,3 @@ int sentence_parse(Sentence sent, Parse_Options opts) } return sent->num_valid_linkages; } - -/* - * Definitions for linkgrammar_get_configuration(). - */ - -#define MACVAL(macro) #macro lg_str(=macro) " " - -#ifdef __STDC_VERSION__ -#define LG_S1 MACVAL(__STDC_VERSION__) -#else -#define LG_S1 -#endif - -#ifdef _POSIX_C_SOURCE -#define LG_S2 MACVAL(_POSIX_C_SOURCE) -#else -#define LG_S2 -#endif - -#if !defined _POSIX_C_SOURCE || _POSIX_C_SOURCE == 0 - #ifdef _POSIX_SOURCE - #define LG_S3 MACVAL(_POSIX_SOURCE) - #else - #define LG_S3 - #endif -#else -#define LG_S3 -#endif - -/* -DCC=$(CC) is added in the Makefile. */ -#ifdef CC -#define LG_CC CC -#elif _MSC_VER -#define LG_CC "lc" -#else -#define LG_CC "(unknown)" -#endif - -#ifdef __VERSION__ -#define LG_V1 MACVAL(__VERSION__) -#else -#define LG_V1 -#endif - -#ifdef _MSC_FULL_VER -#define LG_V2 MACVAL(_MSC_FULL_VER) -#else -#define LG_V2 -#endif - -#define LG_COMP LG_CC " " LG_V1 " " LG_V2 -#define LG_STD LG_S1 LG_S2 LG_S3 - -#ifdef __unix__ -#define LG_unix "__unix__ " -#else -#define LG_unix -#endif - -#ifdef _WIN32 -#define LG_WIN32 "_WIN32 " -#else -#define LG_WIN32 -#endif - -#ifdef _WIN64 -#define LG_WIN64 "_WIN64 " -#else -#define LG_WIN64 -#endif - -#ifdef __CYGWIN__ -#define LG_CYGWIN "__CYGWIN__ " -#else -#define LG_CYGWIN -#endif - -#ifdef __MINGW32__ -#define LG_MINGW32 "__MINGW32__ " -#else -#define LG_MINGW32 -#endif - -#ifdef __MINGW64__ -#define LG_MINGW64 "__MINGW64__ " -#else -#define LG_MINGW64 -#endif - -#ifdef __APPLE__ -#define LG_APPLE "__APPLE__ " -#else -#define LG_APPLE -#endif - -#ifdef __MACH__ -#define LG_MACH "__MACH__ " -#else -#define LG_MACH -#endif - -#ifndef DICTIONARY_DIR -#define DICTIONARY_DIR "None" -#endif - -#define LG_windows LG_WIN32 LG_WIN64 LG_CYGWIN LG_MINGW32 LG_MINGW64 -#define LG_mac LG_APPLE LG_MACH - -/** - * Return information about the configuration as a static string. - */ -const char *linkgrammar_get_configuration(void) -{ - return "Compiled with: " LG_COMP "\n" - "OS: " LG_HOST_OS " " LG_unix LG_windows LG_mac "\n" - "Standards: " LG_STD "\n" - "Configuration (source code):\n\t" - LG_CPPFLAGS "\n\t" - LG_CFLAGS "\n" - "Configuration (features):\n\t" - "DICTIONARY_DIR=" DICTIONARY_DIR "\n\t" - LG_DEFS - ; -} diff --git a/link-grammar/config.c b/link-grammar/config.c new file mode 100644 index 000000000..a1f1026ec --- /dev/null +++ b/link-grammar/config.c @@ -0,0 +1,136 @@ +/*************************************************************************/ +/* Copyright (c) 2021 Amir Plivatsky */ +/* All rights reserved */ +/* */ +/* Use of the link grammar parsing system is subject to the terms of the */ +/* license set forth in the LICENSE file included with this software. */ +/* This license allows free redistribution and use in source and binary */ +/* forms, with or without modification, subject to certain conditions. */ +/* */ +/*************************************************************************/ + +#include "api-structures.h" + +/* + * Definitions for linkgrammar_get_configuration(). + */ + +#define MACVAL(macro) #macro lg_str(=macro) " " + +#ifdef __STDC_VERSION__ +#define LG_S1 MACVAL(__STDC_VERSION__) +#else +#define LG_S1 +#endif + +#ifdef _POSIX_C_SOURCE +#define LG_S2 MACVAL(_POSIX_C_SOURCE) +#else +#define LG_S2 +#endif + +#if !defined _POSIX_C_SOURCE || _POSIX_C_SOURCE == 0 + #ifdef _POSIX_SOURCE + #define LG_S3 MACVAL(_POSIX_SOURCE) + #else + #define LG_S3 + #endif +#else +#define LG_S3 +#endif + +/* -DCC=$(CC) is added in the Makefile. */ +#ifdef CC +#define LG_CC CC +#elif _MSC_VER +#define LG_CC "lc" +#else +#define LG_CC "(unknown)" +#endif + +#ifdef __VERSION__ +#define LG_V1 MACVAL(__VERSION__) +#else +#define LG_V1 +#endif + +#ifdef _MSC_FULL_VER +#define LG_V2 MACVAL(_MSC_FULL_VER) +#else +#define LG_V2 +#endif + +#define LG_COMP LG_CC " " LG_V1 " " LG_V2 +#define LG_STD LG_S1 LG_S2 LG_S3 + +#ifdef __unix__ +#define LG_unix "__unix__ " +#else +#define LG_unix +#endif + +#ifdef _WIN32 +#define LG_WIN32 "_WIN32 " +#else +#define LG_WIN32 +#endif + +#ifdef _WIN64 +#define LG_WIN64 "_WIN64 " +#else +#define LG_WIN64 +#endif + +#ifdef __CYGWIN__ +#define LG_CYGWIN "__CYGWIN__ " +#else +#define LG_CYGWIN +#endif + +#ifdef __MINGW32__ +#define LG_MINGW32 "__MINGW32__ " +#else +#define LG_MINGW32 +#endif + +#ifdef __MINGW64__ +#define LG_MINGW64 "__MINGW64__ " +#else +#define LG_MINGW64 +#endif + +#ifdef __APPLE__ +#define LG_APPLE "__APPLE__ " +#else +#define LG_APPLE +#endif + +#ifdef __MACH__ +#define LG_MACH "__MACH__ " +#else +#define LG_MACH +#endif + +#ifndef DICTIONARY_DIR +#define DICTIONARY_DIR "None" +#endif + +#define LG_windows LG_WIN32 LG_WIN64 LG_CYGWIN LG_MINGW32 LG_MINGW64 +#define LG_mac LG_APPLE LG_MACH + +/** + * Return information about the configuration as a static string. + */ +const char *linkgrammar_get_configuration(void) +{ + return "Compiled with: " LG_COMP "\n" + "OS: " LG_HOST_OS " " LG_unix LG_windows LG_mac "\n" + "Standards: " LG_STD "\n" + "Configuration (source code):\n\t" + LG_CPPFLAGS "\n\t" + LG_CFLAGS "\n" + "Configuration (features):\n\t" + "DICTIONARY_DIR=" DICTIONARY_DIR "\n\t" + LG_DEFS + ; +} From a2a04c61dfc3d80566f01991f5b50ad41acaeafd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Linas=20Vep=C5=A1tas?= Date: Wed, 27 Mar 2024 12:16:13 -0500 Subject: [PATCH 3/4] Remove includes that seem not to be needed --- link-grammar/api.c | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/link-grammar/api.c b/link-grammar/api.c index 49a7d4afe..a93b3dcf8 100644 --- a/link-grammar/api.c +++ b/link-grammar/api.c @@ -11,27 +11,21 @@ /* */ /*************************************************************************/ -#include - #include "api-structures.h" -#include "dict-common/dict-defines.h" -#include "dict-common/dialect.h" +#include "dict-common/dict-common.h" #include "dict-common/dict-utils.h" #include "disjunct-utils.h" // free_sentence_disjuncts #include "linkage/linkage.h" -#include "memory-pool.h" #include "parse/histogram.h" // PARSE_NUM_OVERFLOW #include "parse/parse.h" #include "post-process/post-process.h" // post_process_new #include "prepare/exprune.h" -#include "string-set.h" -#include "tokenize/wordgraph.h" // wordgraph_delete #include "resources.h" #include "sat-solver/sat-encoder.h" #include "tokenize/lookup-exprs.h" #include "tokenize/tokenize.h" +#include "tokenize/wordgraph.h" // wordgraph_delete #include "tokenize/word-structures.h" // Word_struct -#include "utilities.h" /*************************************************************** * From 799978a141b1f3579117c7dfbd88f68bae3c1821 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Linas=20Vep=C5=A1tas?= Date: Wed, 27 Mar 2024 12:21:59 -0500 Subject: [PATCH 4/4] Rename api.c to sentence.c --- link-grammar/Makefile.am | 2 +- link-grammar/{api.c => sentence.c} | 0 2 files changed, 1 insertion(+), 1 deletion(-) rename link-grammar/{api.c => sentence.c} (100%) diff --git a/link-grammar/Makefile.am b/link-grammar/Makefile.am index 895394990..14609b698 100644 --- a/link-grammar/Makefile.am +++ b/link-grammar/Makefile.am @@ -87,7 +87,6 @@ dict-common/regex-morph.lo: CFLAGS = endif liblink_grammar_la_SOURCES = \ - api.c \ config.c \ connectors.c \ dict-common/dialect.c \ @@ -142,6 +141,7 @@ liblink_grammar_la_SOURCES = \ print/print-util.c \ print/wcwidth.c \ resources.c \ + sentence.c \ string-set.c \ string-id.c \ tokenize/anysplit.c \ diff --git a/link-grammar/api.c b/link-grammar/sentence.c similarity index 100% rename from link-grammar/api.c rename to link-grammar/sentence.c