alchemy_language 1.0.2 → 1.0.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 30acde033bab3039bad59d2c0c981c93a06df908
4
- data.tar.gz: 04c6d2f8756530790c99b698ff5162366d9fb95b
3
+ metadata.gz: d43e410a117824cfeacf7a8100d1e3ea7967b835
4
+ data.tar.gz: e15ab0e4c59d60ec5b1ad01e17073dda29de59e8
5
5
  SHA512:
6
- metadata.gz: 7b15382c81970a355ceadf67e78fd214873761b2c08b5f7aa60f116a4fa99cec0b4d1dcb151d762c1f5a4e0f686b30b18d35062a597626ec6a377117b692c6b2
7
- data.tar.gz: 72a13cb7abce74253c5cfb6d259e44bcec25e9e5431ef37b182764ddd76e20e72bf3e0cb33099ce41529cf5a266db753f61a78ce9466ba099d50402dbbc250a4
6
+ metadata.gz: 3c23e70e6fd19d51745bcf63ad3b474e4115641681d38b7bae44bd9a4b5696b650f9cd0d99d9bb8f5290f9fee2c2e1ed7dfe193641e11817c6f8ce454b1f8cf9
7
+ data.tar.gz: 169118b51cdf741de931a125f082a023343290374b202267f79f65c0db700fe60e3ecca5195d2539836e65d73c9737142c1502166d3a4ef2776e2efc81f8a695
data/README.md CHANGED
@@ -4,6 +4,25 @@ AlchemyLanguage is a collection of APIs that offer text analysis through natural
4
4
 
5
5
  Ruby client library to quickly get started with the various Alchemy Language services.
6
6
 
7
+ ## Prerequisites
8
+ You authenticate to the AlchemyLanguage API by passing an API key as a query parameter in each call.
9
+
10
+ To get an API key, you'll need to [sign up for IBM Bluemix](https://console.ng.bluemix.net/registration/). After you create an account:
11
+
12
+ Log in to Bluemix and go to the AlchemyAPI service page.
13
+ Click the "Create" button.
14
+ Click the "Service Credentials" button from the AlchemyAPI page in your Bluemix dashboard to view your API key.
15
+
16
+ After create bluemix account and create autheticate token of AlchemyLanguage, you can use another gem for env variables as ([dotenv](https://github.com/bkeepers/dotenv), [figaro](https://github.com/laserlemon/figaro) or which you want to create env variables).
17
+
18
+ Then in (.env) file you should add:
19
+
20
+ ```ruby
21
+ token=$your_token_from_bluemix
22
+ ```
23
+
24
+ AlchemyLanguage will take your token and it will do request with this token, it's it!
25
+
7
26
  ## Getting Started in ruby
8
27
  You can install this library
9
28
 
@@ -24,6 +43,320 @@ gem 'alchemy_language'
24
43
 
25
44
  Then run `bundle install`
26
45
 
46
+ ## Use
47
+
48
+ ### Service
49
+ Alchemy Language provide three kind of service
50
+
51
+ * Url service
52
+ * Text service
53
+ * HTML service
54
+
55
+ ### Url Service
56
+
57
+ Initially create object with path when you want to do request
58
+
59
+ ```ruby
60
+ url = "http://www.ibm.com/watson/"
61
+ @alchemy_service = AlchemyLanguage::UrlService.new(url)
62
+ ```
63
+
64
+ ### Text Service
65
+
66
+ Initially create object with text when you want to do request
67
+
68
+ ```ruby
69
+ text = "some text"
70
+ @alchemy_service = AlchemyLanguage::TextService.new(text)
71
+ ```
72
+
73
+ ### HTML Service
74
+
75
+ Initially create object with path when you want to do request
76
+
77
+ ```ruby
78
+ url = "http://www.ibm.com/watson/"
79
+ @alchemy_service = AlchemyLanguage::HtmlService.new(text)
80
+ ```
81
+
82
+ ### Models
83
+
84
+ All Services contain these models:
85
+
86
+ ```
87
+ .
88
+ ├── Author
89
+ ├── Concept
90
+ ├── DateExtraxtion
91
+ ├── EmotionAnalysis
92
+ ├── TargetedEmotion
93
+ ├── Entity
94
+ ├── FeedDetection
95
+ ├── Keyword
96
+ ├── LanguageDetection
97
+ ├── Microformat
98
+ ├── PublicationDate
99
+ ├── Relation
100
+ ├── TypedRelation
101
+ ├── SentimentAnalysis
102
+ ├── TargetedSentiment
103
+ ├── Taxonomy
104
+ ├── Text
105
+ ├── RawText
106
+ ├── TitleExtraction
107
+ ├── CombinedCall
108
+
109
+ 20 models
110
+ ```
111
+
112
+ #### Authors
113
+
114
+ Authors - extracts author information from news articles or blog posts. Author extraction enables the categorization of content from online publications by author, and can be used with other AlchemyLanguage functions to generate tag clouds, identify sentiment towards topics and authors, and so on.
115
+
116
+ Services: [html, url]
117
+
118
+ Fetch all result of author model
119
+
120
+ ```ruby
121
+ @alchemy_service.author.result
122
+ ```
123
+
124
+ #### Concepts
125
+
126
+ Concepts - identifes concepts with which the input text is associated, based on other concepts and entities that are present in that text. Concept-related API functions understand how concepts relate, and can identify concepts that are not directly referenced in the text. For example, if an article mentions CERN and the Higgs boson, the Concepts API functions will identify Large Hadron Collider as a concept even if that term is not mentioned explicitly in the page. Concept tagging enables higher level analysis of input content than just basic keyword identification.
127
+
128
+ Services: [html, url, text]
129
+
130
+ Fetch all result of Concepts model
131
+
132
+ ```ruby
133
+ @alchemy_service.concept(
134
+ knowledgeGraph: 1
135
+ ).result
136
+ ```
137
+
138
+ #### Dates
139
+
140
+ Dates - extracts natural language date/time expressions from text, normalizes them to an ISO date string (such as "20040104T000000"), and identifies concepts with which those dates are associated.
141
+
142
+ Services: [html, url, text]
143
+
144
+ Fetch all result of Dates model
145
+
146
+ ```ruby
147
+ @alchemy_service.date_extraction(
148
+ anchorDate: "2016-03-22 00:00:00"
149
+ ).result
150
+ ```
151
+
152
+ #### Emotion Analysis
153
+
154
+ Emotion Analysis - detects anger, disgust, fear, joy, and sadness implied in English text. Emotion Analysis can detect emotions that are associated with targeted phrases, entities, or keywords, or it can analyze the overall emotional tone of your content.
155
+
156
+ Services: [html, url, text]
157
+
158
+ Fetch all result of Emotion Analysis model
159
+
160
+ ```ruby
161
+ @alchemy_service.emotion_analysis(
162
+ targets: "Target 1|Target 2"
163
+ ).result
164
+ ```
165
+
166
+ #### Targeted Emotion
167
+
168
+ Targeted Emotion searches your content for up to 20 targets, and uses context to analyze emotions associated with each phrase. You can analyze emotions for keywords and entities by passing an emotion=1 parameter when you use the respective API methods, or when you extract keywords and entities in a Combined Call.
169
+
170
+ Services: [html, url, text]
171
+
172
+ Fetch all result of Targeted Emotio model
173
+
174
+ ```ruby
175
+ @alchemy_service.targeted_emotion.result
176
+ ```
177
+
178
+ #### Entities
179
+
180
+ Entities - returns items such as persons, places, and organizations that are present in the input text. Entity extraction adds semantic knowledge to content to help understand the subject and context of the text that is being analyzed. The entity extraction technniques used by the AlchemyLanguage service are based on sophisticated statistical algorithms and natural language processing technology, and are unique in the industry with their support for multilingual analysis, context-sensitive disambiguation, and quotations extraction. You can specify a custom model in your request to identify a custom set of entity types in your content, enabling domain-specific entity extraction.
181
+
182
+ Services: [html, url, text]
183
+
184
+ Fetch all result of Entities model
185
+
186
+ ```ruby
187
+ @alchemy_service.entity(
188
+ maxRetrieve: = 3
189
+ ).result
190
+ ```
191
+
192
+ #### Feeds
193
+
194
+ Feeds - extracts any links to web feeds that are embedded in a web page. Web feeds are often embedded in websites to enable automated access to syndicated content. Any feeds that are detected can subsequently be used to discover new content, such as blog posts, news articles, and comment streams.
195
+
196
+ Services: [html, url]
197
+
198
+ Fetch all result of Feeds model
199
+
200
+ ```ruby
201
+ @alchemy_service.feed_detection.result
202
+ ```
203
+
204
+ #### Keywords
205
+
206
+ Keywords - important topics in your content that are typically used when indexing data, generating tag clouds, or when searching. The AlchemyLanguage service automatically identifies supported languages (see the next bullet) in your input content, and then identifies and ranks keywords in that content. Sentiment can also be associated with each keyword by using the AlchemyLanguage sentiment analysis capabilities.
207
+
208
+ Services: [html, url, text]
209
+
210
+ Fetch all result of Keywords model
211
+
212
+ ```ruby
213
+ @alchemy_service.keyword.result
214
+ ```
215
+
216
+ #### Language
217
+
218
+ Language - detects the natural language in which input text, HTML, or web-based content is written. Language identification functions can identify English, German, French, Italian, Portuguese, Russian, Spanish and Swedish. These functions enable applications to categorize or filter content based on the language in which it was written.
219
+
220
+ Services: [html, url, text]
221
+
222
+ Fetch all result of Language model
223
+
224
+ ```ruby
225
+ @alchemy_service.language_detection.result
226
+ ```
227
+
228
+ #### Microformats
229
+
230
+ Microformats - processes microformat information that is included in the HTML of some webpages to add semantic information and to enable easier scanning and processing of those pages by software. The information extracted from web pages by the Microformats method can be used for tasks such as webpage categorization and content discovery.
231
+
232
+ Services: [html, url]
233
+
234
+ Fetch all result of Microformats model
235
+
236
+ ```ruby
237
+ @alchemy_service.microformat.result
238
+ ```
239
+
240
+ #### Publication Date
241
+
242
+ Publication Date - extracts publication date information, if present, from web pages. The date on which a web page was published can be critical when analyzing trends based on text attributes, such as when tracking changing sentiment towards specific topics, products, or brands. The Publication Date API functions understand most date formats, can identify publication dates in different portions of a document, and can differentiate between the publication date of a page and other dates that may be embedded in its content.
243
+
244
+ Services: [html, url]
245
+
246
+ Fetch all result of Publication Date model
247
+
248
+ ```ruby
249
+ @alchemy_service.publication_date.result
250
+ ```
251
+
252
+ #### Relations
253
+
254
+ Relations - identifies subject, action, and object relations within sentences in the input content. After parsing sentences into subject, action, and object form, the Relation Extraction API functions can use this information for subsequent processing by other AlchemyLanguage functions such as entity extraction, keyword extraction, sentiment analysis, and location identification. Relation information can be used to automatically identify buying signals, key events, and other important actions.
255
+
256
+ Services: [html, url, text]
257
+
258
+ Fetch all result of Relations model
259
+
260
+ ```ruby
261
+ @alchemy_service.relation(
262
+ maxRetrieve: 1
263
+ ).result
264
+ ```
265
+
266
+ #### Typed Relations
267
+
268
+ Typed Relations - uses custom models to recognize entities in content, and identifies various types of relations between those entities. The types of entities and relations that can be identified are properties of the custom model that is specified. With the public custom model ie-en-news, Typed Relations can identify entities and relations related to the news domain. For example, given the input "Leonardo DiCaprio won an Oscar," a request using ie-en-news will recognize "Leonardo Dicaprio" as a "Person" entity and "Oscar" as an "EntertainmentAward" entity, and it will recognize an "awardedTo" relation that exists between those entities.
269
+
270
+ Services: [html, url, text]
271
+
272
+ Fetch all result of Typed Relations model
273
+
274
+ ```ruby
275
+ @alchemy_service.typed_relation.result
276
+ ```
277
+
278
+ #### Sentiment
279
+
280
+ Sentiment - identifies attitude, opinions, or feelings in the content that is being analyzed. The AlchemyLanguage service can calculate overall sentiment within a document, sentiment for user-specified targets, entity-level sentiment, quotation-level sentiment, directional-sentiment, and keyword-level sentiment. The combination of these capabilities supports a variety of use cases ranging from social media monitoring to trend analysis.
281
+
282
+ Services: [html, url, text]
283
+
284
+ Fetch all result of Sentiment model
285
+
286
+ ```ruby
287
+ @alchemy_service.sentiment_analysis.result
288
+ ```
289
+
290
+ #### Targeted Sentiment
291
+ Supported languages: Arabic, English, French, German, Italian, Portuguese, Russian, Spanish
292
+
293
+ Fetch all result of Targeted Sentiment model
294
+
295
+ ```ruby
296
+ @alchemy_service.targeted_sentiment(
297
+ targets: "Target 1|Taget 2"
298
+ ).result
299
+ ```
300
+
301
+ #### Taxonomy
302
+
303
+ Taxonomy - categorizes input text, HTML or web-based content into a hierarchical taxonomy up to five levels deep. Deeper levels allow you to classify content into more accurate and useful subsegments. The AlchemyLanguage taxonomy methods use an enhanced version of the standard Interactive Advertising Bureau Quality Assurance Guidelines Taxonomy, extending that taxonomy to over 1000 categories for superior audience targeting and information routing.
304
+
305
+ Services: [html, url, text]
306
+
307
+ Fetch all result of Taxonomy model
308
+
309
+ ```ruby
310
+ @alchemy_service.taxonomy.result
311
+ ```
312
+
313
+ #### Text Extraction
314
+
315
+ Text Extraction - AlchemyLanguage cleans source text from html in each API method by default. This includes normalizing HTML content, removing ads, navigation links, and other unimportant content so that only the important page text is returned.
316
+
317
+ Services: [html, url]
318
+
319
+ Fetch all result of Text Extraction model
320
+
321
+ Text (cleaned)
322
+
323
+ ```ruby
324
+ @alchemy_service.text.result
325
+ ```
326
+
327
+ Text (raw)
328
+
329
+ ```ruby
330
+ @alchemy_service.raw_text.result
331
+ ```
332
+
333
+ #### Title Extraction
334
+
335
+ Title Extraction - Extracts title information from web pages
336
+ Services: [html, url]
337
+
338
+ Fetch all result of Title Extraction model
339
+
340
+ ```ruby
341
+ @alchemy_service.title_extraction.result
342
+ ```
343
+
344
+ #### Combined Call
345
+
346
+ Combined Call - AlchemyLanguage offers a wide variety of text analysis capabilities, but getting a wealth of semantic information for a single document is made simple with combined calls.
347
+
348
+ Services: [html, url, text]
349
+
350
+ Fetch all result of Combined Call model
351
+
352
+ ```ruby
353
+ @alchemy_service.combined_call(
354
+ extract: "entities,keywords",
355
+ sentiment: 1,
356
+ maxRetrieve: 1
357
+ ).result
358
+ ```
359
+
27
360
  ## License
28
361
 
29
362
  This project is licensed under the MIT License - see the [LICENSE.md](LICENSE.md) file for details
@@ -1,5 +1,6 @@
1
1
  require 'rest-client'
2
2
  require 'json'
3
+ require "addressable/uri"
3
4
 
4
5
  module AlchemyLanguage
5
6
  class << self
@@ -8,7 +9,7 @@ module AlchemyLanguage
8
9
  end
9
10
 
10
11
  def secret_token
11
- "da431323d51965268639e605b3c78169f710b86a"
12
+ ENV['token']
12
13
  end
13
14
  end
14
15
  end
@@ -20,9 +21,9 @@ require_relative "alchemy_language/active_model/base.rb"
20
21
  require_relative "alchemy_language/model/author.rb"
21
22
  require_relative "alchemy_language/model/concept.rb"
22
23
  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/model/entity.rb"
24
+ require_relative "alchemy_language/model/emotion_analysis.rb"
25
+ require_relative "alchemy_language/model/targeted_emotion.rb"
26
+ require_relative "alchemy_language/model/entity.rb"
26
27
  require_relative "alchemy_language/model/feed_detection.rb"
27
28
  require_relative "alchemy_language/model/keyword.rb"
28
29
  require_relative "alchemy_language/model/language_detection.rb"
@@ -36,7 +37,7 @@ require_relative "alchemy_language/model/taxonomy.rb"
36
37
  require_relative "alchemy_language/model/text.rb"
37
38
  require_relative "alchemy_language/model/raw_text.rb"
38
39
  require_relative "alchemy_language/model/title_extraction.rb"
40
+ require_relative "alchemy_language/model/combined_call.rb"
39
41
  require_relative "alchemy_language/url_service.rb"
42
+ require_relative "alchemy_language/text_service.rb"
40
43
 
41
- # obj = AlchemyLanguage::UrlService.new("http://www.ibm.com/watson/")
42
- # puts obj.author.status
@@ -7,8 +7,8 @@ module AlchemyLanguage
7
7
 
8
8
  class << self
9
9
  def define_model(name)
10
- define_method(name) do
11
- eval("#{name.to_s.classify}").new(@path, @type)
10
+ define_method(name) do |options = {}|
11
+ eval("#{name.to_s.classify}").new(@path, @type, options)
12
12
  end
13
13
  end
14
14
 
@@ -2,22 +2,34 @@ module AlchemyLanguage
2
2
  module ActiveModel
3
3
  class Base < ActiveMethod::Extra
4
4
  include AlchemyLanguage::Generators::AlchemyRequest
5
- attr_accessor :path, :auth_token, :type, :json_result
5
+ attr_accessor :path, :auth_token, :type, :json_result, :options, :prefix
6
6
 
7
7
  add_response_field(:status)
8
8
  add_response_field(:usage)
9
9
  add_response_field(:url)
10
10
 
11
- def initialize(path, type)
11
+ def initialize(path, type, options={})
12
12
  @path = path
13
13
  @auth_token = AlchemyLanguage.secret_token
14
14
  @type = type
15
+ @options = options
16
+ check_prefix
15
17
  @json_result = request
16
18
  end
17
19
 
18
20
  def request
19
21
  json_parser(endpoint)
20
22
  end
23
+
24
+ def params_addressable
25
+ uri = Addressable::URI.new
26
+ uri.query_values = @options
27
+ uri.query
28
+ end
29
+
30
+ def check_prefix
31
+ @type == "text" ? @prefix = @type.capitalize : @prefix = @type.upcase
32
+ end
21
33
  end
22
34
  end
23
35
  end
@@ -0,0 +1,32 @@
1
+ module AlchemyLanguage
2
+ class HtmlService < 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
+ define_model :entity
12
+ define_model :feed_detaction
13
+ define_model :keyword
14
+ define_model :language_detection
15
+ define_model :microformat
16
+ define_model :publication_date
17
+ define_model :relation
18
+ define_model :typed_relation
19
+ define_model :sentiment_analysis
20
+ define_model :targeted_sentiment
21
+ define_model :taxonomy
22
+ define_model :text
23
+ define_model :raw_text
24
+ define_model :title_extraction
25
+ define_model :combined_call
26
+
27
+ def initialize(text)
28
+ @path = text
29
+ @type = "text"
30
+ end
31
+ end
32
+ end
@@ -3,7 +3,11 @@ module AlchemyLanguage
3
3
  add_response_field(:authors)
4
4
 
5
5
  def endpoint
6
- "#{@type}/URLGetAuthors?apikey=#{@auth_token}&url=#{@path}&outputMode=json"
6
+ url = "#{@type}/#{@prefix}GetAuthors"
7
+ url << "?apikey=#{@auth_token}"
8
+ url << "&#{@type}=#{@path}&outputMode=json"
9
+ url << "&#{params_addressable}" unless params_addressable.empty?
10
+ url
7
11
  end
8
12
  end
9
13
  end
@@ -0,0 +1,34 @@
1
+ module AlchemyLanguage
2
+ class CombinedCall < ActiveModel::Base
3
+ add_response_field(:totalTransactions)
4
+ add_response_field(:language)
5
+
6
+ def initialize(path, type, options={})
7
+ super
8
+ check_options
9
+ end
10
+
11
+ def endpoint
12
+ url = "#{@type}/#{@prefix}GetCombinedData"
13
+ url << "?apikey=#{@auth_token}"
14
+ url << "&#{@type}=#{@path}&outputMode=json"
15
+ url << "&#{params_addressable}" unless params_addressable.empty?
16
+ url
17
+ end
18
+
19
+ def check_options
20
+ if @options.key?(:extract)
21
+ @options[:extract].split(',').each do |option|
22
+ add_dynamic_response_field(option)
23
+ end
24
+ end
25
+ end
26
+
27
+ def add_dynamic_response_field(name)
28
+ self.class.send(:define_method, name) do
29
+ name = name.to_s.gsub('_', '-')
30
+ @json_result[name.to_s]
31
+ end
32
+ end
33
+ end
34
+ end
@@ -3,7 +3,11 @@ module AlchemyLanguage
3
3
  add_response_field(:concepts)
4
4
 
5
5
  def endpoint
6
- "#{@type}/URLGetRankedConcepts?apikey=#{@auth_token}&url=#{@path}&outputMode=json"
6
+ url = "#{@type}/#{@prefix}GetRankedConcepts"
7
+ url << "?apikey=#{@auth_token}"
8
+ url << "&#{@type}=#{@path}&outputMode=json"
9
+ url << "&#{params_addressable}" unless params_addressable.empty?
10
+ url
7
11
  end
8
12
  end
9
13
  end
@@ -5,7 +5,11 @@ module AlchemyLanguage
5
5
  add_response_field(:dates)
6
6
 
7
7
  def endpoint
8
- "#{@type}/URLExtractDates?apikey=#{@auth_token}&url=#{@path}&outputMode=json"
8
+ url = "#{@type}/#{@prefix}ExtractDates"
9
+ url << "?apikey=#{@auth_token}"
10
+ url << "&#{@type}=#{@path}&outputMode=json"
11
+ url << "&#{params_addressable}" unless params_addressable.empty?
12
+ url
9
13
  end
10
14
  end
11
15
  end
@@ -5,7 +5,11 @@ module AlchemyLanguage
5
5
  add_response_field(:docEmotions)
6
6
 
7
7
  def endpoint
8
- "#{@type}/URLGetEmotion?apikey=#{@auth_token}&url=#{@path}&outputMode=json"
8
+ url = "#{@type}/#{@prefix}GetEmotion"
9
+ url << "?apikey=#{@auth_token}"
10
+ url << "&#{@type}=#{@path}&outputMode=json"
11
+ url << "&#{params_addressable}" unless params_addressable.empty?
12
+ url
9
13
  end
10
14
  end
11
15
  end
@@ -4,7 +4,11 @@ module AlchemyLanguage
4
4
  add_response_field(:entities)
5
5
 
6
6
  def endpoint
7
- "#{@type}/URLGetRankedNamedEntities?apikey=#{@auth_token}&url=#{@path}&outputMode=json"
7
+ url = "#{@type}/#{@prefix}GetRankedNamedEntities"
8
+ url << "?apikey=#{@auth_token}"
9
+ url << "&#{@type}=#{@path}&outputMode=json"
10
+ url << "&#{params_addressable}" unless params_addressable.empty?
11
+ url
8
12
  end
9
13
  end
10
14
  end
@@ -3,7 +3,11 @@ module AlchemyLanguage
3
3
  add_response_field(:feeds)
4
4
 
5
5
  def endpoint
6
- "#{@type}/URLGetFeedLinks?apikey=#{@auth_token}&url=#{@path}&outputMode=json"
6
+ url = "#{@type}/#{@prefix}GetFeedLinks"
7
+ url << "?apikey=#{@auth_token}"
8
+ url << "&#{@type}=#{@path}&outputMode=json"
9
+ url << "&#{params_addressable}" unless params_addressable.empty?
10
+ url
7
11
  end
8
12
  end
9
13
  end
@@ -5,7 +5,11 @@ module AlchemyLanguage
5
5
  add_response_field(:keywords)
6
6
 
7
7
  def endpoint
8
- "#{@type}/URLGetRankedKeywords?apikey=#{@auth_token}&url=#{@path}&outputMode=json"
8
+ url = "#{@type}/#{@prefix}GetRankedKeywords"
9
+ url << "?apikey=#{@auth_token}"
10
+ url << "&#{@type}=#{@path}&outputMode=json"
11
+ url << "&#{params_addressable}" unless params_addressable.empty?
12
+ url
9
13
  end
10
14
  end
11
15
  end
@@ -9,7 +9,11 @@ module AlchemyLanguage
9
9
  add_response_field(:wikipedia)
10
10
 
11
11
  def endpoint
12
- "#{@type}/URLGetLanguage?apikey=#{@auth_token}&url=#{@path}&outputMode=json"
12
+ url = "#{@type}/#{@prefix}GetLanguage"
13
+ url << "?apikey=#{@auth_token}"
14
+ url << "&#{@type}=#{@path}&outputMode=json"
15
+ url << "&#{params_addressable}" unless params_addressable.empty?
16
+ url
13
17
  end
14
18
  end
15
19
  end
@@ -3,7 +3,11 @@ module AlchemyLanguage
3
3
  add_response_field(:microformats)
4
4
 
5
5
  def endpoint
6
- "#{@type}/URLGetMicroformatData?apikey=#{@auth_token}&url=#{@path}&outputMode=json"
6
+ url = "#{@type}/#{@prefix}GetMicroformatData"
7
+ url << "?apikey=#{@auth_token}"
8
+ url << "&#{@type}=#{@path}&outputMode=json"
9
+ url << "&#{params_addressable}" unless params_addressable.empty?
10
+ url
7
11
  end
8
12
  end
9
13
  end
@@ -2,10 +2,14 @@ module AlchemyLanguage
2
2
  class PublicationDate < ActiveModel::Base
3
3
  add_response_field(:totalTransactions)
4
4
  add_response_field(:language)
5
- add_response_field(:publicationDate)
5
+ add_response_field(:publicationDate)
6
6
 
7
7
  def endpoint
8
- "#{@type}/URLGetPubDate?apikey=#{@auth_token}&url=#{@path}&outputMode=json"
8
+ url = "#{@type}/#{@prefix}GetPubDate"
9
+ url << "?apikey=#{@auth_token}"
10
+ url << "&#{@type}=#{@path}&outputMode=json"
11
+ url << "&#{params_addressable}" unless params_addressable.empty?
12
+ url
9
13
  end
10
14
  end
11
15
  end
@@ -3,7 +3,11 @@ module AlchemyLanguage
3
3
  add_response_field(:text)
4
4
 
5
5
  def endpoint
6
- "#{@type}/URLGetRawText?apikey=#{@auth_token}&url=#{@path}&outputMode=json"
6
+ url = "#{@type}/#{@prefix}GetRawText"
7
+ url << "?apikey=#{@auth_token}"
8
+ url << "&#{@type}=#{@path}&outputMode=json"
9
+ url << "&#{params_addressable}" unless params_addressable.empty?
10
+ url
7
11
  end
8
12
  end
9
13
  end
@@ -4,7 +4,11 @@ module AlchemyLanguage
4
4
  add_response_field(:relations)
5
5
 
6
6
  def endpoint
7
- "#{@type}/URLGetRelations?apikey=#{@auth_token}&url=#{@path}&outputMode=json"
7
+ url = "#{@type}/#{@prefix}GetRelations"
8
+ url << "?apikey=#{@auth_token}"
9
+ url << "&#{@type}=#{@path}&outputMode=json"
10
+ url << "&#{params_addressable}" unless params_addressable.empty?
11
+ url
8
12
  end
9
13
  end
10
14
  end
@@ -5,7 +5,11 @@ module AlchemyLanguage
5
5
  add_response_field(:docSentiment)
6
6
 
7
7
  def endpoint
8
- "#{@type}/URLGetTextSentiment?apikey=#{@auth_token}&url=#{@path}&outputMode=json"
8
+ url = "#{@type}/#{@prefix}GetTextSentiment"
9
+ url << "?apikey=#{@auth_token}"
10
+ url << "&#{@type}=#{@path}&outputMode=json"
11
+ url << "&#{params_addressable}" unless params_addressable.empty?
12
+ url
9
13
  end
10
14
  end
11
15
  end
@@ -5,7 +5,11 @@ module AlchemyLanguage
5
5
  add_response_field(:results)
6
6
 
7
7
  def endpoint
8
- "#{@type}/URLGetTargetedEmotion?apikey=#{@auth_token}&url=#{@path}&outputMode=json"
8
+ url = "#{@type}/#{@prefix}GetTargetedEmotion"
9
+ url << "?apikey=#{@auth_token}"
10
+ url << "&#{@type}=#{@path}&outputMode=json"
11
+ url << "&#{params_addressable}" unless params_addressable.empty?
12
+ url
9
13
  end
10
14
  end
11
15
  end
@@ -5,7 +5,11 @@ module AlchemyLanguage
5
5
  add_response_field(:results)
6
6
 
7
7
  def endpoint
8
- "#{@type}/URLGetTargetedSentiment?apikey=#{@auth_token}&url=#{@path}&outputMode=json"
8
+ url = "#{@type}/#{@prefix}GetTargetedSentiment"
9
+ url << "?apikey=#{@auth_token}"
10
+ url << "&#{@type}=#{@path}&outputMode=json"
11
+ url << "&#{params_addressable}" unless params_addressable.empty?
12
+ url
9
13
  end
10
14
  end
11
15
  end
@@ -5,7 +5,11 @@ module AlchemyLanguage
5
5
  add_response_field(:taxonomy)
6
6
 
7
7
  def endpoint
8
- "#{@type}/URLGetRankedTaxonomy?apikey=#{@auth_token}&url=#{@path}&outputMode=json"
8
+ url = "#{@type}/#{@prefix}GetRankedTaxonomy"
9
+ url << "?apikey=#{@auth_token}"
10
+ url << "&#{@type}=#{@path}&outputMode=json"
11
+ url << "&#{params_addressable}" unless params_addressable.empty?
12
+ url
9
13
  end
10
14
  end
11
15
  end
@@ -4,7 +4,11 @@ module AlchemyLanguage
4
4
  add_response_field(:text)
5
5
 
6
6
  def endpoint
7
- "#{@type}/URLGetText?apikey=#{@auth_token}&url=#{@path}&outputMode=json"
7
+ url = "#{@type}/#{@prefix}GetText"
8
+ url << "?apikey=#{@auth_token}"
9
+ url << "&#{@type}=#{@path}&outputMode=json"
10
+ url << "&#{params_addressable}" unless params_addressable.empty?
11
+ url
8
12
  end
9
13
  end
10
14
  end
@@ -3,7 +3,11 @@ module AlchemyLanguage
3
3
  add_response_field(:title)
4
4
 
5
5
  def endpoint
6
- "#{@type}/URLGetTitle?apikey=#{@auth_token}&url=#{@path}&outputMode=json"
6
+ url = "#{@type}/#{@prefix}GetTitle"
7
+ url << "?apikey=#{@auth_token}"
8
+ url << "&#{@type}=#{@path}&outputMode=json"
9
+ url << "&#{params_addressable}" unless params_addressable.empty?
10
+ url
7
11
  end
8
12
  end
9
13
  end
@@ -5,7 +5,11 @@ module AlchemyLanguage
5
5
  add_response_field(:typedRelations)
6
6
 
7
7
  def endpoint
8
- "#{@type}/URLGetTypedRelations?apikey=#{@auth_token}&url=#{@path}&outputMode=json"
8
+ url = "#{@type}/#{@prefix}GetTypedRelations"
9
+ url << "?apikey=#{@auth_token}"
10
+ url << "&#{@type}=#{@path}&outputMode=json"
11
+ url << "&#{params_addressable}" unless params_addressable.empty?
12
+ url
9
13
  end
10
14
  end
11
15
  end
@@ -0,0 +1,32 @@
1
+ module AlchemyLanguage
2
+ class TextService < 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
+ define_model :entity
12
+ define_model :feed_detaction
13
+ define_model :keyword
14
+ define_model :language_detection
15
+ define_model :microformat
16
+ define_model :publication_date
17
+ define_model :relation
18
+ define_model :typed_relation
19
+ define_model :sentiment_analysis
20
+ define_model :targeted_sentiment
21
+ define_model :taxonomy
22
+ define_model :text
23
+ define_model :raw_text
24
+ define_model :title_extraction
25
+ define_model :combined_call
26
+
27
+ def initialize(text)
28
+ @path = text
29
+ @type = "text"
30
+ end
31
+ end
32
+ end
@@ -22,6 +22,7 @@ module AlchemyLanguage
22
22
  define_model :text
23
23
  define_model :raw_text
24
24
  define_model :title_extraction
25
+ define_model :combined_call
25
26
 
26
27
  def initialize(path)
27
28
  is_url?
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: alchemy_language
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.2
4
+ version: 1.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Diamant Kolshi
@@ -23,7 +23,9 @@ files:
23
23
  - lib/alchemy_language/active_method/extra.rb
24
24
  - lib/alchemy_language/active_model/base.rb
25
25
  - lib/alchemy_language/generator/alchemy_request.rb
26
+ - lib/alchemy_language/html_service.rb
26
27
  - lib/alchemy_language/model/author.rb
28
+ - lib/alchemy_language/model/combined_call.rb
27
29
  - lib/alchemy_language/model/concept.rb
28
30
  - lib/alchemy_language/model/date_extraction.rb
29
31
  - lib/alchemy_language/model/emotion_analysis.rb
@@ -42,6 +44,7 @@ files:
42
44
  - lib/alchemy_language/model/text.rb
43
45
  - lib/alchemy_language/model/title_extraction.rb
44
46
  - lib/alchemy_language/model/typed_relation.rb
47
+ - lib/alchemy_language/text_service.rb
45
48
  - lib/alchemy_language/url_service.rb
46
49
  homepage: https://github.com/diamantkolshi/alchemy_language
47
50
  licenses: