r68361 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r68360‎ | r68361 | r68362 >
Date:14:57, 21 June 2010
Author:daniel
Status:deferred
Tags:
Comment:
access to wiki resources names etc in global thesaurus
Modified paths:
  • /trunk/WikiWord/WikiWord/src/main/java/de/brightbyte/wikiword/model/ConceptResources.java (added) (history)
  • /trunk/WikiWord/WikiWord/src/main/java/de/brightbyte/wikiword/model/LocalConcept.java (modified) (history)
  • /trunk/WikiWord/WikiWord/src/main/java/de/brightbyte/wikiword/model/WikiWordConcept.java (modified) (history)
  • /trunk/WikiWord/WikiWord/src/main/java/de/brightbyte/wikiword/query/QueryConsole.java (modified) (history)
  • /trunk/WikiWord/WikiWord/src/main/java/de/brightbyte/wikiword/rdf/LocalConceptSkosProperties.java (modified) (history)
  • /trunk/WikiWord/WikiWord/src/main/java/de/brightbyte/wikiword/store/DatabaseGlobalConceptStore.java (modified) (history)
  • /trunk/WikiWord/WikiWord/src/main/java/de/brightbyte/wikiword/store/DatabaseLocalConceptStore.java (modified) (history)
  • /trunk/WikiWord/WikiWord/src/main/java/de/brightbyte/wikiword/store/DatabaseWikiWordConceptStore.java (modified) (history)
  • /trunk/WikiWord/WikiWord/src/main/java/de/brightbyte/wikiword/store/GlobalConceptStore.java (modified) (history)
  • /trunk/WikiWord/WikiWord/src/main/java/de/brightbyte/wikiword/store/WikiWordConceptStore.java (modified) (history)

Diff [purge]

Index: trunk/WikiWord/WikiWord/src/main/java/de/brightbyte/wikiword/store/DatabaseLocalConceptStore.java
@@ -7,8 +7,9 @@
88 import java.sql.Connection;
99 import java.sql.ResultSet;
1010 import java.sql.SQLException;
11 -import java.util.Collection;
 11+import java.util.HashSet;
1212 import java.util.Map;
 13+import java.util.Set;
1314
1415 import javax.sql.DataSource;
1516
@@ -25,6 +26,7 @@
2627 import de.brightbyte.wikiword.ResourceType;
2728 import de.brightbyte.wikiword.TweakSet;
2829 import de.brightbyte.wikiword.model.ConceptRelations;
 30+import de.brightbyte.wikiword.model.ConceptResources;
2931 import de.brightbyte.wikiword.model.LocalConcept;
3032 import de.brightbyte.wikiword.model.TermMeaning;
3133 import de.brightbyte.wikiword.model.TermReference;
@@ -297,7 +299,7 @@
298300
299301 fields += ", "+card+" as qFreq, "+relev+" as qConf ";
300302
301 - if (spec!=null && spec.getIncludeResource()) {
 303+ if (spec!=null && spec.getIncludeResources()) { //FIXME: multiple matches!
302304 fields += ", R.id as rcId, R.name as rcName, R.type as rcType ";
303305 tables += " LEFT JOIN "+aboutTable.getSQLName()+" as A ON A.concept = C.id "+
304306 " LEFT JOIN "+resourceTable.getSQLName()+" as R ON R.id = A.resource ";
@@ -360,9 +362,14 @@
361363 concept.setRelations(relations);
362364 }
363365
364 - if (spec!=null && spec.getIncludeResource()) {
 366+ if (spec!=null && spec.getIncludeResources()) { //FIXME: multiple resources!
365367 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);
367374 }
368375
369376 if (spec!=null && spec.getIncludeDefinition()) {
Index: trunk/WikiWord/WikiWord/src/main/java/de/brightbyte/wikiword/store/DatabaseWikiWordConceptStore.java
@@ -148,7 +148,7 @@
149149
150150 if (card!=null) card = ", "+card;
151151
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, " +
153153 " "+card+" as qCard, "+relev+" as qRelev " +
154154 " FROM "+conceptTable.getSQLName()+" as C ";
155155
Index: trunk/WikiWord/WikiWord/src/main/java/de/brightbyte/wikiword/store/DatabaseGlobalConceptStore.java
@@ -28,7 +28,6 @@
2929 import de.brightbyte.wikiword.schema.ConceptInfoStoreSchema;
3030 import de.brightbyte.wikiword.schema.GlobalConceptStoreSchema;
3131 import de.brightbyte.wikiword.schema.StatisticsStoreSchema;
32 -import de.brightbyte.wikiword.store.WikiWordConceptStore.ConceptQuerySpec;
3332
3433 /**
3534 * A GlobalConceptStore implemented based upon a {@link de.brightbyte.db.DatabaseSchema} object,
@@ -106,6 +105,7 @@
107106 @Override
108107 protected GlobalConcept newConcept(int id, String name, ConceptType type, int card, double relevance) {
109108 GlobalConcept concept = new GlobalConcept(getDatasetIdentifier(), id, type);
 109+ concept.setName(name);
110110 concept.setCardinality(card);
111111 concept.setRelevance(relevance);
112112 return concept;
@@ -145,7 +145,7 @@
146146 if ( spec!=null && spec.getLanguageIndependantTypes()!=null
147147 && !spec.getLanguageIndependantTypes().isEmpty() ) {
148148 //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())+" )";
150150 } else {
151151 sql += " AND M.lang = "+database.quoteString(lang)+" ";
152152 }
@@ -160,6 +160,20 @@
161161 }
162162 }
163163
 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+
164178 /*
165179 public DataSet<GlobalConcept> listMeanings(String lang, String term)
166180 throws PersistenceException {
@@ -248,6 +262,21 @@
249263 }
250264 }
251265
 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+
252281 public DataSet<GlobalConcept> getMeanings(String lang, String term, ConceptQuerySpec spec) throws PersistenceException {
253282 return ((DatabaseGlobalConceptInfoStore)getConceptInfoStore()).getMeanings(lang, term, spec);
254283 }
@@ -270,6 +299,9 @@
271300 }
272301
273302 /////////////////////////////////////////////////////////////////////////////////////////////
 303+ protected PropertyStore<GlobalConcept> newPropertyStore() throws SQLException, PersistenceException {
 304+ throw new UnsupportedOperationException("property stores are not yet supported for a global thesaurus.");
 305+ }
274306
275307 protected class DatabaseGlobalConceptInfoStore extends DatabaseConceptInfoStore<GlobalConcept> {
276308
@@ -329,7 +361,6 @@
330362 GlobalConcept concept = new GlobalConcept(getDatasetIdentifier(), id, type);
331363 concept.setName(name);
332364 concept.setLanguages(languages);
333 - concept.setType(type);
334365 concept.setCardinality(cardinality);
335366 concept.setRelevance(relevance);
336367
Index: trunk/WikiWord/WikiWord/src/main/java/de/brightbyte/wikiword/store/WikiWordConceptStore.java
@@ -15,9 +15,11 @@
1616
1717 private boolean includeRelations;
1818 private boolean includeStatistics;
19 - private boolean includeResource;
 19+ private boolean includeResources;
2020 private boolean includeTerms;
2121 private boolean includeDefinition;
 22+ private boolean includeFeatures;
 23+ private boolean includeProperties;
2224 private Collection<ConceptType> requireTypes;
2325 private Collection<ConceptType> languageIndependantTypes;
2426 private String language;
@@ -47,12 +49,12 @@
4850 this.includeDefinition = includeDefinition;
4951 }
5052
51 - public boolean getIncludeResource() {
52 - return includeResource;
 53+ public boolean getIncludeResources() {
 54+ return includeResources;
5355 }
5456
55 - public void setIncludeResource(boolean includeResource) {
56 - this.includeResource = includeResource;
 57+ public void setIncludeResources(boolean includeResources) {
 58+ this.includeResources = includeResources;
5759 }
5860
5961 public boolean getIncludeTerms() {
@@ -96,6 +98,22 @@
9799 this.requireTypes = requireTypes;
98100 }
99101
 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+
100118 }
101119
102120 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 @@
2929 public List<LocalConcept> getLocalConcepts(int id, ConceptQuerySpec spec) throws PersistenceException;
3030
3131 public Corpus[] getLanguages() throws PersistenceException;
 32+
 33+ public GlobalConcept getConceptByName(String language, String name, ConceptQuerySpec spec) throws PersistenceException;
3234 }
Index: trunk/WikiWord/WikiWord/src/main/java/de/brightbyte/wikiword/model/LocalConcept.java
@@ -7,7 +7,6 @@
88
99 protected String definition;
1010 protected String language;
11 - protected WikiWordResource resource;
1211
1312 public LocalConcept(Corpus corpus, int id, ConceptType type, String name) {
1413 super(corpus, id, type);
@@ -27,15 +26,6 @@
2827 this.definition = definition;
2928 }
3029
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 -
4030 public String getLanguage() {
4131 if (language==null) return getCorpus().getLanguage();
4232 else return language;
Index: trunk/WikiWord/WikiWord/src/main/java/de/brightbyte/wikiword/model/WikiWordConcept.java
@@ -42,8 +42,11 @@
4343 private int cardinality = 1;
4444 private double relevance = 1;
4545
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+
4851 private TermReference[] terms;
4952
5053 public WikiWordConcept(DatasetIdentifier dataset, int id, ConceptType type) {
@@ -83,21 +86,40 @@
8487 this.cardinality = cardinality;
8588 }
8689
87 - public ConceptFeatures getFeatures() {
 90+ public ConceptFeatures<? extends WikiWordConcept, Integer> getFeatures() {
8891 return features;
8992 }
9093
91 - public void setFeatures(ConceptFeatures features) {
 94+ public void setFeatures(ConceptFeatures<? extends WikiWordConcept, Integer> features) {
9295 if (this.features!=null) throw new IllegalStateException("property already initialized");
9396 if (features.getConcept()!=null && !this.equals(features.getConcept())) throw new IllegalArgumentException("ConceptFeatures bound to a different concept: "+features.getConcept());
9497 this.features = features;
9598 }
9699
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() {
98120 return relations;
99121 }
100122
101 - public void setRelations(ConceptRelations relations) {
 123+ public void setRelations(ConceptRelations<? extends WikiWordConcept> relations) {
102124 if (this.relations!=null) throw new IllegalStateException("property already initialized");
103125 this.relations = relations;
104126 }
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 @@
5858 minimalConceptSpec = new ConceptQuerySpec();
5959 resolvedConceptSpec = new ConceptQuerySpec();
6060 resolvedConceptSpec.setIncludeDefinition(true);
61 - resolvedConceptSpec.setIncludeResource(true);
 61+ resolvedConceptSpec.setIncludeResources(true);
6262
6363 detailedConceptSpec = new ConceptQuerySpec();
6464 detailedConceptSpec.setIncludeDefinition(true);
65 - detailedConceptSpec.setIncludeResource(true);
 65+ detailedConceptSpec.setIncludeResources(true);
6666 detailedConceptSpec.setIncludeRelations(true);
6767 }
6868
Index: trunk/WikiWord/WikiWord/src/main/java/de/brightbyte/wikiword/rdf/LocalConceptSkosProperties.java
@@ -8,6 +8,8 @@
99 import de.brightbyte.rdf.RdfPlatform;
1010 import de.brightbyte.rdf.vocab.SKOS;
1111 import de.brightbyte.wikiword.Corpus;
 12+import de.brightbyte.wikiword.ResourceType;
 13+import de.brightbyte.wikiword.model.ConceptResources;
1214 import de.brightbyte.wikiword.model.LocalConcept;
1315 import de.brightbyte.wikiword.model.TermReference;
1416 import de.brightbyte.wikiword.model.WikiWordConcept;
@@ -42,8 +44,12 @@
4345
4446 if (def!=null) setLiteralProperty(about, skos.definition, def, lang);
4547
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+ }
4854
4955 //TODO: threshold! or at least, record freq.
5056 TermReference[] tt = concept.getTerms();

Status & tagging log