<commit_before>:- module(merge_json, [ merge_json/3, merge_json/4, merge_facets/3, merge_facet/4 ]).
:- use_module(helpers).


/**
 * merge_json/4
 * merge_json(JSON1,JSON2,Merged,On_Conflict)
 *
 * Merge two JSON values.
 *
 * On_Conflict:
 *   - 0/hard: fail
 *   - 9/soft: rename keys in objects if the occure multiple
 *           times
 *
 * Exampes:
 *   merge_json(json([type=1]), json([type=1]), json([type=1]), _).
 *   merge_json(json([type=1]), json([type=2]), Merged, soft).
 */
merge_json(JSON1,JSON2,Merged,soft) :- merge_json(JSON1,JSON2,Merged,9).
merge_json(JSON1,JSON2,Merged,hard) :- merge_json(JSON1,JSON2,Merged,0).

merge_json(JSON1,JSON2,_Merged,_On_Conflict) :- (var(JSON1); var(JSON2)), !, false.

merge_json(json([]),json(JSON_List2),json(JSON_List2),_On_Conflict) :- !.
merge_json(json(JSON_List1),json([]),json(JSON_List1),_On_Conflict) :- !.

merge_json(json(['$ref'=Ref]),json(JSON_List2),json(Merged),On_Conflict) :-
  % Avoid combining "$ref" with other properties (c.f. http://json-schema.org/latest/json-schema-core.html#rfc.section.7)
  AllOf = json([
    allOf= [
      json([
        '$ref'= Ref
      ])
    ]
  ]),
  merge_json(AllOf,json(JSON_List2),json(Merged),On_Conflict).
merge_json(json(JSON_List1),json(['$ref'=Ref]),json(Merged),On_Conflict) :-
  % Avoid combining "$ref" with other properties (c.f. http://json-schema.org/latest/json-schema-core.html#rfc.section.7)
  AllOf = json([
    allOf= [
      json([
        '$ref'= Ref
      ])
    ]<commit_msg>Spelling<commit_after>:- module(merge_json, [ merge_json/3, merge_json/4, merge_facets/3, merge_facet/4 ]).
:- use_module(helpers).


/**
 * merge_json/4
 * merge_json(JSON1,JSON2,Merged,On_Conflict)
 *
 * Merge two JSON values.
 *
 * On_Conflict:
 *   - 0/hard: fail
 *   - 9/soft: rename keys in objects if they occur multiple times
 *
 * Exampes:
 *   merge_json(json([type=1]), json([type=1]), json([type=1]), _).
 *   merge_json(json([type=1]), json([type=2]), Merged, soft).
 */
merge_json(JSON1,JSON2,Merged,soft) :- merge_json(JSON1,JSON2,Merged,9).
merge_json(JSON1,JSON2,Merged,hard) :- merge_json(JSON1,JSON2,Merged,0).

merge_json(JSON1,JSON2,_Merged,_On_Conflict) :- (var(JSON1); var(JSON2)), !, false.

merge_json(json([]),json(JSON_List2),json(JSON_List2),_On_Conflict) :- !.
merge_json(json(JSON_List1),json([]),json(JSON_List1),_On_Conflict) :- !.

merge_json(json(['$ref'=Ref]),json(JSON_List2),json(Merged),On_Conflict) :-
  % Avoid combining "$ref" with other properties (c.f. http://json-schema.org/latest/json-schema-core.html#rfc.section.7)
  AllOf = json([
    allOf= [
      json([
        '$ref'= Ref
      ])
    ]
  ]),
  merge_json(AllOf,json(JSON_List2),json(Merged),On_Conflict).
merge_json(json(JSON_List1),json(['$ref'=Ref]),json(Merged),On_Conflict) :-
  % Avoid combining "$ref" with other properties (c.f. http://json-schema.org/latest/json-schema-core.html#rfc.section.7)
  AllOf = json([
    allOf= [
      json([
        '$ref'= Ref
      ])
    ]
{'fraction_non_alphanumeric': 0.19498327759197323, 'fraction_numerical': 0.024749163879598662, 'mean_word_length': 4.488073394495413, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '6498277', 'n_tokens_mistral': 1198, 'n_tokens_neox': 1170, 'n_words': 150}