<commit_before>//
//  Classification.swift
//  NaturalLanguageClassifier
//
//  Created by <NAME> on 11/7/15.
//  Copyright © 2015 IBM. All rights reserved.
//

import Foundation
import ObjectMapper

public struct Classification: Mappable {

  var id: String?
  var url: String?
  var text: String?
  var topClass: String?
  var classes: [ClassifiedClass]?
  
  public init?(_ map: Map) {}
  
  public mutating func mapping(map: Map) {
    id        <- map["classifier_id"]
    text      <- map["text"]
    url       <- map["url"]
    topClass  <- map["top_class"]
    classes   <- map["classes"]
  }
}<commit_msg>IBM-MIL/Watson-iOS-SDK #82 - Natural Language Classifier - Add a topConfidence field for the Classification object  FIX: Added computed field that grabs the top confidence class and gets that confidence value.<commit_after>//
//  Classification.swift
//  NaturalLanguageClassifier
//
//  Created by <NAME> on 11/7/15.
//  Copyright © 2015 IBM. All rights reserved.
//

import Foundation
import ObjectMapper

public struct Classification: Mappable {
    var id: String?
    var url: String?
    var text: String?
    var topClass: String?
    var topConfidence: Double? {
        guard let classes = self.classes else {
            return nil
        }
        var double = 0.0
        for classifiedClass in classes {
            if(classifiedClass.name == topClass) {
                double = classifiedClass.confidence!
            }
        }
        return double
    }
    var classes: [ClassifiedClass]?
    
    public init?(_ map: Map) {}
    
    public mutating func mapping(map: Map) {
        id        <- map["classifier_id"]
        text      <- map["text"]
        url       <- map["url"]
        topClass  <- map["top_class"]
        classes   <- map["classes"]
    }
}
{'fraction_non_alphanumeric': 0.10839355197331851, 'fraction_numerical': 0.012229016120066704, 'mean_word_length': 2.225806451612903, 'pattern_counts': {'":': 0, '<': 15, '<?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': '827618', 'n_tokens_mistral': 558, 'n_tokens_neox': 515, 'n_words': 164}