Class: Opener::OpinionDetectors::ConfigurationCreator
- Inherits:
-
Object
- Object
- Opener::OpinionDetectors::ConfigurationCreator
- Includes:
- ERB::Util
- Defined in:
- lib/opener/opinion_detectors/configuration_creator.rb
Instance Attribute Summary collapse
-
#config_file ⇒ Object
Returns the value of attribute config_file.
-
#domain ⇒ Object
readonly
Returns the value of attribute domain.
-
#language ⇒ Object
readonly
Returns the value of attribute language.
Instance Method Summary collapse
- #close_config ⇒ Object
- #config_file_path ⇒ Object
- #crfsuite_path ⇒ Object
-
#initialize(language, domain, models_path) ⇒ ConfigurationCreator
constructor
A new instance of ConfigurationCreator.
- #models_path ⇒ Object
- #render ⇒ Object
- #svm_classify_path ⇒ Object
- #svm_learn_path ⇒ Object
- #template ⇒ Object
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_file ⇒ Object
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 |
#domain ⇒ Object (readonly)
Returns the value of attribute domain.
7 8 9 |
# File 'lib/opener/opinion_detectors/configuration_creator.rb', line 7 def domain @domain end |
#language ⇒ Object (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_config ⇒ Object
26 27 28 |
# File 'lib/opener/opinion_detectors/configuration_creator.rb', line 26 def close_config config_file.close end |
#config_file_path ⇒ Object
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_path ⇒ Object
42 43 44 |
# File 'lib/opener/opinion_detectors/configuration_creator.rb', line 42 def crfsuite_path File.("../../../../core/vendor/build/bin/crfsuite",__FILE__) end |
#models_path ⇒ Object
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.(language, @models_path) return path end |
#render ⇒ Object
30 31 32 |
# File 'lib/opener/opinion_detectors/configuration_creator.rb', line 30 def render ERB.new(template).result(binding) end |
#svm_classify_path ⇒ Object
50 51 52 |
# File 'lib/opener/opinion_detectors/configuration_creator.rb', line 50 def svm_classify_path File.("../../../../core/vendor/build/bin/svm_classify", __FILE__) end |
#svm_learn_path ⇒ Object
46 47 48 |
# File 'lib/opener/opinion_detectors/configuration_creator.rb', line 46 def svm_learn_path File.("../../../../core/vendor/build/bin/svm_learn", __FILE__) end |
#template ⇒ Object
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 |