Skip to content

Commit da20eb9

Browse files
committed
Properly compute sense definition
1 parent 366eb75 commit da20eb9

File tree

15 files changed

+124
-43
lines changed

15 files changed

+124
-43
lines changed

app/assets/javascripts/directives/sense_tooltip.coffee

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,6 @@ angular.module('wordnet').directive 'senseTooltip', ->
99
if sense?
1010
title += sense.lemma
1111
title += " (#{sense.part_of_speech})" if sense.part_of_speech
12-
title += "#{sense.comment}" if sense.comment
12+
title += "#{sense.definition}" if sense.definition
1313

1414
element.attr('title', title)

app/controllers/api/lexemes.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ class Lexemes < Grape::API
7171
id: e2.id,
7272
lemma: e2.lemma,
7373
sense_index: e2.sense_index,
74-
comment: e2.comment
74+
definition: e2.definition
7575
})
7676
)
7777
""".gsub(/\s+/, ' ').strip.freeze

app/exporters/neo4j/sense.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,15 @@ class Sense < Exporter
66
77
ON CREATE SET
88
n.domain_id = {domain_id},
9-
n.comment = {comment},
9+
n.definition = {definition},
1010
n.sense_index = {sense_index},
1111
n.language = {language},
1212
n.part_of_speech = {part_of_speech},
1313
n.lemma = {lemma}
1414
1515
ON MATCH SET
1616
n.domain_id = {domain_id},
17-
n.comment = {comment},
17+
n.definition = {definition},
1818
n.sense_index = {sense_index},
1919
n.language = {language},
2020
n.part_of_speech = {part_of_speech},

app/importers/importer.rb

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,19 +19,29 @@ def table_name
1919
raise NotImplementedError.new("You must implement table_name.")
2020
end
2121

22-
def initialize(options = {})
23-
@base_connection = options.fetch(:connection, ActiveRecord::Base.connection)
24-
@sequel_connection = Sequel.connect(
22+
def base_connection
23+
@base_connection ||=
24+
options.fetch(:connection, ActiveRecord::Base.connection)
25+
end
26+
27+
def sequel_connection
28+
@sequel_connection ||= Sequel.connect(
2529
Rails.configuration.database_configuration[Rails.env].
2630
merge("adapter" => "postgres")
2731
)
32+
end
33+
34+
def pages
35+
@pages ||= (total_count.to_f / @batch_size).ceil
36+
end
2837

38+
def initialize(options = {})
2939
@batch_size = options.fetch(:batch_size, 400)
30-
@pages = options.fetch(:pages, (total_count.to_f / @batch_size).ceil)
40+
@pages = options.fetch(:pages, nil)
3141
end
3242

3343
def import!
34-
(0...@pages).each do |page|
44+
(0...self.pages).each do |page|
3545
import_entities!(@batch_size, page * @batch_size)
3646
end
3747
end
@@ -51,7 +61,7 @@ def process_entities!(entities)
5161
def process_uuid_mappings(entities, uuid_mappings)
5262
uuid_mappings.each do |key, opts|
5363
uuid_mapping = Hash[
54-
@sequel_connection[opts[:table]].select(:id, opts[:attribute]).
64+
self.sequel_connection[opts[:table]].select(:id, opts[:attribute]).
5565
where(opts[:attribute] => entities.map { |w| w[key] }).to_a.
5666
map { |w| [w[opts[:attribute]], w[:id]] }
5767
]
@@ -67,7 +77,7 @@ def process_uuid_mappings(entities, uuid_mappings)
6777
end
6878

6979
def persist_entities!(table_name, entities, unique_attributes)
70-
Upsert.batch(@base_connection, table_name) do |upsert|
80+
Upsert.batch(self.base_connection, table_name) do |upsert|
7181
entities.each do |hash|
7282
unique_map = hash.extract!(*unique_attributes)
7383
upsert.row(unique_map, hash)

app/importers/progress_bar_importer.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ module ProgressBarImporter
22
def import!(*args, &block)
33
@progress_bar = ProgressBar.create(
44
:title => self.class.name.split('::').last,
5-
:total => @pages,
5+
:total => self.pages,
66
:format => "%t: |%B| %c/%C %E",
77
:smoothing => 0.8
88
)

app/importers/wordnet_pl/sense.rb

Lines changed: 7 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,6 @@ def load_entities(limit, offset)
5151
external_id: lemma[:ID],
5252
domain_id: lemma[:domain],
5353
lemma: lemma[:lemma],
54-
comment: extract_short_definition(lemma[:comment]),
5554
examples: extract_examples(lemma[:comment]),
5655
definition: extract_definition(lemma[:comment]),
5756
language: lemma[:project] > 0 ? 'pl_PL' : 'en_GB',
@@ -67,14 +66,6 @@ def convert_pos(pos_id)
6766
PartOfSpeech.find(pos_id).uuid
6867
end
6968

70-
def process_comment(comment)
71-
return nil if comment.blank?
72-
return nil if comment.include?("brak danych")
73-
return nil if comment.include?("##")
74-
return nil if comment[0..1] == "NP"
75-
comment.match(/^([^#<]+)/).to_s.presence
76-
end
77-
7869
def extract_examples(comment)
7970
comment.
8071
scan(/\[##[^:]+: ([^\]]*)\]/).
@@ -83,14 +74,14 @@ def extract_examples(comment)
8374
reject(&:empty?)
8475
end
8576

86-
def extract_short_definition(comment)
87-
definition = comment.scan(/##D: ([^\.]+)\./).flatten.first
88-
definition && definition.size < 128 ? definition : nil
89-
end
90-
9177
def extract_definition(comment)
92-
definition = comment.scan(/##D: ([^\.]+)\./).flatten.first
93-
definition && definition.size >= 128 ? definition : nil
78+
comment.
79+
scan(/##D:\s*(.+?)\.\s*(?:\z|\[##|\{##L:|<#)/m).
80+
flatten.
81+
first.
82+
to_s.
83+
strip.
84+
presence
9485
end
9586
end
9687
end

app/importers/wordnet_pl/synset.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ def total_count
1515
end
1616

1717
def load_entities(limit, offset)
18-
raw = @connection[:synset].select(:ID, :comment, :definition).order(:ID).
18+
raw = @connection[:synset].select(:ID, :definition).order(:ID).
1919
where('ID >= ? AND ID < ?', offset, offset + limit).to_a
2020

2121
raw.map do |synset|

app/models/sense.rb

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ def fetch_related
4646
id: target.id,
4747
lemma: target.lemma,
4848
domain_id: target.domain_id,
49-
comment: target.comment,
49+
definition: target.definition,
5050
part_of_speech: target.part_of_speech,
5151
sense_index: target.sense_index
5252
})
@@ -73,7 +73,7 @@ def fetch_reverse_related
7373
id: target.id,
7474
lemma: target.lemma,
7575
domain_id: target.domain_id,
76-
comment: target.comment,
76+
definition: target.definition,
7777
part_of_speech: target.part_of_speech,
7878
sense_index: target.sense_index
7979
})
@@ -93,7 +93,7 @@ def as_json(options = {})
9393
:language => language,
9494
:domain_id => domain_id,
9595
:part_of_speech => part_of_speech,
96-
:comment => comment
96+
:definition => definition
9797
}
9898

9999
if options[:extended]
@@ -106,7 +106,6 @@ def as_json(options = {})
106106
).as_json
107107

108108
data[:synset] = synset.as_json(without: id)
109-
data[:definition] = definition
110109
data[:examples] = examples || synset.examples || []
111110
data[:outgoing] = fetch_related
112111
data[:incoming] = fetch_reverse_related

app/models/synset.rb

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ def as_json(options = {})
1717

1818
{
1919
senses: the_senses.as_json,
20-
comment: comment,
2120
definition: definition
2221
}
2322
end

app/views/home/index.slim

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,11 @@
1414
span.u__bold> ng-bind-html="homograph.lemma"
1515
small> ng-bind="homograph.sense_index"
1616
small.u__dim<(
17-
ng-if="homograph.comment"
18-
ng-bind-html="homograph.comment | highlight: $select.search"
17+
ng-if="homograph.definition"
18+
ng-bind-html="homograph.definition | highlight: $select.search"
1919
)
2020
small.u__dim<(
21-
ng-if="!homograph.comment"
21+
ng-if="!homograph.definition"
2222
ng-bind-html="('domain_' + homograph.domain_id) | translate | highlight: $select.search"
2323
)
2424
div style="position: absolute; right: 0px; top: -1px"

0 commit comments

Comments
 (0)