Skip to content

Commit

Permalink
New parser without sstream
Browse files Browse the repository at this point in the history
  • Loading branch information
Javier authored and Javier committed Feb 5, 2017
1 parent f621796 commit 1a1f1d3
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 4,461 deletions.
28 changes: 18 additions & 10 deletions classifier.cpp
Original file line number Diff line number Diff line change
@@ -1,9 +1,4 @@
#include "classifier.h"
#include <sstream>
#include <iostream>
#include <fstream>
#include <string>
#include <vector>

//Constructor. parse() does the rest
Classifier::Classifier (string s){
Expand Down Expand Up @@ -33,13 +28,18 @@ We use a float vectors, so each line would be:
*/
void Classifier::parse (string s)
{
std::stringstream lineStream(s);
//std::stringstream lineStream(s);
string line;
int linePosition;


vector<float> node;

//Divide by lines
while(getline(lineStream, line))
while((linePosition=s.find('\n'))!=-1)
//while(getline(lineStream, line))
{
line=s.substr(0, linePosition+1);
//Check first letter. If feature, push a 0 and the feature number
if(line.at(0) == 'f')
{
Expand All @@ -48,14 +48,21 @@ void Classifier::parse (string s)
node.push_back((float)atof(line.substr(1,line.find(',')-1).data()));

//Push the rest from the first comma
std::stringstream tokenStream(line.substr(line.find(',')-1));
//std::stringstream tokenStream(line.substr(line.find(',')-1));
string token;
string values=line.substr(line.find(',')-1);
int commaPosition;

while(getline(tokenStream, token, ','))
while((commaPosition=values.find(','))!=-1 || (commaPosition=values.find('\n'))!=-1)
//while(getline(tokenStream, token, ','))
{
token=values.substr(0, commaPosition);
node.push_back((float)atof(token.data()));
values=values.substr(commaPosition+1);
}

node.push_back((float)atof(token.data()));

}
//If state, push a 1 and the state number
else if(line.at(0)=='s')
Expand All @@ -64,10 +71,11 @@ void Classifier::parse (string s)
node.push_back((float)atof(line.substr(1).data()));
}
else{
cout<<"Error with classifier input string\n";
// cout<<"Error with classifier input string\n";
break;
}
decisionTree.push_back(node);
s=s.substr(linePosition+1);
node.clear();
}
}
Expand Down
1 change: 0 additions & 1 deletion classifier.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#include <sstream>
#include <iostream>
#include <fstream>
#include <string>
Expand Down
Loading

0 comments on commit 1a1f1d3

Please sign in to comment.