Package ivory.regression.basic

Source Code of ivory.regression.basic.Gov2_NonPositional_Baselines

package ivory.regression.basic;

import ivory.core.eval.Qrels;
import ivory.regression.GroundTruth;
import ivory.regression.GroundTruth.Metric;
import ivory.smrf.retrieval.Accumulator;
import ivory.smrf.retrieval.BatchQueryRunner;

import java.util.Map;
import java.util.Set;

import junit.framework.JUnit4TestAdapter;

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.FileSystem;
import org.apache.log4j.Logger;
import org.junit.Test;

import com.google.common.collect.Maps;

import edu.umd.cloud9.collection.DocnoMapping;

public class Gov2_NonPositional_Baselines {
  private static final Logger LOG = Logger.getLogger(Gov2_NonPositional_Baselines.class);

  private static String[] sDirBaseRawAP = new String[] {
      "701", "0.1037", "702", "0.0562", "703", "0.0000", "704", "0.2736", "705", "0.2713",
      "706", "0.1503", "707", "0.4268", "708", "0.2231", "709", "0.7930", "710", "0.4838",
      "711", "0.1072", "712", "0.5719", "713", "0.3321", "714", "0.1248", "715", "0.1467",
      "716", "0.0791", "717", "0.3586", "718", "0.3391", "719", "0.0740", "720", "0.2969",
      "721", "0.0483", "722", "0.4724", "723", "0.1220", "724", "0.2018", "725", "0.2755",
      "726", "0.5275", "727", "0.4602", "728", "0.4438", "729", "0.0015", "730", "0.5210",
      "731", "0.1218", "732", "0.2384", "733", "0.3154", "734", "0.2396", "735", "0.2312",
      "736", "0.5789", "737", "0.5672", "738", "0.4744", "739", "0.1212", "740", "0.2608",
      "741", "0.0939", "742", "0.3503", "743", "0.0333", "744", "0.0157", "745", "0.4999",
      "746", "0.4649", "747", "0.1050", "748", "0.2025", "749", "0.2929", "750", "0.0593",
      "751", "0.3576", "752", "0.4960", "753", "0.3361", "754", "0.0887", "755", "0.4876",
      "756", "0.3338", "757", "0.2148", "758", "0.6835", "759", "0.2145", "760", "0.3245",
      "761", "0.4779", "762", "0.0204", "763", "0.1732", "764", "0.1724", "765", "0.4796",
      "766", "0.5336", "767", "0.4826", "768", "0.1242", "769", "0.0114", "770", "0.3710",
      "771", "0.5266", "772", "0.3892", "773", "0.5778", "774", "0.3555", "775", "0.1019",
      "776", "0.2608", "777", "0.3142", "778", "0.1082", "779", "0.4978", "780", "0.3421",
      "781", "0.3598", "782", "0.6516", "783", "0.2095", "784", "0.4571", "785", "0.4402",
      "786", "0.4279", "787", "0.5753", "788", "0.5235", "789", "0.2194", "790", "0.5108",
      "791", "0.4538", "792", "0.1647", "793", "0.2988", "794", "0.0645", "795", "0.0246",
      "796", "0.1733", "797", "0.6315", "798", "0.1932", "799", "0.1891", "800", "0.1998",
      "801", "0.4514", "802", "0.4094", "803", "0.0000", "804", "0.4933", "805", "0.0443",
      "806", "0.0141", "807", "0.5632", "808", "0.7256", "809", "0.3118", "810", "0.3130",
      "811", "0.2744", "812", "0.5479", "813", "0.3021", "814", "0.7217", "815", "0.1544",
      "816", "0.7935", "817", "0.3378", "818", "0.2183", "819", "0.5572", "820", "0.7611",
      "821", "0.2489", "822", "0.1110", "823", "0.3301", "824", "0.3342", "825", "0.0533",
      "826", "0.2922", "827", "0.4429", "828", "0.2497", "829", "0.0922", "830", "0.0335",
      "831", "0.6072", "832", "0.1760", "833", "0.5381", "834", "0.3873", "835", "0.0484",
      "836", "0.2219", "837", "0.0788", "838", "0.2846", "839", "0.5712", "840", "0.1665",
      "841", "0.3718", "842", "0.1087", "843", "0.4271", "844", "0.0504", "845", "0.3979",
      "846", "0.1982", "847", "0.3106", "848", "0.1165", "849", "0.2089", "850", "0.2177" };

  private static String[] sDirBaseRawP10 = new String[] {
      "701", "0.4000", "702", "0.2000", "703", "0.0000", "704", "0.5000", "705", "0.4000",
      "706", "0.1000", "707", "0.9000", "708", "0.8000", "709", "0.9000", "710", "0.8000",
      "711", "0.3000", "712", "0.9000", "713", "0.5000", "714", "0.2000", "715", "0.2000",
      "716", "0.1000", "717", "0.9000", "718", "1.0000", "719", "0.4000", "720", "0.6000",
      "721", "0.1000", "722", "1.0000", "723", "0.2000", "724", "0.3000", "725", "0.5000",
      "726", "0.9000", "727", "0.7000", "728", "0.8000", "729", "0.0000", "730", "0.8000",
      "731", "0.1000", "732", "0.4000", "733", "0.8000", "734", "0.4000", "735", "0.6000",
      "736", "1.0000", "737", "0.9000", "738", "1.0000", "739", "0.6000", "740", "0.4000",
      "741", "0.0000", "742", "0.6000", "743", "0.1000", "744", "0.0000", "745", "0.4000",
      "746", "1.0000", "747", "0.9000", "748", "0.2000", "749", "0.7000", "750", "0.1000",
      "751", "0.5000", "752", "1.0000", "753", "0.6000", "754", "0.4000", "755", "0.7000",
      "756", "0.5000", "757", "0.5000", "758", "1.0000", "759", "0.5000", "760", "0.7000",
      "761", "1.0000", "762", "0.1000", "763", "0.5000", "764", "0.4000", "765", "1.0000",
      "766", "1.0000", "767", "0.7000", "768", "0.5000", "769", "0.1000", "770", "0.8000",
      "771", "0.8000", "772", "0.9000", "773", "1.0000", "774", "0.8000", "775", "0.5000",
      "776", "0.3000", "777", "0.5000", "778", "0.4000", "779", "0.9000", "780", "0.7000",
      "781", "0.7000", "782", "0.8000", "783", "0.5000", "784", "0.2000", "785", "0.9000",
      "786", "0.8000", "787", "1.0000", "788", "0.9000", "789", "0.4000", "790", "0.9000",
      "791", "0.7000", "792", "0.6000", "793", "0.5000", "794", "0.1000", "795", "0.0000",
      "796", "0.8000", "797", "1.0000", "798", "0.5000", "799", "0.2000", "800", "0.0000",
      "801", "0.9000", "802", "0.6000", "803", "0.0000", "804", "0.6000", "805", "0.0000",
      "806", "0.2000", "807", "1.0000", "808", "1.0000", "809", "0.9000", "810", "0.3000",
      "811", "0.7000", "812", "0.7000", "813", "1.0000", "814", "0.8000", "815", "0.2000",
      "816", "0.9000", "817", "0.9000", "818", "0.6000", "819", "1.0000", "820", "0.6000",
      "821", "0.4000", "822", "0.2000", "823", "0.7000", "824", "0.9000", "825", "0.1000",
      "826", "0.3000", "827", "0.5000", "828", "0.9000", "829", "0.4000", "830", "0.1000",
      "831", "0.9000", "832", "0.5000", "833", "0.8000", "834", "0.6000", "835", "0.0000",
      "836", "0.2000", "837", "0.1000", "838", "0.8000", "839", "0.9000", "840", "0.1000",
      "841", "0.9000", "842", "0.0000", "843", "0.8000", "844", "0.1000", "845", "0.7000",
      "846", "0.8000", "847", "0.6000", "848", "0.5000", "849", "0.5000", "850", "0.3000" };

  private static String[] sBm25BaseRawAP = new String[] {
      "701", "0.0626", "702", "0.0451", "703", "0.0000", "704", "0.1469", "705", "0.1499",
      "706", "0.0418", "707", "0.2478", "708", "0.2371", "709", "0.8223", "710", "0.5348",
      "711", "0.0504", "712", "0.5609", "713", "0.3321", "714", "0.1455", "715", "0.1463",
      "716", "0.1115", "717", "0.3542", "718", "0.3385", "719", "0.0839", "720", "0.2693",
      "721", "0.0169", "722", "0.3861", "723", "0.1402", "724", "0.2843", "725", "0.2888",
      "726", "0.5141", "727", "0.4446", "728", "0.3672", "729", "0.0043", "730", "0.5027",
      "731", "0.2256", "732", "0.2486", "733", "0.3176", "734", "0.2198", "735", "0.1977",
      "736", "0.6023", "737", "0.5916", "738", "0.5923", "739", "0.0795", "740", "0.2191",
      "741", "0.0970", "742", "0.2480", "743", "0.0179", "744", "0.0138", "745", "0.4222",
      "746", "0.4066", "747", "0.0536", "748", "0.2089", "749", "0.3274", "750", "0.0272",
      "751", "0.3510", "752", "0.5228", "753", "0.3016", "754", "0.0558", "755", "0.5064",
      "756", "0.3689", "757", "0.1960", "758", "0.6989", "759", "0.3019", "760", "0.2400",
      "761", "0.5056", "762", "0.0234", "763", "0.1036", "764", "0.1027", "765", "0.4701",
      "766", "0.4865", "767", "0.4680", "768", "0.1305", "769", "0.0076", "770", "0.4511",
      "771", "0.5409", "772", "0.2170", "773", "0.5560", "774", "0.2928", "775", "0.3234",
      "776", "0.3062", "777", "0.3666", "778", "0.1278", "779", "0.5469", "780", "0.4076",
      "781", "0.3381", "782", "0.6500", "783", "0.0778", "784", "0.4589", "785", "0.3853",
      "786", "0.4403", "787", "0.5716", "788", "0.5701", "789", "0.2253", "790", "0.4652",
      "791", "0.4844", "792", "0.1218", "793", "0.4170", "794", "0.0692", "795", "0.0281",
      "796", "0.2339", "797", "0.5376", "798", "0.1734", "799", "0.3011", "800", "0.2497",
      "801", "0.4360", "802", "0.3865", "803", "0.0000", "804", "0.4788", "805", "0.0659",
      "806", "0.0201", "807", "0.5896", "808", "0.6556", "809", "0.2885", "810", "0.3456",
      "811", "0.2532", "812", "0.6084", "813", "0.3057", "814", "0.6841", "815", "0.2420",
      "816", "0.8159", "817", "0.3985", "818", "0.4326", "819", "0.5179", "820", "0.7725",
      "821", "0.1856", "822", "0.0928", "823", "0.2419", "824", "0.3279", "825", "0.0091",
      "826", "0.2273", "827", "0.3649", "828", "0.2725", "829", "0.0529", "830", "0.0418",
      "831", "0.2782", "832", "0.1672", "833", "0.4185", "834", "0.4305", "835", "0.0422",
      "836", "0.2115", "837", "0.1243", "838", "0.2687", "839", "0.5133", "840", "0.1548",
      "841", "0.3301", "842", "0.1407", "843", "0.4670", "844", "0.0500", "845", "0.3339",
      "846", "0.1627", "847", "0.3731", "848", "0.1340", "849", "0.1671", "850", "0.2759" };

  private static String[] sBm25BaseRawP10 = new String[] {
      "701", "0.3000", "702", "0.2000", "703", "0.0000", "704", "0.4000", "705", "0.4000",
      "706", "0.2000", "707", "1.0000", "708", "0.8000", "709", "0.9000", "710", "0.9000",
      "711", "0.1000", "712", "0.9000", "713", "0.7000", "714", "0.3000", "715", "0.2000",
      "716", "0.2000", "717", "1.0000", "718", "1.0000", "719", "0.4000", "720", "0.6000",
      "721", "0.1000", "722", "0.6000", "723", "0.2000", "724", "0.4000", "725", "0.4000",
      "726", "0.9000", "727", "0.7000", "728", "0.9000", "729", "0.0000", "730", "0.8000",
      "731", "0.2000", "732", "0.5000", "733", "0.8000", "734", "0.5000", "735", "0.6000",
      "736", "1.0000", "737", "1.0000", "738", "1.0000", "739", "0.5000", "740", "0.6000",
      "741", "0.1000", "742", "0.5000", "743", "0.0000", "744", "0.0000", "745", "0.5000",
      "746", "1.0000", "747", "0.7000", "748", "0.3000", "749", "0.8000", "750", "0.0000",
      "751", "0.7000", "752", "1.0000", "753", "0.7000", "754", "0.3000", "755", "0.8000",
      "756", "0.6000", "757", "0.5000", "758", "0.9000", "759", "0.8000", "760", "0.7000",
      "761", "1.0000", "762", "0.1000", "763", "0.2000", "764", "0.6000", "765", "1.0000",
      "766", "1.0000", "767", "1.0000", "768", "0.7000", "769", "0.0000", "770", "1.0000",
      "771", "1.0000", "772", "0.8000", "773", "1.0000", "774", "0.6000", "775", "0.6000",
      "776", "0.5000", "777", "0.5000", "778", "0.4000", "779", "1.0000", "780", "0.8000",
      "781", "0.9000", "782", "0.8000", "783", "0.2000", "784", "0.3000", "785", "0.9000",
      "786", "0.7000", "787", "1.0000", "788", "0.9000", "789", "0.4000", "790", "0.9000",
      "791", "0.8000", "792", "0.5000", "793", "0.6000", "794", "0.2000", "795", "0.0000",
      "796", "0.7000", "797", "0.7000", "798", "0.2000", "799", "0.4000", "800", "0.1000",
      "801", "0.8000", "802", "0.9000", "803", "0.0000", "804", "0.4000", "805", "0.1000",
      "806", "0.2000", "807", "1.0000", "808", "1.0000", "809", "0.8000", "810", "0.5000",
      "811", "0.7000", "812", "0.9000", "813", "0.9000", "814", "0.9000", "815", "0.6000",
      "816", "0.9000", "817", "1.0000", "818", "0.9000", "819", "1.0000", "820", "0.6000",
      "821", "0.4000", "822", "0.2000", "823", "0.6000", "824", "0.9000", "825", "0.0000",
      "826", "0.5000", "827", "0.3000", "828", "0.8000", "829", "0.1000", "830", "0.1000",
      "831", "0.7000", "832", "0.6000", "833", "0.5000", "834", "1.0000", "835", "0.0000",
      "836", "0.4000", "837", "0.1000", "838", "0.7000", "839", "1.0000", "840", "0.1000",
      "841", "0.8000", "842", "0.0000", "843", "0.9000", "844", "0.2000", "845", "0.7000",
      "846", "0.8000", "847", "0.9000", "848", "0.5000", "849", "0.5000", "850", "0.6000" };

  @Test
  public void runRegression() throws Exception {
    String[] params = new String[] {
        "data/gov2/run.gov2.nonpositional.baselines.xml",
        "data/gov2/queries.gov2.title.701-775.xml",
        "data/gov2/queries.gov2.title.776-850.xml" };

    FileSystem fs = FileSystem.getLocal(new Configuration());

    BatchQueryRunner qr = new BatchQueryRunner(params, fs);

    long start = System.currentTimeMillis();
    qr.runQueries();
    long end = System.currentTimeMillis();

    LOG.info("Total query time: " + (end - start) + "ms");

    verifyAllResults(qr.getModels(), qr.getAllResults(), qr.getDocnoMapping(),
        new Qrels("data/gov2/qrels.gov2.all"));
  }

  public static void verifyAllResults(Set<String> models,
      Map<String, Map<String, Accumulator[]>> results, DocnoMapping mapping, Qrels qrels) {

    Map<String, GroundTruth> g = Maps.newHashMap();
    // One topic didn't contain qrels, so trec_eval only picked up 149.
    g.put("gov2-dir-base", new GroundTruth(Metric.AP, 149, sDirBaseRawAP, 0.3077f));
    g.put("gov2-bm25-base", new GroundTruth(Metric.AP, 149, sBm25BaseRawAP, 0.2999f));

    Map<String, GroundTruth> h = Maps.newHashMap();
    // One topic didn't contain qrels, so trec_eval only picked up 149.
    h.put("gov2-dir-base", new GroundTruth(Metric.P10, 149, sDirBaseRawP10, 0.5631f));
    h.put("gov2-bm25-base", new GroundTruth(Metric.P10, 149, sBm25BaseRawP10, 0.5846f));

    for (String model : models) {
      LOG.info("Verifying results of model \"" + model + "\"");

      Map<String, Accumulator[]> r = results.get(model);
      g.get(model).verify(r, mapping, qrels);
      h.get(model).verify(r, mapping, qrels);

      LOG.info("Done!");
    }
  }

  public static junit.framework.Test suite() {
    return new JUnit4TestAdapter(Gov2_NonPositional_Baselines.class);
  }
}
TOP

Related Classes of ivory.regression.basic.Gov2_NonPositional_Baselines

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.