<commit_before>//
//  Article.swift
//  Artikolo
//
//  Created by <NAME> on 5/13/17.
//  Copyright © 2017 <NAME>. All rights reserved.
//

import Foundation

struct Article {
    
    let url: URL
    
}

extension Article: Equatable {
    
    public static func ==(lhs: Article, rhs: Article) -> Bool {
        return lhs.url == rhs.url
    }
    
}<commit_msg>Add JSON parsing for an Article.<commit_after>//
//  Article.swift
//  Artikolo
//
//  Created by <NAME> on 5/13/17.
//  Copyright © 2017 <NAME>. All rights reserved.
//

import Foundation

struct Article {
    
    let url: URL
    
}

extension Article: Equatable {
    
    public static func ==(lhs: Article, rhs: Article) -> Bool {
        return lhs.url == rhs.url
    }
    
}

enum JSONError: Error {
    
    case invalidValue(keypath: String)
    case incorrectType(keyPath: String)
    
}

extension Article {
    
    static func parse(JSON: [String: Any]) throws -> Article {
        guard let urlString = JSON["url"] as? String else { throw JSONError.invalidValue(keypath: "url") }
        guard let url = URL(string: urlString) else { throw JSONError.incorrectType(keyPath: "url") }
        
        return Article(url: url)
    }
    
}
{'fraction_non_alphanumeric': 0.1225328947368421, 'fraction_numerical': 0.014802631578947368, 'mean_word_length': 2.271505376344086, 'pattern_counts': {'":': 0, '<': 7, '<?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': '4082173', 'n_tokens_mistral': 408, 'n_tokens_neox': 385, 'n_words': 117}