Class: Opener::OpinionDetectors::ConfigurationCreator

Inherits:
Object
  • Object
show all
Includes:
ERB::Util
Defined in:
lib/opener/opinion_detectors/configuration_creator.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(language, domain, models_path) ⇒ ConfigurationCreator

Returns a new instance of ConfigurationCreator.



12
13
14
15
16
17
# File 'lib/opener/opinion_detectors/configuration_creator.rb', line 12

def initialize(language, domain, models_path)
  @language = language
  @domain = domain
  @models_path = models_path ||= ENV["OPINION_DETECTOR_MODELS_PATH"]
  @config_file = Tempfile.new('opinion-detector-config')
end

Instance Attribute Details

#config_fileObject

Returns the value of attribute config_file.



8
9
10
# File 'lib/opener/opinion_detectors/configuration_creator.rb', line 8

def config_file
  @config_file
end

#domainObject (readonly)

Returns the value of attribute domain.



7
8
9
# File 'lib/opener/opinion_detectors/configuration_creator.rb', line 7

def domain
  @domain
end

#languageObject (readonly)

Returns the value of attribute language.



7
8
9
# File 'lib/opener/opinion_detectors/configuration_creator.rb', line 7

def language
  @language
end

Instance Method Details

#close_configObject



26
27
28
# File 'lib/opener/opinion_detectors/configuration_creator.rb', line 26

def close_config
  config_file.close
end

#config_file_pathObject



19
20
21
22
23
24
# File 'lib/opener/opinion_detectors/configuration_creator.rb', line 19

def config_file_path
  config_file.write(render)
  config_file.rewind
  
  return config_file.path
end

#crfsuite_pathObject



42
43
44
# File 'lib/opener/opinion_detectors/configuration_creator.rb', line 42

def crfsuite_path
  File.expand_path("../../../../core/vendor/build/bin/crfsuite",__FILE__)
end

#models_pathObject



34
35
36
37
38
39
40
# File 'lib/opener/opinion_detectors/configuration_creator.rb', line 34

def models_path
  if @models_path.nil?
    raise ArgumentError, "Can't find a models path, please set the OPINION_DETECTOR_MODELS_PATH env variable"
  end
  path = File.expand_path(language, @models_path)
  return path
end

#renderObject



30
31
32
# File 'lib/opener/opinion_detectors/configuration_creator.rb', line 30

def render
  ERB.new(template).result(binding)
end

#svm_classify_pathObject



50
51
52
# File 'lib/opener/opinion_detectors/configuration_creator.rb', line 50

def svm_classify_path
  File.expand_path("../../../../core/vendor/build/bin/svm_classify", __FILE__)
end

#svm_learn_pathObject



46
47
48
# File 'lib/opener/opinion_detectors/configuration_creator.rb', line 46

def svm_learn_path
  File.expand_path("../../../../core/vendor/build/bin/svm_learn", __FILE__)
end

#templateObject



54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
# File 'lib/opener/opinion_detectors/configuration_creator.rb', line 54

def template
  %{
[general]
output_folder = <%=models_path%>/<%=domain%>_cfg1

[feature_templates]
expression = <%=models_path%>/<%=domain%>_cfg1/feature_templates/feat_template_expr.txt
holder = <%=models_path%>/<%=domain%>_cfg1/feature_templates/feat_template_holder.txt
target = <%=models_path%>/<%=domain%>_cfg1/feature_templates/feat_template_target.txt

[valid_opinions]
negative = Negative;StrongNegative
positive = Positive;StrongPositive

[relation_features]
use_dependencies = True
use_training_lexicons = True
use_this_expression_lexicon = <%=models_path%>/<%=domain%>_cfg1/lexicons/polarity_lexicon.txt
use_this_target_lexicon = <%=models_path%>/<%=domain%>_cfg1/lexicons/target_lexicon.txt
use_tokens_lemmas = True
exp_tar_threshold = -0.75
exp_hol_threshold = -0.5

[crfsuite]
path_to_binary = <%= crfsuite_path %>
parameters = -a lbfgs

[svmlight]
path_to_binary_learn = <%= svm_learn_path %>
path_to_binary_classify = <%= svm_classify_path %>
parameters = -c 0.1
  }
end