void FileImporter::getSubset(string metapath){ vector < std::pair<float,string> > tmpsubset(0); BaseFileLoader::attrSubset.clear(); ofFile Meta(metapath); if(Meta.exists()){ ofxJSONElement json; json.open(metapath); Json::Value val = json.get("InfoGain", ""); for( Json::Value::iterator iit = val.begin();iit != val.end(); ++iit){ tmpsubset.push_back(std::pair<float,string>((*iit).asFloat(),iit.memberName())); } std::sort(tmpsubset.begin(), tmpsubset.end()); vector< std::pair<float,string> >::iterator startiit = tmpsubset.begin(); if(tmpsubset.size()>numBest){ startiit = tmpsubset.end() - numBest; } ofLogWarning("FileImporter","getting subset :"); for( vector< std::pair<float,string> >::iterator iit = startiit ; iit < tmpsubset.end() ; ++iit ){ BaseFileLoader::attrSubset.push_back(iit->second); ofLogWarning("FileImporter", "\t" +iit->second ); } } }
PyObject *Effect::json2python(const Json::Value &json) const { switch (json.type()) { case Json::nullValue: return Py_BuildValue(""); case Json::realValue: return Py_BuildValue("d", json.asDouble()); case Json::intValue: case Json::uintValue: return Py_BuildValue("i", json.asInt()); case Json::booleanValue: return Py_BuildValue("i", json.asBool() ? 1 : 0); case Json::stringValue: return Py_BuildValue("s", json.asCString()); case Json::objectValue: { PyObject * dict= PyDict_New(); for (Json::Value::iterator i = json.begin(); i != json.end(); ++i) { PyObject * obj = json2python(*i); PyDict_SetItemString(dict, i.memberName(), obj); Py_XDECREF(obj); } return dict; } case Json::arrayValue: { PyObject * list = PyList_New(json.size()); for (Json::Value::iterator i = json.begin(); i != json.end(); ++i) { PyObject * obj = json2python(*i); PyList_SetItem(list, i.index(), obj); Py_XDECREF(obj); } return list; } } assert(false); return nullptr; }