# This class contains all settings relevant to a CQP query and is
# necessary when constructing a SimpleCQP instance.

class CQPQueryContext
  attr_accessor :corpus, :context, :context_type, :alignment, :cutoff,
    :attributes, :structures, :registry, :id, :query_string, :case_insensitive

  def initialize(opts={})
    # id indentifying query dumps, should only be populated with id's
    # generated by SimpleCQP (see SimpleCQP initializer).
    @id = opts[:id] || nil
    # Currently supports a single query terms as a string
    @query_string = opts[:query_string] || nil
    # corpus identifier as a string as used by CQP
    @corpus = opts[:corpus] || nil
    
    @context = opts[:context] || [7, 7]
    @context_type = opts[:context_type] || :words

    # an array of corpus identifiers
    @alignment = opts[:alignment] || []

    @attributes = opts[:attributes] || :word
    @structures = opts[:structures] || nil

    # registry path as a string
    # must be set for all CQP operations
    @registry = opts[:registry] || nil
    
    @case_insensitive = opts[:case_insensitive] || nil
  end

  def left_context
    return @context[0]
  end

  def right_context
    return @context[1]
  end

  def context_type
    return @context_type.to_s
  end
end

# This class contains all settings relevant to a CQP query and is
# necessary when constructing a SimpleCQP instance.

class CQPQueryContext
  attr_accessor :corpus, :context, :context_type, :alignment, :cutoff,
    :attributes, :structures, :registry, :id, :query_string, :case_insensitive

  def initialize(opts={})
    # id indentifying query dumps, should only be populated with id's
    # generated by SimpleCQP (see SimpleCQP initializer).
    @id = opts[:id] || nil
    # Currently supports a single query terms as a string
    @query_string = opts[:query_string] || nil
    # corpus identifier as a string as used by CQP
    @corpus = opts[:corpus] || nil
    
    @context = opts[:context] || [7, 7]
    @context_type = opts[:context_type] || :words

    # an array of corpus identifiers
    @alignment = opts[:alignment] || []

    @attributes = opts[:attributes] || :word
    @structures = opts[:structures] || nil

    # registry path as a string
    # must be set for all CQP operations
    @registry = opts[:registry] ||
      (CQPQueryContext.const_defined?('DEFAULT_REGISTRY') && DEFAULT_REGISTRY)
    Rails.logger.warn('WARNING: No registry specified!') unless @registry
    
    @case_insensitive = opts[:case_insensitive] || nil
  end

  def left_context
    return @context[0]
  end

  def right_context
    return @context[1]
  end

  def context_type
    return @context_type.to_s
  end
end

Use CQPQueryContext::DEFAULT_REGISTRY if no registry specified in request
Use CQPQueryContext::DEFAULT_REGISTRY if no registry specified in request
