A bit more careful error handling during recon.
git-svn-id: http://google-refine.googlecode.com/svn/trunk@105 7d457c2a-affb-35e4-300a-418c747d4874
This commit is contained in:
parent
28a86dfe0f
commit
5264c829ae
@ -1,9 +1,7 @@
|
||||
package com.metaweb.gridworks.model.operations;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.StringWriter;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.net.URL;
|
||||
import java.net.URLConnection;
|
||||
import java.util.ArrayList;
|
||||
@ -203,11 +201,8 @@ public class ReconOperation extends EngineDependentOperation {
|
||||
List<CellChange> cellChanges = new ArrayList<CellChange>(_entries.size());
|
||||
List<String> values = new ArrayList<String>(valueToEntries.keySet());
|
||||
for (int i = 0; i < values.size(); i += 10) {
|
||||
try {
|
||||
recon(valueToEntries, values, i, Math.min(i + 10, values.size()), cellChanges);
|
||||
} catch (JSONException e1) {
|
||||
e1.printStackTrace();
|
||||
}
|
||||
|
||||
_progress = i * 100 / values.size();
|
||||
|
||||
try {
|
||||
@ -240,8 +235,8 @@ public class ReconOperation extends EngineDependentOperation {
|
||||
int from,
|
||||
int to,
|
||||
List<CellChange> cellChanges
|
||||
) throws JSONException {
|
||||
|
||||
) {
|
||||
try {
|
||||
StringWriter stringWriter = new StringWriter();
|
||||
JSONWriter jsonWriter = new JSONWriter(stringWriter);
|
||||
|
||||
@ -267,7 +262,6 @@ public class ReconOperation extends EngineDependentOperation {
|
||||
sb.append("http://api.freebase.com/api/service/search?indent=1&queries=");
|
||||
sb.append(ParsingUtilities.encode(stringWriter.toString()));
|
||||
|
||||
try {
|
||||
URL url = new URL(sb.toString());
|
||||
URLConnection connection = url.openConnection();
|
||||
connection.setConnectTimeout(5000);
|
||||
@ -285,14 +279,17 @@ public class ReconOperation extends EngineDependentOperation {
|
||||
continue;
|
||||
}
|
||||
|
||||
JSONObject o2 = o.getJSONObject(key);
|
||||
if (!(o2.has("result"))) {
|
||||
continue;
|
||||
}
|
||||
Recon recon;
|
||||
|
||||
JSONObject o2 = o.getJSONObject(key);
|
||||
if (o2.has("result")) {
|
||||
JSONArray results = o2.getJSONArray("result");
|
||||
|
||||
Recon recon = createRecon(value, results);
|
||||
recon = createRecon(value, results);
|
||||
} else {
|
||||
recon = new Recon();
|
||||
}
|
||||
|
||||
for (ReconEntry entry : valueToEntries.get(value)) {
|
||||
Cell oldCell = entry.cell;
|
||||
|
||||
@ -306,20 +303,37 @@ public class ReconOperation extends EngineDependentOperation {
|
||||
);
|
||||
cellChanges.add(cellChange);
|
||||
}
|
||||
|
||||
valueToEntries.remove(value);
|
||||
}
|
||||
} finally {
|
||||
is.close();
|
||||
}
|
||||
} catch (UnsupportedEncodingException e) {
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
protected Recon createRecon(String text, JSONArray results) throws JSONException {
|
||||
for (List<ReconEntry> entries : valueToEntries.values()) {
|
||||
Recon recon = new Recon();
|
||||
|
||||
for (ReconEntry entry : entries) {
|
||||
Cell oldCell = entry.cell;
|
||||
Cell newCell = new Cell(oldCell.value, recon);
|
||||
|
||||
CellChange cellChange = new CellChange(
|
||||
entry.rowIndex,
|
||||
_cellIndex,
|
||||
oldCell,
|
||||
newCell
|
||||
);
|
||||
cellChanges.add(cellChange);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected Recon createRecon(String text, JSONArray results) {
|
||||
Recon recon = new Recon();
|
||||
try {
|
||||
int length = results.length();
|
||||
for (int i = 0; i < length && recon.candidates.size() < 3; i++) {
|
||||
JSONObject result = results.getJSONObject(i);
|
||||
@ -358,7 +372,9 @@ public class ReconOperation extends EngineDependentOperation {
|
||||
|
||||
recon.candidates.add(candidate);
|
||||
}
|
||||
|
||||
} catch (JSONException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return recon;
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user