~ubuntu-branches/ubuntu/trusty/hyperestraier/trusty-proposed

« back to all changes in this revision

Viewing changes to javapure/Document.java

  • Committer: Bazaar Package Importer
  • Author(s): Steve Langasek
  • Date: 2006-11-14 05:28:32 UTC
  • mfrom: (2.1.4 feisty)
  • Revision ID: james.westby@ubuntu.com-20061114052832-0lzqzcefn8mt4yqe
Tags: 1.4.9-1.1
* Non-maintainer upload.
* High-urgency upload for RC bugfix.
* Set HOME=$(CURDIR)/junkhome when building, otherwise the package build
  will incorrectly look for headers there -- and fail when the directory
  exists and is unreadable, as happens sometimes on sudo-using
  autobuilders!

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/*************************************************************************************************
2
2
 * Pure Java interface of Hyper Estraier
3
 
 *                                                      Copyright (C) 2004-2005 Mikio Hirabayashi
 
3
 *                                                      Copyright (C) 2004-2006 Mikio Hirabayashi
4
4
 *                                                                           All rights reserved.
5
5
 * This file is part of Hyper Estraier.
6
6
 * Redistribution and use in source and binary forms, with or without modification, are
46
46
  private Map attrs;
47
47
  private List dtexts;
48
48
  private List htexts;
 
49
  private Map kwords;
 
50
  private int score;
49
51
  //----------------------------------------------------------------
50
52
  // constructors
51
53
  //----------------------------------------------------------------
57
59
    attrs = new HashMap(31);
58
60
    dtexts = new ArrayList(31);
59
61
    htexts = new ArrayList(31);
 
62
    kwords = null;
 
63
    score = -1;
60
64
  }
61
65
  /**
62
66
   * Create a document object made from draft data.
69
73
    while(lnum < lines.length){
70
74
      String line = lines[lnum++].trim();
71
75
      if(line.length() < 1) break;
72
 
      if(line.startsWith("%")) continue;
 
76
      if(line.startsWith("%")){
 
77
        if(line.startsWith("%VECTOR\t")){
 
78
          if(kwords == null) kwords = new HashMap(32);
 
79
          String[] fields = Utility.split_fields(line);
 
80
          for(int i = 1; i < fields.length - 1; i += 2){
 
81
            if(fields[i].length() < 0 || fields[i+1].length() < 0 ||
 
82
               fields[i].charAt(0) <= ' ') continue;
 
83
            kwords.put(fields[i], fields[i+1]);
 
84
          }
 
85
        } else if(line.startsWith("%SCORE\t")){
 
86
          String[] fields = Utility.split_fields(line);
 
87
          score = Integer.parseInt(fields[1]);
 
88
        }
 
89
        continue;
 
90
      }
73
91
      int lidx = line.indexOf('=');
74
92
      if(lidx != -1) add_attr(line.substring(0, lidx), line.substring(lidx + 1, line.length()));
75
93
    }
77
95
      String line = lines[lnum++];
78
96
      if(line.length() < 1) continue;
79
97
      if(line.charAt(0) == '\t'){
80
 
        add_hidden_text(line);
 
98
        line = line.substring(1, line.length());
 
99
        if(line.length() > 0) add_hidden_text(line);
81
100
      } else {
82
101
        add_text(line);
83
102
      }
115
134
    if(text.length() > 0) htexts.add(text);
116
135
  }
117
136
  /**
 
137
   * Attach keywords.
 
138
   * @param kwords a map object of keywords.  Keys of the map should be keywords of the document
 
139
   * and values should be their scores in decimal string.
 
140
   */
 
141
  public void set_keywords(Map kwords){
 
142
    this.kwords = kwords;
 
143
  }
 
144
  /**
 
145
   * Set the substitute score.
 
146
   * @param score the substitute score.  It it is negative, the substitute score setting is
 
147
   * nullified.
 
148
   */
 
149
  private void set_score(int score){
 
150
    this.score = score;
 
151
  }
 
152
  /**
118
153
   * Get the ID number.
119
154
   * @return the ID number.  If this object has never been registered, -1 is returned.
120
155
   */
163
198
    return sb.toString();
164
199
  }
165
200
  /**
 
201
   * Get attached keywords.
 
202
   * @return a map object of keywords and their scores in decimal string.  If no keyword is
 
203
   * attached, `null' is returned.
 
204
   */
 
205
  public Map keywords(){
 
206
    return kwords;
 
207
  }
 
208
  /**
 
209
   * Get the substitute score.
 
210
   * @return the substitute score or -1 if it is not set.
 
211
   */
 
212
  public int score(){
 
213
    if(score < 0) return -1;
 
214
    return score;
 
215
  }
 
216
  /**
166
217
   * Dump draft data.
167
218
   * @return draft data.
168
219
   */
177
228
      sb.append((String)attrs.get(name));
178
229
      sb.append("\n");
179
230
    }
 
231
    if(kwords != null){
 
232
      sb.append("%VECTOR");
 
233
      Iterator kwit = kwords.keySet().iterator();
 
234
      while(kwit.hasNext()){
 
235
        String key = (String)kwit.next();
 
236
        sb.append("\t");
 
237
        sb.append(key);
 
238
        sb.append("\t");
 
239
        sb.append((String)kwords.get(key));
 
240
      }
 
241
      sb.append("\n");
 
242
    }
 
243
    if(score >= 0) sb.append("%SCORE\t" + score + "\n");
180
244
    sb.append("\n");
181
245
    Iterator dtit = dtexts.iterator();
182
 
    for(int i = 0; dtit.hasNext(); i++){
 
246
    while(dtit.hasNext()){
183
247
      sb.append(dtit.next());
184
248
      sb.append("\n");
185
249
    }
186
250
    Iterator htit = htexts.iterator();
187
 
    for(int i = 0; htit.hasNext(); i++){
 
251
    while(htit.hasNext()){
188
252
      sb.append("\t");
189
253
      sb.append(htit.next());
190
254
      sb.append("\n");