本文整理汇总了C++中Phrase::size方法的典型用法代码示例。如果您正苦于以下问题:C++ Phrase::size方法的具体用法?C++ Phrase::size怎么用?C++ Phrase::size使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Phrase
的用法示例。
在下文中一共展示了Phrase::size方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: LabelDeEn
void LabelDeEn(const Phrase &source, ostream &out)
{
Ranges ranges;
// find ranges to label
for (int start = 0; start < source.size(); ++start) {
for (int end = start; end < source.size(); ++end) {
if (IsA(source, start, -1, 1, "VAFIN")
&& IsA(source, end, +1, 1, "VVINF VVPP")
&& !Contains(source, start, end, 1, "VAFIN VVINF VVPP VVFIN")) {
Range range(start, end, "reorder-label");
ranges.push_back(range);
}
else if ((start == 0 || IsA(source, start, -1, 1, "$,"))
&& IsA(source, end, +1, 0, "zu")
&& IsA(source, end, +2, 1, "VVINF")
&& !Contains(source, start, end, 1, "$,")) {
Range range(start, end, "reorder-label");
ranges.push_back(range);
}
}
}
OutputWithLabels(source, ranges, out);
}
示例2: ComputeBleuStats
BleuStats ComputeBleuStats(const Phrase &hyp, const Phrase& ref)
{
const size_t refSize = ref.size();
NGramTree refTree;
for (size_t pos = 0; pos < refSize; ++pos)
{
BuildNGramTree(ref, refTree, pos, refSize, 0);
}
const size_t hypSize = hyp.size();
BleuStats lineStats(hypSize, 0);
NGramTree hypTree;
for (size_t pos = 0; pos < hypSize; ++pos)
{
BuildNGramTree(hyp, hypTree, pos, hypSize, 0);
}
CountNGrams(hypTree, refTree, 0, lineStats.m_counts);
// cout << "Ref: " << ref << endl;
// cout << "Hyp: " << hyp << endl;
// cout << "Stats: ";
// cout << lineStats.counts[0] << ", ";
// cout << lineStats.counts[1] << ", ";
// cout << lineStats.counts[2] << ", ";
// cout << lineStats.counts[3] << endl;
return lineStats;
}
示例3: XMLParse
void AlignedSentenceSyntax::XMLParse(Phrase &output,
SyntaxTree &tree,
const pugi::xml_node &parentNode,
const Parameter ¶ms)
{
int childNum = 0;
for (pugi::xml_node childNode = parentNode.first_child(); childNode; childNode = childNode.next_sibling()) {
string nodeName = childNode.name();
// span label
string label;
int startPos = output.size();
if (!nodeName.empty()) {
pugi::xml_attribute attribute = childNode.attribute("label");
label = attribute.as_string();
// recursively call this function. For proper recursive trees
XMLParse(output, tree, childNode, params);
}
// fill phrase vector
string text = childNode.value();
Escape(text);
//cerr << childNum << " " << label << "=" << text << endl;
std::vector<string> toks;
Moses::Tokenize(toks, text);
for (size_t i = 0; i < toks.size(); ++i) {
const string &tok = toks[i];
Word *word = new Word(output.size(), tok);
output.push_back(word);
}
// is it a labelled span?
int endPos = output.size() - 1;
// fill syntax labels
if (!label.empty()) {
label = "[" + label + "]";
tree.Add(startPos, endPos, label, params);
}
++childNum;
}
}
示例4: Found
size_t Found(const Phrase &source, int pos, int factor, const std::string &str)
{
const size_t MAX_RANGE = 10;
vector<string> soughts = Moses::Tokenize(str, " ");
vector<string> puncts = Moses::Tokenize(". : , ;", " ");
size_t maxEnd = std::min(source.size(), (size_t) pos + MAX_RANGE);
for (size_t i = pos + 1; i < maxEnd; ++i) {
const Word &word = source[i];
bool found;
found = Found(word, factor, puncts);
if (found) {
return std::numeric_limits<size_t>::max();
}
found = Found(word, factor, soughts);
if (found) {
return i;
}
}
return std::numeric_limits<size_t>::max();
}
示例5: PopulateWordVec
void AlignedSentence::PopulateWordVec(Phrase &vec, const std::string &line)
{
std::vector<string> toks;
Moses::Tokenize(toks, line);
vec.resize(toks.size());
for (size_t i = 0; i < vec.size(); ++i) {
const string &tok = toks[i];
Word *word = new Word(i, tok);
vec[i] = word;
}
}
示例6: distance
double IBMModelOne::distance( const Phrase& hu, const Phrase& en ) const
{
double val = log(1.0+hu.size()) / en.size() ;
double huRatio = 1.0 / hu.size();
for ( int enPos=0; enPos<en.size(); ++enPos )
{
double sum = 0;
const Word& enWord = en[enPos];
for ( int huPos=0; huPos<hu.size(); ++huPos )
{
sum += lookup( hu[huPos], enWord );
}
massert( sum>0 );
val -= log(sum);
}
throw "unimplemented";
}
示例7: phraseToXML
void ClientXMLDocument::phraseToXML(const Phrase & phrase)
{
int pint(0);
string pmode("");
if (cl("-inv").optionflag) {
outs << " <SENTENCE Type=\"" << phrase.back().second << "\" Inv=\"" << cl("-inv").optionarg << "\">" << endl;
}
else {
outs << " <SENTENCE Type=\"" << phrase.back().second << "\">" << endl;
}
for(unsigned i=0; i<phrase.size()-1; i++) {
if(phrase[i+1].first == TOKEN_PHRASE_DELIMITER) {
pint = 2;
switch (phrase[i+1].second[0]) {
case ':' : pmode="."; break;
default : pmode="?"; break;
}
}
if(phrase[i+1].first == TOKEN_SENTENCE_DELIMITER) {
pint = 5;
switch (phrase[i+1].second[0]) {
case '?' : pmode="?"; break;
default : pmode="."; break;
}
}
outs << " <WORD Orth=\"" << phrase[i].second << "\" PInt=\"" <<pint
<< "\" PMode=\"" << pmode << "\"></WORD>" << endl;
if(pint) {
pint = 0;
pmode="";
i++;
}
}
outs << " </SENTENCE>" << endl;
}
示例8: EnPhrasalVerb
void EnPhrasalVerb(const Phrase &source, int revision, ostream &out)
{
Ranges ranges;
// find ranges to label
for (int start = 0; start < source.size(); ++start) {
size_t end = std::numeric_limits<size_t>::max();
if (IsA(source, start, 0, 0, "ask asked asking")) {
end = Found(source, start, 0, "out");
}
else if (IsA(source, start, 0, 0, "back backed backing")) {
end = Found(source, start, 0, "up");
}
else if (IsA(source, start, 0, 0, "blow blown blew")) {
end = Found(source, start, 0, "up");
}
else if (IsA(source, start, 0, 0, "break broke broken")) {
end = Found(source, start, 0, "down up in");
}
else if (IsA(source, start, 0, 0, "bring brought bringing")) {
end = Found(source, start, 0, "down up in");
}
else if (IsA(source, start, 0, 0, "call called calling")) {
end = Found(source, start, 0, "back up off");
}
else if (IsA(source, start, 0, 0, "check checked checking")) {
end = Found(source, start, 0, "out in");
}
else if (IsA(source, start, 0, 0, "cheer cheered cheering")) {
end = Found(source, start, 0, "up");
}
else if (IsA(source, start, 0, 0, "clean cleaned cleaning")) {
end = Found(source, start, 0, "up");
}
else if (IsA(source, start, 0, 0, "cross crossed crossing")) {
end = Found(source, start, 0, "out");
}
else if (IsA(source, start, 0, 0, "cut cutting")) {
end = Found(source, start, 0, "down off out");
}
else if (IsA(source, start, 0, 0, "do did done")) {
end = Found(source, start, 0, "over up");
}
else if (IsA(source, start, 0, 0, "drop dropped dropping")) {
end = Found(source, start, 0, "off");
}
else if (IsA(source, start, 0, 0, "figure figured figuring")) {
end = Found(source, start, 0, "out");
}
else if (IsA(source, start, 0, 0, "fill filled filling")) {
end = Found(source, start, 0, "in out up");
}
else if (IsA(source, start, 0, 0, "find found finding")) {
end = Found(source, start, 0, "out");
}
else if (IsA(source, start, 0, 0, "get got getting gotten")) {
end = Found(source, start, 0, "across over back");
}
else if (IsA(source, start, 0, 0, "give given gave giving")) {
end = Found(source, start, 0, "away back out up");
}
else if (IsA(source, start, 0, 0, "hand handed handing")) {
end = Found(source, start, 0, "down in over");
}
else if (IsA(source, start, 0, 0, "hold held holding")) {
end = Found(source, start, 0, "back up");
}
else if (IsA(source, start, 0, 0, "keep kept keeping")) {
end = Found(source, start, 0, "from up");
}
else if (IsA(source, start, 0, 0, "let letting")) {
end = Found(source, start, 0, "down in");
}
else if (IsA(source, start, 0, 0, "look looked looking")) {
end = Found(source, start, 0, "over up");
}
else if (IsA(source, start, 0, 0, "make made making")) {
end = Found(source, start, 0, "up");
}
else if (IsA(source, start, 0, 0, "mix mixed mixing")) {
end = Found(source, start, 0, "up");
}
else if (IsA(source, start, 0, 0, "pass passed passing")) {
end = Found(source, start, 0, "out up");
}
else if (IsA(source, start, 0, 0, "pay payed paying")) {
end = Found(source, start, 0, "back");
}
else if (IsA(source, start, 0, 0, "pick picked picking")) {
end = Found(source, start, 0, "out");
}
else if (IsA(source, start, 0, 0, "point pointed pointing")) {
end = Found(source, start, 0, "out");
}
else if (IsA(source, start, 0, 0, "put putting")) {
end = Found(source, start, 0, "down off out together on");
}
else if (IsA(source, start, 0, 0, "send sending")) {
end = Found(source, start, 0, "back");
//.........这里部分代码省略.........
示例9: disectPhrase
void Demidify::disectPhrase(Song *song, size_t trackNo,
int prog_base, int max_prog_delta)
{
if ((*song)[trackNo]->size() == 0) return;
Phrase *phrase = (*(*song)[trackNo])[0]->phrase();
if (!phrase) return;
if (verbose >= 2)
{
out << " | +- Disecting Phrase '" << phrase->title()
<< "' which has "
<< phrase->size() << " events and is in Track " << trackNo
<< ".\n";
}
// STEP ZERO
// Remove program changes and other fun from the Phrase.
if (pullTrackParameters && phrase->size())
{
if (verbose >= 2) out << " | +- Pulling Track parameters.\n";
PhraseEdit pe;
pe.reset(phrase);
size_t pos = 0;
bool culled = false;
MidiEvent e;
do
{
if (pos < pe.size())
{
e = pe[pos];
switch (e.data.status)
{
case MidiCommand_ProgramChange:
(*song)[trackNo]->params()->setProgram(e.data.data1);
(*song)[trackNo]->filter()->setChannel(e.data.channel);
(*song)[trackNo]->filter()->setPort(e.data.port);
pe.erase(pos);
culled = true;
break;
case MidiCommand_ControlChange:
switch (e.data.data1)
{
case MidiControl_BankSelectMSB:
(*song)[trackNo]->params()->setBankMSB
(e.data.data2);
pe.erase(pos);
culled = true;
break;
case MidiControl_BankSelectLSB:
(*song)[trackNo]->params()->setBankLSB
(e.data.data2);
pe.erase(pos);
culled = true;
break;
case MidiControl_PanMSB:
(*song)[trackNo]->params()->setPan
(e.data.data2);
pe.erase(pos);
culled = true;
break;
case MidiControl_ReverbDepth:
(*song)[trackNo]->params()->setReverb
(e.data.data2);
pe.erase(pos);
culled = true;
break;
case MidiControl_ChorusDepth:
(*song)[trackNo]->params()->setChorus
(e.data.data2);
pe.erase(pos);
culled = true;
break;
default:
++pos;
}
break;
default:
++pos;
break;
}
}
}
while (pos < pe.size() && e.data.status != MidiCommand_NoteOn);
if (culled)
{
if (verbose >= 2)
out << " | | |\n"
<< " | | +- Culled some Track information\n";
Phrase *newPhrase = pe.createPhrase(song->phraseList());
replacePhrase(song, phrase, newPhrase);
phrase = newPhrase;
}
}
// STEP ONE:
// Remove the original MidiImport Part from the Track.
if (verbose >= 2) out << " | +- Removing original Part\n";
//.........这里部分代码省略.........