<commit_before>//
//  SGDOTWriter.swift
//  SuperGraph
//
//  Created by <NAME> on 17/04/2015.
//  Copyright (c) 2015 bluetatami. All rights reserved.
//

import Foundation

public class SGDOTWriter {
    
}<commit_msg>added a function to write graph to SGDOTWriter<commit_after>//
//  SGDOTWriter.swift
//  SuperGraph
//
//  Created by <NAME> on 17/04/2015.
//  Copyright (c) 2015 bluetatami. All rights reserved.
//

import Foundation

public class SGDOTWriter {
    public static func writeGraph<N, E: Hashable>(graph: SGGraph<N,E>, withName name: String, toFile outputFileAddress: NSURL) {
        // If folder doesn't exist, create one
        if let folderPath = outputFileAddress.URLByDeletingLastPathComponent?.path {
            // check if element is a directory
            var isDirectory: ObjCBool = ObjCBool(false)
            // Mutates isDirectory pointer
            NSFileManager.defaultManager().fileExistsAtPath(folderPath, isDirectory: &isDirectory)
            
            if !isDirectory {
                var error: NSError?
                
                NSFileManager.defaultManager().createDirectoryAtPath(folderPath, withIntermediateDirectories: false, attributes: nil, error: &error)
            }
        }
        
        // Create new .dot file
        if let dotFilePath = outputFileAddress.path {
            let dotData = graph.dotDescriptionWithName(name).dataUsingEncoding(NSUTF8StringEncoding, allowLossyConversion: false)
            NSFileManager.defaultManager().createFileAtPath(dotFilePath, contents: dotData, attributes: nil)
        }
    }
}
{'fraction_non_alphanumeric': 0.09113764927718417, 'fraction_numerical': 0.01571338780641106, 'mean_word_length': 2.5615212527964206, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, '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': '5280024', 'n_tokens_mistral': 471, 'n_tokens_neox': 440, 'n_words': 116}