diff --git a/.rubocop.yml b/.rubocop.yml new file mode 100644 index 0000000..44c5710 --- /dev/null +++ b/.rubocop.yml @@ -0,0 +1,312 @@ +# This configuration was generated by +# `rubocop --auto-gen-config` +# on 2016-12-07 10:52:04 -0500 using RuboCop version 0.46.0. +# The point is for the user to remove these configuration records +# one by one as the offenses are removed from the code base. +# Note that changes in the inspected code, or installation of new +# versions of RuboCop, may require this file to be generated again. + +# Offense count: 1 +# Configuration parameters: Include. +# Include: **/Gemfile, **/gems.rb +Bundler/OrderedGems: + Exclude: + - 'Gemfile' + +# Offense count: 2 +Lint/Void: + Exclude: + - 'examples/sentences.rb' + - 'examples/sentiment.rb' + +# Offense count: 3 +Metrics/AbcSize: + Max: 41 + +# Offense count: 4 +# Configuration parameters: CountComments. +Metrics/BlockLength: + Max: 425 + +# Offense count: 2 +# Configuration parameters: CountComments. +Metrics/ClassLength: + Max: 140 + +# Offense count: 142 +# Configuration parameters: AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, IgnoredPatterns. +# URISchemes: http, https +Metrics/LineLength: + Max: 408 + +# Offense count: 6 +# Configuration parameters: CountComments. +Metrics/MethodLength: + Max: 42 + +# Offense count: 1 +# Configuration parameters: CountKeywordArgs. +Metrics/ParameterLists: + Max: 6 + +# Offense count: 94 +# Cop supports --auto-correct. +# Configuration parameters: EnforcedHashRocketStyle, EnforcedColonStyle, EnforcedLastArgumentHashStyle, SupportedLastArgumentHashStyles. +# SupportedLastArgumentHashStyles: always_inspect, always_ignore, ignore_implicit, ignore_explicit +Style/AlignHash: + Exclude: + - 'tests/tests_spec.rb' + +# Offense count: 1 +# Cop supports --auto-correct. +# Configuration parameters: EnforcedStyle, SupportedStyles, ProceduralMethods, FunctionalMethods, IgnoredMethods. +# SupportedStyles: line_count_based, semantic, braces_for_chaining +# ProceduralMethods: benchmark, bm, bmbm, create, each_with_object, measure, new, realtime, tap, with_object +# FunctionalMethods: let, let!, subject, watch +# IgnoredMethods: lambda, proc, it +Style/BlockDelimiters: + Exclude: + - 'tests/tests_spec.rb' + +# Offense count: 1 +# Cop supports --auto-correct. +Style/BlockEndNewline: + Exclude: + - 'tests/tests_spec.rb' + +# Offense count: 18 +# Cop supports --auto-correct. +# Configuration parameters: EnforcedStyle, SupportedStyles, SingleLineConditionsOnly. +# SupportedStyles: assign_to_condition, assign_inside_condition +Style/ConditionalAssignment: + Enabled: false + +# Offense count: 40 +# Cop supports --auto-correct. +# Configuration parameters: EnforcedStyle, SupportedStyles. +# SupportedStyles: leading, trailing +Style/DotPosition: + Exclude: + - 'tests/tests_spec.rb' + +# Offense count: 1 +# Cop supports --auto-correct. +# Configuration parameters: AllowAdjacentOneLineDefs. +Style/EmptyLineBetweenDefs: + Exclude: + - 'lib/rosette_api.rb' + +# Offense count: 4 +# Cop supports --auto-correct. +Style/EmptyLines: + Exclude: + - 'examples/sentiment.rb' + - 'lib/request_builder.rb' + - 'rosette_api.gemspec' + +# Offense count: 2 +# Cop supports --auto-correct. +# Configuration parameters: EnforcedStyle, SupportedStyles. +# SupportedStyles: empty_lines, no_empty_lines +Style/EmptyLinesAroundBlockBody: + Exclude: + - 'tests/tests_spec.rb' + +# Offense count: 1 +# Cop supports --auto-correct. +Style/EmptyLinesAroundMethodBody: + Exclude: + - 'lib/request_builder.rb' + +# Offense count: 3 +# Configuration parameters: ExpectMatchingDefinition, Regex, IgnoreExecutableScripts. +Style/FileName: + Exclude: + - 'examples/morphology_compound-components.rb' + - 'examples/morphology_han-readings.rb' + - 'examples/morphology_parts-of-speech.rb' + +# Offense count: 2 +# Configuration parameters: SupportedStyles. +# SupportedStyles: for, each +Style/For: + EnforcedStyle: for + +# Offense count: 30 +# Cop supports --auto-correct. +# Configuration parameters: EnforcedStyle, SupportedStyles. +# SupportedStyles: when_needed, always +Style/FrozenStringLiteralComment: + Enabled: false + +# Offense count: 4 +# Configuration parameters: MinBodyLength. +Style/GuardClause: + Exclude: + - 'lib/name_similarity_parameters.rb' + - 'lib/name_translation_parameters.rb' + - 'lib/request_builder.rb' + +# Offense count: 90 +# Cop supports --auto-correct. +# Configuration parameters: EnforcedStyle, SupportedStyles, UseHashRocketsWithSymbolValues, PreferHashRocketsForNonAlnumEndingSymbols. +# SupportedStyles: ruby19, hash_rockets, no_mixed_keys, ruby19_no_mixed_keys +Style/HashSyntax: + Exclude: + - 'tests/tests_spec.rb' + +# Offense count: 3 +# Cop supports --auto-correct. +# Configuration parameters: EnforcedStyle, SupportedStyles. +# SupportedStyles: normal, rails +Style/IndentationConsistency: + Exclude: + - 'examples/sentences.rb' + - 'examples/sentiment.rb' + - 'lib/rosette_api.rb' + +# Offense count: 5 +# Cop supports --auto-correct. +# Configuration parameters: Width. +Style/IndentationWidth: + Exclude: + - 'examples/morphology_han-readings.rb' + - 'lib/request_builder.rb' + - 'tests/tests_spec.rb' + +# Offense count: 1 +# Cop supports --auto-correct. +Style/MultilineBlockLayout: + Exclude: + - 'tests/tests_spec.rb' + +# Offense count: 41 +# Cop supports --auto-correct. +# Configuration parameters: EnforcedStyle, SupportedStyles, IndentationWidth. +# SupportedStyles: aligned, indented, indented_relative_to_receiver +Style/MultilineMethodCallIndentation: + Exclude: + - 'tests/tests_spec.rb' + +# Offense count: 15 +# Cop supports --auto-correct. +Style/MutableConstant: + Exclude: + - 'lib/rosette_api.rb' + +# Offense count: 1 +# Cop supports --auto-correct. +Style/NegatedIf: + Exclude: + - 'lib/name_translation_parameters.rb' + +# Offense count: 1 +# Cop supports --auto-correct. +# Configuration parameters: IncludeSemanticChanges. +Style/NonNilCheck: + Exclude: + - 'lib/request_builder.rb' + +# Offense count: 2 +Style/OptionalArguments: + Exclude: + - 'lib/request_builder.rb' + +# Offense count: 4 +# Cop supports --auto-correct. +# Configuration parameters: PreferredDelimiters. +Style/PercentLiteralDelimiters: + Exclude: + - 'rosette_api.gemspec' + +# Offense count: 8 +# Cop supports --auto-correct. +# Configuration parameters: SupportedStyles. +# SupportedStyles: compact, exploded +Style/RaiseArgs: + EnforcedStyle: compact + +# Offense count: 7 +# Cop supports --auto-correct. +Style/RedundantSelf: + Exclude: + - 'lib/document_parameters.rb' + - 'lib/name_parameter.rb' + - 'lib/name_similarity_parameters.rb' + - 'lib/name_translation_parameters.rb' + +# Offense count: 1 +# Cop supports --auto-correct. +Style/SpaceAfterColon: + Exclude: + - 'examples/name_similarity.rb' + +# Offense count: 2 +# Cop supports --auto-correct. +# Configuration parameters: AllowForAlignment. +Style/SpaceAroundOperators: + Exclude: + - 'examples/language.rb' + - 'rosette_api.gemspec' + +# Offense count: 56 +# Cop supports --auto-correct. +# Configuration parameters: EnforcedStyle, EnforcedStyleForEmptyBraces, SupportedStyles. +# SupportedStyles: space, no_space, compact +Style/SpaceInsideHashLiteralBraces: + Exclude: + - 'examples/language.rb' + - 'tests/tests_spec.rb' + +# Offense count: 44 +# Cop supports --auto-correct. +# Configuration parameters: EnforcedStyle, SupportedStyles, ConsistentQuotesInMultiline. +# SupportedStyles: single_quotes, double_quotes +Style/StringLiterals: + Exclude: + - 'Gemfile' + - 'examples/categories.rb' + - 'examples/entities.rb' + - 'examples/language.rb' + - 'examples/morphology_complete.rb' + - 'examples/morphology_compound-components.rb' + - 'examples/morphology_han-readings.rb' + - 'examples/name_similarity.rb' + - 'examples/name_translation.rb' + - 'examples/sentiment.rb' + - 'examples/syntax_dependencies.rb' + - 'examples/tokens.rb' + - 'tests/tests_spec.rb' + +# Offense count: 14 +# Cop supports --auto-correct. +# Configuration parameters: EnforcedStyle, SupportedStyles. +# SupportedStyles: final_newline, final_blank_line +Style/TrailingBlankLines: + Exclude: + - 'examples/info.rb' + - 'examples/language.rb' + - 'examples/morphology_compound-components.rb' + - 'examples/morphology_han-readings.rb' + - 'examples/morphology_lemmas.rb' + - 'examples/morphology_parts-of-speech.rb' + - 'examples/name_similarity.rb' + - 'examples/name_translation.rb' + - 'examples/ping.rb' + - 'examples/sentences.rb' + - 'examples/sentiment.rb' + - 'examples/tokens.rb' + - 'lib/rosette_api.rb' + - 'lib/rosette_api_error.rb' + +# Offense count: 1 +# Cop supports --auto-correct. +Style/TrailingWhitespace: + Exclude: + - 'lib/request_builder.rb' + +# Offense count: 4 +# Cop supports --auto-correct. +Style/UnneededPercentQ: + Exclude: + - 'rosette_api.gemspec' diff --git a/examples/README.md b/examples/README.md index 0b8d603..571a7e4 100644 --- a/examples/README.md +++ b/examples/README.md @@ -22,7 +22,6 @@ Each example, when run, prints its output to the console. | ------------- |------------- | | categories.rb | Gets the category of a document at a URL | | entities.rb | Gets the entities from a piece of text | -| entities_linked.rb | Gets the linked (to Wikipedia) entities from a piece of text | | info.rb | Gets information about Rosette API | | language.rb | Gets the language of a piece of text | | name_similarity.rb | Gets the similarity score of two names | diff --git a/examples/categories.rb b/examples/categories.rb index 9991823..8ec4971 100644 --- a/examples/categories.rb +++ b/examples/categories.rb @@ -9,6 +9,10 @@ end categories_url_data = "http://www.onlocationvacations.com/2015/03/05/the-new-ghostbusters-movie-begins-filming-in-boston-in-june/" -params = DocumentParameters.new(content_uri: categories_url_data) -response = rosette_api.get_categories(params) -puts JSON.pretty_generate(response) +begin + params = DocumentParameters.new(content_uri: categories_url_data) + response = rosette_api.get_categories(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 diff --git a/examples/entities.rb b/examples/entities.rb index f4fb8d4..7af0f13 100644 --- a/examples/entities.rb +++ b/examples/entities.rb @@ -1,3 +1,4 @@ +# encoding: UTF-8 require 'rosette_api' api_key, url = ARGV @@ -9,6 +10,10 @@ end entities_text_data = "Bill Murray will appear in new Ghostbusters film: Dr. Peter Venkman was spotted filming a cameo in Boston this… http://dlvr.it/BnsFfS" -params = DocumentParameters.new(content: entities_text_data, genre: 'social-media') -response = rosette_api.get_entities(params) -puts JSON.pretty_generate(response) +begin + params = DocumentParameters.new(content: entities_text_data, genre: 'social-media') + response = rosette_api.get_entities(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 diff --git a/examples/entities_linked.rb b/examples/entities_linked.rb deleted file mode 100644 index c432498..0000000 --- a/examples/entities_linked.rb +++ /dev/null @@ -1,14 +0,0 @@ -require 'rosette_api' - -api_key, url = ARGV - -if !url - rosette_api = RosetteAPI.new(api_key) -else - rosette_api = RosetteAPI.new(api_key, url) -end - -entities_linked_text_data = "Last month director Paul Feig announced the movie will have an all-star female cast including Kristen Wiig, Melissa McCarthy, Leslie Jones and Kate McKinnon." -params = DocumentParameters.new(content: entities_linked_text_data, genre: 'social-media') -response = rosette_api.get_entities(params, true) -puts JSON.pretty_generate(response) diff --git a/examples/info.rb b/examples/info.rb index a82e022..308792a 100644 --- a/examples/info.rb +++ b/examples/info.rb @@ -8,4 +8,8 @@ rosette_api = RosetteAPI.new(api_key, url) end response = rosette_api.info -puts JSON.pretty_generate(response) \ No newline at end of file +begin + 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 diff --git a/examples/language.rb b/examples/language.rb index c26e07b..4611b0d 100644 --- a/examples/language.rb +++ b/examples/language.rb @@ -9,7 +9,11 @@ end language_data = "Por favor Señorita, says the man." -params = DocumentParameters.new(content: language_data) -params.custom_headers = { 'X-RosetteAPI-App'=> 'ruby-app'} -response = rosette_api.get_language(params) -puts JSON.pretty_generate(response) \ No newline at end of file +begin + params = DocumentParameters.new(content: language_data) + params.custom_headers = { 'X-RosetteAPI-App'=> 'ruby-app'} + response = rosette_api.get_language(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 diff --git a/examples/morphology_complete.rb b/examples/morphology_complete.rb index 3bdc348..0603749 100644 --- a/examples/morphology_complete.rb +++ b/examples/morphology_complete.rb @@ -9,6 +9,10 @@ end morphology_complete_data = "The quick brown fox jumped over the lazy dog. Yes he did." -params = DocumentParameters.new(content: morphology_complete_data) -response = rosette_api.get_morphology_complete(params) -puts JSON.pretty_generate(response) +begin + params = DocumentParameters.new(content: morphology_complete_data) + response = rosette_api.get_morphology_complete(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 diff --git a/examples/morphology_compound-components.rb b/examples/morphology_compound-components.rb index 686dd9e..8d64fef 100644 --- a/examples/morphology_compound-components.rb +++ b/examples/morphology_compound-components.rb @@ -9,6 +9,10 @@ end morphology_compound_components_data = "Rechtsschutzversicherungsgesellschaften" -params = DocumentParameters.new(content: morphology_compound_components_data) -response = rosette_api.get_compound_components(params) -puts JSON.pretty_generate(response) \ No newline at end of file +begin + params = DocumentParameters.new(content: morphology_compound_components_data) + response = rosette_api.get_compound_components(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 diff --git a/examples/morphology_han-readings.rb b/examples/morphology_han-readings.rb index 00b0dea..f5dd582 100644 --- a/examples/morphology_han-readings.rb +++ b/examples/morphology_han-readings.rb @@ -9,6 +9,10 @@ end morphology_han_readings_data = "北京大学生物系主任办公室内部会议" -params = DocumentParameters.new(content: morphology_han_readings_data) -response = rosette_api.get_han_readings(params) -puts JSON.pretty_generate(response) \ No newline at end of file +begin + params = DocumentParameters.new(content: morphology_han_readings_data) + response = rosette_api.get_han_readings(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 diff --git a/examples/morphology_lemmas.rb b/examples/morphology_lemmas.rb index ce72907..a8fff0d 100644 --- a/examples/morphology_lemmas.rb +++ b/examples/morphology_lemmas.rb @@ -9,6 +9,10 @@ end morphology_lemmas_data = "The fact is that the geese just went back to get a rest and I'm not banking on their return soon" -params = DocumentParameters.new(content: morphology_lemmas_data) -response = rosette_api.get_lemmas(params) -puts JSON.pretty_generate(response) \ No newline at end of file +begin + params = DocumentParameters.new(content: morphology_lemmas_data) + response = rosette_api.get_lemmas(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 diff --git a/examples/morphology_parts-of-speech.rb b/examples/morphology_parts-of-speech.rb index ea65436..8deea6f 100644 --- a/examples/morphology_parts-of-speech.rb +++ b/examples/morphology_parts-of-speech.rb @@ -9,6 +9,10 @@ end morphology_parts_of_speech_data = "The fact is that the geese just went back to get a rest and I'm not banking on their return soon" -params = DocumentParameters.new(content: morphology_parts_of_speech_data) -response = rosette_api.get_parts_of_speech(params) -puts JSON.pretty_generate(response) \ No newline at end of file +begin + params = DocumentParameters.new(content: morphology_parts_of_speech_data) + response = rosette_api.get_parts_of_speech(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 diff --git a/examples/name_similarity.rb b/examples/name_similarity.rb index de3b427..f776a49 100644 --- a/examples/name_similarity.rb +++ b/examples/name_similarity.rb @@ -10,7 +10,11 @@ matched_name_data1 = "Michael Jackson" matched_name_data2 = "迈克尔·杰克逊" -name1 = NameParameter.new(matched_name_data1, entity_type: 'PERSON', language:'eng') -params = NameSimilarityParameters.new(name1, matched_name_data2) -response = rosette_api.name_similarity(params) -puts JSON.pretty_generate(response) \ No newline at end of file +begin + name1 = NameParameter.new(matched_name_data1, entity_type: 'PERSON', language:'eng') + params = NameSimilarityParameters.new(name1, matched_name_data2) + response = rosette_api.name_similarity(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 diff --git a/examples/name_translation.rb b/examples/name_translation.rb index 3b6def4..b48ba1d 100644 --- a/examples/name_translation.rb +++ b/examples/name_translation.rb @@ -9,6 +9,10 @@ end translated_name_data = "معمر محمد أبو منيار القذاف" -params = NameTranslationParameters.new(translated_name_data, 'eng', target_script: 'Latn') -response = rosette_api.name_translation(params) -puts JSON.pretty_generate(response) \ No newline at end of file +begin + params = NameTranslationParameters.new(translated_name_data, 'eng', target_script: 'Latn') + response = rosette_api.name_translation(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 diff --git a/examples/ping.rb b/examples/ping.rb index fc43e18..b96bcdc 100644 --- a/examples/ping.rb +++ b/examples/ping.rb @@ -7,5 +7,9 @@ else rosette_api = RosetteAPI.new(api_key, url) end -response = rosette_api.ping -puts JSON.pretty_generate(response) \ No newline at end of file +begin + response = rosette_api.ping + 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 diff --git a/examples/relationships.rb b/examples/relationships.rb index 043bf7d..913a81d 100644 --- a/examples/relationships.rb +++ b/examples/relationships.rb @@ -9,7 +9,11 @@ end relationships_text_data = "Bill Gates, Microsoft's former CEO, is a philanthropist." -params = DocumentParameters.new(content: relationships_text_data) -params.rosette_options = { accuracyMode: 'PRECISION' } -response = rosette_api.get_relationships(params) -puts JSON.pretty_generate(response) +begin + params = DocumentParameters.new(content: relationships_text_data) + params.rosette_options = { accuracyMode: 'PRECISION' } + response = rosette_api.get_relationships(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 diff --git a/examples/sentences.rb b/examples/sentences.rb index 2751f27..86f3734 100644 --- a/examples/sentences.rb +++ b/examples/sentences.rb @@ -9,10 +9,12 @@ end sentences_data = "This land is your land. This land is my land\nFrom California to the New York island;\nFrom the red wood forest to the Gulf Stream waters\n\nThis land was made for you and Me.\n\nAs I was walking that ribbon of highway,\nI saw above me that endless skyway:\nI saw below me that golden valley:\nThis land was made for you and me." - ' wood forest to the Gulf Stream waters\n\nThis land was made for you and Me.\n\nAs I was walking' \ - ' that ribbon of highway,\nI saw above me that endless skyway:\nI saw below me that' \ - ' golden valley:\nThis land was made for you and me.' -params = DocumentParameters.new -params.content = sentences_data -response = rosette_api.get_sentences(params) -puts JSON.pretty_generate(response) \ No newline at end of file + +begin + params = DocumentParameters.new + params.content = sentences_data + response = rosette_api.get_sentences(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 diff --git a/examples/sentiment.rb b/examples/sentiment.rb index bc4a31f..b0c6fba 100644 --- a/examples/sentiment.rb +++ b/examples/sentiment.rb @@ -9,15 +9,14 @@ rosette_api = RosetteAPI.new(api_key, url) end - file = Tempfile.new(%w(foo .html)) -sentiment_file_data = "
Original Ghostbuster Dan Aykroyd, who also co-wrote the 1984 Ghostbusters film, couldn’t be more pleased with the new all-female Ghostbusters cast, telling The Hollywood Reporter, “The Aykroyd family is delighted by this inheritance of the Ghostbusters torch by these most magnificent women in comedy.”
" - 'Aykroyd, who also co-wrote the 1984 Ghostbusters film, couldn’t be more pleased with the new ' \ - 'all-female Ghostbusters cast, telling The Hollywood Reporter, The Aykroyd family is delighted ' \ - 'by this inheritance of the Ghostbusters torch by these most magnificent women in comedy ' \ - '.