r108042 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r108041‎ | r108042 | r108043 >
Date:15:34, 4 January 2012
Author:oren
Status:ok
Tags:
Comment:
deprecated from project - these classes do not seem to be in use by search.
they will be removed in the next version together with thier data file
Modified paths:
  • /trunk/lucene-search-2/src/org/wikimedia/lsearch/util/MathFunc.java (modified) (history)
  • /trunk/lucene-search-2/test/org/wikimedia/lsearch/util/MathFuncTest.java (modified) (history)

Diff [purge]

Index: trunk/lucene-search-2/test/org/wikimedia/lsearch/util/MathFuncTest.java
@@ -4,15 +4,45 @@
55 import java.io.File;
66 import java.io.FileNotFoundException;
77 import java.io.FileReader;
 8+import java.io.IOException;
89 import java.util.ArrayList;
9 -import java.util.Arrays;
10 -
1110 import org.wikimedia.lsearch.util.MathFunc;
1211
13 -public class MathFuncTest {
 12+
 13+/**
 14+ * This class is test MathFunc which is not used in the project
 15+ * The test is visual i.e. putput not a success failure
 16+ * also neither MathFunc nor MathFuncTest are referenced in the project
 17+ *
 18+ * @deprecated
 19+ *
 20+ * if the class isn't deprecated then the following should be addressed
 21+ * configure test file location from command line
 22+ * convert to unit test
 23+ * convert to output to log4j for non console execution
 24+
 25+ *
 26+ */
 27+public class MathFuncTest
 28+{
 29+
 30+
 31+ /**
 32+ * prints the entries of an integer and a double arrays side by side
 33+ *
 34+ *
 35+ * @param p the integers
 36+ * @param val the doubles
 37+ */
1438 public static void print(int[] p, double[] val){
 39+
 40+ //for each integer in p
1541 for(int i=0;i<p.length-1;i++){
 42+
 43+ //print the value of val[i]
1644 System.out.print(MathFunc.avg(val,p[i],p[i+1])+" -> ");
 45+
 46+ //prints all a sequence of values from val
1747 for(int j=p[i];j<p[i+1];j++){
1848 System.out.print(val[j]+" ");
1949 }
@@ -21,19 +51,38 @@
2252 System.out.println();
2353 }
2454
25 - public static void main(String[] args) throws Exception{
 55+ /**
 56+ * 1. loads data from "./test-data/mathfunc.test"
 57+ * 2.
 58+ *
 59+ * @param args
 60+ * @throws FileNotFoundException
 61+ */
 62+ public static void main(String[] args) throws FileNotFoundException {
2663 double[] val = {39.2,13.45,12.67,10.25,8.84,8.66,8.31,8.19,8.06,7.99,6.39,6.19,6,5.92,5.85};
2764 String testfile = "./test-data/mathfunc.test";
2865 int[] p = MathFunc.partitionList(val,3);
2966 print(p,val);
3067
 68+
 69+ //load data from file
3170 System.out.println("From "+testfile);
3271 BufferedReader r = new BufferedReader(new FileReader(new File(testfile)));
3372 String line;
3473 ArrayList<Double> val2a = new ArrayList<Double>();
35 - while((line = r.readLine()) != null){
36 - val2a.add(new Double(line));
 74+ try {
 75+ while((line = r.readLine()) != null){
 76+ val2a.add(new Double(line));
 77+ }
 78+ } catch (NumberFormatException e) {
 79+ // TODO badly formated file
 80+ e.printStackTrace();
 81+ } catch (IOException e) {
 82+ // TODO could not read file
 83+ e.printStackTrace();
 84+
3785 }
 86+
3887 double[] val2 = new double[val2a.size()];
3988 for(int i=0;i<val2.length;i++)
4089 val2[i] = val2a.get(i);
@@ -42,6 +91,5 @@
4392 double[] val3 = {1.5192982456140351, 1.222988282514404, 1.053690036900369, 1.053690036900369, 1.003690036900369, 0.5229882825144041};
4493 print(MathFunc.partitionList(val3,5),val3);
4594
46 -
4795 }
4896 }
Index: trunk/lucene-search-2/src/org/wikimedia/lsearch/util/MathFunc.java
@@ -1,19 +1,48 @@
22 package org.wikimedia.lsearch.util;
33
4 -public class MathFunc {
5 -
6 - /** Calculate average value starting from start to end (end excluded) */
 4+/**
 5+ * this class is used only in its own tests.
 6+ *
 7+ * @deprecated
 8+ *
 9+ *
 10+ */
 11+public class MathFunc
 12+{
 13+
 14+ /**
 15+ * Calculate arithmetic mean value of an array of doubles.
 16+ *
 17+ * note: only called from MathFuncTest.
 18+ *
 19+ * @param val - array of values to average.
 20+ * @param start - array index to start.
 21+ * @param end - array index to end with (excluded).
 22+ * @return the average.
 23+ *
 24+ */
725 public static double avg(double[] val, int start, int end){
 26+
827 double s = 0;
928 for(int i=start;i<end;i++)
1029 s+=val[i];
1130 return s/(end-start);
1231 }
13 -
1432 /**
1533 * Approximate the graph of function with num horizontal lines
1634 * (const functions), so to minimize the maximal deviation
17 - * @return list of discontinuities (begin points of horizontal lines)
 35+ *
 36+ * input output for n =4
 37+ * * **
 38+ * * ** ***
 39+ * * * * *** **
 40+ * ** *
 41+ *
 42+ *
 43+ *
 44+ * @param val the heights of the function being approximated
 45+ * @param num number of discrete lines
 46+ * @return list of discontinuities (begin points of horizontal lines)
1847 */
1948 public static int[] partitionList(double[] val, int num){
2049 //System.out.println("Doing: "+Arrays.toString(val));
@@ -74,6 +103,7 @@
75104 return part;
76105 }
77106
 107+
78108 private static void extend(int[] part, int[] newpart, double[] val, int num) {
79109 for(int j=0;j<num;j++)
80110 newpart[j] = part[j];

Status & tagging log