<commit_before>//
//  NSObject+OOModel.h
//  OOModel
//

#import <Foundation/Foundation.h>
#import "OOModelInfo.h"

extern const NSString * oo_compaction_prefix;
/**
 *  compact property key to column.
 *  e.g.
 *
 *  NSArray * models = [oo_modelsWithAfterWhereSql:[NSString stringWithFormat:@"%@ like ?",OOCOMPACT(@"keyword")] arguments:@[@"world"]];
 */
#define OOCOMPACT(tableorcolumn) [NSString stringWithFormat:@"%@%@",oo_compaction_prefix,tableorcolumn]

@protocol OOUniqueModel<NSObject>
/**
 *  this value is used by maptable and db.
 *
 *  @return unique value.
 */
+ (NSString*)uniquePropertyKey;

@end

@protocol OOJsonModel <NSObject>
/**
 *  mapping property key to json keyPath.
 *
 *  @return a mapping dictionary.
 */
+ (NSDictionary*)jsonKeyPathsByPropertyKeys;

@optional
/**
 *  if OOModel do not support this property,you should implementation this method.
 *
 *  @param propertyKey target property key
 *
 *  @return value trasformer.
 */
+ (NSValueTransformer*)jsonValueTransformerForPropertyKey:(NSString*)propertyKey;

@end

@protocol OODbModel <NSObject>
/**
 *  which property should be cached to db;
 *
 *  @return property keys array.
 */
+ (NSArray*)dbColumnsInPropertyKeys;

@optional
/**
 *  if OOModel do not support this property,you should implementation this method.
 *
 *  @param propertyKey target property key.
 *
 *  @return value trasformer.
 */
+ (NSValueTransformer*)dbValueTransformerForPropertyKey:(NSString*)propertyKey;
/**
 *  if OOmodel do not recognize this property,you should implementation this method.
 *
 *  @param propertyKey target property key.
 *
 *  @return column type.
 */
+ (OODbColumnType)dbColumnTypeForPropertyKey:(NSString*)propertyKey;

/**
 *  which property key should be indexed in db.
 *
 *  @return array of indexed property key.
 */
+ (NSArray*)dbIndexesInPropertyKeys;

@end

@interface NSObject (OOModel)

@property (nonatomic,copy,readonly) NSDictionary *oo_jsonDictionary;

@property (nonatomic,copy,readonly) NSString     *oo_jsonString;

@property (nonatomic,assign,readonly) bool       oo_isReplaced;

+ (NSArray*)oo_modelsWithJsonDictionaries:(NSArray*)jsonDictionaries;
/**
 *  model from json.
 *
 *  @param  dictionary or json string.
 *
 *  @return instance
 */
+ (instancetype)oo_modelWithJson:(id)json;
/**
 *  if model's class conform to protocol OOUniqueModel,
 *
 *  @param value unique value
 *
 *  @return instance
 */
+ (instancetype)oo_modelWithUniqueValue:(id)value;

/*
 *  e.g.
 *
 *  NSArray * models = [oo_modelsWithAfterWhereSql:[NSString stringWithFormat:@"%@ like ?",OOCOMPACT(@"keyword")] arguments:@[@"world"]];
 */
+ (NSArray *)oo_modelsWithAfterWhereSql:(NSString*)afterWhereSql arguments:(NSArray*)arguments;
/**
 *  merge model with json.if model conforms to OOUniqueModel,but json has a different unique value,it will occur a error.
 *
 *  @param json 
 */
- (void)oo_mergeWithJson:(id)json;
/**
 *  if model class conforms to OODbModel,should open a db at first.
 *
 *  @param file db file path.
 *
 *  @return result
 */
+ (BOOL)oo_openDb:(NSString*)file;

+ (void)oo_deleteModelsBeforeDate:(NSDate*)date;
/**
 *
 *
 *  @return class info of this class.
 */
+ (OOClassInfo*)oo_classInfo;

- (void)oo_modelEncode:(NSCoder *)aCoder;

- (id)oo_modelDecode:(NSCoder *)aDecoder;
@end
<commit_msg>fix bugs<commit_after>//
//  NSObject+OOModel.h
//  OOModel
//

#import <Foundation/Foundation.h>
#import "OOModelInfo.h"

extern const NSString * oo_compaction_prefix;
/**
 *  compact property key to column.
 *  e.g.
 *
 *  NSArray * models = [oo_modelsWithAfterWhereSql:[NSString stringWithFormat:@"%@ like ?",OOCOMPACT(@"keyword")] arguments:@[@"world"]];
 */
#define OOCOMPACT(tableorcolumn) [NSString stringWithFormat:@"%@%@",oo_compaction_prefix,tableorcolumn]

@protocol OOUniqueModel<NSObject>
/**
 *  this value is used by maptable and db.
 *
 *  @return unique value.
 */
+ (NSString*)uniquePropertyKey;

@end

@protocol OOJsonModel <NSObject>
/**
 *  mapping property key to json keyPath.
 *
 *  @return a mapping dictionary.
 */
+ (NSDictionary*)jsonKeyPathsByPropertyKeys;

@optional
/**
 *  if OOModel do not support this property,you should implementation this method.
 *
 *  @param propertyKey target property key
 *
 *  @return value trasformer.
 */
+ (NSValueTransformer*)jsonValueTransformerForPropertyKey:(NSString*)propertyKey;

@end

@protocol OODbModel <NSObject>
/**
 *  which property should be cached to db;
 *
 *  @return property keys array.
 */
+ (NSArray*)dbColumnsInPropertyKeys;

@optional
/**
 *  if OOModel do not support this property,you should implementation this method.
 *
 *  @param propertyKey target property key.
 *
 *  @return value trasformer.
 */
+ (NSValueTransformer*)dbValueTransformerForPropertyKey:(NSString*)propertyKey;
/**
 *  if OOmodel do not recognize this property,you should implementation this method.
 *
 *  @param propertyKey target property key.
 *
 *  @return column type.
 */
+ (OODbColumnType)dbColumnTypeForPropertyKey:(NSString*)propertyKey;

/**
 *  which property key should be indexed in db.
 *
 *  @return array of indexed property key.
 */
+ (NSArray*)dbIndexesInPropertyKeys;

@end

@interface NSObject (OOModel)

@property (nonatomic,copy,readonly) NSDictionary *oo_jsonDictionary;

@property (nonatomic,copy,readonly) NSString     *oo_jsonString;

@property (nonatomic,assign,readonly) bool       oo_isReplaced;

+ (NSArray*)oo_modelsWithJsonDictionaries:(NSArray*)jsonDictionaries;
/**
 *  model from json.
 *
 *  @param  dictionary or json string.
 *
 *  @return instance
 */
+ (instancetype)oo_modelWithJson:(id)json;
/**
 *  if model's class conform to protocol OOUniqueModel,
 *
 *  @param value unique value
 *
 *  @return instance
 */
+ (instancetype)oo_modelWithUniqueValue:(id)value;

/*
 *  e.g.
 *
 *  NSArray * models = [oo_modelsWithAfterWhereSql:[NSString stringWithFormat:@"%@ like ?",OOCOMPACT(@"keyword")] arguments:@[@"world"]];
 */
+ (NSArray *)oo_modelsWithAfterWhereSql:(NSString*)afterWhereSql arguments:(NSArray*)arguments;
/**
 *  merge model with json.if model conforms to OOUniqueModel,but json has a different unique value,it will occur a error.
 *
 *  @param json 
 */
- (void)oo_mergeWithJson:(id)json;
/**
 *  if model class conforms to OODbModel,should open a db at first.All models use the same db.
 *
 *  @param file db file path.
 *
 *  @return result
 */
+ (BOOL)oo_openDb:(NSString*)file;

+ (void)oo_deleteModelsBeforeDate:(NSDate*)date;
/**
 *
 *
 *  @return class info of this class.
 */
+ (OOClassInfo*)oo_classInfo;

- (void)oo_modelEncode:(NSCoder *)aCoder;

- (id)oo_modelDecode:(NSCoder *)aDecoder;
@end

{'fraction_non_alphanumeric': 0.13205553878659826, 'fraction_numerical': 0.0, 'mean_word_length': 4.762608695652174, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 11, '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': '3609071', 'n_tokens_mistral': 2221, 'n_tokens_neox': 2148, 'n_words': 518}