Class: SenseAnalyzer

Inherits:
Object
  • Object
show all
Defined in:
lib/wikidata/diff/sense_analyzer.rb

Class Method Summary collapse

Class Method Details

.isolate_senses_differences(current_content, parent_content) ⇒ Object



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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
# File 'lib/wikidata/diff/sense_analyzer.rb', line 4

def self.isolate_senses_differences(current_content, parent_content)
     # Initialize empty arrays to store the added, removed, and changed claims
     added_senses = []
     removed_senses = []
     changed_senses = []
     added_glosses = []
     removed_glosses = []
     changed_glosses = []
     added_senseclaims = []
     removed_senseclaims = []
     changed_senseclaims = []
 
     current_content_senses = current_content["senses"] if current_content
     parent_content_senses = parent_content["senses"] if parent_content
 
     if !current_content_senses.is_a?(Array) || !parent_content_senses.is_a?(Array)
     return {
        added_senses: added_senses,
        removed_senses: removed_senses,
        changed_senses: changed_senses,
        added_glosses: added_glosses,
        removed_glosses: removed_glosses,
        changed_glosses: changed_glosses,
        added_senseclaims: added_senseclaims,
        removed_senseclaims: removed_senseclaims,
        changed_senseclaims: changed_senseclaims
     }
     end
 
     current_content_senses = current_content["senses"] || []
     parent_content_senses = parent_content["senses"] || []
     
     # if parentid is 0, add all current claims as added claims and return it
     if parent_content.nil?
        current_content_senses.each_with_index do |current_claim, index|
             added_senses << { index: index }
             glosses = GlossAnalyzer.isolate_gloss_differences(current_claim, nil)
             added_glosses += glosses[:added]
             removed_glosses += glosses[:removed]
             changed_glosses += glosses[:changed]
             senseclaims = InsideClaimAnalyzer.isolate_inside_claim_differences(current_claim, nil)
             added_senseclaims += senseclaims[:added]
             removed_senseclaims += senseclaims[:removed]
             changed_senseclaims += senseclaims[:changed]
        end
     else
        current_content_senses.each_with_index do |current_claim, index|
             parent_claim = parent_content_senses[index]
             if parent_claim.nil?
                 # Claim was added
                added_senses << { index: index }
                glosses = GlossAnalyzer.isolate_gloss_differences(current_claim, parent_claim)
                added_glosses += glosses[:added]
                removed_glosses += glosses[:removed]
                changed_glosses += glosses[:changed]
                senseclaims = InsideClaimAnalyzer.isolate_inside_claim_differences(current_claim, nil)
                added_senseclaims += senseclaims[:added]
                removed_senseclaims += senseclaims[:removed]
                changed_senseclaims += senseclaims[:changed]
             elsif current_claim != parent_claim
                 # Claim was changed
                 changed_senses << { index: index }
                 glosses = GlossAnalyzer.isolate_gloss_differences(current_claim, parent_claim)
                added_glosses += glosses[:added]
                removed_glosses += glosses[:removed]
                changed_glosses += glosses[:changed]
                senseclaims = InsideClaimAnalyzer.isolate_inside_claim_differences(current_claim, nil)
                added_senseclaims += senseclaims[:added]
                removed_senseclaims += senseclaims[:removed]
                changed_senseclaims += senseclaims[:changed]
             end
         end
     end
 
     # Iterate over each claim key in the parent content
     parent_content_senses.each_with_index do |parent_claim, index|
         current_claim = current_content_senses[index]
         if current_claim.nil?
            # Claim was removed
            removed_senses << { index: index }
            glosses = GlossAnalyzer.isolate_gloss_differences(current_claim, parent_claim)
            added_glosses += glosses[:added]
            removed_glosses += glosses[:removed]
            changed_glosses += glosses[:changed]
            senseclaims = InsideClaimAnalyzer.isolate_inside_claim_differences(current_claim, nil)
            added_senseclaims += senseclaims[:added]
            removed_senseclaims += senseclaims[:removed]
            changed_senseclaims += senseclaims[:changed]
         end
     end
     {
        added_senses: added_senses,
        removed_senses: removed_senses,
        changed_senses: changed_senses,
        added_glosses: added_glosses,
        removed_glosses: removed_glosses,
        changed_glosses: changed_glosses,
        added_senseclaims: added_senseclaims,
        removed_senseclaims: removed_senseclaims,
        changed_senseclaims: changed_senseclaims
     }
end