Skip to content

Instantly share code, notes, and snippets.

@alphaKAI
Created January 4, 2013 15:38
Show Gist options
  • Select an option

  • Save alphaKAI/4453537 to your computer and use it in GitHub Desktop.

Select an option

Save alphaKAI/4453537 to your computer and use it in GitHub Desktop.
MeCabで形態素解析させて品詞IDごとにファイルに振り分ける処理がしたいのですが、上手く動かない 自分用ライブラリ使ってます(GitHubにある) 62行目のコマンドが怪しいです てかそこが犯人のはずです。。。 system関数でコマンド実行 → ファイルに出力 → 読み込んでそのIDごとに振り分ける こういう処理がしたいんです・・・
#include "my_lib.h"
//copyright (C) alpha_kai_NET All rights reserved. 2012-2013 alpha-kai-net.info
//GPLv3 LICENSE
int main(void){
//RetrunStrings
char filename[]= "data.txt";
char str[1000];
//int get_line;
int return_sum;
//main
int i;
int num;
int sum;
int dum;
int kum;
//char mecab[260];
char tmp[260];
char tmpf[]= "word/tmp.txt";
int posid;
FILE *fp;
FILE *ftmp;
dum=check(filename);
if(dum==0){
printf("ERROR:\n");
printf("カレントディレクトリに%sがありません\n", filename);
printf("終了します\n");
return 1;
}
else if(dum==1){
sum=how_line(filename);
for(i=1; i<=sum; i++){
return_sum = ReturnStrings(filename, i, str, 1000);
if(return_sum!=0){
switch(return_sum){
case -1:
printf("ファイルオープンに失敗\n");
return -1;
break;
case -2:
printf("データ取得失敗\n");
return -2;
break;
default:
printf("返り値が異常です\n");
return return_sum;
break;
}
}
strtok(str,"\n\0");
strcat(str,"\0");
//コマンド作成
//おそらくこの場所が原因
sprintf(tmp, "echo %s | mecab -F \"%h\n\" -E \" \" > %s", str, tmpf);
num=system(tmp);
//品詞ID取得
ftmp=fopen(tmpf,"wt");
fscanf(ftmp, "%s", &posid);
fclose(ftmp);
sprintf(tmp, "word/%d.txt", posid);
kum=check(tmp);
if(kum==1){
fp=fopen(tmp, "ab");
}
else if(kum==0){
fp=fopen(tmp, "wt");
}
fprintf(fp, "%s\n", str);
fclose(fp);
}
}
else{
printf("ERROR:\n");
printf("ファイルチェックの返り値が異常\n");
return 3;
}
del(tmpf);
printf("Complete\n");
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment