Allow specification of a Google API key.

This commit is contained in:
David Huynh 2013-03-14 18:18:56 -07:00
parent 50888c6f2e
commit fef773bae0
5 changed files with 59 additions and 56 deletions

View File

@ -124,8 +124,6 @@ public class GuidBasedReconConfig extends StrictReconConfig {
StringWriter stringWriter = new StringWriter(); StringWriter stringWriter = new StringWriter();
JSONWriter jsonWriter = new JSONWriter(stringWriter); JSONWriter jsonWriter = new JSONWriter(stringWriter);
jsonWriter.object();
jsonWriter.key("query");
jsonWriter.array(); jsonWriter.array();
jsonWriter.object(); jsonWriter.object();
@ -143,14 +141,13 @@ public class GuidBasedReconConfig extends StrictReconConfig {
jsonWriter.endObject(); jsonWriter.endObject();
jsonWriter.endArray(); jsonWriter.endArray();
jsonWriter.endObject();
query = stringWriter.toString(); query = stringWriter.toString();
} }
StringBuffer sb = new StringBuffer(1024); StringBuffer sb = new StringBuffer(1024);
sb.append(s_mqlreadService); sb.append(getMqlreadService());
sb.append("?query="); sb.append("&query=");
sb.append(ParsingUtilities.encode(query)); sb.append(ParsingUtilities.encode(query));
URL url = new URL(sb.toString()); URL url = new URL(sb.toString());

View File

@ -128,33 +128,30 @@ public class IdBasedReconConfig extends StrictReconConfig {
StringWriter stringWriter = new StringWriter(); StringWriter stringWriter = new StringWriter();
JSONWriter jsonWriter = new JSONWriter(stringWriter); JSONWriter jsonWriter = new JSONWriter(stringWriter);
jsonWriter.array();
jsonWriter.object(); jsonWriter.object();
jsonWriter.key("query");
jsonWriter.array();
jsonWriter.object();
jsonWriter.key("id"); jsonWriter.value(null); jsonWriter.key("id"); jsonWriter.value(null);
jsonWriter.key("name"); jsonWriter.value(null); jsonWriter.key("name"); jsonWriter.value(null);
jsonWriter.key("guid"); jsonWriter.value(null); jsonWriter.key("guid"); jsonWriter.value(null);
jsonWriter.key("type"); jsonWriter.array(); jsonWriter.endArray(); jsonWriter.key("type"); jsonWriter.array(); jsonWriter.endArray();
jsonWriter.key("id|="); jsonWriter.key("id|=");
jsonWriter.array(); jsonWriter.array();
for (ReconJob job : jobs) { for (ReconJob job : jobs) {
jsonWriter.value(((IdBasedReconJob) job).id); jsonWriter.value(((IdBasedReconJob) job).id);
} }
jsonWriter.endArray(); jsonWriter.endArray();
jsonWriter.endObject();
jsonWriter.endArray();
jsonWriter.endObject(); jsonWriter.endObject();
jsonWriter.endArray();
query = stringWriter.toString(); query = stringWriter.toString();
} }
StringBuffer sb = new StringBuffer(1024); StringBuffer sb = new StringBuffer(1024);
sb.append(s_mqlreadService); sb.append(getMqlreadService());
sb.append("?query="); sb.append("&query=");
sb.append(ParsingUtilities.encode(query)); sb.append(ParsingUtilities.encode(query));
URL url = new URL(sb.toString()); URL url = new URL(sb.toString());

View File

@ -129,46 +129,43 @@ public class KeyBasedReconConfig extends StrictReconConfig {
StringWriter stringWriter = new StringWriter(); StringWriter stringWriter = new StringWriter();
JSONWriter jsonWriter = new JSONWriter(stringWriter); JSONWriter jsonWriter = new JSONWriter(stringWriter);
jsonWriter.array();
jsonWriter.object(); jsonWriter.object();
jsonWriter.key("query");
jsonWriter.array();
jsonWriter.object();
jsonWriter.key("id"); jsonWriter.value(null); jsonWriter.key("id"); jsonWriter.value(null);
jsonWriter.key("name"); jsonWriter.value(null); jsonWriter.key("name"); jsonWriter.value(null);
jsonWriter.key("guid"); jsonWriter.value(null); jsonWriter.key("guid"); jsonWriter.value(null);
jsonWriter.key("type"); jsonWriter.array(); jsonWriter.endArray(); jsonWriter.key("type"); jsonWriter.array(); jsonWriter.endArray();
jsonWriter.key("key"); jsonWriter.key("key");
jsonWriter.array(); jsonWriter.array();
jsonWriter.object();
jsonWriter.key("namespace");
jsonWriter.object(); jsonWriter.object();
jsonWriter.key("id"); jsonWriter.value(namespace.id);
jsonWriter.key("namespace");
jsonWriter.object();
jsonWriter.key("id"); jsonWriter.value(namespace.id);
jsonWriter.endObject();
jsonWriter.key("value"); jsonWriter.value(null);
jsonWriter.key("value|=");
jsonWriter.array();
for (ReconJob job : jobs) {
jsonWriter.value(((KeyBasedReconJob) job).key);
}
jsonWriter.endArray();
jsonWriter.endObject(); jsonWriter.endObject();
jsonWriter.key("value"); jsonWriter.value(null);
jsonWriter.key("value|=");
jsonWriter.array();
for (ReconJob job : jobs) {
jsonWriter.value(((KeyBasedReconJob) job).key);
}
jsonWriter.endArray(); jsonWriter.endArray();
jsonWriter.endObject(); jsonWriter.endObject();
jsonWriter.endArray(); jsonWriter.endArray();
jsonWriter.endObject(); jsonWriter.endObject();
jsonWriter.endArray();
query = stringWriter.toString(); query = stringWriter.toString();
} }
StringBuffer sb = new StringBuffer(1024); StringBuffer sb = new StringBuffer(1024);
sb.append(s_mqlreadService); sb.append(getMqlreadService());
sb.append("?query="); sb.append("&query=");
sb.append(ParsingUtilities.encode(query)); sb.append(ParsingUtilities.encode(query));
URL url = new URL(sb.toString()); URL url = new URL(sb.toString());

View File

@ -40,7 +40,12 @@ import com.google.refine.model.Recon.Judgment;
import com.google.refine.model.recon.ReconConfig; import com.google.refine.model.recon.ReconConfig;
abstract public class StrictReconConfig extends ReconConfig { abstract public class StrictReconConfig extends ReconConfig {
final static protected String s_mqlreadService = "http://api.freebase.com/api/service/mqlread"; final static private String s_mqlreadService =
"https://www.googleapis.com/freebase/v1/mqlread";
static protected String getMqlreadService() {
return s_mqlreadService + "?key=" + System.getProperty("refine.google_api_key");
}
static public ReconConfig reconstruct(JSONObject obj) throws Exception { static public ReconConfig reconstruct(JSONObject obj) throws Exception {
String match = obj.getString("match"); String match = obj.getString("match");

7
refine
View File

@ -46,6 +46,8 @@ where [options] include:
-m <memory> max memory heap size to use -m <memory> max memory heap size to use
default: 1024M default: 1024M
-k <google api key> a server API key for calling Google APIs
-v <level> verbosity level [from low to high: error,warn,info,debug,trace] -v <level> verbosity level [from low to high: error,warn,info,debug,trace]
default: info default: info
@ -665,6 +667,10 @@ run() {
add_option "-Drefine.host=$REFINE_HOST" add_option "-Drefine.host=$REFINE_HOST"
fi fi
if [ "$REFINE_GOOGLE_API_KEY" ] ; then
add_option "-Drefine.google_api_key=$REFINE_GOOGLE_API_KEY"
fi
CLASSPATH="$REFINE_CLASSES_DIR${SEP}$REFINE_LIB_DIR/*" CLASSPATH="$REFINE_CLASSES_DIR${SEP}$REFINE_LIB_DIR/*"
RUN_CMD="$JAVA -cp $CLASSPATH $OPTS com.google.refine.Refine" RUN_CMD="$JAVA -cp $CLASSPATH $OPTS com.google.refine.Refine"
@ -869,6 +875,7 @@ while [ $# -ne 0 ] ; do
-w) shift; REFINE_WEBAPP="$1"; shift; continue;; -w) shift; REFINE_WEBAPP="$1"; shift; continue;;
-d) shift; REFINE_DATA_DIR="$1"; shift; continue;; -d) shift; REFINE_DATA_DIR="$1"; shift; continue;;
-m) shift; REFINE_MEMORY="$1"; shift; continue;; -m) shift; REFINE_MEMORY="$1"; shift; continue;;
-k) shift; REFINE_GOOGLE_API_KEY="$1"; shift; continue;;
-v) shift; REFINE_VERBOSITY="$1"; shift; continue;; -v) shift; REFINE_VERBOSITY="$1"; shift; continue;;
-x) shift; REFINE_EXTRA_OPTS="$1"; shift; continue;; -x) shift; REFINE_EXTRA_OPTS="$1"; shift; continue;;
--debug) shift; add_option '-Xdebug -Xrunjdwp:transport=dt_socket,address=8000,server=y,suspend=n'; continue;; --debug) shift; add_option '-Xdebug -Xrunjdwp:transport=dt_socket,address=8000,server=y,suspend=n'; continue;;