dandelionapi 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: d9207ec230e110a9845eaf6d8daacb4f41ac6be1
4
+ data.tar.gz: 693aedb6c8b538106c44a9f21c4abca183ff2fce
5
+ SHA512:
6
+ metadata.gz: b0f3a098862eff987c89fe905c20bb260d50f711da5295e43c77af00375a6de34a52d6e31bf0f53f46b3c959873bfbba4b0625f069fa54acaba010ea89875349
7
+ data.tar.gz: 8816f5f5685d9ebd96dc2073beb58ba8b8853cb1abcd7793d4743b1a3fbc4b2042acec7efc2f867768188ee09f0b0741debc15895384ca32cf9bc135df9798dd
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
@@ -0,0 +1,4 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.2.1
4
+ before_install: gem install bundler -v 1.10.5
@@ -0,0 +1,13 @@
1
+ # Contributor Code of Conduct
2
+
3
+ As contributors and maintainers of this project, we pledge to respect all people who contribute through reporting issues, posting feature requests, updating documentation, submitting pull requests or patches, and other activities.
4
+
5
+ We are committed to making participation in this project a harassment-free experience for everyone, regardless of level of experience, gender, gender identity and expression, sexual orientation, disability, personal appearance, body size, race, ethnicity, age, or religion.
6
+
7
+ Examples of unacceptable behavior by participants include the use of sexual language or imagery, derogatory comments or personal attacks, trolling, public or private harassment, insults, or other unprofessional conduct.
8
+
9
+ Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct. Project maintainers who do not follow the Code of Conduct may be removed from the project team.
10
+
11
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by opening an issue or contacting one or more of the project maintainers.
12
+
13
+ This Code of Conduct is adapted from the [Contributor Covenant](http://contributor-covenant.org), version 1.0.0, available at [http://contributor-covenant.org/version/1/0/0/](http://contributor-covenant.org/version/1/0/0/)
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in dandelionapi.gemspec
4
+ gemspec
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2015 Andrea Mostosi
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
@@ -0,0 +1,53 @@
1
+ # [![Ruby Gem Icon](https://raw.githubusercontent.com/zenkay/dandelionapi-ruby/master/rubygem.png)](https://rubygems.org/gems/dandelionapi) Dandelion API Ruby Gem
2
+
3
+ [![Code Climate](https://codeclimate.com/github/zenkay/dandelionapi-ruby/badges/gpa.svg)](https://codeclimate.com/github/zenkay/dandelionapi-ruby) [![Travis CI](https://travis-ci.org/zenkay/dandelionapi-ruby.svg?branch=master)](https://travis-ci.org/zenkay/dandelionapi-ruby) [![Gem Version](https://badge.fury.io/rb/dandelionapi.svg)](http://badge.fury.io/rb/dandelionapi) [![Coverage Status](https://coveralls.io/repos/zenkay/dandelionapi-ruby/badge.png?branch=master)](https://coveralls.io/r/zenkay/dandelionapi-ruby?branch=master)
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```
10
+ gem 'dandelionapi'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ ```
16
+ $ bundle install
17
+ ```
18
+ ## Setup
19
+
20
+ Setup configuration parameters
21
+
22
+ ```
23
+ Dandelionapi.configure do |c|
24
+ c.app_id = "your-app-id-for-dandelionapi-account"
25
+ c.app_key = "your-app-key-for-dandelionapi-account"
26
+ c.endpoint = "https://api.dandelion.eu/"
27
+ end
28
+ ```
29
+
30
+ ## Usage
31
+
32
+ _Methods references are taken from [Dandelion API's documentation](https://dandelion.eu/docs/)._
33
+
34
+ **Entity Extraction API**: is a named entity extraction & linking API that performs very well even on short texts, on which many other similar services do not. dataTXT-NEX currently works on English, French, German, Italian and Portuguese texts. With this API you will be able to automatically tag your texts, extracting Wikipedia entities and enriching your data.
35
+
36
+ ```
37
+ element = Dandelionapi::EntityExtraction.new
38
+ response = element.analyze(text: "This is a test")
39
+ ```
40
+
41
+ **Text Similarity API**: is a semantic sentence similarity API optimized on short sentences. With this API you will be able to compare two sentences and get a score of their semantic similarity. It works even if the two sentences don't have any word in common.
42
+
43
+ ```
44
+ element = Dandelionapi::TextSimilarity.new
45
+ response = element.analyze(text1: "This is a test", text2: "This is another test")
46
+ ```
47
+
48
+ **Language Detection API**: is a simple language identification API; it is a tool that may be useful when dealing with texts, so we decided to open it to all our users. It currently supports more than 50 languages.
49
+
50
+ ```
51
+ element = Dandelionapi::LanguageDetection.new
52
+ response = element.analyze(text: "Questo è un test")
53
+ ```
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "dandelionapi"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
@@ -0,0 +1,7 @@
1
+ #!/bin/bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+
5
+ bundle install
6
+
7
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,34 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'dandelionapi/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "dandelionapi"
8
+ spec.version = Dandelionapi::VERSION
9
+ spec.authors = ["Andrea Mostosi"]
10
+ spec.email = ["andrea.mostosi@zenkay.net"]
11
+
12
+ spec.summary = %q{Ruby Gem for Dandelion API service}
13
+ spec.description = %q{Ruby Gem for Dandelion API service. Available endpoint: Entity Extraction, Text Similarity and Language Detection}
14
+ spec.homepage = "https://github.com/zenkay/dandelionapi-ruby"
15
+ spec.license = "MIT"
16
+
17
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
18
+ spec.bindir = "exe"
19
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
20
+ spec.require_paths = ["lib"]
21
+
22
+ spec.required_ruby_version = '~> 2.0'
23
+
24
+ spec.add_dependency "faraday", '~> 0.9', '>= 0.9.0'
25
+ spec.add_dependency "faraday_middleware", '~> 0.9', '>= 0.9.1'
26
+
27
+ spec.add_development_dependency "bundler", "~> 1.10"
28
+ spec.add_development_dependency "rake", "~> 10.1"
29
+ spec.add_development_dependency "rspec","~> 3.3"
30
+ spec.add_development_dependency "vcr", "~> 2.4"
31
+ spec.add_development_dependency "webmock", "~> 1.17"
32
+ spec.add_development_dependency "simplecov", "~> 0.8"
33
+ spec.add_development_dependency "coveralls", "~> 0.7"
34
+ end
@@ -0,0 +1,23 @@
1
+ require "dandelionapi/version"
2
+
3
+ require "dandelionapi/base"
4
+ require "dandelionapi/entity_extraction"
5
+ require "dandelionapi/text_similarity"
6
+ require "dandelionapi/language_detection"
7
+
8
+ module Dandelionapi
9
+ def self.configure(&block)
10
+ yield @config ||= Configuration.new
11
+ end
12
+
13
+ def self.config
14
+ @config
15
+ end
16
+
17
+ class Configuration
18
+ attr_accessor :app_id, :app_key, :endpoint
19
+ end
20
+
21
+ class BadResponse < Exception; end
22
+ class BadParameters < Exception; end
23
+ end
@@ -0,0 +1,30 @@
1
+ require "faraday"
2
+ require "faraday_middleware"
3
+ require "json"
4
+
5
+ module Dandelionapi
6
+
7
+ class Base
8
+
9
+ protected
10
+
11
+ def call(endpoint, params)
12
+ begin
13
+ params = params.merge(
14
+ :$app_id => Dandelionapi.config.app_id,
15
+ :$app_key => Dandelionapi.config.app_key
16
+ )
17
+ conn = Faraday.new(url: Dandelionapi.config.endpoint) do |faraday|
18
+ faraday.request :url_encoded
19
+ faraday.adapter Faraday.default_adapter
20
+ end
21
+ response = conn.post endpoint, params
22
+ JSON.parse response.body
23
+ rescue Exception => e
24
+ raise Dandelionapi::BadResponse
25
+ end
26
+ end
27
+
28
+ end
29
+
30
+ end
@@ -0,0 +1,23 @@
1
+ require "faraday"
2
+ require "faraday_middleware"
3
+ require "json"
4
+
5
+ module Dandelionapi
6
+
7
+ class EntityExtraction < Base
8
+
9
+ ENDPOINT = "/datatxt/nex/v1"
10
+
11
+ attr_accessor :text, :url, :html, :html_fragment, :lang, :min_confidence, :min_length, :social_hashtag, :social_mention, :include, :extra_types, :country, :custom_spots
12
+
13
+ def analyze(options)
14
+
15
+ raise BadParameters.new("Please provide one of the following parameters: text, url, html or html_fragment") if ([:text, :url, :html, :html_fragment] & options.keys).empty?
16
+
17
+ params = options
18
+ call(ENDPOINT, params)
19
+ end
20
+
21
+ end
22
+
23
+ end
@@ -0,0 +1,20 @@
1
+ require "faraday"
2
+ require "faraday_middleware"
3
+ require "json"
4
+
5
+ module Dandelionapi
6
+
7
+ class LanguageDetection < Base
8
+
9
+ ENDPOINT = "/datatxt/li/v1"
10
+
11
+ attr_accessor :text, :url, :html, :html_fragment, :clean
12
+
13
+ def analyze(options)
14
+ params = options
15
+ call(ENDPOINT, params)
16
+ end
17
+
18
+ end
19
+
20
+ end
@@ -0,0 +1,20 @@
1
+ require "faraday"
2
+ require "faraday_middleware"
3
+ require "json"
4
+
5
+ module Dandelionapi
6
+
7
+ class TextSimilarity < Base
8
+
9
+ ENDPOINT = "/datatxt/sim/v1"
10
+
11
+ attr_accessor :text1, :url1, :html1, :html_fragment1, :text2, :url2, :html2, :html_fragment2, :lang, :bow
12
+
13
+ def analyze(options)
14
+ params = options
15
+ call(ENDPOINT, params)
16
+ end
17
+
18
+ end
19
+
20
+ end
@@ -0,0 +1,3 @@
1
+ module Dandelionapi
2
+ VERSION = "0.0.1"
3
+ end
Binary file
metadata ADDED
@@ -0,0 +1,202 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: dandelionapi
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Andrea Mostosi
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2015-07-04 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: faraday
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '0.9'
20
+ - - ">="
21
+ - !ruby/object:Gem::Version
22
+ version: 0.9.0
23
+ type: :runtime
24
+ prerelease: false
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ requirements:
27
+ - - "~>"
28
+ - !ruby/object:Gem::Version
29
+ version: '0.9'
30
+ - - ">="
31
+ - !ruby/object:Gem::Version
32
+ version: 0.9.0
33
+ - !ruby/object:Gem::Dependency
34
+ name: faraday_middleware
35
+ requirement: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - "~>"
38
+ - !ruby/object:Gem::Version
39
+ version: '0.9'
40
+ - - ">="
41
+ - !ruby/object:Gem::Version
42
+ version: 0.9.1
43
+ type: :runtime
44
+ prerelease: false
45
+ version_requirements: !ruby/object:Gem::Requirement
46
+ requirements:
47
+ - - "~>"
48
+ - !ruby/object:Gem::Version
49
+ version: '0.9'
50
+ - - ">="
51
+ - !ruby/object:Gem::Version
52
+ version: 0.9.1
53
+ - !ruby/object:Gem::Dependency
54
+ name: bundler
55
+ requirement: !ruby/object:Gem::Requirement
56
+ requirements:
57
+ - - "~>"
58
+ - !ruby/object:Gem::Version
59
+ version: '1.10'
60
+ type: :development
61
+ prerelease: false
62
+ version_requirements: !ruby/object:Gem::Requirement
63
+ requirements:
64
+ - - "~>"
65
+ - !ruby/object:Gem::Version
66
+ version: '1.10'
67
+ - !ruby/object:Gem::Dependency
68
+ name: rake
69
+ requirement: !ruby/object:Gem::Requirement
70
+ requirements:
71
+ - - "~>"
72
+ - !ruby/object:Gem::Version
73
+ version: '10.1'
74
+ type: :development
75
+ prerelease: false
76
+ version_requirements: !ruby/object:Gem::Requirement
77
+ requirements:
78
+ - - "~>"
79
+ - !ruby/object:Gem::Version
80
+ version: '10.1'
81
+ - !ruby/object:Gem::Dependency
82
+ name: rspec
83
+ requirement: !ruby/object:Gem::Requirement
84
+ requirements:
85
+ - - "~>"
86
+ - !ruby/object:Gem::Version
87
+ version: '3.3'
88
+ type: :development
89
+ prerelease: false
90
+ version_requirements: !ruby/object:Gem::Requirement
91
+ requirements:
92
+ - - "~>"
93
+ - !ruby/object:Gem::Version
94
+ version: '3.3'
95
+ - !ruby/object:Gem::Dependency
96
+ name: vcr
97
+ requirement: !ruby/object:Gem::Requirement
98
+ requirements:
99
+ - - "~>"
100
+ - !ruby/object:Gem::Version
101
+ version: '2.4'
102
+ type: :development
103
+ prerelease: false
104
+ version_requirements: !ruby/object:Gem::Requirement
105
+ requirements:
106
+ - - "~>"
107
+ - !ruby/object:Gem::Version
108
+ version: '2.4'
109
+ - !ruby/object:Gem::Dependency
110
+ name: webmock
111
+ requirement: !ruby/object:Gem::Requirement
112
+ requirements:
113
+ - - "~>"
114
+ - !ruby/object:Gem::Version
115
+ version: '1.17'
116
+ type: :development
117
+ prerelease: false
118
+ version_requirements: !ruby/object:Gem::Requirement
119
+ requirements:
120
+ - - "~>"
121
+ - !ruby/object:Gem::Version
122
+ version: '1.17'
123
+ - !ruby/object:Gem::Dependency
124
+ name: simplecov
125
+ requirement: !ruby/object:Gem::Requirement
126
+ requirements:
127
+ - - "~>"
128
+ - !ruby/object:Gem::Version
129
+ version: '0.8'
130
+ type: :development
131
+ prerelease: false
132
+ version_requirements: !ruby/object:Gem::Requirement
133
+ requirements:
134
+ - - "~>"
135
+ - !ruby/object:Gem::Version
136
+ version: '0.8'
137
+ - !ruby/object:Gem::Dependency
138
+ name: coveralls
139
+ requirement: !ruby/object:Gem::Requirement
140
+ requirements:
141
+ - - "~>"
142
+ - !ruby/object:Gem::Version
143
+ version: '0.7'
144
+ type: :development
145
+ prerelease: false
146
+ version_requirements: !ruby/object:Gem::Requirement
147
+ requirements:
148
+ - - "~>"
149
+ - !ruby/object:Gem::Version
150
+ version: '0.7'
151
+ description: 'Ruby Gem for Dandelion API service. Available endpoint: Entity Extraction,
152
+ Text Similarity and Language Detection'
153
+ email:
154
+ - andrea.mostosi@zenkay.net
155
+ executables: []
156
+ extensions: []
157
+ extra_rdoc_files: []
158
+ files:
159
+ - ".gitignore"
160
+ - ".rspec"
161
+ - ".travis.yml"
162
+ - CODE_OF_CONDUCT.md
163
+ - Gemfile
164
+ - LICENSE.txt
165
+ - README.md
166
+ - Rakefile
167
+ - bin/console
168
+ - bin/setup
169
+ - dandelionapi.gemspec
170
+ - lib/dandelionapi.rb
171
+ - lib/dandelionapi/base.rb
172
+ - lib/dandelionapi/entity_extraction.rb
173
+ - lib/dandelionapi/language_detection.rb
174
+ - lib/dandelionapi/text_similarity.rb
175
+ - lib/dandelionapi/version.rb
176
+ - rubygem.png
177
+ homepage: https://github.com/zenkay/dandelionapi-ruby
178
+ licenses:
179
+ - MIT
180
+ metadata: {}
181
+ post_install_message:
182
+ rdoc_options: []
183
+ require_paths:
184
+ - lib
185
+ required_ruby_version: !ruby/object:Gem::Requirement
186
+ requirements:
187
+ - - "~>"
188
+ - !ruby/object:Gem::Version
189
+ version: '2.0'
190
+ required_rubygems_version: !ruby/object:Gem::Requirement
191
+ requirements:
192
+ - - ">="
193
+ - !ruby/object:Gem::Version
194
+ version: '0'
195
+ requirements: []
196
+ rubyforge_project:
197
+ rubygems_version: 2.4.6
198
+ signing_key:
199
+ specification_version: 4
200
+ summary: Ruby Gem for Dandelion API service
201
+ test_files: []
202
+ has_rdoc: