示例#1
0
/********************************************************************
 * Read file
 ********************************************************************/
void Prefixspan::read(const string &_filename, Pairdata &pairdata) {
  string       line;
  int          item;
  unsigned int id = 0;
  istream *is;

  if (_filename == "-") {
    is = &cin;
  } else {
    is = new ifstream(_filename.c_str());
  }

  Transaction transaction;
  while (getline (*is, line)) {
    transaction.second.clear();
    vector<unsigned int> &itemsets = transaction.second;
    istrstream istrs ((char *)line.c_str());

    while (istrs >> item) 
      itemsets.push_back(item);
    
    transaction.first = id++;
    
    pairdata.database.push_back(transaction);
    pairdata.indeces.push_back(0);
  }

  if (_filename != "-") {
      delete is;
  }
}
示例#2
0
istream& PrefixSpan::read (istream &is)
{
        string line;
        vector <int> tmp;
        int item;
        string cc;
        //record;
        //vector<int>temp;
        while (getline (is, line))
        {
           tmp.clear ();
           //temp.clear();
           istrstream istrs ((char *)line.c_str());
           while (istrs >> item) tmp.push_back (item);//每行的数据保存在vector<string>里
          // istrstream iistrs ((char *)line.c_str());
           //while(iistrs >> cc)
            //{temp.push_back(cc.size());cout<<cc.size()<<' ';}
           transaction.push_back (tmp);//transaction 相当于一个二维数组保存了所有数据
           //record.push_back(temp);
        }
        //cout<<record.size()<<record[0][0]<<record[0][1];
		minSupLen = minsup * transaction.size();
		minSupLen = minSupLen > 2? minSupLen :2;
		cout<<"最小支持数:"<<minSupLen<<endl;
        return is;
}