KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > SnowMailClient > Language > Sentence


1 package SnowMailClient.Language;
2
3 import snow.utils.storage.*;
4 import java.util.*;
5
6
7 /** this is the model for a sentence,
8     with his translation in a foreign language
9     or "" if not already translated
10 */

11 public final class Sentence implements Vectorizable
12 {
13   private String JavaDoc sentence;
14   // the translation ("" if not made)
15
private String JavaDoc translation = "";
16
17   // where it was parsed ("" if not found during a parse operation)
18
// useful to locate the translation and guess semantic
19
// ### stores only the first occurence source...
20
private String JavaDoc foundInClass = "";
21   private int linePosition = -1;
22   private int endPosition = -1; // used during parsing
23

24   // number of times this string has been called, give a rough idea of its importance...
25
// (bad)
26
private int callCount = 0;
27
28
29   // a flag to detect old unused sentences during merge operation
30
public boolean visited = false;
31
32 /* public Sentence(String sentence)
33   {
34      this.sentence = sentence;
35   }*/

36
37   public Sentence(String JavaDoc sentence, String JavaDoc _foundInClass, int linePosition, int endPosition)
38   {
39      this.sentence = sentence;
40      this.foundInClass = _foundInClass;
41      this.linePosition = linePosition;
42      this.endPosition = endPosition;
43   }
44
45
46   public String JavaDoc getSentence() { return sentence; }
47   public String JavaDoc getTranslation() { return translation; }
48   public String JavaDoc getLocationClass() { return foundInClass; }
49   public int getCallCount() { return callCount; }
50   public int getLinePosition() { return linePosition; }
51   public int getEndPosition() { return endPosition; }
52
53
54   public void setTranslation(String JavaDoc translation) { this.translation = translation; }
55   public void setLocationClass(String JavaDoc loc, int line)
56   {
57     foundInClass = loc;
58     linePosition = line;
59   }
60
61   public boolean hasTranslation() { return !translation.equals(""); }
62   public void incrementCallCount() { callCount++; }
63
64   public boolean equals(String JavaDoc s)
65   {
66     return s.equals(sentence);
67   }
68
69
70   // Vectorization
71
//
72
public Sentence(){}
73   public Vector<Object JavaDoc> getVectorRepresentation() //throws Exception
74
{
75      Vector<Object JavaDoc> v = new Vector<Object JavaDoc>();
76      v.addElement(3); // 0. version
77
v.addElement(sentence);
78      v.addElement(translation);
79      v.addElement(foundInClass);
80      v.addElement(linePosition);
81      v.addElement(callCount);
82      return v;
83   }
84
85   public void createFromVectorRepresentation( Vector<Object JavaDoc> v )
86   {
87     int version = (Integer JavaDoc) v.get(0);
88
89     if(version==3)
90     {
91       sentence = (String JavaDoc) v.get(1);
92       translation = (String JavaDoc) v.get(2);
93       foundInClass = (String JavaDoc) v.get(3);
94       linePosition = (Integer JavaDoc) v.get(4);
95       callCount = (Integer JavaDoc) v.get(5);
96     }
97     sentence=sentence.trim();
98     translation=translation.trim();
99   }
100
101 } // Sentence
Popular Tags