package uk.ac.susx.tag.classificationframework.featureextraction.pipelines.confighandlers;

/*
 * #%L
 * ConfigHandlerRemoveStopwords.java - classificationframework - CASM Consulting - 2,013
 * %%
 * Copyright (C) 2013 - 2014 CASM Consulting
 * %%
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 *      http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * #L%
 */

import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import uk.ac.susx.tag.classificationframework.featureextraction.filtering.TokenFilterRelevanceStopwords;
import uk.ac.susx.tag.classificationframework.featureextraction.pipelines.FeatureExtractionPipeline;
import uk.ac.susx.tag.classificationframework.featureextraction.pipelines.PipelineBuilder;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * If optionValue is true, then remove stopwords (that are particularly suited
 * to the relevance classification problem).
 *
 * Option value type expected: boolean (will tolerate String "true" and "false" in any capitalisation pattern)
 *
 * User: Andrew D. Robertson
 * Date: 17/02/2014
 * Time: 18:22
 */
public class ConfigHandlerRemoveStopwords extends ConfigHandler {
    @Override
    public void handle(FeatureExtractionPipeline pipeline, String jsonOptionValue, List<PipelineBuilder.Option> other) {

        Map<String, String> mine = new HashMap<>();
        Map<String, String> options = new Gson().fromJson(jsonOptionValue, new TypeToken<Map<String, String>>(){}.getType());
        mine.putAll(options);

        String type = ConfigHandler.getAndRemove("lang", mine, "en");
        boolean use = ConfigHandler.getAndRemove("use", mine, false);

        if(use){
            switch (type) {
                case "en":
                    pipeline.add(new TokenFilterRelevanceStopwords("en"), getKey());
                    break;
                case "zh":
                    pipeline.add(new TokenFilterRelevanceStopwords("zh"), getKey());
                    break;

            }
        }

//        if(new Gson().fromJson(jsonOptionValue, Boolean.class))  // This is pretty tolerant of all the possible ways true and false could appear
//            pipeline.add(new TokenFilterRelevanceStopwords("en"), getKey());
    }

    @Override
    public String getKey() {
        return "remove_stopwords";  //To change body of implemented methods use File | Settings | File Templates.
    }
}

@@ -1767,16 +1767,101 @@
 her) %7B%0A%0A
+        if(jsonOptionValue.contains(%22use%22) && jsonOptionValue.contains(%22lang%22))%7B%0A    
         
@@ -1904,16 +1904,20 @@
 ap%3C%3E();%0A
+    
         
@@ -2042,16 +2042,20 @@
         
+ 
+   
 mine.put
@@ -2077,16 +2077,20 @@
         
+   
+ 
 String t
@@ -2143,16 +2143,20 @@
  %22en%22);%0A
+    
         
@@ -2226,16 +2226,20 @@
         
+ 
+   
 if(use)%7B
@@ -2239,16 +2239,20 @@
 f(use)%7B%0A
+    
         
@@ -2283,24 +2283,28 @@
             
+    
 case %22en%22:%0A 
@@ -2314,32 +2314,36 @@
                 
+  
+  
 pipeline.add(new
@@ -2411,23 +2411,31 @@
         
+    
 break;%0A
+    
         
@@ -2465,32 +2465,36 @@
                 
+   
+ 
 pipeline.add(new
@@ -2566,29 +2566,306 @@
     
+    
 break;%0A
-%0A            %7D
+                %7D%0A            %7D%0A        %7D%0A        else %7B%0A            if(new Gson().fromJson(jsonOptionValue, Boolean.class))  // This is pretty tolerant of all the possible ways true and false could appear%0A                pipeline.add(new TokenFilterRelevanceStopwords(%22en%22), getKey());%0A
 %0A   

update to allow flexible input.