-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
21 changed files
with
522 additions
and
291 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
require 'rosette_api' | ||
|
||
api_key, url = ARGV | ||
|
||
if !url | ||
rosette_api = RosetteAPI.new(api_key) | ||
else | ||
rosette_api = RosetteAPI.new(api_key, url) | ||
end | ||
|
||
name_dedupe_data = 'John Smith,Johnathon Smith,Fred Jones' | ||
|
||
threshold = 0.75 | ||
names = name_dedupe_data.split(',').map { |n| NameParameter.new(n) } | ||
begin | ||
params = NameDeduplicationParameters.new(names, threshold) | ||
response = rosette_api.get_name_deduplication(params) | ||
puts JSON.pretty_generate(response) | ||
rescue RosetteAPIError => rosette_api_error | ||
printf('Rosette API Error (%s): %s', rosette_api_error.status_code, rosette_api_error.message) | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
require 'rosette_api' | ||
|
||
api_key, url = ARGV | ||
|
||
if !url | ||
rosette_api = RosetteAPI.new(api_key) | ||
else | ||
rosette_api = RosetteAPI.new(api_key, url) | ||
end | ||
|
||
transliteration_content_data = 'Kareem Abdul Jabbar holds the records for most points in the NBA' | ||
|
||
begin | ||
params = DocumentParameters.new | ||
params.content = transliteration_content_data | ||
response = rosette_api.get_transliteration(params) | ||
puts JSON.pretty_generate(response) | ||
rescue RosetteAPIError => rosette_api_error | ||
printf('Rosette API Error (%s): %s', rosette_api_error.status_code, rosette_api_error.message) | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
require_relative 'bad_request_error' | ||
require_relative 'name_parameter' | ||
|
||
# This class encapsulates parameters that are needed for name-deduplication in | ||
# Rosette API. | ||
class NameDeduplicationParameters | ||
# Rosette API options (optional, should be a hash) | ||
attr_accessor :rosette_options | ||
# List of Name objects to be de-duplicated | ||
attr_accessor :names | ||
# Threshold for determining cluster size | ||
attr_accessor :threshold | ||
|
||
def initialize(names, threshold, options = {}) #:notnew: | ||
options = { | ||
rosette_options: nil | ||
}.update options | ||
@names = names | ||
@threshold = threshold | ||
@rosette_options = options[:rosette_options] | ||
end | ||
|
||
# Validates the parameters by checking if name1 and name2 are instances of | ||
# a String or NameParameter. | ||
def validate_params | ||
raise BadRequestError.new('names must be an array of name_parameter') unless @names.instance_of? Array | ||
if @threshold | ||
raise BadRequestError.new('threshold must be a float') unless @threshold.is_a?(Float) | ||
raise BadRequestError.new('threshold must be in the range of 0 to 1') if @threshold.negative? || @threshold > 1 | ||
end | ||
if @rosette_options | ||
raise BadRequestError.new('rosette_options can only be an instance of a Hash') unless @rosette_options.is_a? Hash | ||
end | ||
end | ||
|
||
# Converts this class to Hash with its keys in lower CamelCase. | ||
# | ||
# Returns the new Hash. | ||
def load_params | ||
validate_params | ||
to_hash.select { |_key, value| value } | ||
.map { |key, value| [key.to_s.split('_').map(&:capitalize).join.sub!(/\D/, &:downcase), value] } | ||
.to_h | ||
end | ||
|
||
# Converts this class to Hash. | ||
# | ||
# Returns the new Hash. | ||
def to_hash | ||
{ | ||
names: @names.map(&:load_param), | ||
threshold: @threshold, | ||
options: @rosette_options | ||
} | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.