Index: trunk/WikiWord/WikiWord/src/main/java/de/brightbyte/wikiword/store/DatabaseLocalConceptStore.java |
— | — | @@ -7,8 +7,9 @@ |
8 | 8 | import java.sql.Connection; |
9 | 9 | import java.sql.ResultSet; |
10 | 10 | import java.sql.SQLException; |
11 | | -import java.util.Collection; |
| 11 | +import java.util.HashSet; |
12 | 12 | import java.util.Map; |
| 13 | +import java.util.Set; |
13 | 14 | |
14 | 15 | import javax.sql.DataSource; |
15 | 16 | |
— | — | @@ -25,6 +26,7 @@ |
26 | 27 | import de.brightbyte.wikiword.ResourceType; |
27 | 28 | import de.brightbyte.wikiword.TweakSet; |
28 | 29 | import de.brightbyte.wikiword.model.ConceptRelations; |
| 30 | +import de.brightbyte.wikiword.model.ConceptResources; |
29 | 31 | import de.brightbyte.wikiword.model.LocalConcept; |
30 | 32 | import de.brightbyte.wikiword.model.TermMeaning; |
31 | 33 | import de.brightbyte.wikiword.model.TermReference; |
— | — | @@ -297,7 +299,7 @@ |
298 | 300 | |
299 | 301 | fields += ", "+card+" as qFreq, "+relev+" as qConf "; |
300 | 302 | |
301 | | - if (spec!=null && spec.getIncludeResource()) { |
| 303 | + if (spec!=null && spec.getIncludeResources()) { //FIXME: multiple matches! |
302 | 304 | fields += ", R.id as rcId, R.name as rcName, R.type as rcType "; |
303 | 305 | tables += " LEFT JOIN "+aboutTable.getSQLName()+" as A ON A.concept = C.id "+ |
304 | 306 | " LEFT JOIN "+resourceTable.getSQLName()+" as R ON R.id = A.resource "; |
— | — | @@ -360,9 +362,14 @@ |
361 | 363 | concept.setRelations(relations); |
362 | 364 | } |
363 | 365 | |
364 | | - if (spec!=null && spec.getIncludeResource()) { |
| 366 | + if (spec!=null && spec.getIncludeResources()) { //FIXME: multiple resources! |
365 | 367 | WikiWordResource resource = rcId <= 0 ? null : new WikiWordResource(corpus, rcId, rcName, rcType); |
366 | | - concept.setResource(resource); |
| 368 | + |
| 369 | + Set<WikiWordResource> rcSet = new HashSet<WikiWordResource>(); |
| 370 | + rcSet.add(resource); |
| 371 | + |
| 372 | + ConceptResources<LocalConcept> resources = new ConceptResources<LocalConcept>(concept, rcSet); |
| 373 | + concept.setResources(resources); |
367 | 374 | } |
368 | 375 | |
369 | 376 | if (spec!=null && spec.getIncludeDefinition()) { |
Index: trunk/WikiWord/WikiWord/src/main/java/de/brightbyte/wikiword/store/DatabaseWikiWordConceptStore.java |
— | — | @@ -148,7 +148,7 @@ |
149 | 149 | |
150 | 150 | if (card!=null) card = ", "+card; |
151 | 151 | |
152 | | - String sql = "SELECT C.id as cId, C.name as cName, C.type as cType " + |
| 152 | + String sql = "SELECT C.id as cId, C.name as cName, C.type as cType, " + |
153 | 153 | " "+card+" as qCard, "+relev+" as qRelev " + |
154 | 154 | " FROM "+conceptTable.getSQLName()+" as C "; |
155 | 155 | |
Index: trunk/WikiWord/WikiWord/src/main/java/de/brightbyte/wikiword/store/DatabaseGlobalConceptStore.java |
— | — | @@ -28,7 +28,6 @@ |
29 | 29 | import de.brightbyte.wikiword.schema.ConceptInfoStoreSchema; |
30 | 30 | import de.brightbyte.wikiword.schema.GlobalConceptStoreSchema; |
31 | 31 | import de.brightbyte.wikiword.schema.StatisticsStoreSchema; |
32 | | -import de.brightbyte.wikiword.store.WikiWordConceptStore.ConceptQuerySpec; |
33 | 32 | |
34 | 33 | /** |
35 | 34 | * A GlobalConceptStore implemented based upon a {@link de.brightbyte.db.DatabaseSchema} object, |
— | — | @@ -106,6 +105,7 @@ |
107 | 106 | @Override |
108 | 107 | protected GlobalConcept newConcept(int id, String name, ConceptType type, int card, double relevance) { |
109 | 108 | GlobalConcept concept = new GlobalConcept(getDatasetIdentifier(), id, type); |
| 109 | + concept.setName(name); |
110 | 110 | concept.setCardinality(card); |
111 | 111 | concept.setRelevance(relevance); |
112 | 112 | return concept; |
— | — | @@ -145,7 +145,7 @@ |
146 | 146 | if ( spec!=null && spec.getLanguageIndependantTypes()!=null |
147 | 147 | && !spec.getLanguageIndependantTypes().isEmpty() ) { |
148 | 148 | //some types of concepts (proper nouns) may be language independant |
149 | | - sql += " AND ( M.lang = "+database.quoteString(lang)+" OR C.type IN "+getTypeCodeSet(spec.getRequireTypes())+" )"; |
| 149 | + sql += " AND ( M.lang = "+database.quoteString(lang)+" OR C.type IN "+getTypeCodeSet(spec.getLanguageIndependantTypes())+" )"; |
150 | 150 | } else { |
151 | 151 | sql += " AND M.lang = "+database.quoteString(lang)+" "; |
152 | 152 | } |
— | — | @@ -160,6 +160,20 @@ |
161 | 161 | } |
162 | 162 | } |
163 | 163 | |
| 164 | + protected String conceptSQL(String lang, String name, ConceptQuerySpec spec) throws PersistenceException { |
| 165 | + if ( lang == null && spec!=null && spec.getLanguage()!=null) { |
| 166 | + lang = spec.getLanguage(); |
| 167 | + } |
| 168 | + |
| 169 | + if ( lang==null ) throw new IllegalArgumentException("languager must be given, either explicitly or in the QuerySpec"); |
| 170 | + |
| 171 | + String sql = " JOIN "+originTable.getSQLName()+" as O on C.id = O.global_concept " + |
| 172 | + " WHERE O.local_concept_name = "+database.quoteString(name)+" " + |
| 173 | + " AND O.lang = "+database.quoteString(lang)+" "; |
| 174 | + |
| 175 | + return sql; |
| 176 | + } |
| 177 | + |
164 | 178 | /* |
165 | 179 | public DataSet<GlobalConcept> listMeanings(String lang, String term) |
166 | 180 | throws PersistenceException { |
— | — | @@ -248,6 +262,21 @@ |
249 | 263 | } |
250 | 264 | } |
251 | 265 | |
| 266 | + public GlobalConcept getConceptByName(String lang, String name, ConceptQuerySpec spec) throws PersistenceException { |
| 267 | + String sql = conceptSelect(spec, null, null) + conceptSQL(lang, name, spec); |
| 268 | + try { |
| 269 | + ResultSet rs = database.executeQuery("getConceptByName", sql); |
| 270 | + if (!rs.next()) throw new PersistenceException("no concept found with name '"+name+"' in language '"+lang+"'"); |
| 271 | + |
| 272 | + GlobalConcept concept = newConcept(rs, spec); |
| 273 | + |
| 274 | + rs.close(); |
| 275 | + return concept; |
| 276 | + } catch (SQLException e) { |
| 277 | + throw new PersistenceException(e); |
| 278 | + } |
| 279 | + } |
| 280 | + |
252 | 281 | public DataSet<GlobalConcept> getMeanings(String lang, String term, ConceptQuerySpec spec) throws PersistenceException { |
253 | 282 | return ((DatabaseGlobalConceptInfoStore)getConceptInfoStore()).getMeanings(lang, term, spec); |
254 | 283 | } |
— | — | @@ -270,6 +299,9 @@ |
271 | 300 | } |
272 | 301 | |
273 | 302 | ///////////////////////////////////////////////////////////////////////////////////////////// |
| 303 | + protected PropertyStore<GlobalConcept> newPropertyStore() throws SQLException, PersistenceException { |
| 304 | + throw new UnsupportedOperationException("property stores are not yet supported for a global thesaurus."); |
| 305 | + } |
274 | 306 | |
275 | 307 | protected class DatabaseGlobalConceptInfoStore extends DatabaseConceptInfoStore<GlobalConcept> { |
276 | 308 | |
— | — | @@ -329,7 +361,6 @@ |
330 | 362 | GlobalConcept concept = new GlobalConcept(getDatasetIdentifier(), id, type); |
331 | 363 | concept.setName(name); |
332 | 364 | concept.setLanguages(languages); |
333 | | - concept.setType(type); |
334 | 365 | concept.setCardinality(cardinality); |
335 | 366 | concept.setRelevance(relevance); |
336 | 367 | |
Index: trunk/WikiWord/WikiWord/src/main/java/de/brightbyte/wikiword/store/WikiWordConceptStore.java |
— | — | @@ -15,9 +15,11 @@ |
16 | 16 | |
17 | 17 | private boolean includeRelations; |
18 | 18 | private boolean includeStatistics; |
19 | | - private boolean includeResource; |
| 19 | + private boolean includeResources; |
20 | 20 | private boolean includeTerms; |
21 | 21 | private boolean includeDefinition; |
| 22 | + private boolean includeFeatures; |
| 23 | + private boolean includeProperties; |
22 | 24 | private Collection<ConceptType> requireTypes; |
23 | 25 | private Collection<ConceptType> languageIndependantTypes; |
24 | 26 | private String language; |
— | — | @@ -47,12 +49,12 @@ |
48 | 50 | this.includeDefinition = includeDefinition; |
49 | 51 | } |
50 | 52 | |
51 | | - public boolean getIncludeResource() { |
52 | | - return includeResource; |
| 53 | + public boolean getIncludeResources() { |
| 54 | + return includeResources; |
53 | 55 | } |
54 | 56 | |
55 | | - public void setIncludeResource(boolean includeResource) { |
56 | | - this.includeResource = includeResource; |
| 57 | + public void setIncludeResources(boolean includeResources) { |
| 58 | + this.includeResources = includeResources; |
57 | 59 | } |
58 | 60 | |
59 | 61 | public boolean getIncludeTerms() { |
— | — | @@ -96,6 +98,22 @@ |
97 | 99 | this.requireTypes = requireTypes; |
98 | 100 | } |
99 | 101 | |
| 102 | + public boolean getIncludeFeatures() { |
| 103 | + return includeFeatures; |
| 104 | + } |
| 105 | + |
| 106 | + public void setIncludeFeatures(boolean includeFeatures) { |
| 107 | + this.includeFeatures = includeFeatures; |
| 108 | + } |
| 109 | + |
| 110 | + public boolean getIncludeProperties() { |
| 111 | + return includeProperties; |
| 112 | + } |
| 113 | + |
| 114 | + public void setIncludeProperties(boolean includeProperties) { |
| 115 | + this.includeProperties = includeProperties; |
| 116 | + } |
| 117 | + |
100 | 118 | } |
101 | 119 | |
102 | 120 | public DataSet<? extends T> getAllConcepts(ConceptQuerySpec spec) throws PersistenceException; |
Index: trunk/WikiWord/WikiWord/src/main/java/de/brightbyte/wikiword/store/GlobalConceptStore.java |
— | — | @@ -28,4 +28,6 @@ |
29 | 29 | public List<LocalConcept> getLocalConcepts(int id, ConceptQuerySpec spec) throws PersistenceException; |
30 | 30 | |
31 | 31 | public Corpus[] getLanguages() throws PersistenceException; |
| 32 | + |
| 33 | + public GlobalConcept getConceptByName(String language, String name, ConceptQuerySpec spec) throws PersistenceException; |
32 | 34 | } |
Index: trunk/WikiWord/WikiWord/src/main/java/de/brightbyte/wikiword/model/LocalConcept.java |
— | — | @@ -7,7 +7,6 @@ |
8 | 8 | |
9 | 9 | protected String definition; |
10 | 10 | protected String language; |
11 | | - protected WikiWordResource resource; |
12 | 11 | |
13 | 12 | public LocalConcept(Corpus corpus, int id, ConceptType type, String name) { |
14 | 13 | super(corpus, id, type); |
— | — | @@ -27,15 +26,6 @@ |
28 | 27 | this.definition = definition; |
29 | 28 | } |
30 | 29 | |
31 | | - public WikiWordResource getResource() { |
32 | | - return resource; |
33 | | - } |
34 | | - |
35 | | - public void setResource(WikiWordResource resource) { |
36 | | - if (this.resource!=null) throw new IllegalStateException("property already initialized"); |
37 | | - this.resource = resource; |
38 | | - } |
39 | | - |
40 | 30 | public String getLanguage() { |
41 | 31 | if (language==null) return getCorpus().getLanguage(); |
42 | 32 | else return language; |
Index: trunk/WikiWord/WikiWord/src/main/java/de/brightbyte/wikiword/model/WikiWordConcept.java |
— | — | @@ -42,8 +42,11 @@ |
43 | 43 | private int cardinality = 1; |
44 | 44 | private double relevance = 1; |
45 | 45 | |
46 | | - private ConceptRelations relations; |
47 | | - private ConceptFeatures features; |
| 46 | + private ConceptRelations<? extends WikiWordConcept> relations; |
| 47 | + private ConceptFeatures<? extends WikiWordConcept, Integer> features; |
| 48 | + private ConceptResources<? extends WikiWordConcept> resources; |
| 49 | + private ConceptProperties<? extends WikiWordConcept> properties; |
| 50 | + |
48 | 51 | private TermReference[] terms; |
49 | 52 | |
50 | 53 | public WikiWordConcept(DatasetIdentifier dataset, int id, ConceptType type) { |
— | — | @@ -83,21 +86,40 @@ |
84 | 87 | this.cardinality = cardinality; |
85 | 88 | } |
86 | 89 | |
87 | | - public ConceptFeatures getFeatures() { |
| 90 | + public ConceptFeatures<? extends WikiWordConcept, Integer> getFeatures() { |
88 | 91 | return features; |
89 | 92 | } |
90 | 93 | |
91 | | - public void setFeatures(ConceptFeatures features) { |
| 94 | + public void setFeatures(ConceptFeatures<? extends WikiWordConcept, Integer> features) { |
92 | 95 | if (this.features!=null) throw new IllegalStateException("property already initialized"); |
93 | 96 | if (features.getConcept()!=null && !this.equals(features.getConcept())) throw new IllegalArgumentException("ConceptFeatures bound to a different concept: "+features.getConcept()); |
94 | 97 | this.features = features; |
95 | 98 | } |
96 | 99 | |
97 | | - public ConceptRelations getRelations() { |
| 100 | + public ConceptProperties getProperties() { |
| 101 | + return properties; |
| 102 | + } |
| 103 | + |
| 104 | + public void setProperties(ConceptProperties<? extends WikiWordConcept> properties) { |
| 105 | + if (this.properties!=null) throw new IllegalStateException("property already initialized"); |
| 106 | + if (properties.getConcept()!=null && !this.equals(properties.getConcept())) throw new IllegalArgumentException("ConceptFeatures bound to a different concept: "+features.getConcept()); |
| 107 | + this.properties = properties; |
| 108 | + } |
| 109 | + |
| 110 | + public ConceptResources<? extends WikiWordConcept> getResources() { |
| 111 | + return resources; |
| 112 | + } |
| 113 | + |
| 114 | + public void setResources(ConceptResources<? extends WikiWordConcept> resources) { |
| 115 | + if (this.resources!=null) throw new IllegalStateException("property already initialized"); |
| 116 | + this.resources = resources; |
| 117 | + } |
| 118 | + |
| 119 | + public ConceptRelations<? extends WikiWordConcept> getRelations() { |
98 | 120 | return relations; |
99 | 121 | } |
100 | 122 | |
101 | | - public void setRelations(ConceptRelations relations) { |
| 123 | + public void setRelations(ConceptRelations<? extends WikiWordConcept> relations) { |
102 | 124 | if (this.relations!=null) throw new IllegalStateException("property already initialized"); |
103 | 125 | this.relations = relations; |
104 | 126 | } |
Index: trunk/WikiWord/WikiWord/src/main/java/de/brightbyte/wikiword/model/ConceptResources.java |
— | — | @@ -0,0 +1,50 @@ |
| 2 | +package de.brightbyte.wikiword.model; |
| 3 | + |
| 4 | +import java.util.Set; |
| 5 | + |
| 6 | +public class ConceptResources<C extends WikiWordConcept> { |
| 7 | + protected Set<WikiWordResource> resources; |
| 8 | + protected C concept; |
| 9 | + |
| 10 | + public ConceptResources(C concept, Set<WikiWordResource> resources) { |
| 11 | + if (resources==null) throw new NullPointerException(); |
| 12 | + if (concept==null) throw new NullPointerException(); |
| 13 | + this.resources = resources; |
| 14 | + this.concept = concept; |
| 15 | + } |
| 16 | + |
| 17 | + public String toString() { |
| 18 | + return concept+ ":"+resources; |
| 19 | + } |
| 20 | + |
| 21 | + public Set<WikiWordResource> getResources() { |
| 22 | + return resources; |
| 23 | + } |
| 24 | + |
| 25 | + public WikiWordConcept getConcept() { |
| 26 | + return concept; |
| 27 | + } |
| 28 | + |
| 29 | + public int getId() { |
| 30 | + return concept.getId(); |
| 31 | + } |
| 32 | + |
| 33 | + @Override |
| 34 | + public int hashCode() { |
| 35 | + return concept.hashCode(); |
| 36 | + } |
| 37 | + |
| 38 | + @Override |
| 39 | + public boolean equals(Object obj) { |
| 40 | + if (this == obj) |
| 41 | + return true; |
| 42 | + if (obj == null) |
| 43 | + return false; |
| 44 | + if (getClass() != obj.getClass()) |
| 45 | + return false; |
| 46 | + final ConceptResources other = (ConceptResources) obj; |
| 47 | + |
| 48 | + return concept.equals(other.concept); |
| 49 | + } |
| 50 | + |
| 51 | +} |
Index: trunk/WikiWord/WikiWord/src/main/java/de/brightbyte/wikiword/query/QueryConsole.java |
— | — | @@ -57,11 +57,11 @@ |
58 | 58 | minimalConceptSpec = new ConceptQuerySpec(); |
59 | 59 | resolvedConceptSpec = new ConceptQuerySpec(); |
60 | 60 | resolvedConceptSpec.setIncludeDefinition(true); |
61 | | - resolvedConceptSpec.setIncludeResource(true); |
| 61 | + resolvedConceptSpec.setIncludeResources(true); |
62 | 62 | |
63 | 63 | detailedConceptSpec = new ConceptQuerySpec(); |
64 | 64 | detailedConceptSpec.setIncludeDefinition(true); |
65 | | - detailedConceptSpec.setIncludeResource(true); |
| 65 | + detailedConceptSpec.setIncludeResources(true); |
66 | 66 | detailedConceptSpec.setIncludeRelations(true); |
67 | 67 | } |
68 | 68 | |
Index: trunk/WikiWord/WikiWord/src/main/java/de/brightbyte/wikiword/rdf/LocalConceptSkosProperties.java |
— | — | @@ -8,6 +8,8 @@ |
9 | 9 | import de.brightbyte.rdf.RdfPlatform; |
10 | 10 | import de.brightbyte.rdf.vocab.SKOS; |
11 | 11 | import de.brightbyte.wikiword.Corpus; |
| 12 | +import de.brightbyte.wikiword.ResourceType; |
| 13 | +import de.brightbyte.wikiword.model.ConceptResources; |
12 | 14 | import de.brightbyte.wikiword.model.LocalConcept; |
13 | 15 | import de.brightbyte.wikiword.model.TermReference; |
14 | 16 | import de.brightbyte.wikiword.model.WikiWordConcept; |
— | — | @@ -42,8 +44,12 @@ |
43 | 45 | |
44 | 46 | if (def!=null) setLiteralProperty(about, skos.definition, def, lang); |
45 | 47 | |
46 | | - WikiWordResource page = concept.getResource(); |
47 | | - if (page!=null) setReferenceProperty(about, skos.definition, corpus.getURL().toString(), page.getName()); |
| 48 | + ConceptResources<? extends WikiWordConcept> resources = concept.getResources(); |
| 49 | + for (WikiWordResource page: resources.getResources()) { |
| 50 | + if (page.getType().equals(ResourceType.ARTICLE)) { |
| 51 | + setReferenceProperty(about, skos.definition, corpus.getURL().toString(), page.getName()); |
| 52 | + } |
| 53 | + } |
48 | 54 | |
49 | 55 | //TODO: threshold! or at least, record freq. |
50 | 56 | TermReference[] tt = concept.getTerms(); |