Skip to content

Instantly share code, notes, and snippets.

@naoa
Created Apr 5, 2014
Embed
What would you like to do?
compile: gcc -I/usr/include/glib-2.0 -lglib-2.0 -lWN wn_morph.c -o wn_morph dependency:glib2 glib2-devel wordnet wordnet-devel
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <wn.h>
#define MAX_STRINGS 65535
#define MAX_BUF_NUM 4096
#define MAX_BUF_SIZE 255
int main(int argc, char *argv[])
{
char data[MAX_STRINGS];
FILE *fp;
char sp[] = " \n";
char *tok;
int pos;
char *morph;
if (wninit() == -1) {
printf("wninit error.\n");
return -1;
}
if ((fp = fopen(argv[1], "r")) == NULL)
{
printf("input file %s error.\n", argv[1]);
return -1;
}
while( fgets(data, MAX_STRINGS, fp) != NULL){
tok = strtok( data, sp );
char buf[MAX_BUF_NUM][MAX_BUF_SIZE];
int i = 0;
while(tok != NULL){
strcpy (buf[i], tok);
tok = strtok( NULL, sp );
i++;
}
int t;
for(t = 0; t < i ; t++){
//pos 1:NOUN 2:VERB 3:ADJECTIVE 4:ADVERB 5:ADJECTIVE_SATELITE
for(pos = 5; pos >= 1; pos--){
morph = morphstr(buf[t], pos);
if(morph){
break;
}
}
if(morph){
printf( "%s ", morph );
}
else if(buf[t]){
printf( "%s ", buf[t] );
}
}
printf("\n");
}
fclose(fp);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment