| 1 | package felix.test; |
| 2 | |
| 3 | import static org.junit.Assert.*; |
| 4 | |
| 5 | import java.io.BufferedReader; |
| 6 | import java.io.FileReader; |
| 7 | import java.util.ArrayList; |
| 8 | import java.util.HashMap; |
| 9 | import java.util.HashSet; |
| 10 | import java.util.regex.Matcher; |
| 11 | import java.util.regex.Pattern; |
| 12 | |
| 13 | import org.junit.Test; |
| 14 | |
| 15 | import tuffy.util.UIMan; |
| 16 | import felix.main.Felix; |
| 17 | import felix.parser.FelixCommandOptions; |
| 18 | import felix.util.FelixConfig; |
| 19 | import felix.util.FelixUIMan; |
| 20 | |
| 21 | /** |
| 22 | * Test Coref operator's quality. |
| 23 | * @author Ce Zhang |
| 24 | * |
| 25 | */ |
| 26 | public class CorefTest{ |
| 27 | |
| 28 | public static ArrayList<Double> planCosts = new ArrayList<Double>(); |
| 29 | public static String exeTime = ""; |
| 30 | |
| 31 | /** |
| 32 | * Test Coref's quality on a test case which has manually-built ground truth. |
| 33 | */ |
| 34 | @Test |
| 35 | public final void testCorefMAP() { |
| 36 | try{ |
| 37 | String[] args = {"-e", "test/felix/coref_test/evid.db", "-i", "test/felix/coref_test/prog.mln", |
| 38 | "-o", "test/testOutput.txt_coref", "-queryFile", "test/felix/coref_test/query.db", "-keepData"}; |
| 39 | |
| 40 | for(int wwww = 0; wwww < 2; wwww++){ |
| 41 | |
| 42 | FelixConfig.overrideID(); |
| 43 | FelixCommandOptions options = FelixUIMan.parseCommand(args); |
| 44 | |
| 45 | if(wwww == 1){ |
| 46 | options.useDualDecomposition = true; |
| 47 | FelixConfig.nDDIT = 2; |
| 48 | } |
| 49 | |
| 50 | String outfile = "test/testOutput.txt_coref"; |
| 51 | |
| 52 | if(wwww == 1){ |
| 53 | outfile = outfile + "_snap_0"; |
| 54 | } |
| 55 | |
| 56 | |
| 57 | new Felix().run(options); |
| 58 | |
| 59 | BufferedReader br = new BufferedReader(new FileReader(outfile)); |
| 60 | Pattern p = Pattern.compile("coref_map\\(\"(.*?)\", \"(.*?)\"\\)"); |
| 61 | String line; |
| 62 | Integer five = -1; |
| 63 | Integer six = -1; |
| 64 | while( (line = br.readLine()) != null ){ |
| 65 | Matcher m = p.matcher(line); |
| 66 | m.find(); |
| 67 | Integer n1 = Integer.valueOf(m.group(1)); |
| 68 | Integer n2 = Integer.valueOf(m.group(2)); |
| 69 | if(n1 != n2){ |
| 70 | if(n1 == 1 || n1 == 2 || n1 == 3 || n1 == 9){ |
| 71 | assertTrue(n2 == 1 || n2 == 2 || n2 == 3 || n2 == 9); |
| 72 | }else if(n1 ==4 || n1 ==5 || n1 ==6){ |
| 73 | assertTrue(n2 == 4 || n2 ==5 || n2 ==6); |
| 74 | }else if(n1 == 7){ |
| 75 | assertTrue(n2 == 7); |
| 76 | }else if(n1 == 8){ |
| 77 | assertTrue(n2 == 8); |
| 78 | }else{ |
| 79 | assertTrue(false); |
| 80 | } |
| 81 | } |
| 82 | |
| 83 | if(n1 == 5){ |
| 84 | five = n2; |
| 85 | } |
| 86 | if(n1 == 6){ |
| 87 | six = n2; |
| 88 | } |
| 89 | } |
| 90 | |
| 91 | System.out.println(five); |
| 92 | System.out.println(six); |
| 93 | System.out.println(five.equals(six)); |
| 94 | assertFalse(five.equals(six)); |
| 95 | |
| 96 | } |
| 97 | |
| 98 | }catch(Exception e){ |
| 99 | e.printStackTrace(); |
| 100 | assertTrue(false); |
| 101 | } |
| 102 | } |
| 103 | |
| 104 | |
| 105 | |
| 106 | } |
| 107 | |
| 108 | |
| 109 | |
| 110 | |
| 111 | |
| 112 | |