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 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.List;

/**
 * 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) {
        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(), getKey());
    }

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

@@ -840,16 +840,58 @@
 n.Gson;%0A
+import com.google.gson.reflect.TypeToken;%0A
 import u
@@ -987,16 +987,16 @@
 pwords;%0A
-
 import u
@@ -1197,20 +1197,68 @@
 va.util.
-List
+HashMap;%0Aimport java.util.List;%0Aimport java.util.Map
 ;%0A%0A/**%0A 
@@ -1762,24 +1762,726 @@
 n%3E other) %7B%0A
+%0A        Map%3CString, String%3E mine = new HashMap%3C%3E();%0A        Map%3CString, String%3E options = new Gson().fromJson(jsonOptionValue, new TypeToken%3CMap%3CString, String%3E%3E()%7B%7D.getType());%0A        mine.putAll(options);%0A%0A        String type = ConfigHandler.getAndRemove(%22lang%22, mine, %22en%22);%0A        boolean use = ConfigHandler.getAndRemove(%22use%22, mine, false);%0A%0A        if(use)%7B%0A            switch (type) %7B%0A                case %22en%22:%0A                    pipeline.add(new TokenFilterRelevanceStopwords(%22en%22), getKey());%0A                    break;%0A                case %22zh%22:%0A                    pipeline.add(new TokenFilterRelevanceStopwords(%22zh%22), getKey());%0A                    break;%0A%0A            %7D%0A        %7D%0A%0A//
         if(n
@@ -2613,16 +2613,18 @@
  appear%0A
+//
         
@@ -2674,16 +2674,20 @@
 opwords(
+%22en%22
 ), getKe

update to remove_stopwords to allow lang arg