[Document map agent and make it more independent. Some other doc and build fixes. bjorn@bringert.net**20041213165442] < > { hunk ./Makefile 32 -# path to Java Speech API classes -JSAPI_CP=../freetts-1.2beta2/lib/jsapi.jar - -# path to Java Speech Engine classes -JSAPI_ENGINE_CP=../freetts-1.2beta2/lib/freetts.jar - hunk ./Makefile 40 -CLASSPATH=.:build:$(GFC2JAVA)/build:$(DIALOGUTIL)/build:$(TKIT_OAA_JAR):$(OAA_CP):$(JSAPI_CP):$(JSAPI_ENGINE_CP) +CLASSPATH=.:build:$(GFC2JAVA)/build:$(DIALOGUTIL)/build:$(TKIT_OAA_JAR):$(OAA_CP) hunk ./Makefile 63 - -recognize: - $(JAVA) -cp $(CLASSPATH) se.chalmers.cs.gf.dialogutil.sr.Recognizer $(OAA_CONNECT) - -run: - $(JAVA) -cp $(CLASSPATH) se.chalmers.cs.gf.tramdemo.TramDemo $(OAA_CONNECT) - -rungf: - $(JAVA) -cp $(CLASSPATH) se.chalmers.cs.gf.oaa.GFAgent /query.properties /answer.properties $(OAA_CONNECT) - -runmap: - $(JAVA) -cp $(CLASSPATH) se.chalmers.cs.gf.tramdemo.MapAgent $(OAA_CONNECT) - -rungraph: - $(JAVA) -cp $(CLASSPATH) se.chalmers.cs.gf.graph.GraphAgent $(OAA_CONNECT) - -rundm: - $(JAVA) -cp $(CLASSPATH) se.chalmers.cs.gf.tramdemo.OAATramDemo $(OAA_CONNECT) hunk ./README 9 -This section descripes how to run the compiled application using the -binary distribution. If you only have the source code, i.e. from -the darcs repo, follow the instructions under BUILDING first. +This section describes how to run the compiled application using the +binary distribution (tramdemo.jar). If you only have the source code, +follow the instructions under BUILDING first. hunk ./README 15 +You may need to change the file +tramdemo_unix.props (for Unix) or tramdemo_win.props (for windows) +to point to the software below: + hunk ./README 29 - Expected to be in ../freetts-1.2beta2 - If it is somewhere else, modify tramdemo_unix.props or tramdemo_win.props - and set FREETTSAGENT to point to the FreeTTS installation. + Check tramdemo_unix.props or tramdemo_win.props: + FREETTS should to point to the FreeTTS installation. hunk ./README 34 - Expected to be in ../freeTTSAgent + Check tramdemo_unix.props or tramdemo_win.props: + FREETTSAGENT should to point to the FreeTTSAgent installation. + hunk ./README 41 - hunk ./README 42 +Windows: hunk ./README 44 -BUILDING +> ./tramdemo_speech.bat hunk ./README 48 +BUILDING hunk ./README 52 +- GF 2.1 (http://www.cs.chalmers.se/~aarne/GF/) hunk ./README 57 +- TrindiKit java classes (???) hunk ./README 63 -- Build tramdemo: +- Build tramdemo.jar: addfile ./doc/map-agent.html hunk ./doc/map-agent.html 1 - + + + + + +MapAgent + + + + +

MapAgent

+ +

Björn Bringert, +bringert@cs.chalmers.se +

+ +

Introduction

+ +

+MapAgent is an OAA agent which displays a map. The agent has solvables +for drawing labelled edges on the map and for getting user clicks. +

+ +

Download

+ +

+MapAgent is currently distributed as part of the +tramdemo system. +

+ +

Configuration

+ +

MapAgent is currently feared towards transport networks and other +systems which can be represented by a graph.

+ +

The agent is configured by a properties file. Here is and +example of such a file:

+ +
+stops: /stops-gbg.txt
+lines: /lines-gbg.txt
+stopNames: /stops-gbg-sv.txt
+clickThreshold: 20.0
+backgroundImage: /mapbg.png
+
+ +
+ +
stops
+
Java resource name for a file with node descriptions. Each line +describes a node on the format "label x y", e.g.: + +
+Angered                 750     1000
+AxelDahlstromsTorg      200     70
+Biskopsgarden           50      950
+Bergsjon                1000    1000
+
+ +
+ +
lines
+
Java resource name for a file with weighted directed edge +descriptions. The file consists of a number of edge groups. All +edges in a group share the same label. The format of an edge group is: + +
+edge_label  number_of_rows_in_group
+node_label 
+node_label weight_from_previous
+node_label weight_from_previous
+...
+
+ +

Example:

+ +
+62      7
+Redbergsplatsen
+Karralundsgatan         3
+SanktSigfridsplan       5
+Kalleback               8
+SanktSigfridsplan       8
+Karralundsgatan         5
+Redbergsplatsen         3
+
+ +

+Edge groups are separated by an empty line. +

+
+ +
stopNames
+
Java resource name for a file giving human-reable names to +nodes. Format: "node_label: human-readable name", e.g.: + +
+Angered:                Angered
+AxelDahlstromsTorg:     Axel Dahlströms torg
+Biskopsgarden:          Biskopsgården
+Bergsjon:               Bergsjön
+
+ +
+ +
clickThreshold
+
+The radius of the clickable circles around nodes, in map units +(i.e. the same units as the coordinates used for node placment). +
+ +
backgroundImage
+
+Java resource name for an image file containing a background image for +the map. The image is scaled to fit the map display size. +
+ +
+ +

+NOTE: The path names in the properties file are Java resource names, +so leading slashes mean to look in the root of the package +hierarchy to find the file in the current directory. +

+ +

Running

+ +

+If the map properties file is gbg.properties and +the facilitator is running on $FAC_HOST, port +$FAC_PORT, MapAgent is started with: +

+ +
+$ java -cp $CLASSPATH:tramdemo.jar:. se.chalmers.cs.gf.tramdemo.MapAgent /gbg.properties -oaa_connect "tcp('${FAC_HOST}',${FAC_PORT})"
+
+ +

Notes

+ + + +

Solvables

+ +

+MapAgent declares these solvables: +

+ + + +

draw

+ +

draw(Instrs)

+ +

Parameters

+ +
+
Instrs
+
A string which consists of a number of drawing instructions. Each +drawing instruction is terminated by a semicolon. The supported +instructions are: + +
+
clear
+
Clear all old drawings.
+
drawEdge(label, [node_label, node_label, ...])
+
Draw some edges with a common label.
+
+ +
+ +

Examples

+ + + +

clicks

+ +

clicks(Clicks)

+ +

Parameters

+ +
+
Clicks
+
+ + + +
+ + +

Examples

+ + + + + + + hunk ./se/chalmers/cs/gf/tramdemo/MapAgent.java 29 - Properties cityProps = FileUtil.readPropertiesResource(MapAgent.class, "/gbg.properties"); + if (args.length < 1 || !args[0].endsWith(".properties")) { + System.err.println("Usage: java se.chalmers.cs.gf.tramdemo.MapAgent [-oaa_connect tcp('$HOST',$FAC_PORT)]"); + System.exit(1); + } + + Properties cityProps = FileUtil.readPropertiesResource(MapAgent.class, args[0]); hunk ./se/chalmers/cs/gf/tramdemo/TramDemo.java 1 -package se.chalmers.cs.gf.tramdemo; - -import se.chalmers.cs.gf.translate.*; -import se.chalmers.cs.gf.util.FileUtil; -import se.chalmers.cs.gf.util.Pair; -import static se.chalmers.cs.gf.util.Pair.pair; - -import se.chalmers.cs.gf.dialogutil.*; -import se.chalmers.cs.gf.dialogutil.sr.*; -import se.chalmers.cs.gf.dialogutil.tts.*; - -import java.awt.Dimension; -import java.awt.Point; -import javax.swing.JFrame; -import javax.swing.ImageIcon; -import java.util.*; -import java.io.IOException; - -import java.util.logging.*; - -import se.chalmers.cs.gf.graph.*; - -import se.chalmers.cs.gf.tramdemo.query.*; -import se.chalmers.cs.gf.tramdemo.answer.*; - -public class TramDemo { - - protected TextListenerList listeners = new TextListenerList(); - - private InterpretQuery queryInterpreter; - - private DijkstraPath pathFinder; - - private QueryMain queryMain; - - private AnswerMain answerMain; - - private TramMap map; - - public TramDemo(double clickThreshold, TransportNetwork tn, - Translator queryTranslator, - Translator answerTranslator, - String stopHere, TramMap map) { - - CoordMap coordMap = tn.getCoordMap(clickThreshold); - - this.queryInterpreter = new InterpretQuery(coordMap, stopHere); - - this.pathFinder = new DijkstraPath(tn); - - this.queryMain = new QueryMain(queryTranslator); - - this.answerMain = new AnswerMain(answerTranslator); - - this.map = map; - } - - /** - * Add a listener which will get a TextEvent when some text should - * be output to the user. - */ - public void addTextListener(TextListener l) { - listeners.add(l); - } - - public void removeTextListener(TextListener l) { - listeners.remove(l); - } - - protected void fireTextEvent(String text) { - listeners.fireTextEvent(text); - } - - private List> parseQuery(String input) { - return queryMain.parseQueryWithAll(input); - } - - private Pair disambiguate(List> qs) { - if (qs.size() == 0) { - System.out.println(""); - return null; - } else if (qs.size() == 1) { - return qs.iterator().next(); - } else { - System.out.println(""); - for (Pair q : qs) - System.out.println(q.fst + ": " + q.snd); - return null; - } - } - - public void showAnswer(String lang, Route a) { - drawAnswer(a); - String output = answerToText(lang, a); - fireTextEvent(output); - } - - public void drawAnswer(Route a) { - // FIXME: figure out city name dynamically - String mapInstrs = answerMain.linearizeRoute("GbgRouteMap", a); - map.clearPath(); - map.doDrawInstrs(mapInstrs); - } - - private String answerToText(String lang, Route a) { - return answerMain.linearizeRoute(lang, a); - } - - private String getOutputLang(String inputLang) { - String lang = inputLang.substring(inputLang.length()-3); - return "GbgRoute" + lang; // FIXME: figure out city name dynamically - } - - private void handleInput(String input) { - System.err.println("Got input: " + input); - - List> ps1 = parseQuery(input); - List> ps2 - = queryInterpreter.interpretQueries(ps1); - Pair p = disambiguate(ps2); - if (p == null) - return; - - String lang = p.fst; - ShortestPathQuery q = p.snd; - - System.err.println("Language: " + lang); - System.err.println("Query: " + q); - - String outputLang = getOutputLang(lang); - - Path path = pathFinder.computePath(q.getFrom(), q.getTo()); - - Route answer = PathToRoute.pathToRoute(path); - - showAnswer(outputLang, answer); - } - - - private class InputListener implements TextListener { - public void textEvent(TextEvent e) { - handleInput(e.getText()); - } - } - - public static void main(String[] args) throws IOException { - - // set up logging - Handler h = new ConsoleHandler(); - h.setLevel(Level.FINEST); - Logger.getLogger("").addHandler(h); - Logger.getLogger("se.chalmers.cs.gf.parse").setLevel(Level.FINEST); - - Properties cityProps = FileUtil.readPropertiesResource(TramDemo.class, "/gbg.properties"); - - double clickThreshold = Double.parseDouble(cityProps.getProperty("clickThreshold")); - String backgroundImageResource = cityProps.getProperty("backgroundImage"); - String stopHere = cityProps.getProperty("stopHere"); - - String queryProps = "/query.properties"; - String answerProps = "/answer.properties"; - - Translator queryTranslator - = TranslatorFactory.createTranslator(queryProps); - Translator answerTranslator - = TranslatorFactory.createTranslator(answerProps); - TransportNetwork tn = TransportNetwork.fromCityProperties(cityProps); - - TramMap map = TramMap.showMap(clickThreshold, tn, backgroundImageResource); - - TramDemo td = new TramDemo(clickThreshold, tn, - queryTranslator, answerTranslator, - stopHere, map); - - TramInput i = new TramInput(); - i.addTextListener(td.new InputListener()); - - // Get text input from a Swing dialog - i.addTextInput(new DialogInput()); - - // Get text input from Nuance over OAA -// i.addTextInput(new RecognizerInput("tramdemo", args)); - - // Get click input from map - i.addClickInput(td.map); - - // Output text to System.err - td.addTextListener(new ConsoleOutput()); - - // Output text to a speech synthesizer - td.addTextListener(new JavaSpeechOutput()); - } - -} rmfile ./se/chalmers/cs/gf/tramdemo/TramDemo.java hunk ./tramdemo.config 100 -appline ${JAVA} se.chalmers.cs.gf.tramdemo.MapAgent -oaa_connect tcp('${Host}',${FAC_PORT}) +appline ${JAVA} se.chalmers.cs.gf.tramdemo.MapAgent /gbg.properties -oaa_connect tcp('${Host}',${FAC_PORT}) }