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