source: trunk/greenstone3-extensions/vishnu/src/vishnu/builder/CollectionBuilder.java@ 8189

Last change on this file since 8189 was 8189, checked in by kjdon, 20 years ago

first version of Imperial College's Visualiser code

  • Property svn:keywords set to Author Date Id Revision
File size: 5.7 KB
Line 
1package vishnu.builder;
2
3import java.util.*;
4import java.io.*;
5
6public class CollectionBuilder
7{
8 //String site;
9 String collID; // directory name
10 String collHome; // full path to collections directory
11 String collName;
12 String collDesc;
13 String indexer;
14 long numDocs=0;
15
16 private static void usage()
17 {
18 System.out.println("java vishnu.builder.CollectionBuilder\n -collsHome (directory where collections live) \n -collection (directory name of collection)\n -name (descriptive name for collection) \n -description (collection description)\n -index (\"mg\" or \"luc\")");
19 }
20
21
22 public static void main(String[] args)
23 {
24 if( args.length == 0 ){
25 usage();
26 System.exit(0);
27 }
28
29 String collID = null;
30 String collsHome = null;
31 String collName = "";
32 String collDesc = "";
33 String indexer = null;
34
35 int a = 0;
36 while( a < args.length ){
37 //if( args[a].equals("-gHome") )
38 // gHome = args[++a];
39 if (args[a].equals("-collsHome"))
40 collsHome = args[++a];
41 else if (args[a].equals("-collection"))
42 collID = args[++a];
43 else if( args[a].equals("-name") )
44 collName = args[++a];
45 else if( args[a].equals("-description") )
46 collDesc = args[++a];
47 else if( args[a].equals("-index") )
48 indexer = args[++a];
49 a++;
50 }
51
52 if (collsHome==null || collID==null || indexer==null) {
53 usage();
54 System.exit(0);
55 }
56
57 if (collName.equals("")) {
58 collName = collID;
59 }
60 if( !indexer.equals("mg") && !indexer.equals("luc") )
61 indexer = "luc";
62
63 if (!collsHome.endsWith(File.separator)) {
64 collsHome += File.separator;
65 }
66 String coll_home = collsHome + collID + File.separator;
67 //CollectionBuilder cb = new CollectionBuilder(site,collName,gHome,indexer);
68 CollectionBuilder cb = new CollectionBuilder(coll_home,collID, collName,collDesc, indexer);
69 }
70
71
72
73 public CollectionBuilder(String coll_home, String coll_id, String coll_name,String coll_desc, String ind)
74 {
75 this.collHome = coll_home;
76 this.collID = coll_id;
77 this.collName = coll_name;
78 this.collDesc = coll_desc;
79 this.indexer = ind;
80
81 if (!setupCollection()) {
82 System.err.println("Couldn't setup the collection. Quitting build");
83 return;
84 }
85
86
87 /**** get text annotation ****/
88
89 FTIndexing();
90
91
92 /**** extract keywords ****/
93
94 CKIndexing();
95
96 /**** write out the config file ****/
97 printConfig();
98 }
99
100
101
102 private boolean setupCollection()
103 {
104 // create the index directory
105 try {
106 File index_dir = new File(collHome + "building");
107 if (!index_dir.exists()) {
108 index_dir.mkdir();
109 } else if (!index_dir.isDirectory()) {
110 // index is present but is not a directory
111 System.err.println("Trying to create building dir but a file already exists at "+index_dir.toString());
112 return false;
113 }
114 } catch (Exception e) {
115 System.err.println("CollectionBuilder.setupCollection Error: "+e);
116 return false;
117 }
118
119 return true;
120 }
121
122 private void printConfig() {
123
124 String index_type="";
125 if (indexer.equals("luc")) {
126 index_type = "LUCENE";
127 } else if (indexer.equals("mg")) {
128 index_type = "MG";
129 }
130
131 try{
132 File target = new File(collHome + "config.xml");
133 PrintWriter out = new PrintWriter(new FileWriter(target),true);
134
135 StringBuffer buffer = new StringBuffer();
136 buffer.append("<collection name=\"");
137 buffer.append(collName);
138 buffer.append("\" description=\"");
139 buffer.append(collDesc);
140 buffer.append("\" engine=\"");
141 buffer.append(index_type);
142 buffer.append("\" size=\"");
143 buffer.append(String.valueOf(numDocs));
144 buffer.append("\" />");
145
146 out.print(buffer.toString());
147 out.close();
148
149 } catch (IOException e){ System.out.println("Error writing config file: " + e.toString());
150 }
151 }
152
153// private void printConfig()
154// {
155
156// String index_type="";
157// if (indexer.equals("luc")) {
158// index_type = "LUCENE";
159// } else if (indexer.equals("mg")) {
160// index_type = "MG";
161// }
162// /**** print buildConfig.xml ****/
163// try{
164// File target = new File(collHome + "building" + File.separator + "buildConfig.xml");
165// FileWriter fw = new FileWriter(target);
166// PrintWriter out = new PrintWriter(fw,true);
167
168// String str = "<buildConfig>\n";
169// str += "<metadataList/>\n";
170// //str += "<metadata name=\"numDocs\">" + String.valueOf(numDocs) + "</metadata>\n";
171// //str += "<metadata name=\"buildType\">" + indexer + "</metadata>\n";
172// //str += "</metadataList>\n";
173// str += "<serviceRackList>\n";
174// str += "<serviceRack name=\"Visualizer\">\n";
175// str += "<engineType name=\""+index_type+"\"/>\n";
176// str += "</serviceRack>\n";
177// str += "</serviceRackList>\n";
178// str += "</buildConfig>\n";
179// out.print(str);
180// out.close();
181// } catch (IOException e){ System.out.println("Error " + e.toString());}
182// }
183
184
185 private void CKIndexing()
186 {
187 CKWrapper ckw = new CKWrapper();
188
189 String in = collHome + "import"+File.separator;
190 String out = collHome + "building"+File.separator+"ck_index"+File.separator;
191
192 ckw.setCollectionName(collID);
193 ckw.setOutputDirectory(out);
194 ckw.setInputDirectory(in);
195 ckw.startIndexing();
196 }
197
198
199
200 private void FTIndexing()
201 {
202 String in = collHome + "import"+File.separator;
203 String out = collHome + "building"+File.separator + indexer + "_index"+File.separator;
204
205 if( indexer.equals("luc") ){
206 LuceneWrapper luc = new LuceneWrapper();
207 luc.setOutputDirectory(out);
208 luc.setInputDirectory(in);
209 luc.startIndexing();
210 }
211 else if( indexer.equals("mg") ){
212 MGWrapper mg = new MGWrapper();
213 mg.setCollectionName(collID);
214 mg.setOutputDirectory(out);
215 mg.setInputDirectory(in);
216 mg.startIndexing();
217 }
218 }
219}
220
221
222
223
Note: See TracBrowser for help on using the repository browser.