Permalink
Browse files

Updated for changes in maxent package in which PerlHelp was moved to …

…OpenNLP and the BasicEventStream and BasicContextGenerator classes were made available.
  • Loading branch information...
1 parent e9c83db commit 20e32f112dbff4c7a8e1d75f4a362c0706eb2c53 jasonbaldridge committed Nov 20, 2001
@@ -25,7 +25,7 @@
* from the data.
*
* @author Chieu Hai Leong and Jason Baldridge
- * @version $Revision: 1.2 $, $Date: 2001/11/16 10:38:21 $
+ * @version $Revision: 1.3 $, $Date: 2001/11/20 17:07:16 $
*/
public class CreateModel {
@@ -50,8 +50,8 @@ public static void main (String[] args) {
+ "Model.txt";
try {
FileReader datafr = new FileReader(new File(dataFileName));
- EventCollector ec = new MyEventCollector(datafr);
- EventStream es = new EventCollectorAsStream(ec);
+ EventStream es =
+ new BasicEventStream(new PlainTextByLineDataStream(datafr));
GIS.SMOOTHING = USE_SMOOTHING;
GIS.SMOOTHING_OBSERVATION = SMOOTHING_OBSERVATION;
GISModel model = GIS.trainModel(es);
@@ -1,45 +0,0 @@
-///////////////////////////////////////////////////////////////////////////////
-// Copyright (C) 2001 Chieu Hai Leong and Jason Baldridge
-//
-// This library is free software; you can redistribute it and/or
-// modify it under the terms of the GNU Lesser General Public
-// License as published by the Free Software Foundation; either
-// version 2.1 of the License, or (at your option) any later version.
-//
-// This library is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-// GNU Lesser General Public License for more details.
-//
-// You should have received a copy of the GNU Lesser General Public
-// License along with this program; if not, write to the Free Software
-// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
-//////////////////////////////////////////////////////////////////////////////
-
-import opennlp.maxent.*;
-import gnu.regexp.*;
-import java.util.*;
-
-/**
- * Implements opennlp.maxent.ContextGenerator for the Weather sample.
- * Assumes a comma separated list of contextual predicates.
- *
- * @author Chieu Hai Leong and Jason Baldridge
- * @version $Revision: 1.1 $, $Date: 2001/11/15 13:03:41 $
- */
-public class MyContextGenerator implements ContextGenerator {
-
- public String[] getContext(Object o) {
-
- List collectFeats = new ArrayList();
- String[] toks = PerlHelp.split((String)o, ",");
-
- for(int i=0; i<toks.length; i++)
- collectFeats.add(toks[i]);
-
- String[] context= new String[collectFeats.size()];
- collectFeats.toArray(context);
- return context;
- }
-
-}
@@ -1,71 +0,0 @@
-///////////////////////////////////////////////////////////////////////////////
-// Copyright (C) 2001 Chieu Hai Leong and Jason Baldridge
-//
-// This library is free software; you can redistribute it and/or
-// modify it under the terms of the GNU Lesser General Public
-// License as published by the Free Software Foundation; either
-// version 2.1 of the License, or (at your option) any later version.
-//
-// This library is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-// GNU Lesser General Public License for more details.
-//
-// You should have received a copy of the GNU Lesser General Public
-// License along with this program; if not, write to the Free Software
-// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
-//////////////////////////////////////////////////////////////////////////////
-
-import opennlp.maxent.*;
-import java.io.*;
-import java.util.*;
-
-/**
- * Implements opennlp.maxent.EventCollector for the Weather sample.
- * Assumes a comma separated list containing all the features,
- * with the last item being the outcome, e.g.:
- * <p>
- * feature_1, feature_2, ... feature_n, outcome
- *
- * @author Chieu Hai Leong and Jason Baldridge
- * @version $Revision: 1.1 $, $Date: 2001/11/15 13:03:41 $
- */
-public class MyEventCollector implements EventCollector {
-
- private ContextGenerator _cg = new MyContextGenerator();
- private List _eventList;
-
- public MyEventCollector (Reader datafr) {
- _eventList = new ArrayList();
- try {
- BufferedReader br = new BufferedReader( datafr );
- String s = br.readLine();
-
- while (s != null) {
- int lastComma = s.lastIndexOf(',');
- String oc = s.substring(lastComma+1);
- String[] context =
- _cg.getContext(s.substring(0, lastComma));
- _eventList.add(new Event(oc, context));
- s = br.readLine();
- }
-
- br.close();
-
- } catch( Exception e ) {
- e.printStackTrace();
- }
-
- }
-
- public Event[] getEvents () {
- return getEvents(false);
- }
-
- public Event[] getEvents (boolean evalMode) {
- Event[] events = new Event[_eventList.size()];
- _eventList.toArray(events);
- return events ;
- }
-
-}
@@ -24,11 +24,11 @@
* Test the model on some input.
*
* @author Jason Baldridge
- * @version $Revision: 1.1 $, $Date: 2001/11/15 13:03:41 $
+ * @version $Revision: 1.2 $, $Date: 2001/11/20 17:07:17 $
*/
public class Predict {
MaxentModel _model;
- ContextGenerator _cg = new MyContextGenerator();
+ ContextGenerator _cg = new BasicContextGenerator();
public Predict (MaxentModel m) {
_model = m;
@@ -73,7 +73,7 @@ public static void main(String[] args) {
}
if (dataFileName.equals("")) {
- predictor.eval("Rainy,Happy,Humid");
+ predictor.eval("Rainy Happy Humid");
predictor.eval("Rainy");
predictor.eval("Blarmey");
}
@@ -85,7 +85,7 @@ public static void main(String[] args) {
while (ds.hasNext()) {
String s = (String)ds.nextToken();
- predictor.eval(s.substring(0, s.lastIndexOf(',')));
+ predictor.eval(s.substring(0, s.lastIndexOf(' ')));
}
return;
}
@@ -1,14 +1,14 @@
-home=man_united,Beckham=false,Scholes=true,Neville=true,Henry=true,Kanu=true,Parlour=false,Ferguson=confident,Wengler=tense,arsenal_lost_previous,man_united_won_previous,arsenal
-home=man_united,Beckham=true,Scholes=false,Neville=true,Henry=false,Kanu=true,Parlour=false,Ferguson=tense,Wengler=confident,arsenal_won_previous,man_united_lost_previous,man_united
-home=man_united,Beckham=false,Scholes=true,Neville=true,Henry=true,Kanu=true,Parlour=false,Ferguson=tense,Wengler=tense,arsenal_lost_previous,man_united_won_previous,tie
-home=man_united,Beckham=true,Scholes=true,Neville=false,Henry=true,Kanu=false,Parlour=false,Ferguson=confident,Wengler=confident,arsenal_won_previous,man_united_won_previous,tie
-home=man_united,Beckham=false,Scholes=true,Neville=true,Henry=true,Kanu=true,Parlour=false,Ferguson=confident,Wengler=tense,arsenal_won_previous,man_united_won_previous,arsenal
-home=man_united,Beckham=false,Scholes=true,Neville=true,Henry=false,Kanu=true,Parlour=false,Ferguson=confident,Wengler=confident,arsenal_won_previous,man_united_won_previous,man_united
-home=man_united,Beckham=true,Scholes=true,Neville=false,Henry=true,Kanu=true,Parlour=false,Ferguson=confident,Wengler=tense,arsenal_won_previous,man_united_won_previous,man_united
-home=arsenal,Beckham=false,Scholes=true,Neville=true,Henry=true,Kanu=true,Parlour=false,Ferguson=confident,Wengler=tense,arsenal_lost_previous,man_united_won_previous,arsenal
-home=arsenal,Beckham=true,Scholes=false,Neville=true,Henry=false,Kanu=true,Parlour=false,Ferguson=tense,Wengler=confident,arsenal_won_previous,man_united_lost_previous,arsenal
-home=arsenal,Beckham=false,Scholes=true,Neville=true,Henry=true,Kanu=true,Parlour=false,Ferguson=tense,Wengler=tense,arsenal_lost_previous,man_united_won_previous,tie
-home=arsenal,Beckham=true,Scholes=true,Neville=false,Henry=true,Kanu=false,Parlour=false,Ferguson=confident,Wengler=confident,arsenal_won_previous,man_united_won_previous,man_united
-home=arsenal,Beckham=false,Scholes=true,Neville=true,Henry=true,Kanu=true,Parlour=false,Ferguson=confident,Wengler=tense,arsenal_won_previous,man_united_won_previous,arsenal
-home=arsenal,Beckham=false,Scholes=true,Neville=true,Henry=false,Kanu=true,Parlour=false,Ferguson=confident,Wengler=confident,arsenal_won_previous,man_united_won_previous,man_united
-home=arsenal,Beckham=true,Scholes=true,Neville=false,Henry=true,Kanu=true,Parlour=false,Ferguson=confident,Wengler=tense,arsenal_won_previous,man_united_won_previous,arsenal
+home=man_united Beckham=false Scholes=true Neville=true Henry=true Kanu=true Parlour=false Ferguson=confident Wengler=tense arsenal_lost_previous man_united_won_previous arsenal
+home=man_united Beckham=true Scholes=false Neville=true Henry=false Kanu=true Parlour=false Ferguson=tense Wengler=confident arsenal_won_previous man_united_lost_previous man_united
+home=man_united Beckham=false Scholes=true Neville=true Henry=true Kanu=true Parlour=false Ferguson=tense Wengler=tense arsenal_lost_previous man_united_won_previous tie
+home=man_united Beckham=true Scholes=true Neville=false Henry=true Kanu=false Parlour=false Ferguson=confident Wengler=confident arsenal_won_previous man_united_won_previous tie
+home=man_united Beckham=false Scholes=true Neville=true Henry=true Kanu=true Parlour=false Ferguson=confident Wengler=tense arsenal_won_previous man_united_won_previous arsenal
+home=man_united Beckham=false Scholes=true Neville=true Henry=false Kanu=true Parlour=false Ferguson=confident Wengler=confident arsenal_won_previous man_united_won_previous man_united
+home=man_united Beckham=true Scholes=true Neville=false Henry=true Kanu=true Parlour=false Ferguson=confident Wengler=tense arsenal_won_previous man_united_won_previous man_united
+home=arsenal Beckham=false Scholes=true Neville=true Henry=true Kanu=true Parlour=false Ferguson=confident Wengler=tense arsenal_lost_previous man_united_won_previous arsenal
+home=arsenal Beckham=true Scholes=false Neville=true Henry=false Kanu=true Parlour=false Ferguson=tense Wengler=confident arsenal_won_previous man_united_lost_previous arsenal
+home=arsenal Beckham=false Scholes=true Neville=true Henry=true Kanu=true Parlour=false Ferguson=tense Wengler=tense arsenal_lost_previous man_united_won_previous tie
+home=arsenal Beckham=true Scholes=true Neville=false Henry=true Kanu=false Parlour=false Ferguson=confident Wengler=confident arsenal_won_previous man_united_won_previous man_united
+home=arsenal Beckham=false Scholes=true Neville=true Henry=true Kanu=true Parlour=false Ferguson=confident Wengler=tense arsenal_won_previous man_united_won_previous arsenal
+home=arsenal Beckham=false Scholes=true Neville=true Henry=false Kanu=true Parlour=false Ferguson=confident Wengler=confident arsenal_won_previous man_united_won_previous man_united
+home=arsenal Beckham=true Scholes=true Neville=false Henry=true Kanu=true Parlour=false Ferguson=confident Wengler=tense arsenal_won_previous man_united_won_previous arsenal
@@ -1,5 +1,5 @@
-home=arsenal,?
-home=man_united,arsenal_won_previous,man_united_won_previous,Wengler=tense,?
-home=man_united,Beckham=true,Henry=true,?
-home=arsenal,Beckham=false,Henry=true,?
-home=arsenal,Beckham=true,Henry=false,?
+home=arsenal ?
+home=man_united arsenal_won_previous man_united_won_previous Wengler=tense ?
+home=man_united Beckham=true Henry=true ?
+home=arsenal Beckham=false Henry=true ?
+home=arsenal Beckham=true Henry=false ?
@@ -1,15 +1,15 @@
-Sunny,Happy,Outdoor
-Sunny,Happy,Dry,Outdoor
-Sunny,Happy,Humid,Outdoor
-Sunny,Sad,Dry,Outdoor
-Sunny,Sad,Humid,Outdoor
-Cloudy,Happy,Humid,Outdoor
-Cloudy,Happy,Humid,Outdoor
-Cloudy,Sad,Humid,Outdoor
-Cloudy,Sad,Humid,Outdoor
-Rainy,Happy,Humid,Indoor
-Rainy,Happy,Dry,Indoor
-Rainy,Sad,Dry,Indoor
-Rainy,Sad,Humid,Indoor
-Cloudy,Sad,Humid,Indoor
-Cloudy,Sad,Humid,Indoor
+Sunny Happy Outdoor
+Sunny Happy Dry Outdoor
+Sunny Happy Humid Outdoor
+Sunny Sad Dry Outdoor
+Sunny Sad Humid Outdoor
+Cloudy Happy Humid Outdoor
+Cloudy Happy Humid Outdoor
+Cloudy Sad Humid Outdoor
+Cloudy Sad Humid Outdoor
+Rainy Happy Humid Indoor
+Rainy Happy Dry Indoor
+Rainy Sad Dry Indoor
+Rainy Sad Humid Indoor
+Cloudy Sad Humid Indoor
+Cloudy Sad Humid Indoor
@@ -1,9 +1,9 @@
-Cloudy,Sad,?
-Sunny,?
-Rainy,Happy,Humid,?
-Happy,Dry,?
-Rainy,?
-Rainy,Dry,?
-Sunny,Sad,Dry,?
-Cloudy,Happy,Humid,?
-Cloudy,Humid,?
+Cloudy Sad ?
+Sunny ?
+Rainy Happy Humid ?
+Happy Dry ?
+Rainy ?
+Rainy Dry ?
+Sunny Sad Dry ?
+Cloudy Happy Humid ?
+Cloudy Humid ?

0 comments on commit 20e32f1

Please sign in to comment.