<commit_before>/*
 * Copyright 2014 McGill University
 *
 * 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.
 */
package ca.mcgill.cs.creco.logic;

import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Set;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import ca.mcgill.cs.creco.data.Attribute;
import ca.mcgill.cs.creco.data.Category;
import ca.mcgill.cs.creco.data.IDataStore;
import ca.mcgill.cs.creco.data.Product;

 /**
 * This class handles the extraction of most relevant attribute from a category.
 * This class is a Bean (singleton) and it is created at startup. You should access this class
 * to get information on attributes within a category such as attribute entropy
 * and correlation with overall score. Iterables are returned and ScoredAttribtues 
 * are immutable.
 */
@Component
public class AttributeExtractor
{
	/** Sorting methods for attributes. */
	public static enum SORT_METHOD
	{ ENTROPY, SCORE, CORRELATION }
	private static final SORT_METHOD DEFAULT_SORT = SORT_METHOD.ENTROPY;
	private static final Logger LOG = LoggerFactory.getLogger(AttributeExtractor.class);
	@Autowired
 	private IDataStore aDataStore;
	private HashMap<String, ArrayList<ScoredAttribute>> aAllAttributes;
	/** Constructor that takes a category.
	 * @param pCategory the whole space of interesting products
	 */
	public AttributeExtractor()
	{
		
		aAllAttributes = new HashMap<String, ArrayList<ScoredAttribute>>();
		for(Category cat : aDataStore.getCategories())
		{
			ArrayList<ScoredAttribute> scoredAttributeList = new ArrayList<ScoredAttribute>();
			HashMap<String, Attribute> attributes = new HashMap<String, Attribute>();
			for(Product prod : cat.getProducts())
			{
				for(Attribute att : prod.getAttributes())
				{
					attributes.put(att.getId(), att);
				}
			}
			for(String key : attributes.keySet())
			{
				scoredAttributeList.add(new ScoredAttribute(attributes.get(key), cat));
			}
			sort(DEFAULT_SORT, scoredAttributeList);
			aAllAttributes.put(cat.getId(), scoredAttributeList);
		}
		
		
		
	}
	
<commit_msg>#72 Fixed issued with linking Bean with IDataStore<commit_after>/*
 * Copyright 2014 McGill University
 *
 * 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.
 */
package ca.mcgill.cs.creco.logic;

import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Set;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import ca.mcgill.cs.creco.data.Attribute;
import ca.mcgill.cs.creco.data.Category;
import ca.mcgill.cs.creco.data.IDataStore;
import ca.mcgill.cs.creco.data.Product;

 /**
 * This class handles the extraction of most relevant attribute from a category.
 * This class is a Bean (singleton) and it is created at startup. You should access this class
 * to get information on attributes within a category such as attribute entropy
 * and correlation with overall score. Iterables are returned and ScoredAttribtues 
 * are immutable.
 */
@Component
public class AttributeExtractor
{
	/** Sorting methods for attributes. */
	public static enum SORT_METHOD
	{ ENTROPY, SCORE, CORRELATION }
	private static final SORT_METHOD DEFAULT_SORT = SORT_METHOD.ENTROPY;
	private static final Logger LOG = LoggerFactory.getLogger(AttributeExtractor.class);
 	private IDataStore aDataStore;
	private HashMap<String, ArrayList<ScoredAttribute>> aAllAttributes;
	/** Constructor that takes a category.
	 * @param pCategory the whole space of interesting products
	 */
	@Autowired
	public AttributeExtractor(IDataStore pDataStore)
	{
		aDataStore = pDataStore;
		aAllAttributes = new HashMap<String, ArrayList<ScoredAttribute>>();
		for(Category cat : aDataStore.getCategories())
		{
			ArrayList<ScoredAttribute> scoredAttributeList = new ArrayList<ScoredAttribute>();
			HashMap<String, Attribute> attributes = new HashMap<String, Attribute>();
			for(Product prod : cat.getProducts())
			{
				for(Attribute att : prod.getAttributes())
				{
					attributes.put(att.getId(), att);
				}
			}
			for(String key : attributes.keySet())
			{
				scoredAttributeList.add(new ScoredAttribute(attributes.get(key), cat));
			}
			sort(DEFAULT_SORT, scoredAttributeList);
			aAllAttributes.put(cat.getId(), scoredAttributeList);
		}
		
		
		
	}
	

{'fraction_non_alphanumeric': 0.09050017992083484, 'fraction_numerical': 0.00395825836631882, 'mean_word_length': 4.476847290640394, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 19, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5216262', 'n_tokens_mistral': 1670, 'n_tokens_neox': 1562, 'n_words': 508}