Пример #1
0
/*
  Counts the significant words per line in the given search file
*/
void countSigWords(const std::string searchFile,
                   const std::set<tfidfPair> result) {
    std::ifstream search(searchFile);
    std::string line, currWord;
    int lineNumber = 1;  // start at one, because logic
    // get line by line
    while (std::getline(search, line)) {
        std::istringstream ss(line);
        // store into set because dups ain't no thang
        std::set<std::string> wordSet;
        std::set<tfidfPair>tempSet(result);
        // store cleaned versions of words into set
        while (ss >> currWord != NULL) {
            wordSet.insert(currWord);
        }
        std::transform(line.begin(), line.end(), line.begin(), ::tolower);
        // get the count for the words in result that are also in wordset
        int c = 0;
        for (std::string resWord : wordSet) {
            c += countForWord(resWord, tempSet);
        }        
        if (c > 1) { 
            std::cout << lineNumber << "[" << c << "]: " << line
                      << std::endl;
        }
        lineNumber++;
    }
}
Пример #2
0
void CDialogSystem::Serialize(TSerialize ser)
{
	m_dialogQueueManager.Serialize(ser);

	if (ser.IsWriting())
	{
		// All Sessions
		uint32 count = m_allSessions.size();
		ser.Value("sessionCount", count);
		for (TDialogSessionMap::const_iterator iter = m_allSessions.begin(); iter != m_allSessions.end(); ++iter)
		{
			CDialogSession* pSession = iter->second;
			ser.BeginGroup("Session");
			int sessionID = pSession->GetSessionID();
			ser.Value("id", sessionID);
			ser.Value("script", pSession->GetScript()->GetID());
			pSession->Serialize(ser);
			ser.EndGroup();
		}

		// Active Sessions: We store the SessionID of active session. They will get restored on Load
		std::vector<int> temp;
		temp.reserve(m_activeSessions.size());
		for (TDialogSessionVec::const_iterator iter = m_activeSessions.begin(); iter != m_activeSessions.end(); ++iter)
		{
			temp.push_back((*iter)->GetSessionID());
		}
		ser.Value("m_activeSessions", temp);

		// next session id
		ser.Value("m_nextSessionID", m_nextSessionID);
	}
	else
	{
		// Delete/Clean all sessions
		ReleaseSessions();

		// Serialize All Sessions
		uint32 sessionCount = 0;
		ser.Value("sessionCount", sessionCount);
		for (int i=0; i<sessionCount; ++i)
		{
			ser.BeginGroup("Session");
			int id = 0;
			string scriptID;
			ser.Value("id", id);
			ser.Value("script", scriptID);
			CDialogSession* pSession = InternalCreateSession(scriptID, id);
			if (pSession)
			{
				pSession->Serialize(ser);
			}
			ser.EndGroup();
		}

		// Active sessions restore
		// Make sure that ID's are unique in there
		std::vector<int> temp;
		ser.Value("m_activeSessions", temp);
		std::set<int> tempSet (temp.begin(), temp.end()); 
		// good when temp.size() is rather large, otherwise push_back_unique would be better
		assert (tempSet.size() == temp.size());
		if (tempSet.size() != temp.size())
		{
			GameWarning("[DIALOG] CDialogSystem::Serialize: Active Sessions are not unique!");
		}

		// Store IDs of Session to be restored. They get restored on 1st Update call
		m_restoreSessions.insert (m_restoreSessions.end(), tempSet.begin(), tempSet.end());
		
		// next session id: in case we couldn't recreate a session (script invalid)
		// the m_nextSessionID should be taken from file
		int nextSessionID = m_nextSessionID;
		ser.Value("m_nextSessionID", nextSessionID);
		assert (nextSessionID >= m_nextSessionID);
		m_nextSessionID = nextSessionID;
	}
}
Пример #3
0
//Eliminates duplicates from the global vars
void eliminateDuplicates(strvec& vecRef)
{
	std::set<std::string> tempSet(vecRef.begin(), vecRef.end()); //sets only allow unique elements! just stuff the whole vector in, then:
	vecRef.clear();
	vecRef.assign(tempSet.begin(), tempSet.end());
}