Index: trunk/WikiWord/WikiWord/src/main/java/de/brightbyte/wikiword/disambig/StoredMeaningFetcher.java |
— | — | @@ -4,27 +4,27 @@ |
5 | 5 | |
6 | 6 | import de.brightbyte.data.cursor.DataSet; |
7 | 7 | import de.brightbyte.util.PersistenceException; |
8 | | -import de.brightbyte.wikiword.ConceptType; |
9 | 8 | import de.brightbyte.wikiword.model.LocalConcept; |
10 | 9 | import de.brightbyte.wikiword.store.LocalConceptStore; |
| 10 | +import de.brightbyte.wikiword.store.WikiWordConceptStore.ConceptQuerySpec; |
11 | 11 | |
12 | 12 | public class StoredMeaningFetcher implements MeaningFetcher<LocalConcept> { |
13 | 13 | protected LocalConceptStore store; |
14 | | - protected ConceptType type; |
| 14 | + protected ConceptQuerySpec spec; |
15 | 15 | |
16 | 16 | public StoredMeaningFetcher(LocalConceptStore store) { |
17 | 17 | this(store, null); |
18 | 18 | } |
19 | 19 | |
20 | | - public StoredMeaningFetcher(LocalConceptStore store, ConceptType type) { |
| 20 | + public StoredMeaningFetcher(LocalConceptStore store, ConceptQuerySpec type) { |
21 | 21 | if (store==null) throw new NullPointerException(); |
22 | 22 | |
23 | 23 | this.store = store; |
24 | | - this.type = type; |
| 24 | + this.spec = type; |
25 | 25 | } |
26 | 26 | |
27 | 27 | public List<LocalConcept> getMeanings(String term) throws PersistenceException { |
28 | | - DataSet<LocalConcept> m = store.getMeanings(term, type); //FIXME: filter/cut-off rules, sort order! //XXX: relevance value? |
| 28 | + DataSet<LocalConcept> m = store.getMeanings(term, spec); //FIXME: filter/cut-off rules, sort order! //XXX: relevance value? |
29 | 29 | return m.load(); |
30 | 30 | } |
31 | 31 | |
Index: trunk/WikiWord/WikiWord/src/main/java/de/brightbyte/wikiword/store/StatisticsStore.java |
— | — | @@ -21,7 +21,7 @@ |
22 | 22 | * it's interpreted as a percentage of the total number of concepts. |
23 | 23 | * @return a random concept from the range specified by the top argument. |
24 | 24 | */ |
25 | | - public T pickRandomConcept(int top) |
| 25 | + public T pickRandomConcept(int top, WikiWordConceptStore.ConceptQuerySpec spec) |
26 | 26 | throws PersistenceException; |
27 | 27 | |
28 | 28 | } |
Index: trunk/WikiWord/WikiWord/src/main/java/de/brightbyte/wikiword/store/DatabaseLocalConceptStore.java |
— | — | @@ -116,10 +116,10 @@ |
117 | 117 | */ |
118 | 118 | } |
119 | 119 | |
120 | | - protected String meaningWhere(String term, ConceptType t) { |
| 120 | + protected String meaningWhere(String term, ConceptQuerySpec spec) { |
121 | 121 | String sql = " JOIN "+meaningTable.getSQLName()+" as M ON C.id = M.concept "; |
122 | 122 | sql += " WHERE M.term_text = "+database.quoteString(term)+" "; |
123 | | - if (t!=null) sql += " AND C.type = "+t.getCode()+" "; |
| 123 | + if (spec!=null && spec.getRequireType()!=null) sql += " AND C.type = "+spec.getRequireType().getCode()+" "; |
124 | 124 | sql += " ORDER BY freq DESC"; |
125 | 125 | return sql; |
126 | 126 | } |
— | — | @@ -145,30 +145,24 @@ |
146 | 146 | return corpus; |
147 | 147 | } |
148 | 148 | |
149 | | - public DataSet<LocalConcept> listMeanings(String term) throws PersistenceException { |
150 | | - return this.listMeanings(term, null); |
151 | | - } |
152 | | - |
| 149 | + /* |
153 | 150 | public DataSet<LocalConcept> listMeanings(String term, ConceptType t) |
154 | 151 | throws PersistenceException { |
155 | 152 | |
156 | | - String sql = referenceSelect("M.freq") + meaningWhere(term, t); |
| 153 | + String sql = conceptSelect("M.freq") + meaningWhere(term, t); |
157 | 154 | |
158 | 155 | return new QueryDataSet<LocalConcept>(database, getRowConceptFactory(), "listMeanings", sql, false); |
159 | 156 | } |
160 | | - |
161 | | - public LocalConcept getConceptByName(String name) throws PersistenceException { |
162 | | - return ((DatabaseLocalConceptInfoStore)getConceptInfoStore()).getConceptByName(name); |
| 157 | + */ |
| 158 | + |
| 159 | + public LocalConcept getConceptByName(String name, ConceptQuerySpec spec) throws PersistenceException { |
| 160 | + return ((DatabaseLocalConceptInfoStore)getConceptInfoStore()).getConceptByName(name, spec); |
163 | 161 | } |
164 | 162 | |
165 | | - public DataSet<LocalConcept> getMeanings(String term) throws PersistenceException { |
166 | | - return ((DatabaseLocalConceptInfoStore)getConceptInfoStore()).getMeanings(term); |
| 163 | + public DataSet<LocalConcept> getMeanings(String term, ConceptQuerySpec spec) throws PersistenceException { |
| 164 | + return ((DatabaseLocalConceptInfoStore)getConceptInfoStore()).getMeanings(term, spec); |
167 | 165 | } |
168 | 166 | |
169 | | - public DataSet<LocalConcept> getMeanings(String term, ConceptType t) throws PersistenceException { |
170 | | - return ((DatabaseLocalConceptInfoStore)getConceptInfoStore()).getMeanings(term, t); |
171 | | - } |
172 | | - |
173 | 167 | public TermReference pickRandomTerm(int top) throws PersistenceException { |
174 | 168 | return ((LocalStatisticsStore<LocalConcept>)getStatisticsStore()).pickRandomTerm(top); |
175 | 169 | } |
— | — | @@ -269,30 +263,56 @@ |
270 | 264 | } |
271 | 265 | |
272 | 266 | @Override |
273 | | - protected String conceptSelect(String card, String relev, boolean useDistrib) { |
274 | | - String distribJoin = !useDistrib ? "" : " JOIN " + database.getSQLTableName("degree", true) + " as DT ON DT.concept = C.id"; |
| 267 | + protected String conceptSelect(ConceptQuerySpec spec, String card, String relev) { |
| 268 | + boolean useDistrib = (relev!=null || (spec!=null && spec.getIncludeStatistics())) && areStatsComplete(); |
275 | 269 | |
276 | | - String sql = "SELECT C.id as cId, C.name as cName, C.type as cType, " + |
277 | | - " "+card+" as qFreq, "+relev+" as qConf, " + |
278 | | - " R.id as rcId, R.name as rcName, R.type as rcType, " + |
279 | | - " F.definition as fDefinition, " + |
280 | | - " I.inlinks as rInlinks, I.outlinks as rOutlinks, " + |
281 | | - " I.broader as rBroader, I.narrower as rNarrower, I.langlinks as rLanglinks, " + |
282 | | - " I.similar as rSimilar, I.related as rRelated, " + |
283 | | - " D.terms as dTerms" + |
284 | | - " FROM "+conceptTable.getSQLName()+" as C "+ |
285 | | - distribJoin+ |
286 | | - " LEFT JOIN "+aboutTable.getSQLName()+" as A ON A.concept = C.id "+ |
287 | | - " LEFT JOIN "+resourceTable.getSQLName()+" as R ON R.id = A.resource "+ |
288 | | - " LEFT JOIN "+definitionTable.getSQLName()+" as F ON F.concept = C.id "+ |
289 | | - " LEFT JOIN "+conceptInfoTable.getSQLName()+" as I ON I.concept = C.id "+ |
290 | | - " LEFT JOIN "+conceptDescriptionTable.getSQLName()+" as D ON D.concept = C.id "; |
| 270 | + String fields = "C.id as cId, C.name as cName, C.type as cType"; |
| 271 | + String tables = ""+conceptTable.getSQLName()+" as C "; |
291 | 272 | |
| 273 | + if (useDistrib) { |
| 274 | + tables += " JOIN " + database.getSQLTableName("degree", true) + " as DT ON DT.concept = C.id "; |
| 275 | + if (relev==null) relev = "DT.idf"; |
| 276 | + } else { |
| 277 | + relev = "-1"; |
| 278 | + } |
| 279 | + |
| 280 | + if (relev==null) relev = "-1"; |
| 281 | + if (card==null) card = "-1"; |
| 282 | + |
| 283 | + fields += ", "+card+" as qFreq, "+relev+" as qConf "; |
| 284 | + |
| 285 | + if (spec!=null && spec.getIncludeResource()) { |
| 286 | + fields += ", R.id as rcId, R.name as rcName, R.type as rcType "; |
| 287 | + tables += " LEFT JOIN "+aboutTable.getSQLName()+" as A ON A.concept = C.id "+ |
| 288 | + " LEFT JOIN "+resourceTable.getSQLName()+" as R ON R.id = A.resource "; |
| 289 | + } |
| 290 | + |
| 291 | + if (spec!=null && spec.getIncludeDefinition()) { |
| 292 | + fields += ", F.definition as fDefinition "; |
| 293 | + |
| 294 | + tables += " LEFT JOIN "+definitionTable.getSQLName()+" as F ON F.concept = C.id "; |
| 295 | + } |
| 296 | + |
| 297 | + if (spec!=null && spec.getIncludeRelations()) { |
| 298 | + fields += ", I.inlinks as rInlinks, I.outlinks as rOutlinks, " + |
| 299 | + " I.broader as rBroader, I.narrower as rNarrower, I.langlinks as rLanglinks, " + |
| 300 | + " I.similar as rSimilar, I.related as rRelated "; |
| 301 | + |
| 302 | + tables += " LEFT JOIN "+conceptInfoTable.getSQLName()+" as I ON I.concept = C.id "; |
| 303 | + } |
| 304 | + |
| 305 | + if (spec!=null && spec.getIncludeTerms()) { |
| 306 | + fields += ", D.terms as dTerms"; |
| 307 | + |
| 308 | + tables += " LEFT JOIN "+conceptDescriptionTable.getSQLName()+" as D ON D.concept = C.id "; |
| 309 | + } |
| 310 | + |
| 311 | + String sql = "SELECT " + fields + " FROM " + tables; |
292 | 312 | return sql; |
293 | 313 | } |
294 | 314 | |
295 | 315 | @Override |
296 | | - protected LocalConcept newConcept(Map<String, Object> m) throws PersistenceException { |
| 316 | + protected LocalConcept newConcept(Map<String, Object> m, ConceptQuerySpec spec) throws PersistenceException { |
297 | 317 | int id = asInt(m.get("cId")); |
298 | 318 | String name = asString(m.get("cName")); |
299 | 319 | ConceptType type = corpus.getConceptTypes().getType(asInt(m.get("cType"))); |
— | — | @@ -304,60 +324,61 @@ |
305 | 325 | String rcName = asString(m.get("rcName")); |
306 | 326 | ResourceType rcType = m.get("rcType") != null ? ResourceType.getType(asInt(m.get("rcType"))) : null; |
307 | 327 | |
308 | | - String definition = asString(m.get("fDefinition")); |
309 | | - |
310 | 328 | LocalConcept concept = new LocalConcept(getCorpus(), id, null, name); |
311 | 329 | concept.setCardinality(cardinality); |
312 | 330 | concept.setRelevance(relevance); |
| 331 | + concept.setType(type); |
313 | 332 | |
314 | | - LocalConcept[] inlinks = LocalConcept.parseList( asString(m.get("rInlinks")), getConceptFactory(), ((ConceptInfoStoreSchema)database).inLinksReferenceListEntry ); |
315 | | - LocalConcept[] outlinks = LocalConcept.parseList( asString(m.get("rOutlinks")), getConceptFactory(), ((ConceptInfoStoreSchema)database).outLinksReferenceListEntry ); |
316 | | - LocalConcept[] broader = LocalConcept.parseList( asString(m.get("rBroader")), getConceptFactory(), ((ConceptInfoStoreSchema)database).broaderReferenceListEntry ); |
317 | | - LocalConcept[] narrower = LocalConcept.parseList( asString(m.get("rNarrower")), getConceptFactory(), ((ConceptInfoStoreSchema)database).narrowerReferenceListEntry ); |
318 | | - LocalConcept[] langlinks = LocalConcept.parseList( asString(m.get("rLanglinks")), getConceptFactory(), ((ConceptInfoStoreSchema)database).langlinkReferenceListEntry ); |
319 | | - LocalConcept[] similar = LocalConcept.parseList( asString(m.get("rSimilar")), getConceptFactory(), ((ConceptInfoStoreSchema)database).similarReferenceListEntry ); |
320 | | - LocalConcept[] related = LocalConcept.parseList( asString(m.get("rRelated")), getConceptFactory(), ((ConceptInfoStoreSchema)database).relatedReferenceListEntry ); |
321 | | - TermReference[] terms = TermReference.parseList( asString(m.get("dTerms")), getConceptFactory(), ((ConceptInfoStoreSchema)database).termReferenceListEntry ); |
| 333 | + if (spec!=null && spec.getIncludeRelations()) { |
| 334 | + LocalConcept[] inlinks = LocalConcept.parseList( asString(m.get("rInlinks")), getConceptFactory(), ((ConceptInfoStoreSchema)database).inLinksReferenceListEntry ); |
| 335 | + LocalConcept[] outlinks = LocalConcept.parseList( asString(m.get("rOutlinks")), getConceptFactory(), ((ConceptInfoStoreSchema)database).outLinksReferenceListEntry ); |
| 336 | + LocalConcept[] broader = LocalConcept.parseList( asString(m.get("rBroader")), getConceptFactory(), ((ConceptInfoStoreSchema)database).broaderReferenceListEntry ); |
| 337 | + LocalConcept[] narrower = LocalConcept.parseList( asString(m.get("rNarrower")), getConceptFactory(), ((ConceptInfoStoreSchema)database).narrowerReferenceListEntry ); |
| 338 | + LocalConcept[] langlinks = LocalConcept.parseList( asString(m.get("rLanglinks")), getConceptFactory(), ((ConceptInfoStoreSchema)database).langlinkReferenceListEntry ); |
| 339 | + LocalConcept[] similar = LocalConcept.parseList( asString(m.get("rSimilar")), getConceptFactory(), ((ConceptInfoStoreSchema)database).similarReferenceListEntry ); |
| 340 | + LocalConcept[] related = LocalConcept.parseList( asString(m.get("rRelated")), getConceptFactory(), ((ConceptInfoStoreSchema)database).relatedReferenceListEntry ); |
| 341 | + |
| 342 | + ConceptRelations<LocalConcept> relations = new ConceptRelations<LocalConcept>(broader, narrower, inlinks, outlinks, similar, related, langlinks); |
| 343 | + concept.setRelations(relations); |
| 344 | + } |
322 | 345 | |
323 | | - WikiWordResource resource = rcId <= 0 ? null : new WikiWordResource(corpus, rcId, rcName, rcType); |
| 346 | + if (spec!=null && spec.getIncludeResource()) { |
| 347 | + WikiWordResource resource = rcId <= 0 ? null : new WikiWordResource(corpus, rcId, rcName, rcType); |
| 348 | + concept.setResource(resource); |
| 349 | + } |
324 | 350 | |
325 | | - concept.setResource(resource); |
326 | | - concept.setType(type); |
327 | | - concept.setDefinition(definition); |
328 | | - concept.setTerms(terms); |
| 351 | + if (spec!=null && spec.getIncludeDefinition()) { |
| 352 | + String definition = asString(m.get("fDefinition")); |
| 353 | + concept.setDefinition(definition); |
| 354 | + } |
329 | 355 | |
330 | | - ConceptRelations<LocalConcept> relations = new ConceptRelations<LocalConcept>(broader, narrower, inlinks, outlinks, similar, related, langlinks); |
331 | | - concept.setRelations(relations); |
| 356 | + if (spec!=null && spec.getIncludeTerms()) { |
| 357 | + TermReference[] terms = TermReference.parseList( asString(m.get("dTerms")), getConceptFactory(), ((ConceptInfoStoreSchema)database).termReferenceListEntry ); |
| 358 | + concept.setTerms(terms); |
| 359 | + } |
332 | 360 | |
333 | 361 | return concept; |
334 | 362 | } |
335 | 363 | |
336 | 364 | |
337 | | - public DataSet<LocalConcept> getMeanings(String term) |
| 365 | + public DataSet<LocalConcept> getMeanings(String term, ConceptQuerySpec spec) |
338 | 366 | throws PersistenceException { |
| 367 | + String sql = conceptSelect(spec, "M.freq") + meaningWhere(term, spec); |
339 | 368 | |
340 | | - return getMeanings(term, null); |
| 369 | + return new QueryDataSet<LocalConcept>(database, new ConceptFactory(spec), "getMeanins", sql, false); |
341 | 370 | } |
342 | 371 | |
343 | | - public DataSet<LocalConcept> getMeanings(String term, ConceptType t) |
344 | | - throws PersistenceException { |
345 | | - |
346 | | - String sql = conceptSelect("M.freq") + meaningWhere(term, t); |
347 | | - |
348 | | - return new QueryDataSet<LocalConcept>(database, new ConceptFactory(), "getMeanins", sql, false); |
349 | | - } |
350 | | - |
351 | 372 | |
352 | | - public LocalConcept getConceptByName(String name) throws PersistenceException { |
| 373 | + public LocalConcept getConceptByName(String name, ConceptQuerySpec spec) throws PersistenceException { |
353 | 374 | |
354 | | - String sql = conceptSelect("-1") + " WHERE C.name = "+database.quoteString(name); |
| 375 | + String sql = conceptSelect(spec, "-1") + " WHERE C.name = "+database.quoteString(name); |
355 | 376 | |
356 | 377 | try { |
357 | 378 | ResultSet row = executeQuery("getConcept", sql); |
358 | 379 | if (!row.next()) throw new PersistenceException("no concept found with name = "+name); |
359 | 380 | |
360 | 381 | Map<String, Object> data = DatabaseSchema.rowMap(row); |
361 | | - LocalConcept c = newConcept(data); |
| 382 | + LocalConcept c = newConcept(data, spec); |
362 | 383 | |
363 | 384 | return c; |
364 | 385 | } catch (SQLException e) { |
Index: trunk/WikiWord/WikiWord/src/main/java/de/brightbyte/wikiword/store/DatabaseWikiWordConceptStore.java |
— | — | @@ -6,9 +6,7 @@ |
7 | 7 | |
8 | 8 | import java.sql.ResultSet; |
9 | 9 | import java.sql.SQLException; |
10 | | -import java.util.ArrayList; |
11 | 10 | import java.util.HashMap; |
12 | | -import java.util.List; |
13 | 11 | import java.util.Map; |
14 | 12 | |
15 | 13 | import de.brightbyte.data.cursor.DataSet; |
— | — | @@ -22,7 +20,6 @@ |
23 | 21 | import de.brightbyte.util.PersistenceException; |
24 | 22 | import de.brightbyte.wikiword.ConceptType; |
25 | 23 | import de.brightbyte.wikiword.Corpus; |
26 | | -import de.brightbyte.wikiword.DatasetIdentifier; |
27 | 24 | import de.brightbyte.wikiword.TweakSet; |
28 | 25 | import de.brightbyte.wikiword.model.WikiWordConcept; |
29 | 26 | import de.brightbyte.wikiword.schema.ConceptInfoStoreSchema; |
— | — | @@ -36,8 +33,15 @@ |
37 | 34 | |
38 | 35 | |
39 | 36 | private class RowConceptFactory implements DatabaseDataSet.Factory<T> { |
| 37 | + private ConceptQuerySpec spec; |
| 38 | + |
| 39 | + public RowConceptFactory(ConceptQuerySpec spec) { |
| 40 | + super(); |
| 41 | + this.spec = spec; |
| 42 | + } |
| 43 | + |
40 | 44 | public T newInstance(ResultSet row) throws SQLException, PersistenceException { |
41 | | - return newConcept(row); |
| 45 | + return newConcept(row, spec); |
42 | 46 | } |
43 | 47 | } |
44 | 48 | |
— | — | @@ -56,7 +60,7 @@ |
57 | 61 | } |
58 | 62 | } |
59 | 63 | |
60 | | - private RowConceptFactory rowConceptFactory = new RowConceptFactory(); |
| 64 | + private RowConceptFactory rowConceptFactory = new RowConceptFactory(null); |
61 | 65 | private ConceptFactory conceptFactory = new ConceptFactory(); |
62 | 66 | |
63 | 67 | protected EntityTable conceptTable; |
— | — | @@ -91,7 +95,7 @@ |
92 | 96 | return conceptFactory; |
93 | 97 | } |
94 | 98 | |
95 | | - protected T newConcept(ResultSet row) throws SQLException, PersistenceException { |
| 99 | + protected T newConcept(ResultSet row, ConceptQuerySpec spec) throws SQLException, PersistenceException { |
96 | 100 | int id = row.getInt("cId"); |
97 | 101 | String name = asString(row.getObject("cName")); |
98 | 102 | int type = row.getInt("cType"); |
— | — | @@ -101,7 +105,7 @@ |
102 | 106 | return newConcept(id, name, getConceptType(type), card, relev); |
103 | 107 | } |
104 | 108 | |
105 | | - protected T newConcept(Map m) throws PersistenceException { |
| 109 | + protected T newConcept(Map m, ConceptQuerySpec spec) throws PersistenceException { |
106 | 110 | int id = asInt(m.get("cId")); |
107 | 111 | String name = asString(m.get("cName")); |
108 | 112 | int type = asInt(m.get("cType")); |
— | — | @@ -114,12 +118,14 @@ |
115 | 119 | protected abstract T newConcept(int id, String name, ConceptType type, int card, double relevance) throws PersistenceException; |
116 | 120 | protected abstract T[] newConceptArray(int n) ; |
117 | 121 | |
118 | | - protected String referenceSelect(String card) { |
119 | | - if (areStatsComplete()) return referenceSelect(card, "DT.idf", true); |
120 | | - else return referenceSelect(card, "-1", false); |
| 122 | + protected String conceptSelect(ConceptQuerySpec spec, String card) { |
| 123 | + if (areStatsComplete()) return conceptSelect(spec, card, "DT.idf"); |
| 124 | + else return conceptSelect(spec, card, null); |
121 | 125 | } |
122 | 126 | |
123 | | - protected String referenceSelect(String card, String relev, boolean useDistrib) { |
| 127 | + protected String conceptSelect(ConceptQuerySpec spec, String card, String relev) { |
| 128 | + boolean useDistrib = (relev!=null || (spec!=null && spec.getIncludeStatistics())) && areStatsComplete(); |
| 129 | + |
124 | 130 | if (card!=null) card = ", "+card; |
125 | 131 | |
126 | 132 | String sql = "SELECT C.id as cId, C.name as cName, C.type as cType " + |
— | — | @@ -142,32 +148,28 @@ |
143 | 149 | } |
144 | 150 | } |
145 | 151 | |
146 | | - public DataSet<? extends T> getConcepts(int[] ids) throws PersistenceException { |
147 | | - return getConceptInfoStore().getConcepts(ids); |
| 152 | + public DataSet<? extends T> getConcepts(int[] ids, ConceptQuerySpec spec) throws PersistenceException { |
| 153 | + return getConceptInfoStore().getConcepts(ids, spec); |
148 | 154 | } |
149 | 155 | |
150 | | - public T getConcept(int id) throws PersistenceException { |
151 | | - return getConceptInfoStore().getConcept(id); |
| 156 | + public T getConcept(int id, ConceptQuerySpec spec) throws PersistenceException { |
| 157 | + return getConceptInfoStore().getConcept(id, spec); |
152 | 158 | } |
153 | 159 | |
154 | | - public T getRandomConcept(int top) throws PersistenceException { |
155 | | - T r = pickRandomConcept(top); |
156 | | - return getConcept(r.getId()); |
| 160 | + public T getRandomConcept(int top, ConceptQuerySpec spec) throws PersistenceException { |
| 161 | + T r = getStatisticsStore().pickRandomConcept(top, spec); |
| 162 | + return getConcept(r.getId(), spec); |
157 | 163 | } |
158 | 164 | |
159 | | - public DataSet<T> getAllConcepts() throws PersistenceException { |
| 165 | + public DataSet<T> getAllConcepts(ConceptQuerySpec spec) throws PersistenceException { |
160 | 166 | try { |
161 | | - String sql = referenceSelect("-1"); |
| 167 | + String sql = conceptSelect(spec, "-1"); |
162 | 168 | return new ChunkedQueryDataSet<T>(database, getRowConceptFactory(), "getAllConcepts", "query", sql, null, null, conceptTable, "id", queryChunkSize); |
163 | 169 | } catch (SQLException e) { |
164 | 170 | throw new PersistenceException(e); |
165 | 171 | } |
166 | 172 | } |
167 | 173 | |
168 | | - public T pickRandomConcept(int top) throws PersistenceException { |
169 | | - return getStatisticsStore().pickRandomConcept(top); |
170 | | - } |
171 | | - |
172 | 174 | public int getNumberOfConcepts() throws PersistenceException { |
173 | 175 | if (numberOfConcepts<0) { |
174 | 176 | String sql = "select count(*) from "+conceptTable.getSQLName(); |
— | — | @@ -344,7 +346,7 @@ |
345 | 347 | } |
346 | 348 | } |
347 | 349 | |
348 | | - public T pickRandomConcept(int top) |
| 350 | + public T pickRandomConcept(int top, ConceptQuerySpec spec) |
349 | 351 | throws PersistenceException { |
350 | 352 | |
351 | 353 | if (!areStatsComplete()) throw new IllegalStateException("satistics need to be built before accessing node degree!"); |
— | — | @@ -354,13 +356,13 @@ |
355 | 357 | |
356 | 358 | int r = (int)Math.floor(Math.random() * top) +1; |
357 | 359 | |
358 | | - String sql = referenceSelect("DT.in_degree", "DT.idf", true) |
| 360 | + String sql = conceptSelect(spec, "DT.in_degree", "DT.idf") |
359 | 361 | + " WHERE in_rank = "+r; |
360 | 362 | |
361 | 363 | try { |
362 | 364 | T pick = null; |
363 | 365 | ResultSet rs = executeQuery("pickRandomConcept", sql); |
364 | | - if (rs.next()) pick = newConcept(rs); |
| 366 | + if (rs.next()) pick = newConcept(rs, spec); |
365 | 367 | rs.close(); |
366 | 368 | return pick; |
367 | 369 | } catch (SQLException e) { |
— | — | @@ -378,10 +380,17 @@ |
379 | 381 | |
380 | 382 | |
381 | 383 | protected class ConceptFactory implements DatabaseDataSet.Factory<C> { |
| 384 | + private ConceptQuerySpec spec; |
| 385 | + |
| 386 | + public ConceptFactory(ConceptQuerySpec spec) { |
| 387 | + super(); |
| 388 | + this.spec = spec; |
| 389 | + } |
| 390 | + |
382 | 391 | public C newInstance(ResultSet row) throws SQLException, PersistenceException { |
383 | 392 | Map<String, Object> m = DatabaseSchema.rowMap(row); |
384 | 393 | |
385 | | - return newConcept(m); |
| 394 | + return newConcept(m, spec); |
386 | 395 | } |
387 | 396 | } |
388 | 397 | |
— | — | @@ -395,24 +404,24 @@ |
396 | 405 | conceptInfoTable = (EntityTable)database.getTable("concept_info"); |
397 | 406 | } |
398 | 407 | |
399 | | - protected String conceptSelect(String card) { |
400 | | - if (areStatsComplete()) return conceptSelect(card, "DT.idf", true); |
401 | | - else return conceptSelect(card, "-1", false); |
| 408 | + protected String conceptSelect(ConceptQuerySpec spec, String card) { |
| 409 | + if (areStatsComplete()) return conceptSelect(spec, card, "DT.idf"); |
| 410 | + else return conceptSelect(spec, card, "-1"); |
402 | 411 | } |
403 | 412 | |
404 | | - protected abstract String conceptSelect(String card, String relev, boolean useDistrib); |
| 413 | + protected abstract String conceptSelect(ConceptQuerySpec spec, String card, String relev); |
405 | 414 | |
406 | | - public C getConcept(int id) |
| 415 | + public C getConcept(int id, ConceptQuerySpec spec) |
407 | 416 | throws PersistenceException { |
408 | 417 | |
409 | | - String sql = conceptSelect("-1") + " WHERE C.id = "+id; |
| 418 | + String sql = conceptSelect(spec, "-1") + " WHERE C.id = "+id; |
410 | 419 | |
411 | 420 | try { |
412 | 421 | ResultSet row = executeQuery("getConcept", sql); |
413 | 422 | if (!row.next()) throw new PersistenceException("no concept found with id = "+id); |
414 | 423 | |
415 | 424 | Map<String, Object> data = DatabaseSchema.rowMap(row); |
416 | | - C c = newConcept(data); |
| 425 | + C c = newConcept(data, spec); |
417 | 426 | |
418 | 427 | return c; |
419 | 428 | } catch (SQLException e) { |
— | — | @@ -420,30 +429,30 @@ |
421 | 430 | } |
422 | 431 | } |
423 | 432 | |
424 | | - public DataSet<C> getAllConcepts() |
| 433 | + public DataSet<C> getAllConcepts(ConceptQuerySpec spec) |
425 | 434 | throws PersistenceException { |
426 | 435 | |
427 | 436 | try { |
428 | | - String sql = conceptSelect("-1"); |
429 | | - return new ChunkedQueryDataSet<C>(database, new ConceptFactory(), "getAllConcepts", "query", sql, null, null, conceptTable, "id", queryChunkSize); |
| 437 | + String sql = conceptSelect(spec, "-1"); |
| 438 | + return new ChunkedQueryDataSet<C>(database, new ConceptFactory(spec), "getAllConcepts", "query", sql, null, null, conceptTable, "id", queryChunkSize); |
430 | 439 | } catch (SQLException e) { |
431 | 440 | throw new PersistenceException(e); |
432 | 441 | } |
433 | 442 | } |
434 | 443 | |
435 | | - public DataSet<C> getConcepts(int[] ids) |
| 444 | + public DataSet<C> getConcepts(int[] ids, ConceptQuerySpec spec) |
436 | 445 | throws PersistenceException { |
437 | 446 | |
438 | 447 | try { |
439 | | - String sql = conceptSelect("-1"); |
| 448 | + String sql = conceptSelect(spec, "-1"); |
440 | 449 | sql += " WHERE C.id IN " + database.encodeSet(ids); |
441 | | - return new QueryDataSet<C>(database, new ConceptFactory(), "getConcepts", sql, false); |
| 450 | + return new QueryDataSet<C>(database, new ConceptFactory(spec), "getConcepts", sql, false); |
442 | 451 | } catch (SQLException e) { |
443 | 452 | throw new PersistenceException(e); |
444 | 453 | } |
445 | 454 | } |
446 | 455 | |
447 | | - protected abstract C newConcept(Map<String, Object> data) throws PersistenceException; |
| 456 | + protected abstract C newConcept(Map<String, Object> data, ConceptQuerySpec spec) throws PersistenceException; |
448 | 457 | |
449 | 458 | } |
450 | 459 | |
Index: trunk/WikiWord/WikiWord/src/main/java/de/brightbyte/wikiword/store/DatabaseGlobalConceptStore.java |
— | — | @@ -124,12 +124,14 @@ |
125 | 125 | return sql; |
126 | 126 | } |
127 | 127 | |
| 128 | + /* |
128 | 129 | public DataSet<GlobalConcept> listMeanings(String lang, String term) |
129 | 130 | throws PersistenceException { |
130 | 131 | |
131 | | - String sql = referenceSelect("M.freq") + meaningsSQL(lang, term); |
| 132 | + String sql = conceptSelect("M.freq") + meaningsSQL(lang, term); |
132 | 133 | return new QueryDataSet<GlobalConcept>(database, getRowConceptFactory(), "listMeanings", sql, false); |
133 | 134 | } |
| 135 | + */ |
134 | 136 | |
135 | 137 | protected void registerLocalStore(DatabaseLocalConceptStore store) throws PersistenceException { |
136 | 138 | trace("registered local store for "+store.getCorpus().getLanguage()); |
— | — | @@ -210,12 +212,12 @@ |
211 | 213 | } |
212 | 214 | } |
213 | 215 | |
214 | | - public DataSet<GlobalConcept> getMeanings(String lang, String term) throws PersistenceException { |
215 | | - return ((DatabaseGlobalConceptInfoStore)getConceptInfoStore()).getMeanings(lang, term); |
| 216 | + public DataSet<GlobalConcept> getMeanings(String lang, String term, ConceptQuerySpec spec) throws PersistenceException { |
| 217 | + return ((DatabaseGlobalConceptInfoStore)getConceptInfoStore()).getMeanings(lang, term, spec); |
216 | 218 | } |
217 | 219 | |
218 | | - public List<LocalConcept> getLocalConcepts(int id) throws PersistenceException { |
219 | | - return ((DatabaseGlobalConceptInfoStore)getConceptInfoStore()).getLocalConcepts(id); |
| 220 | + public List<LocalConcept> getLocalConcepts(int id, ConceptQuerySpec spec) throws PersistenceException { |
| 221 | + return ((DatabaseGlobalConceptInfoStore)getConceptInfoStore()).getLocalConcepts(id, spec); |
220 | 222 | } |
221 | 223 | |
222 | 224 | ///////////////////////////////////////////////////////////////////////////////////////////// |
— | — | @@ -236,23 +238,42 @@ |
237 | 239 | } |
238 | 240 | |
239 | 241 | @Override |
240 | | - protected String conceptSelect(String card, String relev, boolean useDistrib) { |
241 | | - String distribJoin = !useDistrib ? "" : " JOIN " + database.getSQLTableName("degree", true) + " as DT ON DT.concept = C.id"; |
242 | | - |
243 | | - return "SELECT C.id as cId, C.name as cName, " + |
244 | | - "C.language_bits as cLangBits, C.language_count as cLangCount, " + |
245 | | - "C.type as cType, " + |
246 | | - " "+card+" as qFreq, "+relev+" as qConf, " + |
247 | | - " I.inlinks as rInlinks, I.outlinks as rOutlinks, " + |
248 | | - " I.broader as rBroader, I.narrower as rNarrower, " + |
249 | | - " I.similar as rSimilar, I.related as rRelated, I.langlinks as rLanglinks " + |
250 | | - " FROM "+conceptTable.getSQLName()+" as C "+ |
251 | | - distribJoin+ |
252 | | - " LEFT JOIN "+conceptInfoTable.getSQLName()+" as I ON I.concept = C.id "; |
| 242 | + protected String conceptSelect(ConceptQuerySpec spec, String card, String relev) { |
| 243 | + boolean useDistrib = (relev!=null || (spec!=null && spec.getIncludeStatistics())) && areStatsComplete(); |
| 244 | + |
| 245 | + String fields = "C.id as cId, C.name as cName, C.type as cType, " + |
| 246 | + "C.language_bits as cLangBits, C.language_count as cLangCount "; |
| 247 | + |
| 248 | + String tables = ""+conceptTable.getSQLName()+" as C "; |
| 249 | + |
| 250 | + if (useDistrib) { |
| 251 | + tables += " JOIN " + database.getSQLTableName("degree", true) + " as DT ON DT.concept = C.id "; |
| 252 | + if (relev==null) relev = "DT.idf"; |
| 253 | + } else { |
| 254 | + relev = "-1"; |
| 255 | + } |
| 256 | + |
| 257 | + if (relev==null) relev = "-1"; |
| 258 | + if (card==null) card = "-1"; |
| 259 | + |
| 260 | + fields += ", "+card+" as qFreq, "+relev+" as qConf "; |
| 261 | + |
| 262 | + if (spec!=null && spec.getIncludeRelations()) { |
| 263 | + fields += ", I.inlinks as rInlinks, I.outlinks as rOutlinks, " + |
| 264 | + " I.broader as rBroader, I.narrower as rNarrower, I.langlinks as rLanglinks, " + |
| 265 | + " I.similar as rSimilar, I.related as rRelated "; |
| 266 | + |
| 267 | + tables += " LEFT JOIN "+conceptInfoTable.getSQLName()+" as I ON I.concept = C.id "; |
| 268 | + } |
| 269 | + |
| 270 | + //TODO: include features! |
| 271 | + |
| 272 | + String sql = "SELECT " + fields + " FROM " + tables; |
| 273 | + return sql; |
253 | 274 | } |
254 | 275 | |
255 | 276 | @Override |
256 | | - protected GlobalConcept newConcept(Map<String, Object> m) throws PersistenceException { |
| 277 | + protected GlobalConcept newConcept(Map<String, Object> m, ConceptQuerySpec spec) throws PersistenceException { |
257 | 278 | try { |
258 | 279 | int id = asInt(m.get("cId")); |
259 | 280 | int langBits = asInt(m.get("cLangBits")); |
— | — | @@ -266,27 +287,32 @@ |
267 | 288 | Corpus[] languages = ((GlobalConceptStoreSchema)DatabaseGlobalConceptStore.this.database).getLanguages(langBits); |
268 | 289 | |
269 | 290 | GlobalConcept concept = new GlobalConcept(getDatasetIdentifier(), id, type); |
| 291 | + concept.setName(name); |
| 292 | + concept.setLanguages(languages); |
| 293 | + concept.setType(type); |
270 | 294 | concept.setCardinality(cardinality); |
271 | 295 | concept.setRelevance(relevance); |
272 | 296 | |
273 | | - GlobalConcept[] inlinks = GlobalConcept.parseList( asString(m.get("rInlinks")), getConceptFactory(), ((ConceptInfoStoreSchema)database).inLinksReferenceListEntry ); |
274 | | - GlobalConcept[] outlinks = GlobalConcept.parseList( asString(m.get("rOutlinks")), getConceptFactory(), ((ConceptInfoStoreSchema)database).outLinksReferenceListEntry ); |
275 | | - GlobalConcept[] broader = GlobalConcept.parseList( asString(m.get("rBroader")), getConceptFactory(), ((ConceptInfoStoreSchema)database).broaderReferenceListEntry ); |
276 | | - GlobalConcept[] narrower = GlobalConcept.parseList( asString(m.get("rNarrower")), getConceptFactory(), ((ConceptInfoStoreSchema)database).narrowerReferenceListEntry ); |
277 | | - GlobalConcept[] langlinks = GlobalConcept.parseList( asString(m.get("rLanglinks")), getConceptFactory(), ((ConceptInfoStoreSchema)database).langlinkReferenceListEntry ); |
278 | | - GlobalConcept[] similar = GlobalConcept.parseList( asString(m.get("rSimilar")), getConceptFactory(), ((ConceptInfoStoreSchema)database).similarReferenceListEntry ); |
279 | | - GlobalConcept[] related = GlobalConcept.parseList( asString(m.get("rRelated")), getConceptFactory(), ((ConceptInfoStoreSchema)database).relatedReferenceListEntry ); |
| 297 | + if (spec!=null && spec.getIncludeRelations()) { |
| 298 | + GlobalConcept[] inlinks = GlobalConcept.parseList( asString(m.get("rInlinks")), getConceptFactory(), ((ConceptInfoStoreSchema)database).inLinksReferenceListEntry ); |
| 299 | + GlobalConcept[] outlinks = GlobalConcept.parseList( asString(m.get("rOutlinks")), getConceptFactory(), ((ConceptInfoStoreSchema)database).outLinksReferenceListEntry ); |
| 300 | + GlobalConcept[] broader = GlobalConcept.parseList( asString(m.get("rBroader")), getConceptFactory(), ((ConceptInfoStoreSchema)database).broaderReferenceListEntry ); |
| 301 | + GlobalConcept[] narrower = GlobalConcept.parseList( asString(m.get("rNarrower")), getConceptFactory(), ((ConceptInfoStoreSchema)database).narrowerReferenceListEntry ); |
| 302 | + GlobalConcept[] langlinks = GlobalConcept.parseList( asString(m.get("rLanglinks")), getConceptFactory(), ((ConceptInfoStoreSchema)database).langlinkReferenceListEntry ); |
| 303 | + GlobalConcept[] similar = GlobalConcept.parseList( asString(m.get("rSimilar")), getConceptFactory(), ((ConceptInfoStoreSchema)database).similarReferenceListEntry ); |
| 304 | + GlobalConcept[] related = GlobalConcept.parseList( asString(m.get("rRelated")), getConceptFactory(), ((ConceptInfoStoreSchema)database).relatedReferenceListEntry ); |
| 305 | + |
| 306 | + ConceptRelations<GlobalConcept> relations = new ConceptRelations<GlobalConcept>(broader, narrower, inlinks, outlinks, similar, related, langlinks); |
| 307 | + concept.setRelations(relations); |
| 308 | + } |
280 | 309 | |
281 | | - ConceptRelations<GlobalConcept> relations = new ConceptRelations<GlobalConcept>(broader, narrower, inlinks, outlinks, similar, related, langlinks); |
282 | | - concept.setRelations(relations); |
283 | | - |
284 | 310 | return concept; |
285 | 311 | } catch (SQLException e) { |
286 | 312 | throw new PersistenceException(e); |
287 | 313 | } |
288 | 314 | } |
289 | 315 | |
290 | | - protected LocalConcept getLocalConcept(int id, DatabaseLocalConceptStore store) throws PersistenceException { |
| 316 | + protected LocalConcept getLocalConcept(int id, ConceptQuerySpec spec, DatabaseLocalConceptStore store) throws PersistenceException { |
291 | 317 | String lang = store.getCorpus().getLanguage(); |
292 | 318 | String sql = "select local_concept" |
293 | 319 | +" from "+originTable.getSQLName() |
— | — | @@ -297,13 +323,13 @@ |
298 | 324 | Integer localId = asInt(database.executeSingleValueQuery("getConceptDescription", sql)); |
299 | 325 | if (localId==null) throw new PersistenceException("concept #"+id+" has no description in language "+lang); |
300 | 326 | |
301 | | - return store.getConceptInfoStore().getConcept(localId); |
| 327 | + return store.getConceptInfoStore().getConcept(localId, spec); |
302 | 328 | } catch (SQLException e) { |
303 | 329 | throw new PersistenceException(e); |
304 | 330 | } |
305 | 331 | } |
306 | 332 | |
307 | | - public List<LocalConcept> getLocalConcepts(int id) throws PersistenceException { |
| 333 | + public List<LocalConcept> getLocalConcepts(int id, ConceptQuerySpec spec) throws PersistenceException { |
308 | 334 | List<LocalConcept> m = new ArrayList<LocalConcept>(); |
309 | 335 | |
310 | 336 | String sql = "select lang, local_concept" |
— | — | @@ -315,7 +341,7 @@ |
316 | 342 | while (res.next()) { |
317 | 343 | String lang = asString(res.getObject("lang")); |
318 | 344 | DatabaseLocalConceptStore store = getLocalConceptStore(lang); |
319 | | - LocalConcept c = getLocalConcept(id, store); |
| 345 | + LocalConcept c = getLocalConcept(id, spec, store); |
320 | 346 | m.add(c); |
321 | 347 | } |
322 | 348 | |
— | — | @@ -326,11 +352,11 @@ |
327 | 353 | } |
328 | 354 | } |
329 | 355 | |
330 | | - public DataSet<GlobalConcept> getMeanings(String lang, String term) |
| 356 | + public DataSet<GlobalConcept> getMeanings(String lang, String term, ConceptQuerySpec spec) |
331 | 357 | throws PersistenceException { |
332 | 358 | |
333 | | - String sql = conceptSelect("M.freq") + meaningsSQL(lang, term); |
334 | | - return new QueryDataSet<GlobalConcept>(database, new ConceptFactory(), "getMeanings", sql, false); |
| 359 | + String sql = conceptSelect(spec, "M.freq") + meaningsSQL(lang, term); |
| 360 | + return new QueryDataSet<GlobalConcept>(database, new ConceptFactory(spec), "getMeanings", sql, false); |
335 | 361 | } |
336 | 362 | } |
337 | 363 | |
Index: trunk/WikiWord/WikiWord/src/main/java/de/brightbyte/wikiword/store/LocalConceptStore.java |
— | — | @@ -2,9 +2,9 @@ |
3 | 3 | |
4 | 4 | import de.brightbyte.data.cursor.DataSet; |
5 | 5 | import de.brightbyte.util.PersistenceException; |
6 | | -import de.brightbyte.wikiword.ConceptType; |
7 | 6 | import de.brightbyte.wikiword.model.LocalConcept; |
8 | 7 | import de.brightbyte.wikiword.model.TermReference; |
| 8 | +import de.brightbyte.wikiword.store.WikiWordConceptStore.ConceptQuerySpec; |
9 | 9 | |
10 | 10 | |
11 | 11 | /** |
— | — | @@ -12,15 +12,8 @@ |
13 | 13 | */ |
14 | 14 | public interface LocalConceptStore extends WikiWordConceptStore<LocalConcept>, WikiWordLocalStore { |
15 | 15 | |
16 | | - /* |
17 | | - public abstract DataSet<ConceptReference> getBroaderConcepts() throws PersistenceException; |
18 | | - public abstract DataSet<ConceptReference> getNarrowerConcepts() throws PersistenceException; |
19 | | - */ |
20 | | - |
21 | | - public abstract DataSet<LocalConcept> getMeanings(String term, ConceptType t) throws PersistenceException; |
| 16 | + public abstract DataSet<LocalConcept> getMeanings(String term, ConceptQuerySpec spec) throws PersistenceException; |
22 | 17 | |
23 | | - public abstract DataSet<LocalConcept> getMeanings(String term) throws PersistenceException; |
24 | | - |
25 | 18 | public int getNumberOfTerms() throws PersistenceException; |
26 | 19 | |
27 | 20 | public abstract DataSet<TermReference> getAllTerms() throws PersistenceException; |
— | — | @@ -41,6 +34,6 @@ |
42 | 35 | public TermReference pickRandomTerm(int top) |
43 | 36 | throws PersistenceException; |
44 | 37 | |
45 | | - public LocalConcept getConceptByName(String name) throws PersistenceException; |
| 38 | + public LocalConcept getConceptByName(String name, ConceptQuerySpec spec) throws PersistenceException; |
46 | 39 | |
47 | 40 | } |
Index: trunk/WikiWord/WikiWord/src/main/java/de/brightbyte/wikiword/store/WikiWordConceptStore.java |
— | — | @@ -7,8 +7,64 @@ |
8 | 8 | |
9 | 9 | |
10 | 10 | public interface WikiWordConceptStore<T extends WikiWordConcept> extends WikiWordConceptStoreBase { |
| 11 | + |
| 12 | + public static class ConceptQuerySpec { |
| 13 | + private boolean includeRelations; |
| 14 | + private boolean includeStatistics; |
| 15 | + private boolean includeResource; |
| 16 | + private boolean includeTerms; |
| 17 | + private ConceptType requireType; |
| 18 | + private boolean includeDefinition; |
| 19 | + |
| 20 | + public boolean getIncludeRelations() { |
| 21 | + return includeRelations; |
| 22 | + } |
| 23 | + public void setIncludeRelations(boolean includeRelations) { |
| 24 | + this.includeRelations = includeRelations; |
| 25 | + } |
| 26 | + |
| 27 | + public ConceptType getRequireType() { |
| 28 | + return requireType; |
| 29 | + } |
| 30 | + |
| 31 | + public void setRequireType(ConceptType requireType) { |
| 32 | + this.requireType = requireType; |
| 33 | + } |
| 34 | + |
| 35 | + public boolean getIncludeStatistics() { |
| 36 | + return includeStatistics; |
| 37 | + } |
| 38 | + |
| 39 | + public void setIncludeStatistics(boolean includeStatistics) { |
| 40 | + this.includeStatistics = includeStatistics; |
| 41 | + } |
| 42 | + |
| 43 | + public boolean getIncludeDefinition() { |
| 44 | + return includeDefinition; |
| 45 | + } |
| 46 | + |
| 47 | + public void setIncludeDefinition(boolean includeDefinition) { |
| 48 | + this.includeDefinition = includeDefinition; |
| 49 | + } |
| 50 | + |
| 51 | + public boolean getIncludeResource() { |
| 52 | + return includeResource; |
| 53 | + } |
| 54 | + |
| 55 | + public void setIncludeResource(boolean includeResource) { |
| 56 | + this.includeResource = includeResource; |
| 57 | + } |
| 58 | + |
| 59 | + public boolean getIncludeTerms() { |
| 60 | + return includeTerms; |
| 61 | + } |
| 62 | + |
| 63 | + public void setIncludeTerms(boolean includeTerms) { |
| 64 | + this.includeTerms = includeTerms; |
| 65 | + } |
| 66 | + } |
11 | 67 | |
12 | | - public DataSet<? extends T> getAllConcepts() throws PersistenceException; |
| 68 | + public DataSet<? extends T> getAllConcepts(ConceptQuerySpec spec) throws PersistenceException; |
13 | 69 | |
14 | 70 | public ConceptType getConceptType(int type) throws PersistenceException; |
15 | 71 | |
— | — | @@ -17,21 +73,11 @@ |
18 | 74 | public FeatureStore<T, Integer> getFeatureStore() throws PersistenceException; |
19 | 75 | public ProximityStore<T, Integer> getProximityStore() throws PersistenceException; |
20 | 76 | |
21 | | - public T getConcept(int id) throws PersistenceException; |
| 77 | + public T getConcept(int id, ConceptQuerySpec spec) throws PersistenceException; |
22 | 78 | |
23 | | - public DataSet<? extends T> getConcepts(int[] ids) throws PersistenceException; |
| 79 | + public DataSet<? extends T> getConcepts(int[] ids, ConceptQuerySpec spec) throws PersistenceException; |
24 | 80 | |
25 | 81 | /** |
26 | | - * Returns a WikiWordConceptReference for a random concept from the top-n |
27 | | - * concepts with repect to in-degree. |
28 | | - * @param top the maximum rank of the concept to be returned. If top is 0, |
29 | | - * any concept from the full range may be returned. If it is negative, |
30 | | - * it's interpreted as a percentage of the total number of concepts. |
31 | | - * @return a random concept from the range specified by the top argument. |
32 | | - */ |
33 | | - public T pickRandomConcept(int top) throws PersistenceException; |
34 | | - |
35 | | - /** |
36 | 82 | * Returns a WikiWordConcept for a random concept from the top-n |
37 | 83 | * concepts with repect to in-degree. |
38 | 84 | * @param top the maximum rank of the concept to be returned. If top is 0, |
— | — | @@ -39,7 +85,7 @@ |
40 | 86 | * it's interpreted as a percentage of the total number of concepts. |
41 | 87 | * @return a random concept from the range specified by the top argument. |
42 | 88 | */ |
43 | | - public T getRandomConcept(int top) throws PersistenceException; |
| 89 | + public T getRandomConcept(int top, ConceptQuerySpec spec) throws PersistenceException; |
44 | 90 | |
45 | 91 | /** |
46 | 92 | * Returns the number of concepts in the store. Since the content of a concept |
Index: trunk/WikiWord/WikiWord/src/main/java/de/brightbyte/wikiword/store/GlobalConceptStore.java |
— | — | @@ -14,10 +14,8 @@ |
15 | 15 | */ |
16 | 16 | public interface GlobalConceptStore extends WikiWordConceptStore<GlobalConcept> { |
17 | 17 | |
18 | | - public DataSet<GlobalConcept> getAllConcepts() throws PersistenceException; |
19 | | - |
20 | 18 | //TODO: relevance limit? order? |
21 | | - public DataSet<GlobalConcept> getMeanings(String lang, String term) throws PersistenceException; |
| 19 | + public DataSet<GlobalConcept> getMeanings(String lang, String term, ConceptQuerySpec spec) throws PersistenceException; |
22 | 20 | |
23 | 21 | //public abstract ResultSet queryTermRefersTo() throws PersistenceException; |
24 | 22 | |
— | — | @@ -28,7 +26,7 @@ |
29 | 27 | |
30 | 28 | public LocalConceptStore getLocalConceptStore(Corpus corpus) throws PersistenceException; |
31 | 29 | |
32 | | - public List<LocalConcept> getLocalConcepts(int id) throws PersistenceException; |
| 30 | + public List<LocalConcept> getLocalConcepts(int id, ConceptQuerySpec spec) throws PersistenceException; |
33 | 31 | |
34 | 32 | public Corpus[] getLanguages() throws PersistenceException; |
35 | 33 | } |
Index: trunk/WikiWord/WikiWord/src/main/java/de/brightbyte/wikiword/model/GlobalConcept.java |
— | — | @@ -6,11 +6,13 @@ |
7 | 7 | |
8 | 8 | import de.brightbyte.util.PersistenceException; |
9 | 9 | import de.brightbyte.wikiword.ConceptType; |
| 10 | +import de.brightbyte.wikiword.Corpus; |
10 | 11 | import de.brightbyte.wikiword.DatasetIdentifier; |
11 | 12 | |
12 | 13 | |
13 | 14 | public class GlobalConcept extends WikiWordConcept { |
14 | | - protected Map<String, LocalConcept> concepts; |
| 15 | + private Map<String, LocalConcept> concepts; |
| 16 | + private Corpus[] languages; |
15 | 17 | |
16 | 18 | public GlobalConcept(DatasetIdentifier dataset, int id, ConceptType type) { |
17 | 19 | super(dataset, id, type); |
— | — | @@ -20,15 +22,25 @@ |
21 | 23 | return concepts; |
22 | 24 | } |
23 | 25 | |
| 26 | + public Corpus[] getLanguages() throws PersistenceException { |
| 27 | + return languages; |
| 28 | + } |
| 29 | + |
24 | 30 | public LocalConcept getLocalConcept(String lang) throws PersistenceException { |
25 | 31 | if (concepts==null) return null; |
26 | 32 | return concepts.get(lang); |
27 | 33 | } |
28 | 34 | |
29 | 35 | public void setConcepts(Map<String, LocalConcept> concepts) { |
| 36 | + if (this.concepts!=null) throw new IllegalStateException("property already initialized"); |
30 | 37 | this.concepts = concepts; |
31 | 38 | } |
32 | 39 | |
| 40 | + public void setLanguages(Corpus[] languages) { |
| 41 | + if (this.languages!=null) throw new IllegalStateException("property already initialized"); |
| 42 | + this.languages = languages; |
| 43 | + } |
| 44 | + |
33 | 45 | public void setConcepts(List<LocalConcept> concepts) { |
34 | 46 | Map<String, LocalConcept> m = new HashMap<String, LocalConcept>(); |
35 | 47 | |
Index: trunk/WikiWord/WikiWord/src/main/java/de/brightbyte/wikiword/query/QueryConsole.java |
— | — | @@ -35,13 +35,27 @@ |
36 | 36 | import de.brightbyte.wikiword.store.LocalConceptStore; |
37 | 37 | import de.brightbyte.wikiword.store.ProximityStore; |
38 | 38 | import de.brightbyte.wikiword.store.WikiWordConceptStore; |
| 39 | +import de.brightbyte.wikiword.store.WikiWordConceptStore.ConceptQuerySpec; |
39 | 40 | |
40 | 41 | public class QueryConsole extends ConsoleApp<WikiWordConceptStore> { |
41 | 42 | |
42 | 43 | protected Disambiguator disambiguator; |
| 44 | + protected ConceptQuerySpec minimalConceptSpec; |
| 45 | + protected ConceptQuerySpec resolvedConceptSpec; |
| 46 | + protected ConceptQuerySpec detailedConceptSpec; |
43 | 47 | |
44 | 48 | public QueryConsole() { |
45 | 49 | super(true, true); |
| 50 | + |
| 51 | + minimalConceptSpec = new ConceptQuerySpec(); |
| 52 | + resolvedConceptSpec = new ConceptQuerySpec(); |
| 53 | + resolvedConceptSpec.setIncludeDefinition(true); |
| 54 | + resolvedConceptSpec.setIncludeResource(true); |
| 55 | + |
| 56 | + detailedConceptSpec = new ConceptQuerySpec(); |
| 57 | + detailedConceptSpec.setIncludeDefinition(true); |
| 58 | + detailedConceptSpec.setIncludeResource(true); |
| 59 | + detailedConceptSpec.setIncludeRelations(true); |
46 | 60 | } |
47 | 61 | |
48 | 62 | protected static class ConsoleOutput { |
— | — | @@ -231,7 +245,7 @@ |
232 | 246 | String n = r.getName(); |
233 | 247 | |
234 | 248 | if (n==null && c < maxAutoResolve) { |
235 | | - WikiWordConcept x = ((WikiWordConceptStore)conceptStore).getConcept(id); |
| 249 | + WikiWordConcept x = ((WikiWordConceptStore)conceptStore).getConcept(id, resolvedConceptSpec); |
236 | 250 | r = x; |
237 | 251 | a = r; |
238 | 252 | } |
— | — | @@ -415,27 +429,27 @@ |
416 | 430 | } |
417 | 431 | |
418 | 432 | public void listConcepts(ConsoleOutput out) throws PersistenceException { |
419 | | - DataSet<? extends LocalConcept> meanings = getLocalConceptStore().getAllConcepts(); |
| 433 | + DataSet<? extends LocalConcept> meanings = getLocalConceptStore().getAllConcepts(minimalConceptSpec); |
420 | 434 | out.writeConcepts(meanings); |
421 | 435 | } |
422 | 436 | |
423 | 437 | public void listMeaningsLocal(String term, ConsoleOutput out) throws PersistenceException { |
424 | | - DataSet<LocalConcept> meanings = getLocalConceptStore().getMeanings(term); |
| 438 | + DataSet<LocalConcept> meanings = getLocalConceptStore().getMeanings(term, resolvedConceptSpec); |
425 | 439 | out.writeConcepts(meanings); |
426 | 440 | } |
427 | 441 | |
428 | 442 | public void listMeaningsGlobal(String lang, String term, ConsoleOutput out) throws PersistenceException { |
429 | | - DataSet<GlobalConcept> meanings = getGlobalConceptStore().getMeanings(lang, term); |
| 443 | + DataSet<GlobalConcept> meanings = getGlobalConceptStore().getMeanings(lang, term, resolvedConceptSpec); |
430 | 444 | out.writeConcepts(meanings); |
431 | 445 | } |
432 | 446 | |
433 | 447 | public void showConcept(int id, ConsoleOutput out) throws PersistenceException { |
434 | | - WikiWordConcept c = conceptStore.getConcept(id); |
| 448 | + WikiWordConcept c = conceptStore.getConcept(id, detailedConceptSpec); |
435 | 449 | out.writeConcept(c); |
436 | 450 | } |
437 | 451 | |
438 | 452 | public void showConcept(int id, String lang, ConsoleOutput out) throws PersistenceException { |
439 | | - GlobalConcept c = getGlobalConceptStore().getConcept(id); |
| 453 | + GlobalConcept c = getGlobalConceptStore().getConcept(id, detailedConceptSpec); |
440 | 454 | out.writeConcept(c); |
441 | 455 | |
442 | 456 | LocalConcept lc = c.getLocalConcept(lang); |
— | — | @@ -452,7 +466,7 @@ |
453 | 467 | public void showConcept(String lang, int id, ConsoleOutput out) throws PersistenceException { |
454 | 468 | LocalConceptStore lstore = getGlobalConceptStore().getLocalConceptStore(Corpus.forName(getStoreDataset().getCollection(), lang, tweaks)); |
455 | 469 | |
456 | | - LocalConcept lc = lstore.getConcept(id); |
| 470 | + LocalConcept lc = lstore.getConcept(id, detailedConceptSpec); |
457 | 471 | if (out.getOutput() instanceof ConceptDumper) { |
458 | 472 | ((ConceptDumper)out.getOutput()).setMaxAutoResolve(0); |
459 | 473 | } |