Project: engagement_generation License: BSD Dependencies:
Used by:
None |
engagement_generation/src/edu/wpi/hri/gen/ebml/SpeechOption.javaGo to the documentation of this file.00001 /* 00002 * Software License Agreement (BSD License) 00003 * 00004 * Copyright (c) 2010, Worcester Polytechnic Institute 00005 * All rights reserved. 00006 * 00007 * Redistribution and use in source and binary forms, with or without 00008 * modification, are permitted provided that the following conditions 00009 * are met: 00010 * 00011 * * Redistributions of source code must retain the above copyright 00012 * notice, this list of conditions and the following disclaimer. 00013 * * Redistributions in binary form must reproduce the above 00014 * copyright notice, this list of conditions and the following 00015 * disclaimer in the documentation and/or other materials provided 00016 * with the distribution. 00017 * * Neither the name of Worcester Polytechnic Institute. nor the names 00018 * of its contributors may be used to endorse or promote products 00019 * derived from this software without specific prior written permission. 00020 * 00021 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 00022 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 00023 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 00024 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 00025 * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 00026 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 00027 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 00028 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 00029 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 00030 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 00031 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 00032 * POSSIBILITY OF SUCH DAMAGE. 00033 */ 00034 package edu.wpi.hri.gen.ebml; 00035 00036 import java.util.ArrayList; 00037 import java.util.List; 00038 00039 import org.w3c.dom.Element; 00040 import org.w3c.dom.NodeList; 00041 00042 import edu.wpi.hri.gen.GenerationParams; 00043 import edu.wpi.hri.gen.policy.ref.DistractorSet; 00044 import edu.wpi.hri.log.Logger; 00045 import edu.wpi.hri.log.Logger.Colors; 00046 import edu.wpi.hri.log.Logger.LoggerLevel; 00047 00055 public class SpeechOption { 00056 00057 private static final String TEXT_ATTR = "text"; 00058 private static final String COST_ATTR = "cost"; 00059 private static final String DISTRACTOR_ELEM = "distractor"; 00060 private static final String OBJECT_ATTR = "object"; 00061 private static final String DEICTIC_ATTR = "deictic"; 00062 00063 private final Logger logger; 00064 private final String id; 00065 private final String text; 00066 private final double cost; 00067 private final boolean deictic; 00068 private final DistractorSet distractors; 00069 00082 SpeechOption(Logger logger, Element elem, String name) { 00083 this.id = name; 00084 this.logger = logger.sub(Colors.BEHAVIOR, name); 00085 this.text = elem.getAttribute(TEXT_ATTR); 00086 this.cost = Double.parseDouble(elem.getAttribute(COST_ATTR)); 00087 00088 // get if the speech option is deictic or not 00089 if (elem.hasAttribute(DEICTIC_ATTR)) 00090 this.deictic = Boolean 00091 .parseBoolean(elem.getAttribute(DEICTIC_ATTR)); 00092 else 00093 this.deictic = false; 00094 00095 List<String> dists = new ArrayList<String>(); 00096 00097 NodeList list = elem.getElementsByTagName(DISTRACTOR_ELEM); 00098 for (int c = 0; c < list.getLength(); c++) { 00099 dists.add(((Element) list.item(c)).getAttribute(OBJECT_ATTR)); 00100 } 00101 this.distractors = new DistractorSet(dists); 00102 00103 this.logger.debug(LoggerLevel.BEHAVIOR, "Created ..."); 00104 } 00105 00111 public double getCost() { 00112 return cost; 00113 } 00114 00120 public String getText() { 00121 return text; 00122 } 00123 00130 public boolean isDeictic() { 00131 return deictic; 00132 } 00133 00139 public DistractorSet getDistractors() { 00140 return distractors; 00141 } 00142 00149 public String getID() { 00150 return id; 00151 } 00152 00158 public double getReliability() { 00159 if ((text == null) || (text.isEmpty())) 00160 return 0; 00161 else 00162 return GenerationParams.RELIABILITY_SPEECH.getDouble(); 00163 } 00164 } |