Tokenizer { @SuppressWarnings("unchecked") ArrayList<Unit> predict(final Instance inst) { if ((trained == false) || (model == null)) throw new IllegalStateException( "No model available. Train or load trained model first."); final ArrayList<Unit> units = (ArrayList<Unit>) inst.getName(); if (units.size() > 0) { final Sequence<?> input = (Sequence<?>) inst.getData(); final Sequence<?> crfOutput = model.transduce(input); for (int j = 0; j < crfOutput.size(); j++) units.get(j).label = (String) crfOutput.get(j); } return units; } Tokenizer(); CRF getModel(); ArrayList<Unit> predict(final String sentence); void readModel(final File file); void readModel(InputStream is);  }
@Test public void testPredict() throws Exception { final Tokenizer tokenizer = new Tokenizer(); tokenizer.readModel(new File(FILENAME_MODEL)); final List<String> orgSentences = readLinesFromFile(FILENAME_ABSTRACT); final ArrayList<String> tokSentences = new ArrayList<String>(); for (int i = 0; i < orgSentences.size(); ++i) tokSentences.add(""); final InstanceList iList = tokenizer.makePredictionData(orgSentences, tokSentences); for (final Instance instance : iList) { final ArrayList<Unit> unitList = tokenizer.predict(instance); assertNotNull(unitList); for (final Unit unit : unitList) LOGGER.trace("unit=" + unit); } }