internal AttributeSelection BuildSelection(IAssetType assetType)
        {
            var attributes = new AttributeSelection();

            attributes.AddRange(Selectors.Select(property => assetType.GetAttributeDefinition(ResolvePropertyName(property))));
            return(attributes);
        }
		public void Find2() {
			var query = new Query(new MockAssetType());
			var findin = new AttributeSelection { new MockAttributeDefinition("Name"), new MockAttributeDefinition("Description") };
			query.Find = new QueryFind("TextToFind", findin);
			var testMe = new QueryURLBuilder(query);
			Assert.AreEqual("Data/Mock?sel=&find=\"TextToFind\"&findin=Mock.Name,Mock.Description", testMe.ToString());
		}
        internal QueryFind BuildFind(IAssetType assetType)
        {
            if (!string.IsNullOrEmpty(Find.SearchString))
            {
                var attributes = new AttributeSelection();

                if (Find.Fields.Count > 0)
                {
                    attributes.AddRange(Find.Fields.Select(field => assetType.GetAttributeDefinition(ResolvePropertyName(field))));
                }
                else
                {
                    if (assetType.ShortNameAttribute != null)
                    {
                        attributes.Add(assetType.ShortNameAttribute);
                    }

                    if (assetType.NameAttribute != null)
                    {
                        attributes.Add(assetType.NameAttribute);
                    }

                    if (assetType.DescriptionAttribute != null)
                    {
                        attributes.Add(assetType.DescriptionAttribute);
                    }
                }

                return(new QueryFind(Find.SearchString, attributes));
            }

            return(null);
        }
Exemple #4
0
        private static IEnumerable <IAttributeDefinition> GetSuggestedSelection(IAssetType assetType, Type type)
        {
            var result = new AttributeSelection();

            for (var t = type; t != null; t = t.BaseType)
            {
                var attributes = t.GetCustomAttributes(typeof(MetaDataAttribute), false);

                foreach (MetaDataAttribute attrib in attributes)
                {
                    var names = attrib.DefaultAttributeSelectionNames;

                    if (!string.IsNullOrEmpty(names))
                    {
                        foreach (var name in names.Split(','))
                        {
                            IAttributeDefinition def;

                            if (assetType.TryGetAttributeDefinition(name, out def))
                            {
                                if (!result.Contains(def))
                                {
                                    result.Add(def);
                                }
                            }
                        }
                    }
                }
            }

            return(result);
        }
Exemple #5
0
        private AttributeSelection AttributeSelectionFilter(int opcao)
        {
            AttributeSelection filter = new AttributeSelection();

            // CfSubsetEval e BestFirst
            if (opcao == 1)
            {
                weka.attributeSelection.CfsSubsetEval evaluator = new weka.attributeSelection.CfsSubsetEval();
                filter.setEvaluator(evaluator);

                weka.attributeSelection.BestFirst search = new weka.attributeSelection.BestFirst();
                filter.setSearch(search);
            }
            // InfoGainAttributeEval e Ranker
            else if (opcao == 2)
            {
                // Evaluator
                weka.attributeSelection.InfoGainAttributeEval evaluator = new weka.attributeSelection.InfoGainAttributeEval();
                //evaluator.setMissingSeparate(true);
                filter.setEvaluator(evaluator);

                // Search strategy: best first (default values)
                weka.attributeSelection.Ranker search = new weka.attributeSelection.Ranker();
                search.setThreshold(0);
                filter.setSearch(search);
            }

            return(filter);
        }
        public void Find2()
        {
            var query  = new Query(new MockAssetType());
            var findin = new AttributeSelection {
                new MockAttributeDefinition("Name"), new MockAttributeDefinition("Description")
            };

            query.Find = new QueryFind("TextToFind", findin);
            var testMe = new QueryURLBuilder(query);

            Assert.AreEqual("Data/Mock?sel=&find=\"TextToFind\"&findin=Mock.Name,Mock.Description", testMe.ToString());
        }
    protected void btnAddAttribute_Click(object sender, EventArgs e)
    {
        Commerce.Common.Attribute att = new Commerce.Common.Attribute();
        att.Name          = txtAttributeNew.Text.Trim();
        att.Description   = txtAttNewDesc.Text.Trim();
        att.SelectionType = (AttributeType)int.Parse(ddlAttNewSelectionType.SelectedValue);

        //get the selections from the viewstate
        ArrayList aList = GetSelections();

        att.Selections = new System.Collections.Generic.List <AttributeSelection>();

        if (att.SelectionType != AttributeType.UserInput)
        {
            for (int i = 0; i < aList.Count; i++)
            {
                att.Selections.Add((AttributeSelection)aList[i]);
            }
        }
        else
        {
            AttributeSelection sel = new AttributeSelection();
            sel.Value           = "";
            sel.PriceAdjustment = 0;
            att.Selections.Add(sel);
        }


        //a product can have one or more attribute selections
        //like "size" and "color"
        //store these into the viewstate as they are saved
        //and synch them with the product bits as well
        Commerce.Common.Attributes atts = null;
        if (ViewState["atts"] == null)
        {
            atts = new Attributes();
        }
        else
        {
            atts = (Attributes)ViewState["atts"];
        }
        atts.Add(att);


        //put it back the ViewState
        ViewState["atts"] = atts;

        //and set it to the product, which will serialize it down
        //to XML
        ProductController.UpdateProductAttributes(int.Parse(lblID.Text), atts);
        //bind up the grid
        BindAttList(atts);
    }
Exemple #8
0
        private ICollection <T> QueryToEntityEnum <T>(Query query) where T : Entity
        {
            var assetStateSelection = new AttributeSelection();
            IAttributeDefinition assetStateDef;

            if (query.AssetType.TryGetAttributeDefinition("AssetState", out assetStateDef))
            {
                assetStateSelection.Add(assetStateDef);
            }

            var suggestedSelection = GetSuggestedSelection(query.AssetType, typeof(T));
            var flattenedSelection = FlattenSelection(query.AssetType, query.Selection);

            query.Selection = AttributeSelection.Merge(assetStateSelection, suggestedSelection, flattenedSelection);

            return(AssetEnumToEntityEnum <T>(Services.Retrieve(query).Assets));
        }
    protected void btnAddAtt_Click(object sender, EventArgs e)
    {
        //create an attribute list
        ArrayList aList = GetSelections();

        if (aList == null)
        {
            aList = new ArrayList();
        }

        //create a new selection and add it
        Commerce.Common.AttributeSelection sel = new AttributeSelection();
        sel.PriceAdjustment = decimal.Parse(txtPriceAdjustment.Text);
        sel.Value           = txtSelectionAdd.Text;

        aList.Add(sel);
        BindSells(aList);

        ViewState["aList"] = aList;
    }
Exemple #10
0
        private static AttributeSelection FlattenSelection(IAssetType querytype, IEnumerable <IAttributeDefinition> orig)
        {
            var selection = new AttributeSelection();

            foreach (var def in orig)
            {
                IAttributeDefinition newdef = null;

                if (def.AssetType.Is(querytype))
                {
                    if (def.AssetType == querytype || def.Base == null)
                    {
                        newdef = def;
                    }
                    else if (def.Base.AssetType.Is(querytype))
                    {
                        newdef = def.Base;
                    }
                    else
                    {
                        newdef = querytype.GetAttributeDefinition(def.Name);
                    }
                }
                else if (querytype.Is(def.AssetType))
                {
                    newdef = querytype.GetAttributeDefinition(def.Name);
                }

                if (newdef != null && !selection.Contains(newdef))
                {
                    selection.Add(newdef);
                }
            }

            return(selection);
        }
        private int[] ReduceByGreedySupervised(weka.core.Instances insts)
        {
            int[] rang = null;

            AttributeSelection filter = new AttributeSelection();  // package weka.filters.supervised.attribute!
            CfsSubsetEval eval = new CfsSubsetEval();
            GreedyStepwise search = new GreedyStepwise();
            search.setSearchBackwards(true);
            filter.setEvaluator(eval);
            filter.setSearch(search);
            filter.SelectAttributes(insts);
            rang = filter.selectedAttributes();

            return rang;
        }
 public QueryFind(string text, AttributeSelection sel) {
     Text = text;
     Attributes = sel;
 }
Exemple #13
0
 public QueryFind(string text, AttributeSelection sel)
 {
     Text       = text;
     Attributes = sel;
 }
Exemple #14
0
        //public static T[] SubArray<T>(this T[] data, int index, int length)
        //{
        //    T[] result = new T[length];
        //    Array.Copy(data, index, result, 0, length);
        //    return result;
        //}

        public static void useLowLevelInformationGainFeatureSelection(Instances data)
        {
            AttributeSelection    attsel = new AttributeSelection();
            InfoGainAttributeEval eval   = new InfoGainAttributeEval();
            Ranker search = new Ranker();

            //1000 features >0, should be equal to -1 features and threshold 0.0. anyway i use 0.01.

            //int numtoselect = 1000;// 1520;
            //search.setThreshold(-1.7976931348623157E308d);


            int   numtoselect = 0;
            float threshold   = 0;

            if (GuiPreferences.Instance.IgSelectionType == IGType.Threshold)
            {
                numtoselect = -1;
                threshold   = Convert.ToSingle(GuiPreferences.Instance.NudIGThreshold);
                GuiPreferences.Instance.setLog("Filtering using IG threshold: " + GuiPreferences.Instance.NudIGThreshold.ToString());
            }
            else if (GuiPreferences.Instance.IgSelectionType == IGType.Voxels)
            {
                //num of vox plus above 0 cut off.
                numtoselect = Convert.ToInt32(GuiPreferences.Instance.NudIGVoxelAmount);
                //search.setThreshold(-1.7976931348623157E308d);
                GuiPreferences.Instance.setLog("Filtering using IG Voxel Amount of: " + GuiPreferences.Instance.NudIGVoxelAmount.ToString());
            }
            else
            {
                GuiPreferences.Instance.setLog("error wrong IG type");
            }


            search.setNumToSelect(numtoselect);
            search.setThreshold(threshold);
            attsel.setEvaluator(eval);
            attsel.setSearch(search);
            attsel.SelectAttributes(data);

            //reeturned back to the global instance
            Preferences.Instance.attsel = attsel;

            //hIstogram saving indices and ranked to preferences for easy access
            SortedDictionary <double, int> Histogram = new SortedDictionary <double, int>();

            double[][] blah = attsel.rankedAttributes();

            for (double i = -0.05; i < 1.2; i += 0.05)
            {
                if (!Histogram.ContainsKey(i))
                {
                    Histogram.Add(i, 0);
                }
                for (int j = 0; j < blah.Length; j++)
                {
                    if (blah[j][1] > i - 0.05 && blah[j][1] <= i)
                    {
                        Histogram[i] += 1;
                    }
                }
            }

            GuiPreferences.Instance.setLog("Histogram:");
            for (double i = -0.05; i < 1.2; i += 0.05)
            {
                GuiPreferences.Instance.setLog("Threshold: " + i.ToString() + ": " + Histogram[i].ToString());
            }

            //--------------

            if (GuiPreferences.Instance.IgSelectionType == IGType.Voxels)
            {
                //SELECT K BIGGER THAN ZERO.
                int IgVoxAboveZero = 0;
                for (int j = 0; j < GuiPreferences.Instance.NudIGVoxelAmount; j++)
                {
                    if (blah[j][1] > 0)
                    {
                        IgVoxAboveZero++;
                    }
                }

                //this is a bit redundant, to replace this redundancy, create two vectors, selected() & ranked()
                search.setNumToSelect(IgVoxAboveZero);
                search.setThreshold(threshold);
                attsel.setEvaluator(eval);
                attsel.setSearch(search);
                attsel.SelectAttributes(data);
                Preferences.Instance.attsel = attsel;

                GuiPreferences.Instance.NudIGVoxelAmount = IgVoxAboveZero;
                GuiPreferences.Instance.setLog("Filtering using IG Voxel Amount of (above zero): " + GuiPreferences.Instance.NudIGVoxelAmount.ToString());
                GuiPreferences.Instance.setLog("Changing NudIGVoxelAmount to the above figure!");
            }

            //////////////////////////////////////////////////////////////////////////////////////////////////////
            ///
            //NOTE: uncommenting this proves that ranked attributes are 0-based. this sorts them out from 0 to 204799 (Also threshold above should be 0

            /*double[][] blah = attsel.rankedAttributes();
             * double[] blat = new double[blah.Length];
             * for (int i = 0; i < blah.Length;i++ )
             * {
             *  blat[i] = blah[i][0];
             * }
             *  Array.Sort(blat);*/
            //////////////////////////////////////////////////////////////////////////////////////////////////////


            //if this code is used it will need to be ammended for numtoselect which is -1 (All) in this case

            /*double[][] ranked = attsel.rankedAttributes();
             * int indexBiggerThanZero = 0;
             * int classColumn = indices[indices.Length - 1];
             * while ((ranked[indexBiggerThanZero][1] > threshold) && (indexBiggerThanZero < numtoselect))
             *  indexBiggerThanZero++;
             *
             * //return K features whose IG value is bigger than zero
             * int[] indicesFinal = new int[] {};
             * //less than K features, we dynamically resize an array and return it + class
             * if (indexBiggerThanZero < numtoselect)
             * {
             *  Array.Resize(ref indicesFinal, indexBiggerThanZero+1);
             *  Array.Copy(indices, 0, indicesFinal, 0, indexBiggerThanZero);
             *
             *  //Array.Copy(indices, 0, indices, 0, indices.Length+1);
             *  indicesFinal[indicesFinal.Length - 1] = classColumn;
             *
             *  return indicesFinal;
             * }
             * else
             * {
             *  //if indexBiggerThanZero is the same, all features ig values are aboce zero, we return the original int array
             *  return indices;
             * }*/
        }
        /// <summary>
        /// Attempts to match owners of the workitem in the external system to users in VersionOne.
        /// </summary>
        /// <param name="ownerNames">Comma seperated list of usernames.</param>
        /// <returns>Oids of matching users in VersionOne.</returns>
        //TODO refactor
        private IEnumerable<Oid> GetOwnerOids(string ownerNames)
        {
            var result = new List<Oid>();

            if(!string.IsNullOrEmpty(ownerNames)) {
                var memberType = metaModel.GetAssetType("Member");

                foreach(var ownerName in ownerNames.Split(',')) {
                    if (!string.IsNullOrEmpty(ownerName)) {
                        var ownerQuery = new Query(memberType);
                        var nameSelection = new AttributeSelection(memberType.GetAttributeDefinition("Username"));
                        ownerQuery.Find = new QueryFind(ownerName, nameSelection);
                        var matches = services.Retrieve(ownerQuery).Assets;
                        result.AddRange(matches.Select(owner => owner.Oid));
                    }
                }
            }

            return result.ToArray();
        }
 internal AttributeSelection BuildSelection(IAssetType assetType) {
     var attributes = new AttributeSelection();
     attributes.AddRange(Selectors.Select(property => assetType.GetAttributeDefinition(ResolvePropertyName(property))));
     return attributes;
 }
        internal QueryFind BuildFind(IAssetType assetType) {
            if (!string.IsNullOrEmpty(Find.SearchString)) {
                var attributes = new AttributeSelection();

                if (Find.Fields.Count > 0) {
                    attributes.AddRange(Find.Fields.Select(field => assetType.GetAttributeDefinition(ResolvePropertyName(field))));
                } else {
                    if(assetType.ShortNameAttribute != null) {
                        attributes.Add(assetType.ShortNameAttribute);
                    }

                    if(assetType.NameAttribute != null) {
                        attributes.Add(assetType.NameAttribute);
                    }

                    if(assetType.DescriptionAttribute != null) {
                        attributes.Add(assetType.DescriptionAttribute);
                    }
                }

                return new QueryFind(Find.SearchString, attributes);
            }

            return null;
        }