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/query_filter_processor.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

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  ] ,
  [ "fb.author.country"                 , true  , true  , true  ] ,
  [ "fb.author.country_code"            , true  , true  , true  ] ,
  [ "fb.author.gender"                  , true  , true  , true  ] ,
  [ "fb.author.region"                  , true  , true  , true  ] ,
  [ "fb.author.type"                    , true  , true  , true  ] ,
  [ "fb.content"                        , true  , false , true  ] ,
  [ "fb.hashtags"                       , true  , true  , true  ] ,
  [ "fb.language"                       , true  , true  , true  ] ,
  [ "fb.link"                           , true  , true  , true  ] ,
  [ "fb.media_type"                     , true  , true  , true  ] ,
  [ "fb.parent.author.age"              , true  , true  , true  ] ,
  [ "fb.parent.author.country"          , true  , true  , true  ] ,
  [ "fb.parent.author.country_code"     , true  , true  , true  ] ,
  [ "fb.parent.author.gender"           , true  , true  , true  ] ,
  [ "fb.parent.author.type"             , true  , true  , true  ] ,
  [ "fb.parent.content"                 , true  , false , true  ] ,
  [ "fb.parent.hashtags"                , true  , true  , true  ] ,
  [ "fb.parent.interface"               , true  , true  , true  ] ,
  [ "fb.parent.language"                , true  , true  , true  ] ,
  [ "fb.parent.link"                    , true  , true  , true  ] ,
  [ "fb.parent.media_type"              , true  , true  , true  ] ,
  [ "fb.parent.sentiment"               , true  , true  , true  ] ,
  [ "fb.parent.topics.about"            , true  , false , false ] ,
  [ "fb.parent.topics.category"         , true  , true  , true  ] ,
  [ "fb.parent.topics.company_overview" , true  , false , false ] ,
  [ "fb.parent.topics.location_city"    , true  , false , false ] ,
  [ "fb.parent.topics.location_street"  , true  , false , false ] ,
  [ "fb.parent.topics.mission"          , true  , false , false ] ,
  [ "fb.parent.topics.name"             , true  , true  , true  ] ,
  [ "fb.parent.topics.products"         , true  , false , false ] ,
  [ "fb.parent.topics.release_date"     , true  , false , false ] ,
  [ "fb.parent.topics.username"         , true  , false , false ] ,
  [ "fb.parent.topics.website"          , true  , false , false ] ,
  [ "fb.parent.topic_ids"               , true  , true  , true  ] ,
  [ "fb.sentiment"                      , true  , true  , true  ] ,
  [ "fb.topics.about"                   , true  , false , false ] ,
  [ "fb.topics.category"                , true  , true  , true  ] ,
  [ "fb.topics.company_overview"        , true  , false , false ] ,
  [ "fb.topics.location_city"           , true  , false , false ] ,
  [ "fb.topics.location_street"         , true  , false , false ] ,
  [ "fb.topics.mission"                 , true  , false , false ] ,
  [ "fb.topics.name"                    , true  , true  , true  ] ,
  [ "fb.topics.products"                , true  , false , false ] ,
  [ "fb.topics.release_date"            , true  , false , false ] ,
  [ "fb.topics.username"                , true  , false , false ] ,
  [ "fb.topics.website"                 , true  , false , false ] ,
  [ "fb.topic_ids"                      , true  , true  , true  ] ,
  [ "fb.type"                           , true  , true  , true  ] ,
  [ "interaction.content"               , true  , false , true  ] ,
  [ "interaction.hashtags"              , true  , true  , true  ] ,
  [ "interaction.media_type"            , true  , true  , true  ] ,
  [ "interaction.ml.categories"         , false , true  , true  ] ,
  [ "interaction.raw_content"           , true  , false , true  ] ,
  [ "interaction.subtype"               , true  , true  , true  ] ,
  [ "interaction.tag_tree"              , false , true  , false ] ,
  [ "interaction.tags"                  , false , true  , true  ] ,
  [ "links.code"                        , true  , true  , true  ] ,
  [ "links.domain"                      , true  , true  , true  ] ,
  [ "links.normalized_url"              , true  , true  , true  ] ,
  [ "links.url"                         , true  , true  , true  ]
]
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)|
  accumulator[target_name] = Target.new(target_name, interaction, analysis, query)
  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.2.1"
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.



134
135
136
# File 'lib/csdl/targets.rb', line 134

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.



120
121
122
# File 'lib/csdl/targets.rb', line 120

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

Parameters:

  • target_name (String)

    The name of the target.

Returns:

  • (Boolean)

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



148
149
150
# File 'lib/csdl/targets.rb', line 148

def self.query_target?(target_name)
  QUERY_TARGETS.key?(target_name)
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.



106
107
108
# File 'lib/csdl/targets.rb', line 106

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