From 0c70d281c772a33c1714f928d780755150a247ca Mon Sep 17 00:00:00 2001 From: David Huynh Date: Mon, 17 May 2010 23:47:09 +0000 Subject: [PATCH] Issue 28: mql-like preview is not properly unquoting numbers. git-svn-id: http://google-refine.googlecode.com/svn/trunk@807 7d457c2a-affb-35e4-300a-418c747d4874 --- CHANGES.txt | 2 ++ .../MqlreadLikeTransposedNodeFactory.java | 4 +++- .../metaweb/gridworks/util/JSONUtilities.java | 21 +++++++++++++++++++ 3 files changed, 26 insertions(+), 1 deletion(-) diff --git a/CHANGES.txt b/CHANGES.txt index a42bd1ac1..da6219ac1 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -8,6 +8,8 @@ Fixes: - Issue 41: "Envelope quotation marks are removed by CSV importer" - Issue 19: "CSV import is too basic" - Issue 15: "Ability to rename projects" +- Issue 16: "Column name collision when adding data from Freebase" +- Issue 28: "mql-like preview is not properly unquoting numbers" Changes: - Moved unit tests from JUnit to TestNG diff --git a/src/main/java/com/metaweb/gridworks/protograph/transpose/MqlreadLikeTransposedNodeFactory.java b/src/main/java/com/metaweb/gridworks/protograph/transpose/MqlreadLikeTransposedNodeFactory.java index c4ca93684..b7be8b837 100644 --- a/src/main/java/com/metaweb/gridworks/protograph/transpose/MqlreadLikeTransposedNodeFactory.java +++ b/src/main/java/com/metaweb/gridworks/protograph/transpose/MqlreadLikeTransposedNodeFactory.java @@ -17,6 +17,7 @@ import com.metaweb.gridworks.protograph.CellValueNode; import com.metaweb.gridworks.protograph.FreebaseProperty; import com.metaweb.gridworks.protograph.FreebaseTopicNode; import com.metaweb.gridworks.protograph.ValueNode; +import com.metaweb.gridworks.util.JSONUtilities; public class MqlreadLikeTransposedNodeFactory implements TransposedNodeFactory { protected List rootObjects = new LinkedList(); @@ -126,7 +127,8 @@ public class MqlreadLikeTransposedNodeFactory implements TransposedNodeFactory { if (obj == null) { obj = new JSONObject(); try { - obj.put(VALUE, cell.value.toString()); + JSONUtilities.putField(obj, VALUE, cell.value); + obj.put(TYPE, node.valueType); if ("/type/text".equals(node.valueType)) { obj.put(LANG, node.lang); diff --git a/src/main/java/com/metaweb/gridworks/util/JSONUtilities.java b/src/main/java/com/metaweb/gridworks/util/JSONUtilities.java index 5f5654581..61dc680f8 100644 --- a/src/main/java/com/metaweb/gridworks/util/JSONUtilities.java +++ b/src/main/java/com/metaweb/gridworks/util/JSONUtilities.java @@ -1,5 +1,6 @@ package com.metaweb.gridworks.util; +import java.util.Calendar; import java.util.Date; import java.util.List; @@ -108,4 +109,24 @@ public class JSONUtilities { } writer.endArray(); } + + static public void putField(JSONObject obj, String key, Object value) throws JSONException { + if (value instanceof Integer) { + obj.put(key, ((Integer) value).intValue()); + } else if (value instanceof Long) { + obj.put(key, ((Long) value).intValue()); + } else if (value instanceof Number) { + obj.put(key, ((Double) value).doubleValue()); + } else if (value instanceof Boolean) { + obj.put(key, (Boolean) value); + } else if (value instanceof Date) { + obj.put(key, ParsingUtilities.dateToString((Date) value)); + } else if (value instanceof Calendar) { + obj.put(key, ParsingUtilities.dateToString(((Calendar) value).getTime())); + } else if (value instanceof String) { + obj.put(key, (String) value); + } else { + obj.put(key, value.toString()); + } + } }