diff options
Diffstat (limited to 'fsa/src/alltest/conceptnet_test.cpp')
-rw-r--r-- | fsa/src/alltest/conceptnet_test.cpp | 80 |
1 files changed, 80 insertions, 0 deletions
diff --git a/fsa/src/alltest/conceptnet_test.cpp b/fsa/src/alltest/conceptnet_test.cpp new file mode 100644 index 00000000000..38c020aa511 --- /dev/null +++ b/fsa/src/alltest/conceptnet_test.cpp @@ -0,0 +1,80 @@ +// Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. +#include <stdlib.h> +#include <unistd.h> +#include <stdio.h> + +#include <vespa/fsa/conceptnet.h> +#include <vespa/fsamanagers/conceptnetmanager.h> + +using namespace fsa; + +int main(int argc, char **argv) +{ + char opt; + //extern char *optarg; + extern int optind; + + bool do_ext = false, do_assoc = false, do_cat = false; + + while((opt=getopt(argc,argv,"aec")) != -1){ + switch(opt){ + case 'a': + do_assoc = true; + break; + case 'e': + do_ext = true; + break; + case 'c': + do_cat = true; + break; + case '?': + fprintf(stderr,"conceptnet_test: unrecognized option"); + exit(1); + } + } + + if(optind>=argc){ + fprintf(stderr,"usage: conceptnet_test [-aec] DOMAIN [UNIT ...]\n"); + exit(1); + } + + std::string domain = argv[optind]; + + if(!ConceptNetManager::instance().load(domain, + domain + ".fsa", + domain + ".dat")){ + fprintf(stderr,"failed to load concept net %s\n",domain.c_str()); + exit(1); + } + + ConceptNet::Handle* cn = ConceptNetManager::instance().get(domain); + + if(cn!=NULL){ + for(int i=optind+1;i<argc;i++){ + int idx = (*cn)->lookup(argv[i]); + printf("%s(%d) : (%d,%d,%d,%d) (%f,%f)\n",argv[i],idx, + (*cn)->frq(idx),(*cn)->cFrq(idx),(*cn)->qFrq(idx),(*cn)->sFrq(idx), + (*cn)->score(idx),(*cn)->strength(idx)); + if(do_ext){ + for(int e = 0; e<(*cn)->numExt(idx); e++){ + printf(" %s, %d\n",(*cn)->lookup((*cn)->ext(idx,e)),(*cn)->extFrq(idx,e)); + } + } + if(do_assoc){ + for(int a = 0; a<(*cn)->numAssoc(idx); a++){ + printf(" %s, %d\n",(*cn)->lookup((*cn)->assoc(idx,a)),(*cn)->assocFrq(idx,a)); + } + } + if(do_cat){ + for(int c = 0; c<(*cn)->numCat(idx); c++){ + printf(" %s\n",(*cn)->catName((*cn)->cat(idx,c))); + } + } + } + } + else { + fprintf(stderr,"failed to load concept net %s\n",domain.c_str()); + exit(1); + } + +} |