/edu/uncc/parsets/data/CategoryHandle.java

https://code.google.com/p/parsets/ · Java · 103 lines · 57 code · 16 blank · 30 comment · 2 complexity · c36960ed9615240be3bd19ff096af335 MD5 · raw file

  1. package edu.uncc.parsets.data;
  2. /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *\
  3. * Copyright (c) 2009, Robert Kosara, Caroline Ziemkiewicz,
  4. * and others (see Authors.txt for full list)
  5. * All rights reserved.
  6. *
  7. * Redistribution and use in source and binary forms, with or without
  8. * modification, are permitted provided that the following conditions are met:
  9. *
  10. * * Redistributions of source code must retain the above copyright
  11. * notice, this list of conditions and the following disclaimer.
  12. * * Redistributions in binary form must reproduce the above copyright
  13. * notice, this list of conditions and the following disclaimer in the
  14. * documentation and/or other materials provided with the distribution.
  15. * * Neither the name of UNC Charlotte nor the names of its contributors
  16. * may be used to endorse or promote products derived from this software
  17. * without specific prior written permission.
  18. *
  19. * THIS SOFTWARE IS PROVIDED BY ITS AUTHORS ''AS IS'' AND ANY
  20. * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  21. * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  22. * DISCLAIMED. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY
  23. * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  24. * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  25. * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  26. * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  27. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
  28. * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  29. \* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
  30. public class CategoryHandle implements Comparable<CategoryHandle> {
  31. private String name;
  32. private String handle;
  33. private int num;
  34. private DimensionHandle dimension;
  35. private int apriori;
  36. // used for comparing categories, so that the same name in different
  37. // dimensions doesn't look like the same handle
  38. private String categoryID;
  39. public CategoryHandle(String name, String handle, int num, DimensionHandle dim, int count) {
  40. this.name = name;
  41. this.handle = handle;
  42. this.num = num;
  43. dimension = dim;
  44. apriori = count;
  45. categoryID = dim.getHandle()+":"+handle;
  46. }
  47. public String getName() {
  48. return name;
  49. }
  50. @Override
  51. public String toString() {
  52. return name;
  53. }
  54. public String getHandle() {
  55. return handle;
  56. }
  57. public int getCategoryNum() {
  58. return num;
  59. }
  60. public int getCount() {
  61. return apriori;
  62. }
  63. public void setCount(int count){
  64. this.apriori = count;
  65. }
  66. public float getMarginalFrequency() {
  67. return (float)apriori/dimension.getDataSet().getNumRecords();
  68. }
  69. public DimensionHandle getDimension() {
  70. return dimension;
  71. }
  72. public int compareTo(CategoryHandle o) {
  73. return categoryID.compareTo(o.categoryID);
  74. }
  75. @Override
  76. public boolean equals(Object o) {
  77. if (o instanceof CategoryHandle)
  78. return compareTo((CategoryHandle)o) == 0;
  79. else
  80. return false;
  81. }
  82. @Override
  83. public int hashCode() {
  84. assert false : "hashCode not designed";
  85. return 42; // any arbitrary constant will do
  86. }
  87. }