forked from hathibelagal/German-English-JSON-Dictionary
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathparseDict.rb
More file actions
28 lines (22 loc) · 653 Bytes
/
Copy pathparseDict.rb
File metadata and controls
28 lines (22 loc) · 653 Bytes
1
2
3
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
# encoding: utf-8
require 'nokogiri'
require 'open-uri'
require 'json'
mode=ARGV[0] # Should be "ge" for German to English
dictionaryHTML = Nokogiri::HTML(
open("http://www.gutenberg.org/files/3212/3212-h/3212-h.htm")
)
dictionaryObject={}
dictionaryHTML.xpath('//tr').each do |row|
if row.children.size() == 2 then
german = row.children[0].content
english = row.children[1].content
if mode=="ge" then
dictionaryObject[german]=english
elsif mode=="eg" then
dictionaryObject[english]=german
end
end
end
dictionaryJSON = JSON.generate(dictionaryObject)
puts dictionaryJSON