static inline void print_output(char *address, normalize_options_t options, bool use_json) { size_t num_expansions; char **strings = expand_address(address, options, &num_expansions); char *normalized; if (!use_json) { for (size_t i = 0; i < num_expansions; i++) { normalized = strings[i]; printf("%s\n", normalized); free(normalized); } } else { printf("{\"expansions\": ["); for (size_t i = 0; i < num_expansions; i++) { normalized = strings[i]; char *json_string = json_encode_string(normalized); printf("%s%s", json_string, i < num_expansions - 1 ? ", ": ""); free(normalized); free(json_string); } printf("]}\n"); } free(strings); }
int main(int argc, char **argv) { if (argc < 3) { log_error("Usage: test_libpostal string languages...\n"); exit(EXIT_FAILURE); } char *str = argv[1]; char *languages[argc - 2]; for (int i = 0; i < argc - 2; i++) { char *arg = argv[i + 2]; if (strlen(arg) >= MAX_LANGUAGE_LEN) { printf("arg %d was longer than a language code (%d chars). Make sure to quote the input string\n", i + 2, MAX_LANGUAGE_LEN - 1); } languages[i] = arg; } if (!libpostal_setup()) { exit(EXIT_FAILURE); } normalize_options_t options = get_libpostal_default_options(); options.num_languages = 1; options.languages = languages; size_t num_expansions; char **strings; char *normalized; int num_loops = 100000; token_array *tokens = tokenize(str); uint64_t num_tokens = tokens->n; token_array_destroy(tokens); clock_t t1 = clock(); for (int i = 0; i < num_loops; i++) { strings = expand_address(str, options, &num_expansions); for (uint64_t i = 0; i < num_expansions; i++) { normalized = strings[i]; free(normalized); } free(strings); } clock_t t2 = clock(); double benchmark_time = (double)(t2 - t1) / CLOCKS_PER_SEC; printf("Benchmark time: %f\n", benchmark_time); double addresses_per_second = num_loops / benchmark_time; printf("addresses/s = %f\n", addresses_per_second); double tokens_per_second = (num_loops * num_tokens) / benchmark_time; printf("tokens/s = %f\n", tokens_per_second); libpostal_teardown(); }
static greatest_test_res test_expansion_contains(char *input, char *output, normalize_options_t options) { size_t num_expansions; char **expansions = expand_address(input, options, &num_expansions); bool contains_expansion = false; char *expansion; for (size_t i = 0; i < num_expansions; i++) { expansion = expansions[i]; if (strcmp(output, expansion) == 0) { contains_expansion = true; break; } } ASSERT(contains_expansion); PASS(); }
int main(int argc, char **argv) { if (argc < 3) { log_error("Usage: test_libpostal string languages...\n"); exit(EXIT_FAILURE); } char *str = argv[1]; char *languages[argc - 2]; for (int i = 0; i < argc - 2; i++) { char *arg = argv[i + 2]; if (strlen(arg) >= MAX_LANGUAGE_LEN) { printf("arg %d was longer than a language code (%d chars). Make sure to quote the input string\n", i + 2, MAX_LANGUAGE_LEN - 1); } languages[i] = arg; } if (!libpostal_setup()) { exit(EXIT_FAILURE); } normalize_options_t options = LIBPOSTAL_DEFAULT_OPTIONS; options.languages = languages; uint64_t num_expansions; char **strings = expand_address(str, options, &num_expansions); char *normalized; for (uint64_t i = 0; i < num_expansions; i++) { normalized = strings[i]; printf("%s\n", normalized); free(normalized); } free(strings); libpostal_teardown(); }
// ====================================================== void simppoll::OnOK() // ====================================================== { CString str,full,info; char tmp[MAX_PATH],path[MAX_PATH]; char eofchr[]={0,0}; time_t oldsecs; int errorcode,zone,net,node,point; OLDPKTHDR po; // groesse jeweils 58 bytes NEWPKTHDR *pn; FILE *fp; m_edit.GetWindowText(str); trim_all(str); int ret=expand_address(str,full,info,1,1,0,errorcode); if (!ret) ERR_MSG_RET("W_NOFSFIM"); CFido xx; xx=PS full; make_path(tmp,gc.OutboundPath,xx.GetAsDir(0)); if (!access(tmp,0)) ERR_MSG2_RET("M_PSAE",full); time(&oldsecs); str.Format("%08X",oldsecs); _mkdir(tmp); make_path(path,tmp,str); // now fill pkt-structure get_first_aka(&zone,&net,&node,&point); pn = (NEWPKTHDR *)&po; memset(pn,0,sizeof(NEWPKTHDR)); pn->product = 0; pn->rev_lev = 0; pn->subver = 2; pn->version = 2; pn->ozone = zone; // main aka pn->onet = net; pn->onode = node; pn->opoint = point; pn->dzone = xx.zone; // remote aka pn->dnet = xx.net; pn->dnode = xx.node; pn->dpoint = xx.point; fp=fopen(path,"wb"); if (!fp) ERR_MSG2_RET("E_CANTCREATEDUMMY",path); fwrite(pn,sizeof(NEWPKTHDR),1,fp); fwrite(eofchr,2,1,fp); fclose(fp); gMailer.ShowWindow(SW_SHOWNORMAL); gMailer.GraphicalStatusDisplay(1); CDialog::OnOK(); }