null+****@clear*****
null+****@clear*****
Wed Jun 13 16:59:42 JST 2012
SUZUKI Miho 2012-06-13 16:59:42 +0900 (Wed, 13 Jun 2012) New Revision: 66029c5e97bb5d43d275e7cfd37c8a4aab6a387b Log: Use glossary object instead of glossary source when run lookup command Modified files: lib/logaling/command/application.rb lib/logaling/glossary_db.rb lib/logaling/repository.rb spec/logaling/glossary_spec.rb spec/logaling/repository_spec.rb Modified: lib/logaling/command/application.rb (+3 -1) =================================================================== --- lib/logaling/command/application.rb 2012-06-13 16:44:12 +0900 (3ee4d4c) +++ lib/logaling/command/application.rb 2012-06-13 16:59:42 +0900 (b9c9375) @@ -236,7 +236,9 @@ module Logaling::Command def lookup(source_term) check_logaling_home_exists @repository.index - terms =****@repos*****(source_term, glossary_source, options["dictionary"]) + project =****@repos*****_project(@config.glossary) + glossary = project.find_glossary(@config.source_language, @config.target_language) + terms =****@repos*****(source_term, glossary, options["dictionary"]) unless terms.empty? max_str_size = terms.map{|term| term[:source_term].size}.sort.last run_pager Modified: lib/logaling/glossary_db.rb (+6 -6) =================================================================== --- lib/logaling/glossary_db.rb 2012-06-13 16:44:12 +0900 (7a0b14d) +++ lib/logaling/glossary_db.rb 2012-06-13 16:59:42 +0900 (1e717f3) @@ -84,18 +84,18 @@ module Logaling create_terms if offline_index? end - def lookup(source_term, glossary_source=nil) + def lookup(source_term, glossary=nil) records_selected = Groonga["translations"].select do |record| conditions = [record.source_term =~ source_term] - if glossary_source - conditions << (record.source_language =~ glossary_source.source_language) if glossary_source.source_language - conditions << (record.target_language =~ glossary_source.target_language) if glossary_source.target_language + if glossary + conditions << (record.source_language =~ glossary.source_language) if glossary.source_language + conditions << (record.target_language =~ glossary.target_language) if glossary.target_language end conditions end - if glossary_source + if glossary specified_glossary = records_selected.select do |record| - record.glossary == glossary_source.glossary + record.glossary == glossary.name end specified_glossary.each do |record| record.key._score += 10 Modified: lib/logaling/repository.rb (+2 -2) =================================================================== --- lib/logaling/repository.rb 2012-06-13 16:44:12 +0900 (6d69108) +++ lib/logaling/repository.rb 2012-06-13 16:59:42 +0900 (dbc5a0f) @@ -64,7 +64,7 @@ module Logaling raise Logaling::CommandFailed, "Failed import_tmx #{glossary_source.class.name} to #{cache_path}." end - def lookup(source_term, glossary_source, dictionary=false) + def lookup(source_term, glossary, dictionary=false) raise Logaling::GlossaryDBNotFound unless File.exist?(logaling_db_home) terms = [] @@ -72,7 +72,7 @@ module Logaling if dictionary terms = db.lookup_dictionary(source_term) else - terms = db.lookup(source_term, glossary_source) + terms = db.lookup(source_term, glossary) end end terms Modified: spec/logaling/glossary_spec.rb (+3 -2) =================================================================== --- spec/logaling/glossary_spec.rb 2012-06-13 16:44:12 +0900 (f58b4a9) +++ spec/logaling/glossary_spec.rb 2012-06-13 16:59:42 +0900 (b89b3f2) @@ -25,6 +25,7 @@ module Logaling let(:glossary_source) { GlossarySource.new(project, 'en', 'ja', logaling_home) } let(:glossary_source_path) { glossary_source.source_path } let(:repository) { Logaling::Repository.new(logaling_home) } + let(:glossary) {repository.find_project(project).find_glossary('en', 'ja')} before do FileUtils.remove_entry_secure(File.join(logaling_home, 'projects', 'spec'), true) @@ -101,7 +102,7 @@ module Logaling glossary_source.add("delete_logaling", "てすと2", "備考") glossary_source.delete("delete_logaling", "てすと1") repository.index - @result = repository.lookup("delete_logaling", glossary_source) + @result = repository.lookup("delete_logaling", glossary) end it 'should delete the bilingual pair' do @@ -138,7 +139,7 @@ module Logaling glossary_source.add("user_logaling", "ユーザ", "備考") glossary_source.delete_all("user_logaling") repository.index - @result = repository.lookup("user_logaling", glossary_source) + @result = repository.lookup("user_logaling", glossary) end it 'should delete the term' do Modified: spec/logaling/repository_spec.rb (+6 -5) =================================================================== --- spec/logaling/repository_spec.rb 2012-06-13 16:44:12 +0900 (2012e8f) +++ spec/logaling/repository_spec.rb 2012-06-13 16:59:42 +0900 (daa6ed5) @@ -26,6 +26,7 @@ module Logaling let(:glossary_source_path) { glossary_source.source_path } let(:repository) { Logaling::Repository.new(logaling_home) } let(:db_home) { File.join(logaling_home, "db") } + let(:glossary) {repository.find_project(project).find_glossary('en', 'ja')} before do FileUtils.remove_entry_secure(File.join(logaling_home, 'projects', 'spec'), true) @@ -39,7 +40,7 @@ module Logaling glossary_source.add("user-logaling", "ユーザー", "") File.stub!(:mtime).and_return(Time.now - 1) repository.index - @terms = repository.lookup("user-logaling", glossary_source) + @terms = repository.lookup("user-logaling", glossary) end it 'succeed at find by term' do @@ -98,7 +99,7 @@ module Logaling FileUtils.touch(tsv_path) File.open(tsv_path, "w"){|f| f.puts "test-logaling\tユーザー\ntest-logaling\tユーザ"} repository.index - @terms = repository.lookup("test-logaling", glossary_source) + @terms = repository.lookup("test-logaling", glossary) end it 'succeed at find by term' do @@ -122,7 +123,7 @@ module Logaling FileUtils.touch(glossary_source_path) glossary_source.add("spec_logaling", "スペック", "備考") repository.index - @terms = repository.lookup("spec_logaling", glossary_source) + @terms = repository.lookup("spec_logaling", glossary) end it 'glossaries should be indexed' do @@ -140,7 +141,7 @@ module Logaling FileUtils.touch(tsv_path) File.open(tsv_path, "w"){|f| f.puts "user-logaling\tユーザ"} repository.index - @terms = repository.lookup("user-logaling", glossary_source) + @terms = repository.lookup("user-logaling", glossary) end @@ -159,7 +160,7 @@ module Logaling FileUtils.touch(csv_path) File.open(csv_path, "w"){|f| f.puts "test_logaling,テスト"} repository.index - @terms = repository.lookup("test_logaling", glossary_source) + @terms = repository.lookup("test_logaling", glossary) end it 'glossaries should be indexed' do