Package ivory.core

Examples of ivory.core.RetrievalException


        }

        try {
          metafeatureValues.put(mf, readDataStats(file));
        } catch (IOException e) {
          throw new RetrievalException("Error: " + e);
        }

        float defaultValue = XMLTools.getAttributeValue(child, "default", 0.0f);
        defaultValues.put(mf.getName(), defaultValue);
      }
View Full Code Here


        // Get concept importance source (if applicable).
        String importanceSource = XMLTools.getAttributeValue(child, "importance", "");
        if (!importanceSource.equals("")) {
          importanceModel = env.getImportanceModel(importanceSource);
          if (importanceModel == null) {
            throw new RetrievalException("ImportanceModel " + importanceSource + " not found!");
          }
        }

        // Get CliqueSet type.
        String cliqueSetType = XMLTools.getAttributeValue(child, "cliqueSet", "");
View Full Code Here

        builder = new CascadeFeatureBasedMRFBuilder(env, model);
      } else {
        throw new ConfigurationException("Unrecognized model type: " + modelType);
      }
    } catch (IOException e) {
      throw new RetrievalException("Error getting MRFBuilder: " + e);
    }

    return builder;
  }
View Full Code Here

          ConceptImportanceModel importanceModel = null;
          String importanceSource = XMLTools.getAttributeValue(child, "importance", null);
          if (importanceSource != null) {
            importanceModel = env.getImportanceModel(importanceSource);
            if (importanceModel == null) {
              throw new RetrievalException("Error: importancemodel " + importanceSource
                  + " not found!");
            }
          }
          importanceModels.add(importanceModel);
        }
View Full Code Here

    super(env, model);

    // model type
    modelType = XMLTools.getAttributeValue(model, "style", null);
    if (modelType == null || (!"Indep".equals(modelType) && !"Joint".equals(modelType))) {
      throw new RetrievalException(
          "Error: GreedyConstrainedMRFBuilder requires a model type attribute of Indep or Joint!");
    }

    // query likelihood
    qlMultiple = XMLTools.getAttributeValue(model, "qlMultiple", -1.0f);

    // unigram and bigram basic thresholds
    unigramAddThreshold = XMLTools.getAttributeValue(model, "unigramAddThreshold", -1.0f);
    bigramAddThreshold = XMLTools.getAttributeValue(model, "bigramAddThreshold", -1.0f);

    // unigram and bigram redundancy thresholds
    unigramRedundThreshold = XMLTools.getAttributeValue(model, "unigramRedundThreshold", -1.0f);
    bigramRedundThreshold = XMLTools.getAttributeValue(model, "bigramRedundThreshold", -1.0f);

    // beta value
    beta = XMLTools.getAttributeValue(model, "beta", -1.0f);

    if ("Indep".equals(modelType) && (qlMultiple == -1 || unigramAddThreshold == -1)) {
      throw new RetrievalException(
          "Error: Indep model must specify valid qlMultiple, unigramAddThreshold, and bigramAddThreshold attributes!");
    }

    if ("Joint".equals(modelType) &&
         (qlMultiple == -1 || unigramAddThreshold == -1 || bigramAddThreshold == -1
            || unigramRedundThreshold == -1 || bigramRedundThreshold == -1 || beta == -1)) {
      throw new RetrievalException(
          "Error: Joint model must specify valid qlMultiple, unigramAddThreshold, bigramAddThreshold, unigramRedundThreshold, bigramRedundThreshold, and beta attributes!");
    }

    String file = XMLTools.getAttributeValue(model, "file", null);
    if (file == null) {
      throw new RetrievalException(
          "Error: GreedyConstrainedMRFBuilder requires a file attribute specifying the location of the document frequencies!");
    }

    // Read document frequencies.
    dfs = LinearImportanceModel.readDataStats(file);
View Full Code Here

      if ("feature".equals(child.getNodeName())) {
        // Get the feature id.
        String featureID = XMLTools.getAttributeValue(child, "id", "");
        if (featureID.equals("")) {
          throw new RetrievalException("Each feature must specify an id attribute!");
        }

        // Get feature weight (default = 1.0).
        float weight = XMLTools.getAttributeValue(child, "weight", 1.0f);

        // Concept importance model (optional).
        ConceptImportanceModel importanceModel = null;

        // Get concept importance source (if applicable).
        String importanceSource = XMLTools.getAttributeValue(child, "importance", "");
        if (!importanceSource.equals("")) {
          importanceModel = env.getImportanceModel(importanceSource);
          if (importanceModel == null) {
            throw new RetrievalException("ImportanceModel " + importanceSource + " not found!");
          }
        }

        // Get CliqueSet type.
        String cliqueSetType = XMLTools.getAttributeValue(child, "cliqueSet", "");

        // Get Cascade stage (if any)
        int cascadeStage = XMLTools.getAttributeValue(child, "cascadeStage", -1);

        String pruner_and_params = XMLTools.getAttributeValue(child, "prune", "null");
        String thePruner = (pruner_and_params.trim().split("\\s+"))[0];
        String conceptBinType = XMLTools.getAttributeValue(child, "conceptBinType", "");
        String conceptBinParams = XMLTools.getAttributeValue(child, "conceptBinParams", "");
        String scoreFunction = XMLTools.getAttributeValue(child, "scoreFunction", null);

        int width = XMLTools.getAttributeValue(child, "width", -1);

        if (cascadeStage != -1) {
          RetrievalEnvironment.setIsNew(true);
        } else {
          RetrievalEnvironment.setIsNew(false);
        }

        if (cascadeStage != -1) {
          if (!conceptBinType.equals("") || !conceptBinParams.equals("")) {
            if (conceptBinType.equals("") || conceptBinParams.equals("")) {
              throw new RetrievalException("Most specify conceptBinType || conceptBinParams");
            }
            importanceModel = env.getImportanceModel("wsd");

            if (importanceModel == null) {
              throw new RetrievalException("ImportanceModel " + importanceSource + " not found!");
            }
          }
        }

        cascade_stage_proper = cascadeStage;
View Full Code Here

      // [0]: # bins; [1]: which bin for this feature
      String[] tokens = conceptBinParams.split("\\s+");

      if (tokens.length != 2) {
        throw new RetrievalException(
            "For impact binning, should specify # bins(as a fraction of # total cliques) and which bin for this feature");
      }

      // K
      double numBins = Math.floor(Double.parseDouble(tokens[0]));

      // 1-indexed!!!!
      int whichBin = Integer.parseInt(tokens[1]);

      if (sanityCheck.containsKey(conceptBinType + " " + numBins + " " + whichBin + " "
          + all_concepts + " " + featureID + " " + thePruner + " " + width + " " + scoreFunction)) {
        throw new RetrievalException("Bin " + whichBin
            + " has been used by this concept type before " + conceptBinType + " " + numBins + " "
            + all_concepts + " " + featureID + " " + thePruner + " " + width + " " + scoreFunction);
      } else {
        sanityCheck.put(conceptBinType + " " + numBins + " " + whichBin + " " + all_concepts + " "
            + featureID + " " + thePruner + " " + width + " " + scoreFunction, "1");
      }

      if (conceptBinType.equals("default")) {
        // concept importance in descending order
        int[] order_descending = new int[order.length];
        for (int i = 0; i < order_descending.length; i++) {
          order_descending[i] = order[order.length - i - 1];
        }

        int[] cascadeCliques = null;

        // if there are 5 bigram concepts, if there are 3 bins, the last bin will take concepts 3,
        // 4, 5
        if (numBins == whichBin && order_descending.length > numBins) {
          cascadeCliques = new int[order_descending.length - (int) numBins + 1];
          for (int j = whichBin - 1; j < order_descending.length; j++) { // 0-indexed
            cascadeCliques[j - whichBin + 1] = order_descending[j];
          }
        } else {
          cascadeCliques = new int[1];

          if ((whichBin - 1) < order_descending.length) {
            cascadeCliques[0] = order_descending[whichBin - 1];
          } else {
            return new int[0];
          }
        }

        // sort by clique numbers
        double[] cascadeCliques_sorted_by_clique_number = new double[cascadeCliques.length];
        int[] order1 = new int[cascadeCliques.length];
        for (int j = 0; j < order1.length; j++) {
          order1[j] = j;
          cascadeCliques_sorted_by_clique_number[j] = cascadeCliques[j];
        }
        ivory.smrf.model.constrained.ConstraintModel.Quicksort(
            cascadeCliques_sorted_by_clique_number, order1, 0, order1.length - 1);

        for (int j = 0; j < cascadeCliques_sorted_by_clique_number.length; j++) {
          cascadeCliques[j] = (int) cascadeCliques_sorted_by_clique_number[j];
        }
        return cascadeCliques;
      }

      else if (conceptBinType.equals("impact")) {

        double totalCliques = (double) (conceptWeights.length);
        double base = Math.pow((totalCliques + 1), (1 / numBins));

        double firstBinSize = base - 1;
        if (firstBinSize < 1) {
          firstBinSize = 1;
        }

        int start = 0;
        int end = (int) (Math.round(firstBinSize));
        double residual = firstBinSize - end;

        for (int i = 2; i <= whichBin; i++) {
          start = end;
          double v = firstBinSize * Math.pow(base, (i - 1));
          double v_plus_residual = v + residual;
          double v_round = Math.round(v_plus_residual);
          residual = v_plus_residual - v_round;
          end += (int) v_round;
        }

        if (start >= totalCliques) {
          return new int[0];
        }

        if (end > totalCliques) {
          end = (int) totalCliques;
        }

        int[] cascadeCliques = new int[end - start];

        // concept importance in descending order
        int[] order_descending = new int[order.length];
        for (int i = 0; i < order_descending.length; i++) {
          order_descending[i] = order[order.length - i - 1];
        }

        for (int i = start; i < end; i++) {
          cascadeCliques[i - start] = order_descending[i];
        }

        // sort by clique numbers
        double[] cascadeCliques_sorted_by_clique_number = new double[cascadeCliques.length];
        int[] order1 = new int[cascadeCliques.length];
        for (int j = 0; j < order1.length; j++) {
          cascadeCliques_sorted_by_clique_number[j] = cascadeCliques[j];
          order1[j] = j;
        }
        ivory.smrf.model.constrained.ConstraintModel.Quicksort(
            cascadeCliques_sorted_by_clique_number, order1, 0, order1.length - 1);

        for (int j = 0; j < cascadeCliques_sorted_by_clique_number.length; j++) {
          cascadeCliques[j] = (int) cascadeCliques_sorted_by_clique_number[j];
        }
        return cascadeCliques;
      }
    } else {
      throw new RetrievalException("Not yet supported " + conceptBinType);
    }

    return null;
  }
View Full Code Here

        Arrays.sort(conceptResults, new Accumulator.DocnoComparator());

        float score = 0.0f;
        for (int i = 0; i < conceptResults.length; i++) {
          if (fbResults[i].docno != conceptResults[i].docno) {
            throw new RetrievalException("Error: Mismatch occured in getExpandedMRF!");
          }
          score += Math.exp(fbResults[i].score + conceptResults[i].score);
        }

        int size = sortedConcepts.size();
View Full Code Here

    // Extract tf and doclen information from document vectors.
    TfDoclengthStatistics stats = null;
    try {
      stats = getTfDoclengthStatistics(docVecs);
    } catch (IOException e) {
      throw new RetrievalException(
          "Error: Unable to extract tf and doclen information from document vectors!");
    }

    VocabFrequencyPair[] vocab = stats.getVocab();
    Map<String, Short>[] tfs = stats.getTfs();
View Full Code Here

      float[] z_scores = new float[accumulated_scores.length];
      for (int i = 0; i < z_scores.length; i++) {
        z_scores[i] = (accumulated_scores[i] - avgScores) / stddev;
      }
    } else {
      throw new RetrievalException("PruningFunction " + pruner + " is not supported!");
    }

    if (retainSize < mK) {
      if (mDocSet.length >= mK) {
        retainSize = mK;
View Full Code Here

TOP

Related Classes of ivory.core.RetrievalException

Copyright © 2018 www.massapicom. 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.