<commit_before>//
//  NSManagedObject+Extensions.swift
//  SnapStack
//
//  Created by <NAME> on 2015-09-17.
//  Copyright © 2015 <NAME>. All rights reserved.
//

import Foundation
import CoreData

internal extension NSManagedObject {
    internal class func entityName() -> String {
        return  NSStringFromClass(self).componentsSeparatedByString(".").last!
    }
}

internal extension NSManagedObject {
    internal func inContext<T: NSManagedObject>(context: NSManagedObjectContext) -> T? {
        if self.managedObjectContext === context { return self as? T }
        
        if objectID.temporaryID {
            do {
                try withExtendedLifetime(managedObjectContext) {
                    return try managedObjectContext?.obtainPermanentIDsForObjects([self])
                }
            }
            catch let nsError as NSError {
                print("NSManagedObject.inContext(): \(nsError)")
                return nil
            }
        }
        
        do {
            return try context.existingObjectWithID(objectID) as? T
        }
        catch let nsError as NSError {
            print("NSManagedObject.inContext(): \(nsError)")
            return nil
        }
    }
}

public extension NSManagedObject {
    public func deleteFromContext() {
        managedObjectContext?.deleteObject(self)
    }
}<commit_msg>added nsExpression for constant values<commit_after>//
//  NSManagedObject+Extensions.swift
//  SnapStack
//
//  Created by <NAME> on 2015-09-17.
//  Copyright © 2015 <NAME>. All rights reserved.
//

import Foundation
import CoreData

internal extension NSManagedObject {
    internal class func entityName() -> String {
        return  NSStringFromClass(self).componentsSeparatedByString(".").last!
    }
}

internal extension NSManagedObject {
    internal func inContext<T: NSManagedObject>(context: NSManagedObjectContext) -> T? {
        if self.managedObjectContext === context { return self as? T }
        
        if objectID.temporaryID {
            do {
                try withExtendedLifetime(managedObjectContext) {
                    return try managedObjectContext?.obtainPermanentIDsForObjects([self])
                }
            }
            catch let nsError as NSError {
                print("NSManagedObject.inContext(): \(nsError)")
                return nil
            }
        }
        
        do {
            return try context.existingObjectWithID(objectID) as? T
        }
        catch let nsError as NSError {
            print("NSManagedObject.inContext(): \(nsError)")
            return nil
        }
    }
}

public extension NSManagedObject {
    public func deleteFromContext() {
        managedObjectContext?.deleteObject(self)
    }
}

public extension NSManagedObject {
    static func nsExpression(value: NSManagedObject?) -> NSExpression {
        if let actual = value {
            return NSExpression(forConstantValue: actual)
        }
        else {
            return NSExpression(forConstantValue: NSNull())
        }
    }
}
{'fraction_non_alphanumeric': 0.08908612754766601, 'fraction_numerical': 0.007889546351084813, 'mean_word_length': 2.086206896551724, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 14, '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': '3829234', 'n_tokens_mistral': 815, 'n_tokens_neox': 767, 'n_words': 191}