Module: NexosisApi::Client::Vocabulary

Included in:
NexosisApi::Client
Defined in:
lib/nexosis_api/client/vocabulary.rb

Overview

Vocabluary-based API operations

See Also:

Since:

  • 2.2.0

Instance Method Summary collapse

Instance Method Details

#get_vocabulary(vocabulary_id, type = 'word', page = 0, page_size = 50) ⇒ NexosisApi::PagedArray of NexosisApi::VocabularyWord

Note:

words will be sorted in rank order

Gets a list of Vocabulary Words from a vocabulary

Parameters:

  • vocabulary_id (String)

    required unique identifier for vocabulary to get

  • type (String) (defaults to: 'word')

    whether to return ‘word’ types (default), ‘stopWord’ for only stop words, or nil for both.

  • page (Integer) (defaults to: 0)

    the page number for paged results. Defaults to 0.

  • page_size (Integer) (defaults to: 50)

    the size of each page of paged results. Defaults to 50.

Returns:

Raises:

Since:

  • 2.2.0



42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/nexosis_api/client/vocabulary.rb', line 42

def get_vocabulary(vocabulary_id, type = 'word', page = 0, page_size = 50)
  raise ArgumentError, 'vocabulary_id was not provided and is not optional' if vocabulary_id.nil?
  vocab_url = "/vocabulary/#{vocabulary_id}"
  query = {
    page: page,
    pageSize: page_size
  }
  query.store('type', type) unless type.nil?
  response = self.class.get(vocab_url, headers: @headers, query: query)
  raise HttpException.new("There was a problem getting a vocabulary: #{response.code}.",
                          "getting vocabulary #{vocabulary_id}",
                          response) unless response.success?
  NexosisApi::PagedArray.new(response.parsed_response,
                             response.parsed_response['items']
                             .map { |item| NexosisApi::VocabularyWord.new(item) })
end

#list_vocabularies(datasource_name = nil, created_from_session = nil, page = 0, page_size = 50) ⇒ NexosisApi::PagedArray of NexosisApi::VocabularySummary

Gets summary information about the Vocabulary built from the Text columns in a session vocabularies created for this data source name. vocabularies created for the given session.

Parameters:

  • datasource_name (String) (defaults to: nil)

    optionally limit to those

  • created_from_session (String) (defaults to: nil)

    optionally limit to those

  • page (Integer) (defaults to: 0)

    the page number for paged results. Defaults to 0.

  • page_size (Integer) (defaults to: 50)

    the size of each page of paged results. Defaults to 50.

Returns:

Raises:

Since:

  • 2.2.0



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/nexosis_api/client/vocabulary.rb', line 17

def list_vocabularies(datasource_name = nil, created_from_session=nil, page = 0, page_size = 50)
  vocab_url = '/vocabulary'
  query = {
    page: page,
    pageSize: page_size
  }
  query.store('created_from_session', datasource_name) unless created_from_session.nil?
  query.store('dataSourceName', datasource_name) unless datasource_name.nil?
  response = self.class.get(vocab_url, headers: @headers, query: query)
  raise HttpException.new("There was a problem listing vocabularies: #{response.code}.",
                          "listing vocabularies with data source name #{datasource_name}",
                          response) unless response.success?
  NexosisApi::PagedArray.new(response.parsed_response,
                             response.parsed_response['items']
                             .map { |item| NexosisApi::VocabularySummary.new(item) })
end