Last active
December 11, 2015 01:19
-
-
Save AruniRC/4522824 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.io.BufferedReader; | |
import java.io.File; | |
import java.io.FileInputStream; | |
import java.io.IOException; | |
import java.io.InputStreamReader; | |
import java.io.ObjectInputStream; | |
import java.util.ArrayList; | |
import java.util.Collections; | |
import java.util.HashMap; | |
/** | |
* This class matches stroke recognition results to character | |
* Assumes existence of "LUTforward.dat" and "LUTback.dat" files in project directory | |
* TODO - Edit-distance for user-corrections | |
* @author aruni | |
* | |
*/ | |
public class LUTRead { | |
public static void main(String[] args) throws IOException, ClassNotFoundException | |
{ | |
//Reading in the LUT from file to HashMap | |
ObjectInputStream oin = new ObjectInputStream(new FileInputStream(new File("LUTforward.dat"))); | |
HashMap<String,String> LUTforward = (HashMap<String, String>) oin.readObject(); | |
System.out.println(LUTforward); | |
//Creating object with LUT for character recognition | |
CharLUT Lut = new CharLUT(LUTforward); | |
//ArrayList to store the recognised strokes | |
ArrayList<String> stroke_str = new ArrayList<String>(); | |
/* | |
* Simulating the stroke recognition portion as user input from console | |
*/ | |
System.out.println("Enter stroke sequence. Enter -1 to exit."); | |
BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); | |
String read=br.readLine(); | |
while(!read.equals("-1")) | |
{ | |
stroke_str.add(read); | |
read=br.readLine(); | |
} | |
String char_class = Lut.getValue(stroke_str); | |
System.out.println("Character class: "+ char_class + " for strokes: " + stroke_str.toString()); | |
oin.close(); | |
} | |
} | |
class CharLUT | |
{ | |
HashMap<String,String> LUTforward; | |
String strokeSeq; | |
String charClass; | |
String correctedCharClass; | |
String correctedStrokeSeq; | |
/** | |
* public constructor of class CharLUT | |
* @param HashMap<String,String> LUTfwd | |
*/ | |
public CharLUT(HashMap<String,String> LUTfwd) | |
{ | |
LUTforward = LUTfwd; | |
} | |
/** | |
* Overloaded function | |
* @param ArrayList<String> stroke_seq | |
* @return String character class | |
*/ | |
public String getValue(ArrayList<String> stroke_seq) | |
{ | |
Collections.sort(stroke_seq); | |
String arr = (String) stroke_seq.toString(); | |
String key_string = arr.replaceAll("(^\\[|\\]$)", "").replace(", ", " "); | |
strokeSeq = key_string; | |
charClass = LUTforward.get(key_string); | |
return charClass; | |
} | |
/** | |
* Overloaded function | |
* @param String stroke_seq | |
* @return String character class | |
*/ | |
public String getValue(String stroke_seq) | |
{ | |
strokeSeq = stroke_seq; | |
charClass = LUTforward.get(stroke_seq); | |
return charClass; | |
} | |
/** | |
* @param String correctCharClass from user's correction | |
* @return String character class | |
*/ | |
public void setCorrectCharClass(String correctClass) | |
{ | |
correctedCharClass = correctClass; | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment