예제 #1
0
void FrameNetBuilder::read_relations(FrameNet &fn){

    rapidxml::file<> fdoc(this->relation_file_path.c_str());
    rapidxml::xml_document<> doc;
    doc.parse<0>(fdoc.data());

    rapidxml::xml_node<>* root = doc.first_node();
    for(auto fr_type = root->first_node("frameRelationType");fr_type!= nullptr;fr_type = fr_type->next_sibling("frameRelationType")){
        std::string fr_type_name = fr_type->first_attribute("name")->value();
        for(auto fr = fr_type->first_node("frameRelation");fr!= nullptr;fr = fr->next_sibling("frameRelation")){
            std::string subFrame = fr->first_attribute("subFrameName")->value();
            std::string superFrame = fr->first_attribute("superFrameName")->value();
            Frame *current_frame = fn.get_frame(subFrame);
            if(fr_type_name == "Causative_of"||fr_type_name == "Inchoative_of"||fr_type_name == "Precedes"){
                current_frame = fn.get_frame(superFrame);
            }

            for(auto fe_r =fr->first_node("FERelation");fe_r!= nullptr;fe_r = fe_r->next_sibling("FERelation")){
                std::string parent = fe_r->first_attribute("superFEName")->value();
                std::string child = fe_r->first_attribute("subFEName")->value();
                FrameElementRelation *fr = new FrameElementRelation(parent,child,fr_type_name,superFrame,subFrame);
                current_frame->add_fe_relation(fr);

            }

        }
    }
}
void ReadServerErrCodeFile(std::map<uint32_t, std::map<ELanguageType, TString> >& languageServerErrCodeMap)
{
    TString filePath = CResourceManager::GetInstance()->GetResourcePath(eRT_Language);
    filePath.append(_T("\\")).append("networkError.xml");
    if (CFilePathTool::GetInstance()->Exists(filePath.c_str()))
    {
        rapidxml::file<> fdoc(filePath.c_str());
        rapidxml::xml_document<> errCodeXML;
        try
        {
            errCodeXML.parse<rapidxml::parse_default>(fdoc.data());
        }
        catch (rapidxml::parse_error err)
        {
            BEATS_ASSERT(false, _T("Load config file %s faled!/n%s/n"), "errno.xml", err.what());
        }
        rapidxml::xml_node<>* pRootElement = errCodeXML.first_node("config");
        if (pRootElement)
        {
            for (auto element = pRootElement->first_node(); element; element = element->next_sibling())
            {
                std::map<ELanguageType, TString> curMap;
                curMap[eLT_Chinese] = element->first_attribute("lang_zhCN")->value();
                curMap[eLT_English] = element->first_attribute("lang_enUS")->value();
                languageServerErrCodeMap[_tstoi(element->first_attribute("code")->value())] = curMap;
            }
        }
    }
}
예제 #3
0
LexicalUnit* FrameBuilder::build_LU(rapidxml::xml_node<>*node,std::string frame_name){
    int ID = atoi(node->first_attribute("ID")->value());
    std::string name = node->first_attribute("name")->value();
    std::string POS = node->first_attribute("POS")->value();
    std::string status = node->first_attribute("status")->value();
    LexicalUnit *lu = new LexicalUnit(name,POS,frame_name,ID,status);
    auto p=node->first_node("semType");
    if(p!= nullptr){
        std::string name = p->first_attribute("name")->value();
        int ID = atoi(p->first_attribute("ID")->value());
        SemType *s = new SemType(name,ID);
        lu->set_semtype(s);
    }
    return lu;
}
예제 #4
0
void mlUnitInfo::fetch( const std::string & name )
{
	pugi::xml_document doc;
	doc.load_file( ("ini/units/" + name + ".xml").c_str() );
	auto root = doc.root().first_child();

	while( root.attribute( "template" ) )
	{
		pugi::xml_document doc;
		doc.load_file( root.attribute( "template" ).as_string() );
		root.remove_attribute( "template" );

		auto temp = doc.root().first_child();
		for( auto attr = temp.first_attribute(); attr; attr = attr.next_attribute() )
		{
			auto attrRoot = root.attribute( attr.name() );
			if( !attrRoot )
				attrRoot = root.append_attribute( attr.name() );
			attrRoot.set_value( attr.value() );
		}
	}

	Info info;
	info.layer = strToUnitLayer( root.attribute( "unitlayer" ).as_string() );
	info.type = strToUnitType( root.attribute( "unittype" ).as_string() );
	info.radius = root.attribute( "radius" ).as_float();

	_info.insert( std::pair<std::string, Info>( name, info ) );
}
// Build the vector of tiled_object_property's
void tiled_object::build_property_vec( xml_node<>* properties_node )
{
	for ( auto inner_node = properties_node->first_node();
		inner_node;
		inner_node = inner_node->next_sibling() )
	{
		tiled_object_property to_push;
		
		for ( auto attr=inner_node->first_attribute();
			attr;
			attr=attr->next_attribute() )
		{
			if ( attr->name() == string("name") )
			{
				to_push.name = attr->value();
			}
			else if ( attr->name() == string("value") )
			{
				to_push.value = attr->value();
			}
		}
		
		property_vec.push_back(to_push);
	}
	
}
예제 #6
0
FERealization* FrameNetBuilder::build_realization(rapidxml::xml_node<>* node,std::string frame_name,std::string lu_name){
    int total = atoi(node->first_attribute("total")->value());
    FERealization* fe_realization = new FERealization(frame_name,total,lu_name);
    std::string fe_name = node->first_node("FE")->first_attribute("name")->value();
    fe_realization->set_fe(fe_name);
    for(auto p_pattern = node->first_node("pattern");p_pattern != nullptr;p_pattern = p_pattern->next_sibling("pattern")){
        for(auto p_anno = p_pattern->first_node("annoSet");p_anno != nullptr; p_anno = p_anno->next_sibling("annoSet") ){
            fe_realization->set_annotationID(atoi(p_anno->first_attribute("ID")->value()));
        }
    }
    return fe_realization;
}
tiled_objectgroup::tiled_objectgroup( xml_node<>* node )
{
	// find the name attribute
	for ( auto attr=node->first_attribute();
		attr;
		attr=attr->next_attribute() )
	{
		if ( attr->name() == string("name") )
		{
			name = attr->value();
			
			// I don't know why I don't include a break statement after
			// finding the name attribute.
		}
	}
	
	// Loop through all the internal nodes within the current objectgroup
	// for the purpose of building object_vec.
	for ( auto object_node=node->first_node();
		object_node;
		object_node=object_node->next_sibling() )
	{
		tiled_object to_push;
		
		// Build to_push using the attributes of object_node.
		for ( auto attr=object_node->first_attribute();
			attr;
			attr=attr->next_attribute() )
		{
			stringstream attr_sstm;
			
			attr_sstm << attr->value();
			
			if ( attr->name() == string("id") )
			{
				attr_sstm >> to_push.id;
			}
			else if ( attr->name() == string("gid") )
			{
				attr_sstm >> to_push.gid_raw;
				
				// Tiled stores hflip and vflip within an object's gid
				// parameter.
				to_push.gid = to_push.gid_raw & 0x3fffffff;
				to_push.vflip = to_push.gid_raw & 0x40000000;
				to_push.hflip = to_push.gid_raw & 0x80000000;
				
				// subtract the gid by 1
				if ( to_push.gid > 0 )
				{
					--to_push.gid;
				}
			}
예제 #8
0
void dllmain::load_config()
{
	try
	{
		rapidxml::xml_document doc;
		std::ifstream file("easydatabase.xml");
		std::vector<char> buffer((std::istreambuf_iterator<char>(file)), std::istreambuf_iterator<char>());
		buffer.push_back('\0');
		doc.parse<0>(buffer.data());
		auto root_node = doc.first_node("MyBeerJournal");

		// Get Configuration
		m_allowNonPrepared = xml_get_bool(root_node->first_node("allownonprepared"), false);

		// Get Connections
		for (auto connection_node = root_node->first_node("connection"); connection_node; connection_node = connection_node->next_sibling())
		{
			easydatabase::connection con;
			con.name = connection_node->first_attribute("name")->value();
			con.uri = connection_node->first_node("uri")->value();
			con.database = connection_node->first_node("database")->value();
			con.username = connection_node->first_node("username")->value();
			con.password = connection_node->first_node("password")->value();
			m_connections.push_back(con);
		}

		// Get Prepared Statements
		for (auto statement_node = root_node->first_node("statement"); statement_node; statement_node = statement_node->next_sibling())
		{
			easydatabase::prepared_statement stmnt;
			stmnt.name = statement_node->first_attribute("name")->value();
			stmnt.query = statement_node->value();
			m_prepared_statements.push_back(stmnt);
		}
	}
	catch(std::exception ex) { }
}
예제 #9
0
FrameElement* FrameBuilder::build_FE(rapidxml::xml_node<>*node,std::string frame_name){
    std::string name = node->first_attribute("name")->value();
    std::string abbrev = node->first_attribute("abbrev")->value();
    std::string coreType = node->first_attribute("coreType")->value();
    int ID = atoi(node->first_attribute("ID")->value());
    std::string xml_definition = node->first_node("definition")->value();
    boost::regex expr{"<[^>]*>"};
    std::string fmt{""};
    std::string def_text = boost::regex_replace(xml_definition, expr, fmt);

    FrameElement *element = new FrameElement(name,abbrev,coreType,frame_name,ID,def_text);

    //set semType
    auto p=node->first_node("semType");
    if(p!= nullptr){
        std::string name = p->first_attribute("name")->value();
        int ID = atoi(p->first_attribute("ID")->value());
        SemType *s = new SemType(name,ID);
        element->set_semtype(s);
    }

    //set excludesFEs
    for(auto p=node->first_node("excludesFE");p!= nullptr;p = p->next_sibling("excludesFEs")){
        std::string name = p->first_attribute("name")->value();
        element->add_excludes(name);
    }

    //set requiresFEs
    for(auto p=node->first_node("requiresFE");p!= nullptr;p = p->next_sibling("requiresFEs")){
        std::string name = p->first_attribute("name")->value();
        element->add_requires(name);
    }


    return  element;
}
예제 #10
0
    bool BilibiliParser::ParseXml(const char* data, bool inplace) {
        if (mDanmakus.get() == nullptr)
            return false;

        char* buffer = nullptr;
        std::unique_ptr<char[]> raii_buffer;

        if (inplace) {
            buffer = const_cast<char*>(data);
        } else {
            size_t buffer_size = strlen(data) + 1;
            buffer = new char[buffer_size];
            raii_buffer = std::move(std::unique_ptr<char[]>(buffer));
            memset(buffer, 0, buffer_size);
            strcpy_s(buffer, buffer_size, data);
        }

        xml_document<> doc;
        doc.parse<0>(buffer);

        xml_node<char>* root = doc.first_node("i");
        if (root == nullptr)
            return false;

        for (auto node = root->first_node("d"); node != nullptr; node = node->next_sibling()) {
            const char* attr = node->first_attribute("p")->value();
            std::vector<std::string> attributes;
            attributes.reserve(8);
            SplitString(attr, ',', attributes);

            if (attributes.size() >= 8) {
                time_t time = static_cast<time_t>(std::stod(attributes[0]) * 1000);
                DanmakuType type = static_cast<DanmakuType>(std::stoi(attributes[1]));
                int textSize = static_cast<int>(std::stof(attributes[2]));
                int textColor = std::stoi(attributes[3]) | 0xFF000000;
                time_t timestamp = std::stoull(attributes[4]);
                int danmakuId = std::stoi(attributes[7]);
                std::wstring comment = UTF8ToWideString(node->value());

                DanmakuRef danmaku = DanmakuFactory::CreateDanmaku(type, time, comment, textSize, textColor, timestamp, danmakuId);
                if (danmaku != nullptr) {
                    mDanmakus->push_back(danmaku);
                }
            }
        }
        return true;
    }
예제 #11
0
Annotation* FrameNetBuilder::build_annotation(rapidxml::xml_node<>* senten){

    std::string text = senten->first_node("text")->value();
    for(auto annoset = senten->first_node("annotationSet");annoset != nullptr;annoset = annoset->next_sibling("annotationSet")){
        std::string status = annoset->first_attribute("status")->value();
        if(status == "MANUAL"||status == "AUTO_EDITED"){
            int ID = atoi(annoset->first_attribute("ID")->value());
            std::vector<Label> labels;

            for(auto layer = annoset->first_node("layer");layer != nullptr;layer = layer->next_sibling("layer")){
                std::string ly_name = layer->first_attribute("name")->value();

                if(ly_name == "FE"){
                    for(auto label = layer->first_node("label");label != nullptr;label = label->next_sibling("label")){
                        auto attr = label->first_attribute("start");
                        if(attr!= nullptr){
                            int start = std::stoi(label->first_attribute("start")->value());
                            int end = std::stoi(label->first_attribute("end")->value());
                            std::string fe_name = label->first_attribute("name")->value();
                            int fe_ID = std::stoi(label->first_attribute("feID")->value());
                            labels.push_back({start,end,fe_name,fe_ID});
                        }
                    }
                }
                if(ly_name == "Target"){
                    for(auto label = layer->first_node("label");label != nullptr;label = label->next_sibling("label")){
                        int start = std::stoi(label->first_attribute("start")->value());
                        int end = std::stoi(label->first_attribute("end")->value());
                        std::string fe_name =text.substr(start,end-start+1);
                        int fe_ID = -1;
                        labels.push_back({start,end,fe_name,fe_ID});
                    }
                }
            }
            Annotation *annotation = new Annotation(text,ID,status,labels);
            return annotation;
        }
    }
}
예제 #12
0
int checkSearchEntry(BerElement *ber)
{
	int rc = LDAP_SUCCESS;
	ber_tag_t tag;
	ber_len_t len =0;
	BerValue attr;
	BerVarray vals;
	attr.bv_val = NULL;
	attr.bv_len = 0;
	char *a;
	int n;
	struct berval dn = BER_BVNULL;
	BerElement ber_value, ber_backup;
	ber_value = ber_backup= *ber;
		
	
#ifdef DEBUG 
	    int ival = -1;
        ber_set_option( NULL, LBER_OPT_DEBUG_LEVEL, &ival );
#endif
	
	 n=0;
	for ( a = first_attribute( ber ); a != NULL; a = next_attribute(  ber ) )
		{
			struct berval	**vals;
			//printf( "| | ATTR: %s\n", a );
			if ( (vals = get_values_len( &ber_value, a )) == NULL )
			{
				printf( "| | %s:\t(no values)\n" , a);
			}else {
				int i;
				for ( i = 0; vals[i] != NULL; i++ ) {
					int	j, nonascii;

					nonascii = 0;
					for ( j = 0; (ber_len_t) j < vals[i]->bv_len; j++ )
					//Non-display ASCII will be shown as HEX, It is Control code before 33 in ASCII Table
						if ( !isascii( vals[i]->bv_val[j] ) || vals[i]->bv_val[j] < 33 ) {
							nonascii = 1;
							break;
						}
					
					if ( nonascii ) {
						printf( "|-%s(not ascii):\tlen (%ld) \n",a, vals[i]->bv_len );
					
						ber_bprint( vals[i]->bv_val, vals[i]->bv_len );
					
						continue;
					}
				
#ifdef DETAIL
					printf( "|-%s:\tlen (%ld) \t%s\n",a, vals[i]->bv_len, vals[i]->bv_val );
#else					
					printf( "|-%s:\t\t%s\n",a, vals[i]->bv_val );
					
#endif					
				}
				
				ber_bvecfree( vals );
			}
			ber_value = ber_backup;
			n++;
		}
		
	
	return n;
}
void GameOptions::Init(const char *xmlFilePath, const char *cmdLine)
{
    auto content = ReadOptionsFile(xmlFilePath);

    if (content == NULL)
        return;

    xml_document<> document;
    document.parse<0>(content);

    //
    // Loading GRAPHICS settings
    //
    auto graphicsNode = document.first_node("Graphics");
    if (graphicsNode)
    {
        auto heightAttribute = graphicsNode->first_attribute("height");
        if (heightAttribute)
        {
            m_screenSize.y = atoi(heightAttribute->value());
        }

        auto widthAttribute = graphicsNode->first_attribute("width");
        if (widthAttribute)
        {
            m_screenSize.x = atoi(widthAttribute->value());
        }

        auto runFullSpeedAttribute = graphicsNode->first_attribute("runFullSpeed");
        if (runFullSpeedAttribute)
        {
            m_runFullSpeed = GAME_OPTIONS_SWITCH_TO_BOOLEAN(runFullSpeedAttribute->value());
        }
    }

    //
    // Loading SOUND settings
    //
    auto soundNode = document.first_node("Sound");
    if (soundNode)
    {
        auto musicVolumeAttribute = soundNode->first_attribute("musicVolume");
        if (musicVolumeAttribute)
        {
            m_musicVolume = atoi(musicVolumeAttribute->value()) / 100.0f;
        }

        auto soundEffectsVolumeAttribute = soundNode->first_attribute("sfxVolume");
        if (soundEffectsVolumeAttribute)
        {
            m_soundEffectsVolume = atoi(soundEffectsVolumeAttribute->value()) / 100.0f;
        }
    }

    //
    // Loading DEV settings
    //
    auto devNode = document.first_node("Development");
    if (devNode)
    {
        auto useDevDirectoriesAttribute = devNode->first_attribute("useDevelopmentDirectories");
        if (useDevDirectoriesAttribute)
        {
            m_useDevelopmentDirectories = GAME_OPTIONS_SWITCH_TO_BOOLEAN(useDevDirectoriesAttribute->value());
        }
    }

    free(content);
}