private void SegmentTrainSetStrokes() { SystemSettings.CurrentRecognizierOperation = this.RECGONIZE_OPERATION_TRAIN; CaptureStrokes = true; ExmapleType = EXAMPLE_POS; if (TrainSetStrokes != null) { Interactive = false; int count = 0; int catCount = 0; for (Iterator iterator = TrainSetStrokes.types(); iterator.hasNext(); ) { String type = (String) iterator.next(); logger.info(" segmeting the type " + type); CurrentCategory = type; CurrentCat = getCategoryide(type); ArrayList<ArrayList<Stroke>> catArray = TrainSetStrokes.getExamples(CurrentCategory); count = 0; catCount = 0; for (int i = 0; i < catArray.size(); i++) { Stroke stroke = null; // catCount++; // if (catCount>20){ // break; // } // if (count % 50 == 0) { logger.info(" Example number " + count); logger.info(" example count in strokes trains set is " + trainSet.getExamplesCount()); } count++; ArrayList<Stroke> strokeArray = catArray.get(i); for (int j = 0; j < strokeArray.size(); j++) { stroke = strokeArray.get(j); // for strokes do NewStrokeEvent newStroke = new NewStrokeEvent(this); newStroke.setEventStroke(stroke); newStroke.setFlagConsumed(false); HandleNewStroke(newStroke); } // /// after stroke do the follwoing createClusterFromStrokes(); } } } }
public void ReadTrainingSetXML(String filename) { logger.info("Reading the xml data "); xmlRead = true; TrainSetStrokes.readXML(filename); Categories = new Hashtable<Integer, String>(); Iterator<String> iterator = TrainSetStrokes.types(); int i = 0; for (; iterator.hasNext(); ) { String cat = iterator.next(); Categories.put(i, cat); i++; } // Categories.put(i, ) }
/* (non-Javadoc) * @see SketchMaster.system.Recogniziers.RecognizierSystem#deleteCategory(java.lang.String) */ @Override public void deleteCategory(String Name) { // check if exist if (Categories.containsValue(Name)) { Set<Entry<Integer, String>> collection = Categories.entrySet(); for (Iterator iter = collection.iterator(); iter.hasNext(); ) { Entry element = (Entry) iter.next(); if (element.getValue().equals(Name)) { iter.remove(); break; } } // now remove all entries of this category from the train set. trainSet.removeType(Name); if (Interactive) TrainSetStrokes.removeType(Name); return; } trained = false; }
/* (non-Javadoc) * @see SketchMaster.system.Recogniziers.RecognizierSystem#addCategoryExample(int, java.lang.Object) */ @Override public void addCategoryExample(int i, Object ink) { String temp; if (Categories.contains(i)) temp = Categories.get(i); else temp = CurrentCategory; // (InkInterface) // logger.info("addint the exmaple of "+i+" "+CurrentCategory); if (ink instanceof SegmentCluster) { // logger.info("addding ............"+ink); SegmentCluster segment = (SegmentCluster) ink; SegmentClusterFeatureSet example = new SegmentClusterFeatureSet(); example.setSegmentCluster(segment); example.initAll(); SVMFeatureSet feats = example.computeSVMFeatures(); trainSet.addPositiveExample(temp, feats); if (Interactive) TrainSetStrokes.addPositiveExample(temp, segment.getStrokeInSymbol()); // logger.info(" SVM adding example "+temp); // segment. trained = false; } }
private void addCategoryNegativeExample(int i, SegmentCluster ink) { String currentCategory; if (Categories.contains(i)) currentCategory = Categories.get(i); else currentCategory = CurrentCategory; // (InkInterface) // if (ink instanceof SegmentCluster) { SegmentCluster segment = (SegmentCluster) ink; SegmentClusterFeatureSet example = new SegmentClusterFeatureSet(); example.setSegmentCluster(segment); example.initAll(); SVMFeatureSet feats = example.computeSVMFeatures(); String temp; for (int j = 0; j < Categories.size(); j++) { temp = Categories.get(j); if (!temp.equals(currentCategory)) trainSet.addNegativeExample(temp, feats); if (Interactive) TrainSetStrokes.addNegativeExample(temp, ink.getStrokeInSymbol()); } logger.info(" SVM adding -ve example for " + currentCategory); // segment. trained = false; // } }
public void SaveTrainingSetXML(String filename) { TrainSetStrokes.saveXML(filename); }