Exemple #1
0
void Sentence::complete(const Dict& book){
int a =0;
int b=0;
int max;
max = book.getlength(3);
cout<<"Sentence completion for: "<<input<<"\n";
cout<<"--------------------------------"<<"\n";
while(a < max){
int counter = 1;
input2 = book.lookup(3, a);
for(int i=0; i < input.length()-1; i++){	//for loop that flags counter as zero if beginning is not the same
	if(input[i] != input2[i]){
		counter = 0;
		break;
	}
}
if(counter == 1){
	cout<<input2<<"\n";
	b++;
}
a++;
}

if(b == 0){
	cout<<"no completion found \n";
}

}
void ff::Dict::Merge(const Dict &rhs)
{
	for (StringRef name: rhs.GetAllNames())
	{
		Value *value = rhs.GetValue(name);
		ff::ValuePtr newValue;

		if (value->IsType(ff::Value::Type::Dict) ||
			value->IsType(ff::Value::Type::SavedDict))
		{
			Value *myValue = GetValue(name);
			if (myValue && (myValue->IsType(ff::Value::Type::Dict) ||
				myValue->IsType(ff::Value::Type::SavedDict)))
			{
				ff::ValuePtr dictValue, myDictValue;
				if (value->Convert(ff::Value::Type::Dict, &dictValue) &&
					myValue->Convert(ff::Value::Type::Dict, &myDictValue))
				{
					Dict myDict = myDictValue->AsDict();
					myDict.Merge(dictValue->AsDict());

					if (ff::Value::CreateDict(std::move(myDict), &newValue))
					{
						value = newValue;
					}
				}
			}
		}

		SetValue(name, value);
	}
}
//Conta o numero de palavras no arquivo
void count_words() {
    totalPalavras=0;
    int dictShortQtd=0;
    int dictCompoundQtd=0;

    char *pch = strtok (text, "\n");
    int length;
    
    for(int i=0; i<6; i++)
    	qtd_palavra[i] = 0;
                                                                       
    while(pch != NULL){
        length = strlen(pch);

        if(length <= 5) {
            qtd_palavra[length]++;
            dictShortQtd++;
        } else
            dictCompoundQtd++;
        totalPalavras++;

    	pch = strtok (NULL, "\n");                                    
    }

    shortDict.init(dictShortQtd, MAX_SHORT_SIZE);
    compoundDict.init(dictCompoundQtd, MAX_COMPOUND_SIZE);
}
Exemple #4
0
ImportInfo::ImportInfo( Dict & attrs ) : 
	attrs( attrs )
{
	Dict::iterator it = attrs.find( FROM );
	if ( it == attrs.end() ) {
		throw Mishap( "Missing attribute in import" ).culprit( "Attribute", FROM );
	}
	this->from = it->second;
	
	set< string > matches;
	set< string > intos;
	for (
		Dict::iterator it = attrs.begin();
		it != attrs.end();
		++it
	) {
		if ( it->first.compare( 0, MATCH_SIZE, MATCH ) == 0 ) {
			matches.insert( it->second );
		} else if ( it->first.compare( 0, INTO_SIZE, INTO ) == 0 ) {
			intos.insert( it->second );
		}
	}
	
	this->match_tags = fetchFacetSet( matches );
	this->into_tags = fetchFacetSet( intos );
}
Exemple #5
0
Dict* Track::player(Dict *d, bool fallback) const{
    Dict *p = d->AddIncludeDictionary("PLAYER");
    p->SetFilename("html/player.tpl");
    fill(p);
    p->SetIntValue("LIST", id);
    if(fallback) p->ShowSection("FALLBACK");
    return p;
}
Exemple #6
0
  Dict Options::sanitize(const Dict& opts) {
    // Drop nulls
    if (has_null(opts)) {
      // Create a new dictionary without the null entries
      Dict ret;
      for (auto&& op : opts) {
        if (!op.second.is_null()) ret[op.first] = op.second;
      }
      return ret;
    }

    //  Treat the case where any of the options have a dot (dictionary shorthand)
    if (has_dot(opts)) {
      // New options dictionary being constructed
      Dict ret;

      // Sub-dictionary and corresponding name being constructed
      Dict sopts;
      std::string sname;

      // Process options
      for (auto&& op : opts) {
        // Find the dot if any
        string::size_type dotpos = op.first.find('.'), dotpos_end;
        if (dotpos==string::npos) {
          dotpos = op.first.find("__");
          if (dotpos!=string::npos) dotpos_end = dotpos+2;
        } else {
          dotpos_end = dotpos+1;
        }

        // Flush last sub-dictionary
        if (!sname.empty() && (dotpos==string::npos
                               || op.first.compare(0, dotpos, sname)!=0)) {
          ret[sname] = sopts;
          sname.clear();
          sopts.clear();
        }

        // Add to dictionary
        if (dotpos != string::npos) {
          sname = op.first.substr(0, dotpos);
          sopts[op.first.substr(dotpos_end)] = op.second;
        } else {
          ret[op.first] = op.second;
        }
      }

      // Flush trailing sub-dictionary
      if (!sname.empty()) ret[sname] = sopts;

      return ret;
    }

    // Nothing to do
    return opts;
  }
Exemple #7
0
LLBC_Variant::LLBC_Variant(const Dict &dictVal)
{
    _holder.type = LLBC_VariantType::VT_DICT_DFT;
    if (!dictVal.empty())
    {
        _holder.dict= new Dict();
        _holder.dict->insert(dictVal.begin(), dictVal.end());
    }
}
Exemple #8
0
int main (){
    cout << boolalpha;

    // constructor
    Dict<string,long> d;
    // add
    d.add("bill", 10);
    d.add("rich", 20);
    // output
    cout << d << endl << endl;

    //copy
    Dict<string,long> d2(d);
    cout << d2 << endl << endl;

    // add to existing key
    d2.add("bill", 100);
    // copy working?
    cout << d << endl << endl;
    cout << d2 << endl << endl;
    cout << "CHECK THIS ^^" << endl;

    // exists
    cout << "Exists bill:"<<d.exists("bill")<<endl;
    cout << "Exists john:"<<d.exists("john")<<endl;
    // get_value
    cout << "Value of bill:"<<d.get_value("bill")<<endl;
    // get_value throws on bad key
    try{
	d.get_value("john");
    }
    catch (range_error &e){
	cout << "bad get_value "<<e.what()<<endl;
    }

    // make the array grow
    d.add("fred", 30);
    d.add("bob", 40);
    d.add("irving", 50);
    d.add("john",60);
    cout << endl;
    cout << d << endl<<endl;

    // assignment
    Dict<string,long> d3;
    d3 = d;

    // erase
    d.erase("bob");
    // assignment working?
    cout << d << endl<<endl;
    cout << d3 << endl<<endl;
    cout << "D2: " << endl;
    cout << d2 << endl;

}
void ff::Dict::Add(const Dict &rhs)
{
	Vector<String> names = rhs.GetAllNames();

	for (StringRef name: names)
	{
		Value *value = rhs.GetValue(name);
		SetValue(name, value);
	}
}
Exemple #10
0
// ---- Split ----
int getWord(const char* begin, const char* findAfter, const Dict& dict) {
    while (*findAfter != '\0') {
        string s(begin, findAfter + 1);
        if (dict.find(s) != dict.end())
            return findAfter - begin + 1;
        ++findAfter;
    }

    return -1;
}
Exemple #11
0
std::map<CPLString, GDALPDFObject*>& GDALPDFDictionaryPoppler::GetValues()
{
    int i = 0;
    int nLength = m_poDict->getLength();
    for(i=0;i<nLength;i++)
    {
        Get((const char*)m_poDict->getKey(i));
    }
    return m_map;
}
Exemple #12
0
void testStringVals(){
  BOOST_LOG(rdErrorLog) << "-------------------------------------" << std::endl;
  BOOST_LOG(rdErrorLog) << "Testing String Pickle Roundtrips." << std::endl;
  {
    Dict d;
    std::string sv;
    sv="1";
    d.setVal("foo",sv);
    int iv;
    d.getVal("foo",iv);
    TEST_ASSERT(iv==1);
  }
  {
    Dict d;
    d.setVal("foo","1");
    int iv;
    d.getVal("foo",iv);
    TEST_ASSERT(iv==1);
  }
  {
    Dict d;
    std::string sv;
    sv="1.3";
    d.setVal("foo",sv);
    double dv;
    d.getVal("foo",dv);
    TEST_ASSERT(feq(dv,1.3));
  }
  
  BOOST_LOG(rdErrorLog) << "\tdone" << std::endl;
}
	bool build(Dict &_front, Dict &_back, Dict &dict, Tree &tree, bool flag)
	{
		if (_front.empty()) return false;
		if (_front.size() > _back.size())
			return build(_back, _front, dict, tree, !flag);
		for (auto &word : _front) dict.erase(word);
		for (auto &word : _back) dict.erase(word);
		Dict hoge;
		bool piyo = false;
		for (auto &i : _front)
		{
			string word = i;
			for (auto &c : word)
			{
				char fuga = c;
				for (c = 'a'; c <= 'z'; c++)
				{
					if (c == fuga) continue;
					if (_back.count(word))
					{
						piyo = true;
						!flag ? tree[i].push_back(word): tree[word].push_back(i);
					}
					else if (!piyo && dict.count(word))
					{
						hoge.insert(word);
						!flag ? tree[i].push_back(word): tree[word].push_back(i);
					}
				}
				c = fuga;
			}
		}
		return piyo || build(hoge, _back, dict, tree, flag);
	}
bool OCGs::optContentIsVisible( Object *dictRef )
{
  Object dictObj;
  Dict *dict;
  Object dictType;
  Object ocg;
  Object policy;
  bool result = true;
  dictRef->fetch( m_xref, &dictObj );
  if ( ! dictObj.isDict() ) {
    error(-1, "Unexpected oc reference target: %i", dictObj.getType() );
    dictObj.free();
    return result;
  }
  dict = dictObj.getDict();
  // printf("checking if optContent is visible\n");
  dict->lookup("Type", &dictType);
  if (dictType.isName("OCMD")) {
    // If we supported Visibility Expressions, we'd check
    // for a VE entry, and then call out to the parser here...
    // printf("found OCMD dict\n");
    dict->lookup("P", &policy);
    dict->lookupNF("OCGs", &ocg);
    if (ocg.isArray()) {
      if (policy.isName("AllOn")) {
	result = allOn( ocg.getArray() );
      } else if (policy.isName("AllOff")) {
	result = allOff( ocg.getArray() );
      } else if (policy.isName("AnyOff")) {
	result = anyOff( ocg.getArray() );
      } else if ( (!policy.isName()) || (policy.isName("AnyOn") ) ) {
	// this is the default
	result = anyOn( ocg.getArray() );
      }
    } else if (ocg.isRef()) {
      OptionalContentGroup* oc = findOcgByRef( ocg.getRef() );      
      if ( !oc || oc->getState() == OptionalContentGroup::Off ) {
	result = false;
      } else {
	result = true ;
      }
    }
    ocg.free();
    policy.free();
  } else if ( dictType.isName("OCG") ) {
    OptionalContentGroup* oc = findOcgByRef( dictRef->getRef() );
    if ( !oc || oc->getState() == OptionalContentGroup::Off ) {
      result=false;
    }
  }
  dictType.free();
  dictObj.free();
  // printf("visibility: %s\n", result? "on" : "off");
  return result;
}
Exemple #15
0
Dict* Ast::CreateDict(const location& loc, AstNode* seq, AstNode* key,
		AstNode* value)
{
	Dict *dict = dynamic_cast<Dict*>(seq);
	if (dict != NULL) {
		dict->AddKeyValue(key, value);
		return dict;
	}

	return new Dict(this, loc, key, value);
}
Exemple #16
0
int main(char** argv, int argc) {
    dict.insert("liu");
    dict.insert("kai");
    dict.insert("liuk");
    dict.insert("ai");

    split("liukai", dict, printVector);
    split("kaiai", dict, printVector);
    split("", dict, printVector);

    return 0;
}
Exemple #17
0
void Sentence::check(const Dict& book){
int a =0;
int b=0;
int max;
max = book.getlength(3);
int n[max];
string m[max];
cout<<"Sentence correction for: "<<input<<"\n";
cout<<"--------------------------------"<<"\n";
while( a < max){
int counter = 0;
int num=0;
input2 = book.lookup(3, a);
if(input2.length() > input.length()-1){
	num=input2.length();
}
else {
	num=input.length()-1;
}
//Hamming distance calculator
for(int i=0; i < num; i++){
	if(input[i] != input2[i]){
		counter++;
	}
}


if(a<10){
m[a] = input2;
n[a] = counter;
}
else{
for(int L=0; L<10;L++){
	if(counter < n[L]){
		for(int x=11; x>L; x--){
		n[x] = n[x-1];
		m[x]= m[x-1];
		}
		m[L] = input2;
		n[L] = counter;
		break;
	}	
}
}

a++;
}

for(int w=0; w<10; w++){
cout<<m[w]<<"\n";
}

}
// Parsea as palavras lidas
void parser() {
    char *pch = strtok (text, "\n");
    int countShort=0;
    int countCompound=0;
    
    while(pch != NULL){
        if(strlen(pch) <= 5)
            shortDict.insert(countShort++, pch);
        else
            compoundDict.insert(countCompound++, pch);
    	pch = strtok (NULL, "\n");                                    
    }
                                                                         
}
/*
================
DeclParser::Parse
================
*/
void DeclParser::Parse( Lexer &lexer ) {
	Dict *resultDict = OG_NULL;

	bool getKeyValue = false;

	int index;
	const Token *token;
	String key, value;

	const char *p;
	while ( (token = lexer.ReadToken()) != OG_NULL ) {
		p = token->GetString();
		if ( p ) {
			if ( *p == '\0' )
				lexer.Error("Unexpected Empty Token");
			if ( !getKeyValue ) {
				index = declTypes.Find(p);
				if ( index != -1 ) {
					value = lexer.ReadString();

					if ( value.IsEmpty() )
						lexer.Error("Empty name!");

					DictEx<Dict> &result = declTypes[index]->declList;
					index = result.Find(p);
					if ( index == -1 ) 
						resultDict = &result[p];
					else {
						resultDict = &result[index];
						resultDict->Clear();
					}
				} else {
					resultDict = OG_NULL;
					lexer.Warning( Format("Unknown decl Type '$*'") << p );
				}
				lexer.ExpectToken("{");
				getKeyValue = true;
			} else {
				if ( *p == '}' )
					getKeyValue = false;
				else if ( resultDict ) {
					key = p;
					(*resultDict).Set( key.c_str(), lexer.ReadString() );
				}
			}
		}
	}
	if ( getKeyValue )
		throw LexerError( LexerError::END_OF_FILE );
}
Exemple #20
0
int main() {
    string a, b, c;
    cin >> a >> b;
    Dict d;
    d["pixel"] = a;
    d["set"] = b;
    cout << d["pixel"] << endl;
    cout << d["SET"] << endl;
    cout << d["java"] << endl;
    d.remove("pixel");
    d["java"] = "computer element";
    cout << d["pixel"] << endl;
    cout << d.size() << endl;
    cout << d;
}
Exemple #21
0
void ff::DumpDict(ff::StringRef name, const Dict &dict, Log *log, bool chain, bool debugOnly)
{
	if (debugOnly && !GetThisModule().IsDebugBuild())
	{
		return;
	}

	Log extraLog;
	Log &realLog = log ? *log : extraLog;

	realLog.TraceF(L"+- Options for: %s --\r\n", name.c_str());

	Vector<String> names = dict.GetAllNames(chain, true, false);
	for (const String &key: names)
	{
		Value *value = dict.GetValue(key, chain);
		assert(value);

		String valueString;
		ValuePtr convertedValue;

		if (value->Convert(ff::Value::Type::String, &convertedValue))
		{
			valueString = convertedValue->AsString();
		}
		else if (value->Convert(ff::Value::Type::StringVector, &convertedValue))
		{
			Vector<String> &strs = convertedValue->AsStringVector();

			for (size_t i = 0; i < strs.Size(); i++)
			{
				valueString += String::format_new(L"\r\n|    [%lu]: %s", i, strs[i].c_str());
			}
		}
		else if (value->Convert(ff::Value::Type::Data, &convertedValue))
		{
			valueString.format(L"<data[%lu]>", convertedValue->AsData()->GetSize());
		}
		else
		{
			valueString = L"<data>";
		}

		realLog.TraceF(L"| %s: %s\r\n", key.c_str(), valueString.c_str());
	}

	realLog.Trace(L"+- Done --\r\n");
}
Exemple #22
0
void Pages::user(Document *doc){

    std::string sub;
    int uid = route("user", path, sub);

    if(!uid || (sub != "" && sub != "json")) return;

    Account u(uid);
    if(!u) return;

    if(sub == "json"){
        doc->setJson("json/account.tpl");
        u.fill(doc->dict());
        doc->dict()->ShowSection("LONG");
        Tracks::byUser(u.id, 0).fillJson(doc->dict(), false);

        std::vector<Playlist> playlists = Playlist::forUser(u);
        for(std::vector<Playlist>::const_iterator i=playlists.begin(); i!=playlists.end(); i++){
            Dict *playlistDict = doc->dict()->AddSectionDictionary("PLAYLIST");
            Dict *item = playlistDict->AddIncludeDictionary("PLAYLIST");
            item->SetFilename("json/playlist.tpl");
            i->fill(item);
        }

    } else { // plain HTML
        doc->setHtml("html/user.tpl", u.name);
        u.fill(doc->dict());
        Tracks::byUser(u.id, u.self()).fill(doc->dict(), "TRACK_LIST");

#ifdef HAVE_LIBHIREDIS
        Stat::push("userView", uid);
#endif

        std::vector<Playlist> playlists = Playlist::forUser(u);
        doc->dict()->ShowSection(playlists.empty() ? "NO_PLAYLIST" : "HAS_PLAYLISTS");
        for(std::vector<Playlist>::const_iterator i=playlists.begin(); i!=playlists.end(); i++){
            Dict *playlistDict = doc->dict()->AddSectionDictionary("PLAYLIST");
            i->fill(playlistDict);
        }

        EventList::user(u, 12).fill(doc->dict(), "EVENTS");
        Follower(u.id).followed().fill(doc->dict(), "FOLLOWED_USERS");

        Feature(u.id).fill(doc->dict());

    }
}
Exemple #23
0
std::string
demo::__toString(const Dict& arg)
{
  std::string result = "{";
  for(Dict::const_iterator it = arg.begin(); it != arg.end(); ++it)
  {
    result += "<";
    result += __toString(it->first);
    result += ",";
    result += __toString(it->second);
    result += ">";
    result += " ";
  }
  trimEnd(result);
  result += "}";
  return result;
}
FusionOperator IFusionOperator::fromString(const std::string& type)
{
    typedef map<string, FusionOperator, pfs::utils::StringUnsensitiveComp> Dict;
    static Dict v =
            map_list_of
            ("debevec", DEBEVEC)
            ("robertson", ROBERTSON)
            ("robertson-auto", ROBERTSON_AUTO)
            ;

    Dict::const_iterator it = v.find(type);
    if (it != v.end())
    {
        return it->second;
    }
    return DEBEVEC;
}
TransactionType
transaction_type_from_verb(wxString const& p_phrase)
{
    typedef map<wxString, TransactionType> Dict;
    static Dict dict;
    static bool calculated_already = false;
    if (!calculated_already)
    {
        JEWEL_ASSERT (dict.empty());
        dict[expenditure_verb()] = TransactionType::expenditure;
        dict[revenue_verb()] = TransactionType::revenue;
        dict[balance_sheet_verb()] = TransactionType::balance_sheet;
        dict[envelope_verb()] = TransactionType::envelope;
        dict[generic_verb()] = TransactionType::generic;
        calculated_already = true;
    }
    JEWEL_ASSERT (!dict.empty());
    JEWEL_ASSERT
    (   dict.size() ==
        static_cast<Dict::size_type>(TransactionType::num_transaction_types)
    );
    Dict::const_iterator const it = dict.find(p_phrase);
    if (it == dict.end())
    {
        JEWEL_THROW
        (   InvalidTransactionTypeException,
            "wxString passed to transaction_type_from_verb does not "
            "correspond to any TransactionType."
        );
    }
    JEWEL_ASSERT (it != dict.end());
    return it->second;
}
Exemple #26
0
Production *ProductionState::getProduction(const char *result) {
    Production *p = (Production *)_production[result];
    if( p == NULL ) {
        p = new Production(result, _constraint, knownInvalid);
        _production.Insert(result, p);
    }

    return p;
}
// Calcula a proporcao de palavras com ateh 5 letras
void calc_proporcao() {
	for(int i=0; i<6; i++)
    	qtd_palavra[i] = 0;
    
    Dict::iterator it;
    for(it=mydict.begin(); it!=mydict.end(); ++it) {
    	if(strlen(*it) <=5 ) {
    		qtd_palavra[strlen(*it)]++;
    		qtd_palavra[0]++;
    	}
    }
	
    for(int i=0; i<6; i++)
        cout << i << ":" << qtd_palavra[i] << endl;

	cout << "total prop: " << qtd_palavra[0] << endl;
    total_palavras = qtd_palavra[0];
}
Exemple #28
0
bool test_dict_non_const_square_brackets_operator()
{
	cout << "Testing non const operator[] to ensure it is inserting values as expected" << endl << endl;
	map<string, EMObject> objects = get_test_dict_keys();

	Dict dict;

	// Here is where the insertion occurs
	map<string, EMObject>::const_iterator mapIt = objects.begin();
	for( ; mapIt != objects.end(); ++mapIt )
	{
		dict[mapIt->first] = mapIt->second;
	}

	bool success = true;


	for( mapIt = objects.begin(); mapIt != objects.end(); ++mapIt )
	{
		bool found = false;
		cout << "Testing the insertion of map key/value pair with key " << mapIt->first << " (inserted into Dict with operator[]) ..... ";
		for( Dict::const_iterator it = dict.begin(); it != dict.end(); ++it )
		{
			if ( it->first == mapIt-> first && it->second == mapIt->second )
			{
				found = true;
				break;
			}
		}

		if ( found )
			cout << "passed";
		else
		{
			cout << "FAILED";
			success = false;
		}

		cout << endl;
	}

	print_success_message(success);
	return success;
}
std::unordered_map<uint, QString> RefactoringClient::convertFilePaths(
        const ClangBackEnd::FilePathDict &filePaths)
{
    using Dict = std::unordered_map<uint, QString>;
    Dict qstringFilePaths;
    qstringFilePaths.reserve(filePaths.size());

    auto convertFilePath = [] (const ClangBackEnd::FilePathDict::value_type &dictonaryEntry) {
        return std::make_pair(dictonaryEntry.first,
                              concatenateFilePath(dictonaryEntry.second).toQString());
    };

    std::transform(filePaths.begin(),
                   filePaths.end(),
                   std::inserter(qstringFilePaths, qstringFilePaths.begin()),
                   convertFilePath);

    return qstringFilePaths;
}
Exemple #30
0
void EMUtil::dump_dict(const Dict & dict)
{
	vector < string > keys = dict.keys();
	vector < EMObject > values = dict.values();

	for (unsigned int i = 0; i < keys.size(); i++) {
		EMObject obj = values[i];

		if (! obj.is_null()) {
			string val = obj.to_str();

			if (keys[i] == "datatype") {
				val = get_datatype_string((EMDataType) (int) obj);
			}

			fprintf(stdout, "%25s\t%s\n", keys[i].c_str(), val.c_str());
		}
	}
}