2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
|
# File 'lib/wikidata/diff/inside_claim_analyzer.rb', line 2
def self.isolate_inside_claim_differences(current_content, parent_content)
added = []
removed = []
changed = []
if current_content.nil?
current_content_claims = {}
else
current_content_claims = current_content["claims"]
if !current_content_claims.is_a?(Hash)
current_content_claims = {}
end
end
if parent_content.nil?
parent_content_claims = {}
else
parent_content_claims = parent_content["claims"]
if !parent_content_claims.is_a?(Hash)
parent_content_claims = {}
end
end
if parent_content.nil?
current_content_claims.each do |claim_key, current_claims|
current_claims.each_with_index do |current_claim, index|
added << { key: claim_key, index: index }
end
end
else
current_content_claims.each do |claim_key, current_claims|
if parent_content_claims.key?(claim_key)
parent_claims = parent_content_claims[claim_key]
current_claims.each_with_index do |current_claim, index|
parent_claim = parent_claims[index]
if parent_claim.nil?
added << { key: claim_key, index: index }
elsif current_claim != parent_claim
changed << { key: claim_key, index: index }
end
end
parent_claims.each_with_index do |parent_claim, index|
current_claim = current_claims[index]
if current_claim.nil?
removed << { key: claim_key, index: index }
end
end
else
current_claims.each_index do |index|
added << { key: claim_key, index: index }
end
end
end
parent_content_claims.each do |claim_key, parent_claims|
parent_claims.each_index do |index|
if current_content_claims.nil? || !current_content_claims.key?(claim_key)
removed << { key: claim_key, index: index }
end
end
end
end
{
added: added,
removed: removed,
changed: changed
}
end
|