<commit_before>//
//  VKItem.swift
//  vkclient
//
//  Created by <NAME> on 10.03.16.
//  Copyright © 2016 <NAME>. All rights reserved.
//

import Foundation
import VK_ios_sdk

class VKItem: JSONConvertable {
    
    var type: String //TODO: to enum
    var sourceId: Int
    var date: NSDate
    var postId: Int
    var postType: String //TODO: to enum
    var text: String
    var friendsOnly : Bool
    //TODO var attachments
    //TODO post_source, likes, reposts
    var attacments: [VKApiObject] = []
    
    
    required init(withJSON json: NSDictionary) {
        type = json.parseField(withName: "type", defaultValue: "")
        sourceId = json.parseField(withName: "source_id", defaultValue: 0)
        date = NSDate(timeIntervalSince1970: json.parseField(withName: "date", defaultValue: 0.0))
        postId = json.parseField(withName: "post_id", defaultValue: 0)
        postType = json.parseField(withName: "post_type", defaultValue: "")
        text = json.parseField(withName: "text", defaultValue: "")
        friendsOnly = Bool.init(json.parseField(withName: "friends_only", defaultValue: 0))
        
        let attachmentsArray = json.parseField(withName: "attachments", defaultValue: NSArray())
        for item in attachmentsArray {
            if let attachment = item as? NSDictionary {
                let attachmentType = attachment["type"] as! NSString
                
                switch attachmentType {
                case "photo":
                    attacments.append(VKPhoto.init(dictionary: attachment["photo"] as! [NSObject : AnyObject]))
                case "audio":
                    attacments.append(VKAudio.init(dictionary: attachment["audio"] as! [NSObject : AnyObject]))
                default: break
                }
            }
        }
    }
    
    public func haveText() -> bool {
        return text != ""
    }
    
    
}<commit_msg>Help functions<commit_after>//
//  VKItem.swift
//  vkclient
//
//  Created by <NAME> on 10.03.16.
//  Copyright © 2016 <NAME>. All rights reserved.
//

import Foundation
import VK_ios_sdk

class VKItem: JSONConvertable {
    
    var type: String //TODO: to enum
    var sourceId: Int
    var date: NSDate
    var postId: Int
    var postType: String //TODO: to enum
    var text: String
    var friendsOnly : Bool
    //TODO var attachments
    //TODO post_source, likes, reposts
    var attacments: [VKApiObject] = []
    
    
    required init(withJSON json: NSDictionary) {
        type = json.parseField(withName: "type", defaultValue: "")
        sourceId = json.parseField(withName: "source_id", defaultValue: 0)
        date = NSDate(timeIntervalSince1970: json.parseField(withName: "date", defaultValue: 0.0))
        postId = json.parseField(withName: "post_id", defaultValue: 0)
        postType = json.parseField(withName: "post_type", defaultValue: "")
        text = json.parseField(withName: "text", defaultValue: "")
        friendsOnly = Bool.init(json.parseField(withName: "friends_only", defaultValue: 0))
        
        let attachmentsArray = json.parseField(withName: "attachments", defaultValue: NSArray())
        for item in attachmentsArray {
            if let attachment = item as? NSDictionary {
                let attachmentType = attachment["type"] as! NSString
                
                switch attachmentType {
                case "photo":
                    attacments.append(VKPhoto.init(dictionary: attachment["photo"] as! [NSObject : AnyObject]))
                case "audio":
                    attacments.append(VKAudio.init(dictionary: attachment["audio"] as! [NSObject : AnyObject]))
                default: break
                }
            }
        }
    }
    
    internal func haveText() -> Bool {
        return text != ""
    }
    
    internal func getFirstPhotoIfExist() -> VKPhoto? {
        if (attacments.count > 0) {
            if let photo = attacments.first as? VKPhoto {
                return photo
            }
        }
        
        return nil
    }
    
}
{'fraction_non_alphanumeric': 0.1078940856223707, 'fraction_numerical': 0.009651076466221232, 'mean_word_length': 2.138198757763975, 'pattern_counts': {'":': 4, '<': 7, '<?xml version=': 0, '>': 11, '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': '6791151', 'n_tokens_mistral': 1213, 'n_tokens_neox': 1144, 'n_words': 300}