Skip to content

Instantly share code, notes, and snippets.

@tonylambiris
Created July 28, 2018 00:48
Show Gist options
  • Select an option

  • Save tonylambiris/b86267f61660516ea9209488353e86a0 to your computer and use it in GitHub Desktop.

Select an option

Save tonylambiris/b86267f61660516ea9209488353e86a0 to your computer and use it in GitHub Desktop.
gposttl shared library tokenizer test
#include <stdlib.h>
#include <stdio.h>
#include <dlfcn.h>
int (*initialize_tagger)(char *envp);
void (*destroy_tagger)(void);
char *(*Tokenizer)(char *buff);
char *(*tag)(char *buf, int enhanced_penntag);
int main(int argc, char **argv) {
int i;
char *token;
void *handle;
char *error;
char *words = "My name is The Plauge.";
handle = dlopen ("/usr/lib/libgposttl.so.0.0.0", RTLD_GLOBAL|RTLD_LAZY);
if (!handle) {
fputs (dlerror(), stderr);
exit(1);
}
initialize_tagger = dlsym(handle, "initialize_tagger");
if ((error = dlerror()) != NULL) {
fputs(error, stderr);
exit(1);
}
destroy_tagger = dlsym(handle, "destroy_tagger");
if ((error = dlerror()) != NULL) {
fputs(error, stderr);
exit(1);
}
Tokenizer = dlsym(handle, "Tokenizer");
if ((error = dlerror()) != NULL) {
fputs(error, stderr);
exit(1);
}
tag = dlsym(handle, "tag");
if ((error = dlerror()) != NULL) {
fputs(error, stderr);
exit(1);
}
i = initialize_tagger("/usr/share/gposttl");
if(i == -1) {
fputs("Error in tagger init", stderr);
exit(1);
}
token = tag(Tokenizer(words), 1);
if(token == NULL) {
fputs("Error in tokenizer", stderr);
exit(1);
}
puts(token);
destroy_tagger();
dlclose(handle);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment