1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115
|
#include <iostream>
#include <io.h>
#include <string>
#include <cstring>
#include <map>
#include <fcntl.h>
using namespace std;
#define FILENAME "G:\\MS_shirazu\\TextMining\\HWs\\TWA\\TWA\\Bass.Test"
int main()
{
char buffer[120000] = {0}, fishBuffer[120000] = {0}, audioBuffer[120000] = {0};
int fh = _open(FILENAME, O_RDONLY);
_read(fh, buffer, 120000 );
map<string, int> fishMap, musicMap;
//cout << buffer << endl;
int i=0;
char *pc0=&buffer[0]; //points to the first element
char *pc1;
char *pc2;
char *ps1, *ps2;
int senseNo = 1;
ps1 = strstr(buffer, "%"); //searching for the first occurrence of %
pc1 = strstr(buffer, "<context>"); //searching for the first occurrence of <context>
pc2 = strstr(pc1, "</context>");
ps2 = strstr(ps1, "/>");
switch( *(ps1+1) )
{
case 'm':
strncat(audioBuffer, pc1+10, pc2-10-pc1);
break;
case 'f':
strncat(fishBuffer, pc1+10, pc2-10-pc1);
break;
}//end switch
ps1=ps2;
while(ps1 &&senseNo<107)
{
ps1 = strstr(ps1, "%");
++senseNo ;
ps2 = strstr(ps1, "\"/>");
pc1 = strstr(pc1, "<context>"); //searching for the first occurrence of <context>
pc2 = strstr(pc1, "</context>");
switch( *(ps1+1) )
{
case 'm':
strncat(audioBuffer, pc1+10, pc2-10-pc1);
break;
case 'f':
strncat(fishBuffer, pc1+10, pc2-10-pc1);
break;
}//end switch
ps1=ps2;
pc1=pc2;
}
i=0;
char **word_fish = new char *[strlen(fishBuffer)];
for(int j=0;j<strlen(fishBuffer); ++j)
word_fish[j] = new char[strlen(fishBuffer)];
word_fish[i] = strtok(fishBuffer, " .,;!?");
cout <<strlen(audioBuffer);
char **word_music = new char *[strlen(audioBuffer)];
for(int k=0;k<strlen(audioBuffer); ++k)
word_music[k] = new char[100];
word_music[50][50] = 'c';
cout << word_music[50][50];
//cout << word_music[0] << endl;
while( word_fish[i++] )
{
word_fish[i] = strtok(0, " .,;!?");
fishMap[ word_fish[i-1] ]++;
}
i=0;
int f;
// cout << strlen( audioBuffer );
word_music[i] = strtok(audioBuffer, " .,;");
while( word_music[i++] )
{
word_music[i]= strtok(0, " .,;");
//cout << word_music[i] << " ";
i=f;
musicMap[ word_music[i-1] ]++;
}
cout << i;//doesn't print
cin >> f;
////////////////////////////////////
string *ds = new string[senseNo];
return 0;
}
|