Skip to content

Commit

Permalink
initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
burningTyger committed May 27, 2011
0 parents commit a155d62
Showing 1 changed file with 51 additions and 0 deletions.
51 changes: 51 additions & 0 deletions converter.rb
@@ -0,0 +1,51 @@
require 'mongo_mapper'

MongoMapper.database = 'testing'

class Lemma
include MongoMapper::Document
key :lemma, String
key :translation_ids, Array
many :translations, :in => :translation_ids
timestamps!
end

class Translation
include MongoMapper::Document
key :source, String
key :target, String
timestamps!
end

Lemma.collection.remove
Translation.collection.remove
Lemma.ensure_index(:lemma)

error = {}
Dir.glob('../farhang/*.txt').each do |ff|
File.open(ff, 'r') do |f|
lemma = nil
f.each_line do |l|
source, target = l.split(';')
begin
source.strip!
target.strip!
rescue
error["#{ff.basename}: #{f.lineno}"] = l
end
unless source.start_with?('- ')
lemma = Lemma.create( :lemma => source )
trans = Translation.create( :source => source, :target => target )
lemma.translations << trans
lemma.save
else
source.sub!('- ', '')
trans = Translation.create( :source => source, :target => target )
lemma.translations << trans
lemma.save
end
end
end
end

p error.to_s

0 comments on commit a155d62

Please sign in to comment.