Module: CSDL

Defined in:
lib/csdl.rb,
lib/csdl/error.rb,
lib/csdl/builder.rb,
lib/csdl/targets.rb,
lib/csdl/version.rb,
lib/csdl/operators.rb,
lib/csdl/processor.rb,
lib/csdl/target_values.rb,
lib/csdl/target_values/topics.rb,
lib/csdl/target_values/regions.rb,
lib/csdl/query_filter_processor.rb,
lib/csdl/target_values/countries.rb,
lib/csdl/target_values/languages.rb,
lib/csdl/interaction_filter_processor.rb

Overview

CSDL is a library for manipulating Abstract Syntax Trees that represent raw CSDL defintions. Using an AST makes it much simpler to manipulate, traverse, validate, and test complex CSDL queries.

Use the DSL Builder class to produce a tree of nodes, then process those nodes with Processor, InteractionFilterProcessor, or QueryFilterProcessor. See those individuals classes for usage documentation.

Defined Under Namespace

Modules: TargetValues Classes: Builder, Error, InteractionFilterProcessor, InvalidInteractionTargetError, InvalidQueryTargetError, MissingChildNodesError, MissingReturnStatementScopeError, MissingTagClassError, MissingTagNodesError, MissingTagStatementScopeError, Operator, Processor, QueryFilterProcessor, Target, UnknownOperatorError, UnknownTargetError

Constant Summary collapse

RAW_TARGETS =

A raw array of targets with their usage flags.

Returns:

  • (Array<String, Boolean, Boolean, Boolean>)

    Array of targets used to produce TARGETS hash.

[

  [ "fb.author.age"                     , true  , true  , true  , :AGES ] ,
  [ "fb.author.country"                 , true  , true  , true  , :COUNTRIES ] ,
  [ "fb.author.country_code"            , true  , true  , true  , :COUNTRY_CODES ] ,
  [ "fb.author.gender"                  , true  , true  , true  , :GENDERS ] ,
  [ "fb.author.region"                  , true  , true  , true  , :REGIONS ] ,
  [ "fb.author.type"                    , true  , true  , true  , :AUTHOR_TYPES ] ,
  [ "fb.content"                        , true  , false , true  , :UNBOUNDED ] ,
  [ "fb.hashtags"                       , true  , true  , true  , :UNBOUNDED ] ,
  [ "fb.language"                       , true  , true  , true  , :LANGUAGE_CODES ] ,
  [ "fb.link"                           , true  , true  , true  , :UNBOUNDED ] ,
  [ "fb.media_type"                     , true  , true  , true  , :MEDIA_TYPES ] ,
  [ "fb.parent.author.age"              , true  , true  , true  , :AGES ] ,
  [ "fb.parent.author.country"          , true  , true  , true  , :COUNTRIES ] ,
  [ "fb.parent.author.country_code"     , true  , true  , true  , :COUNTRY_CODES ] ,
  [ "fb.parent.author.gender"           , true  , true  , true  , :GENDERS ] ,
  [ "fb.parent.author.type"             , true  , true  , true  , :AUTHOR_TYPES ] ,
  [ "fb.parent.content"                 , true  , false , true  , :UNBOUNDED ] ,
  [ "fb.parent.hashtags"                , true  , true  , true  , :UNBOUNDED ] ,
  [ "fb.parent.interface"               , true  , true  , true  , :INTERFACES ] ,
  [ "fb.parent.language"                , true  , true  , true  , :LANGUAGE_CODES ] ,
  [ "fb.parent.link"                    , true  , true  , true  , :UNBOUNDED ] ,
  [ "fb.parent.media_type"              , true  , true  , true  , :MEDIA_TYPES ] ,
  [ "fb.parent.sentiment"               , true  , true  , true  , :SENTIMENT ] ,
  [ "fb.parent.topics.about"            , true  , false , false , :UNBOUNDED ] ,
  [ "fb.parent.topics.category"         , true  , true  , true  , :TOPIC_CATEGORIES ] ,
  [ "fb.parent.topics.company_overview" , true  , false , false , :UNBOUNDED ] ,
  [ "fb.parent.topics.location_city"    , true  , false , false , :UNBOUNDED ] ,
  [ "fb.parent.topics.location_street"  , true  , false , false , :UNBOUNDED ] ,
  [ "fb.parent.topics.mission"          , true  , false , false , :UNBOUNDED ] ,
  [ "fb.parent.topics.name"             , true  , true  , true  , :UNBOUNDED ] ,
  [ "fb.parent.topics.products"         , true  , false , false , :UNBOUNDED ] ,
  [ "fb.parent.topics.release_date"     , true  , false , false , :UNBOUNDED ] ,
  [ "fb.parent.topics.username"         , true  , false , false , :UNBOUNDED ] ,
  [ "fb.parent.topics.website"          , true  , false , false , :UNBOUNDED ] ,
  [ "fb.parent.topic_ids"               , true  , true  , true  , :UNBOUNDED ] ,
  [ "fb.sentiment"                      , true  , true  , true  , :SENTIMENT ] ,
  [ "fb.topics.about"                   , true  , false , false , :UNBOUNDED ] ,
  [ "fb.topics.category"                , true  , true  , true  , :TOPIC_CATEGORIES ] ,
  [ "fb.topics.company_overview"        , true  , false , false , :UNBOUNDED ] ,
  [ "fb.topics.location_city"           , true  , false , false , :UNBOUNDED ] ,
  [ "fb.topics.location_street"         , true  , false , false , :UNBOUNDED ] ,
  [ "fb.topics.mission"                 , true  , false , false , :UNBOUNDED ] ,
  [ "fb.topics.name"                    , true  , true  , true  , :UNBOUNDED ] ,
  [ "fb.topics.products"                , true  , false , false , :UNBOUNDED ] ,
  [ "fb.topics.release_date"            , true  , false , false , :UNBOUNDED ] ,
  [ "fb.topics.username"                , true  , false , false , :UNBOUNDED ] ,
  [ "fb.topics.website"                 , true  , false , false , :UNBOUNDED ] ,
  [ "fb.topic_ids"                      , true  , true  , true  , :UNBOUNDED ] ,
  [ "fb.type"                           , true  , true  , true  , :INTERACTION_TYPES ] ,
  [ "interaction.content"               , true  , false , true  , :UNBOUNDED ] ,
  [ "interaction.hashtags"              , true  , true  , true  , :UNBOUNDED ] ,
  [ "interaction.media_type"            , true  , true  , true  , :MEDIA_TYPES ] ,
  [ "interaction.ml.categories"         , false , true  , true  , :UNBOUNDED ] ,
  [ "interaction.raw_content"           , true  , false , true  , :UNBOUNDED ] ,
  [ "interaction.subtype"               , true  , true  , true  , :INTERACTION_TYPES ] ,
  [ "interaction.tags"                  , false , true  , false , :UNBOUNDED ] ,
  [ "interaction.tag_tree"              , false , true  , true  , :UNBOUNDED ] ,
  [ "links.code"                        , true  , true  , true  , :UNBOUNDED ] ,
  [ "links.domain"                      , true  , true  , true  , :UNBOUNDED ] ,
  [ "links.normalized_url"              , true  , true  , true  , :UNBOUNDED ] ,
  [ "links.url"                         , true  , true  , true  , :UNBOUNDED ]

]
TARGETS =

All possible targets.

Returns:

  • (Hash<String, Target>)

    Hash of Target structs, keyed by the string name of the target.

RAW_TARGETS.reduce({}) do |accumulator, (target_name, interaction, analysis, query, values_constant)|
  accumulator[target_name] = Target.new(target_name, interaction, analysis, query, TargetValues.const_get(values_constant))
  accumulator
end.freeze
INTERACTION_TARGETS =
TARGETS.select { |_, target| target.interaction? }
ANALYSIS_TARGETS =
TARGETS.select { |_, target| target.analysis? }
QUERY_TARGETS =
TARGETS.select { |_, target| target.query? }
VERSION =
"0.3.5"
RAW_OPERATORS =

A raw array of operators with their valid argument types.

Returns:

  • (Array<String, Array<Symbol>>)

    Array of operators used to produce OPERATORS hash.

[
  [ "contains"         , [ :string ] ],
  [ "cs contains"      , [ :string ] ],
  [ "substr"           , [ :string ] ],
  [ "cs substr"        , [ :string ] ],
  [ "contains_any"     , [ :string ] ],
  [ "cs contains_any"  , [ :string ] ],
  [ "any"              , [ :string ] ],
  [ "cs any"           , [ :string ] ],
  [ "wildcard"         , [ :string ] ],
  [ "cs wildcard"      , [ :string ] ],
  [ "wild"             , [ :string ] ],
  [ "cs wild"          , [ :string ] ],
  [ "contains_all"     , [ :string ] ],
  [ "cs contains_all"  , [ :string ] ],
  [ "all"              , [ :string ] ],
  [ "cs all"           , [ :string ] ],
  [ "contains_near"    , [ :string ] ],
  [ "cs contains_near" , [ :string ] ],
  [ "exists"           , [ :string ] ],
  [ "in"               , [ :string ] ],
  [ "url_in"           , [ :string ] ],
  [ "=="               , [ :string ] ],
  [ "!="               , [ :string ] ],
  [ "cs =="            , [ :string ] ],
  [ "cs !="            , [ :string ] ],
  [ ">"                , [ :string ] ],
  [ ">="               , [ :string ] ],
  [ "<"                , [ :string ] ],
  [ "<="               , [ :string ] ],
  [ "regex_partial"    , [ :string ] ],
  [ "regex_exact"      , [ :string ] ],
  [ "geo_box"          , [ :string ] ],
  [ "geo_radius"       , [ :string ] ],
  [ "geo_polygon"      , [ :string ] ]
]
OPERATORS =

All possible operators.

Returns:

  • (Hash<String, Operator>)

    Hash of Operator structs, keyed by the string name of the operator.

RAW_OPERATORS.reduce({}) do |accumulator, (operator_name, argument_types)|
  accumulator[operator_name] = Operator.new(operator_name, argument_types)
  accumulator
end.freeze

Class Method Summary collapse

Class Method Details

.analysis_target?(target_name) ⇒ Boolean

Check if the given target is a valid analysis target.

Examples:

CSDL.analysis_target?("interaction.content") # => false
CSDL.analysis_target?("interaction.tags") # => true

Parameters:

  • target_name (String)

    The name of the target.

Returns:

  • (Boolean)

    Whether or not the value is a valid CSDL Analysis Target.


137
138
139
# File 'lib/csdl/targets.rb', line 137

def self.analysis_target?(target_name)
  ANALYSIS_TARGETS.key?(target_name)
end

.interaction_target?(target_name) ⇒ Boolean

Check if the given target is a valid interaction target.

Examples:

CSDL.interaction_target?("interaction.tags") # => false
CSDL.interaction_target?("interaction.content") # => true

Parameters:

  • target_name (String)

    The name of the target.

Returns:

  • (Boolean)

    Whether or not the value is a valid CSDL Interaction Filter Target.


123
124
125
# File 'lib/csdl/targets.rb', line 123

def self.interaction_target?(target_name)
  INTERACTION_TARGETS.key?(target_name)
end

.operator?(operator) ⇒ Boolean

Check if the given target is a valid operator.

Examples:

CSDL.operator?("fake") # => false
CSDL.operator?("contains") # => true
CSDL.operator?(">=") # => true

Parameters:

  • operator (String)

    The name of the target.

Returns:

  • (Boolean)

    Whether or not the value is a valid CSDL Operator.


73
74
75
# File 'lib/csdl/operators.rb', line 73

def self.operator?(operator)
  OPERATORS.key?(operator)
end

.query_target?(target_name) ⇒ Boolean

Check if the given target is a valid query target.

Examples:

CSDL.query_target?("fb.topics.website") # => false
CSDL.query_target?("fb.topic_ids") # => true

Verifying an interaction.tag_tree target

CSDL.query_target?("interaction.tag_tree.foo") # => true

Parameters:

  • target_name (String)

    The name of the target.

Returns:

  • (Boolean)

    Whether or not the value is a valid CSDL Query Filter Target.


154
155
156
# File 'lib/csdl/targets.rb', line 154

def self.query_target?(target_name)
  QUERY_TARGETS.key?(target_name) || target_name =~ /^interaction\.tag_tree\..+$/
end

.target?(target_name) ⇒ Boolean

Check if the given target is a valid target.

Examples:

CSDL.target?("fake") # => false
CSDL.target?("fb.content") # => true

Parameters:

  • target_name (String)

    The name of the target.

Returns:

  • (Boolean)

    Whether or not the value is a valid CSDL Target.


109
110
111
# File 'lib/csdl/targets.rb', line 109

def self.target?(target_name)
  TARGETS.key?(target_name)
end