<commit_before>//
//  JsonUtil.swift
//  OralWar
//
//  Created by MrSmall on 2015/09/30.
//  Copyright © 2015年 MrSmall. All rights reserved.
//

import Foundation

let TYPE: String = "json"

// extension : add isEmpty func
extension NSData {
    
    func isEmpty() -> Bool {
        return self.length == 0
    }
}

class JsonUtil {
    
    var jsonData: NSDictionary!
    
    init () {
        
    }
    
    // get json data from resource
    func getJsonDataFromResource(fileName: String) -> NSData {
        
        guard let path = NSBundle.mainBundle().pathForResource(fileName, ofType: TYPE) else {
            return NSData()
        }
        guard let fileHandle: NSFileHandle = NSFileHandle(forReadingAtPath: path) else {
            return NSData()
        }
        return fileHandle.readDataToEndOfFile()
    }
    
    // parse json data
    func parse(data: NSData) -> Bool {
        
        do {
            jsonData = try NSJSONSerialization.JSONObjectWithData(
                data, options: NSJSONReadingOptions.AllowFragments) as! NSDictionary
        } catch  {
            return false
        }
        return true
    }
}<commit_msg>Added getJsonDataFromUrl func<commit_after>//
//  JsonUtil.swift
//  OralWar
//
//  Created by MrSmall on 2015/09/30.
//  Copyright © 2015年 MrSmall. All rights reserved.
//

import Foundation

let TYPE: String = "json"

// extension : add isEmpty func
extension NSData {
    
    func isEmpty() -> Bool {
        return self.length == 0
    }
}

class JsonUtil {
    
    var jsonData: NSDictionary!
    
    init () {
        
    }
    
    // get json data from resource
    func getJsonDataFromResource(fileName: String) -> NSData {
        
        guard let path = NSBundle.mainBundle().pathForResource(fileName, ofType: TYPE) else {
            return NSData()
        }
        guard let fileHandle: NSFileHandle = NSFileHandle(forReadingAtPath: path) else {
            return NSData()
        }
        return fileHandle.readDataToEndOfFile()
    }
    
    // get json data from url
    func getJsonDataFromUrl(url: String) -> NSData {
        
        let _url = NSURL(string: url)
        print(_url)
        return NSData()
    }
    
    // parse json data
    func parse(data: NSData) -> Bool {
        
        do {
            jsonData = try NSJSONSerialization.JSONObjectWithData(
                data, options: NSJSONReadingOptions.AllowFragments) as! NSDictionary
        } catch  {
            return false
        }
        return true
    }
}
{'fraction_non_alphanumeric': 0.08968787040695378, 'fraction_numerical': 0.010272619517977083, 'mean_word_length': 1.8164627363737487, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 10, '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': '492692', 'n_tokens_mistral': 764, 'n_tokens_neox': 734, 'n_words': 196}