1 
2  //\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\
3  //                                                                        \\
4  //                 Centre for Speech Technology Research                  \\
5  //                      University of Edinburgh, UK                       \\
6  //                        Copyright (c) 1996,1997                         \\
7  //                         All Rights Reserved.                           \\
8  //   Permission is hereby granted, free of charge, to use and distribute  \\
9  //   this software and its documentation without restriction, including   \\
10  //   without limitation the rights to use, copy, modify, merge, publish,  \\
11  //   distribute, sublicense, and/or sell copies of this work, and to      \\
12  //   permit persons to whom this work is furnished to do so, subject to   \\
13  //   the following conditions:                                            \\
14  //    1. The code must retain the above copyright notice, this list of    \\
15  //       conditions and the following disclaimer.                         \\
16  //    2. Any modifications must be clearly marked as such.                \\
17  //    3. Original authors' names are not deleted.                         \\
18  //    4. The authors' names are not used to endorse or promote products   \\
19  //       derived from this software without specific prior written        \\
20  //       permission.                                                      \\
21  //   THE UNIVERSITY OF EDINBURGH AND THE CONTRIBUTORS TO THIS WORK        \\
22  //   DISCLAIM ALL WARRANTIES With REGARD TO THIS SOFTWARE, INCLUDING      \\
23  //   ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT   \\
24  //   SHALL THE UNIVERSITY OF EDINBURGH NOR THE CONTRIBUTORS BE LIABLE     \\
25  //   FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES    \\
26  //   WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN   \\
27  //   AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,          \\
28  //   ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF       \\
29  //   THIS SOFTWARE.                                                       \\
30  //                                                                        \\
31  //\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\
32  //                                                                        \\
33  //                  Author: Richard Caley (rjc@cstr.ed.ac.uk)             \\
34  //                    Date: Friday 12th September 1997                    \\
35  //  --------------------------------------------------------------------  \\
36  //  Wrapper around the EST_Utterance class.                               \\
37  //                                                                        \\
38  //\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\
39 
40 package cstr.est;
41 
42 import java.util.*;
43 import java.lang.*;
44 import java.io.*;
45 
46 import cstr.util.*;
47 
48 public class Utterance
49 {
50   private long cpp_handle;
51   private LongHash cache;
52 
Utterance()53   public Utterance()
54     {
55       create_cpp_utterance();
56       cache = new LongHash(200);
57     }
58 
finalize()59   protected void finalize() throws Throwable
60     {
61       destroy_cpp_utterance();
62       super.finalize();
63     }
64 
getItem(long handle)65   final Item getItem(long handle)
66     {
67       Item i;
68       i = (Item)cache.get(handle);
69       if (i==null)
70 	{
71 	  i = new Item(handle, this);
72 	  cache.put(handle, i);
73 	}
74       return i;
75     }
76 
cpp_num_relations()77   private native int cpp_num_relations();
78 
num_relations()79   public int num_relations()
80     {
81       return cpp_num_relations();
82     }
83 
cpp_has_relation(String name)84   private native boolean cpp_has_relation(String name);
85 
has_relation(String n)86   public boolean has_relation(String n)
87     {
88       return cpp_has_relation(n);
89     }
90 
cpp_relation_n(int n)91   private native long cpp_relation_n(int n);
92 
relation(int n)93   public Relation relation(int n)
94     {
95       return new Relation(cpp_relation_n(n), this);
96     }
97 
cpp_relation(String name)98   private native long cpp_relation(String name);
99 
relation(String n)100   public Relation relation(String n)
101     {
102       long rel_h = cpp_relation(n);
103       if (rel_h==0)
104 	return null;
105       else
106 	return new Relation(rel_h, this);
107     }
108 
cpp_create_relation(String name)109   private native long cpp_create_relation(String name);
110 
create_relation(String name)111   public Relation create_relation(String name)
112     {
113 	long rel_h = cpp_create_relation(name);
114 	if (rel_h==0)
115 	    return null;
116 	else
117 	    return new Relation(rel_h, this);
118     }
119 
cpp_load(String filename)120   private native String cpp_load(String filename);
121 
load(String filename)122   public void load(String filename) throws FileNotFoundException
123     {
124       String res = cpp_load(filename);
125 
126       if (!res.equals(""))
127 	  throw new FileNotFoundException(res);
128     }
129 
cpp_save(String filename, String format)130   private native String cpp_save(String filename, String format);
131 
save(String filename, UtteranceFileFormat format)132   public void save(String filename, UtteranceFileFormat format) throws IOException
133     {
134       String res = cpp_save(filename, format.toString());
135 
136       if (!res.equals(""))
137 	  throw new IOException(res);
138     }
139 
save(String filename)140   public void save(String filename) throws IOException
141     {
142       save(filename, UtteranceFileFormat.EST_ASCII);
143     }
144 
cpp_findItem(float time)145   private native int cpp_findItem(float time);
146 
findItem(float time)147   public int findItem(float time)
148     {
149       return cpp_findItem(time);
150     }
151 
cpp_getEndTime()152   private native float cpp_getEndTime();
153 
getEndTime()154   public float getEndTime()
155     {
156       return cpp_getEndTime();
157     }
158 
initialise_cpp()159   private native static boolean initialise_cpp();
finalise_cpp()160   private native static boolean finalise_cpp();
create_cpp_utterance()161   private native boolean create_cpp_utterance();
destroy_cpp_utterance()162   private native boolean destroy_cpp_utterance();
163 
164   static {
165     System.loadLibrary("estjava");
166     if (!initialise_cpp())
167 	throw new ExceptionInInitializerError("Utterance C++ fails");
168   }
169 }
170