001package conexp.fx.gui.graph.option;
002
003/*
004 * #%L
005 * Concept Explorer FX
006 * %%
007 * Copyright (C) 2010 - 2023 Francesco Kriegel
008 * %%
009 * This program is free software: you can redistribute it and/or modify
010 * it under the terms of the GNU General Public License as
011 * published by the Free Software Foundation, either version 3 of the
012 * License, or (at your option) any later version.
013 * 
014 * This program is distributed in the hope that it will be useful,
015 * but WITHOUT ANY WARRANTY; without even the implied warranty of
016 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
017 * GNU General Public License for more details.
018 * 
019 * You should have received a copy of the GNU General Public
020 * License along with this program.  If not, see
021 * <http://www.gnu.org/licenses/gpl-3.0.html>.
022 * #L%
023 */
024
025
026import java.util.Set;
027
028import com.google.common.base.Predicate;
029import com.google.common.collect.Sets;
030
031import conexp.fx.core.context.Concept;
032import conexp.fx.core.context.ConceptLattice;
033import conexp.fx.core.context.Context;
034
035public enum VertexRadius
036{
037  NONE("None")
038  {
039    public <G, M> double get(
040        final Context<G, M> context,
041        final ConceptLattice<G, M> lattice,
042        final Concept<G, M> concept)
043    {
044      return 0d;
045    }
046  },
047  TINY("Tiny")
048  {
049    public <G, M> double get(
050        final Context<G, M> context,
051        final ConceptLattice<G, M> lattice,
052        final Concept<G, M> concept)
053    {
054      return 3d;
055    }
056  },
057  SMALL("Small")
058  {
059    public <G, M> double get(
060        final Context<G, M> context,
061        final ConceptLattice<G, M> lattice,
062        final Concept<G, M> concept)
063    {
064      return 4d;
065    }
066  },
067  NORMAL("Normal")
068  {
069    public <G, M> double get(
070        final Context<G, M> context,
071        final ConceptLattice<G, M> lattice,
072        final Concept<G, M> concept)
073    {
074      return 5d;
075    }
076  },
077  LARGE("Large")
078  {
079    public <G, M> double get(
080        final Context<G, M> context,
081        final ConceptLattice<G, M> lattice,
082        final Concept<G, M> concept)
083    {
084      return 7d;
085    }
086  },
087  HUGE("Huge")
088  {
089    public <G, M> double get(
090        final Context<G, M> context,
091        final ConceptLattice<G, M> lattice,
092        final Concept<G, M> concept)
093    {
094      return 10d;
095    }
096  },
097  EXTENT("Extent Size")
098  {
099    public <G, M> double get(
100        final Context<G, M> context,
101        final ConceptLattice<G, M> lattice,
102        final Concept<G, M> concept)
103    {
104      return 3d + 17d * Math.sqrt(((double) concept.extent().size()) / ((double) context.rowHeads().size()));
105    }
106  },
107  INTENT("Intent Size")
108  {
109    public <G, M> double get(
110        final Context<G, M> context,
111        final ConceptLattice<G, M> lattice,
112        final Concept<G, M> concept)
113    {
114      return 3d + 17d * Math.sqrt(((double) concept.intent().size()) / ((double) context.colHeads().size()));
115    }
116  },
117  OBJECT_LABELS("Object Labels Size")
118  {
119    public <G, M> double get(
120        final Context<G, M> context,
121        final ConceptLattice<G, M> lattice,
122        final Concept<G, M> concept)
123    {
124      return 3d + 17d * Math.sqrt(((double) lattice.objectLabels(concept).size())
125          / ((double) context.rowHeads().size()));
126    }
127  },
128  ATTRIBUTE_LABELS("Attribute Labels Size")
129  {
130    public <G, M> double get(
131        final Context<G, M> context,
132        final ConceptLattice<G, M> lattice,
133        final Concept<G, M> concept)
134    {
135      return 3d + 17d * Math.sqrt(((double) lattice.attributeLabels(concept).size())
136          / ((double) context.colHeads().size()));
137    }
138  },
139  EXTENT_STABILITY("Extent Stability")
140  {
141    public <G, M> double get(
142        final Context<G, M> context,
143        final ConceptLattice<G, M> lattice,
144        final Concept<G, M> concept)
145    {
146      if (concept.intent().size() > 10d)
147        return 5d;
148      return 3d + 17d * (double) Sets.filter(Sets.powerSet(concept.intent()), new Predicate<Set<M>>()
149        {
150          public boolean apply(Set<M> intentSubset)
151          {
152            return context.colAnd(intentSubset).equals(concept.extent());
153          }
154        }).size() / (double) (1 << concept.intent().size());
155    }
156  },
157  INTENT_STABILITY("Intent Stability")
158  {
159    public <G, M> double get(
160        final Context<G, M> context,
161        final ConceptLattice<G, M> lattice,
162        final Concept<G, M> concept)
163    {
164      if (concept.extent().size() > 10d)
165        return 5d;
166      return 3d + 17d * (double) Sets.filter(Sets.powerSet(concept.extent()), new Predicate<Set<G>>()
167        {
168          public boolean apply(Set<G> extentSubset)
169          {
170            return context.rowAnd(extentSubset).equals(concept.intent());
171          }
172        }).size() / (double) (1 << concept.extent().size());
173    }
174  };
175  private final String name;
176
177  private VertexRadius(final String name)
178  {
179    this.name = name;
180  }
181
182  public abstract <G, M> double get(
183      final Context<G, M> context,
184      final ConceptLattice<G, M> lattice,
185      final Concept<G, M> concept);
186
187  public final String toString()
188  {
189    return name;
190  }
191}