001: package Language;
002:
003: import Schmortopf.Utility.Vectorizable;
004:
005: import java.util.*;
006:
007: /** this is the model for a sentence,
008: with his translation in a foreign language
009: or "" if not already translated
010: */
011: public class Sentence {
012: private String sentence;
013: // the translation ("" if not made)
014: private String translation = "";
015:
016: // where it was parsed ("" if not found during a parse operation)
017: // useful to locate the translation and guess semantic
018: // ### stores only the first occurence source...
019: private String foundInClass = "";
020: private int linePosition = -1;
021:
022: // number of times this string has been called, give a rough idea of its importance...
023: // (bad)
024: private int callCount = 0;
025:
026: // a flag to detect old unused sentences during merge operation
027: public boolean visited = false;
028:
029: public Sentence(String sentence) {
030: this .sentence = sentence;
031: }
032:
033: public Sentence(String sentence, String _foundInClass,
034: int linePosition) {
035: this .sentence = sentence;
036: this .foundInClass = _foundInClass;
037: this .linePosition = linePosition;
038: }
039:
040: public String getSentence() {
041: return sentence;
042: }
043:
044: public String getTranslation() {
045: return translation;
046: }
047:
048: public String getLocationClass() {
049: return foundInClass;
050: }
051:
052: public int getCallCount() {
053: return callCount;
054: }
055:
056: public int getLinePosition() {
057: return linePosition;
058: }
059:
060: public void setTranslation(String translation) {
061: this .translation = translation;
062: }
063:
064: public void setLocationClass(String loc, int line) {
065: foundInClass = loc;
066: linePosition = line;
067: }
068:
069: public boolean hasTranslation() {
070: return !translation.equals("");
071: }
072:
073: public void incrementCallCount() {
074: callCount++;
075: }
076:
077: public boolean equals(String s) {
078: return s.equals(sentence);
079: }
080:
081: // Vectorization
082: //
083: public Sentence() {
084: }
085:
086: public Vector getVectorRepresentation() throws Exception {
087: Vector v = new Vector();
088: v.addElement(new Integer(3)); // 0. version
089: v.addElement(sentence);
090: v.addElement(translation);
091: v.addElement(foundInClass);
092: v.addElement(new Integer(linePosition));
093: v.addElement(new Integer(callCount));
094: return v;
095: }
096:
097: public void createFromVectorRepresentation(Vector v) {
098: int version = ((Integer) v.elementAt(0)).intValue();
099: if (version == 1) {
100: sentence = (String) v.elementAt(1);
101: translation = (String) v.elementAt(2);
102: foundInClass = (String) v.elementAt(3);
103: callCount = 0;
104: } else if (version == 2) {
105: sentence = (String) v.elementAt(1);
106: translation = (String) v.elementAt(2);
107: foundInClass = (String) v.elementAt(3);
108: callCount = ((Integer) v.elementAt(4)).intValue();
109: } else if (version == 3) {
110: sentence = (String) v.elementAt(1);
111: translation = (String) v.elementAt(2);
112: foundInClass = (String) v.elementAt(3);
113: linePosition = ((Integer) v.elementAt(4)).intValue();
114: callCount = ((Integer) v.elementAt(5)).intValue();
115: }
116: sentence = sentence.trim();
117: translation = translation.trim();
118: }
119:
120: } // Sentence
|