r62121 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r62120‎ | r62121 | r62122 >
Date:09:46, 8 February 2010
Author:daniel
Status:deferred
Tags:
Comment:
feature store, work in progress
Modified paths:
  • /trunk/WikiWord/WikiWord/src/main/java/de/brightbyte/wikiword/store/DatabaseFeatureStore.java (modified) (history)

Diff [purge]

Index: trunk/WikiWord/WikiWord/src/main/java/de/brightbyte/wikiword/store/DatabaseFeatureStore.java
@@ -12,6 +12,7 @@
1313 import de.brightbyte.db.EntityTable;
1414 import de.brightbyte.db.QueryDataSet;
1515 import de.brightbyte.db.RelationTable;
 16+import de.brightbyte.db.TemporaryTableDataSet;
1617 import de.brightbyte.util.PersistenceException;
1718 import de.brightbyte.wikiword.TweakSet;
1819 import de.brightbyte.wikiword.model.WikiWordConcept;
@@ -105,15 +106,49 @@
106107 return v;
107108 }
108109
109 - public DataSet<WikiWordConceptFeatures> getNeighbourhoodFeatures(int concept) throws PersistenceException {
110 - String sql = "SELECT X.concept as concept, X.feature as feature, X.normal_value as value ";
111 - sql += " FROM " + featureTable.getSQLName() + " as X ";
112 - sql += " JOIN "+featureTable.getSQLName()+" as N ON N.feature = C.id ";
113 - sql += " JOIN "+featureTable.getSQLName()+" as F ON F.feature = N.concept ";
 110+ public DataSet<WikiWordConceptFeatures> getNeighbourhoodFeatures(final int concept) throws PersistenceException {
 111+ /*
 112+ String sql = "SELECT C.id as concept, C.name as name, X.feature as feature, X.normal_weight as value ";
 113+ sql += " FROM " + featureTable.getSQLName() + " as X force key (PRIMARY) ";
 114+ sql += " JOIN "+featureTable.getSQLName()+" as N force key (PRIMARY) ON N.feature = X.concept ";
 115+ sql += " JOIN "+featureTable.getSQLName()+" as F force key (feature) ON F.feature = N.concept ";
 116+ sql += " JOIN "+conceptTable.getSQLName()+" as C force key (PRIMARY) ON C.id = X.concept ";
114117 sql += " WHERE F.concept = "+concept;
115 - sql += " ORDER BY C.id";
 118+ sql += " ORDER BY X.concept";
116119
117120 return new QueryDataSet<WikiWordConceptFeatures>(database, getConceptFeaturesFactory(), "getNeighbourhoodFeatures", sql, false);
 121+ */
 122+ return new TemporaryTableDataSet<WikiWordConceptFeatures>(database, getConceptFeaturesFactory()) {
 123+
 124+ @Override
 125+ public Cursor<WikiWordConceptFeatures> cursor() throws PersistenceException {
 126+ try {
 127+ String n = database.createTemporaryTable("id integer not null, name varchar(255) default null, primary key (id)");
 128+ String sql = "INSERT IGNORE INTO "+n+" (id) ";
 129+ sql += " SELECT N.feature as id ";
 130+ sql += " FROM "+featureTable.getSQLName()+" AS F ";
 131+ sql += " JOIN "+featureTable.getSQLName()+" AS N ON F.feature = N.concept ";
 132+ sql += " WHERE F.concept = "+concept;
 133+
 134+ database.executeUpdate("getNeighbourhoodFeatures#neighbours", sql);
 135+
 136+ sql = "UPDATE "+n+" as N ";
 137+ sql+= " JOIN "+conceptTable.getSQLName()+" AS C ON C.id = N.id ";
 138+ sql+= " SET N.name = C.name ";
 139+
 140+ database.executeUpdate("getNeighbourhoodFeatures#names", sql);
 141+
 142+ sql = "SELECT N.id as concept, N.name as name, X.feature as feature, X.normal_weight as value ";
 143+ sql+= " FROM "+n+" AS N ";
 144+ sql+= " JOIN "+featureTable.getSQLName()+" as X ON X.concept = N.id ";
 145+
 146+ ResultSet rs = database.executeQuery("getNeighbourhoodFeatures#features", sql);
 147+ return new TemporaryTableDataSet.Cursor<WikiWordConceptFeatures>(rs, factory, database, new String[] { n }, database.getLogOutput() );
 148+ } catch (SQLException e) {
 149+ throw new PersistenceException(e);
 150+ }
 151+ }
 152+ };
118153 }
119154
120155 private DatabaseDataSet.Factory<WikiWordConceptFeatures> getConceptFeaturesFactory() {

Status & tagging log