// Function to filter sentences out of a stream static inline bool parsesentence( const char*& seek, Sentence& out ) { std::string content; while ( true ) { const char c = *seek++; switch( c ) { // End of the stream case 0: seek--; // If there is no new sentence and the stream ended, we have to quit reading if ( content.empty() ) return false; // ... indicated by false out = Sentence( content, SENTENCE_NORMAL ); return true; // Some standard sentence. case '.': // We should not care about empty sentences if ( content.empty() ) break; out = Sentence( content, SENTENCE_NORMAL ); return true; // The guy wants to express something! case '!': if ( content.empty() ) break; out = Sentence( content, SENTENCE_COMMAND ); return true; // We are getting some question! case '?': if ( content.empty() ) break; out = Sentence( content, SENTENCE_QUESTION ); return true; } content += c; } return true; }
void VoiceEndpoint::timerEvent(QTimerEvent *event) { if(m_sesTimer > 0 && event && event->timerId() == m_sesTimer) { killTimer(m_sesTimer); m_sesTimer = 0; switch (m_sesPhase) { case PhSetupRequest: sessionSetupResponse(ResTimeout,QUuid()); break; case PhSetupComplete: sessionSetupResponse(ResInvalidMessage,QUuid()); break; case PhAudioStarted: stopAudioStream(m_sessId); break; case PhAudioStopped: //transcriptionResponse(ResTimeout,QList<Sentence>(),QUuid()); // We should actualy reply like this but lets do... transcriptionResponse(ResSuccess, QList<Sentence>({ Sentence({8,QList<Word>({{1,2,"No"},{1,3,"one"},{1,5,"dared"},{1,2,"to"},{1,5,"reply"},{1,1,"."},{1,7,"Service"},{1,7,"Timeout"}})}) }), m_appUuid); // Example transcription - for the reference break; case PhResultReceived: sendDictationResults(); sessionDestroy(); break; default: qDebug() << "Unhandled timer event for phase" << m_sesPhase; } } }
int XML4NLP::SetSentencesToParagraph(const vector<string> &vecSentence, int paragraphIdx) { if (0 != CheckRange(paragraphIdx)) { return -1; } if (!document.paragraphs[paragraphIdx].sentences.empty()) { return -1; } Paragraph & paragraph = document.paragraphs[paragraphIdx]; TiXmlElement * paragraphPtr = paragraph.paragraphPtr; vector<Sentence> &sentences = paragraph.sentences; TiXmlText *textPtr = paragraphPtr->FirstChild()->ToText(); if (textPtr == NULL) { return -1; } else { paragraphPtr->RemoveChild(textPtr); } for (int i = 0; i < vecSentence.size(); ++i) { TiXmlElement *sentencePtr = new TiXmlElement(TAG_SENT); sentencePtr->SetAttribute(TAG_ID, static_cast<int>(i)); sentencePtr->SetAttribute(TAG_CONT, vecSentence[i].c_str()); paragraphPtr->LinkEndChild(sentencePtr); sentences.push_back( Sentence() ); sentences[sentences.size()-1].sentencePtr = sentencePtr; } return 0; }
Sentence Paragraph::first(){ if(head){ return head->data; }else{ Sentence s = Sentence(); return s; } }
int XML4NLP::InitXmlSentence(vector<Sentence> &sentences, TiXmlElement *stnsPtr) { sentences.push_back( Sentence() ); Sentence &sentence = sentences[sentences.size()-1]; sentence.sentencePtr = stnsPtr; TiXmlElement *wordPtr = stnsPtr->FirstChildElement(TAG_WORD); if (wordPtr == NULL) return 0; // have not done word segment do { if (0 != InitXmlWord(sentence.words, wordPtr)) return -1; wordPtr = wordPtr->NextSiblingElement(TAG_WORD); } while(wordPtr != NULL); return 0; }
static Bitmap read_bmp_or_throw(const FilePath& filePath){ BinaryReader in(filePath); if (!in.good()){ throw ReadBmpError(error_open_file_read(filePath)); } auto bitmapFileHeader = read_struct_or_throw_bmp<BitmapFileHeader>(in); if (bitmapFileHeader.fileType != BITMAP_SIGNATURE){ throw ReadBmpError(error_bitmap_signature(bitmapFileHeader.fileType)); } auto bitmapInfoHeader = read_struct_or_throw_bmp<BitmapInfoHeader>(in); if (invalid_header_length(bitmapInfoHeader.headerLen)){ throw ReadBmpError(error_truncated_bmp_header(bitmapInfoHeader.headerLen)); } if (bitmapInfoHeader.compression != Compression::BI_RGB){ throw ReadBmpError(error_compression(bitmapInfoHeader.compression)); } if (bitmapInfoHeader.colorPlanes != 1){ throw ReadBmpError(error_color_planes(bitmapInfoHeader.colorPlanes)); } auto bmpSize = get_size_and_order(bitmapInfoHeader); if (bitmapInfoHeader.paletteColors != 0){ if (bitmapInfoHeader.bitsPerPixel != 8){ // Fixme: Maybe support? throw ReadBmpError("Palette for non 8-bpp bitmaps unsupported by Faint."); } auto colorList = or_throw(read_color_table(in, bitmapInfoHeader.paletteColors), "Failed reading color table."); in.seekg(bitmapFileHeader.dataOffset); auto alphaMap = or_throw(read_8bipp_BI_RGB(in, bmpSize), "Failed reading 8-bits-per-pixel data"); return bitmap_from_indexed_colors(alphaMap, colorList); } else{ // No palette in.seekg(bitmapFileHeader.dataOffset); if (bitmapInfoHeader.bitsPerPixel == 8){ auto alphaMap = or_throw(read_8bipp_BI_RGB(in, bmpSize), "Failed reading 8-bits-per-pixel data"); return bitmap_from_indexed_colors(alphaMap, grayscale_color_table()); } else if (bitmapInfoHeader.bitsPerPixel == 24){ return or_throw(read_24bipp_BI_RGB(in, bmpSize), "Failed reading 24-bits-per-pixel data."); } else if (bitmapInfoHeader.bitsPerPixel == 32){ return or_throw(read_32bipp_BI_RGB(in, bmpSize), "Failed reading 32-bits-per-pixel data."); } } throw ReadBmpError(Sentence("Unsupported bits-per-pixel", bracketed(str_int(bitmapInfoHeader.bitsPerPixel)))); }