View Javadoc

1   /*
2    * @(#)$Id: SigerAlgorithm.java 824 2010-05-26 22:38:01Z bpuype $
3    *
4    * Author		:	Ueli Kurmann, igesture@uelikurmann.ch
5    *
6    * Purpose		: 	Implementation of the Siger algortithm.
7    *
8    * -----------------------------------------------------------------------
9    *
10   * Revision Information:
11   *
12   * Date				Who			Reason
13   *
14   * Dec 6, 2006		ukurmann	Initial Release
15   * Mar 16, 2007     bsigner     Cleanup
16   *
17   * -----------------------------------------------------------------------
18   *
19   * Copyright 1999-2009 ETH Zurich. All Rights Reserved.
20   *
21   * This software is the proprietary information of ETH Zurich.
22   * Use is subject to license terms.
23   * 
24   */
25  
26  
27  package org.ximtec.igesture.algorithm.siger;
28  
29  import java.util.ArrayList;
30  import java.util.HashMap;
31  import java.util.List;
32  
33  import org.sigtec.ink.Note;
34  import org.ximtec.igesture.algorithm.AlgorithmException;
35  import org.ximtec.igesture.algorithm.DefaultAlgorithm;
36  import org.ximtec.igesture.configuration.Configuration;
37  import org.ximtec.igesture.core.Gesture;
38  import org.ximtec.igesture.core.GestureClass;
39  import org.ximtec.igesture.core.GestureSample;
40  import org.ximtec.igesture.core.GestureSet;
41  import org.ximtec.igesture.core.Result;
42  import org.ximtec.igesture.core.ResultSet;
43  import org.ximtec.igesture.core.TextDescriptor;
44  import org.ximtec.igesture.util.Constant;
45  
46  
47  /**
48   * Implementation of the Siger algorithm.
49   * 
50   * @version 1.0 Dec 2006
51   * @author Ueli Kurmann, igesture@uelikurmann.ch
52   * @author Beat Signer, signer@inf.ethz.ch
53   */
54  public class SigerAlgorithm extends DefaultAlgorithm {
55  
56     private HashMap<ClassMatcher, GestureClass> gestures;
57  
58     private static String DEFAULT_MIN_DISTANCE = "5";
59     
60     public enum Config {
61        MIN_DISTANCE
62     }
63     
64     static{
65  	   /**
66  	    * Parameter Default Values
67  	    */
68  	   DEFAULT_CONFIGURATION.put(Config.MIN_DISTANCE.name(), DEFAULT_MIN_DISTANCE);
69     }
70  
71  
72     public SigerAlgorithm() {
73     }
74  
75  
76     public void init(Configuration configuration) throws AlgorithmException {
77        gestures = new HashMap<ClassMatcher, GestureClass>();
78        final GestureSet gestureSet = configuration.getGestureSet();
79        for (final GestureClass gestureClass : gestureSet.getGestureClasses()) {
80           final TextDescriptor descriptor = gestureClass
81                 .getDescriptor(TextDescriptor.class);
82           gestures.put(new ClassMatcher(descriptor.getText()), gestureClass);
83        }
84  
85     } // init
86  
87  
88     public Config[] getConfigParameters() {
89        return Config.values();
90     } // getConfigParameters
91  
92  
93     public ResultSet recognise(Gesture<?> gesture) {
94        ResultSet result = new ResultSet();
95  
96        if (gesture instanceof GestureSample) {
97           Note note = ((GestureSample)gesture).getGesture();
98  
99           StrokeInfo si = new StrokeInfo(note);
100          List<Result> resultList = new ArrayList<Result>();
101          result.setGesture(gesture);
102 
103          for (final ClassMatcher regex : gestures.keySet()) {
104             if (regex.isMatch(si)) {
105                resultList.add(new Result(gestures.get(regex), 1));
106             }
107          }
108 
109          for (final Result r : resultList) {
110             r.setAccuracy((double)1 / resultList.size());
111             result.addResult(r);
112          }
113       }
114 
115       return result;
116    } // recognise
117 
118 	@Override
119 	public int getType() {
120 		return Constant.TYPE_2D;
121 	}
122 
123 }