<commit_before>//
//  GXLWriter.swift
//  SOGraphDB
//
//  Created by <NAME> on 15.01.18.
//

import Foundation

class GXLWriter {
    
    let store: XMLFileStore
    
    var xml = ""
    
    let documentHeader = "<?xml version=\"1.0\" encoding=\"utf-8\"?>"
    
    init(store: XMLFileStore) {
        self.store = store
    }
    
    func writeHeader() {
        xml = documentHeader
    }
    
    func write(startElement elementName: String,
               attributes attributeDict: [String : String] = [String : String]()) {
        
        var xmlAttributes = ""
        
        for (attributeName,attributeValue) in attributeDict {
            xmlAttributes += " \(attributeName)=\"\(attributeValue)\""
        }
        
        xml += "<\(elementName)\(xmlAttributes)>"
    }
    
    func write(endElement elementName: String) {
        xml += "</\(elementName)>"
    }
    
    func write(elementText text: String) {
        xml += text
    }
    
    func writeAttributes(_ element: PropertyElement) {
        element.onAllProperties{ (property) in
            
            let keyNodeID = String(property.keyNodeID)
            write(startElement: GLX.Elements.property, attributes: [GLX.Attributes.key: keyNodeID] )
            write(elementText: property.string())
            write(endElement: GLX.Elements.property)
            
        }
    }
    
    func writeElement(type: String, element: PropertyElement) {
        
        let uid = String(element.uid)
        write(startElement: type, attributes: [GLX.Attributes.key: uid] )
        writeAttributes(element)
        write(endElement: type)
        
    }
    

    
    
    
    func writeXML() {
        writeHeader()
        
        write(startElement: GLX.Elements.glx)
         write(startElement: GLX.Elements.graph, attributes: [GLX.Attributes.key: "01"] )
        
         // write all nodes
         store.onAllNodes { (node) in
            writeElement(type: GLX.Elements.node, element: node)
         }
        
         // write all relationships
        store.onAllRelationships { (rel) in
            writeElement(type: GLX.Elements.property, element: rel)
        }
        
         write(endElement: GLX.Elements.graph)
        write(endElement: GLX.Elements.glx)
    }
    
    func write(file url:URL) throws {
        
        /**
        do {
            try text.write(to: fileURL, atomically: false, encoding: .utf8)
        }
        catch {/* error handling here */}
        */
    }
}
<commit_msg>fix first issues - add CR - replace key by id<commit_after>//
//  GXLWriter.swift
//  SOGraphDB
//
//  Created by <NAME> on 15.01.18.
//

import Foundation

class GXLWriter {
    
    let store: XMLFileStore
    
    var xml = ""
    
    let documentHeader = "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n"
    
    init(store: XMLFileStore) {
        self.store = store
    }
    
    func writeHeader() {
        xml = documentHeader
    }
    
    func write(startElement elementName: String,
               attributes attributeDict: [String : String] = [String : String]()) {
        
        var xmlAttributes = ""
        
        for (attributeName,attributeValue) in attributeDict {
            xmlAttributes += " \(attributeName)=\"\(attributeValue)\""
        }
        
        xml += "<\(elementName)\(xmlAttributes)>\n"
    }
    
    func write(endElement elementName: String) {
        xml += "</\(elementName)>\n"
    }
    
    func write(elementText text: String) {
        xml += text
    }
    
    func writeAttributes(_ element: PropertyElement) {
        element.onAllProperties{ (property) in
            
            let keyNodeID = String(property.keyNodeID)
            write(startElement: GLX.Elements.property, attributes: [GLX.Attributes.key: keyNodeID] )
            write(elementText: property.string())
            write(endElement: GLX.Elements.property)
            
        }
    }
    
    func writeElement(type: String, element: PropertyElement) {
        
        let uid = String(element.uid)
        write(startElement: type, attributes: [GLX.Attributes.id: uid] )
        writeAttributes(element)
        write(endElement: type)
        
    }
    

    func writeXML() -> String {
        writeHeader()
        
        write(startElement: GLX.Elements.glx)
         write(startElement: GLX.Elements.graph, attributes: [GLX.Attributes.id: "01"] )
        
         // write all nodes
         store.onAllNodes { (node) in
            writeElement(type: GLX.Elements.node, element: node)
         }
        
         // write all relationships
        store.onAllRelationships { (rel) in
            writeElement(type: GLX.Elements.property, element: rel)
        }
        
         write(endElement: GLX.Elements.graph)
        write(endElement: GLX.Elements.glx)
        
        return xml
    }
    
    func write(file url:URL) throws {
        
        /**
        do {
            try text.write(to: fileURL, atomically: false, encoding: .utf8)
        }
        catch {/* error handling here */}
        */
    }
}

{'fraction_non_alphanumeric': 0.11330049261083744, 'fraction_numerical': 0.004729064039408867, 'mean_word_length': 1.7423014586709886, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 2, '>': 12, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 19}, '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': '2491401', 'n_tokens_mistral': 1469, 'n_tokens_neox': 1444, 'n_words': 305}