Beispiel #1
0
// make a search for the user's input
// inside the database of the program
void TechBot::selectMatch() 
{
    std::fstream outfile("keywords.txt", std::ios::out);
    RespLISTonse.clear();
    
    // introduce thse new "string variable" to help 
    // support the implementation of keyword ranking 
    // during the matching process
    std::string bestKeyWord;
    Vstr ListOfWord;
    
    
    if(TB_Input.find("**") == std::string::npos)
    {
        RightClear(TB_Input, ".");
        ToUpperCase(TB_Input);
        SplitToWords(TB_Input, ListOfWord);
        bestKeyWord = findBestKey(ListOfWord);
        TB_KeyWord = bestKeyWord;
    }
    else
    {
        TB_KeyWord = TB_Input;
    }
    bool found=false;
    
    for(mapString ::iterator it=KnowledgeBase.begin();it!=KnowledgeBase.end();it++)
    {
        std::string temp=it->first;
        if((std::string)temp==(std::string)TB_KeyWord)
          found=true;
         
    }
        if(!found)
         {

            for(mapString ::iterator it=KnowledgeBase.begin();it!=KnowledgeBase.end();it++)
            {
                std::string temp=it->first;
                if(temp.find(TB_Input)!=std::string::npos)
                    {
                        found=true;
                    }

                
            }

        }
        if(found)
            { std::string tt=TB_KeyWord;
                std::vector<TBResponse> RespLISTObj = KnowledgeBase[tt];
                RespListgetter(RespLISTObj);
            }
            
}
Beispiel #2
0
const CKeyMap::KeyItem*
CKeyMap::mapCharacterKey(Keystrokes& keys, KeyID id, SInt32 group,
				ModifierToKeys& activeModifiers,
				KeyModifierMask& currentState,
				KeyModifierMask desiredMask,
				bool isAutoRepeat) const
{
	// find KeySym in table
	KeyIDMap::const_iterator i = m_keyIDMap.find(id);
	if (i == m_keyIDMap.end()) {
		// unknown key
		LOG((CLOG_DEBUG1 "key %04x is not on keyboard", id));
		return NULL;
	}
	const KeyGroupTable& keyGroupTable = i->second;

	// find best key in any group, starting with the active group
	SInt32 keyIndex  = -1;
	SInt32 numGroups = getNumGroups();
	SInt32 groupOffset;
	LOG((CLOG_DEBUG1 "find best:  %04x %04x", currentState, desiredMask));
	for (groupOffset = 0; groupOffset < numGroups; ++groupOffset) {
		SInt32 effectiveGroup = getEffectiveGroup(group, groupOffset);
		keyIndex = findBestKey(keyGroupTable[effectiveGroup],
								currentState, desiredMask);
		if (keyIndex != -1) {
			LOG((CLOG_DEBUG1 "found key in group %d", effectiveGroup));
			break;
		}
	}
	if (keyIndex == -1) {
		// no mapping for this keysym
		LOG((CLOG_DEBUG1 "no mapping for key %04x", id));
		return NULL;
	}

	// get keys to press for key
	SInt32 effectiveGroup = getEffectiveGroup(group, groupOffset);
	const KeyItemList& itemList = keyGroupTable[effectiveGroup][keyIndex];
	if (itemList.empty()) {
		return NULL;
	}
	const KeyItem& keyItem = itemList.back();

	// make working copy of modifiers
	ModifierToKeys newModifiers = activeModifiers;
	KeyModifierMask newState    = currentState;
	SInt32 newGroup             = group;

	// add each key
	for (size_t j = 0; j < itemList.size(); ++j) {
		if (!keysForKeyItem(itemList[j], newGroup, newModifiers,
							newState, desiredMask,
							0, isAutoRepeat, keys)) {
			LOG((CLOG_DEBUG1 "can't map key"));
			keys.clear();
			return NULL;
		}
	}

	// add keystrokes to restore modifier keys
	if (!keysToRestoreModifiers(keyItem, group, newModifiers, newState,
								activeModifiers, keys)) {
		LOG((CLOG_DEBUG1 "failed to restore modifiers"));
		keys.clear();
		return NULL;
	}

	// add keystrokes to restore group
	if (newGroup != group) {
		keys.push_back(Keystroke(group, true, true));
	}

	// save new modifiers
	activeModifiers = newModifiers;
	currentState    = newState;

	return &keyItem;
}