I want to use a dependency parser, which is free (al least for education purpose). So Minipar might be the right one. There is an example came with the package but parsing result is relied on surface forms. Surface form is easy to understand but it will be problematic when there are 2 duplicated words in the same sentence so I use position of word in the sentence instead and fortunately it is available the API ^_^. I just use head_pos() from node as below:
#include
#include
#include “ptree.h”
#define LINE_SIZE 100000
void
printParseResult(const ParseNode* node)
{
ParseNode* parent = ((ParseNode*) node)->parent();
if (node->relation() && parent && parent->category()) {
if (parent->root() && parent->category() &&
node->category() && node->root() && node->relation()) {
/* print parent head_pos, surface, category */
printf(“%d\t%s\t%s”, parent->head_pos(),
parent->root(),
parent->category());
printf(“\t”);
/* print node head_pos, surface, category */
printf(“%d\t%s\t%s”, node->head_pos(),
node->root(),
node->category());
printf(“\t”);
/* relation */
printf(“%s”, node->relation());
}
printf(“\n”);
}
forall (ParseNode*, sub, TRSTree, node) {
printParseResult(sub);
}
}
int
main(int argc, char **argv)
{
const char *path;
ParseTree parseTree;
char line[LINE_SIZE];
if(argc != 2) {
fprintf(stderr, “Usage: %s \n”, argv[0]);
return EXIT_FAILURE;
}
path = argv[1];
initialize_minipar(path);
while(fgets(line, LINE_SIZE, stdin) != NULL) {
parseTree.reset();
parse(line, parseTree);
printParseResult(parseTree.root());
}
return EXIT_SUCCESS;
}
I use it like this:
$ echo "I like a cat." | ./vparse ../data 2> /dev/null 1 fin C 2 like V i 2 like V 1 I N s 2 like V 3 I N subj 2 like V 4 cat N obj 4 cat N 3 a Det det $