<commit_before>//
//  ElloLinkedStore.swift
//  Ello
//
//  Created by Sean on 1/26/15.
//  Copyright (c) 2015 Ello. All rights reserved.
//

import Foundation

var Store = ElloLinkedStore()

struct ElloLinkedStore {

    var store = [String:[String:AnyObject]]()

    mutating func parseLinked(linked:[String:[[String:AnyObject]]]){
        for (type:String, typeObjects:[[String:AnyObject]]) in linked {
            if store[type] == nil {
                store[type] = [String:AnyObject]()
            }
            for object:[String:AnyObject] in typeObjects {
                store[type]?[object["id"] as String] = object
            }
        }
    }

     static func parseLinks(links: [String: AnyObject]) -> [String: AnyObject] {
        var modelLinks = [String: AnyObject]()
        for (key, value) in links {
            if let link:String = value["type"] as? String {
                if let mappingType = MappingType(rawValue: value["type"] as String) {
                    if let linkJSON = Store.store[link]?[value["id"] as String] as? [String: AnyObject] {
                        var jsonable: JSONAble = mappingType.fromJSON(data: linkJSON)
                        modelLinks[key] = jsonable
                    }
                }
            }
            else if let link:String = value as? String {
                if let mappingType = MappingType(rawValue: key) {
                    if let linkJSON = Store.store[key]?[link] as? [String: AnyObject] {
                        var jsonable: JSONAble = mappingType.fromJSON(data: linkJSON)
                        modelLinks[key] = jsonable
                    }
                }
            }
            else if let strArray = links[key] as? [String] {
                if let mappingType = MappingType(rawValue: key) {
                    if mappingType.isOrdered {
                        var linkArray = [JSONAble]()
                        for str in strArray {
                            if let linkJSON = Store.store[key]?[str] as? [String: AnyObject] {
                                let linkModel = mappingType.fromJSON(data: linkJSON)
//                                let user = model as? User
//                                let post = linkModel  as? Post
//                                if user != nil && post != nil {
//                                    post!.author = user!
//                                }
                                linkArray.append(linkModel)
                            }
                        }
                        modelLinks[key] = linkArray
                    }
                    else {
                        var linkDict = [String: JSONAble]()
                        for link: String in strArray {
                            if let linkJSON = Store.store[key]?[link] as? [String: AnyObject] {
                                let linkModel = mappingType.fromJSON(data: linkJSON)
                                linkDict[link] = linkModel
                            }
                        }
                        modelLinks[key] = linkDict
                    }
                }
            }
        }
        return modelLinks
    }

}<commit_msg>Fixes post loading for users.<commit_after>//
//  ElloLinkedStore.swift
//  Ello
//
//  Created by Sean on 1/26/15.
//  Copyright (c) 2015 Ello. All rights reserved.
//

import Foundation

var Store = ElloLinkedStore()

struct ElloLinkedStore {

    var store = [String:[String:AnyObject]]()

    mutating func parseLinked(linked:[String:[[String:AnyObject]]]){
        for (type:String, typeObjects:[[String:AnyObject]]) in linked {
            if store[type] == nil {
                store[type] = [String:AnyObject]()
            }
            for object:[String:AnyObject] in typeObjects {
                store[type]?[object["id"] as String] = object
            }
        }
    }

     static func parseLinks(links: [String: AnyObject]) -> [String: AnyObject] {
        var modelLinks = [String: AnyObject]()
        for (key, value) in links {
            if let link:String = value["type"] as? String {
                if let mappingType = MappingType(rawValue: value["type"] as String) {
                    if let linkJSON = Store.store[link]?[value["id"] as String] as? [String: AnyObject] {
                        var jsonable: JSONAble = mappingType.fromJSON(data: linkJSON)
                        modelLinks[key] = jsonable
                    }
                }
            }
            else if let link:String = value as? String {
                if let mappingType = MappingType(rawValue: key) {
                    if let linkJSON = Store.store[key]?[link] as? [String: AnyObject] {
                        var jsonable: JSONAble = mappingType.fromJSON(data: linkJSON)
                        modelLinks[key] = jsonable
                    }
                }
            }
            else if let strArray = links[key] as? [String] {
                modelLinks = parseArray(key, strArray: strArray, modelLinks: modelLinks)
            }
            else if let strArray = links[key]?["ids"] as? [String] {
                modelLinks = parseArray(key, strArray: strArray, modelLinks: modelLinks)
            }
        }
        return modelLinks
    }

    static func parseArray(key: String, strArray: [String], modelLinks: [String: AnyObject]) -> [String: AnyObject] {
        var modelLinksCopy = modelLinks
        if let mappingType = MappingType(rawValue: key) {
            if mappingType.isOrdered {
                var linkArray = [JSONAble]()
                for str in strArray {
                    if let linkJSON = Store.store[key]?[str] as? [String: AnyObject] {
                        let linkModel = mappingType.fromJSON(data: linkJSON)
                        linkArray.append(linkModel)
                    }
                }
                modelLinksCopy[key] = linkArray
            }
            else {
                var linkDict = [String: JSONAble]()
                for link: String in strArray {
                    if let linkJSON = Store.store[key]?[link] as? [String: AnyObject] {
                        let linkModel = mappingType.fromJSON(data: linkJSON)
                        linkDict[link] = linkModel
                    }
                }
                modelLinksCopy[key] = linkDict
            }
        }
        return modelLinksCopy
    }

}
{'fraction_non_alphanumeric': 0.09859594383775351, 'fraction_numerical': 0.0028081123244929796, 'mean_word_length': 1.3253536452665942, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 6, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 10, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3379732', 'n_tokens_mistral': 1704, 'n_tokens_neox': 1607, 'n_words': 414}