<commit_before>import CoreData

public typealias Object = NSManagedObject

// MARK: kvc

extension Object
{
    public func value<Value>(set value: Value?, for key: String, transform: ((Value) -> Any?)? = nil) {
        if let value: Value = value, let transform: ((Value) -> Any?) = transform {
            self.setValue(transform(value), forKey: key)
        } else {
            self.setValue(value, forKey: key)
        }
    }

    public func value<Value>(for key: String) -> Value? {
        return self.value(forKey: key) as! Value?
    }

    public func value<Raw, Transformed>(for key: String, transform: ((Raw) -> Transformed?)?) -> Transformed? {
        let value: Raw? = self.value(forKey: key) as! Raw?

        if let value: Raw = value, let transform: ((Raw) -> Transformed?) = transform {
            return transform(value)
        } else {
            return value as! Transformed?
        }
    }
}

// MARK: relationship

extension Object
{

    /*
    Returns related models using model construction method in batch derived from specified batchable protocol.
    */
    open func relationship<T:BatchableProtocol>(for name: String) -> [T] {
        let batch: Batch<T> = T.Batch(models: []) as! Batch<T>
        var models: [T] = []

        for object in self.mutableSetValue(forKey: name).allObjects as! [Object] {
            let model: T = batch.construct(with: object)
            model.id = String(id: object.objectID)
            models.append(model)
        }

        return models
    }

    open func relationship<T:BatchableProtocol>(for name: String) -> T? {
        if let object: Object = self.value(for: name) {
            let batch: Batch<T> = T.Batch(models: []) as! Batch<T>
            let model: T = batch.construct(with: object)
            model.id = String(id: object.objectID)
            return model<commit_msg>Add raw object relationship accessor<commit_after>import CoreData

public typealias Object = NSManagedObject

// MARK: kvc

extension Object
{
    public func value<Value>(set value: Value?, for key: String, transform: ((Value) -> Any?)? = nil) {
        if let value: Value = value, let transform: ((Value) -> Any?) = transform {
            self.setValue(transform(value), forKey: key)
        } else {
            self.setValue(value, forKey: key)
        }
    }

    public func value<Value>(for key: String) -> Value? {
        return self.value(forKey: key) as! Value?
    }

    public func value<Raw, Transformed>(for key: String, transform: ((Raw) -> Transformed?)?) -> Transformed? {
        let value: Raw? = self.value(forKey: key) as! Raw?

        if let value: Raw = value, let transform: ((Raw) -> Transformed?) = transform {
            return transform(value)
        } else {
            return value as! Transformed?
        }
    }
}

// MARK: relationship

extension Object
{
    @nonobjc open func relationship(for name: String) -> [Object] {
        return self.mutableSetValue(forKey: name).allObjects as! [Object]
    }

    @nonobjc open func relationship(for name: String) -> Object? {
        return self.value(forKey: name) as! Object?
    }

    // MARK: -

    /*
    Returns related models using model construction method in batch derived from specified batchable protocol.
    */
    open func relationship<Model:BatchableProtocol>(for name: String) -> [Model] {
        let batch: Batch<Model> = Model.Batch(models: []) as! Batch<Model>
        var models: [Model] = []

        for object in self.mutableSetValue(forKey: name).allObjects as! [Object] {
            let model: Model = batch.construct(with: object)
            model.id = String(id: object.objectID)
            models.append(model)
        }

        return models
    }

    open func relationship<Model:BatchableProtocol>(for name: String) -> Model? {
        if let object: Object = self.value(for: name) {
            let batch: Batch<Model> = Model.Batch(models: []) as! Batch<Model>
            let model: Model = batch.construct(with: object)
            model.id = String(id: object.objectID)
            return model
{'fraction_non_alphanumeric': 0.12197506722072843, 'fraction_numerical': 0.0, 'mean_word_length': 2.456081081081081, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 39, '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': '4988355', 'n_tokens_mistral': 1177, 'n_tokens_neox': 1162, 'n_words': 354}