<commit_before>//
//  NestedQuery.swift
//  Tongs
//
//  Created by suguru-kishimoto on 2017/08/23.
//  Copyright © 2017年 <NAME>. All rights reserved.
//

import Foundation

public protocol HasParameter: class {
    func add(_ parameter: QueryParameter)
}

extension HasParameter {
    public func term(_ key: String, _ value: QueryValue) -> Self {
        add(Tongs.Parameter.Term(key: key, value: value))
        return self
    }

    public func term<K, V: QueryValue>(_ keypath: KeyPath<K, V>, _ value: V) -> Self {
        return term(keypath._kvcKeyPathString!, value)
    }

    public func terms(_ key: String, _ values: [QueryValue]) -> Self {
        add(Tongs.Parameter.Terms(key: key, values: values))
        return self
    }

    public func terms<K, V: QueryValue>(_ keypath: KeyPath<K, V>, _ values: [V]) -> Self {
        return terms(keypath._kvcKeyPathString!, values)
    }

    public func range(_ key: String, _ condition: Tongs.Parameter.Range.Condition) -> Self {
        return range(key, [condition])
    }

    public func range<K, V: QueryNumberValue>(_ keypath: KeyPath<K, V>, _ condition: Tongs.Parameter.Range.Condition) -> Self {
        return range(keypath._kvcKeyPathString!, condition)
    }

    public func range(_ key: String, _ conditions: [Tongs.Parameter.Range.Condition]) -> Self {
        add(Tongs.Parameter.Range(key: key, conditions: conditions))
        return self
    }

    public func range<K, V: QueryNumberValue>(_ keypath: KeyPath<K, V>, _ conditions: [Tongs.Parameter.Range.Condition]) -> Self {
        return range(keypath._kvcKeyPathString!, conditions)
    }
}<commit_msg>Support Optional KeyPath.<commit_after>//
//  NestedQuery.swift
//  Tongs
//
//  Created by suguru-kishimoto on 2017/08/23.
//  Copyright © 2017年 <NAME>. All rights reserved.
//

import Foundation

public protocol HasParameter: class {
    func add(_ parameter: QueryParameter)
}

extension HasParameter {
    public func term(_ key: String, _ value: QueryValue) -> Self {
        add(Tongs.Parameter.Term(key: key, value: value))
        return self
    }

    public func term<K, V: QueryValue>(_ keypath: KeyPath<K, V>, _ value: V) -> Self {
        return term(keypath._kvcKeyPathString!, value)
    }

    public func term<K, V: QueryValue>(_ keypath: KeyPath<K, V?>, _ value: V) -> Self {
        return term(keypath._kvcKeyPathString!, value)
    }

    public func terms(_ key: String, _ values: [QueryValue]) -> Self {
        add(Tongs.Parameter.Terms(key: key, values: values))
        return self
    }

    public func terms<K, V: QueryValue>(_ keypath: KeyPath<K, V>, _ values: [V]) -> Self {
        return terms(keypath._kvcKeyPathString!, values)
    }

    public func terms<K, V: QueryValue>(_ keypath: KeyPath<K, V?>, _ values: [V]) -> Self {
        return terms(keypath._kvcKeyPathString!, values)
    }

    public func range(_ key: String, _ condition: Tongs.Parameter.Range.Condition) -> Self {
        return range(key, [condition])
    }

    public func range<K, V: QueryNumberValue>(_ keypath: KeyPath<K, V>, _ condition: Tongs.Parameter.Range.Condition) -> Self {
        return range(keypath._kvcKeyPathString!, condition)
    }

    public func range<K, V: QueryNumberValue>(_ keypath: KeyPath<K, V?>, _ condition: Tongs.Parameter.Range.Condition) -> Self {
        return range(keypath._kvcKeyPathString!, condition)
    }

    public func range(_ key: String, _ conditions: [Tongs.Parameter.Range.Condition]) -> Self {
        add(Tongs.Parameter.Range(key: key, conditions: conditions))
        return self
    }

    public func range<K, V: QueryNumberValue>(_ keypath: KeyPath<K, V>, _ conditions: [Tongs.Parameter.Range.Condition]) -> Self {
        return range(keypath._kvcKeyPathString!, conditions)
    }

    public func range<K, V: QueryNumberValue>(_ keypath: KeyPath<K, V?>, _ conditions: [Tongs.Parameter.Range.Condition]) -> Self {
        return range(keypath._kvcKeyPathString!, conditions)
    }

}
{'fraction_non_alphanumeric': 0.12879738890283707, 'fraction_numerical': 0.006025608837559628, 'mean_word_length': 3.1717277486910995, 'pattern_counts': {'":': 0, '<': 29, '<?xml version=': 0, '>': 49, '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': '6169657', 'n_tokens_mistral': 1299, 'n_tokens_neox': 1219, 'n_words': 330}