@@ -1054,47 +1054,108 @@ address_parser_response_t *parse_address(char *address, address_parser_options_t
10541054 return parsed ;
10551055}
10561056
1057- bool libpostal_setup (void ) {
1058- if (!transliteration_module_setup (NULL )) {
1059- log_error ("Error loading transliteration module, LIBPOSTAL_DATA_DIR=%s\n" , LIBPOSTAL_DATA_DIR );
1057+ bool libpostal_setup_datadir (char * datadir ) {
1058+ char * transliteration_path = NULL ;
1059+ char * numex_path = NULL ;
1060+ char * address_dictionary_path = NULL ;
1061+
1062+ if (datadir != NULL ) {
1063+ transliteration_path = path_join (3 , datadir , LIBPOSTAL_TRANSLITERATION_SUBDIR , TRANSLITERATION_DATA_FILE );
1064+ numex_path = path_join (3 , datadir , LIBPOSTAL_NUMEX_SUBDIR , NUMEX_DATA_FILE );
1065+ address_dictionary_path = path_join (3 , datadir , LIBPOSTAL_ADDRESS_EXPANSIONS_SUBDIR , ADDRESS_DICTIONARY_DATA_FILE );
1066+ }
1067+
1068+ if (!transliteration_module_setup (transliteration_path )) {
1069+ log_error ("Error loading transliteration module, dir=%s\n" , transliteration_path );
10601070 return false;
10611071 }
10621072
1063- if (!numex_module_setup (NULL )) {
1064- log_error ("Error loading numex module, LIBPOSTAL_DATA_DIR =%s\n" , LIBPOSTAL_DATA_DIR );
1073+ if (!numex_module_setup (numex_path )) {
1074+ log_error ("Error loading numex module, dir =%s\n" , numex_path );
10651075 return false;
10661076 }
10671077
1068- if (!address_dictionary_module_setup (NULL )) {
1069- log_error ("Error loading dictionary module, LIBPOSTAL_DATA_DIR =%s\n" , LIBPOSTAL_DATA_DIR );
1078+ if (!address_dictionary_module_setup (address_dictionary_path )) {
1079+ log_error ("Error loading dictionary module, dir =%s\n" , address_dictionary_path );
10701080 return false;
10711081 }
10721082
1083+ if (transliteration_path != NULL ) {
1084+ free (transliteration_path );
1085+ }
1086+
1087+ if (numex_path != NULL ) {
1088+ free (numex_path );
1089+ }
1090+
1091+ if (address_dictionary_path != NULL ) {
1092+ free (address_dictionary_path );
1093+ }
1094+
10731095 return true;
10741096}
10751097
1076- bool libpostal_setup_language_classifier (void ) {
1077- if (!language_classifier_module_setup (NULL )) {
1078- log_error ("Error loading language classifier, LIBPOSTAL_DATA_DIR=%s\n" , LIBPOSTAL_DATA_DIR );
1098+ bool libpostal_setup (void ) {
1099+ return libpostal_setup_datadir (NULL );
1100+ }
1101+
1102+ bool libpostal_setup_language_classifier_datadir (char * datadir ) {
1103+ char * language_classifier_dir = NULL ;
1104+
1105+ if (datadir != NULL ) {
1106+ language_classifier_dir = path_join (2 , datadir , LIBPOSTAL_LANGUAGE_CLASSIFIER_SUBDIR );
1107+ }
1108+
1109+ if (!language_classifier_module_setup (language_classifier_dir )) {
1110+ log_error ("Error loading language classifier, dir=%s\n" , language_classifier_dir );
10791111 return false;
10801112 }
1113+
1114+ if (language_classifier_dir != NULL ) {
1115+ free (language_classifier_dir );
1116+ }
1117+
10811118 return true;
10821119}
10831120
1084- bool libpostal_setup_parser (void ) {
1085- if (!geodb_module_setup (NULL )) {
1086- log_error ("Error loading geodb module, LIBPOSTAL_DATA_DIR=%s\n" , LIBPOSTAL_DATA_DIR );
1121+ bool libpostal_setup_language_classifier (void ) {
1122+ return libpostal_setup_language_classifier_datadir (NULL );
1123+ }
1124+
1125+ bool libpostal_setup_parser_datadir (char * datadir ) {
1126+ char * parser_dir = NULL ;
1127+ char * geodb_dir = NULL ;
1128+
1129+ if (datadir != NULL ) {
1130+ parser_dir = path_join (2 , datadir , LIBPOSTAL_ADDRESS_PARSER_SUBDIR );
1131+ geodb_dir = path_join (2 , datadir , LIBPOSTAL_GEODB_SUBDIR );
1132+ }
1133+
1134+ if (!geodb_module_setup (geodb_dir )) {
1135+ log_error ("Error loading geodb module, dir=%s\n" , geodb_dir );
10871136 return false;
10881137 }
10891138
1090- if (!address_parser_module_setup (NULL )) {
1091- log_error ("Error loading address parser module, LIBPOSTAL_DATA_DIR =%s\n" , LIBPOSTAL_DATA_DIR );
1139+ if (!address_parser_module_setup (parser_dir )) {
1140+ log_error ("Error loading address parser module, dir =%s\n" , parser_dir );
10921141 return false;
10931142 }
10941143
1144+ if (parser_dir != NULL ) {
1145+ free (parser_dir );
1146+ }
1147+
1148+ if (geodb_dir != NULL ) {
1149+ free (geodb_dir );
1150+ }
1151+
10951152 return true;
10961153}
10971154
1155+ bool libpostal_setup_parser (void ) {
1156+ return libpostal_setup_parser_datadir (NULL );
1157+ }
1158+
10981159void libpostal_teardown (void ) {
10991160 transliteration_module_teardown ();
11001161
0 commit comments