1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365
|
//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\
// \\
// Centre for Speech Technology Research \\
// University of Edinburgh, UK \\
// Copyright (c) 1996,1997 \\
// All Rights Reserved. \\
// Permission is hereby granted, free of charge, to use and distribute \\
// this software and its documentation without restriction, including \\
// without limitation the rights to use, copy, modify, merge, publish, \\
// distribute, sublicense, and/or sell copies of this work, and to \\
// permit persons to whom this work is furnished to do so, subject to \\
// the following conditions: \\
// 1. The code must retain the above copyright notice, this list of \\
// conditions and the following disclaimer. \\
// 2. Any modifications must be clearly marked as such. \\
// 3. Original authors' names are not deleted. \\
// 4. The authors' names are not used to endorse or promote products \\
// derived from this software without specific prior written \\
// permission. \\
// THE UNIVERSITY OF EDINBURGH AND THE CONTRIBUTORS TO THIS WORK \\
// DISCLAIM ALL WARRANTIES With REGARD TO THIS SOFTWARE, INCLUDING \\
// ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT \\
// SHALL THE UNIVERSITY OF EDINBURGH NOR THE CONTRIBUTORS BE LIABLE \\
// FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES \\
// WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN \\
// AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, \\
// ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF \\
// THIS SOFTWARE. \\
// \\
//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\
// \\
// Author: Richard Caley (rjc@cstr.ed.ac.uk) \\
// Date: Tue Mar 31 1998 \\
// -------------------------------------------------------------------- \\
// Java wrapper around relations. \\
// \\
//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\
package cstr.est ;
import java.lang.*;
import java.util.*;
import java.awt.*;
import java.io.*;
import cstr.util.*;
public class Relation
implements Featured
{
private long cpp_handle;
private Utterance utterance;
private boolean mine;
public Relation()
{
this(0L, null, true);
}
public Relation(long handle)
{
this(handle, null, false);
}
public Relation(long handle, Utterance u)
{
this(handle, u, false);
}
Relation(long handle, Utterance u, boolean m)
{
create_cpp_relation(handle);
utterance=u;
mine=m;
}
protected void finalize() throws Throwable
{
if (mine)
destroy_cpp_relation();
super.finalize();
}
protected final Item getItem(long handle)
{
Item i;
if (utterance != null)
i = utterance.getItem(handle);
else
i = new Item(handle);
return i;
}
private native String cpp_name();
public String name()
{
return cpp_name();
}
public String getName()
{
return cpp_name();
}
public long getHandle()
{
return cpp_handle;
}
public boolean equals(Object o)
{
return o instanceof Relation && ((Relation)o).cpp_handle == cpp_handle;
}
private native String cpp_type();
public String type()
{
return cpp_type();
}
private native String cpp_getFeature(String n);
public String getFeature(String n)
{
if (n.equals("_NAME_"))
return getName();
else
return cpp_getFeature(n);
}
public String getS(String n)
{
if (n.equals("_NAME_"))
return getName();
else
return cpp_getFeature(n);
}
public String [] featureNames()
{
return featureNames(false, true);
}
public String [] featureNames(boolean nodes, boolean leaves)
{
Vector names = new Vector();
Hashtable found = new Hashtable();
Enumeration is = getElements();
while (is.hasMoreElements())
{
Item item = (Item)is.nextElement();
Item_Content cont = item.getContent();
Vector paths = new Vector();
cont.getFeatures().getPaths(null, paths, nodes, leaves);
for(int i=0; i< paths.size(); i++)
{
String name = (String)paths.elementAt(i);
if (found.get(name) != null)
continue;
for(int p=0; p<names.size(); p++)
{
int cmp = name.compareTo((String)names.elementAt(p));
if (cmp>0)
continue;
if (cmp< 0)
{
names.insertElementAt(name, p);
found.put(name,name);
}
name=null;
break;
}
if (name != null)
{
names.addElement(name);
found.put(name, name);
}
}
}
String [] ns = new String[names.size()];
for(int i=0; i<names.size(); i++)
ns[i] = (String)names.elementAt(i);
return ns;
}
public void setUtterance(Utterance u)
{
utterance=u;
}
public Utterance getUtterance()
{
return utterance;
}
private native String cpp_load(String filename);
public void load(String filename) throws FileNotFoundException
{
String res = cpp_load(filename);
if (!res.equals(""))
throw new FileNotFoundException(res);
// findTimePoints();
}
private native String cpp_save(String filename, String format);
public void save(String filename, String format) throws IOException
{
String res = cpp_save(filename, format);
if (!res.equals(""))
throw new IOException(res);
}
private native float cpp_getEndTime();
public float getEndTime()
{
return cpp_getEndTime();
}
public Enumeration getElements()
{
return new RelationEnumeration(this);
}
public Enumeration getElements(float from, float to)
{
return new RelationEnumeration(this, from, to);
}
private native long cpp_head();
public Item head()
{
long h = cpp_head();
if (h != 0)
return getItem(h);
else
return null;
}
private native long cpp_tail();
public Item tail()
{
long h = cpp_tail();
if (h != 0)
return getItem(h);
else
return null;
}
private native long cpp_append();
public Item append()
{
long h = cpp_append();
if (h != 0)
return getItem(h);
else
return null;
}
private native void cpp_removeItemList(long itemh);
public void removeItemList(Item i)
{
cpp_removeItemList(i.getHandle());
}
private native long cpp_findItem(float time);
public Item findItem(float time)
{
long p = cpp_findItem(time);
return p==0L?null:getItem(p);
}
private native static boolean initialise_cpp();
private native static boolean finalise_cpp();
private native boolean create_cpp_relation(long handle);
private native boolean destroy_cpp_relation();
static {
System.loadLibrary("estjava");
if (!initialise_cpp())
throw new ExceptionInInitializerError("Relation C++ fails");
}
static class RelationEnumeration implements Enumeration
{
private Relation relation;
private Item current;
private float endTime;
public RelationEnumeration(Relation st)
{
relation = st;
current = st.head();
endTime = (float)-1.0;
}
public RelationEnumeration(Relation st, float from, float to)
{
relation = st;
current = st.findItem(from);
endTime = to;
}
public boolean hasMoreElements()
{
return current != null;
}
public Object nextElement()
{
Item n = current;
current = n.down();
if (current == null)
current = n.next();
if (current == null)
{
current=n;
while (current.prev()!=null)
current=current.prev();
current = current.up();
while (current != null && current.next()==null)
{
while (current.prev()!=null)
current=current.prev();
current=current.up();
}
if (current != null)
current = current.next();
}
if (current != null && endTime >= 0 && current.getEndTime() > endTime)
current = null;
return n;
}
}
}
|