<commit_before>//
//  Entity.swift
//  Moulin
//
//  Created by asai.yuki on 2015/12/27.
//  Copyright © 2015年 yukiasai. All rights reserved.
//

import Foundation

class Entity: JSONConvertible, ValueType {
    typealias ReflectedProperty = (label: String, property: PropertyType)
    
    required init() { }
    
    convenience init(json: AnyObject) {
        self.init()
        fromJSON(json)
    }
    
    private lazy var reflectedProperties: [ReflectedProperty] = {
        return Mirror(reflecting: self).children.filter { $1 is PropertyType }.flatMap { ($0!, $1 as! PropertyType) }
    }()
    
    func fromJSON(json: AnyObject) {
        guard let dic = json as? [String: AnyObject] else {
            // TODO: Imp not dictionary case
            return
        }
        reflectedProperties.forEach {
            let key = $1.keyWith($0)
            if let value = dic[key] {
                $1.fromJSON(value)
            }
        }
    }
    
    func toJSON() -> AnyObject? {<commit_msg>Modify access control of Entity to public.<commit_after>//
//  Entity.swift
//  Moulin
//
//  Created by asai.yuki on 2015/12/27.
//  Copyright © 2015年 yukiasai. All rights reserved.
//

import Foundation

public class Entity: JSONConvertible, ValueType {
    typealias ReflectedProperty = (label: String, property: PropertyType)
    
    required public init() { }
    
    convenience init(json: AnyObject) {
        self.init()
        fromJSON(json)
    }
    
    private lazy var reflectedProperties: [ReflectedProperty] = {
        return Mirror(reflecting: self).children.filter { $1 is PropertyType }.flatMap { ($0!, $1 as! PropertyType) }
    }()
    
    public func fromJSON(json: AnyObject) {
        guard let dic = json as? [String: AnyObject] else {
            // TODO: Imp not dictionary case
            return
        }
        reflectedProperties.forEach {
            let key = $1.keyWith($0)
            if let value = dic[key] {
                $1.fromJSON(value)
            }
        }
    }
    
    public func toJSON() -> AnyObject? {
{'fraction_non_alphanumeric': 0.1097148380860319, 'fraction_numerical': 0.017399710004833254, 'mean_word_length': 1.9913294797687862, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, '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': '4849628', 'n_tokens_mistral': 630, 'n_tokens_neox': 607, 'n_words': 168}