CRF/0000775000176000017600000000000010421533400012104 5ustar abhishekaabhishekaCRF/src/0000775000176000017600000000000010421454646012711 5ustar abhishekaabhishekaCRF/src/iitb/0000775000176000017600000000000010421533310013622 5ustar abhishekaabhishekaCRF/src/iitb/Utils/0000775000176000017600000000000010421454646014740 5ustar abhishekaabhishekaCRF/src/iitb/Utils/Counters.java0000644000176000017600000000351310421544046017377 0ustar abhishekaabhishekapackage iitb.Utils; import java.util.BitSet; public class Counters { int cnts[] = null; int maxVals[] = null; BitSet fixedVals; public Counters(int numCtrs, int maxVal) { this(numCtrs, new int[numCtrs]); for (int i = 0; i < maxVals.length; maxVals[i++] = maxVal); } public Counters(int numCtrs, int maxVals[]) { cnts = new int[numCtrs]; fixedVals = new BitSet(numCtrs+1); this.maxVals = maxVals; } public void fix(int index, int val) {cnts[index ] =val; fixedVals.set(index);} public void clear() { for (int i = 0; i < cnts.length; cnts[i++] = 0); fixedVals.clear(); } public void init(int maxVal[]) { clear(); for (int i = 0; i < maxVals.length; maxVals[i] = maxVal[i],i++) { if (maxVal[i]==0) cnts[cnts.length-1]=maxVal[cnts.length-1]; } } public void init(int maxVal) { clear(); for (int i = 0; i < maxVals.length; maxVals[i] = maxVal,i++); } int nextNonFixed(int i) {return fixedVals.nextClearBit(i);} public boolean isFixed(int index) {return fixedVals.get(index);} public boolean advance() { for (int i = 0; (i < cnts.length); i++) { i = nextNonFixed(i); if (i < cnts.length) { cnts[i]++; if (cnts[i] < maxVals[i]) return true; else if (i < cnts.length-1) cnts[i] = 0; } } return false; } public boolean done() {return (cnts[cnts.length-1] >= maxVals[cnts.length-1]);} public int get(int index) {return cnts[index];} public int value(int endIndex, int startIndex) { int val = 0; for (int i = endIndex; i >= startIndex; i--) { val = (val*maxVals[i] + cnts[i]); } return val; } public int value() {return value(cnts.length-1,0);} public void arrayCopy(int endIndex, int startIndex, int arr[]) { for (int i = endIndex; i >= startIndex; i--) { arr[i-startIndex] = cnts[i]; } } }; CRF/src/iitb/Utils/Utils.java0000644000176000017600000000056110421454646016703 0ustar abhishekaabhisheka/* * Created on Dec 6, 2004 * */ package iitb.Utils; /** * @author Administrator * */ public class Utils { public static int log2Ceil(int numArg) { int log2 = 0; int num = numArg; for (; num > 0; log2++) { num = (num >> 1); } if ((1 << (log2-1)) == numArg) log2--; return log2; } } CRF/src/iitb/Utils/Options.java0000644000176000017600000001563610421544053017237 0ustar abhishekaabhishekapackage iitb.Utils; import java.io.FileInputStream; import java.io.IOException; import java.io.PrintStream; import java.util.Comparator; import java.util.Enumeration; import java.util.Iterator; import java.util.Properties; import java.util.SortedSet; import java.util.TreeSet; /* * ==================================================================== * Copyright (c) 1995-1999 Purple Technology, Inc. All rights * reserved. * * PLAIN LANGUAGE LICENSE: Do whatever you like with this code, free * of charge, just give credit where credit is due. If you improve it, * please send your improvements to server@purpletech.com. Check * http://www.purpletech.com/server/ for the latest version and news. * * LEGAL LANGUAGE LICENSE: Redistribution and use in source and binary * forms, with or without modification, are permitted provided that * the following conditions are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above * copyright notice, this list of conditions and the following * disclaimer in the documentation and/or other materials provided * with the distribution. * * 3. The names of the authors and the names "Purple Technology," * "Purple Server" and "Purple Chat" must not be used to endorse or * promote products derived from this software without prior written * permission. For written permission, please contact * server@purpletech.com. * * THIS SOFTWARE IS PROVIDED BY THE AUTHORS AND PURPLE TECHNOLOGY ``AS * IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE * AUTHORS OR PURPLE TECHNOLOGY BE LIABLE FOR ANY DIRECT, INDIRECT, * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED * OF THE POSSIBILITY OF SUCH DAMAGE. * * ==================================================================== * **/ /** * Parses command-line options. *
 * Command-line usage: java Options [properties.txt] -param [val] ...
 *   properties.txt - optional file in Properties format
 *   param - property name
 *   val - value for that property (set to null if not present)
 * 
* @author Alex * @version VERSIONDATA */ public class Options extends java.util.Properties { public static Options parse(String[] args) { Options o = new Options(args); return o; } ////////// /** @serial **/ protected String[] args; public boolean appendValues = false; public Options(Properties defaults, String[] args) { super(defaults); this.args = args; parse(); } public Options(String[][] defaults, String[] args) { Properties def = new Properties(); for (int i=0; i" + valueNew); } public void add(int startIndex, String args[]) { this.args = args; parse(startIndex); } public void print(PrintStream out) { String key; String val; // SortedSet set = new TreeSet(); // JDK 1.2 // JDK 1.1 compatible SortedSet set = new TreeSet( new Comparator() { public int compare(Object a, Object b) { return ((String)a).compareTo((String) b); } } ); Enumeration e = propertyNames(); while (e.hasMoreElements()) { Object o = e.nextElement(); set.add(o); } Iterator i = set.iterator(); while (i.hasNext()) { key = (String)i.next(); val = (String)getProperty(key); out.println(key + " = " + val); } } public String getString(String key) { return (String)getProperty(key); } public int getIntLoose(String key) { try { return Integer.parseInt( (String)getProperty(key) ); } catch (Exception e) { return 0; } } public double getDoubleLoose(String key) { try { return new Double((String)getProperty(key)).doubleValue(); } catch (Exception e) { return 0; } } public int getInt(String key) throws ConfigException { try { if (getProperty(key) == null) return 0; return Integer.parseInt( (String)getProperty(key) ); } catch (Exception e) { throw new ConfigException(key + " cannot parse to integer "); } } public double getDouble(String key) throws ConfigException { try { return new Double((String)getProperty(key)).doubleValue(); } catch (Exception e) { throw new ConfigException(key + " cannot parse to double "); } } public String getMandatoryProperty(final String name) throws ConfigException { String ans = getProperty(name); if ( ans == null ) throw new ConfigException(name + " not defined in config"); return ans; } /** * The main method for running this class as a standalone application * @param args The argument list sent to the program. */ public static void main(String args[]) { Options.parse(args).list(System.out); } } CRF/src/iitb/Utils/ConfigException.java0000644000176000017600000000025710421454646020671 0ustar abhishekaabhishekapackage iitb.Utils; /** * * @author Sunita Sarawagi * */ public class ConfigException extends Exception { public ConfigException(String msg) { super(msg); } }; CRF/src/iitb/CRF/0000775000176000017600000000000010421454647014253 5ustar abhishekaabhishekaCRF/src/iitb/CRF/package.html0000644000176000017600000000323010421454646016527 0ustar abhishekaabhisheka Provides an implementation of Conditional Random Fields (CRF) for use in sequential classification tasks. This package can be used independent of the other packages in this distribution.

This implementation of CRF is as described in the following two papers.