diff --git a/extensions/freebase/src/com/google/refine/freebase/model/recon/GuidBasedReconConfig.java b/extensions/freebase/src/com/google/refine/freebase/model/recon/GuidBasedReconConfig.java index ec467c262..7c7f91f5b 100644 --- a/extensions/freebase/src/com/google/refine/freebase/model/recon/GuidBasedReconConfig.java +++ b/extensions/freebase/src/com/google/refine/freebase/model/recon/GuidBasedReconConfig.java @@ -124,8 +124,6 @@ public class GuidBasedReconConfig extends StrictReconConfig { StringWriter stringWriter = new StringWriter(); JSONWriter jsonWriter = new JSONWriter(stringWriter); - jsonWriter.object(); - jsonWriter.key("query"); jsonWriter.array(); jsonWriter.object(); @@ -143,14 +141,13 @@ public class GuidBasedReconConfig extends StrictReconConfig { jsonWriter.endObject(); jsonWriter.endArray(); - jsonWriter.endObject(); query = stringWriter.toString(); } StringBuffer sb = new StringBuffer(1024); - sb.append(s_mqlreadService); - sb.append("?query="); + sb.append(getMqlreadService()); + sb.append("&query="); sb.append(ParsingUtilities.encode(query)); URL url = new URL(sb.toString()); diff --git a/extensions/freebase/src/com/google/refine/freebase/model/recon/IdBasedReconConfig.java b/extensions/freebase/src/com/google/refine/freebase/model/recon/IdBasedReconConfig.java index 7da13c97f..c7134731a 100644 --- a/extensions/freebase/src/com/google/refine/freebase/model/recon/IdBasedReconConfig.java +++ b/extensions/freebase/src/com/google/refine/freebase/model/recon/IdBasedReconConfig.java @@ -128,33 +128,30 @@ public class IdBasedReconConfig extends StrictReconConfig { StringWriter stringWriter = new StringWriter(); JSONWriter jsonWriter = new JSONWriter(stringWriter); + jsonWriter.array(); jsonWriter.object(); - jsonWriter.key("query"); - jsonWriter.array(); - jsonWriter.object(); + + jsonWriter.key("id"); jsonWriter.value(null); + jsonWriter.key("name"); jsonWriter.value(null); + jsonWriter.key("guid"); jsonWriter.value(null); + jsonWriter.key("type"); jsonWriter.array(); jsonWriter.endArray(); + + jsonWriter.key("id|="); + jsonWriter.array(); + for (ReconJob job : jobs) { + jsonWriter.value(((IdBasedReconJob) job).id); + } + jsonWriter.endArray(); - jsonWriter.key("id"); jsonWriter.value(null); - jsonWriter.key("name"); jsonWriter.value(null); - jsonWriter.key("guid"); jsonWriter.value(null); - jsonWriter.key("type"); jsonWriter.array(); jsonWriter.endArray(); - - jsonWriter.key("id|="); - jsonWriter.array(); - for (ReconJob job : jobs) { - jsonWriter.value(((IdBasedReconJob) job).id); - } - jsonWriter.endArray(); - - jsonWriter.endObject(); - jsonWriter.endArray(); jsonWriter.endObject(); + jsonWriter.endArray(); query = stringWriter.toString(); } StringBuffer sb = new StringBuffer(1024); - sb.append(s_mqlreadService); - sb.append("?query="); + sb.append(getMqlreadService()); + sb.append("&query="); sb.append(ParsingUtilities.encode(query)); URL url = new URL(sb.toString()); diff --git a/extensions/freebase/src/com/google/refine/freebase/model/recon/KeyBasedReconConfig.java b/extensions/freebase/src/com/google/refine/freebase/model/recon/KeyBasedReconConfig.java index 682338454..378a518b2 100644 --- a/extensions/freebase/src/com/google/refine/freebase/model/recon/KeyBasedReconConfig.java +++ b/extensions/freebase/src/com/google/refine/freebase/model/recon/KeyBasedReconConfig.java @@ -129,46 +129,43 @@ public class KeyBasedReconConfig extends StrictReconConfig { StringWriter stringWriter = new StringWriter(); JSONWriter jsonWriter = new JSONWriter(stringWriter); + jsonWriter.array(); jsonWriter.object(); - jsonWriter.key("query"); - jsonWriter.array(); - jsonWriter.object(); + + jsonWriter.key("id"); jsonWriter.value(null); + jsonWriter.key("name"); jsonWriter.value(null); + jsonWriter.key("guid"); jsonWriter.value(null); + jsonWriter.key("type"); jsonWriter.array(); jsonWriter.endArray(); - jsonWriter.key("id"); jsonWriter.value(null); - jsonWriter.key("name"); jsonWriter.value(null); - jsonWriter.key("guid"); jsonWriter.value(null); - jsonWriter.key("type"); jsonWriter.array(); jsonWriter.endArray(); + jsonWriter.key("key"); + jsonWriter.array(); + jsonWriter.object(); - jsonWriter.key("key"); - jsonWriter.array(); + jsonWriter.key("namespace"); jsonWriter.object(); - - 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.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.endArray(); + + jsonWriter.endObject(); + jsonWriter.endArray(); + jsonWriter.endObject(); + jsonWriter.endArray(); query = stringWriter.toString(); } StringBuffer sb = new StringBuffer(1024); - sb.append(s_mqlreadService); - sb.append("?query="); + sb.append(getMqlreadService()); + sb.append("&query="); sb.append(ParsingUtilities.encode(query)); URL url = new URL(sb.toString()); diff --git a/extensions/freebase/src/com/google/refine/freebase/model/recon/StrictReconConfig.java b/extensions/freebase/src/com/google/refine/freebase/model/recon/StrictReconConfig.java index 3fe200a7e..e892b4604 100644 --- a/extensions/freebase/src/com/google/refine/freebase/model/recon/StrictReconConfig.java +++ b/extensions/freebase/src/com/google/refine/freebase/model/recon/StrictReconConfig.java @@ -40,7 +40,12 @@ import com.google.refine.model.Recon.Judgment; import com.google.refine.model.recon.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 { String match = obj.getString("match"); diff --git a/refine b/refine index feaaa6704..b09a8b397 100755 --- a/refine +++ b/refine @@ -45,7 +45,9 @@ where [options] include: -m max memory heap size to use default: 1024M - + + -k a server API key for calling Google APIs + -v verbosity level [from low to high: error,warn,info,debug,trace] default: info @@ -664,7 +666,11 @@ run() { if [ "$REFINE_HOST" ] ; then add_option "-Drefine.host=$REFINE_HOST" 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/*" RUN_CMD="$JAVA -cp $CLASSPATH $OPTS com.google.refine.Refine" @@ -701,7 +707,7 @@ broker_run() { add_option "-Drefine.autoreload=true -Dbutterfly.autoreload=true" add_option "-Drefine.development=true" fi - + add_option "-Drefine.webapp=broker/core" add_option "-Drefine.headless=true" @@ -869,6 +875,7 @@ while [ $# -ne 0 ] ; do -w) shift; REFINE_WEBAPP="$1"; shift; continue;; -d) shift; REFINE_DATA_DIR="$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;; -x) shift; REFINE_EXTRA_OPTS="$1"; shift; continue;; --debug) shift; add_option '-Xdebug -Xrunjdwp:transport=dt_socket,address=8000,server=y,suspend=n'; continue;;