本文整理汇总了C++中Sentence类的典型用法代码示例。如果您正苦于以下问题:C++ Sentence类的具体用法?C++ Sentence怎么用?C++ Sentence使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Sentence类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: clear
bool Lattice::assign(utils::piece::const_iterator& iter, utils::piece::const_iterator end)
{
namespace qi = boost::spirit::qi;
namespace standard = boost::spirit::standard;
clear();
// empty lattice...
if (iter == end) return true;
utils::piece::const_iterator iter_back = iter;
if (qi::phrase_parse(iter, end, lattice_grammar_parser_impl::instance(), standard::space, lattice)) {
initialize_distance();
return true;
} else {
clear();
// fallback to sentence...
iter = iter_back;
Sentence sentence;
if (sentence.assign(iter, end)) {
Sentence::const_iterator iter_end = sentence.end();
for (Sentence::const_iterator iter = sentence.begin(); iter != iter_end; ++ iter)
lattice.push_back(arc_set_type(1, arc_type(*iter)));
return true;
} else {
clear();
return false;
}
}
}
示例2: isPELCNFLiteral
bool isPELCNFLiteral(const Sentence& sentence) {
if (sentence.getTypeCode() == Atom::TypeCode
|| sentence.getTypeCode() == BoolLit::TypeCode
|| sentence.getTypeCode() == LiquidOp::TypeCode) {
return true;
}
if (sentence.getTypeCode() == Negation::TypeCode) {
const Negation& neg = static_cast<const Negation&>(sentence);
// TODO: necessary to check for double negation?
if (neg.sentence()->getTypeCode() == Negation::TypeCode) return false;
return isPELCNFLiteral(*neg.sentence());
}
if (sentence.getTypeCode() == DiamondOp::TypeCode) {
const DiamondOp& dia = static_cast<const DiamondOp&>(sentence);
if ( dia.sentence()->getTypeCode() == Atom::TypeCode
|| dia.sentence()->getTypeCode() == BoolLit::TypeCode
|| dia.sentence()->getTypeCode() == LiquidOp::TypeCode) { // TODO add liquidop
return true;
}
return false;
}
if (sentence.getTypeCode() == Conjunction::TypeCode) {
const Conjunction& con = static_cast<const Conjunction&>(sentence);
if ((con.left()->getTypeCode() == Atom::TypeCode
|| con.left()->getTypeCode() == BoolLit::TypeCode)
&& (con.right()->getTypeCode() == Atom::TypeCode
|| con.right()->getTypeCode() == BoolLit::TypeCode)) {
return true;
}
return false;
}
return false;
}
示例3: kahnsOrDragons
IChoiceTag* IChoiceTag::Create(Sentence& sentence)
{
static Sentence kahnsOrDragons("As THIS enters the battlefield, choose Khans or Dragons.");
static Sentence opponentChoose("An opponent chooses one " HYPEN);
if (kahnsOrDragons.IsEqualTo(sentence))
{
sentence.Clear();
return new KahnsOrDragons;
}
if (opponentChoose.IsEqualTo(sentence))
{
sentence.Clear();
return new OpponentChoose;
}
auto first = sentence.Find(
[](IObjectTag* tag) -> bool { return tag->GetType() == ObjectType::Choose; });
if (first.found)
{
auto second = sentence.Find(
[](IObjectTag* tag) -> bool { return tag->GetType() == ObjectType::BigSeperator; },
first.iterator);
if (second.found)
{
return new ChoiceBegin(sentence.Splice(second.iterator));
}
}
return nullptr;
}
示例4: askOr
bool KnowLedgeBasedAgent::askOr(string query, vector<string>& theta)
{
Predicate p = TextParser::GetPredicate(query);
if (predicateMap.find(p.name) != predicateMap.end())
{
vector<int>rules = predicateMap[p.name];
bool flag = false;
for (int ruleIterator = 0; ruleIterator < rules.size(); ruleIterator++)
{
Sentence sentence = KnowledgeBase[rules[ruleIterator]-1];
vector<string> premise = sentence.GetPremise();
string conclusion = sentence.GetConclusion();
Predicate q = TextParser::GetPredicate(conclusion);
string substitution = "";
bool unificationResult = Unify(p, q, substitution);
if (!unificationResult) continue;
if (find(theta.begin(), theta.end(), substitution) == theta.end())
{
theta.push_back(*new string(substitution));
}
bool validity = askAnd(premise, theta);
if (validity) flag = true;
else flag = false;
}
if(flag) return true;
else return false;
}
else return false;
}
示例5: MakePerceptSentence
void KnowLedgeBasedAgent::Tell(string percept)
{
t = t+1;
Sentence sentence = MakePerceptSentence(percept);
KnowledgeBase.push_back(sentence);
Predicate conclusion = TextParser::GetPredicate(sentence.GetConclusion());
if (predicateMap.find(conclusion.name) == predicateMap.end())
{
vector<int> conclusionId;
conclusionId.push_back(t);
predicateMap[conclusion.name] = conclusionId;
if (conclusion.arg1[0] != 'x' && find(constants.begin(), constants.end(), conclusion.arg1) == constants.end())
constants.push_back(conclusion.arg1);
if (conclusion.arg2[0] != 'x' && find(constants.begin(), constants.end(), conclusion.arg2) == constants.end())
constants.push_back(conclusion.arg2);
}
else
{
(predicateMap[conclusion.name]).push_back(t);
if (conclusion.arg1[0] != 'x' && find(constants.begin(), constants.end(), conclusion.arg1) == constants.end())
constants.push_back(conclusion.arg1);
if (conclusion.arg2[0] != 'x' && find(constants.begin(), constants.end(), conclusion.arg2) == constants.end())
constants.push_back(conclusion.arg2);
}
vector<string> premises = sentence.GetPremise();
for (int i=0; i<premises.size(); i++)
{
Predicate premise = TextParser::GetPredicate(premises[i]);
if (premise.arg1[0] != 'x' && find(constants.begin(), constants.end(), premise.arg1) == constants.end())
constants.push_back(premise.arg1);
if (premise.arg2[0] != 'x' && find(constants.begin(), constants.end(), premise.arg2) == constants.end())
constants.push_back(premise.arg2);
}
}
示例6: readWordFile
void readWordFile(string filePath)
{
ifstream in(filePath.c_str());
int sentenceId, wordNo, wordId;
SentenceLine sentenceline;
int lastSentenceId = 1;
while (in>>sentenceId>>wordNo>>wordId)
{
if (sentenceId!=lastSentenceId&&sentenceId>1)
{
Sentence s;
s.ReadLine(sentenceline);
if (sentenceId-lastSentenceId>1) // some files the sentenceId is not continous, treat it as zero length sentence
{
for (int i=0; i<sentenceId-lastSentenceId-1; i++)
{
Sentence tmp;
AppendSentence(tmp);
}
}
AppendSentence(s); //note that byte is zero, need to correct and Combine Step
sentenceline.clear();
lastSentenceId= sentenceId;
}
sentenceline.push_back(wordId);
}
Sentence s;
s.ReadLine(sentenceline);
AppendSentence(s);
in.close();
}
示例7: decltype
long DataManager::readPOSFile(const char* filePath, const std::function<void (Sentence*)> placementFunction)
{
Sentence *sentence = nullptr;
long counter = 0;
decltype(readLine()) line = nullptr;
if (openFile(filePath, true)) {
while ((line = readLine()) != nullptr) {
if (strlen(line) == 0) {
if (sentence) {
placementFunction(sentence);
sentence = nullptr;
}
continue;
}
auto indexOfTab = line;
for (; *indexOfTab != '\0'; indexOfTab++) {
if (*indexOfTab == '\t') {
*(indexOfTab++) = '\0';
break;
}
}
if (!sentence)
sentence = new Sentence();
sentence->addWord(line, indexOfTab);
}
}
return counter;
}
示例8: parse
void Run::parse(const std::string &sInputFile, const std::string &sOutputFile,
const std::string &sFeatureFile) const {
Sentence sentence;
DependencyTree tree;
std::cout << "Parsing started" << std::endl;
auto time_begin = time(NULL);
std::unique_ptr<DepParser> parser(new DepParser(sFeatureFile, sFeatureFile, ParserState::PARSE));
std::ifstream input(sInputFile);
std::ofstream output(sOutputFile);
if (input) {
while (input >> sentence) {
if (sentence.size() < MAX_SENTENCE_SIZE) {
parser->parse(sentence, &tree);
output << tree;
tree.clear();
}
}
}
input.close();
output.close();
auto time_end = time(NULL);
auto seconds = difftime(time_end, time_begin);
std::cout << "Parsing has finished successfully. Total time taken is: " << difftime(time_end, time_begin) <<
"s" << std::endl;
}
示例9: year_is_found
// "((this|next|last) year)|(\d\d\d\d)"
int year_is_found( Sentence& mSentence, struct tm* mFillin=NULL )
{
int retval=0;
retval = mSentence.is_found_in_sentence("this year");
if (retval)
{
if (mFillin) mFillin->tm_year = retval = bd_now.tm_year;
return retval;
} else if ((retval = mSentence.is_found_in_sentence("next year")))
{
if (mFillin) mFillin->tm_year = retval = bd_now.tm_year+1;
return retval;
} else if ((retval = mSentence.is_found_in_sentence("last year")))
{
if (mFillin) mFillin->tm_year = retval = bd_now.tm_year-1;
return retval;
}
/* Scan numbers 1900 to 2016 */
char year_ascii[4];
for (int year=1900; year<2100; year++) {
sprintf(year_ascii, "%d", year);
if (mSentence.is_found_in_sentence( year_ascii )) {
if (mFillin) mFillin->tm_year = year-1900;
return mSentence.get_word_index(year_ascii);
}
}
return retval;
}
示例10: doTranslate
// 인자로 주어진 파일로부터 한문장씩 읽어 이를 번역
void doTranslate(char* pInFile, Manual& out, int wantedLang)
{
ifstream ifs(pInFile);
if (!ifs)
{
cout << "Can't open file : " << pInFile << endl;
return;
}
string result;
Sentence next;
while (!(next = getSentence(ifs)).getString().empty())
{
switch (next.getType())
{
case NORMAL_SENTENCE: // 평서문
result = TransNormalSentence(next.getString(), wantedLang);
break;
case INTERROGATIVE_SENTENCE: // 의문문
result = TransInterrogativeSentence(next.getString(), wantedLang);
break;
case IMPERATIVE_SENTENCE: // 명령문
result = TransImperativeSentence(next.getString(), wantedLang);
break;
default:
cout << "Untranslatable sentence type" << endl;
return;
}
out.addContents(result);
}
}
示例11: CreateConstantExpression
VbCodeExpressionPtr VbCodeExpressionFactory::CreateConstantExpression(const Sentence& sentence)
{
if (sentence.GetNodes().size() != 1)
throw std::runtime_error("Literal should contain exactly 1 token.");
auto& value = VbCodeValueFactory::Create(sentence.GetNodes()[0]->AsToken());
return std::make_shared<VbCodeConstantExpression>(value);
}
示例12: range
/** constructor; just initialize the base class */
TranslationOptionCollectionText::TranslationOptionCollectionText(Sentence const &input, size_t maxNoTransOptPerCoverage, float translationOptionThreshold)
: TranslationOptionCollection(input, maxNoTransOptPerCoverage, translationOptionThreshold)
{
size_t size = input.GetSize();
m_inputPathMatrix.resize(size);
for (size_t phaseSize = 1; phaseSize <= size; ++phaseSize) {
for (size_t startPos = 0; startPos < size - phaseSize + 1; ++startPos) {
size_t endPos = startPos + phaseSize -1;
vector<InputPath*> &vec = m_inputPathMatrix[startPos];
WordsRange range(startPos, endPos);
Phrase subphrase(input.GetSubString(WordsRange(startPos, endPos)));
const NonTerminalSet &labels = input.GetLabelSet(startPos, endPos);
InputPath *node;
if (range.GetNumWordsCovered() == 1) {
node = new InputPath(subphrase, labels, range, NULL, NULL);
vec.push_back(node);
} else {
const InputPath &prevNode = GetInputPath(startPos, endPos - 1);
node = new InputPath(subphrase, labels, range, &prevNode, NULL);
vec.push_back(node);
}
m_phraseDictionaryQueue.push_back(node);
}
}
}
示例13: makeNGram
// make N-gram
Sentence makeNGram(const Sentence& sent, Position begin, unsigned int n)
{
Sentence ret;
auto it1 = sent.begin() + begin;
auto it2 = it1 + n;
ret.insert(ret.end(), it1, it2);
return move(ret);
}
示例14: PrintSentence
void ParallelCorpus::PrintSentence(
const Sentence& sentence, const Vocab& vocab, std::ostream& out) const {
if (sentence.size() > 0) {
out << vocab.GetWord(sentence.at(0));
}
for (int i = 1; i < sentence.size(); ++i) {
out << " " << vocab.GetWord(sentence.at(i));
}
}
示例15: putSentence
// render a sentence in words
void putSentence(const Wordlist& wlist, const Sentence sent)
{
for (Sentence::const_iterator i = sent.begin() ; i != sent.end() ; ++i) {
if (*i != 0)
cout << wlist[*i-1] << " " ;
}
cout << endl ;
}