syllabs-api 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.DS_Store +0 -0
- data/.gitignore +17 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +1 -0
- data/README.md +98 -0
- data/Rakefile +12 -0
- data/lib/.DS_Store +0 -0
- data/lib/syllabs-api.rb +26 -0
- data/lib/syllabs-api/.DS_Store +0 -0
- data/lib/syllabs-api/client.rb +43 -0
- data/lib/syllabs-api/exceptions.rb +11 -0
- data/lib/syllabs-api/http_processor.rb +27 -0
- data/lib/syllabs-api/modules/.DS_Store +0 -0
- data/lib/syllabs-api/modules/extract/base.rb +30 -0
- data/lib/syllabs-api/modules/extract/response.rb +16 -0
- data/lib/syllabs-api/modules/language_detection/base.rb +28 -0
- data/lib/syllabs-api/modules/language_detection/response.rb +31 -0
- data/lib/syllabs-api/modules/named_entity_extraction/base.rb +37 -0
- data/lib/syllabs-api/modules/named_entity_extraction/response.rb +35 -0
- data/lib/syllabs-api/modules/sentiment_analysis/base.rb +36 -0
- data/lib/syllabs-api/modules/sentiment_analysis/response.rb +30 -0
- data/lib/syllabs-api/modules/terms/base.rb +37 -0
- data/lib/syllabs-api/modules/terms/response.rb +29 -0
- data/lib/syllabs-api/version.rb +3 -0
- data/syllabs-api.gemspec +19 -0
- data/test/.DS_Store +0 -0
- data/test/client_test.rb +66 -0
- data/test/modules/extract_test.rb +23 -0
- data/test/modules/language_detection_test.rb +24 -0
- data/test/modules/named_entity_extraction_test.rb +30 -0
- data/test/modules/sentiment_analysis_test.rb +26 -0
- data/test/modules/terms_test.rb +24 -0
- metadata +87 -0
data/.DS_Store
ADDED
Binary file
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
Copyright (c) 2013 Samuel Sanchez
|
data/README.md
ADDED
@@ -0,0 +1,98 @@
|
|
1
|
+
# SyllabsApi
|
2
|
+
|
3
|
+
Syllabs develops advanced technologies for semantic analysis of text content.
|
4
|
+
These technologies are now made available on the web through the Syllabs API.
|
5
|
+
|
6
|
+
Using the Syllabs API, you can harness the power of our semantic analysis platform in your own web site or application.
|
7
|
+
|
8
|
+
# Features
|
9
|
+
|
10
|
+
We’re starting with the following key features, and we’ll be adding more.
|
11
|
+
|
12
|
+
Language detection
|
13
|
+
the API can automatically identify the language and encoding of your text.
|
14
|
+
Information extraction
|
15
|
+
the API can extract key terms and “named entities” (people, places…) from your text, that you can use to add semantic tags to your content.
|
16
|
+
Related keywords
|
17
|
+
Starting with one or more terms, the API can generate a set of related keywords, that you can use to link to similar topics.
|
18
|
+
|
19
|
+
|
20
|
+
## Installation
|
21
|
+
|
22
|
+
Add this line to your application's Gemfile:
|
23
|
+
|
24
|
+
gem 'syllabs-api'
|
25
|
+
|
26
|
+
And then execute:
|
27
|
+
|
28
|
+
$ bundle
|
29
|
+
|
30
|
+
Or install it yourself as:
|
31
|
+
|
32
|
+
$ gem install syllabs-api
|
33
|
+
|
34
|
+
## Usage
|
35
|
+
|
36
|
+
### Language detection
|
37
|
+
|
38
|
+
```
|
39
|
+
#encoding: utf-8
|
40
|
+
require 'syllabs-api'
|
41
|
+
|
42
|
+
API_KEY = 'Your API Key...'
|
43
|
+
client = SyllabsApi::Client.new(API_KEY)
|
44
|
+
|
45
|
+
text_fr = 'Rarement un contrat passé par la Ville de Paris aura aussi bien porté son nom'
|
46
|
+
text_en = 'Spanish Prime Minister Mariano Rajoy announces new austerity measures including a 3% rise in VAT, as thousands of miners protest against big subsidy cuts.'
|
47
|
+
|
48
|
+
client.languages(text_fr).each do |language|
|
49
|
+
puts "#{language.name}: #{language.score}%"
|
50
|
+
end
|
51
|
+
|
52
|
+
client.languages(text_en).each do |language|
|
53
|
+
puts "#{language.name}: #{language.score}%"
|
54
|
+
end
|
55
|
+
|
56
|
+
```
|
57
|
+
|
58
|
+
### Named Entity Extraction
|
59
|
+
|
60
|
+
```
|
61
|
+
text = 'Il étaient plusieurs dizaines de milliers venant des Asturies, de Castille et Leon et d\'Aragon, d\'anciens bassins de charbons d\'Espagne aujourd\'hui mourants. Après plus de 400 kilomètres à pied depuis le nord du pays, la "marche noire" des mineurs espagnols est arrivée, mercredi 11 juillet, à Madrid.'
|
62
|
+
|
63
|
+
client.entities(text).each do |entity|
|
64
|
+
puts "#{entity.name} (#{entity.type}): #{entity.count}"
|
65
|
+
end
|
66
|
+
|
67
|
+
```
|
68
|
+
|
69
|
+
### Terms Extraction
|
70
|
+
|
71
|
+
```
|
72
|
+
text = 'The Russian government shares many of the U.S. concerns about the continuing violence in Syria, but Moscow is reluctant to embrace Washington\'s proposals to solve them because it is wary of its motives, experts say.'
|
73
|
+
|
74
|
+
client.terms(text).each do |term|
|
75
|
+
puts "#{term.text}: #{term.lemma}"
|
76
|
+
end
|
77
|
+
|
78
|
+
```
|
79
|
+
|
80
|
+
### Sentiment Analysis
|
81
|
+
|
82
|
+
```
|
83
|
+
text = 'Notre meilleur souvenir du mois que nous avons passé au Sri Lanka. Un accueil tout particulièrement chaleureux et sympathique de Chanie et Lali, les jeunes propriétaires de cette guesthouse qui offre trois chambres confortables et tenues de façon impeccable. Et toujours des améliorations : nous avons eu l\'agréable surprise d\'avoir l\'eau chaude récemment installée dans notre chambre.'
|
84
|
+
|
85
|
+
client.evaluations(text).each do |e|
|
86
|
+
puts "#{e.object}: #{e.eval}"
|
87
|
+
end
|
88
|
+
|
89
|
+
```
|
90
|
+
|
91
|
+
|
92
|
+
## Contributing
|
93
|
+
|
94
|
+
1. Fork it
|
95
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
96
|
+
3. Commit your changes (`git commit -am 'Added some feature'`)
|
97
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
98
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
2
|
+
|
3
|
+
require 'rake/testtask'
|
4
|
+
Rake::TestTask.new do |t|
|
5
|
+
t.libs << 'test'
|
6
|
+
# t.test_files = Dir.glob("test/**/*_test.rb")
|
7
|
+
t.test_files = ['test/client_test.rb']
|
8
|
+
t.verbose = false
|
9
|
+
end
|
10
|
+
|
11
|
+
desc 'Run tests'
|
12
|
+
task :default => :test
|
data/lib/.DS_Store
ADDED
Binary file
|
data/lib/syllabs-api.rb
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
require 'net/http'
|
2
|
+
require 'uri'
|
3
|
+
require 'cgi'
|
4
|
+
require 'json'
|
5
|
+
require 'timeout'
|
6
|
+
|
7
|
+
require "syllabs-api/version"
|
8
|
+
require "syllabs-api/client"
|
9
|
+
require "syllabs-api/http_processor"
|
10
|
+
require "syllabs-api/exceptions"
|
11
|
+
|
12
|
+
require "syllabs-api/modules/extract/base"
|
13
|
+
require "syllabs-api/modules/extract/response"
|
14
|
+
|
15
|
+
require "syllabs-api/modules/language_detection/base"
|
16
|
+
require "syllabs-api/modules/language_detection/response"
|
17
|
+
|
18
|
+
require "syllabs-api/modules/named_entity_extraction/base"
|
19
|
+
require "syllabs-api/modules/named_entity_extraction/response"
|
20
|
+
|
21
|
+
require "syllabs-api/modules/terms/base"
|
22
|
+
require "syllabs-api/modules/terms/response"
|
23
|
+
|
24
|
+
require "syllabs-api/modules/sentiment_analysis/base"
|
25
|
+
require "syllabs-api/modules/sentiment_analysis/response"
|
26
|
+
|
Binary file
|
@@ -0,0 +1,43 @@
|
|
1
|
+
module SyllabsApi
|
2
|
+
|
3
|
+
class Client
|
4
|
+
def initialize(api_key)
|
5
|
+
raise InvalidKey if api_key.nil?
|
6
|
+
@api_key = api_key
|
7
|
+
rescue Exception => e
|
8
|
+
raise e
|
9
|
+
end
|
10
|
+
|
11
|
+
def terms(text)
|
12
|
+
Modules::Terms::Base.process(@api_key, text).terms
|
13
|
+
rescue Exception => e
|
14
|
+
raise e
|
15
|
+
end
|
16
|
+
|
17
|
+
def evaluations(text)
|
18
|
+
Modules::SentimentAnalysis::Base.process(@api_key, text).evaluations
|
19
|
+
rescue Exception => e
|
20
|
+
raise e
|
21
|
+
end
|
22
|
+
|
23
|
+
def entities(text)
|
24
|
+
Modules::NamedEntityExtraction::Base.process(@api_key, text).entities
|
25
|
+
rescue Exception => e
|
26
|
+
raise e
|
27
|
+
end
|
28
|
+
|
29
|
+
def extract_from_url(url)
|
30
|
+
Modules::Extract::Base.process(@api_key, url).text
|
31
|
+
rescue Exception => e
|
32
|
+
raise e
|
33
|
+
end
|
34
|
+
|
35
|
+
def languages(text)
|
36
|
+
Modules::LanguageDetection::Base.process(@api_key, text).languages
|
37
|
+
rescue Exception => e
|
38
|
+
raise e
|
39
|
+
end
|
40
|
+
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
@@ -0,0 +1,27 @@
|
|
1
|
+
module SyllabsApi
|
2
|
+
|
3
|
+
class HttpProcessor
|
4
|
+
TIMEOUT = 30
|
5
|
+
|
6
|
+
def self.post(api_key, api_url, params)
|
7
|
+
raise Exceptions::InvalidKey if api_key.nil?
|
8
|
+
|
9
|
+
header = {'Api-Key' => api_key}
|
10
|
+
api_uri = URI.parse(api_url)
|
11
|
+
|
12
|
+
http_response = nil
|
13
|
+
Timeout::timeout(TIMEOUT) do
|
14
|
+
http = Net::HTTP.new(api_uri.host, api_uri.port)
|
15
|
+
post = Net::HTTP::Post.new(api_uri.request_uri, header)
|
16
|
+
post.set_form_data(params)
|
17
|
+
http_response = http.request post
|
18
|
+
end
|
19
|
+
return http_response
|
20
|
+
|
21
|
+
rescue Exception => e
|
22
|
+
raise e
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
end
|
27
|
+
|
Binary file
|
@@ -0,0 +1,30 @@
|
|
1
|
+
|
2
|
+
module SyllabsApi
|
3
|
+
module Modules
|
4
|
+
module Extract
|
5
|
+
|
6
|
+
class Base
|
7
|
+
API_URL = 'http://api.syllabs.com/v0/extract?extract=body'
|
8
|
+
RESPONSE_FORMAT = 'json'
|
9
|
+
|
10
|
+
def self.process(api_key, url)
|
11
|
+
params = {url: url, format: RESPONSE_FORMAT}
|
12
|
+
http_response = HttpProcessor.post(api_key, API_URL, params)
|
13
|
+
fetch_response(http_response.body)
|
14
|
+
rescue Exception => e
|
15
|
+
raise e
|
16
|
+
end
|
17
|
+
|
18
|
+
|
19
|
+
def self.fetch_response(body)
|
20
|
+
json = JSON.parse(body)
|
21
|
+
Extract::Response.new(json['response']['url'], json['response']['text'])
|
22
|
+
rescue Exception => e
|
23
|
+
raise e
|
24
|
+
end
|
25
|
+
|
26
|
+
end
|
27
|
+
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
|
2
|
+
module SyllabsApi
|
3
|
+
module Modules
|
4
|
+
module LanguageDetection
|
5
|
+
|
6
|
+
class Base
|
7
|
+
API_URL = 'http://api.syllabs.com/v0/language'
|
8
|
+
RESPONSE_FORMAT = 'json'
|
9
|
+
|
10
|
+
def self.process(api_key, text)
|
11
|
+
params = {text: text, format: RESPONSE_FORMAT}
|
12
|
+
http_response = HttpProcessor.post(api_key, API_URL, params)
|
13
|
+
fetch_response(http_response.body)
|
14
|
+
rescue Exception => e
|
15
|
+
raise e
|
16
|
+
end
|
17
|
+
|
18
|
+
def self.fetch_response(body)
|
19
|
+
LanguageDetection::Response.new JSON.parse(body)
|
20
|
+
rescue Exception => e
|
21
|
+
raise e
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
@@ -0,0 +1,31 @@
|
|
1
|
+
|
2
|
+
module SyllabsApi
|
3
|
+
module Modules
|
4
|
+
module LanguageDetection
|
5
|
+
|
6
|
+
class Response
|
7
|
+
attr_reader :languages
|
8
|
+
|
9
|
+
def initialize(json)
|
10
|
+
@languages = []
|
11
|
+
json['response']['languages'].each do |l|
|
12
|
+
@languages << Language.new(l['name'], l['alph2'], l['alpha3'], l['score'])
|
13
|
+
end
|
14
|
+
rescue Exception => e
|
15
|
+
raise e
|
16
|
+
end
|
17
|
+
|
18
|
+
end
|
19
|
+
|
20
|
+
class Language
|
21
|
+
attr_accessor :name, :alpha2, :alpha3, :score
|
22
|
+
def initialize(name, alpha2, alpha3, score)
|
23
|
+
@name, @alpha2, @alpha3, @score = name, alpha2, alpha3, score
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
|
@@ -0,0 +1,37 @@
|
|
1
|
+
|
2
|
+
module SyllabsApi
|
3
|
+
module Modules
|
4
|
+
module NamedEntityExtraction
|
5
|
+
|
6
|
+
ENTITY_TYPES = ['Geo',
|
7
|
+
'Person',
|
8
|
+
'Occupation',
|
9
|
+
'Organization',
|
10
|
+
'Relation']
|
11
|
+
|
12
|
+
class Base
|
13
|
+
API_URL = 'http://api.syllabs.com/v0/entities'
|
14
|
+
RESPONSE_FORMAT = 'json'
|
15
|
+
|
16
|
+
def self.process(api_key, text)
|
17
|
+
params = {text: text, format: RESPONSE_FORMAT}
|
18
|
+
http_response = HttpProcessor.post(api_key, API_URL, params)
|
19
|
+
fetch_response(http_response.body)
|
20
|
+
rescue Exception => e
|
21
|
+
raise e
|
22
|
+
end
|
23
|
+
|
24
|
+
|
25
|
+
def self.fetch_response(body)
|
26
|
+
NamedEntityExtraction::Response.new JSON.parse(body)
|
27
|
+
rescue Exception => e
|
28
|
+
raise e
|
29
|
+
end
|
30
|
+
|
31
|
+
end
|
32
|
+
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
|
@@ -0,0 +1,35 @@
|
|
1
|
+
|
2
|
+
module SyllabsApi
|
3
|
+
module Modules
|
4
|
+
module NamedEntityExtraction
|
5
|
+
|
6
|
+
class Response
|
7
|
+
attr_reader :entities
|
8
|
+
|
9
|
+
def initialize(json)
|
10
|
+
@entities = []
|
11
|
+
ENTITY_TYPES.each do |raw_entity_type|
|
12
|
+
raw_entities = json['response']['entities'][raw_entity_type]
|
13
|
+
next if raw_entities.nil?
|
14
|
+
raw_entities.each do |raw_entity|
|
15
|
+
# puts "[#{raw_entity_type}] #{raw_entity['text']}: #{raw_entity['count']}"
|
16
|
+
@entities << Entity.new(raw_entity_type, raw_entity['text'], raw_entity['count'])
|
17
|
+
end
|
18
|
+
end
|
19
|
+
rescue Exception => e
|
20
|
+
raise e
|
21
|
+
end
|
22
|
+
|
23
|
+
end
|
24
|
+
|
25
|
+
class Entity
|
26
|
+
attr_accessor :name, :type, :count
|
27
|
+
def initialize(type, name, count); @name = name; @type = type; @count = count; end
|
28
|
+
end
|
29
|
+
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
|
35
|
+
|
@@ -0,0 +1,36 @@
|
|
1
|
+
|
2
|
+
module SyllabsApi
|
3
|
+
module Modules
|
4
|
+
module SentimentAnalysis
|
5
|
+
|
6
|
+
class Base
|
7
|
+
MOD_GENERIC = 'generic'
|
8
|
+
MOD_HOTEL = 'hotel'
|
9
|
+
MOD_RESTAURANT = 'restaurant'
|
10
|
+
MOD_TELECOM = 'telecom'
|
11
|
+
|
12
|
+
API_URL = 'http://api.syllabs.com/v0/sentiment'
|
13
|
+
RESPONSE_FORMAT = 'json'
|
14
|
+
|
15
|
+
def self.process(api_key, text, mod=MOD_GENERIC, lang='fr')
|
16
|
+
api_url = "#{API_URL}/#{mod}"
|
17
|
+
params = {content: text, format: RESPONSE_FORMAT, lang: lang}
|
18
|
+
http_response = HttpProcessor.post(api_key, api_url, params)
|
19
|
+
fetch_response(http_response.body)
|
20
|
+
rescue Exception => e
|
21
|
+
raise e
|
22
|
+
end
|
23
|
+
|
24
|
+
def self.fetch_response(body)
|
25
|
+
SentimentAnalysis::Response.new JSON.parse(body)
|
26
|
+
rescue Exception => e
|
27
|
+
raise e
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
|
36
|
+
|
@@ -0,0 +1,30 @@
|
|
1
|
+
|
2
|
+
module SyllabsApi
|
3
|
+
module Modules
|
4
|
+
module SentimentAnalysis
|
5
|
+
|
6
|
+
class Response
|
7
|
+
attr_reader :evaluations
|
8
|
+
def initialize(json)
|
9
|
+
@evaluations = []
|
10
|
+
json['response']['results']['evaluations'].each do |e|
|
11
|
+
@evaluations << Evaluation.new(e['confidence'], e['object'], e['value'], e['eval'])
|
12
|
+
end
|
13
|
+
rescue Exception => e
|
14
|
+
raise e
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
class Evaluation
|
19
|
+
attr_accessor :confidence, :object, :value, :eval
|
20
|
+
def initialize(confidence, object, value, eval)
|
21
|
+
@confidence, @object, @value, @eval = confidence, object, value, eval
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
|
29
|
+
|
30
|
+
|
@@ -0,0 +1,37 @@
|
|
1
|
+
|
2
|
+
module SyllabsApi
|
3
|
+
module Modules
|
4
|
+
module Terms
|
5
|
+
|
6
|
+
class Base
|
7
|
+
API_URL = 'http://api.syllabs.com/v0/terms'
|
8
|
+
RESPONSE_FORMAT = 'json'
|
9
|
+
LEMMATIZE = true
|
10
|
+
CONFIDENCE = 0.3
|
11
|
+
LANG = 'detect'
|
12
|
+
|
13
|
+
def self.process(api_key, text, lemmatize=LEMMATIZE, confidence=CONFIDENCE, lang=LANG)
|
14
|
+
params = {text: text, format: RESPONSE_FORMAT,
|
15
|
+
lemmatize: lemmatize, confidence: confidence,
|
16
|
+
lang: lang}
|
17
|
+
http_response = HttpProcessor.post(api_key, API_URL, params)
|
18
|
+
fetch_response(http_response.body)
|
19
|
+
rescue Exception => e
|
20
|
+
raise e
|
21
|
+
end
|
22
|
+
|
23
|
+
|
24
|
+
def self.fetch_response(body)
|
25
|
+
Terms::Response.new JSON.parse(body)
|
26
|
+
rescue Exception => e
|
27
|
+
raise e
|
28
|
+
end
|
29
|
+
|
30
|
+
end
|
31
|
+
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
|
37
|
+
|
@@ -0,0 +1,29 @@
|
|
1
|
+
|
2
|
+
module SyllabsApi
|
3
|
+
module Modules
|
4
|
+
module Terms
|
5
|
+
|
6
|
+
class Response
|
7
|
+
attr_reader :terms
|
8
|
+
|
9
|
+
def initialize(json)
|
10
|
+
@terms = []
|
11
|
+
json['response']['terms'].each do |t|
|
12
|
+
@terms << Term.new(t['text'], t['lemma'])
|
13
|
+
end
|
14
|
+
rescue Exception => e
|
15
|
+
raise e
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
class Term
|
20
|
+
attr_accessor :text, :lemma
|
21
|
+
def initialize(text, lemma)
|
22
|
+
@text, @lemma = text, lemma
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
data/syllabs-api.gemspec
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'syllabs-api/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |gem|
|
7
|
+
gem.name = "syllabs-api"
|
8
|
+
gem.version = SyllabsApi::VERSION
|
9
|
+
gem.authors = ["Sam"]
|
10
|
+
gem.email = ["samuel@pagedegeek.com"]
|
11
|
+
gem.description = %q{Syllabs develops advanced technologies for semantic analysis of text content.}
|
12
|
+
gem.summary = %q{Using the Syllabs API, you can harness the power of our semantic analysis platform in your own web site or application.}
|
13
|
+
gem.homepage = "http://www.github.com/PagedeGeek/syllabs-api"
|
14
|
+
|
15
|
+
gem.files = `git ls-files`.split($/)
|
16
|
+
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
17
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
18
|
+
gem.require_paths = ["lib"]
|
19
|
+
end
|
data/test/.DS_Store
ADDED
Binary file
|
data/test/client_test.rb
ADDED
@@ -0,0 +1,66 @@
|
|
1
|
+
#encoding: utf-8
|
2
|
+
|
3
|
+
require 'test/unit'
|
4
|
+
|
5
|
+
$:.unshift(File.dirname(__FILE__) + "/../lib")
|
6
|
+
require 'syllabs-api'
|
7
|
+
|
8
|
+
class ClientTest < Test::Unit::TestCase
|
9
|
+
|
10
|
+
def load_api_key_from_file
|
11
|
+
File.open('my_api_key', 'r').read.strip
|
12
|
+
end
|
13
|
+
|
14
|
+
def setup
|
15
|
+
# @api_key = ENV['SYLLABS_API_KEY']
|
16
|
+
@api_key = load_api_key_from_file
|
17
|
+
end
|
18
|
+
|
19
|
+
def test_init_client
|
20
|
+
assert_nothing_raised do
|
21
|
+
client = SyllabsApi::Client.new(@api_key)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
def test_evaluations
|
26
|
+
text = 'Notre meilleur souvenir du mois que nous avons passé au Sri Lanka. Un accueil tout particulièrement chaleureux et sympathique de Chanie et Lali, les jeunes propriétaires de cette guesthouse qui offre trois chambres confortables et tenues de façon impeccable. Et toujours des améliorations : nous avons eu l\'agréable surprise d\'avoir l\'eau chaude récemment installée dans notre chambre.'
|
27
|
+
client = SyllabsApi::Client.new(@api_key)
|
28
|
+
evaluations = client.evaluations(text)
|
29
|
+
assert_equal(4, evaluations.size)
|
30
|
+
evaluations.each do |e|
|
31
|
+
assert e.is_a?(SyllabsApi::Modules::SentimentAnalysis::Evaluation)
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
def test_terms
|
36
|
+
text = 'The Russian government shares many of the U.S. concerns about the continuing violence in Syria, but Moscow is reluctant to embrace Washington\'s proposals to solve them because it is wary of its motives, experts say.'
|
37
|
+
client = SyllabsApi::Client.new(@api_key)
|
38
|
+
terms = client.terms(text)
|
39
|
+
assert_equal(2, terms.size)
|
40
|
+
end
|
41
|
+
|
42
|
+
def test_named_entity_extraction
|
43
|
+
text = 'Il étaient plusieurs dizaines de milliers venant des Asturies, de Castille et Leon et d\'Aragon, d\'anciens bassins de charbons d\'Espagne aujourd\'hui mourants. Après plus de 400 kilomètres à pied depuis le nord du pays, la "marche noire" des mineurs espagnols est arrivée, mercredi 11 juillet, à Madrid.'
|
44
|
+
client = SyllabsApi::Client.new(@api_key)
|
45
|
+
entities = client.entities(text)
|
46
|
+
assert_equal(4, entities.size)
|
47
|
+
end
|
48
|
+
|
49
|
+
def test_extract_from_url
|
50
|
+
url = 'http://www.lemonde.fr'
|
51
|
+
client = SyllabsApi::Client.new(@api_key)
|
52
|
+
assert_not_nil client.extract_from_url(url)
|
53
|
+
end
|
54
|
+
|
55
|
+
def test_client_languages_detection
|
56
|
+
text_fr = 'Au clair de la lune'
|
57
|
+
text_en = 'Your big text mister !'
|
58
|
+
|
59
|
+
client = SyllabsApi::Client.new(@api_key)
|
60
|
+
|
61
|
+
assert_equal 'french', client.languages(text_fr)[0].name
|
62
|
+
assert_equal 'english', client.languages(text_en)[0].name
|
63
|
+
end
|
64
|
+
|
65
|
+
end
|
66
|
+
|
@@ -0,0 +1,23 @@
|
|
1
|
+
|
2
|
+
require 'test/unit'
|
3
|
+
|
4
|
+
$:.unshift(File.dirname(__FILE__) + "/../../lib")
|
5
|
+
require 'syllabs-api'
|
6
|
+
|
7
|
+
include SyllabsApi::Modules
|
8
|
+
|
9
|
+
class ExtractText < Test::Unit::TestCase
|
10
|
+
|
11
|
+
def setup
|
12
|
+
@api_key = ENV['SYLLABS_API_KEY']
|
13
|
+
end
|
14
|
+
|
15
|
+
def test_extract_from_url
|
16
|
+
url = 'http://www.google.fr'
|
17
|
+
response = Extract::Base.process(@api_key, url)
|
18
|
+
assert_instance_of Extract::Response, response
|
19
|
+
end
|
20
|
+
|
21
|
+
end
|
22
|
+
|
23
|
+
|
@@ -0,0 +1,24 @@
|
|
1
|
+
|
2
|
+
require 'test/unit'
|
3
|
+
|
4
|
+
$:.unshift(File.dirname(__FILE__) + "/../../lib")
|
5
|
+
require 'syllabs-api'
|
6
|
+
|
7
|
+
include SyllabsApi::Modules
|
8
|
+
|
9
|
+
class LanguageDetectionTest < Test::Unit::TestCase
|
10
|
+
|
11
|
+
def setup
|
12
|
+
@api_key = ENV['SYLLABS_API_KEY']
|
13
|
+
end
|
14
|
+
|
15
|
+
def test_language_detection
|
16
|
+
text = 'Au clair de la lune'
|
17
|
+
response = LanguageDetection::Base.process(@api_key, text)
|
18
|
+
assert_instance_of LanguageDetection::Response, response
|
19
|
+
assert_equal 1, response.languages.size
|
20
|
+
assert_instance_of LanguageDetection::Language, response.languages[0]
|
21
|
+
end
|
22
|
+
|
23
|
+
end
|
24
|
+
|
@@ -0,0 +1,30 @@
|
|
1
|
+
#encoding: utf-8
|
2
|
+
|
3
|
+
require 'test/unit'
|
4
|
+
|
5
|
+
$:.unshift(File.dirname(__FILE__) + "/../../lib")
|
6
|
+
require 'syllabs-api'
|
7
|
+
|
8
|
+
include SyllabsApi::Modules
|
9
|
+
|
10
|
+
class NamedEntityExtractionTest < Test::Unit::TestCase
|
11
|
+
|
12
|
+
def setup
|
13
|
+
@api_key = ENV['SYLLABS_API_KEY']
|
14
|
+
end
|
15
|
+
|
16
|
+
def test_extraction
|
17
|
+
text = 'Il étaient plusieurs dizaines de milliers venant des Asturies, de Castille et Leon et d\'Aragon, d\'anciens bassins de charbons d\'Espagne aujourd\'hui mourants. Après plus de 400 kilomètres à pied depuis le nord du pays, la "marche noire" des mineurs espagnols est arrivée, mercredi 11 juillet, à Madrid.'
|
18
|
+
response = NamedEntityExtraction::Base.process(@api_key, text)
|
19
|
+
assert_instance_of NamedEntityExtraction::Response, response
|
20
|
+
|
21
|
+
response.entities.each do |e|
|
22
|
+
assert_instance_of NamedEntityExtraction::Entity, e
|
23
|
+
end
|
24
|
+
|
25
|
+
assert_equal 4, response.entities.size
|
26
|
+
end
|
27
|
+
|
28
|
+
end
|
29
|
+
|
30
|
+
|
@@ -0,0 +1,26 @@
|
|
1
|
+
#encoding: utf-8
|
2
|
+
|
3
|
+
require 'test/unit'
|
4
|
+
|
5
|
+
$:.unshift(File.dirname(__FILE__) + "/../../lib")
|
6
|
+
require 'syllabs-api'
|
7
|
+
|
8
|
+
include SyllabsApi::Modules
|
9
|
+
|
10
|
+
class SentimentAnalysisTest < Test::Unit::TestCase
|
11
|
+
|
12
|
+
def setup
|
13
|
+
@api_key = ENV['SYLLABS_API_KEY']
|
14
|
+
end
|
15
|
+
|
16
|
+
def test_process
|
17
|
+
text = 'Notre meilleur souvenir du mois que nous avons passé au Sri Lanka. Un accueil tout particulièrement chaleureux et sympathique de Chanie et Lali, les jeunes propriétaires de cette guesthouse qui offre trois chambres confortables et tenues de façon impeccable. Et toujours des améliorations : nous avons eu l\'agréable surprise d\'avoir l\'eau chaude récemment installée dans notre chambre.'
|
18
|
+
response = SentimentAnalysis::Base.process(@api_key, text)
|
19
|
+
assert_equal(4, response.evaluations.size)
|
20
|
+
response.evaluations.each do |e|
|
21
|
+
assert e.is_a?(SentimentAnalysis::Evaluation)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
end
|
26
|
+
|
@@ -0,0 +1,24 @@
|
|
1
|
+
#encoding: utf-8
|
2
|
+
|
3
|
+
require 'test/unit'
|
4
|
+
|
5
|
+
$:.unshift(File.dirname(__FILE__) + "/../../lib")
|
6
|
+
require 'syllabs-api'
|
7
|
+
|
8
|
+
include SyllabsApi::Modules
|
9
|
+
|
10
|
+
class TermsTest < Test::Unit::TestCase
|
11
|
+
|
12
|
+
def setup
|
13
|
+
@api_key = ENV['SYLLABS_API_KEY']
|
14
|
+
end
|
15
|
+
|
16
|
+
def test_terms
|
17
|
+
text = 'The Russian government shares many of the U.S. concerns about the continuing violence in Syria, but Moscow is reluctant to embrace Washington\'s proposals to solve them because it is wary of its motives, experts say.'
|
18
|
+
response = Terms::Base.process(@api_key, text)
|
19
|
+
assert_equal(2, response.terms.size)
|
20
|
+
end
|
21
|
+
|
22
|
+
end
|
23
|
+
|
24
|
+
|
metadata
ADDED
@@ -0,0 +1,87 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: syllabs-api
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Sam
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2013-02-05 00:00:00.000000000 Z
|
13
|
+
dependencies: []
|
14
|
+
description: Syllabs develops advanced technologies for semantic analysis of text
|
15
|
+
content.
|
16
|
+
email:
|
17
|
+
- samuel@pagedegeek.com
|
18
|
+
executables: []
|
19
|
+
extensions: []
|
20
|
+
extra_rdoc_files: []
|
21
|
+
files:
|
22
|
+
- .DS_Store
|
23
|
+
- .gitignore
|
24
|
+
- Gemfile
|
25
|
+
- LICENSE.txt
|
26
|
+
- README.md
|
27
|
+
- Rakefile
|
28
|
+
- lib/.DS_Store
|
29
|
+
- lib/syllabs-api.rb
|
30
|
+
- lib/syllabs-api/.DS_Store
|
31
|
+
- lib/syllabs-api/client.rb
|
32
|
+
- lib/syllabs-api/exceptions.rb
|
33
|
+
- lib/syllabs-api/http_processor.rb
|
34
|
+
- lib/syllabs-api/modules/.DS_Store
|
35
|
+
- lib/syllabs-api/modules/extract/base.rb
|
36
|
+
- lib/syllabs-api/modules/extract/response.rb
|
37
|
+
- lib/syllabs-api/modules/language_detection/base.rb
|
38
|
+
- lib/syllabs-api/modules/language_detection/response.rb
|
39
|
+
- lib/syllabs-api/modules/named_entity_extraction/base.rb
|
40
|
+
- lib/syllabs-api/modules/named_entity_extraction/response.rb
|
41
|
+
- lib/syllabs-api/modules/sentiment_analysis/base.rb
|
42
|
+
- lib/syllabs-api/modules/sentiment_analysis/response.rb
|
43
|
+
- lib/syllabs-api/modules/terms/base.rb
|
44
|
+
- lib/syllabs-api/modules/terms/response.rb
|
45
|
+
- lib/syllabs-api/version.rb
|
46
|
+
- syllabs-api.gemspec
|
47
|
+
- test/.DS_Store
|
48
|
+
- test/client_test.rb
|
49
|
+
- test/modules/extract_test.rb
|
50
|
+
- test/modules/language_detection_test.rb
|
51
|
+
- test/modules/named_entity_extraction_test.rb
|
52
|
+
- test/modules/sentiment_analysis_test.rb
|
53
|
+
- test/modules/terms_test.rb
|
54
|
+
homepage: http://www.github.com/PagedeGeek/syllabs-api
|
55
|
+
licenses: []
|
56
|
+
post_install_message:
|
57
|
+
rdoc_options: []
|
58
|
+
require_paths:
|
59
|
+
- lib
|
60
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
61
|
+
none: false
|
62
|
+
requirements:
|
63
|
+
- - ! '>='
|
64
|
+
- !ruby/object:Gem::Version
|
65
|
+
version: '0'
|
66
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
67
|
+
none: false
|
68
|
+
requirements:
|
69
|
+
- - ! '>='
|
70
|
+
- !ruby/object:Gem::Version
|
71
|
+
version: '0'
|
72
|
+
requirements: []
|
73
|
+
rubyforge_project:
|
74
|
+
rubygems_version: 1.8.23
|
75
|
+
signing_key:
|
76
|
+
specification_version: 3
|
77
|
+
summary: Using the Syllabs API, you can harness the power of our semantic analysis
|
78
|
+
platform in your own web site or application.
|
79
|
+
test_files:
|
80
|
+
- test/.DS_Store
|
81
|
+
- test/client_test.rb
|
82
|
+
- test/modules/extract_test.rb
|
83
|
+
- test/modules/language_detection_test.rb
|
84
|
+
- test/modules/named_entity_extraction_test.rb
|
85
|
+
- test/modules/sentiment_analysis_test.rb
|
86
|
+
- test/modules/terms_test.rb
|
87
|
+
has_rdoc:
|