alchemy_language 1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/README.md +29 -0
- data/lib/alchemy_language.rb +28 -0
- data/lib/alchemy_language/active_method/base.rb +38 -0
- data/lib/alchemy_language/active_method/extra.rb +15 -0
- data/lib/alchemy_language/active_model/base.rb +23 -0
- data/lib/alchemy_language/generator/alchemy_request.rb +17 -0
- data/lib/alchemy_language/model/author.rb +9 -0
- data/lib/alchemy_language/model/concept.rb +9 -0
- data/lib/alchemy_language/model/date_extraction.rb +11 -0
- data/lib/alchemy_language/model/emotion_analysis.rb +11 -0
- data/lib/alchemy_language/model/targeted_emotion.rb +11 -0
- data/lib/alchemy_language/url_service.rb +26 -0
- metadata +56 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: f7f930bd2480d701dd62d06f121b67160b2909e0
|
4
|
+
data.tar.gz: 98f15dfbb39fa0330f40026885cb06c58b9117e6
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 336ba82283c726006e0c23933247e08f294652bb5be0b3db0e45838601a8bd5f857eba9bedc112fc611ed080878e01891e92a9ef218b84819b561b5fb607cc87
|
7
|
+
data.tar.gz: 454408c2f4ab5dce9db41f3020bc1ddc5de7de20d0d443dfed2d09a81d9befccc800d659e7fe49173bb41a1ecd658a8d984bdcc5d5b8f2a8bc3c41a21565d8ac
|
data/README.md
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
# AlchemyLanguage
|
2
|
+
|
3
|
+
AlchemyLanguage is a collection of APIs that offer text analysis through natural language processing. This set of APIs can analyze text to help you understand its concepts, entities, keywords, sentiment, and more. Additionally, you can create a custom model for some APIs to get specific results that are tailored to your domain.
|
4
|
+
|
5
|
+
Ruby client library to quickly get started with the various Alchemy Language services.
|
6
|
+
|
7
|
+
## Getting Started in ruby
|
8
|
+
You can install this library
|
9
|
+
|
10
|
+
`gem install 'alchemy_language'`
|
11
|
+
|
12
|
+
and use
|
13
|
+
|
14
|
+
```ruby
|
15
|
+
require 'alchemy_language'
|
16
|
+
```
|
17
|
+
|
18
|
+
## Getting Started in Rails
|
19
|
+
AlchemyLanguage works with Rails > 4.1 onwards. You can add it to your Gemfile with:
|
20
|
+
|
21
|
+
```ruby
|
22
|
+
gem 'alchemy_language'
|
23
|
+
```
|
24
|
+
|
25
|
+
Then run `bundle install`
|
26
|
+
|
27
|
+
## License
|
28
|
+
|
29
|
+
This project is licensed under the MIT License - see the [LICENSE.md](LICENSE.md) file for details
|
@@ -0,0 +1,28 @@
|
|
1
|
+
require 'rest-client'
|
2
|
+
require 'json'
|
3
|
+
|
4
|
+
module AlchemyLanguage
|
5
|
+
class << self
|
6
|
+
def base_url_request
|
7
|
+
"https://gateway-a.watsonplatform.net/calls"
|
8
|
+
end
|
9
|
+
|
10
|
+
def secret_token
|
11
|
+
"da431323d51965268639e605b3c78169f710b86a"
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
require_relative "alchemy_language/active_method/base.rb"
|
17
|
+
require_relative "alchemy_language/active_method/extra.rb"
|
18
|
+
require_relative "alchemy_language/generator/alchemy_request.rb"
|
19
|
+
require_relative "alchemy_language/active_model/base.rb"
|
20
|
+
require_relative "alchemy_language/model/author.rb"
|
21
|
+
require_relative "alchemy_language/model/concept.rb"
|
22
|
+
require_relative "alchemy_language/model/date_extraction.rb"
|
23
|
+
require_relative "alchemy_language/model/emotion_analysis.rb"
|
24
|
+
require_relative "alchemy_language/model/targeted_emotion.rb"
|
25
|
+
require_relative "alchemy_language/url_service.rb"
|
26
|
+
|
27
|
+
# obj = AlchemyLanguage::UrlService.new("http://www.ibm.com/watson/")
|
28
|
+
# puts obj.author.status
|
@@ -0,0 +1,38 @@
|
|
1
|
+
require 'active_support/core_ext/string'
|
2
|
+
module AlchemyLanguage
|
3
|
+
module ActiveMethod
|
4
|
+
class Base
|
5
|
+
@@auth_url ="#{AlchemyLanguage.base_url_request}/url/URLGetAuthors?apikey=#{AlchemyLanguage.secret_token}&url=www.ibm.com&outputMode=json"
|
6
|
+
attr_accessor :json_res
|
7
|
+
|
8
|
+
class << self
|
9
|
+
def define_model(name)
|
10
|
+
define_method(name) do
|
11
|
+
eval("#{name.to_s.classify}").new(@path, @type)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
def before_request(name)
|
16
|
+
send name
|
17
|
+
end
|
18
|
+
|
19
|
+
def authenticate!
|
20
|
+
return "secret key is not valid" unless authenticate_successfully?
|
21
|
+
end
|
22
|
+
|
23
|
+
def authenticate_successfully?
|
24
|
+
@json_res = RestClient.get(@@auth_url)
|
25
|
+
valid_api_key? ? true : false
|
26
|
+
end
|
27
|
+
|
28
|
+
def valid_api_key?
|
29
|
+
!json_parser.key?("statusInfo")
|
30
|
+
end
|
31
|
+
|
32
|
+
def json_parser
|
33
|
+
parse_in_json = JSON.parse(@json_res)
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
module AlchemyLanguage
|
2
|
+
module ActiveModel
|
3
|
+
class Base < ActiveMethod::Extra
|
4
|
+
include AlchemyLanguage::Generators::AlchemyRequest
|
5
|
+
attr_accessor :path, :auth_token, :type, :json_result
|
6
|
+
|
7
|
+
add_response_field(:status)
|
8
|
+
add_response_field(:usage)
|
9
|
+
add_response_field(:url)
|
10
|
+
|
11
|
+
def initialize(path, type)
|
12
|
+
@path = path
|
13
|
+
@auth_token = AlchemyLanguage.secret_token
|
14
|
+
@type = type
|
15
|
+
@json_result = request
|
16
|
+
end
|
17
|
+
|
18
|
+
def request
|
19
|
+
json_parser(end_point)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module AlchemyLanguage
|
2
|
+
module Generators
|
3
|
+
module AlchemyRequest
|
4
|
+
def base_url
|
5
|
+
"#{AlchemyLanguage.base_url_request}"
|
6
|
+
end
|
7
|
+
|
8
|
+
def rest_client_api(request_api)
|
9
|
+
RestClient.get(request_api)
|
10
|
+
end
|
11
|
+
|
12
|
+
def json_parser(url)
|
13
|
+
JSON.parse(rest_client_api(base_url + "/" + url))
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
module AlchemyLanguage
|
2
|
+
class DateExtraction < ActiveModel::Base
|
3
|
+
add_response_field(:totalTransactions)
|
4
|
+
add_response_field(:language)
|
5
|
+
add_response_field(:dates)
|
6
|
+
|
7
|
+
def end_point
|
8
|
+
"#{@type}/URLExtractDates?apikey=#{@auth_token}&url=#{@path}&outputMode=json"
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
module AlchemyLanguage
|
2
|
+
class EmotionAnalysis < ActiveModel::Base
|
3
|
+
add_response_field(:totalTransactions)
|
4
|
+
add_response_field(:language)
|
5
|
+
add_response_field(:docEmotions)
|
6
|
+
|
7
|
+
def end_point
|
8
|
+
"#{@type}/URLGetEmotion?apikey=#{@auth_token}&url=#{@path}&outputMode=json"
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
module AlchemyLanguage
|
2
|
+
class TargetedEmotion < ActiveModel::Base
|
3
|
+
add_response_field(:totalTransactions)
|
4
|
+
add_response_field(:language)
|
5
|
+
add_response_field(:results)
|
6
|
+
|
7
|
+
def end_point
|
8
|
+
"#{@type}/URLGetTargetedEmotion?apikey=#{@auth_token}&url=#{@path}&outputMode=json"
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
module AlchemyLanguage
|
2
|
+
class UrlService < ActiveMethod::Base
|
3
|
+
attr_accessor :path, :type
|
4
|
+
before_request :authenticate!
|
5
|
+
|
6
|
+
define_model :author
|
7
|
+
define_model :concept
|
8
|
+
define_model :date_extraction
|
9
|
+
define_model :emotion_analysis
|
10
|
+
define_model :targeted_emotion
|
11
|
+
|
12
|
+
def initialize(path)
|
13
|
+
is_url?
|
14
|
+
@path = path
|
15
|
+
@type = "url"
|
16
|
+
end
|
17
|
+
|
18
|
+
def is_url?
|
19
|
+
"params is not url" if check_url.nil?
|
20
|
+
end
|
21
|
+
|
22
|
+
def check_url
|
23
|
+
@path =~ URI::regexp(["ftp", "http", "https"])
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
metadata
ADDED
@@ -0,0 +1,56 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: alchemy_language
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: '1.0'
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Diamant Kolshi
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2017-02-10 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description: AlchemyLanguage is a collection of APIs that offer text analysis through
|
14
|
+
natural language processing.
|
15
|
+
email: diamantkolshi@gmail.com
|
16
|
+
executables: []
|
17
|
+
extensions: []
|
18
|
+
extra_rdoc_files: []
|
19
|
+
files:
|
20
|
+
- README.md
|
21
|
+
- lib/alchemy_language.rb
|
22
|
+
- lib/alchemy_language/active_method/base.rb
|
23
|
+
- lib/alchemy_language/active_method/extra.rb
|
24
|
+
- lib/alchemy_language/active_model/base.rb
|
25
|
+
- lib/alchemy_language/generator/alchemy_request.rb
|
26
|
+
- lib/alchemy_language/model/author.rb
|
27
|
+
- lib/alchemy_language/model/concept.rb
|
28
|
+
- lib/alchemy_language/model/date_extraction.rb
|
29
|
+
- lib/alchemy_language/model/emotion_analysis.rb
|
30
|
+
- lib/alchemy_language/model/targeted_emotion.rb
|
31
|
+
- lib/alchemy_language/url_service.rb
|
32
|
+
homepage: https://github.com/diamantkolshi/alchemy_language
|
33
|
+
licenses:
|
34
|
+
- MIT
|
35
|
+
metadata: {}
|
36
|
+
post_install_message:
|
37
|
+
rdoc_options: []
|
38
|
+
require_paths:
|
39
|
+
- lib
|
40
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
41
|
+
requirements:
|
42
|
+
- - ">="
|
43
|
+
- !ruby/object:Gem::Version
|
44
|
+
version: '0'
|
45
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
46
|
+
requirements:
|
47
|
+
- - ">="
|
48
|
+
- !ruby/object:Gem::Version
|
49
|
+
version: '0'
|
50
|
+
requirements: []
|
51
|
+
rubyforge_project:
|
52
|
+
rubygems_version: 2.6.7
|
53
|
+
signing_key:
|
54
|
+
specification_version: 4
|
55
|
+
summary: Alchemy Language!
|
56
|
+
test_files: []
|