<commit_before>/*
    Weave (Web-based Analysis and Visualization Environment)
    Copyright (C) 2008-2011 University of Massachusetts Lowell

    This file is a part of Weave.

    Weave is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License, Version 3,
    as published by the Free Software Foundation.

    Weave is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with Weave.  If not, see <http://www.gnu.org/licenses/>.
*/

package weave.data.DataSources
{
	import weave.api.WeaveAPI;
	import weave.api.core.IDisposableObject;
	import weave.api.core.ILinkableHashMap;
	import weave.api.core.ILinkableObject;
	import weave.api.data.AttributeColumnMetadata;
	import weave.api.data.IAttributeColumn;
	import weave.api.data.IAttributeHierarchy;
	import weave.api.data.IColumnReference;
	import weave.api.data.IDataSource;
	import weave.api.getCallbackCollection;
	import weave.api.getSessionState;
	import weave.api.newLinkableChild;
	import weave.core.LinkableDynamicObject;
	import weave.core.LinkableXML;
	import weave.data.AttributeColumns.EquationColumn;
	import weave.data.AttributeColumns.ProxyColumn;
	import weave.data.ColumnReferences.HierarchyColumnReference;
	import weave.primitives.AttributeHierarchy;
	import weave.services.beans.HierarchicalClusteringResult;
	import weave.utils.ColumnUtils;
	import weave.utils.HierarchyUtils;

	/**
	 * MultiDataSource
	 * This is a class to keep an updated list of all the available data sources
	 * 
	 * @author skolman
	*/
	public class MultiDataSource implements IDataSource, IDisposableObject
	{
		public function MultiDataSource()
		{
			var sources:Array = _root.getObjects(IDataSource);
			
			for each(var source:IDataSource in sources)
			{
				if(!(source is MultiDataSource))
				{
					getCallbackCollection(source.attributeHierarchy).addImmediateCallback(this, handleHierarchyChange);
				}
			}
			
			_root.childListCallbacks.addImmediateCallback(this, handleWeaveChildListChange);
			handleHierarchyChange();
		}
		
		private static var _instance:MultiDataSource;
		public static function get instance():MultiDataSource
		{
			if (!_instance)
				_instance = new MultiDataSource();
			return _instance;
		}
		private var _root:ILinkableHashMap = WeaveAPI.globalHashMap;
		
		/**
		 * attributeHierarchy
		 * @return An AttributeHierarchy object that will be updated when new pieces of the hierarchy are filled in.
		 */
		private const _attributeHierarchy:AttributeHierarchy = newLinkableChild(this, AttributeHierarchy);
		public function get attributeHierarchy():IAttributeHierarchy
		{
			return _attributeHierarchy;
		}
		
		
		private function handleWeaveChildListChange():void
		{
			// add callback to new IDataSource or IAttributeColumn so we refresh the hierarchy when it changes
			var newObj:ILinkableObject = _root.childListCallbacks.lastObjectAdded;
			if (!(newObj is MultiDataSource))
				if (newObj is IDataSource || newObj is IAttributeColumn)
					getCallbackCollection(newObj).addImmediateCallback(this, handleHierarchyChange);
			
			handleHierarchyChange();
		}
		
		private function handleHierarchyChange():void
		{
			var rootNode:XML = <hierarchy name="DataSources"/>;
			
			// add category for each IDataSource
			var sources:Array = _root.getObjects(IDataSource);
			for each(var source:IDataSource in sources)
			{
				if(!(source is MultiDataSource))
				{
					var xml:XML = (source.attributeHierarchy as AttributeHierarchy).value;
					if (xml != null)
					{
						var category:XML = xml.copy();
						category.setName("category");
						category.@dataSourceName = _root.getName(source);
						rootNode.appendChild(category);
					}
				}
			}
			
			// add category for global column objects
			// TEMPORARY SOLUTION -- only allow EquationColumns
			var eqCols:Array = _root.getObjects(EquationColumn);
			if (eqCols.length > 0)
			{
				var globalCategory:XML = <category title="Equations"/>;
				for each(var col:IAttributeColumn in eqCols)
				{
					globalCategory.appendChild(<attribute name={ _root.getName(col) } title={ col.getMetadata(AttributeColumnMetadata.TITLE) }/>);
				}
				rootNode.appendChild(globalCategory);
			}
			
			_attributeHierarchy.value = rootNode;
			
		}
		
		
		/**<commit_msg>CSVColumns now appear in the attribute selector.<commit_after>/*
    Weave (Web-based Analysis and Visualization Environment)
    Copyright (C) 2008-2011 University of Massachusetts Lowell

    This file is a part of Weave.

    Weave is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License, Version 3,
    as published by the Free Software Foundation.

    Weave is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with Weave.  If not, see <http://www.gnu.org/licenses/>.
*/

package weave.data.DataSources
{
	import weave.api.WeaveAPI;
	import weave.api.core.IDisposableObject;
	import weave.api.core.ILinkableHashMap;
	import weave.api.core.ILinkableObject;
	import weave.api.data.AttributeColumnMetadata;
	import weave.api.data.IAttributeColumn;
	import weave.api.data.IAttributeHierarchy;
	import weave.api.data.IColumnReference;
	import weave.api.data.IDataSource;
	import weave.api.getCallbackCollection;
	import weave.api.getSessionState;
	import weave.api.newLinkableChild;
	import weave.core.LinkableDynamicObject;
	import weave.core.LinkableXML;
	import weave.data.AttributeColumns.CSVColumn;
	import weave.data.AttributeColumns.EquationColumn;
	import weave.data.AttributeColumns.ProxyColumn;
	import weave.data.ColumnReferences.HierarchyColumnReference;
	import weave.primitives.AttributeHierarchy;
	import weave.services.beans.HierarchicalClusteringResult;
	import weave.utils.ColumnUtils;
	import weave.utils.HierarchyUtils;

	/**
	 * MultiDataSource
	 * This is a class to keep an updated list of all the available data sources
	 * 
	 * @author skolman
	*/
	public class MultiDataSource implements IDataSource, IDisposableObject
	{
		public function MultiDataSource()
		{
			var sources:Array = _root.getObjects(IDataSource);
			
			for each(var source:IDataSource in sources)
			{
				if(!(source is MultiDataSource))
				{
					getCallbackCollection(source.attributeHierarchy).addImmediateCallback(this, handleHierarchyChange);
				}
			}
			
			_root.childListCallbacks.addImmediateCallback(this, handleWeaveChildListChange);
			handleHierarchyChange();
		}
		
		private static var _instance:MultiDataSource;
		public static function get instance():MultiDataSource
		{
			if (!_instance)
				_instance = new MultiDataSource();
			return _instance;
		}
		private var _root:ILinkableHashMap = WeaveAPI.globalHashMap;
		
		/**
		 * attributeHierarchy
		 * @return An AttributeHierarchy object that will be updated when new pieces of the hierarchy are filled in.
		 */
		private const _attributeHierarchy:AttributeHierarchy = newLinkableChild(this, AttributeHierarchy);
		public function get attributeHierarchy():IAttributeHierarchy
		{
			return _attributeHierarchy;
		}
		
		
		private function handleWeaveChildListChange():void
		{
			// add callback to new IDataSource or IAttributeColumn so we refresh the hierarchy when it changes
			var newObj:ILinkableObject = _root.childListCallbacks.lastObjectAdded;
			if (!(newObj is MultiDataSource))
				if (newObj is IDataSource || newObj is IAttributeColumn)
					getCallbackCollection(newObj).addImmediateCallback(this, handleHierarchyChange);
			
			handleHierarchyChange();
		}
		
		private function handleHierarchyChange():void
		{
			var rootNode:XML = <hierarchy name="DataSources"/>;
			
			// add category for each IDataSource
			var sources:Array = _root.getObjects(IDataSource);
			for each(var source:IDataSource in sources)
			{
				if(!(source is MultiDataSource))
				{
					var xml:XML = (source.attributeHierarchy as AttributeHierarchy).value;
					if (xml != null)
					{
						var category:XML = xml.copy();
						category.setName("category");
						category.@dataSourceName = _root.getName(source);
						rootNode.appendChild(category);
					}
				}
			}
			
			// add category for global column objects
			// TEMPORARY SOLUTION -- only allow EquationColumns
			var eqCols:Array = _root.getObjects(EquationColumn).concat(_root.getObjects(CSVColumn));
			if (eqCols.length > 0)
			{
				var globalCategory:XML = <category title="Equations"/>;
				for each(var col:IAttributeColumn in eqCols)
				{
					globalCategory.appendChild(<attribute name={ _root.getName(col) } title={ col.getMetadata(AttributeColumnMetadata.TITLE) }/>);
				}
				rootNode.appendChild(globalCategory);
			}
			
			_attributeHierarchy.value = rootNode;
			
		}
		
		
		/**
{'fraction_non_alphanumeric': 0.08115468409586056, 'fraction_numerical': 0.002178649237472767, 'mean_word_length': 4.038968166849616, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 6}, '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': '4328966', 'n_tokens_mistral': 3079, 'n_tokens_neox': 2620, 'n_words': 706}