Examples of LabelAlphabet


Examples of org.fnlp.ml.types.alphabet.LabelAlphabet

   */
  private InstanceSet readInstanceSet(String pos) throws IOException {

    InstanceSet instset = new InstanceSet();

    LabelAlphabet labelAlphabet = factory.buildLabelAlphabet(pos);

    BufferedReader in = new BufferedReader(new InputStreamReader(
        new FileInputStream(fp), charset));

    String line = null;
    while ((line = in.readLine()) != null) {
      line = line.trim();
      if (line.matches("^$"))
        continue;
      if (line.startsWith(pos + " ")) {
        List<String> tokens = Arrays.asList(line.split("\\s+"));

        int[] data = new int[tokens.size() - 2];
        for (int i = 0; i < data.length; i++) {
          data[i] = Integer.parseInt(tokens.get(i + 2));
        }
        Instance inst = new Instance(data);
        inst.setTarget(labelAlphabet.lookupIndex(tokens.get(1)));

        instset.add(inst);
      }
    }

    in.close();

    labelAlphabet.setStopIncrement(true);
    instset.setAlphabetFactory(factory);

    return instset;
  }
View Full Code Here
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.