Class: RevisionAnalyzer
- Inherits:
-
Object
- Object
- RevisionAnalyzer
- Defined in:
- lib/wikidata/diff/revision_analyzer.rb
Constant Summary collapse
- CLAIM_TYPES =
[:added_claims, :removed_claims, :changed_claims,:added_references, :removed_references, :changed_references,:added_qualifiers, :removed_qualifiers, :changed_qualifiers].freeze
- ALIAS_TYPES =
[:added_aliases, :removed_aliases, :changed_aliases].freeze
- LABEL_TYPES =
[:added_labels, :removed_labels, :changed_labels].freeze
- DESCRIPTION_TYPES =
[:added_descriptions, :removed_descriptions, :changed_descriptions].freeze
- SITELINK_TYPES =
[:added_sitelinks, :removed_sitelinks, :changed_sitelinks].freeze
- COMMENT_TYPES =
[:merge_to, :merge_from, :redirect, :undo, :restore, :clear_item].freeze
- LEMMA_TYPES =
[:added_lemmas, :removed_lemmas, :changed_lemmas].freeze
- FORM_TYPES =
[:added_forms, :removed_forms, :changed_forms, :added_representations, :removed_representations, :changed_representations, :added_formclaims, :removed_formclaims, :changed_formclaims].freeze
- SENSE_TYPES =
[:added_senses, :removed_senses, :changed_senses, :added_glosses, :removed_glosses, :changed_glosses, :added_senseclaims, :removed_senseclaims, :changed_senseclaims].freeze
- NOT_IN_ITEM =
[:create_lexeme, :create_property, :added_lemmas, :removed_lemmas, :changed_lemmas, :added_forms, :removed_forms, :changed_forms, :added_senses, :removed_senses, :changed_senses, :added_representations, :removed_representations, :changed_representations, :added_glosses, :removed_glosses, :changed_glosses, :added_formclaims, :removed_formclaims, :changed_formclaims, :added_senseclaims, :removed_senseclaims, :changed_senseclaims].freeze
- NOT_IN_PROPERTY =
[:create_lexeme, :create_item, :added_sitelinks, :removed_sitelinks, :changed_sitelinks, :added_lemmas, :removed_lemmas, :changed_lemmas, :added_forms, :removed_forms, :changed_forms, :added_senses, :removed_senses, :changed_senses, :added_representations, :removed_representations, :changed_representations, :added_glosses, :removed_glosses, :changed_glosses, :added_formclaims, :removed_formclaims, :changed_formclaims, :added_senseclaims, :removed_senseclaims, :changed_senseclaims].freeze
- NOT_IN_LEXEME =
[:create_item, :create_property, :added_sitelinks, :changed_sitelinks, :removed_sitelinks, :added_aliases, :changed_aliases, :removed_aliases, :added_labels, :changed_labels, :removed_labels, :added_descriptions, :changed_descriptions, :removed_descriptions].freeze
Class Method Summary collapse
-
.analyze_diff(revision_data) ⇒ Object
This method takes two revisions as input and returns the differences between them.
- .item(diff, revision_data) ⇒ Object
- .lexeme(diff, revision_data) ⇒ Object
- .property(diff, revision_data) ⇒ Object
Class Method Details
.analyze_diff(revision_data) ⇒ Object
This method takes two revisions as input and returns the differences between them.
27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/wikidata/diff/revision_analyzer.rb', line 27 def self.analyze_diff(revision_data) model = revision_data[:model] diff = {} if model == 'wikibase-item' item(diff, revision_data) elsif model == 'wikibase-property' property(diff, revision_data) elsif model == 'wikibase-lexeme' lexeme(diff, revision_data) end diff end |
.item(diff, revision_data) ⇒ Object
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 |
# File 'lib/wikidata/diff/revision_analyzer.rb', line 40 def self.item(diff, revision_data) current_content = revision_data[:current_content] parent_content = revision_data[:parent_content] comment = revision_data[:comment] claim_diff = ClaimAnalyzer.isolate_claims_differences(current_content, parent_content) CLAIM_TYPES.each do |change_type| diff[change_type] = claim_diff[change_type].length end alias_diff = AliasAnalyzer.isolate_aliases_differences(current_content, parent_content) ALIAS_TYPES.each do |change_type| diff[change_type] = alias_diff[change_type].length end # Calculate label differences label_diff = LabelAnalyzer.isolate_labels_differences(current_content, parent_content) LABEL_TYPES.each do |change_type| diff[change_type] = label_diff[change_type].length end # Calculate description differences description_diff = DescriptionAnalyzer.isolate_descriptions_differences(current_content, parent_content) DESCRIPTION_TYPES.each do |change_type| diff[change_type] = description_diff[change_type].length end # Calculate sitelink differences sitelink_diff = SitelinkAnalyzer.isolate_sitelinks_differences(current_content, parent_content) SITELINK_TYPES.each do |change_type| diff[change_type] = sitelink_diff[change_type].length end phrases = CommentAnalyzer.isolate_comment_differences(comment) COMMENT_TYPES.each do |change_type| diff[change_type] = phrases[change_type] end NOT_IN_ITEM.each do |change_type| diff[change_type] = 0 end diff[:create_item] = phrases[:create_item] diff end |
.lexeme(diff, revision_data) ⇒ Object
129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 |
# File 'lib/wikidata/diff/revision_analyzer.rb', line 129 def self.lexeme(diff, revision_data) current_content = revision_data[:current_content] parent_content = revision_data[:parent_content] comment = revision_data[:comment] claim_diff = ClaimAnalyzer.isolate_claims_differences(current_content, parent_content) CLAIM_TYPES.each do |change_type| diff[change_type] = claim_diff[change_type].length end forms_diff = FormAnalyzer.isolate_forms_differences(current_content, parent_content) FORM_TYPES.each do |change_type| diff[change_type] = forms_diff[change_type].length end # Calculate label differences lemmas_diff = LemmaAnalyzer.isolate_lemmas_differences(current_content, parent_content) LEMMA_TYPES.each do |change_type| diff[change_type] = lemmas_diff[change_type].length end # Calculate description differences senses_diff = SenseAnalyzer.isolate_senses_differences(current_content, parent_content) SENSE_TYPES.each do |change_type| diff[change_type] = senses_diff[change_type].length end phrases = CommentAnalyzer.isolate_comment_differences(comment) COMMENT_TYPES.each do |change_type| diff[change_type] = phrases[change_type] end NOT_IN_LEXEME.each do |change_type| diff[change_type] = 0 end diff[:create_lexeme] = phrases[:create_item] end |
.property(diff, revision_data) ⇒ Object
88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 |
# File 'lib/wikidata/diff/revision_analyzer.rb', line 88 def self.property(diff, revision_data) current_content = revision_data[:current_content] parent_content = revision_data[:parent_content] comment = revision_data[:comment] claim_diff = ClaimAnalyzer.isolate_claims_differences(current_content, parent_content) CLAIM_TYPES.each do |change_type| diff[change_type] = claim_diff[change_type].length end alias_diff = AliasAnalyzer.isolate_aliases_differences(current_content, parent_content) ALIAS_TYPES.each do |change_type| diff[change_type] = alias_diff[change_type].length end # Calculate label differences label_diff = LabelAnalyzer.isolate_labels_differences(current_content, parent_content) LABEL_TYPES.each do |change_type| diff[change_type] = label_diff[change_type].length end # Calculate description differences description_diff = DescriptionAnalyzer.isolate_descriptions_differences(current_content, parent_content) DESCRIPTION_TYPES.each do |change_type| diff[change_type] = description_diff[change_type].length end phrases = CommentAnalyzer.isolate_comment_differences(comment) COMMENT_TYPES.each do |change_type| diff[change_type] = phrases[change_type] end diff[:create_property] = phrases[:create_item] NOT_IN_PROPERTY.each do |change_type| diff[change_type] = 0 end end |