Esempio n. 1
0
 public boolean load(ByteArray byteArray, V[] value) {
   if (byteArray == null) return false;
   size = byteArray.nextInt();
   base = new int[size + 65535]; // 多留一些,防止越界
   check = new int[size + 65535];
   for (int i = 0; i < size; i++) {
     base[i] = byteArray.nextInt();
     check[i] = byteArray.nextInt();
   }
   v = value;
   return true;
 }
Esempio n. 2
0
    /**
     * 从字节流中加载
     *
     * @param byteArray
     * @param natureIndexArray
     * @return
     */
    public static Attribute create(ByteArray byteArray, Nature[] natureIndexArray) {
      int currentTotalFrequency = byteArray.nextInt();
      int length = byteArray.nextInt();
      Attribute attribute = new Attribute(length);
      attribute.totalFrequency = currentTotalFrequency;
      for (int j = 0; j < length; ++j) {
        attribute.nature[j] = natureIndexArray[byteArray.nextInt()];
        attribute.frequency[j] = byteArray.nextInt();
      }

      return attribute;
    }
Esempio n. 3
0
 /**
  * 从磁盘加载双数组
  *
  * @param path
  * @return
  */
 static boolean loadDat(String path) {
   try {
     ByteArray byteArray = ByteArray.createByteArray(path + Predefine.BIN_EXT);
     if (byteArray == null) return false;
     int size = byteArray.nextInt();
     CoreDictionary.Attribute[] attributes = new CoreDictionary.Attribute[size];
     final Nature[] natureIndexArray = Nature.values();
     for (int i = 0; i < size; ++i) {
       // 第一个是全部频次,第二个是词性个数
       int currentTotalFrequency = byteArray.nextInt();
       int length = byteArray.nextInt();
       attributes[i] = new CoreDictionary.Attribute(length);
       attributes[i].totalFrequency = currentTotalFrequency;
       for (int j = 0; j < length; ++j) {
         attributes[i].nature[j] = natureIndexArray[byteArray.nextInt()];
         attributes[i].frequency[j] = byteArray.nextInt();
       }
     }
     if (!trie.load(byteArray, attributes) || byteArray.hasMore()) return false;
   } catch (Exception e) {
     logger.warning("读取失败,问题发生在" + e);
     return false;
   }
   return true;
 }
Esempio n. 4
0
 @Override
 public boolean load(ByteArray byteArray) {
   int length = byteArray.nextInt();
   for (int i = 0; i < length; ++i) {
     charTreeSet.add(byteArray.nextChar());
   }
   simplifiedSourceNode = new SimpleMDAGNode();
   simplifiedSourceNode.load(byteArray);
   length = byteArray.nextInt();
   mdagDataArray = new SimpleMDAGNode[length];
   for (int i = 0; i < length; ++i) {
     mdagDataArray[i] = new SimpleMDAGNode();
     mdagDataArray[i].load(byteArray);
   }
   sourceNode = null;
   return true;
 }
Esempio n. 5
0
 /**
  * 从字节流快速加载
  *
  * @param byteArray
  * @return
  */
 public static MaxEntModel create(ByteArray byteArray) {
   MaxEntModel m = new MaxEntModel();
   m.correctionConstant = byteArray.nextInt(); // correctionConstant
   m.correctionParam = byteArray.nextDouble(); // getCorrectionParameter
   // label
   int numOutcomes = byteArray.nextInt();
   String[] outcomeLabels = new String[numOutcomes];
   m.outcomeNames = outcomeLabels;
   for (int i = 0; i < numOutcomes; i++) outcomeLabels[i] = byteArray.nextString();
   // pattern
   int numOCTypes = byteArray.nextInt();
   int[][] outcomePatterns = new int[numOCTypes][];
   for (int i = 0; i < numOCTypes; i++) {
     int length = byteArray.nextInt();
     int[] infoInts = new int[length];
     for (int j = 0; j < length; j++) {
       infoInts[j] = byteArray.nextInt();
     }
     outcomePatterns[i] = infoInts;
   }
   // feature
   int NUM_PREDS = byteArray.nextInt();
   String[] predLabels = new String[NUM_PREDS];
   m.pmap = new DoubleArrayTrie<Integer>();
   for (int i = 0; i < NUM_PREDS; i++) {
     predLabels[i] = byteArray.nextString();
   }
   Integer[] v = new Integer[NUM_PREDS];
   for (int i = 0; i < v.length; i++) {
     v[i] = byteArray.nextInt();
   }
   m.pmap.load(byteArray, v);
   // params
   Context[] params = new Context[NUM_PREDS];
   int pid = 0;
   for (int i = 0; i < outcomePatterns.length; i++) {
     int[] outcomePattern = new int[outcomePatterns[i].length - 1];
     for (int k = 1; k < outcomePatterns[i].length; k++) {
       outcomePattern[k - 1] = outcomePatterns[i][k];
     }
     for (int j = 0; j < outcomePatterns[i][0]; j++) {
       double[] contextParameters = new double[outcomePatterns[i].length - 1];
       for (int k = 1; k < outcomePatterns[i].length; k++) {
         contextParameters[k - 1] = byteArray.nextDouble();
       }
       params[pid] = new Context(outcomePattern, contextParameters);
       pid++;
     }
   }
   // prior
   m.prior = new UniformPrior();
   m.prior.setLabels(outcomeLabels);
   // eval
   m.evalParams =
       new EvalParameters(params, m.correctionParam, m.correctionConstant, outcomeLabels.length);
   return m;
 }