本文整理汇总了C++中CSentence类的典型用法代码示例。如果您正苦于以下问题:C++ CSentence类的具体用法?C++ CSentence怎么用?C++ CSentence使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了CSentence类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: CScript
void CDialogueManager::LoadDialogue(const char *szFilename)
{
int scriptNum;
int sentenceNum;
int strLen;
char* buffer;
// Load in all the dialogue from file at beginning of game
ifstream in;
in.open(szFilename,ios_base::in | ios_base::binary);
if( in.is_open() )
{
in.read((char*)&scriptNum,sizeof(int));
for( int script = 0; script < scriptNum; script++ )
{
in.read((char*)&strLen,sizeof(int));
buffer = new char[strLen+1];
in.read(buffer,strLen);
buffer[strLen] = '\0';
string szName = buffer;
CScript* newScript = new CScript(szName);
delete[] buffer;
in.read((char*)&sentenceNum,sizeof(int));
for( int sentence = 0; sentence < sentenceNum; sentence++ )
{
in.read((char*)&strLen,sizeof(int));
buffer = new char[strLen+1];
in.read(buffer,strLen);
buffer[strLen] = '\0';
string szSentence = buffer;
delete[] buffer;
in.read((char*)&strLen,sizeof(int));
buffer = new char[strLen+1];
in.read(buffer,strLen);
buffer[strLen] = '\0';
string szTrigger = buffer;
delete[] buffer;
CSentence* newSentence = new CSentence(szSentence,szTrigger);
if( strLen < 1 )
newSentence->SetEventBool(false);
else
newSentence->SetEventBool(true);
newScript->AddSentence(newSentence);
}
m_vScripts.push_back(newScript);
}
}
in.close();
}
示例2: CheckSumWork
bool CSoundCombiner::IsCombinedFileChecksumValid( IFileSystem *filesystem, char const *outfile, CUtlVector< CombinerEntry >& info )
{
unsigned int computedChecksum = CheckSumWork( filesystem, info );
char fullpath[ MAX_PATH ];
Q_strncpy( fullpath, outfile, sizeof( fullpath ) );
filesystem->GetLocalPath( outfile, fullpath, sizeof( fullpath ) );
CSentence sentence;
bool valid = false;
if ( LoadSentenceFromWavFile( fullpath, sentence ) )
{
unsigned int diskFileEmbeddedChecksum = sentence.GetDataCheckSum();
valid = computedChecksum == diskFileEmbeddedChecksum;
if ( !valid )
{
Warning( " checksum computed %u, disk %u\n",
computedChecksum, diskFileEmbeddedChecksum );
}
}
else
{
Warning( "CSoundCombiner::IsCombinedFileChecksumValid: Unabled to load %s\n", fullpath );
}
CleanupWork();
return valid;
}
示例3: GetConjProperties
static int GetConjProperties(const CSentence& S, int WordNo, ConjFromWhatList& FromWhere,int& iConjIndex, int UpperBorder)
{
if( (WordNo == -1) || (WordNo >= UpperBorder) )
return -1;
int OborotNo = S.m_Words[WordNo].GetOborotNo();
if ( OborotNo != -1
&& S.GetOpt()->m_pOborDic->m_Entries[OborotNo].HasPartOfSpeech(S.GetOpt()->m_Conjunction)
)
{
for(size_t i = WordNo ; i < UpperBorder; i++ )
if( S.m_Words[i].HasOborot2())
{
FromWhere = FROM_OBOR_DIC;
iConjIndex = OborotNo;
return WordNo + 1;
}
}
iConjIndex = S.m_Words[WordNo].m_SubordinateConjNo;
int HomonymNo;
if ( (iConjIndex != -1 )
&& !S.IsRelativSentencePronoun(0, WordNo, HomonymNo)
)
{
FromWhere = FROM_SUB_CONJ;
return WordNo+1;
}
return -1;
}
示例4: Append
void CSentence::Append( float starttime, const CSentence& src )
{
#if PHONEME_EDITOR
int i;
// Combine
for ( i = 0 ; i < src.m_Words.Size(); i++ )
{
CWordTag *word = src.m_Words[ i ];
CWordTag *newWord = new CWordTag( *word );
newWord->m_flStartTime += starttime;
newWord->m_flEndTime += starttime;
// Offset times
int c = newWord->m_Phonemes.Count();
for ( int i = 0; i < c; ++i )
{
CPhonemeTag *tag = newWord->m_Phonemes[ i ];
tag->AddStartTime( starttime );
tag->AddEndTime( starttime );
}
AddWordTag( newWord );
}
if ( src.GetText()[ 0 ] )
{
char fulltext[ 4096 ];
if ( GetText()[ 0 ] )
{
Q_snprintf( fulltext, sizeof( fulltext ), "%s %s", GetText(), src.GetText() );
}
else
{
Q_strncpy( fulltext, src.GetText(), sizeof( fulltext ) );
}
SetText( fulltext );
}
int c = src.m_EmphasisSamples.Size();
for ( i = 0; i < c; i++ )
{
CEmphasisSample s = src.m_EmphasisSamples[ i ];
s.time += starttime;
m_EmphasisSamples.AddToTail( s );
}
// Or in voice duck settings
m_bShouldVoiceDuck |= src.m_bShouldVoiceDuck;
#else
Assert( 0 );
#endif
}
示例5: GetNodeGrmStr
string GetNodeGrmStr(const CSentence& Sentence, const CRelationsIterator& RelIt, int GroupNo, int WordNo, string& Lemma)
{
Lemma = "";
if (GroupNo != -1)
return "";
else {
size_t ClauseNo = Sentence.GetMinClauseByWordNo(WordNo);
const CClause& Clause = Sentence.GetClause(ClauseNo);
const CMorphVariant* pSynVar = &*Clause.GetSynVariantByNo(0);
int UnitNo = pSynVar->UnitNoByWordNo(WordNo);
const CSynUnit& U = pSynVar->m_SynUnits[UnitNo];
Lemma = Sentence.GetWords()[WordNo].GetHomonym(U.m_iHomonymNum)->m_strLemma;
return Sentence.GetOpt()->GetGramTab()->GrammemsToStr(U.m_iGrammems | U.m_TypeGrammems);
}
}
示例6: LoadSentenceFromWavFileUsingIO
bool CSoundCombiner::LoadSentenceFromWavFileUsingIO( char const *wavfile, CSentence& sentence, IFileReadBinary& io )
{
sentence.Reset();
InFileRIFF riff( wavfile, io );
// UNDONE: Don't use printf to handle errors
if ( riff.RIFFName() != RIFF_WAVE )
{
return false;
}
// set up the iterator for the whole file (root RIFF is a chunk)
IterateRIFF walk( riff, riff.RIFFSize() );
// This chunk must be first as it contains the wave's format
// break out when we've parsed it
bool found = false;
while ( walk.ChunkAvailable() && !found )
{
switch( walk.ChunkName() )
{
case WAVE_VALVEDATA:
{
found = true;
CSoundCombiner::ParseSentence( sentence, walk );
}
break;
}
walk.ChunkNext();
}
return true;
}
示例7: GetGroups
void GetGroups(const CSentence& Sentence, const CAgramtab& A, string& Res)
{
int nClausesCount = Sentence.GetClausesCount();
for (int ClauseNo = 0; ClauseNo<nClausesCount; ClauseNo++)
{
const CClause& Clause = Sentence.GetClause(ClauseNo);
int nCvar = Clause.m_SynVariants.size();
if (Clause.m_SynVariants.empty()) continue;
int nVmax = Clause.m_SynVariants.begin()->m_iWeight;
for (CSVI pSynVar = Clause.m_SynVariants.begin(); pSynVar != Clause.m_SynVariants.end(); pSynVar++)
{
if (pSynVar->m_iWeight < nVmax) break;
const CMorphVariant& V = *pSynVar;
Res += Format("\t<synvar>\n");
// print the clause
{
int ClauseType = (V.m_ClauseTypeNo == -1) ? UnknownSyntaxElement : Clause.m_vectorTypes[V.m_ClauseTypeNo].m_Type;;
string Type;
if (ClauseType != UnknownSyntaxElement)
Type = (const char*)A.GetClauseNameByType(ClauseType);
else
Type = "EMPTY";
Res += Format("\t\t<clause type=\"%s\">%s</clause>\n", Type.c_str(), GetWords(Sentence, Clause).c_str());
}
for (int GroupNo = 0; GroupNo < V.m_vectorGroups.GetGroups().size(); GroupNo++)
{
const CGroup& G = V.m_vectorGroups.GetGroups()[GroupNo];
Res += Format("\t\t<group type=\"%s\">%s</group>\n",
Sentence.GetOpt()->GetGroupNameByIndex(G.m_GroupType),
GetWords(Sentence, G).c_str());
};
Res += Format("\t</synvar>\n");
}
}
}
示例8: StoreValveDataChunk
//-----------------------------------------------------------------------------
// Purpose:
// Input : store -
//-----------------------------------------------------------------------------
void CSoundCombiner::StoreValveDataChunk( CSentence& sentence )
{
// Buffer and dump data
CUtlBuffer buf( 0, 0, CUtlBuffer::TEXT_BUFFER );
sentence.SaveToBuffer( buf );
// Copy into store
m_pOutIterator->ChunkWriteData( buf.Base(), buf.TellPut() );
}
示例9: ParseSentence
//-----------------------------------------------------------------------------
// Purpose:
// Input : &walk -
//-----------------------------------------------------------------------------
void CSoundCombiner::ParseSentence( CSentence& sentence, IterateRIFF &walk )
{
CUtlBuffer buf( 0, 0, CUtlBuffer::TEXT_BUFFER );
buf.EnsureCapacity( walk.ChunkSize() );
walk.ChunkRead( buf.Base() );
buf.SeekPut( CUtlBuffer::SEEK_HEAD, walk.ChunkSize() );
sentence.InitFromDataChunk( buf.Base(), buf.TellPut() );
}
示例10: GetRelations
void GetRelations(const CSentence& Sentence, string& Result)
{
CRelationsIterator RelIt;
RelIt.SetSentence(&Sentence);
for (int i = 0; i<Sentence.m_vectorPrClauseNo.size(); i++)
RelIt.AddClauseNoAndVariantNo(Sentence.m_vectorPrClauseNo[i], 0);
RelIt.BuildRelations();
for (long RelNo = 0; RelNo < RelIt.GetRelations().size(); RelNo++)
{
const CSynOutputRelation& piRel = RelIt.GetRelations()[RelNo];
string RelName = Sentence.GetOpt()->GetGroupNameByIndex(piRel.m_Relation.type);
string Src = GetNodeStr(Sentence, RelIt, piRel.m_iSourceGroup, piRel.m_Relation.m_iFirstWord);
string Trg = GetNodeStr(Sentence, RelIt, piRel.m_iTargetGroup, piRel.m_Relation.m_iLastWord);
string SrcLemma, TrgLemma;
string SrcGrm = GetNodeGrmStr(Sentence, RelIt, piRel.m_iSourceGroup, piRel.m_Relation.m_iFirstWord, SrcLemma);
string TrgGrm = GetNodeGrmStr(Sentence, RelIt, piRel.m_iTargetGroup, piRel.m_Relation.m_iLastWord, TrgLemma);
string GramRel = Sentence.GetOpt()->GetGramTab()->GrammemsToStr(piRel.m_Relation.m_iGrammems);
Result += Format("\t<rel name=\"%s\" gramrel=\"%s\" lemmprnt=\"%s\" grmprnt=\"%s\" lemmchld=\"%s\" grmchld=\"%s\" > %s -> %s </rel>\n",
RelName.c_str(), GramRel.c_str(), SrcLemma.c_str(), SrcGrm.c_str(), TrgLemma.c_str(), TrgGrm.c_str(), Src.c_str(), Trg.c_str());
}
}
示例11: LogPhonemes
//-----------------------------------------------------------------------------
// Purpose:
// Input : *phonemes -
//-----------------------------------------------------------------------------
void LogPhonemes( CSentence& sentence )
{
return;
Log( "Phonemecount == %i\n", sentence.CountPhonemes() );
for ( int i = 0; i < sentence.m_Words.Size(); i++ )
{
const CWordTag *w = sentence.m_Words[ i ];
for ( int j = 0; j < w->m_Phonemes.Size(); j++ )
{
const CPhonemeTag *p = w->m_Phonemes[ j ];
Log( "Phoneme %s %u to %u\n", p->GetTag(), p->m_uiStartByte, p->m_uiEndByte );
}
}
}
示例12: printf
bool CSentencesCollection::ReadAndProcessSentences(const CPlmLineCollection* piPlmLine)
{
const size_t LinesCount = piPlmLine->m_Items.size();
if( !m_pSyntaxOptions->IsValid())
return false;
if (m_bEnableProgressBar)
printf ("Starting Syntax\n");
time_t t1;
time (&t1);
for (size_t LineNo = 0; LineNo < LinesCount; )
{
if (m_bEnableProgressBar)
printf ("%i of %i \r", LineNo, LinesCount);
CSentence* S = m_pSyntaxOptions->NewSentence();
if (!S)
{
m_pSyntaxOptions->OutputErrorString("Cannot allocate space for the new sentence!");
return false;
};
try
{
S->m_pSyntaxOptions = m_pSyntaxOptions;
bool bResult = S->ReadNextFromPlmLines(piPlmLine,LineNo);
if (m_bLogProcessedSentence)
{
FILE * fp = fopen ("last_read_sentence.log", "w");
fprintf (fp, "%s\n",S->GetSentenceBeginStr().c_str());
fclose(fp);
};
if( !bResult )
{
// a parse error occurs
delete S;
return false;
};
}
catch (...)
{
m_pSyntaxOptions->OutputErrorString("Cannot read a sentence from Mapost");
delete S;
return false;
};
if( S->m_Words.empty() )
{
// no not-empty sentence can be found, we are at the end of the text
delete S;
break;
}
try
{
bool bRes = S->BuildClauses();
if( !bRes )
{
delete S;
return false;
};
S->CalculatePrimitiveClausesCount();
if (m_bEnableProgressBar)
{
if (S->m_bPanicMode)
printf (" found a \"panic\" sentence\n");
};
m_vectorSents.push_back(S);
}
catch (...)
{
if (m_bEnableProgressBar)
{
printf ("\n");
if (!S->m_Words.empty())
printf ("exception at offset %i\n", S->m_Words[0].m_GraphematicalUnitOffset);
};
delete S;
m_pSyntaxOptions->OutputErrorString("An exception in Synan occurred!");
return false;
};
//.........这里部分代码省略.........
示例13: ExtractPhonemes
//-----------------------------------------------------------------------------
// Purpose: Given a wave file and a string of words "text", creates a CFG from the
// sentence and stores the resulting words/phonemes in CSentence
// Input : *wavname -
// text -
// sentence -
// (*pfnPrint -
// Output : SR_RESULT
//-----------------------------------------------------------------------------
SR_RESULT ExtractPhonemes( const char *wavname, CSpDynamicString& text, CSentence& sentence, void (*pfnPrint)( const char *fmt, ...) )
{
// Assume failure
SR_RESULT result = SR_RESULT_ERROR;
if ( text.Length() <= 0 )
{
pfnPrint( "Error: no rule / text specified\n" );
return result;
}
USES_CONVERSION;
HRESULT hr;
CUtlVector < WORDRULETYPE > wordRules;
CComPtr<ISpStream> cpInputStream;
CComPtr<ISpRecognizer> cpRecognizer;
CComPtr<ISpRecoContext> cpRecoContext;
CComPtr<ISpRecoGrammar> cpRecoGrammar;
CComPtr<ISpPhoneConverter> cpPhoneConv;
// Create basic SAPI stream object
// NOTE: The helper SpBindToFile can be used to perform the following operations
hr = cpInputStream.CoCreateInstance(CLSID_SpStream);
if ( FAILED( hr ) )
{
pfnPrint( "Error: SAPI 5.1 Stream object not installed?\n" );
return result;
}
CSpStreamFormat sInputFormat;
// setup stream object with wav file MY_WAVE_AUDIO_FILENAME
// for read-only access, since it will only be access by the SR engine
hr = cpInputStream->BindToFile(
T2W(wavname),
SPFM_OPEN_READONLY,
NULL,
sInputFormat.WaveFormatExPtr(),
SPFEI_ALL_EVENTS );
if ( FAILED( hr ) )
{
pfnPrint( "Error: couldn't open wav file %s\n", wavname );
return result;
}
// Create in-process speech recognition engine
hr = cpRecognizer.CoCreateInstance(CLSID_SpInprocRecognizer);
if ( FAILED( hr ) )
{
pfnPrint( "Error: SAPI 5.1 In process recognizer object not installed?\n" );
return result;
}
// Create recognition context to receive events
hr = cpRecognizer->CreateRecoContext(&cpRecoContext);
if ( FAILED( hr ) )
{
pfnPrint( "Error: SAPI 5.1 Unable to create recognizer context\n" );
return result;
}
// Create a grammar
hr = cpRecoContext->CreateGrammar( EP_GRAM_ID, &cpRecoGrammar );
if ( FAILED( hr ) )
{
pfnPrint( "Error: SAPI 5.1 Unable to create recognizer grammar\n" );
return result;
}
LANGID englishID = 0x409; // 1033 decimal
bool userSpecified = false;
LANGID langID = SpGetUserDefaultUILanguage();
// Allow commandline override
if ( CommandLine()->FindParm( "-languageid" ) != 0 )
{
userSpecified = true;
langID = CommandLine()->ParmValue( "-languageid", langID );
}
// Create a phoneme converter ( so we can convert to IPA codes )
hr = SpCreatePhoneConverter( langID, NULL, NULL, &cpPhoneConv );
if ( FAILED( hr ) )
{
if ( langID != englishID )
{
if ( userSpecified )
//.........这里部分代码省略.........
示例14: EnumeratePhonemes
//-----------------------------------------------------------------------------
// Purpose: Walk list of words and phonemes and create phoneme tags in CSentence object
// FIXME: Right now, phonemes are assumed to evenly space out across a word.
// Input : *converter -
// result -
// sentence -
//-----------------------------------------------------------------------------
void EnumeratePhonemes( ISpPhoneConverter *converter, const ISpRecoResult* result, CSentence& sentence )
{
USES_CONVERSION;
// Grab access to element container
ISpPhrase *phrase = ( ISpPhrase * )result;
if ( !phrase )
return;
SPPHRASE *pElements;
if ( !SUCCEEDED( phrase->GetPhrase( &pElements ) ) )
return;
// Only use it if it's better/same size as what we already had on-hand
if ( pElements->Rule.ulCountOfElements > 0 )
//(unsigned int)( sentence.m_Words.Size() - sentence.GetWordBase() ) )
{
sentence.ResetToBase();
// Walk list of words
for ( ULONG i = 0; i < pElements->Rule.ulCountOfElements; i++ )
{
unsigned int wordstart, wordend;
// Get start/end sample index
wordstart = pElements->pElements[i].ulAudioStreamOffset + (unsigned int)pElements->ullAudioStreamPosition;
wordend = wordstart + pElements->pElements[i].ulAudioSizeBytes;
// Create word tag
CWordTag *w = new CWordTag( W2T( pElements->pElements[i].pszDisplayText ) );
Assert( w );
w->m_uiStartByte = wordstart;
w->m_uiEndByte = wordend;
sentence.AddWordTag( w );
// Count # of phonemes in this word
SPPHONEID pstr[ 2 ];
pstr[ 1 ] = 0;
WCHAR wszPhoneme[ SP_MAX_PRON_LENGTH ];
const SPPHONEID *current;
SPPHONEID phoneme;
current = pElements->pElements[i].pszPronunciation;
float total_weight = 0.0f;
while ( 1 )
{
phoneme = *current++;
if ( !phoneme )
break;
pstr[ 0 ] = phoneme;
wszPhoneme[ 0 ] = L'\0';
converter->IdToPhone( pstr, wszPhoneme );
total_weight += WeightForPhoneme( W2A( wszPhoneme ) );
}
current = pElements->pElements[i].pszPronunciation;
// Decide # of bytes/phoneme weight
float psize = 0;
if ( total_weight )
{
psize = ( wordend - wordstart ) / total_weight;
}
int number = 0;
// Re-walk the phoneme list and create true phoneme tags
float startWeight = 0.0f;
while ( 1 )
{
phoneme = *current++;
if ( !phoneme )
break;
pstr[ 0 ] = phoneme;
wszPhoneme[ 0 ] = L'\0';
converter->IdToPhone( pstr, wszPhoneme );
CPhonemeTag *p = new CPhonemeTag( W2A( wszPhoneme ) );
Assert( p );
float weight = WeightForPhoneme( W2A( wszPhoneme ) );
p->m_uiStartByte = wordstart + (int)( startWeight * psize );
p->m_uiEndByte = p->m_uiStartByte + (int)( psize * weight );
startWeight += weight;
//.........这里部分代码省略.........
示例15: max
int CSentence::CanLinkSimpleSimilar(int CommaWordNo)
{
try
{
/*
if comma is at the very beginning of ath the end, then exit
*/
if ( (CommaWordNo == 0)
|| (CommaWordNo + 1 >= m_Words.size() )
)
return -1;
if (GetOpt()->m_Language == morphGerman)
{
// we can use CSentence::m_GroupsUnion if Tomita is enabled
for (size_t i=0; i< m_GroupsUnion.GetGroups().size(); i++)
{
const CGroup& group = m_GroupsUnion.GetGroups()[i];
// ignore groups which contain only three words and the second word is
// a comma (a clause delimiter)
if (group.size() == 3)
if (m_Words[group.m_iFirstWord+1].m_bComma)
continue;
if ( (group.m_iFirstWord < CommaWordNo)
&& (group.m_iLastWord > CommaWordNo)
)
return group.m_iLastWord;
};
return -1;
};
const int Radius = (GetOpt()->m_Language == morphGerman)? 10 : 6;
int StartClauseWordNo = max(0, CommaWordNo - Radius);
CSentence* pSent = GetOpt()->NewSentence();
if (!pSent)
throw CExpc ("Cannot create sentence");
for (int i = StartClauseWordNo; i < min((int)m_Words.size(), CommaWordNo + Radius); i++)
pSent->m_Words.push_back(m_Words[i]);
CClause C(pSent, 0, pSent->m_Words.size() - 1);
pSent->AddClause(C);
pSent->m_bShouldUseTwoPotentialRule = false;
pSent->RunSyntaxInClauses(SimpleSimilarRules);
int Result = -1;
const CClause& prClause = pSent->m_Clauses[0];
for (CSVI it = prClause.m_SynVariants.begin(); (Result == -1)&& (it!=prClause.m_SynVariants.end()); it++)
for (size_t i=0; i< it->m_vectorGroups.GetGroups().size(); i++)
{
const CGroup& group = it->m_vectorGroups.GetGroups()[i];
// ignore groups which contain only three words and the second word is
// a comma (a clause delimiter)
if (group.size() == 3)
{
const CSynUnit& U = it->m_SynUnits[group.m_iFirstWord+1];
if (pSent->m_Words[U.m_SentPeriod.m_iFirstWord].m_bComma)
continue;
};
if ( (group.m_iFirstWord+StartClauseWordNo < CommaWordNo)
&& (group.m_iLastWord+StartClauseWordNo > CommaWordNo)
)
{
Result = group.m_iLastWord + StartClauseWordNo;
break;
};
}
delete pSent;
return Result;
}
catch(...)
{
OutputErrorString("Failed RunSyntaxInClause(CanLinkSimpleSimilar)");
return -1;
}
}