int IsCorrect(char *s,int start,int end) { int i; if(end==start) { if(s[start]<='z'&&s[start]>='p') { return 1; } else { return 0; } } else if(s[start]=='N'&&IsCorrect(s,start+1,end)) { return 1; } else if(s[start]<='E'&&s[start]>='C'||s[start]=='I') { for(i=1;i<end-start;i++) { if(IsCorrect(s,start+1,start+i)&&IsCorrect(s,start+i+1,end)) {return 1;} } return 0; } else { return 0; } }
//creates the OPEN message *#who*where*#dimension*val_1*val_2*...val_n## void bt_openwebnet::CreateWrDimensionMsgOpen(string who, string where, string dimension, vector<string> value) { //call CreateNullMsgOpen function CreateNullMsgOpen(); stringstream frame; // creates the OPEN message frame << "*#"; frame << who; frame << "*"; frame << where; frame << "*#"; frame << dimension; for (vector<string>::iterator it = value.begin(); it != value.end(); it++) { frame << "*"; frame << *it; } frame << "##"; frame_open = EliminoCaratteriControllo(frame.str()); length_frame_open = frame_open.length(); // checks for correct syntax ... IsCorrect(); }
//creates the OPEN message *#who*where#level#interface*dimension## void bt_openwebnet::CreateDimensionMsgOpen(string who, string where, string lev, string interf, string dimension) { //call CreateNullMsgOpen function CreateNullMsgOpen(); stringstream frame; // creates the OPEN message frame << "*#"; frame << who; frame << "*"; frame << where; frame << "#"; if (lev.empty()) frame << "4"; else frame << lev; frame << "#"; frame << interf; //to remove the trailing asterisk if (dimension.length() != 0) frame << "*"; frame << dimension; frame << "##"; frame_open = EliminoCaratteriControllo(frame.str()); length_frame_open = frame_open.length(); // checks for correct syntax ... IsCorrect(); }
// creates the open message *who*what*where*when## void bt_openwebnet::CreateMsgOpen(string who, string what, string where, string when) { //call CreateNullMsgOpen function CreateNullMsgOpen(); stringstream frame; // creates the open message frame << "*"; frame << who; frame << "*"; frame << what; frame << "*"; frame << where; //to remove the trailing asterisk if (when.length() != 0) { frame << "*"; frame << when; } frame << "##"; frame_open = EliminoCaratteriControllo(frame.str()); length_frame_open = frame_open.length(); // checks for correct syntax ... IsCorrect(); }
void CParser::checkFinished() { if( IsCorrect() ) { state = &CParser::parsingInitial; } else if( IsWrong() ) { state = &CParser::parsingIgnoreLine; AddToken(); } }
bool TestSegmentation::IsCorrect(const string expect, const vector<vector<string>>& result) { for (unsigned int i=0;i<result.size();++i) { if (IsCorrect(expect, result[i])) { return true; } } return false; }
void TestSegmentation::Run(const string filename) { //string filename = "dgk_shooter_z.conv"; try { HopeLove::InitializeBrain("..\\Data\\"); } catch (const std::exception& e) { cout << e.what() << endl; } ofstream out("Incorrect segmentation.txt"); // string raw = "合金材、优质板分别增加21.7%和28%特别是市场紧俏的优质镀锌钢丝和镀锌钢丝绳分别比去年同期增长60.8%和94.8%,"; // vector<vector<string>> result2 = HopeLove::WordSegmentAll(raw.c_str(), HopeLove::ForwardSegment); int correctNum = 0; int totalNum = 0; vector<SentenceSample> samples = ReadSentences(filename); for (unsigned int i=0;i<samples.size();++i) { try { vector<vector<string>> result = HopeLove::WordSegmentAll(samples[i].raw.c_str(), HopeLove::BackwardSegment); if (IsCorrect(samples[i].segmented, result)) { correctNum++; } else { OutputResult(samples[i].segmented, result, out); } ++totalNum; } catch (const std::exception&) { continue; } } cout << "Correct Ratio: " << (double)correctNum / totalNum << endl; cout << "Total Number: " << totalNum << endl; }
StdMessage::UniquePtr_t StdMessageFactory::Create( char* p_message, int p_length ) { #ifdef _DEBUG /*sLogger.Debug(QString("StdMessageFactory::Create: creating standard message with id `%1`..."). arg(QString::fromAscii(p_message, 2)));*/ #endif auto id = StdMessage::MapIdStrToEnum(p_message); auto msg = createById(id, p_message, p_length); if (!msg->IsCorrect()) { msg = StdMessage::UniquePtr_t(new RawStdMessage(p_message, p_length)); } return msg; }
void bt_openwebnet::CreateMsgOpen(string message) { //call CreateNullMsgOpen function CreateNullMsgOpen(); // saves the type of frame and its length frame_open = message; frame_open = EliminoCaratteriControllo(frame_open); length_frame_open = frame_open.length(); // checks for correct syntax ... IsCorrect(); }
void TestPOSTagging::Run(const string corpusFilename) { //Running too slow try { HopeLove::InitializeBrain("..\\Data\\"); } catch (const std::exception& e) { cout << e.what() << endl; } ofstream out("Incorrect posTagging.txt"); auto samples = ReadSentences(corpusFilename); int correctNum = 0; int totalNum = 0; for (unsigned int i = 0; i < samples.size(); ++i) { try { auto result = HopeLove::POSTagging(samples[i].raw); if (IsCorrect(samples[i].POSTag, result)) { correctNum++; } else { OutputResult(samples[i].POSUnsplit, result, out); } ++totalNum; } catch (const std::exception&) { continue; } } cout << "Correct Ratio: " << (double)correctNum / totalNum << endl; cout << "Total Number: " << totalNum << endl; }
//creates the OPEN message *#who*where## void bt_openwebnet::CreateStateMsgOpen(string who, string where) { //call CreateNullMsgOpen function CreateNullMsgOpen(); stringstream frame; // creates the OPEN message frame << "*#"; frame << who; frame << "*"; frame << where; frame << "##"; frame_open = EliminoCaratteriControllo(frame.str()); length_frame_open = frame_open.length(); // checks for correct syntax ... IsCorrect(); }
// +--------------------------------------------------------------+ // | message nameLen | uint32 // +--------------------------------------------------------------+ // | | // | message name | // | | // +--------------------------------------------------------------+ // | | // | data | // | | // +--------------------------------------------------------------+ // | checkSum | uint32 // adler32 of nameLen, typeName and protobufData // +--------------------------------------------------------------+ shared_ptr_Msg ProtobufCodec::Decode(const char* buf, uint32_t len) { //len is length of the namelength, name,data,checksum shared_ptr_Msg result = NULL; if (IsCorrect(buf, len)) { //get message type name uint32_t nameLen = PeekUInt32(buf); if (nameLen >= 2 && nameLen <= len - 2 * kHeaderLen) { std::string typeName(buf + kHeaderLen, buf + kHeaderLen + nameLen - 1); //create message object shared_ptr_Msg message = CreateMessage(typeName); if (message) { //parse from buffer const char* data = buf + kHeaderLen + nameLen; int32_t dataLen = len - nameLen - 2 * kHeaderLen;//namelen,name,checksum if (message->ParseFromArray(data, dataLen)) { result = message; } else { message->Clear(); } } else { // unknown message type } } else { // invalid name len } } else { // check sum error } return result; }
int main() { int len,i; char s[260]; while((scanf("%s",s))!=EOF) { len=strlen(s); i=IsCorrect(s,0,len-1); if(i==1) { printf("YES\n"); } else { printf("NO\n"); } } return 0; }
bool bt_openwebnet::IsEqual(bt_openwebnet msg_to_compare) { // checks for correct syntax ... IsCorrect(); //control that is the same type if(msg_to_compare.frame_type != frame_type) return false; //control that are both two frames extended or not if(msg_to_compare.extended != extended) return false; if(!extended) { if ((msg_to_compare.Extract_who().compare(chi) == 0) && (msg_to_compare.Extract_what().compare(cosa) == 0) && (msg_to_compare.Extract_where().compare(dove) == 0) && (msg_to_compare.Extract_when().compare(quando) == 0) && (msg_to_compare.Extract_dimension().compare(grandezza) == 0)) return true; else return false; } else { if ((msg_to_compare.Extract_who().compare(chi) == 0) && (msg_to_compare.Extract_what().compare(cosa) == 0) && (msg_to_compare.Extract_where().compare(dove) == 0) && (msg_to_compare.Extract_level().compare(livello) == 0) && (msg_to_compare.Extract_interface().compare(interfaccia) == 0) && (msg_to_compare.Extract_when().compare(quando) == 0) && (msg_to_compare.Extract_dimension().compare(grandezza) == 0)) return true; else return false; } }
//creates the OPEN message *#who*where#level#interface## void bt_openwebnet::CreateStateMsgOpen(string who, string where, string lev, string interf) { //call CreateNullMsgOpen function CreateNullMsgOpen(); stringstream frame; frame << "#"; frame << who; frame << "*"; frame << where; frame << "#"; if (lev.empty()) frame << "4"; else frame << lev; frame << "#"; frame << interf; frame << "##"; frame_open = EliminoCaratteriControllo(frame.str()); length_frame_open = frame_open.length(); // checks for correct syntax ... IsCorrect(); }
//creates the OPEN message *#who*where#level#interface*#dimension*val_1*val_2*...val_n## void bt_openwebnet::CreateWrDimensionMsgOpen(string who, string where, string lev, string interf, string dimension, vector<string> value) { //call CreateNullMsgOpen function CreateNullMsgOpen(); stringstream frame; // creates the OPEN message frame << "*#"; frame << who; frame << "*"; frame << where; frame << "*#"; if (lev.empty()) frame << "4"; else frame << lev; frame << "#"; frame << interf; //to remove the trailing asterisk if (!dimension.empty()) { frame << "*"; frame << dimension; } for (vector<string>::iterator it = value.begin(); it != value.end(); it++) { frame << "*"; frame << *it; } frame << "##"; frame_open = EliminoCaratteriControllo(frame.str()); length_frame_open = frame_open.length(); // checks for correct syntax ... IsCorrect(); }