//This function returns current running PID int CurrentPID() { long currentContext = CurrentContext(); struct Process_Control_Block *PCB = findPCBbyContextID(currentContext); if (PCB != NULL) { return PCB->ProcessID; } else { return -1; } }
std::vector< std::vector< int > > NHPYLM::Generate(std::string Mode, int NumWordsOrCharacters, int SentEndWordId, std::vector<double> *GeneratedWordLengthDistribution_) const { if (Mode == "CHPYLM") { /* build vector of character ids */ std::vector<int> CharacterIds(CharactersEnd - CharactersBegin, 0); std::iota(CharacterIds.begin(), CharacterIds.end(), CharactersBegin); CharacterIds.push_back(EOW); CharacterIds.push_back(EOS); CharacterIds.push_back(PHI); /* initialize base probabilities */ std::vector<double> BaseProbabilites; BaseProbabilites.reserve(CharacterIds.size()); for (std::vector<int>::iterator Character = CharacterIds.begin(); Character != CharacterIds.end(); ++Character) { if (*Character != PHI) { BaseProbabilites.push_back(CHPYLMBaseProbabilities.find(*Character)->second); } else { BaseProbabilites.push_back(0); } } /* sample the sentences */ int WordLength = 0; int NumWords = 0; double MeanWordLength = 0; std::vector<double> GeneratedWordLengthDistribution; std::vector<double> *WordLengthsProbabilities; if (GeneratedWordLengthDistribution_) { WordLengthsProbabilities = GeneratedWordLengthDistribution_; WordLengthsProbabilities->clear(); } else { WordLengthsProbabilities = &GeneratedWordLengthDistribution; } std::vector<int> CurrentContext(CHPYLMOrder - 1, EOW); std::vector<int> GeneratedSentence; std::vector<std::vector<int> > GeneratedSentences; while (NumWords < NumWordsOrCharacters) { GeneratedSentence.push_back(CHPYLM.GenerateWord(CurrentContext, CharacterIds, BaseProbabilites, true)); WordLength++; if ((CHPYLMOrder > 1) && (GeneratedSentence.back() != EOW) && (GeneratedSentence.back() != EOS)) { CurrentContext.erase(CurrentContext.begin()); CurrentContext.push_back(GeneratedSentence.back()); } else { if (GeneratedSentence.back() == EOW) { NumWords++; MeanWordLength += WordLength; WordLengthsProbabilities->resize(std::max(static_cast<size_t>(WordLength + 1), WordLengthsProbabilities->size()), 0); WordLengthsProbabilities->at(WordLength)++; WordLength = 0; } if (GeneratedSentence.back() == EOS) { GeneratedSentence.push_back(EOW); GeneratedSentences.push_back(GeneratedSentence); GeneratedSentence.clear(); } CurrentContext.assign(CHPYLMOrder - 1, EOW); } } for (unsigned int WordLength = 0; WordLength < WordLengthsProbabilities->size(); WordLength++) { WordLengthsProbabilities->at(WordLength) /= NumWords; // std::cout << std::setprecision(4) << std::fixed << "Word length: " << WordLength << ", word length probability: " << WordLengthsProbabilities->at(WordLength) << std::endl; } MeanWordLength /= NumWords; std::cout << " Mean length of generated words by CHPYLM: " << MeanWordLength << ", number of words: " << NumWords << std::endl << std::endl; return GeneratedSentences; } else if (Mode == "WHPYLM") { /* build vector of word ids */ std::vector<int> WordIds; WordIds.reserve(GetId2Word().size()); for (Id2WordHashmap::const_iterator Id2Word = GetId2Word().begin(); Id2Word != GetId2Word().end(); ++Id2Word) { WordIds.push_back(Id2Word->first); } WordIds.push_back(PHI); /* initialize base probabilities */ std::vector<double> BaseProbabilites; BaseProbabilites.reserve(WordIds.size()); for (std::vector<int>::iterator Word = WordIds.begin(); Word != WordIds.end(); ++Word) { if (*Word != PHI) { BaseProbabilites.push_back(exp(CHPYLM.WordSequenceLoglikelihood(GetWordVector(*Word), CHPYLMBaseProbabilities))); } else { BaseProbabilites.push_back(0); } } /* sample the sentences */ std::vector<int> CurrentContext(WHPYLMOrder - 1, SentEndWordId); std::vector<int> GeneratedSentence; std::vector<std::vector<int> > GeneratedSentences; for (int NumWords = 0; NumWords < NumWordsOrCharacters; NumWords++) { GeneratedSentence.push_back(WHPYLM.GenerateWord(CurrentContext, WordIds, BaseProbabilites, false)); if ((WHPYLMOrder > 1) && (GeneratedSentence.back() != SentEndWordId)) { CurrentContext.erase(CurrentContext.begin()); CurrentContext.push_back(GeneratedSentence.back()); } else { if (GeneratedSentence.back() == SentEndWordId) { CurrentContext.assign(WHPYLMOrder - 1, SentEndWordId); GeneratedSentences.push_back(GeneratedSentence); GeneratedSentence.clear(); } } } return GeneratedSentences; } else { return std::vector<std::vector<int> >(); } }
//This function returns current running PCB struct Process_Control_Block *CurrentPCB() { long currentContext = CurrentContext(); struct Process_Control_Block *PCB = findPCBbyContextID(currentContext); return PCB; }
void LMSetMemErr(SInt16 value) { CurrentContext()->globals.LM_memErr = value; }
SInt16 LMGetMemErr(void) { return CurrentContext()->globals.LM_memErr; }
static inline MemoryManagerPrivate *_MemGetPrivate(void) { return CurrentContext()->memoryMgrPrivate; }