读取样本

根据词性读取样本文件中的样本

@param pos
词性
@return 样本集
@throws Exception
176196
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;
	}
234028
public int read(long pos) {
    if (pos >= size) {
      return -1;
    }

    byte[] block = blocks[blockIndex(pos)];
    int off = offsetInBlock(pos);
    return UnsignedBytes.toInt(block[off]);
  }
1238409
private String parseExemplarLocation(String text, ParsePosition pos) {
        int startIdx = pos.getIndex();
        int parsedPos = -1;
        String tzID = null;

        EnumSet<NameType> nameTypes = EnumSet.of(NameType.EXEMPLAR_LOCATION);
        Collection<MatchInfo> exemplarMatches = _tznames.find(text, startIdx, nameTypes);
        if (exemplarMatches != null) {
            MatchInfo exemplarMatch = null;
            for (MatchInfo match : exemplarMatches) {
                if (startIdx + match.matchLength() > parsedPos) {
                    exemplarMatch = match;
                    parsedPos = startIdx + match.matchLength();
                }
            }
            if (exemplarMatch != null) {
                tzID = getTimeZoneID(exemplarMatch.tzID(), exemplarMatch.mzID());
                pos.setIndex(parsedPos);
            }
        }
        if (tzID == null) {
            pos.setErrorIndex(startIdx);
        }

        return tzID;
    }
197019
@Override
  public int positionedRead(long pos, byte[] b, int off, int len) throws IOException {
    return positionedReadInternal(pos, b, off, len);
  }
227955
def _get_at_pos(self, pos):
        """"""

        if pos < 0:
            # line 0 is the start of the file, no more above
            return None, None

        if len(self.lines) > pos:
            # we have that line so return it
            return self.lines[pos], pos

        if self.file is None:
            # file is closed, so there are no more lines
            return None, None

        assert pos == len(self.lines), "out of order request?"

        self.read_next_line()

        return self.lines[-1], pos
1265808
public InputGate<? extends IOReadableWritable> getInputGate(final int pos) {
		if (pos < this.inputGates.size()) {
			return this.inputGates.get(pos);
		}

		return null;
	}
791054
public final long getBeUlong40(final int pos) {
        final int position = origin + pos;

        if (pos + 4 >= limit || pos < 0) throw new IllegalArgumentException("limit excceed: "
                                                                            + (pos < 0 ? pos : (pos + 4)));

        byte[] buf = buffer;
        return ((long) (0xff & buf[position + 4])) | ((long) (0xff & buf[position + 3]) << 8)
               | ((long) (0xff & buf[position + 2]) << 16) | ((long) (0xff & buf[position + 1]) << 24)
               | ((long) (0xff & buf[position]) << 32);
    }
916843
public List<String> parse(String[] args, int pos) {
    List<String> parameters = new ArrayList<String>();
    for(; pos < args.length; pos++) {
      if (args[pos].charAt(0) == '-' && args[pos].length() > 1) {
        String opt = args[pos].substring(1);
        if (options.containsKey(opt))
          options.put(opt, Boolean.TRUE);
        else {
          try {
            Long.parseLong(args[pos]);
            parameters.add(args[pos]);
          } catch (NumberFormatException e) {
            throw new IllegalArgumentException("Illegal option " + args[pos]);
          }
        }
      }
      else
        parameters.add(args[pos]);
    }
    int psize = parameters.size();
    if (psize < minPar || psize > maxPar)
      throw new IllegalArgumentException("Illegal number of arguments");
    return parameters;
  }
298358
private void seekNonWs(final String pattern, final ParsePosition pos) {
        int len = 0;
        final char[] buffer = pattern.toCharArray();
        do {
            len = StrMatcher.splitMatcher().isMatch(buffer, pos.getIndex());
            pos.setIndex(pos.getIndex() + len);
        } while (len > 0 && pos.getIndex() < pattern.length());
    }
996058
@Override
  public synchronized long getPos() throws IOException {
    long pos = channel.position();
    logger.atFine().log("getPos: %d", pos);
    return pos;
  }
1369184
public Object parseObject(String source, ParsePosition pos) {
        pos.setIndex(0);
        pos.setErrorIndex(0);
        return null;
    }
1131438
public final String getFixString(final int pos, final int len, String charsetName) {
        if (pos + len > limit || pos < 0) throw new IllegalArgumentException("limit excceed: "
                                                                             + (pos < 0 ? pos : (pos + len)));

        final int from = origin + pos;
        final int end = from + len;
        byte[] buf = buffer;
        int found = from;
        for (; (found < end) && buf[found] != '\0'; found++)
            /* empty loop */;

        try {
            return new String(buf, from, found - from, charsetName);
        } catch (UnsupportedEncodingException e) {
            throw new IllegalArgumentException("Unsupported encoding: " + charsetName, e);
        }
    }
1077479
public final short readTTFShort(long pos) throws IOException {
        final long cp = getCurrentPos();
        seekSet(pos);
        final short ret = readTTFShort();
        seekSet(cp);
        return ret;
    }
672444
public final long getUlong40(final int pos) {
        final int position = origin + pos;

        if (pos + 4 >= limit || pos < 0) throw new IllegalArgumentException("limit excceed: "
                                                                            + (pos < 0 ? pos : (pos + 4)));

        byte[] buf = buffer;
        return ((long) (0xff & buf[position])) | ((long) (0xff & buf[position + 1]) << 8)
               | ((long) (0xff & buf[position + 2]) << 16) | ((long) (0xff & buf[position + 3]) << 24)
               | ((long) (0xff & buf[position + 4]) << 32);
    }
1162088
public long seek(long pos) throws IOException {
    FileChannel fc = fos.getChannel();
    fc.position(pos);
    return pos;
  }
279258
public void rawWarning(int pos, String msg) {
        PrintWriter warnWriter = writers.get(WriterKind.ERROR);
        if (nwarnings < MaxWarnings && emitWarnings) {
            printRawDiag(warnWriter, "warning: ", pos, msg);
        }
        prompt();
        nwarnings++;
        warnWriter.flush();
    }
117535
public int setString(long pos, String str) throws SQLException {
    int bytePosition = utf8Position((int) pos - 1);
    super.setBytes(bytePosition + 1 - offset, str.getBytes(StandardCharsets.UTF_8));
    return str.length();
  }