treccani 0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/lib/treccani.rb +18 -0
- data/lib/treccani/sezioni/citazione.rb +19 -0
- data/lib/treccani/sezioni/enciclopedia.rb +29 -0
- data/lib/treccani/sezioni/sinonimi.rb +24 -0
- data/lib/treccani/sezioni/vocabolario.rb +28 -0
- data/lib/treccani/treccani.rb +17 -0
- data/lib/treccani/utils.rb +15 -0
- data/lib/treccani/version.rb +15 -0
- data/spec/treccani_spec.rb +36 -0
- metadata +96 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 7d2517c9785eab462b664f244046cabe5e2fde36
|
4
|
+
data.tar.gz: bbdd82433d75096bf08b957d94fea1a8a5c167fb
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 33a22fcaf20996712daeacaafbd940920395cfd59fed604addf5be87ad7ed8ea2e2aeb12851f6021dfc0bb5eeaff4fff6119369025c3577702e2c893c8c7bd77
|
7
|
+
data.tar.gz: 4bb5f8e385a8762f08d43a357d585f53c37eaf1f8d0d1d445f03f4728cea05082c704476cd2459b35620da1809264c36a9d6bc2844e950e444347e7c233e1088
|
data/lib/treccani.rb
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
#--
|
2
|
+
# DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
|
3
|
+
# Version 2, December 2004
|
4
|
+
#
|
5
|
+
# DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
|
6
|
+
# TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
|
7
|
+
#
|
8
|
+
# 0. You just DO WHAT THE FUCK YOU WANT TO.
|
9
|
+
#++
|
10
|
+
require 'open-uri'
|
11
|
+
require 'nokogiri'
|
12
|
+
|
13
|
+
require 'treccani/treccani'
|
14
|
+
require 'treccani/sezioni/citazione'
|
15
|
+
require 'treccani/sezioni/enciclopedia'
|
16
|
+
require 'treccani/sezioni/sinonimi'
|
17
|
+
require 'treccani/sezioni/vocabolario'
|
18
|
+
require 'treccani/utils'
|
@@ -0,0 +1,19 @@
|
|
1
|
+
#
|
2
|
+
# DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
|
3
|
+
# Version 2, December 2004
|
4
|
+
#
|
5
|
+
# DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
|
6
|
+
# TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
|
7
|
+
#
|
8
|
+
# 0. You just DO WHAT THE FUCK YOU WANT TO.
|
9
|
+
#
|
10
|
+
|
11
|
+
class Citazione < Treccani
|
12
|
+
def get
|
13
|
+
{}.tap { |result|
|
14
|
+
page = Nokogiri::HTML open(@server)
|
15
|
+
result[:citazione] = page.at_xpath('//p[@class="citazione"]').text.strip
|
16
|
+
result[:autore] = page.at_xpath('//p[@class="autore"]').text.strip
|
17
|
+
}
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
#
|
2
|
+
# DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
|
3
|
+
# Version 2, December 2004
|
4
|
+
#
|
5
|
+
# DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
|
6
|
+
# TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
|
7
|
+
#
|
8
|
+
# 0. You just DO WHAT THE FUCK YOU WANT TO.
|
9
|
+
#
|
10
|
+
|
11
|
+
class Enciclopedia < Treccani
|
12
|
+
def get(word)
|
13
|
+
page = Nokogiri::HTML open("#{@server}#{get_url(word)}")
|
14
|
+
{}.tap { |result|
|
15
|
+
page = page.xpath '//div[@class="spiega attacco"]/p'
|
16
|
+
result[:lemma] = page.shift.text.strip
|
17
|
+
result[:meanings] = page.map { |m| m.text.strip }
|
18
|
+
result[:meaning] = result[:meanings].join.strip
|
19
|
+
}
|
20
|
+
end
|
21
|
+
alias_method :find, :get
|
22
|
+
|
23
|
+
private
|
24
|
+
def get_url(word)
|
25
|
+
url = Nokogiri::HTML(open("#{@server}/enciclopedia/ricerca/#{word}/")).at_xpath('//ol[@class="listing"]/li/h2/a/@href').to_s
|
26
|
+
raise 'Term not found.' if url.empty?
|
27
|
+
url
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
#
|
2
|
+
# DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
|
3
|
+
# Version 2, December 2004
|
4
|
+
#
|
5
|
+
# DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
|
6
|
+
# TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
|
7
|
+
#
|
8
|
+
# 0. You just DO WHAT THE FUCK YOU WANT TO.
|
9
|
+
#
|
10
|
+
|
11
|
+
class Sinonimi < Treccani
|
12
|
+
def get(word)
|
13
|
+
page = Nokogiri::HTML open("#{@server}#{get_url(word)}")
|
14
|
+
page.at_xpath('//div[@class="spiega attacco"]/p').text.strip
|
15
|
+
end
|
16
|
+
alias_method :find, :get
|
17
|
+
|
18
|
+
private
|
19
|
+
def get_url(word)
|
20
|
+
url = Nokogiri::HTML(open("#{@server}/vocabolario/ricerca/#{word}/Sinonimi_e_Contrari/")).at_xpath('//li[@class="result fs"]/h2/a/@href').to_s
|
21
|
+
raise 'Term not found.' if url.empty?
|
22
|
+
url
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
#
|
2
|
+
# DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
|
3
|
+
# Version 2, December 2004
|
4
|
+
#
|
5
|
+
# DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
|
6
|
+
# TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
|
7
|
+
#
|
8
|
+
# 0. You just DO WHAT THE FUCK YOU WANT TO.
|
9
|
+
#
|
10
|
+
|
11
|
+
class Vocabolario < Treccani
|
12
|
+
def get(word)
|
13
|
+
{}.tap { |result|
|
14
|
+
page = Nokogiri::HTML open("#{@server}#{get_url(word)}")
|
15
|
+
wot = page.at_xpath('//div[@class="spiega attacco"]/p').to_s.split '<br><br>'
|
16
|
+
result[:lemma] = wot.shift.remove_tags[0..-4].strip
|
17
|
+
result[:meanings] = wot.join.split(/<strong>[0-9]\.<\/strong>/i).map { |m| m.remove_tags.strip }[1..-1]
|
18
|
+
}
|
19
|
+
end
|
20
|
+
alias_method :find, :get
|
21
|
+
|
22
|
+
private
|
23
|
+
def get_url(word)
|
24
|
+
url = Nokogiri::HTML(open("#{@server}/vocabolario/tag/#{word}/")).at_xpath('//li[@class="result fs"]/h2/a/@href').to_s
|
25
|
+
raise 'Term not found.' if url.empty?
|
26
|
+
url
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
#
|
2
|
+
# DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
|
3
|
+
# Version 2, December 2004
|
4
|
+
#
|
5
|
+
# DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
|
6
|
+
# TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
|
7
|
+
#
|
8
|
+
# 0. You just DO WHAT THE FUCK YOU WANT TO.
|
9
|
+
#
|
10
|
+
|
11
|
+
class Treccani
|
12
|
+
attr_accessor :server
|
13
|
+
|
14
|
+
def initialize(server = 'http://www.treccani.it')
|
15
|
+
@server = server
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
#
|
2
|
+
# DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
|
3
|
+
# Version 2, December 2004
|
4
|
+
#
|
5
|
+
# DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
|
6
|
+
# TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
|
7
|
+
#
|
8
|
+
# 0. You just DO WHAT THE FUCK YOU WANT TO.
|
9
|
+
#
|
10
|
+
|
11
|
+
class String
|
12
|
+
def remove_tags
|
13
|
+
gsub %r{</?[^>]+?>}, ''
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
#
|
2
|
+
# DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
|
3
|
+
# Version 2, December 2004
|
4
|
+
#
|
5
|
+
# DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
|
6
|
+
# TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
|
7
|
+
#
|
8
|
+
# 0. You just DO WHAT THE FUCK YOU WANT TO.
|
9
|
+
#
|
10
|
+
|
11
|
+
class Treccani
|
12
|
+
def self.version
|
13
|
+
'0.1'
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
#! /usr/bin/env ruby
|
2
|
+
require 'treccani'
|
3
|
+
|
4
|
+
describe Treccani do
|
5
|
+
it 'gets the daily quote and its author' do
|
6
|
+
expect {
|
7
|
+
trec = Treccani::Citazione.new.get
|
8
|
+
trec[:citazione].length.should > 2
|
9
|
+
trec[:autore].length.should > 2
|
10
|
+
}.to_not raise_error
|
11
|
+
end
|
12
|
+
|
13
|
+
it 'gets the lemma and the meanings of the given term from Enciclopedia' do
|
14
|
+
expect {
|
15
|
+
trec = Treccani::Enciclopedia.new.get 'insegnare'
|
16
|
+
trec[:lemma].length.should > 2
|
17
|
+
trec[:meanings].first.length.should > 2
|
18
|
+
trec[:meaning].length.should > 2
|
19
|
+
}.to_not raise_error
|
20
|
+
end
|
21
|
+
|
22
|
+
it 'gets the synonyms of the given term' do
|
23
|
+
expect {
|
24
|
+
trec = Treccani::Sinonimi.new.get 'insegnare'
|
25
|
+
trec.length.should > 2
|
26
|
+
}.to_not raise_error
|
27
|
+
end
|
28
|
+
|
29
|
+
it 'gets the lemma and the meanings of the given term from Vocabolario' do
|
30
|
+
expect {
|
31
|
+
trec = Treccani::Vocabolario.new.get 'insegnare'
|
32
|
+
trec[:lemma].length.should > 2
|
33
|
+
trec[:meanings].first.length.should > 2
|
34
|
+
}.to_not raise_error
|
35
|
+
end
|
36
|
+
end
|
metadata
ADDED
@@ -0,0 +1,96 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: treccani
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: '0.1'
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Giovanni Capuano
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2013-12-13 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: nokogiri
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rspec
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rake
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
description: RESTful API to get the meaning and synonyms of italian all the italian
|
56
|
+
terms.
|
57
|
+
email: webmaster@giovannicapuano.net
|
58
|
+
executables: []
|
59
|
+
extensions: []
|
60
|
+
extra_rdoc_files: []
|
61
|
+
files:
|
62
|
+
- lib/treccani/sezioni/citazione.rb
|
63
|
+
- lib/treccani/sezioni/enciclopedia.rb
|
64
|
+
- lib/treccani/sezioni/sinonimi.rb
|
65
|
+
- lib/treccani/sezioni/vocabolario.rb
|
66
|
+
- lib/treccani/treccani.rb
|
67
|
+
- lib/treccani/utils.rb
|
68
|
+
- lib/treccani/version.rb
|
69
|
+
- lib/treccani.rb
|
70
|
+
- spec/treccani_spec.rb
|
71
|
+
homepage: http://www.giovannicapuano.net
|
72
|
+
licenses:
|
73
|
+
- WTFPL
|
74
|
+
metadata: {}
|
75
|
+
post_install_message:
|
76
|
+
rdoc_options: []
|
77
|
+
require_paths:
|
78
|
+
- lib
|
79
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
80
|
+
requirements:
|
81
|
+
- - ">="
|
82
|
+
- !ruby/object:Gem::Version
|
83
|
+
version: '0'
|
84
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
85
|
+
requirements:
|
86
|
+
- - ">="
|
87
|
+
- !ruby/object:Gem::Version
|
88
|
+
version: '0'
|
89
|
+
requirements: []
|
90
|
+
rubyforge_project:
|
91
|
+
rubygems_version: 2.0.3
|
92
|
+
signing_key:
|
93
|
+
specification_version: 4
|
94
|
+
summary: RESTful API for Treccani.
|
95
|
+
test_files:
|
96
|
+
- spec/treccani_spec.rb
|