<commit_before>//
//  sdSaver.cpp
//

#include <vector>
#include <iostream>
#include <sstream>
#include <algorithm>
#include "sdConst.h"
#include "sdEntity.h"
#include "sdScene.h"
#include "sdSaver.h"
#include "tinyxml2.h"
#include "JSONNode.h"

using namespace std;

string sdGlobalEvent::getKindAsString(void){
    string str;
    switch (kind) {
        case SD_SOURCE:
            str = string("source");
            break;
        case SD_SINK:
            str = string("sink");
            break;
        default:
            break;
    }
    return str;
}

string sdSaver::XMLFromScene(sdScene *scene){
    using namespace tinyxml2;
    
    XMLDocument xml;
 	XMLDeclaration* decl = xml.NewDeclaration();
	decl->SetValue("xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"");
	xml.InsertEndChild(decl);
    
    XMLElement* spatdif = xml.NewElement("spatdif");
	xml.InsertEndChild(spatdif);
    // meta section
    
    XMLElement* meta = xml.NewElement("meta");
    spatdif->SetAttribute("version", "0.3");
    spatdif->InsertEndChild(meta);
    
    XMLElement* info = xml.NewElement("info");
    meta->InsertEndChild(info);
    
    sdInfo information = scene->getInfo();

    string infoStrings[6];
    string elementNameStrings[6];
    
    infoStrings[0] = information.getAuthor();
    infoStrings[1] = information.getHost();
    infoStrings[2] = information.getDateAsString();
    infoStrings[3] = information.getLocation();
    infoStrings[4] = information.getSession();
    infoStrings[5] = information.getAnnotation();

    elementNameStrings[0] = "author";
    elementNameStrings[1] = "host";
    elementNameStrings[2] = "date";
    elementNameStrings[3] = "location";
    elementNameStrings[4] = "session";
    elementNameStrings[5] = "annotation";
    
    for(int i = 0; i< 6; i++){
        if(!infoStrings[i].empty()){
            XMLElement* e  = xml.NewElement(elementNameStrings[i].c_str());
            XMLText* t = xml.NewText(infoStrings[i].c_str());
            e->InsertEndChild(t);
            info->InsertEndChild(e);
        }
    }
    
    // check the number of extension
    int num = scene->getNumberOfActivatedExtensions();

    if(num > 0){
        XMLElement* extensions = xml.NewElement("extensions");
        string extString;
        for(int i = 0; i< num; i++){

            EExtension ext = scene->getActivatedExtension(i);
            extString = extString + extensionToString(ext);
        }
        
        XMLText* extensionsText = xml.NewText(extString.c_str());
        extensions->InsertEndChild(extensionsText);
    }
    XMLElement* order = xml.NewElement("ordering");
    XMLText* orderingText = xml.NewText(scene->getOrderingAsString().c_str());
    order->InsertEndChild(orderingText);
    meta->InsertEndChild(order);
    
    // time section
    
    vector<sdEntityCore*> entityVector = scene->getEntityVector();

    /* ordered by time */
    if(scene->getOrdering() == SD_TIME){
        
        // 1. pool all events in globalEvent Set
        vector<sdEntityCore*>::iterator it = entityVector.begin();
        multiset<sdGlobalEvent, sdGlobalEventCompare> allEventSet;
        
        while(it != entityVector.end()){
            sdEntityCore *entity = *it;
            multiset<sdEvent*, sdEventCompare> eventSet = entity->getEventSet();
            multiset<sdEvent*, sdEventCompare>::iterator iit =eventSet.begin();
            while(iit != eventSet.end()){
                sdEvent* event = *iit;
                sdGlobalEvent globalEvent(event, entity->getName(), entity->getKind());                
                allEventSet.insert(globalEvent); // gather pointer to all existing instances of sdEvent
                ++iit;
            }
            ++it;
        }

        // 2. create string
        multiset<sdGlobalEvent, sdGlobalEventCompare>::iterator eit = allEventSet.begin();
        while(eit != allEventSet.end()){<commit_msg>sdSaver Extension compatibility in progress<commit_after>//
//  sdSaver.cpp
//

#include <vector>
#include <iostream>
#include <sstream>
#include <algorithm>
#include "sdConst.h"
#include "sdEntity.h"
#include "sdEntityExtension.h"
#include "sdScene.h"
#include "sdSaver.h"
#include "tinyxml2.h"
#include "JSONNode.h"

using namespace std;

string sdGlobalEvent::getKindAsString(void){
    string str;
    switch (kind) {
        case SD_SOURCE:
            str = string("source");
            break;
        case SD_SINK:
            str = string("sink");
            break;
        default:
            break;
    }
    return str;
}

string sdSaver::XMLFromScene(sdScene *scene){
    using namespace tinyxml2;
    
    XMLDocument xml;
 	XMLDeclaration* decl = xml.NewDeclaration();
	decl->SetValue("xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"");
	xml.InsertEndChild(decl);
    
    XMLElement* spatdif = xml.NewElement("spatdif");
	xml.InsertEndChild(spatdif);
    // meta section
    
    XMLElement* meta = xml.NewElement("meta");
    spatdif->SetAttribute("version", "0.3");
    spatdif->InsertEndChild(meta);
    
    XMLElement* info = xml.NewElement("info");
    meta->InsertEndChild(info);
    
    sdInfo information = scene->getInfo();

    string infoStrings[6];
    string elementNameStrings[6];
    
    infoStrings[0] = information.getAuthor();
    infoStrings[1] = information.getHost();
    infoStrings[2] = information.getDateAsString();
    infoStrings[3] = information.getLocation();
    infoStrings[4] = information.getSession();
    infoStrings[5] = information.getAnnotation();

    elementNameStrings[0] = "author";
    elementNameStrings[1] = "host";
    elementNameStrings[2] = "date";
    elementNameStrings[3] = "location";
    elementNameStrings[4] = "session";
    elementNameStrings[5] = "annotation";
    
    for(int i = 0; i< 6; i++){
        if(!infoStrings[i].empty()){
            XMLElement* elem  = xml.NewElement(elementNameStrings[i].c_str());
            XMLText* tex = xml.NewText(infoStrings[i].c_str());
            elem->InsertEndChild(tex);
            info->InsertEndChild(elem);
        }
    }
    
    // check the number of extension
    int num = scene->getNumberOfActivatedExtensions();

    if(num > 0){
        XMLElement* extensions = xml.NewElement("extensions");
        string extString;
        for(int i = 0; i< num; i++){

            EExtension ext = scene->getActivatedExtension(i);
            extString = extString + extensionToString(ext);
        }
        
        XMLText* extensionsText = xml.NewText(extString.c_str());
        extensions->InsertEndChild(extensionsText);
        meta->InsertEndChild(extensions);
    }
    
    XMLElement* order = xml.NewElement("ordering");
    XMLText* orderingText = xml.NewText(scene->getOrderingAsString().c_str());
    order->InsertEndChild(orderingText);
    meta->InsertEndChild(order);
    
    // time section
    
    vector<sdEntityCore*> entityVector = scene->getEntityVector();

    /* ordered by time */
    if(scene->getOrdering() == SD_TIME){
        
        // 1. pool all events in globalEvent Set
        vector<sdEntityCore*>::iterator it = entityVector.begin();
        multiset<sdGlobalEvent, sdGlobalEventCompare> allEventSet;
        
        while(it != entityVector.end()){
            
            // core event
            sdEntityCore *entity = *it;
            multiset<sdEvent*, sdEventCompare> eventSet = entity->getEventSet();
            multiset<sdEvent*, sdEventCompare>::iterator iit =eventSet.begin();
            while(iit != eventSet.end()){
                sdEvent* event = *iit;
                sdGlobalEvent globalEvent(event, entity->getName(), entity->getKind());                
                allEventSet.insert(globalEvent); // gather pointer to all existing instances of sdEvent
                ++iit;
            }
            // extension event
            vector <sdEntityExtension*> extensionVector = entity->getExtensionVector();
            vector <sdEntityExtension*>::iterator evit = extensionVector.begin();
            while (evit != extensionVector.end()) {
                sdEntityExtension* attachedExtension = *evit;
                multiset<sdEvent*, sdEventCompare> extEventSet = attachedExtension->getEventSet();
                multiset<sdEvent*, sdEventCompare>::iterator aeit = extEventSet.begin();
                while (aeit != extEventSet.end()) {
                    sdEvent* extEvent = *aeit;
                    sdGlobalEvent globalExtEvent(extEvent, entity->getName(), entity->getKind());
                    allEventSet.insert(globalExtEvent);
                    ++aeit;
                }
                evit++;
            }
            
            ++it;
        }

        // 2. create string
        multiset<sdGlobalEvent, sdGlobalEventCompare>::iterator eit = allEventSet.begin();
        while(eit != allEventSet.end()){
{'fraction_non_alphanumeric': 0.13215859030837004, 'fraction_numerical': 0.006099627245001694, 'mean_word_length': 2.5345309381237526, 'pattern_counts': {'":': 0, '<': 31, '<?xml version=': 2, '>': 70, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 32}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6368351', 'n_tokens_mistral': 2594, 'n_tokens_neox': 2539, 'n_words': 499}