From 7648ca91cadc779c2e7f4f029dd43b5a60c0360d Mon Sep 17 00:00:00 2001 From: Antonin Delpeuch Date: Sun, 23 Sep 2018 11:27:41 +0100 Subject: [PATCH] Jackson serialization for GREL functions --- .../refine/expr/functions/Coalesce.java | 25 +++++++++------- .../google/refine/expr/functions/Cross.java | 21 +++++++------- .../refine/expr/functions/FacetCount.java | 21 +++++++------- .../com/google/refine/expr/functions/Get.java | 23 ++++++++------- .../refine/expr/functions/HasField.java | 19 +++++++----- .../google/refine/expr/functions/Jsonize.java | 19 +++++++----- .../google/refine/expr/functions/Length.java | 20 +++++++------ .../google/refine/expr/functions/Slice.java | 23 ++++++++------- .../google/refine/expr/functions/ToDate.java | 24 ++++++++------- .../refine/expr/functions/ToNumber.java | 21 +++++++------- .../refine/expr/functions/ToString.java | 21 +++++++------- .../google/refine/expr/functions/Type.java | 21 +++++++------- .../expr/functions/arrays/ArgsToArray.java | 21 +++++++------- .../refine/expr/functions/arrays/Join.java | 19 +++++++----- .../refine/expr/functions/arrays/Reverse.java | 19 +++++++----- .../refine/expr/functions/arrays/Sort.java | 19 +++++++----- .../refine/expr/functions/arrays/Uniques.java | 19 +++++++----- .../refine/expr/functions/booleans/And.java | 23 ++++++++------- .../refine/expr/functions/booleans/Not.java | 21 +++++++------- .../refine/expr/functions/booleans/Or.java | 23 ++++++++------- .../refine/expr/functions/booleans/Xor.java | 26 ++++++++--------- .../refine/expr/functions/date/DatePart.java | 29 ++++++++++--------- .../refine/expr/functions/date/Inc.java | 21 ++++++++------ .../refine/expr/functions/date/Now.java | 12 ++++---- .../refine/expr/functions/html/InnerHtml.java | 22 +++++++------- .../refine/expr/functions/html/ParseHtml.java | 23 ++++++++------- .../refine/expr/functions/math/ACos.java | 23 ++++++++------- .../refine/expr/functions/math/ASin.java | 23 ++++++++------- .../refine/expr/functions/math/ATan.java | 23 ++++++++------- .../refine/expr/functions/math/ATan2.java | 23 ++++++++------- .../refine/expr/functions/math/Abs.java | 21 +++++++------- .../refine/expr/functions/math/Ceil.java | 21 +++++++------- .../refine/expr/functions/math/Combin.java | 23 ++++++++------- .../refine/expr/functions/math/Cos.java | 23 ++++++++------- .../refine/expr/functions/math/Cosh.java | 23 ++++++++------- .../refine/expr/functions/math/Degrees.java | 23 ++++++++------- .../refine/expr/functions/math/Even.java | 23 ++++++++------- .../refine/expr/functions/math/Exp.java | 21 +++++++------- .../refine/expr/functions/math/Fact.java | 23 ++++++++------- .../refine/expr/functions/math/FactN.java | 23 ++++++++------- .../refine/expr/functions/math/Floor.java | 21 +++++++------- .../math/GreatestCommonDenominator.java | 23 ++++++++------- .../functions/math/LeastCommonMultiple.java | 23 ++++++++------- .../google/refine/expr/functions/math/Ln.java | 21 +++++++------- .../refine/expr/functions/math/Log.java | 21 +++++++------- .../refine/expr/functions/math/Max.java | 21 +++++++------- .../refine/expr/functions/math/Min.java | 21 +++++++------- .../refine/expr/functions/math/Mod.java | 21 +++++++------- .../expr/functions/math/Multinomial.java | 23 ++++++++------- .../refine/expr/functions/math/Odd.java | 23 ++++++++------- .../refine/expr/functions/math/Pow.java | 21 +++++++------- .../refine/expr/functions/math/Quotient.java | 23 ++++++++------- .../refine/expr/functions/math/Radians.java | 23 ++++++++------- .../refine/expr/functions/math/Round.java | 21 +++++++------- .../refine/expr/functions/math/Sin.java | 23 ++++++++------- .../refine/expr/functions/math/Sinh.java | 23 ++++++++------- .../refine/expr/functions/math/Sum.java | 21 +++++++------- .../refine/expr/functions/math/Tan.java | 23 ++++++++------- .../refine/expr/functions/math/Tanh.java | 23 ++++++++------- .../refine/expr/functions/strings/Chomp.java | 20 +++++++------ .../expr/functions/strings/Contains.java | 21 +++++++------- .../refine/expr/functions/strings/Diff.java | 20 ++++++++----- .../expr/functions/strings/EndsWith.java | 21 +++++++------- .../refine/expr/functions/strings/Escape.java | 20 +++++++------ .../refine/expr/functions/strings/Find.java | 21 +++++++------- .../expr/functions/strings/Fingerprint.java | 21 +++++++------- .../expr/functions/strings/IndexOf.java | 21 +++++++------- .../expr/functions/strings/LastIndexOf.java | 21 +++++++------- .../refine/expr/functions/strings/MD5.java | 20 +++++++------ .../refine/expr/functions/strings/Match.java | 21 +++++++------- .../refine/expr/functions/strings/NGram.java | 20 +++++++------ .../functions/strings/NGramFingerprint.java | 21 +++++++------- .../expr/functions/strings/ParseJson.java | 19 +++++++----- .../expr/functions/strings/Partition.java | 23 ++++++++------- .../expr/functions/strings/Phonetic.java | 21 +++++++------- .../expr/functions/strings/RPartition.java | 23 ++++++++------- .../refine/expr/functions/strings/Range.java | 27 ++++++++--------- .../expr/functions/strings/Reinterpret.java | 21 +++++++------- .../expr/functions/strings/Replace.java | 21 +++++++------- .../expr/functions/strings/ReplaceChars.java | 20 +++++++------ .../refine/expr/functions/strings/SHA1.java | 20 +++++++------ .../expr/functions/strings/SmartSplit.java | 25 ++++++++-------- .../refine/expr/functions/strings/Split.java | 20 +++++++------ .../functions/strings/SplitByCharType.java | 20 +++++++------ .../functions/strings/SplitByLengths.java | 21 +++++++------- .../expr/functions/strings/StartsWith.java | 21 +++++++------- .../expr/functions/strings/ToLowercase.java | 21 +++++++------- .../expr/functions/strings/ToTitlecase.java | 20 +++++++------ .../expr/functions/strings/ToUppercase.java | 21 +++++++------- .../refine/expr/functions/strings/Trim.java | 22 +++++++------- .../expr/functions/strings/Unescape.java | 20 +++++++------ .../expr/functions/strings/Unicode.java | 21 +++++++------- .../expr/functions/strings/UnicodeType.java | 21 +++++++------- .../refine/expr/functions/xml/OwnText.java | 22 +++++++------- .../refine/expr/functions/xml/SelectXml.java | 22 +++++++------- .../refine/expr/functions/xml/XmlAttr.java | 22 +++++++------- .../refine/expr/functions/xml/XmlText.java | 22 +++++++------- main/src/com/google/refine/grel/Function.java | 28 ++++++++++++++++++ 98 files changed, 1144 insertions(+), 978 deletions(-) diff --git a/main/src/com/google/refine/expr/functions/Coalesce.java b/main/src/com/google/refine/expr/functions/Coalesce.java index 5ef489c35..e3b384a46 100644 --- a/main/src/com/google/refine/expr/functions/Coalesce.java +++ b/main/src/com/google/refine/expr/functions/Coalesce.java @@ -35,9 +35,6 @@ package com.google.refine.expr.functions; import java.util.Properties; -import org.json.JSONException; -import org.json.JSONWriter; - import com.google.refine.expr.EvalError; import com.google.refine.grel.ControlFunctionRegistry; import com.google.refine.grel.Function; @@ -60,13 +57,19 @@ public class Coalesce implements Function { } @Override - public void write(JSONWriter writer, Properties options) - throws JSONException { - - writer.object(); - writer.key("description"); writer.value("Returns the first non-null from a series of values"); - writer.key("params"); writer.value("two or more objects"); - writer.key("returns"); writer.value("object or null"); - writer.endObject(); + public String getDescription() { + return "Returns the first non-null from a series of values"; } + + @Override + public String getParams() { + return "two or more objects"; + } + + @Override + public String getReturns() { + return "object or null"; + } + + } diff --git a/main/src/com/google/refine/expr/functions/Cross.java b/main/src/com/google/refine/expr/functions/Cross.java index 70347a941..b9ed764f2 100644 --- a/main/src/com/google/refine/expr/functions/Cross.java +++ b/main/src/com/google/refine/expr/functions/Cross.java @@ -35,9 +35,6 @@ package com.google.refine.expr.functions; import java.util.Properties; -import org.json.JSONException; -import org.json.JSONWriter; - import com.google.refine.InterProjectModel.ProjectJoin; import com.google.refine.ProjectManager; import com.google.refine.expr.EvalError; @@ -78,13 +75,17 @@ public class Cross implements Function { } @Override - public void write(JSONWriter writer, Properties options) - throws JSONException { + public String getDescription() { + return "join with another project by column"; + } - writer.object(); - writer.key("description"); writer.value("join with another project by column"); - writer.key("params"); writer.value("cell c or string value, string projectName, string columnName"); - writer.key("returns"); writer.value("array"); - writer.endObject(); + @Override + public String getParams() { + return "cell c or string value, string projectName, string columnName"; + } + + @Override + public String getReturns() { + return "array"; } } diff --git a/main/src/com/google/refine/expr/functions/FacetCount.java b/main/src/com/google/refine/expr/functions/FacetCount.java index 42e172265..7c4c689b0 100644 --- a/main/src/com/google/refine/expr/functions/FacetCount.java +++ b/main/src/com/google/refine/expr/functions/FacetCount.java @@ -35,9 +35,6 @@ package com.google.refine.expr.functions; import java.util.Properties; -import org.json.JSONException; -import org.json.JSONWriter; - import com.google.refine.browsing.Engine; import com.google.refine.browsing.util.ExpressionNominalValueGrouper; import com.google.refine.expr.EvalError; @@ -87,13 +84,17 @@ public class FacetCount implements Function { } @Override - public void write(JSONWriter writer, Properties options) - throws JSONException { + public String getDescription() { + return "Returns the facet count corresponding to the given choice value"; + } - writer.object(); - writer.key("description"); writer.value("Returns the facet count corresponding to the given choice value"); - writer.key("params"); writer.value("choiceValue, string facetExpression, string columnName"); - writer.key("returns"); writer.value("number"); - writer.endObject(); + @Override + public String getParams() { + return "choiceValue, string facetExpression, string columnName"; + } + + @Override + public String getReturns() { + return "number"; } } diff --git a/main/src/com/google/refine/expr/functions/Get.java b/main/src/com/google/refine/expr/functions/Get.java index 4e69fc020..d3dad40fd 100644 --- a/main/src/com/google/refine/expr/functions/Get.java +++ b/main/src/com/google/refine/expr/functions/Get.java @@ -39,7 +39,6 @@ import java.util.Properties; import org.json.JSONArray; import org.json.JSONException; import org.json.JSONObject; -import org.json.JSONWriter; import com.google.refine.expr.ExpressionUtils; import com.google.refine.expr.HasFields; @@ -166,17 +165,21 @@ public class Get implements Function { } @Override - public void write(JSONWriter writer, Properties options) - throws JSONException { - - writer.object(); - writer.key("description"); writer.value( + public String getDescription() { + return "If o has fields, returns the field named 'from' of o. " + "If o is an array, returns o[from, to]. " + "if o is a string, returns o.substring(from, to)" - ); - writer.key("params"); writer.value("o, number or string from, optional number to"); - writer.key("returns"); writer.value("Depends on actual arguments"); - writer.endObject(); + ; + } + + @Override + public String getParams() { + return "o, number or string from, optional number to"; + } + + @Override + public String getReturns() { + return "Depends on actual arguments"; } } diff --git a/main/src/com/google/refine/expr/functions/HasField.java b/main/src/com/google/refine/expr/functions/HasField.java index 25f8f32e9..8fb0cb282 100644 --- a/main/src/com/google/refine/expr/functions/HasField.java +++ b/main/src/com/google/refine/expr/functions/HasField.java @@ -37,7 +37,6 @@ import java.util.Properties; import org.json.JSONException; import org.json.JSONObject; -import org.json.JSONWriter; import com.google.refine.expr.HasFields; import com.google.refine.grel.Function; @@ -67,13 +66,17 @@ public class HasField implements Function { } @Override - public void write(JSONWriter writer, Properties options) - throws JSONException { + public String getDescription() { + return "Returns whether o has field name"; + } - writer.object(); - writer.key("description"); writer.value("Returns whether o has field name"); - writer.key("params"); writer.value("o, string name"); - writer.key("returns"); writer.value("boolean"); - writer.endObject(); + @Override + public String getParams() { + return "o, string name"; + } + + @Override + public String getReturns() { + return "boolean"; } } diff --git a/main/src/com/google/refine/expr/functions/Jsonize.java b/main/src/com/google/refine/expr/functions/Jsonize.java index ab0bc9567..1fdd02dbf 100644 --- a/main/src/com/google/refine/expr/functions/Jsonize.java +++ b/main/src/com/google/refine/expr/functions/Jsonize.java @@ -40,7 +40,6 @@ import java.util.Properties; import org.json.JSONArray; import org.json.JSONException; import org.json.JSONObject; -import org.json.JSONWriter; import com.google.refine.grel.Function; @@ -79,13 +78,17 @@ public class Jsonize implements Function { @Override - public void write(JSONWriter writer, Properties options) - throws JSONException { + public String getDescription() { + return "Quotes a value as a JSON literal value"; + } - writer.object(); - writer.key("description"); writer.value("Quotes a value as a JSON literal value"); - writer.key("params"); writer.value("value"); - writer.key("returns"); writer.value("JSON literal value"); - writer.endObject(); + @Override + public String getParams() { + return "value"; + } + + @Override + public String getReturns() { + return "JSON literal value"; } } diff --git a/main/src/com/google/refine/expr/functions/Length.java b/main/src/com/google/refine/expr/functions/Length.java index bbe7c3a88..e01b45eaf 100644 --- a/main/src/com/google/refine/expr/functions/Length.java +++ b/main/src/com/google/refine/expr/functions/Length.java @@ -37,8 +37,6 @@ import java.util.Collection; import java.util.Properties; import org.json.JSONArray; -import org.json.JSONException; -import org.json.JSONWriter; import com.google.refine.expr.EvalError; import com.google.refine.expr.HasFieldsList; @@ -72,13 +70,17 @@ public class Length implements Function { } @Override - public void write(JSONWriter writer, Properties options) - throws JSONException { + public String getDescription() { + return "Returns the length of o"; + } - writer.object(); - writer.key("description"); writer.value("Returns the length of o"); - writer.key("params"); writer.value("array or string o"); - writer.key("returns"); writer.value("number"); - writer.endObject(); + @Override + public String getParams() { + return "array or string o"; + } + + @Override + public String getReturns() { + return "number"; } } diff --git a/main/src/com/google/refine/expr/functions/Slice.java b/main/src/com/google/refine/expr/functions/Slice.java index c2aa63ae6..b757337ce 100644 --- a/main/src/com/google/refine/expr/functions/Slice.java +++ b/main/src/com/google/refine/expr/functions/Slice.java @@ -38,7 +38,6 @@ import java.util.Properties; import org.json.JSONArray; import org.json.JSONException; -import org.json.JSONWriter; import com.google.refine.expr.ExpressionUtils; import com.google.refine.expr.HasFieldsList; @@ -130,16 +129,20 @@ public class Slice implements Function { } @Override - public void write(JSONWriter writer, Properties options) - throws JSONException { - - writer.object(); - writer.key("description"); writer.value( + public String getDescription() { + return "If o is an array, returns o[from, to]. " + "if o is a string, returns o.substring(from, to)" - ); - writer.key("params"); writer.value("o, number from, optional number to"); - writer.key("returns"); writer.value("Depends on actual arguments"); - writer.endObject(); + ; + } + + @Override + public String getParams() { + return "o, number from, optional number to"; + } + + @Override + public String getReturns() { + return "Depends on actual arguments"; } } diff --git a/main/src/com/google/refine/expr/functions/ToDate.java b/main/src/com/google/refine/expr/functions/ToDate.java index 1a20e8cdf..2eecfe4b8 100644 --- a/main/src/com/google/refine/expr/functions/ToDate.java +++ b/main/src/com/google/refine/expr/functions/ToDate.java @@ -46,12 +46,10 @@ import java.util.Properties; import java.util.TimeZone; import org.apache.commons.lang3.StringUtils; -import org.json.JSONException; -import org.json.JSONWriter; import com.google.refine.expr.EvalError; -import com.google.refine.expr.util.CalendarParserException; import com.google.refine.expr.util.CalendarParser; +import com.google.refine.expr.util.CalendarParserException; import com.google.refine.grel.ControlFunctionRegistry; import com.google.refine.grel.Function; import com.google.refine.util.ParsingUtilities; @@ -188,13 +186,17 @@ public class ToDate implements Function { } @Override - public void write(JSONWriter writer, Properties options) - throws JSONException { - - writer.object(); - writer.key("description"); writer.value("Returns o converted to a date object, you can hint if the day or the month is listed first, or give an ordered list of possible formats using this syntax: http://docs.oracle.com/javase/7/docs/api/java/text/SimpleDateFormat.html"); - writer.key("params"); writer.value("o, boolean month_first / format1, format2, ... (all optional)"); - writer.key("returns"); writer.value("date"); - writer.endObject(); + public String getDescription() { + return "Returns o converted to a date object, you can hint if the day or the month is listed first, or give an ordered list of possible formats using this syntax: http://docs.oracle.com/javase/7/docs/api/java/text/SimpleDateFormat.html"; + } + + @Override + public String getParams() { + return "o, boolean month_first / format1, format2, ... (all optional)"; + } + + @Override + public String getReturns() { + return "date"; } } diff --git a/main/src/com/google/refine/expr/functions/ToNumber.java b/main/src/com/google/refine/expr/functions/ToNumber.java index 4935b3199..e4d6c9a80 100644 --- a/main/src/com/google/refine/expr/functions/ToNumber.java +++ b/main/src/com/google/refine/expr/functions/ToNumber.java @@ -35,9 +35,6 @@ package com.google.refine.expr.functions; import java.util.Properties; -import org.json.JSONException; -import org.json.JSONWriter; - import com.google.refine.expr.EvalError; import com.google.refine.grel.ControlFunctionRegistry; import com.google.refine.grel.Function; @@ -71,14 +68,18 @@ public class ToNumber implements Function { } @Override - public void write(JSONWriter writer, Properties options) - throws JSONException { + public String getDescription() { + return "Returns o converted to a number"; + } - writer.object(); - writer.key("description"); writer.value("Returns o converted to a number"); - writer.key("params"); writer.value("o"); - writer.key("returns"); writer.value("number"); - writer.endObject(); + @Override + public String getParams() { + return "o"; + } + + @Override + public String getReturns() { + return "number"; } } diff --git a/main/src/com/google/refine/expr/functions/ToString.java b/main/src/com/google/refine/expr/functions/ToString.java index 02bdaa203..6e90b684f 100644 --- a/main/src/com/google/refine/expr/functions/ToString.java +++ b/main/src/com/google/refine/expr/functions/ToString.java @@ -37,9 +37,6 @@ import java.time.OffsetDateTime; import java.time.format.DateTimeFormatter; import java.util.Properties; -import org.json.JSONException; -import org.json.JSONWriter; - import com.google.refine.expr.EvalError; import com.google.refine.grel.ControlFunctionRegistry; import com.google.refine.grel.Function; @@ -72,13 +69,17 @@ public class ToString implements Function { @Override - public void write(JSONWriter writer, Properties options) - throws JSONException { + public String getDescription() { + return "Returns o converted to a string"; + } - writer.object(); - writer.key("description"); writer.value("Returns o converted to a string"); - writer.key("params"); writer.value("o, string format (optional)"); - writer.key("returns"); writer.value("string"); - writer.endObject(); + @Override + public String getParams() { + return "o, string format (optional)"; + } + + @Override + public String getReturns() { + return "string"; } } diff --git a/main/src/com/google/refine/expr/functions/Type.java b/main/src/com/google/refine/expr/functions/Type.java index c22572a54..6c01a6071 100644 --- a/main/src/com/google/refine/expr/functions/Type.java +++ b/main/src/com/google/refine/expr/functions/Type.java @@ -37,9 +37,6 @@ import java.time.OffsetDateTime; import java.util.List; import java.util.Properties; -import org.json.JSONException; -import org.json.JSONWriter; - import com.google.refine.expr.EvalError; import com.google.refine.grel.ControlFunctionRegistry; import com.google.refine.grel.Function; @@ -72,13 +69,17 @@ public class Type implements Function { } @Override - public void write(JSONWriter writer, Properties options) - throws JSONException { + public String getDescription() { + return "Returns the type of o"; + } - writer.object(); - writer.key("description"); writer.value("Returns the type of o"); - writer.key("params"); writer.value("object o"); - writer.key("returns"); writer.value("string"); - writer.endObject(); + @Override + public String getParams() { + return "object o"; + } + + @Override + public String getReturns() { + return "string"; } } diff --git a/main/src/com/google/refine/expr/functions/arrays/ArgsToArray.java b/main/src/com/google/refine/expr/functions/arrays/ArgsToArray.java index 6612e1f9d..0d6c52217 100644 --- a/main/src/com/google/refine/expr/functions/arrays/ArgsToArray.java +++ b/main/src/com/google/refine/expr/functions/arrays/ArgsToArray.java @@ -35,9 +35,6 @@ package com.google.refine.expr.functions.arrays; import java.util.Properties; -import org.json.JSONException; -import org.json.JSONWriter; - import com.google.refine.grel.Function; public class ArgsToArray implements Function { @@ -48,13 +45,17 @@ public class ArgsToArray implements Function { } @Override - public void write(JSONWriter writer, Properties options) - throws JSONException { + public String getDescription() { + return "Returns all arguments passed to it as an array"; + } - writer.object(); - writer.key("description"); writer.value("Returns all arguments passed to it as an array"); - writer.key("params"); writer.value("a1, a2, ..."); - writer.key("returns"); writer.value("array"); - writer.endObject(); + @Override + public String getParams() { + return "a1, a2, ..."; + } + + @Override + public String getReturns() { + return "array"; } } diff --git a/main/src/com/google/refine/expr/functions/arrays/Join.java b/main/src/com/google/refine/expr/functions/arrays/Join.java index 2930b27a1..fb3fad9a4 100644 --- a/main/src/com/google/refine/expr/functions/arrays/Join.java +++ b/main/src/com/google/refine/expr/functions/arrays/Join.java @@ -38,7 +38,6 @@ import java.util.Properties; import org.json.JSONArray; import org.json.JSONException; -import org.json.JSONWriter; import com.google.refine.expr.EvalError; import com.google.refine.expr.ExpressionUtils; @@ -101,13 +100,17 @@ public class Join implements Function { } @Override - public void write(JSONWriter writer, Properties options) - throws JSONException { + public String getDescription() { + return "Returns the string obtained by joining the array a with the separator sep"; + } - writer.object(); - writer.key("description"); writer.value("Returns the string obtained by joining the array a with the separator sep"); - writer.key("params"); writer.value("array a, string sep"); - writer.key("returns"); writer.value("string"); - writer.endObject(); + @Override + public String getParams() { + return "array a, string sep"; + } + + @Override + public String getReturns() { + return "string"; } } diff --git a/main/src/com/google/refine/expr/functions/arrays/Reverse.java b/main/src/com/google/refine/expr/functions/arrays/Reverse.java index be0a3289e..eedc0195e 100644 --- a/main/src/com/google/refine/expr/functions/arrays/Reverse.java +++ b/main/src/com/google/refine/expr/functions/arrays/Reverse.java @@ -38,7 +38,6 @@ import java.util.Properties; import org.json.JSONArray; import org.json.JSONException; -import org.json.JSONWriter; import com.google.refine.expr.EvalError; import com.google.refine.expr.ExpressionUtils; @@ -88,13 +87,17 @@ public class Reverse implements Function { } @Override - public void write(JSONWriter writer, Properties options) - throws JSONException { + public String getDescription() { + return "Reverses array a"; + } - writer.object(); - writer.key("description"); writer.value("Reverses array a"); - writer.key("params"); writer.value("array a"); - writer.key("returns"); writer.value("array"); - writer.endObject(); + @Override + public String getParams() { + return "array a"; + } + + @Override + public String getReturns() { + return "array"; } } diff --git a/main/src/com/google/refine/expr/functions/arrays/Sort.java b/main/src/com/google/refine/expr/functions/arrays/Sort.java index de52ea7dd..090a79968 100644 --- a/main/src/com/google/refine/expr/functions/arrays/Sort.java +++ b/main/src/com/google/refine/expr/functions/arrays/Sort.java @@ -40,7 +40,6 @@ import java.util.Properties; import org.json.JSONArray; import org.json.JSONException; -import org.json.JSONWriter; import com.google.refine.expr.EvalError; import com.google.refine.grel.ControlFunctionRegistry; @@ -86,13 +85,17 @@ public class Sort implements Function { } @Override - public void write(JSONWriter writer, Properties options) - throws JSONException { + public String getDescription() { + return "Sorts array a"; + } - writer.object(); - writer.key("description"); writer.value("Sorts array a"); - writer.key("params"); writer.value("array a"); - writer.key("returns"); writer.value("array"); - writer.endObject(); + @Override + public String getParams() { + return "array a"; + } + + @Override + public String getReturns() { + return "array"; } } diff --git a/main/src/com/google/refine/expr/functions/arrays/Uniques.java b/main/src/com/google/refine/expr/functions/arrays/Uniques.java index 1acd8e41b..0ee2c50ef 100644 --- a/main/src/com/google/refine/expr/functions/arrays/Uniques.java +++ b/main/src/com/google/refine/expr/functions/arrays/Uniques.java @@ -40,7 +40,6 @@ import java.util.Set; import org.json.JSONArray; import org.json.JSONException; -import org.json.JSONWriter; import com.google.refine.expr.EvalError; import com.google.refine.expr.ExpressionUtils; @@ -86,13 +85,17 @@ public class Uniques implements Function { } @Override - public void write(JSONWriter writer, Properties options) - throws JSONException { + public String getDescription() { + return "Returns array a with duplicates removed"; + } - writer.object(); - writer.key("description"); writer.value("Returns array a with duplicates removed"); - writer.key("params"); writer.value("array a"); - writer.key("returns"); writer.value("array"); - writer.endObject(); + @Override + public String getParams() { + return "array a"; + } + + @Override + public String getReturns() { + return "array"; } } diff --git a/main/src/com/google/refine/expr/functions/booleans/And.java b/main/src/com/google/refine/expr/functions/booleans/And.java index 8794cb865..fea94814a 100644 --- a/main/src/com/google/refine/expr/functions/booleans/And.java +++ b/main/src/com/google/refine/expr/functions/booleans/And.java @@ -35,9 +35,6 @@ package com.google.refine.expr.functions.booleans; import java.util.Properties; -import org.json.JSONException; -import org.json.JSONWriter; - import com.google.refine.expr.EvalError; import com.google.refine.grel.ControlFunctionRegistry; import com.google.refine.grel.Function; @@ -58,13 +55,17 @@ public class And implements Function { } @Override - public void write(JSONWriter writer, Properties options) - throws JSONException { - - writer.object(); - writer.key("description"); writer.value("AND two or more booleans to yield a boolean"); - writer.key("params"); writer.value("boolean a, boolean b"); - writer.key("returns"); writer.value("boolean"); - writer.endObject(); + public String getDescription() { + return "AND two or more booleans to yield a boolean"; + } + + @Override + public String getParams() { + return "boolean a, boolean b"; + } + + @Override + public String getReturns() { + return "boolean"; } } diff --git a/main/src/com/google/refine/expr/functions/booleans/Not.java b/main/src/com/google/refine/expr/functions/booleans/Not.java index 4b62afb8d..05b2c7968 100644 --- a/main/src/com/google/refine/expr/functions/booleans/Not.java +++ b/main/src/com/google/refine/expr/functions/booleans/Not.java @@ -35,9 +35,6 @@ package com.google.refine.expr.functions.booleans; import java.util.Properties; -import org.json.JSONException; -import org.json.JSONWriter; - import com.google.refine.expr.EvalError; import com.google.refine.grel.ControlFunctionRegistry; import com.google.refine.grel.Function; @@ -58,13 +55,17 @@ public class Not implements Function { } @Override - public void write(JSONWriter writer, Properties options) - throws JSONException { + public String getDescription() { + return "Returns the opposite of b"; + } - writer.object(); - writer.key("description"); writer.value("Returns the opposite of b"); - writer.key("params"); writer.value("boolean b"); - writer.key("returns"); writer.value("boolean"); - writer.endObject(); + @Override + public String getParams() { + return "boolean b"; + } + + @Override + public String getReturns() { + return "boolean"; } } diff --git a/main/src/com/google/refine/expr/functions/booleans/Or.java b/main/src/com/google/refine/expr/functions/booleans/Or.java index 0b1b10b0e..91b3a2b6c 100644 --- a/main/src/com/google/refine/expr/functions/booleans/Or.java +++ b/main/src/com/google/refine/expr/functions/booleans/Or.java @@ -35,9 +35,6 @@ package com.google.refine.expr.functions.booleans; import java.util.Properties; -import org.json.JSONException; -import org.json.JSONWriter; - import com.google.refine.expr.EvalError; import com.google.refine.grel.ControlFunctionRegistry; import com.google.refine.grel.Function; @@ -58,13 +55,17 @@ public class Or implements Function { } @Override - public void write(JSONWriter writer, Properties options) - throws JSONException { - - writer.object(); - writer.key("description"); writer.value("OR two or more booleans to yield a boolean"); - writer.key("params"); writer.value("boolean a, boolean b"); - writer.key("returns"); writer.value("boolean"); - writer.endObject(); + public String getDescription() { + return "OR two or more booleans to yield a boolean"; + } + + @Override + public String getParams() { + return "boolean a, boolean b"; + } + + @Override + public String getReturns() { + return "boolean"; } } diff --git a/main/src/com/google/refine/expr/functions/booleans/Xor.java b/main/src/com/google/refine/expr/functions/booleans/Xor.java index 39bc687a6..d104772a5 100644 --- a/main/src/com/google/refine/expr/functions/booleans/Xor.java +++ b/main/src/com/google/refine/expr/functions/booleans/Xor.java @@ -27,9 +27,6 @@ package com.google.refine.expr.functions.booleans; import java.util.Properties; -import org.json.JSONException; -import org.json.JSONWriter; - import com.google.refine.expr.EvalError; import com.google.refine.grel.ControlFunctionRegistry; import com.google.refine.grel.Function; @@ -45,16 +42,17 @@ public class Xor implements Function { } @Override - public void write(JSONWriter writer, Properties options) - throws JSONException { - - writer.object(); - writer.key("description"); - writer.value("XORs two or more boolean values"); - writer.key("params"); - writer.value("boolean a, boolean b"); - writer.key("returns"); - writer.value("boolean"); - writer.endObject(); + public String getDescription() { + return "XORs two or more boolean values"; + } + + @Override + public String getParams() { + return "boolean a, boolean b"; + } + + @Override + public String getReturns() { + return "boolean"; } } diff --git a/main/src/com/google/refine/expr/functions/date/DatePart.java b/main/src/com/google/refine/expr/functions/date/DatePart.java index 8b305470c..6f048310a 100644 --- a/main/src/com/google/refine/expr/functions/date/DatePart.java +++ b/main/src/com/google/refine/expr/functions/date/DatePart.java @@ -33,18 +33,15 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. package com.google.refine.expr.functions.date; -import java.util.Calendar; -import java.util.Date; -import java.util.Properties; -import java.util.TimeZone; import java.time.DayOfWeek; import java.time.LocalDate; import java.time.OffsetDateTime; import java.time.temporal.TemporalField; import java.time.temporal.WeekFields; - -import org.json.JSONException; -import org.json.JSONWriter; +import java.util.Calendar; +import java.util.Date; +import java.util.Properties; +import java.util.TimeZone; import com.google.refine.expr.EvalError; import com.google.refine.grel.ControlFunctionRegistry; @@ -141,11 +138,17 @@ public class DatePart implements Function { } @Override - public void write(JSONWriter writer, Properties options) throws JSONException { - writer.object(); - writer.key("description"); writer.value("Returns part of a date"); - writer.key("params"); writer.value("date d, string part"); - writer.key("returns"); writer.value("date"); - writer.endObject(); + public String getDescription() { + return "Returns part of a date"; + } + + @Override + public String getParams() { + return "date d, string part"; + } + + @Override + public String getReturns() { + return "date"; } } diff --git a/main/src/com/google/refine/expr/functions/date/Inc.java b/main/src/com/google/refine/expr/functions/date/Inc.java index ff521d620..a5a3c1c2e 100644 --- a/main/src/com/google/refine/expr/functions/date/Inc.java +++ b/main/src/com/google/refine/expr/functions/date/Inc.java @@ -38,9 +38,6 @@ import java.time.temporal.ChronoUnit; import java.time.temporal.TemporalUnit; import java.util.Properties; -import org.json.JSONException; -import org.json.JSONWriter; - import com.google.refine.expr.EvalError; import com.google.refine.grel.ControlFunctionRegistry; import com.google.refine.grel.Function; @@ -88,11 +85,17 @@ public class Inc implements Function { } @Override - public void write(JSONWriter writer, Properties options) throws JSONException { - writer.object(); - writer.key("description"); writer.value("Returns a date changed by the given amount in the given unit of time"); - writer.key("params"); writer.value("date d, number value, string unit (default to 'hour')"); - writer.key("returns"); writer.value("date"); - writer.endObject(); + public String getDescription() { + return "Returns a date changed by the given amount in the given unit of time"; + } + + @Override + public String getParams() { + return "date d, number value, string unit (default to 'hour')"; + } + + @Override + public String getReturns() { + return "date"; } } diff --git a/main/src/com/google/refine/expr/functions/date/Now.java b/main/src/com/google/refine/expr/functions/date/Now.java index 158f81a2e..ba0d88c63 100644 --- a/main/src/com/google/refine/expr/functions/date/Now.java +++ b/main/src/com/google/refine/expr/functions/date/Now.java @@ -53,12 +53,12 @@ public class Now implements Function { } @Override - public void write(JSONWriter writer, Properties options) - throws JSONException { + public String getDescription() { + return "Returns the current time"; + } - writer.object(); - writer.key("description"); writer.value("Returns the current time"); - writer.key("returns"); writer.value("date"); - writer.endObject(); + @Override + public String getReturns() { + return "date"; } } diff --git a/main/src/com/google/refine/expr/functions/html/InnerHtml.java b/main/src/com/google/refine/expr/functions/html/InnerHtml.java index 5e9853d46..5a0b8b4f8 100644 --- a/main/src/com/google/refine/expr/functions/html/InnerHtml.java +++ b/main/src/com/google/refine/expr/functions/html/InnerHtml.java @@ -35,8 +35,6 @@ package com.google.refine.expr.functions.html; import java.util.Properties; -import org.json.JSONException; -import org.json.JSONWriter; import org.jsoup.nodes.Element; import com.google.refine.expr.EvalError; @@ -61,14 +59,18 @@ public class InnerHtml implements Function { @Override - public void write(JSONWriter writer, Properties options) - throws JSONException { - - writer.object(); - writer.key("description"); writer.value("The innerHtml of an HTML element"); - writer.key("params"); writer.value("Element e"); - writer.key("returns"); writer.value("String innerHtml"); - writer.endObject(); + public String getDescription() { + return "The innerHtml of an HTML element"; + } + + @Override + public String getParams() { + return "Element e"; + } + + @Override + public String getReturns() { + return "String innerHtml"; } } diff --git a/main/src/com/google/refine/expr/functions/html/ParseHtml.java b/main/src/com/google/refine/expr/functions/html/ParseHtml.java index 14ae4b3cd..482fd2c7f 100644 --- a/main/src/com/google/refine/expr/functions/html/ParseHtml.java +++ b/main/src/com/google/refine/expr/functions/html/ParseHtml.java @@ -35,8 +35,7 @@ package com.google.refine.expr.functions.html; import java.util.Properties; -import org.json.JSONException; -import org.json.JSONWriter; +import org.jsoup.Jsoup; import com.google.refine.expr.EvalError; import com.google.refine.expr.functions.xml.ParseXml; @@ -58,14 +57,18 @@ public class ParseHtml implements Function { @Override - public void write(JSONWriter writer, Properties options) - throws JSONException { - - writer.object(); - writer.key("description"); writer.value("Parses a string as HTML"); - writer.key("params"); writer.value("string s"); - writer.key("returns"); writer.value("HTML object"); - writer.endObject(); + public String getDescription() { + return "Parses a string as HTML"; + } + + @Override + public String getParams() { + return "string s"; + } + + @Override + public String getReturns() { + return "HTML object"; } } diff --git a/main/src/com/google/refine/expr/functions/math/ACos.java b/main/src/com/google/refine/expr/functions/math/ACos.java index e4b31269e..99a2632fa 100644 --- a/main/src/com/google/refine/expr/functions/math/ACos.java +++ b/main/src/com/google/refine/expr/functions/math/ACos.java @@ -35,9 +35,6 @@ package com.google.refine.expr.functions.math; import java.util.Properties; -import org.json.JSONException; -import org.json.JSONWriter; - import com.google.refine.expr.EvalError; import com.google.refine.grel.ControlFunctionRegistry; import com.google.refine.grel.Function; @@ -53,13 +50,17 @@ public class ACos implements Function { } @Override - public void write(JSONWriter writer, Properties options) - throws JSONException { - - writer.object(); - writer.key("description"); writer.value("Returns the arc cosine of an angle, in the range 0 through PI"); - writer.key("params"); writer.value("number d"); - writer.key("returns"); writer.value("number"); - writer.endObject(); + public String getDescription() { + return "Returns the arc cosine of an angle, in the range 0 through PI"; + } + + @Override + public String getParams() { + return "number d"; + } + + @Override + public String getReturns() { + return "number"; } } \ No newline at end of file diff --git a/main/src/com/google/refine/expr/functions/math/ASin.java b/main/src/com/google/refine/expr/functions/math/ASin.java index 6abdb5c1b..c7cbbeb7c 100644 --- a/main/src/com/google/refine/expr/functions/math/ASin.java +++ b/main/src/com/google/refine/expr/functions/math/ASin.java @@ -35,9 +35,6 @@ package com.google.refine.expr.functions.math; import java.util.Properties; -import org.json.JSONException; -import org.json.JSONWriter; - import com.google.refine.expr.EvalError; import com.google.refine.grel.ControlFunctionRegistry; import com.google.refine.grel.Function; @@ -53,13 +50,17 @@ public class ASin implements Function { } @Override - public void write(JSONWriter writer, Properties options) - throws JSONException { - - writer.object(); - writer.key("description"); writer.value("Returns the arc sine of an angle in the range of -PI/2 through PI/2"); - writer.key("params"); writer.value("number d"); - writer.key("returns"); writer.value("number"); - writer.endObject(); + public String getDescription() { + return "Returns the arc sine of an angle in the range of -PI/2 through PI/2"; + } + + @Override + public String getParams() { + return "number d"; + } + + @Override + public String getReturns() { + return "number"; } } \ No newline at end of file diff --git a/main/src/com/google/refine/expr/functions/math/ATan.java b/main/src/com/google/refine/expr/functions/math/ATan.java index 76e85f513..226bd18a6 100644 --- a/main/src/com/google/refine/expr/functions/math/ATan.java +++ b/main/src/com/google/refine/expr/functions/math/ATan.java @@ -35,9 +35,6 @@ package com.google.refine.expr.functions.math; import java.util.Properties; -import org.json.JSONException; -import org.json.JSONWriter; - import com.google.refine.expr.EvalError; import com.google.refine.grel.ControlFunctionRegistry; import com.google.refine.grel.Function; @@ -53,13 +50,17 @@ public class ATan implements Function { } @Override - public void write(JSONWriter writer, Properties options) - throws JSONException { - - writer.object(); - writer.key("description"); writer.value("Returns the arc tangent of an angle in the range of -PI/2 through PI/2"); - writer.key("params"); writer.value("number d"); - writer.key("returns"); writer.value("number"); - writer.endObject(); + public String getDescription() { + return "Returns the arc tangent of an angle in the range of -PI/2 through PI/2"; + } + + @Override + public String getParams() { + return "number d"; + } + + @Override + public String getReturns() { + return "number"; } } \ No newline at end of file diff --git a/main/src/com/google/refine/expr/functions/math/ATan2.java b/main/src/com/google/refine/expr/functions/math/ATan2.java index e175a5fc3..6b2019dd2 100644 --- a/main/src/com/google/refine/expr/functions/math/ATan2.java +++ b/main/src/com/google/refine/expr/functions/math/ATan2.java @@ -35,9 +35,6 @@ package com.google.refine.expr.functions.math; import java.util.Properties; -import org.json.JSONException; -import org.json.JSONWriter; - import com.google.refine.expr.EvalError; import com.google.refine.grel.ControlFunctionRegistry; import com.google.refine.grel.Function; @@ -54,13 +51,17 @@ public class ATan2 implements Function { } @Override - public void write(JSONWriter writer, Properties options) - throws JSONException { - - writer.object(); - writer.key("description"); writer.value("Converts rectangular coordinates (x, y) to polar (r, theta)"); - writer.key("params"); writer.value("number x, number y"); - writer.key("returns"); writer.value("number theta"); - writer.endObject(); + public String getDescription() { + return "Converts rectangular coordinates (x, y) to polar (r, theta)"; + } + + @Override + public String getParams() { + return "number x, number y"; + } + + @Override + public String getReturns() { + return "number theta"; } } \ No newline at end of file diff --git a/main/src/com/google/refine/expr/functions/math/Abs.java b/main/src/com/google/refine/expr/functions/math/Abs.java index a67734377..14a5cc0cb 100644 --- a/main/src/com/google/refine/expr/functions/math/Abs.java +++ b/main/src/com/google/refine/expr/functions/math/Abs.java @@ -35,9 +35,6 @@ package com.google.refine.expr.functions.math; import java.util.Properties; -import org.json.JSONException; -import org.json.JSONWriter; - import com.google.refine.expr.EvalError; import com.google.refine.grel.ControlFunctionRegistry; import com.google.refine.grel.Function; @@ -53,13 +50,17 @@ public class Abs implements Function { } @Override - public void write(JSONWriter writer, Properties options) - throws JSONException { + public String getDescription() { + return "Returns the absolute value of a number"; + } - writer.object(); - writer.key("description"); writer.value("Returns the absolute value of a number"); - writer.key("params"); writer.value("number d"); - writer.key("returns"); writer.value("number"); - writer.endObject(); + @Override + public String getParams() { + return "number d"; + } + + @Override + public String getReturns() { + return "number"; } } diff --git a/main/src/com/google/refine/expr/functions/math/Ceil.java b/main/src/com/google/refine/expr/functions/math/Ceil.java index 3053df1e9..c986a0429 100644 --- a/main/src/com/google/refine/expr/functions/math/Ceil.java +++ b/main/src/com/google/refine/expr/functions/math/Ceil.java @@ -35,9 +35,6 @@ package com.google.refine.expr.functions.math; import java.util.Properties; -import org.json.JSONException; -import org.json.JSONWriter; - import com.google.refine.expr.EvalError; import com.google.refine.grel.ControlFunctionRegistry; import com.google.refine.grel.Function; @@ -53,13 +50,17 @@ public class Ceil implements Function { } @Override - public void write(JSONWriter writer, Properties options) - throws JSONException { + public String getDescription() { + return "Returns the ceiling of a number"; + } - writer.object(); - writer.key("description"); writer.value("Returns the ceiling of a number"); - writer.key("params"); writer.value("number d"); - writer.key("returns"); writer.value("number"); - writer.endObject(); + @Override + public String getParams() { + return "number d"; + } + + @Override + public String getReturns() { + return "number"; } } diff --git a/main/src/com/google/refine/expr/functions/math/Combin.java b/main/src/com/google/refine/expr/functions/math/Combin.java index 4ad3d849c..0e9a120c0 100644 --- a/main/src/com/google/refine/expr/functions/math/Combin.java +++ b/main/src/com/google/refine/expr/functions/math/Combin.java @@ -35,9 +35,6 @@ package com.google.refine.expr.functions.math; import java.util.Properties; -import org.json.JSONException; -import org.json.JSONWriter; - import com.google.refine.expr.EvalError; import com.google.refine.grel.ControlFunctionRegistry; import com.google.refine.grel.Function; @@ -87,13 +84,17 @@ public class Combin implements Function { } @Override - public void write(JSONWriter writer, Properties options) - throws JSONException { - - writer.object(); - writer.key("description"); writer.value("Returns the number of combinations for n elements as divided into k"); - writer.key("params"); writer.value("number d"); - writer.key("returns"); writer.value("number"); - writer.endObject(); + public String getDescription() { + return "Returns the number of combinations for n elements as divided into k"; + } + + @Override + public String getParams() { + return "number d"; + } + + @Override + public String getReturns() { + return "number"; } } \ No newline at end of file diff --git a/main/src/com/google/refine/expr/functions/math/Cos.java b/main/src/com/google/refine/expr/functions/math/Cos.java index 9f597df62..6d15df4dc 100644 --- a/main/src/com/google/refine/expr/functions/math/Cos.java +++ b/main/src/com/google/refine/expr/functions/math/Cos.java @@ -35,9 +35,6 @@ package com.google.refine.expr.functions.math; import java.util.Properties; -import org.json.JSONException; -import org.json.JSONWriter; - import com.google.refine.expr.EvalError; import com.google.refine.grel.ControlFunctionRegistry; import com.google.refine.grel.Function; @@ -53,13 +50,17 @@ public class Cos implements Function { } @Override - public void write(JSONWriter writer, Properties options) - throws JSONException { - - writer.object(); - writer.key("description"); writer.value("Returns the trigonometric cosine of an angle"); - writer.key("params"); writer.value("number d"); - writer.key("returns"); writer.value("number"); - writer.endObject(); + public String getDescription() { + return "Returns the trigonometric cosine of an angle"; + } + + @Override + public String getParams() { + return "number d"; + } + + @Override + public String getReturns() { + return "number"; } } \ No newline at end of file diff --git a/main/src/com/google/refine/expr/functions/math/Cosh.java b/main/src/com/google/refine/expr/functions/math/Cosh.java index 867d6dce6..04420734e 100644 --- a/main/src/com/google/refine/expr/functions/math/Cosh.java +++ b/main/src/com/google/refine/expr/functions/math/Cosh.java @@ -35,9 +35,6 @@ package com.google.refine.expr.functions.math; import java.util.Properties; -import org.json.JSONException; -import org.json.JSONWriter; - import com.google.refine.expr.EvalError; import com.google.refine.grel.ControlFunctionRegistry; import com.google.refine.grel.Function; @@ -53,13 +50,17 @@ public class Cosh implements Function { } @Override - public void write(JSONWriter writer, Properties options) - throws JSONException { - - writer.object(); - writer.key("description"); writer.value("Returns the hyperbolic cosine of a value"); - writer.key("params"); writer.value("number d"); - writer.key("returns"); writer.value("number"); - writer.endObject(); + public String getDescription() { + return "Returns the hyperbolic cosine of a value"; + } + + @Override + public String getParams() { + return "number d"; + } + + @Override + public String getReturns() { + return "number"; } } diff --git a/main/src/com/google/refine/expr/functions/math/Degrees.java b/main/src/com/google/refine/expr/functions/math/Degrees.java index 03aac39d0..96c3e3b85 100644 --- a/main/src/com/google/refine/expr/functions/math/Degrees.java +++ b/main/src/com/google/refine/expr/functions/math/Degrees.java @@ -35,9 +35,6 @@ package com.google.refine.expr.functions.math; import java.util.Properties; -import org.json.JSONException; -import org.json.JSONWriter; - import com.google.refine.expr.EvalError; import com.google.refine.grel.ControlFunctionRegistry; import com.google.refine.grel.Function; @@ -53,13 +50,17 @@ public class Degrees implements Function { } @Override - public void write(JSONWriter writer, Properties options) - throws JSONException { - - writer.object(); - writer.key("description"); writer.value("Converts an angle from radians to degrees."); - writer.key("params"); writer.value("number d"); - writer.key("returns"); writer.value("number"); - writer.endObject(); + public String getDescription() { + return "Converts an angle from radians to degrees."; + } + + @Override + public String getParams() { + return "number d"; + } + + @Override + public String getReturns() { + return "number"; } } \ No newline at end of file diff --git a/main/src/com/google/refine/expr/functions/math/Even.java b/main/src/com/google/refine/expr/functions/math/Even.java index 12e678495..22bef743a 100644 --- a/main/src/com/google/refine/expr/functions/math/Even.java +++ b/main/src/com/google/refine/expr/functions/math/Even.java @@ -35,9 +35,6 @@ package com.google.refine.expr.functions.math; import java.util.Properties; -import org.json.JSONException; -import org.json.JSONWriter; - import com.google.refine.expr.EvalError; import com.google.refine.grel.ControlFunctionRegistry; import com.google.refine.grel.Function; @@ -58,13 +55,17 @@ public class Even implements Function { } @Override - public void write(JSONWriter writer, Properties options) - throws JSONException { - - writer.object(); - writer.key("description"); writer.value("Rounds the number up to the nearest even integer"); - writer.key("params"); writer.value("number d"); - writer.key("returns"); writer.value("number"); - writer.endObject(); + public String getDescription() { + return "Rounds the number up to the nearest even integer"; + } + + @Override + public String getParams() { + return "number d"; + } + + @Override + public String getReturns() { + return "number"; } } \ No newline at end of file diff --git a/main/src/com/google/refine/expr/functions/math/Exp.java b/main/src/com/google/refine/expr/functions/math/Exp.java index 273bf732f..52f01b688 100644 --- a/main/src/com/google/refine/expr/functions/math/Exp.java +++ b/main/src/com/google/refine/expr/functions/math/Exp.java @@ -35,9 +35,6 @@ package com.google.refine.expr.functions.math; import java.util.Properties; -import org.json.JSONException; -import org.json.JSONWriter; - import com.google.refine.grel.Function; public class Exp implements Function { @@ -51,13 +48,17 @@ public class Exp implements Function { } @Override - public void write(JSONWriter writer, Properties options) - throws JSONException { + public String getDescription() { + return "Returns e^n"; + } - writer.object(); - writer.key("description"); writer.value("Returns e^n"); - writer.key("params"); writer.value("number n"); - writer.key("returns"); writer.value("number"); - writer.endObject(); + @Override + public String getParams() { + return "number n"; + } + + @Override + public String getReturns() { + return "number"; } } diff --git a/main/src/com/google/refine/expr/functions/math/Fact.java b/main/src/com/google/refine/expr/functions/math/Fact.java index e1f8ab1ec..b9aa916ce 100644 --- a/main/src/com/google/refine/expr/functions/math/Fact.java +++ b/main/src/com/google/refine/expr/functions/math/Fact.java @@ -35,9 +35,6 @@ package com.google.refine.expr.functions.math; import java.util.Properties; -import org.json.JSONException; -import org.json.JSONWriter; - import com.google.refine.expr.EvalError; import com.google.refine.grel.ControlFunctionRegistry; import com.google.refine.grel.Function; @@ -53,13 +50,17 @@ public class Fact implements Function { } @Override - public void write(JSONWriter writer, Properties options) - throws JSONException { - - writer.object(); - writer.key("description"); writer.value("Returns the factorial of a number"); - writer.key("params"); writer.value("number i"); - writer.key("returns"); writer.value("number"); - writer.endObject(); + public String getDescription() { + return "Returns the factorial of a number"; + } + + @Override + public String getParams() { + return "number i"; + } + + @Override + public String getReturns() { + return "number"; } } \ No newline at end of file diff --git a/main/src/com/google/refine/expr/functions/math/FactN.java b/main/src/com/google/refine/expr/functions/math/FactN.java index 9b2254526..dfcb73bbc 100644 --- a/main/src/com/google/refine/expr/functions/math/FactN.java +++ b/main/src/com/google/refine/expr/functions/math/FactN.java @@ -35,9 +35,6 @@ package com.google.refine.expr.functions.math; import java.util.Properties; -import org.json.JSONException; -import org.json.JSONWriter; - import com.google.refine.expr.EvalError; import com.google.refine.grel.ControlFunctionRegistry; import com.google.refine.grel.Function; @@ -80,13 +77,17 @@ public class FactN implements Function { } @Override - public void write(JSONWriter writer, Properties options) - throws JSONException { - - writer.object(); - writer.key("description"); writer.value("Returns the factorial of a number"); - writer.key("params"); writer.value("number i"); - writer.key("returns"); writer.value("number"); - writer.endObject(); + public String getDescription() { + return "Returns the factorial of a number"; + } + + @Override + public String getParams() { + return "number i"; + } + + @Override + public String getReturns() { + return "number"; } } \ No newline at end of file diff --git a/main/src/com/google/refine/expr/functions/math/Floor.java b/main/src/com/google/refine/expr/functions/math/Floor.java index ccf9aa35f..2d7602b95 100644 --- a/main/src/com/google/refine/expr/functions/math/Floor.java +++ b/main/src/com/google/refine/expr/functions/math/Floor.java @@ -35,9 +35,6 @@ package com.google.refine.expr.functions.math; import java.util.Properties; -import org.json.JSONException; -import org.json.JSONWriter; - import com.google.refine.expr.EvalError; import com.google.refine.grel.ControlFunctionRegistry; import com.google.refine.grel.Function; @@ -53,14 +50,18 @@ public class Floor implements Function { } @Override - public void write(JSONWriter writer, Properties options) - throws JSONException { + public String getDescription() { + return "Returns the floor of a number as an integer"; + } - writer.object(); - writer.key("description"); writer.value("Returns the floor of a number as an integer"); - writer.key("params"); writer.value("number d"); - writer.key("returns"); writer.value("number"); - writer.endObject(); + @Override + public String getParams() { + return "number d"; + } + + @Override + public String getReturns() { + return "number"; } } diff --git a/main/src/com/google/refine/expr/functions/math/GreatestCommonDenominator.java b/main/src/com/google/refine/expr/functions/math/GreatestCommonDenominator.java index a9702f1f6..c9a115112 100644 --- a/main/src/com/google/refine/expr/functions/math/GreatestCommonDenominator.java +++ b/main/src/com/google/refine/expr/functions/math/GreatestCommonDenominator.java @@ -35,9 +35,6 @@ package com.google.refine.expr.functions.math; import java.util.Properties; -import org.json.JSONException; -import org.json.JSONWriter; - import com.google.refine.expr.EvalError; import com.google.refine.grel.ControlFunctionRegistry; import com.google.refine.grel.Function; @@ -58,13 +55,17 @@ public class GreatestCommonDenominator implements Function { } @Override - public void write(JSONWriter writer, Properties options) - throws JSONException { - - writer.object(); - writer.key("description"); writer.value("Returns the greatest common denominator of the two numbers"); - writer.key("params"); writer.value("number d, number e"); - writer.key("returns"); writer.value("number"); - writer.endObject(); + public String getDescription() { + return "Returns the greatest common denominator of the two numbers"; + } + + @Override + public String getParams() { + return "number d, number e"; + } + + @Override + public String getReturns() { + return "number"; } } \ No newline at end of file diff --git a/main/src/com/google/refine/expr/functions/math/LeastCommonMultiple.java b/main/src/com/google/refine/expr/functions/math/LeastCommonMultiple.java index 1fb8054d2..ad6635421 100644 --- a/main/src/com/google/refine/expr/functions/math/LeastCommonMultiple.java +++ b/main/src/com/google/refine/expr/functions/math/LeastCommonMultiple.java @@ -35,9 +35,6 @@ package com.google.refine.expr.functions.math; import java.util.Properties; -import org.json.JSONException; -import org.json.JSONWriter; - import com.google.refine.expr.EvalError; import com.google.refine.grel.ControlFunctionRegistry; import com.google.refine.grel.Function; @@ -70,13 +67,17 @@ public class LeastCommonMultiple implements Function { } @Override - public void write(JSONWriter writer, Properties options) - throws JSONException { - - writer.object(); - writer.key("description"); writer.value("Returns the greatest common denominator of the two numbers"); - writer.key("params"); writer.value("number d, number e"); - writer.key("returns"); writer.value("number"); - writer.endObject(); + public String getDescription() { + return "Returns the greatest common denominator of the two numbers"; + } + + @Override + public String getParams() { + return "number d, number e"; + } + + @Override + public String getReturns() { + return "number"; } } \ No newline at end of file diff --git a/main/src/com/google/refine/expr/functions/math/Ln.java b/main/src/com/google/refine/expr/functions/math/Ln.java index 227eb15be..2da1c4249 100644 --- a/main/src/com/google/refine/expr/functions/math/Ln.java +++ b/main/src/com/google/refine/expr/functions/math/Ln.java @@ -35,9 +35,6 @@ package com.google.refine.expr.functions.math; import java.util.Properties; -import org.json.JSONException; -import org.json.JSONWriter; - import com.google.refine.expr.EvalError; import com.google.refine.grel.ControlFunctionRegistry; import com.google.refine.grel.Function; @@ -53,13 +50,17 @@ public class Ln implements Function { } @Override - public void write(JSONWriter writer, Properties options) - throws JSONException { + public String getDescription() { + return "Returns the natural log of n"; + } - writer.object(); - writer.key("description"); writer.value("Returns the natural log of n"); - writer.key("params"); writer.value("number n"); - writer.key("returns"); writer.value("number"); - writer.endObject(); + @Override + public String getParams() { + return "number n"; + } + + @Override + public String getReturns() { + return "number"; } } diff --git a/main/src/com/google/refine/expr/functions/math/Log.java b/main/src/com/google/refine/expr/functions/math/Log.java index e24b74955..efeac212d 100644 --- a/main/src/com/google/refine/expr/functions/math/Log.java +++ b/main/src/com/google/refine/expr/functions/math/Log.java @@ -35,9 +35,6 @@ package com.google.refine.expr.functions.math; import java.util.Properties; -import org.json.JSONException; -import org.json.JSONWriter; - import com.google.refine.expr.EvalError; import com.google.refine.grel.ControlFunctionRegistry; import com.google.refine.grel.Function; @@ -53,13 +50,17 @@ public class Log implements Function { } @Override - public void write(JSONWriter writer, Properties options) - throws JSONException { + public String getDescription() { + return "Returns the base 10 log of n"; + } - writer.object(); - writer.key("description"); writer.value("Returns the base 10 log of n"); - writer.key("params"); writer.value("number n"); - writer.key("returns"); writer.value("number"); - writer.endObject(); + @Override + public String getParams() { + return "number n"; + } + + @Override + public String getReturns() { + return "number"; } } diff --git a/main/src/com/google/refine/expr/functions/math/Max.java b/main/src/com/google/refine/expr/functions/math/Max.java index a59d86cb8..8fa28325a 100644 --- a/main/src/com/google/refine/expr/functions/math/Max.java +++ b/main/src/com/google/refine/expr/functions/math/Max.java @@ -35,9 +35,6 @@ package com.google.refine.expr.functions.math; import java.util.Properties; -import org.json.JSONException; -import org.json.JSONWriter; - import com.google.refine.expr.EvalError; import com.google.refine.grel.ControlFunctionRegistry; import com.google.refine.grel.Function; @@ -57,13 +54,17 @@ public class Max implements Function { } @Override - public void write(JSONWriter writer, Properties options) - throws JSONException { + public String getDescription() { + return "Returns the greater of two numbers"; + } - writer.object(); - writer.key("description"); writer.value("Returns the greater of two numbers"); - writer.key("params"); writer.value("number a, number b"); - writer.key("returns"); writer.value("number"); - writer.endObject(); + @Override + public String getParams() { + return "number a, number b"; + } + + @Override + public String getReturns() { + return "number"; } } diff --git a/main/src/com/google/refine/expr/functions/math/Min.java b/main/src/com/google/refine/expr/functions/math/Min.java index 7b7b146c2..fad87784f 100644 --- a/main/src/com/google/refine/expr/functions/math/Min.java +++ b/main/src/com/google/refine/expr/functions/math/Min.java @@ -35,9 +35,6 @@ package com.google.refine.expr.functions.math; import java.util.Properties; -import org.json.JSONException; -import org.json.JSONWriter; - import com.google.refine.expr.EvalError; import com.google.refine.grel.ControlFunctionRegistry; import com.google.refine.grel.Function; @@ -57,13 +54,17 @@ public class Min implements Function { } @Override - public void write(JSONWriter writer, Properties options) - throws JSONException { + public String getDescription() { + return "Returns the smaller of two numbers"; + } - writer.object(); - writer.key("description"); writer.value("Returns the smaller of two numbers"); - writer.key("params"); writer.value("number a, number b"); - writer.key("returns"); writer.value("number"); - writer.endObject(); + @Override + public String getParams() { + return "number a, number b"; + } + + @Override + public String getReturns() { + return "number"; } } diff --git a/main/src/com/google/refine/expr/functions/math/Mod.java b/main/src/com/google/refine/expr/functions/math/Mod.java index d48f93ced..2851f0d1d 100644 --- a/main/src/com/google/refine/expr/functions/math/Mod.java +++ b/main/src/com/google/refine/expr/functions/math/Mod.java @@ -35,9 +35,6 @@ package com.google.refine.expr.functions.math; import java.util.Properties; -import org.json.JSONException; -import org.json.JSONWriter; - import com.google.refine.expr.EvalError; import com.google.refine.grel.ControlFunctionRegistry; import com.google.refine.grel.Function; @@ -58,13 +55,17 @@ public class Mod implements Function { } @Override - public void write(JSONWriter writer, Properties options) - throws JSONException { + public String getDescription() { + return "Returns a modulus b"; + } - writer.object(); - writer.key("description"); writer.value("Returns a modulus b"); - writer.key("params"); writer.value("number a, number b"); - writer.key("returns"); writer.value("number"); - writer.endObject(); + @Override + public String getParams() { + return "number a, number b"; + } + + @Override + public String getReturns() { + return "number"; } } diff --git a/main/src/com/google/refine/expr/functions/math/Multinomial.java b/main/src/com/google/refine/expr/functions/math/Multinomial.java index bf20eaa1a..64fdfe437 100644 --- a/main/src/com/google/refine/expr/functions/math/Multinomial.java +++ b/main/src/com/google/refine/expr/functions/math/Multinomial.java @@ -35,9 +35,6 @@ package com.google.refine.expr.functions.math; import java.util.Properties; -import org.json.JSONException; -import org.json.JSONWriter; - import com.google.refine.expr.EvalError; import com.google.refine.grel.ControlFunctionRegistry; import com.google.refine.grel.Function; @@ -63,13 +60,17 @@ public class Multinomial implements Function { } @Override - public void write(JSONWriter writer, Properties options) - throws JSONException { - - writer.object(); - writer.key("description"); writer.value("Calculates the multinomial of a series of numbers"); - writer.key("params"); writer.value("one or more numbers"); - writer.key("returns"); writer.value("number"); - writer.endObject(); + public String getDescription() { + return "Calculates the multinomial of a series of numbers"; + } + + @Override + public String getParams() { + return "one or more numbers"; + } + + @Override + public String getReturns() { + return "number"; } } diff --git a/main/src/com/google/refine/expr/functions/math/Odd.java b/main/src/com/google/refine/expr/functions/math/Odd.java index e43788417..1c5b6198e 100644 --- a/main/src/com/google/refine/expr/functions/math/Odd.java +++ b/main/src/com/google/refine/expr/functions/math/Odd.java @@ -35,9 +35,6 @@ package com.google.refine.expr.functions.math; import java.util.Properties; -import org.json.JSONException; -import org.json.JSONWriter; - import com.google.refine.expr.EvalError; import com.google.refine.grel.ControlFunctionRegistry; import com.google.refine.grel.Function; @@ -58,13 +55,17 @@ public class Odd implements Function { } @Override - public void write(JSONWriter writer, Properties options) - throws JSONException { - - writer.object(); - writer.key("description"); writer.value("Rounds the number up to the nearest even integer"); - writer.key("params"); writer.value("number d"); - writer.key("returns"); writer.value("number"); - writer.endObject(); + public String getDescription() { + return "Rounds the number up to the nearest even integer"; + } + + @Override + public String getParams() { + return "number d"; + } + + @Override + public String getReturns() { + return "number"; } } \ No newline at end of file diff --git a/main/src/com/google/refine/expr/functions/math/Pow.java b/main/src/com/google/refine/expr/functions/math/Pow.java index 32e76c860..dcfa71bdf 100644 --- a/main/src/com/google/refine/expr/functions/math/Pow.java +++ b/main/src/com/google/refine/expr/functions/math/Pow.java @@ -35,9 +35,6 @@ package com.google.refine.expr.functions.math; import java.util.Properties; -import org.json.JSONException; -import org.json.JSONWriter; - import com.google.refine.grel.Function; public class Pow implements Function { @@ -54,13 +51,17 @@ public class Pow implements Function { } @Override - public void write(JSONWriter writer, Properties options) - throws JSONException { + public String getDescription() { + return "Returns a^b"; + } - writer.object(); - writer.key("description"); writer.value("Returns a^b"); - writer.key("params"); writer.value("number a, number b"); - writer.key("returns"); writer.value("number"); - writer.endObject(); + @Override + public String getParams() { + return "number a, number b"; + } + + @Override + public String getReturns() { + return "number"; } } diff --git a/main/src/com/google/refine/expr/functions/math/Quotient.java b/main/src/com/google/refine/expr/functions/math/Quotient.java index c484cfb59..93f6718a4 100644 --- a/main/src/com/google/refine/expr/functions/math/Quotient.java +++ b/main/src/com/google/refine/expr/functions/math/Quotient.java @@ -35,9 +35,6 @@ package com.google.refine.expr.functions.math; import java.util.Properties; -import org.json.JSONException; -import org.json.JSONWriter; - import com.google.refine.expr.EvalError; import com.google.refine.grel.ControlFunctionRegistry; import com.google.refine.grel.Function; @@ -54,13 +51,17 @@ public class Quotient implements Function { } @Override - public void write(JSONWriter writer, Properties options) - throws JSONException { - - writer.object(); - writer.key("description"); writer.value("Returns the integer portion of a division"); - writer.key("params"); writer.value("number numerator, number denominator"); - writer.key("returns"); writer.value("number"); - writer.endObject(); + public String getDescription() { + return "Returns the integer portion of a division"; + } + + @Override + public String getParams() { + return "number numerator, number denominator"; + } + + @Override + public String getReturns() { + return "number"; } } diff --git a/main/src/com/google/refine/expr/functions/math/Radians.java b/main/src/com/google/refine/expr/functions/math/Radians.java index c74e0834f..9f1115a15 100644 --- a/main/src/com/google/refine/expr/functions/math/Radians.java +++ b/main/src/com/google/refine/expr/functions/math/Radians.java @@ -35,9 +35,6 @@ package com.google.refine.expr.functions.math; import java.util.Properties; -import org.json.JSONException; -import org.json.JSONWriter; - import com.google.refine.expr.EvalError; import com.google.refine.grel.ControlFunctionRegistry; import com.google.refine.grel.Function; @@ -53,13 +50,17 @@ public class Radians implements Function { } @Override - public void write(JSONWriter writer, Properties options) - throws JSONException { - - writer.object(); - writer.key("description"); writer.value("Converts an angle in degrees to radians"); - writer.key("params"); writer.value("number d"); - writer.key("returns"); writer.value("number"); - writer.endObject(); + public String getDescription() { + return "Converts an angle in degrees to radians"; + } + + @Override + public String getParams() { + return "number d"; + } + + @Override + public String getReturns() { + return "number"; } } \ No newline at end of file diff --git a/main/src/com/google/refine/expr/functions/math/Round.java b/main/src/com/google/refine/expr/functions/math/Round.java index f88cdadbc..4537c3067 100644 --- a/main/src/com/google/refine/expr/functions/math/Round.java +++ b/main/src/com/google/refine/expr/functions/math/Round.java @@ -35,9 +35,6 @@ package com.google.refine.expr.functions.math; import java.util.Properties; -import org.json.JSONException; -import org.json.JSONWriter; - import com.google.refine.expr.EvalError; import com.google.refine.grel.ControlFunctionRegistry; import com.google.refine.grel.Function; @@ -53,13 +50,17 @@ public class Round implements Function { } @Override - public void write(JSONWriter writer, Properties options) - throws JSONException { + public String getDescription() { + return "Returns n rounded"; + } - writer.object(); - writer.key("description"); writer.value("Returns n rounded"); - writer.key("params"); writer.value("number n"); - writer.key("returns"); writer.value("number"); - writer.endObject(); + @Override + public String getParams() { + return "number n"; + } + + @Override + public String getReturns() { + return "number"; } } diff --git a/main/src/com/google/refine/expr/functions/math/Sin.java b/main/src/com/google/refine/expr/functions/math/Sin.java index b862402ae..599eccb65 100644 --- a/main/src/com/google/refine/expr/functions/math/Sin.java +++ b/main/src/com/google/refine/expr/functions/math/Sin.java @@ -35,9 +35,6 @@ package com.google.refine.expr.functions.math; import java.util.Properties; -import org.json.JSONException; -import org.json.JSONWriter; - import com.google.refine.expr.EvalError; import com.google.refine.grel.ControlFunctionRegistry; import com.google.refine.grel.Function; @@ -53,13 +50,17 @@ public class Sin implements Function { } @Override - public void write(JSONWriter writer, Properties options) - throws JSONException { - - writer.object(); - writer.key("description"); writer.value("Returns the trigonometric sine of an angle"); - writer.key("params"); writer.value("number d"); - writer.key("returns"); writer.value("number"); - writer.endObject(); + public String getDescription() { + return "Returns the trigonometric sine of an angle"; + } + + @Override + public String getParams() { + return "number d"; + } + + @Override + public String getReturns() { + return "number"; } } \ No newline at end of file diff --git a/main/src/com/google/refine/expr/functions/math/Sinh.java b/main/src/com/google/refine/expr/functions/math/Sinh.java index 9f26a42d9..94d0e2d5e 100644 --- a/main/src/com/google/refine/expr/functions/math/Sinh.java +++ b/main/src/com/google/refine/expr/functions/math/Sinh.java @@ -35,9 +35,6 @@ package com.google.refine.expr.functions.math; import java.util.Properties; -import org.json.JSONException; -import org.json.JSONWriter; - import com.google.refine.expr.EvalError; import com.google.refine.grel.ControlFunctionRegistry; import com.google.refine.grel.Function; @@ -53,13 +50,17 @@ public class Sinh implements Function { } @Override - public void write(JSONWriter writer, Properties options) - throws JSONException { - - writer.object(); - writer.key("description"); writer.value("Returns the hyperbolic sine of an angle"); - writer.key("params"); writer.value("number d"); - writer.key("returns"); writer.value("number"); - writer.endObject(); + public String getDescription() { + return "Returns the hyperbolic sine of an angle"; + } + + @Override + public String getParams() { + return "number d"; + } + + @Override + public String getReturns() { + return "number"; } } \ No newline at end of file diff --git a/main/src/com/google/refine/expr/functions/math/Sum.java b/main/src/com/google/refine/expr/functions/math/Sum.java index aee0878e2..03da9acc5 100644 --- a/main/src/com/google/refine/expr/functions/math/Sum.java +++ b/main/src/com/google/refine/expr/functions/math/Sum.java @@ -36,9 +36,6 @@ package com.google.refine.expr.functions.math; import java.util.List; import java.util.Properties; -import org.json.JSONException; -import org.json.JSONWriter; - import com.google.refine.expr.EvalError; import com.google.refine.expr.ExpressionUtils; import com.google.refine.grel.ControlFunctionRegistry; @@ -82,13 +79,17 @@ public class Sum implements Function { } @Override - public void write(JSONWriter writer, Properties options) - throws JSONException { + public String getDescription() { + return "Sums numbers in array a"; + } - writer.object(); - writer.key("description"); writer.value("Sums numbers in array a"); - writer.key("params"); writer.value("array a"); - writer.key("returns"); writer.value("number"); - writer.endObject(); + @Override + public String getParams() { + return "array a"; + } + + @Override + public String getReturns() { + return "number"; } } diff --git a/main/src/com/google/refine/expr/functions/math/Tan.java b/main/src/com/google/refine/expr/functions/math/Tan.java index 8eb7f9018..b510c75bb 100644 --- a/main/src/com/google/refine/expr/functions/math/Tan.java +++ b/main/src/com/google/refine/expr/functions/math/Tan.java @@ -35,9 +35,6 @@ package com.google.refine.expr.functions.math; import java.util.Properties; -import org.json.JSONException; -import org.json.JSONWriter; - import com.google.refine.expr.EvalError; import com.google.refine.grel.ControlFunctionRegistry; import com.google.refine.grel.Function; @@ -53,13 +50,17 @@ public class Tan implements Function { } @Override - public void write(JSONWriter writer, Properties options) - throws JSONException { - - writer.object(); - writer.key("description"); writer.value("Returns the trigonometric tangent of an angle"); - writer.key("params"); writer.value("number d"); - writer.key("returns"); writer.value("number"); - writer.endObject(); + public String getDescription() { + return "Returns the trigonometric tangent of an angle"; + } + + @Override + public String getParams() { + return "number d"; + } + + @Override + public String getReturns() { + return "number"; } } \ No newline at end of file diff --git a/main/src/com/google/refine/expr/functions/math/Tanh.java b/main/src/com/google/refine/expr/functions/math/Tanh.java index 0d9d5c6c9..49be8c5ad 100644 --- a/main/src/com/google/refine/expr/functions/math/Tanh.java +++ b/main/src/com/google/refine/expr/functions/math/Tanh.java @@ -35,9 +35,6 @@ package com.google.refine.expr.functions.math; import java.util.Properties; -import org.json.JSONException; -import org.json.JSONWriter; - import com.google.refine.expr.EvalError; import com.google.refine.grel.ControlFunctionRegistry; import com.google.refine.grel.Function; @@ -53,13 +50,17 @@ public class Tanh implements Function { } @Override - public void write(JSONWriter writer, Properties options) - throws JSONException { - - writer.object(); - writer.key("description"); writer.value("Returns the hyperbolic tangent of a value"); - writer.key("params"); writer.value("number d"); - writer.key("returns"); writer.value("number"); - writer.endObject(); + public String getDescription() { + return "Returns the hyperbolic tangent of a value"; + } + + @Override + public String getParams() { + return "number d"; + } + + @Override + public String getReturns() { + return "number"; } } \ No newline at end of file diff --git a/main/src/com/google/refine/expr/functions/strings/Chomp.java b/main/src/com/google/refine/expr/functions/strings/Chomp.java index 8ee9b5ae2..5a0de0ae1 100644 --- a/main/src/com/google/refine/expr/functions/strings/Chomp.java +++ b/main/src/com/google/refine/expr/functions/strings/Chomp.java @@ -36,8 +36,6 @@ package com.google.refine.expr.functions.strings; import java.util.Properties; import org.apache.commons.lang3.StringUtils; -import org.json.JSONException; -import org.json.JSONWriter; import com.google.refine.grel.Function; @@ -56,13 +54,17 @@ public class Chomp implements Function { } @Override - public void write(JSONWriter writer, Properties options) - throws JSONException { + public String getDescription() { + return "Removes separator from the end of str if it's there, otherwise leave it alone."; + } - writer.object(); - writer.key("description"); writer.value("Removes separator from the end of str if it's there, otherwise leave it alone."); - writer.key("params"); writer.value("string str, string separator"); - writer.key("returns"); writer.value("string"); - writer.endObject(); + @Override + public String getParams() { + return "string str, string separator"; + } + + @Override + public String getReturns() { + return "string"; } } diff --git a/main/src/com/google/refine/expr/functions/strings/Contains.java b/main/src/com/google/refine/expr/functions/strings/Contains.java index 99737b8de..2e7eb41bc 100644 --- a/main/src/com/google/refine/expr/functions/strings/Contains.java +++ b/main/src/com/google/refine/expr/functions/strings/Contains.java @@ -37,9 +37,6 @@ import java.util.Properties; import java.util.regex.Matcher; import java.util.regex.Pattern; -import org.json.JSONException; -import org.json.JSONWriter; - import com.google.refine.grel.Function; public class Contains implements Function { @@ -64,13 +61,17 @@ public class Contains implements Function { return null; } @Override - public void write(JSONWriter writer, Properties options) - throws JSONException { + public String getDescription() { + return "Returns whether s contains frag"; + } - writer.object(); - writer.key("description"); writer.value("Returns whether s contains frag"); - writer.key("params"); writer.value("string s, string frag"); - writer.key("returns"); writer.value("boolean"); - writer.endObject(); + @Override + public String getParams() { + return "string s, string frag"; + } + + @Override + public String getReturns() { + return "boolean"; } } diff --git a/main/src/com/google/refine/expr/functions/strings/Diff.java b/main/src/com/google/refine/expr/functions/strings/Diff.java index 155b0bfea..d6196e39e 100644 --- a/main/src/com/google/refine/expr/functions/strings/Diff.java +++ b/main/src/com/google/refine/expr/functions/strings/Diff.java @@ -37,8 +37,6 @@ import java.time.OffsetDateTime; import java.util.Properties; import org.apache.commons.lang3.StringUtils; -import org.json.JSONException; -import org.json.JSONWriter; import com.google.refine.expr.EvalError; import com.google.refine.grel.Function; @@ -104,12 +102,18 @@ public class Diff implements Function { } @Override - public void write(JSONWriter writer, Properties options) throws JSONException { - writer.object(); - writer.key("description"); writer.value("For strings, returns the portion where they differ. For dates, it returns the difference in given time units"); - writer.key("params"); writer.value("o1, o2, time unit (optional)"); - writer.key("returns"); writer.value("string for strings, number for dates"); - writer.endObject(); + public String getDescription() { + return "For strings, returns the portion where they differ. For dates, it returns the difference in given time units"; + } + + @Override + public String getParams() { + return "o1, o2, time unit (optional)"; + } + + @Override + public String getReturns() { + return "string for strings, number for dates"; } private long getNano(OffsetDateTime odt) { diff --git a/main/src/com/google/refine/expr/functions/strings/EndsWith.java b/main/src/com/google/refine/expr/functions/strings/EndsWith.java index e9d97e391..91d51ea44 100644 --- a/main/src/com/google/refine/expr/functions/strings/EndsWith.java +++ b/main/src/com/google/refine/expr/functions/strings/EndsWith.java @@ -35,9 +35,6 @@ package com.google.refine.expr.functions.strings; import java.util.Properties; -import org.json.JSONException; -import org.json.JSONWriter; - import com.google.refine.expr.EvalError; import com.google.refine.grel.ControlFunctionRegistry; import com.google.refine.grel.Function; @@ -57,13 +54,17 @@ public class EndsWith implements Function { } @Override - public void write(JSONWriter writer, Properties options) - throws JSONException { + public String getDescription() { + return "Returns whether s ends with sub"; + } - writer.object(); - writer.key("description"); writer.value("Returns whether s ends with sub"); - writer.key("params"); writer.value("string s, string sub"); - writer.key("returns"); writer.value("boolean"); - writer.endObject(); + @Override + public String getParams() { + return "string s, string sub"; + } + + @Override + public String getReturns() { + return "boolean"; } } diff --git a/main/src/com/google/refine/expr/functions/strings/Escape.java b/main/src/com/google/refine/expr/functions/strings/Escape.java index b25f532de..9f0e5d0e9 100644 --- a/main/src/com/google/refine/expr/functions/strings/Escape.java +++ b/main/src/com/google/refine/expr/functions/strings/Escape.java @@ -38,8 +38,6 @@ import java.net.URLEncoder; import java.util.Properties; import org.apache.commons.lang3.StringEscapeUtils; -import org.json.JSONException; -import org.json.JSONWriter; import com.google.refine.expr.EvalError; import com.google.refine.grel.ControlFunctionRegistry; @@ -85,13 +83,17 @@ public class Escape implements Function { } @Override - public void write(JSONWriter writer, Properties options) - throws JSONException { + public String getDescription() { + return "Escapes a string depending on the given escaping mode."; + } - writer.object(); - writer.key("description"); writer.value("Escapes a string depending on the given escaping mode."); - writer.key("params"); writer.value("string s, string mode ['html','xml','csv','url','javascript']"); - writer.key("returns"); writer.value("string"); - writer.endObject(); + @Override + public String getParams() { + return "string s, string mode ['html','xml','csv','url','javascript']"; + } + + @Override + public String getReturns() { + return "string"; } } diff --git a/main/src/com/google/refine/expr/functions/strings/Find.java b/main/src/com/google/refine/expr/functions/strings/Find.java index dfec5d990..1220182e9 100644 --- a/main/src/com/google/refine/expr/functions/strings/Find.java +++ b/main/src/com/google/refine/expr/functions/strings/Find.java @@ -7,9 +7,6 @@ import java.util.Properties; import java.util.regex.Matcher; import java.util.regex.Pattern; -import org.json.JSONException; -import org.json.JSONWriter; - import com.google.refine.expr.EvalError; import com.google.refine.grel.ControlFunctionRegistry; import com.google.refine.grel.Function; @@ -41,13 +38,17 @@ public class Find implements Function { } @Override - public void write(JSONWriter writer, Properties options) - throws JSONException { + public String getDescription() { + return "Returns all the occurances of match given regular expression"; + } - writer.object(); - writer.key("description"); writer.value("Returns all the occurances of match given regular expression"); - writer.key("params"); writer.value("string or regexp"); - writer.key("returns"); writer.value("array of strings"); - writer.endObject(); + @Override + public String getParams() { + return "string or regexp"; + } + + @Override + public String getReturns() { + return "array of strings"; } } diff --git a/main/src/com/google/refine/expr/functions/strings/Fingerprint.java b/main/src/com/google/refine/expr/functions/strings/Fingerprint.java index 2ec124915..46cff1b42 100644 --- a/main/src/com/google/refine/expr/functions/strings/Fingerprint.java +++ b/main/src/com/google/refine/expr/functions/strings/Fingerprint.java @@ -35,9 +35,6 @@ package com.google.refine.expr.functions.strings; import java.util.Properties; -import org.json.JSONException; -import org.json.JSONWriter; - import com.google.refine.clustering.binning.FingerprintKeyer; import com.google.refine.clustering.binning.Keyer; import com.google.refine.grel.Function; @@ -57,13 +54,17 @@ public class Fingerprint implements Function { } @Override - public void write(JSONWriter writer, Properties options) - throws JSONException { + public String getDescription() { + return "Returns the fingerprint of s, a derived string that aims to be a more canonical form of it (this is mostly useful for finding clusters of strings related to the same information)."; + } - writer.object(); - writer.key("description"); writer.value("Returns the fingerprint of s, a derived string that aims to be a more canonical form of it (this is mostly useful for finding clusters of strings related to the same information)."); - writer.key("params"); writer.value("string s"); - writer.key("returns"); writer.value("string"); - writer.endObject(); + @Override + public String getParams() { + return "string s"; + } + + @Override + public String getReturns() { + return "string"; } } diff --git a/main/src/com/google/refine/expr/functions/strings/IndexOf.java b/main/src/com/google/refine/expr/functions/strings/IndexOf.java index a4e0a415c..9edf5d8ca 100644 --- a/main/src/com/google/refine/expr/functions/strings/IndexOf.java +++ b/main/src/com/google/refine/expr/functions/strings/IndexOf.java @@ -35,9 +35,6 @@ package com.google.refine.expr.functions.strings; import java.util.Properties; -import org.json.JSONException; -import org.json.JSONWriter; - import com.google.refine.expr.EvalError; import com.google.refine.grel.ControlFunctionRegistry; import com.google.refine.grel.Function; @@ -57,13 +54,17 @@ public class IndexOf implements Function { } @Override - public void write(JSONWriter writer, Properties options) - throws JSONException { + public String getDescription() { + return "Returns the index of sub first ocurring in s"; + } - writer.object(); - writer.key("description"); writer.value("Returns the index of sub first ocurring in s"); - writer.key("params"); writer.value("string s, string sub"); - writer.key("returns"); writer.value("number"); - writer.endObject(); + @Override + public String getParams() { + return "string s, string sub"; + } + + @Override + public String getReturns() { + return "number"; } } diff --git a/main/src/com/google/refine/expr/functions/strings/LastIndexOf.java b/main/src/com/google/refine/expr/functions/strings/LastIndexOf.java index c80dac41b..bab4bf68e 100644 --- a/main/src/com/google/refine/expr/functions/strings/LastIndexOf.java +++ b/main/src/com/google/refine/expr/functions/strings/LastIndexOf.java @@ -35,9 +35,6 @@ package com.google.refine.expr.functions.strings; import java.util.Properties; -import org.json.JSONException; -import org.json.JSONWriter; - import com.google.refine.expr.EvalError; import com.google.refine.grel.ControlFunctionRegistry; import com.google.refine.grel.Function; @@ -57,14 +54,18 @@ public class LastIndexOf implements Function { } @Override - public void write(JSONWriter writer, Properties options) - throws JSONException { + public String getDescription() { + return "Returns the index of sub last ocurring in s"; + } - writer.object(); - writer.key("description"); writer.value("Returns the index of sub last ocurring in s"); - writer.key("params"); writer.value("string s, string sub"); - writer.key("returns"); writer.value("number"); - writer.endObject(); + @Override + public String getParams() { + return "string s, string sub"; + } + + @Override + public String getReturns() { + return "number"; } } diff --git a/main/src/com/google/refine/expr/functions/strings/MD5.java b/main/src/com/google/refine/expr/functions/strings/MD5.java index 84213e877..ec2d83136 100644 --- a/main/src/com/google/refine/expr/functions/strings/MD5.java +++ b/main/src/com/google/refine/expr/functions/strings/MD5.java @@ -36,8 +36,6 @@ package com.google.refine.expr.functions.strings; import java.util.Properties; import org.apache.commons.codec.digest.DigestUtils; -import org.json.JSONException; -import org.json.JSONWriter; import com.google.refine.expr.EvalError; import com.google.refine.grel.ControlFunctionRegistry; @@ -56,13 +54,17 @@ public class MD5 implements Function { } @Override - public void write(JSONWriter writer, Properties options) - throws JSONException { + public String getDescription() { + return "Returns the MD5 hash of s"; + } - writer.object(); - writer.key("description"); writer.value("Returns the MD5 hash of s"); - writer.key("params"); writer.value("string s"); - writer.key("returns"); writer.value("string"); - writer.endObject(); + @Override + public String getParams() { + return "string s"; + } + + @Override + public String getReturns() { + return "string"; } } diff --git a/main/src/com/google/refine/expr/functions/strings/Match.java b/main/src/com/google/refine/expr/functions/strings/Match.java index d8f5e0816..141948abf 100644 --- a/main/src/com/google/refine/expr/functions/strings/Match.java +++ b/main/src/com/google/refine/expr/functions/strings/Match.java @@ -37,9 +37,6 @@ import java.util.Properties; import java.util.regex.Matcher; import java.util.regex.Pattern; -import org.json.JSONException; -import org.json.JSONWriter; - import com.google.refine.expr.EvalError; import com.google.refine.grel.ControlFunctionRegistry; import com.google.refine.grel.Function; @@ -78,13 +75,17 @@ public class Match implements Function { } @Override - public void write(JSONWriter writer, Properties options) - throws JSONException { + public String getDescription() { + return "Returns an array of the groups matching the given regular expression"; + } - writer.object(); - writer.key("description"); writer.value("Returns an array of the groups matching the given regular expression"); - writer.key("params"); writer.value("string or regexp"); - writer.key("returns"); writer.value("array of strings"); - writer.endObject(); + @Override + public String getParams() { + return "string or regexp"; + } + + @Override + public String getReturns() { + return "array of strings"; } } diff --git a/main/src/com/google/refine/expr/functions/strings/NGram.java b/main/src/com/google/refine/expr/functions/strings/NGram.java index 4c715a938..e27c9f4c5 100644 --- a/main/src/com/google/refine/expr/functions/strings/NGram.java +++ b/main/src/com/google/refine/expr/functions/strings/NGram.java @@ -36,8 +36,6 @@ package com.google.refine.expr.functions.strings; import java.util.Properties; import org.apache.commons.lang3.StringUtils; -import org.json.JSONException; -import org.json.JSONWriter; import com.google.refine.expr.EvalError; import com.google.refine.grel.ControlFunctionRegistry; @@ -79,13 +77,17 @@ public class NGram implements Function { } @Override - public void write(JSONWriter writer, Properties options) - throws JSONException { + public String getDescription() { + return "Returns an array of the word ngrams of s"; + } - writer.object(); - writer.key("description"); writer.value("Returns an array of the word ngrams of s"); - writer.key("params"); writer.value("string s, number n"); - writer.key("returns"); writer.value("array of strings"); - writer.endObject(); + @Override + public String getParams() { + return "string s, number n"; + } + + @Override + public String getReturns() { + return "array of strings"; } } diff --git a/main/src/com/google/refine/expr/functions/strings/NGramFingerprint.java b/main/src/com/google/refine/expr/functions/strings/NGramFingerprint.java index d6d1c4da0..c35c03ce9 100644 --- a/main/src/com/google/refine/expr/functions/strings/NGramFingerprint.java +++ b/main/src/com/google/refine/expr/functions/strings/NGramFingerprint.java @@ -36,9 +36,6 @@ package com.google.refine.expr.functions.strings; import java.util.Properties; import java.util.TreeSet; -import org.json.JSONException; -import org.json.JSONWriter; - import com.google.refine.clustering.binning.Keyer; import com.google.refine.clustering.binning.NGramFingerprintKeyer; import com.google.refine.expr.EvalError; @@ -76,13 +73,17 @@ public class NGramFingerprint implements Function { } @Override - public void write(JSONWriter writer, Properties options) - throws JSONException { + public String getDescription() { + return "Returns the n-gram fingerprint of s"; + } - writer.object(); - writer.key("description"); writer.value("Returns the n-gram fingerprint of s"); - writer.key("params"); writer.value("string s, number n"); - writer.key("returns"); writer.value("string"); - writer.endObject(); + @Override + public String getParams() { + return "string s, number n"; + } + + @Override + public String getReturns() { + return "string"; } } diff --git a/main/src/com/google/refine/expr/functions/strings/ParseJson.java b/main/src/com/google/refine/expr/functions/strings/ParseJson.java index 20d1f46ab..3e2725282 100644 --- a/main/src/com/google/refine/expr/functions/strings/ParseJson.java +++ b/main/src/com/google/refine/expr/functions/strings/ParseJson.java @@ -37,7 +37,6 @@ import java.util.Properties; import org.json.JSONException; import org.json.JSONTokener; -import org.json.JSONWriter; import com.google.refine.expr.EvalError; import com.google.refine.grel.ControlFunctionRegistry; @@ -62,13 +61,17 @@ public class ParseJson implements Function { @Override - public void write(JSONWriter writer, Properties options) - throws JSONException { + public String getDescription() { + return "Parses a string as JSON"; + } - writer.object(); - writer.key("description"); writer.value("Parses a string as JSON"); - writer.key("params"); writer.value("string s"); - writer.key("returns"); writer.value("JSON object"); - writer.endObject(); + @Override + public String getParams() { + return "string s"; + } + + @Override + public String getReturns() { + return "JSON object"; } } diff --git a/main/src/com/google/refine/expr/functions/strings/Partition.java b/main/src/com/google/refine/expr/functions/strings/Partition.java index 7163a5767..ee7acabb9 100644 --- a/main/src/com/google/refine/expr/functions/strings/Partition.java +++ b/main/src/com/google/refine/expr/functions/strings/Partition.java @@ -37,9 +37,6 @@ import java.util.Properties; import java.util.regex.Matcher; import java.util.regex.Pattern; -import org.json.JSONException; -import org.json.JSONWriter; - import com.google.refine.grel.Function; public class Partition implements Function { @@ -101,14 +98,18 @@ public class Partition implements Function { } @Override - public void write(JSONWriter writer, Properties options) - throws JSONException { + public String getDescription() { + return + "Returns an array of strings [a,frag,b] where a is the string part before the first occurrence of frag in s and b is what's left. If omitFragment is true, frag is not returned."; + } - writer.object(); - writer.key("description"); writer.value( - "Returns an array of strings [a,frag,b] where a is the string part before the first occurrence of frag in s and b is what's left. If omitFragment is true, frag is not returned."); - writer.key("params"); writer.value("string s, string or regex frag, optional boolean omitFragment"); - writer.key("returns"); writer.value("array"); - writer.endObject(); + @Override + public String getParams() { + return "string s, string or regex frag, optional boolean omitFragment"; + } + + @Override + public String getReturns() { + return "array"; } } diff --git a/main/src/com/google/refine/expr/functions/strings/Phonetic.java b/main/src/com/google/refine/expr/functions/strings/Phonetic.java index 004e647f5..7c2758fe1 100644 --- a/main/src/com/google/refine/expr/functions/strings/Phonetic.java +++ b/main/src/com/google/refine/expr/functions/strings/Phonetic.java @@ -35,9 +35,6 @@ package com.google.refine.expr.functions.strings; import java.util.Properties; -import org.json.JSONException; -import org.json.JSONWriter; - import com.google.refine.clustering.binning.ColognePhoneticKeyer; import com.google.refine.clustering.binning.DoubleMetaphoneKeyer; import com.google.refine.clustering.binning.Metaphone3Keyer; @@ -100,13 +97,17 @@ public class Phonetic implements Function { } @Override - public void write(JSONWriter writer, Properties options) - throws JSONException { + public String getDescription() { + return "Returns the a phonetic encoding of s (optionally indicating which encoding to use')"; + } - writer.object(); - writer.key("description"); writer.value("Returns the a phonetic encoding of s (optionally indicating which encoding to use')"); - writer.key("params"); writer.value("string s, string encoding (optional, defaults to 'metaphone3')"); - writer.key("returns"); writer.value("string"); - writer.endObject(); + @Override + public String getParams() { + return "string s, string encoding (optional, defaults to 'metaphone3')"; + } + + @Override + public String getReturns() { + return "string"; } } diff --git a/main/src/com/google/refine/expr/functions/strings/RPartition.java b/main/src/com/google/refine/expr/functions/strings/RPartition.java index 3be977f92..caf155b84 100644 --- a/main/src/com/google/refine/expr/functions/strings/RPartition.java +++ b/main/src/com/google/refine/expr/functions/strings/RPartition.java @@ -37,9 +37,6 @@ import java.util.Properties; import java.util.regex.Matcher; import java.util.regex.Pattern; -import org.json.JSONException; -import org.json.JSONWriter; - import com.google.refine.grel.Function; public class RPartition implements Function { @@ -102,14 +99,18 @@ public class RPartition implements Function { } @Override - public void write(JSONWriter writer, Properties options) - throws JSONException { + public String getDescription() { + return + "Returns an array of strings [a,frag,b] where a is the string part before the last occurrence of frag in s and b is what's left. If omitFragment is true, frag is not returned."; + } - writer.object(); - writer.key("description"); writer.value( - "Returns an array of strings [a,frag,b] where a is the string part before the last occurrence of frag in s and b is what's left. If omitFragment is true, frag is not returned."); - writer.key("params"); writer.value("string s, string or regex frag, optional boolean omitFragment"); - writer.key("returns"); writer.value("array"); - writer.endObject(); + @Override + public String getParams() { + return "string s, string or regex frag, optional boolean omitFragment"; + } + + @Override + public String getReturns() { + return "array"; } } diff --git a/main/src/com/google/refine/expr/functions/strings/Range.java b/main/src/com/google/refine/expr/functions/strings/Range.java index c26d45e5a..815ef639f 100644 --- a/main/src/com/google/refine/expr/functions/strings/Range.java +++ b/main/src/com/google/refine/expr/functions/strings/Range.java @@ -1,11 +1,8 @@ package com.google.refine.expr.functions.strings; +import java.util.Properties; import java.util.regex.Matcher; import java.util.regex.Pattern; -import java.util.Properties; - -import org.json.JSONException; -import org.json.JSONWriter; import com.google.refine.expr.EvalError; import com.google.refine.grel.ControlFunctionRegistry; @@ -295,14 +292,18 @@ public class Range implements Function { } @Override - public void write(JSONWriter writer, Properties options) - throws JSONException { - - writer.object(); - writer.key("description"); writer.value( - "Returns an array where a and b are the start and the end of the range respectively and c is the step (increment)."); - writer.key("params"); writer.value("A single string 'a', 'a, b' or 'a, b, c' or one, two or three integers a or a, b or a, b, c"); - writer.key("returns"); writer.value("array"); - writer.endObject(); + public String getDescription() { + return + "Returns an array where a and b are the start and the end of the range respectively and c is the step (increment)."; + } + + @Override + public String getParams() { + return "A single string 'a', 'a, b' or 'a, b, c' or one, two or three integers a or a, b or a, b, c"; + } + + @Override + public String getReturns() { + return "array"; } } diff --git a/main/src/com/google/refine/expr/functions/strings/Reinterpret.java b/main/src/com/google/refine/expr/functions/strings/Reinterpret.java index d096b90ba..cc7057862 100644 --- a/main/src/com/google/refine/expr/functions/strings/Reinterpret.java +++ b/main/src/com/google/refine/expr/functions/strings/Reinterpret.java @@ -36,9 +36,6 @@ package com.google.refine.expr.functions.strings; import java.io.UnsupportedEncodingException; import java.util.Properties; -import org.json.JSONException; -import org.json.JSONWriter; - import com.google.refine.ProjectManager; import com.google.refine.expr.EvalError; import com.google.refine.grel.ControlFunctionRegistry; @@ -99,13 +96,17 @@ public class Reinterpret implements Function { } @Override - public void write(JSONWriter writer, Properties options) - throws JSONException { + public String getDescription() { + return "Returns s reinterpreted thru the given encoder."; + } - writer.object(); - writer.key("description"); writer.value("Returns s reinterpreted thru the given encoder."); - writer.key("params"); writer.value("string s, string encoder"); - writer.key("returns"); writer.value("string"); - writer.endObject(); + @Override + public String getParams() { + return "string s, string encoder"; + } + + @Override + public String getReturns() { + return "string"; } } diff --git a/main/src/com/google/refine/expr/functions/strings/Replace.java b/main/src/com/google/refine/expr/functions/strings/Replace.java index 71b96fa71..017dc082e 100644 --- a/main/src/com/google/refine/expr/functions/strings/Replace.java +++ b/main/src/com/google/refine/expr/functions/strings/Replace.java @@ -36,9 +36,6 @@ package com.google.refine.expr.functions.strings; import java.util.Properties; import java.util.regex.Pattern; -import org.json.JSONException; -import org.json.JSONWriter; - import com.google.refine.expr.EvalError; import com.google.refine.grel.ControlFunctionRegistry; import com.google.refine.grel.Function; @@ -67,13 +64,17 @@ public class Replace implements Function { @Override - public void write(JSONWriter writer, Properties options) - throws JSONException { + public String getDescription() { + return "Returns the string obtained by replacing f with r in s"; + } - writer.object(); - writer.key("description"); writer.value("Returns the string obtained by replacing f with r in s"); - writer.key("params"); writer.value("string s, string or regex f, string r"); - writer.key("returns"); writer.value("string"); - writer.endObject(); + @Override + public String getParams() { + return "string s, string or regex f, string r"; + } + + @Override + public String getReturns() { + return "string"; } } diff --git a/main/src/com/google/refine/expr/functions/strings/ReplaceChars.java b/main/src/com/google/refine/expr/functions/strings/ReplaceChars.java index 4c32ff606..320df6055 100644 --- a/main/src/com/google/refine/expr/functions/strings/ReplaceChars.java +++ b/main/src/com/google/refine/expr/functions/strings/ReplaceChars.java @@ -36,8 +36,6 @@ package com.google.refine.expr.functions.strings; import java.util.Properties; import org.apache.commons.lang3.StringUtils; -import org.json.JSONException; -import org.json.JSONWriter; import com.google.refine.expr.EvalError; import com.google.refine.grel.ControlFunctionRegistry; @@ -61,13 +59,17 @@ public class ReplaceChars implements Function { @Override - public void write(JSONWriter writer, Properties options) - throws JSONException { + public String getDescription() { + return "Returns the string obtained by replacing all chars in f with the char in s at that same position"; + } - writer.object(); - writer.key("description"); writer.value("Returns the string obtained by replacing all chars in f with the char in s at that same position"); - writer.key("params"); writer.value("string s, string f, string r"); - writer.key("returns"); writer.value("string"); - writer.endObject(); + @Override + public String getParams() { + return "string s, string f, string r"; + } + + @Override + public String getReturns() { + return "string"; } } diff --git a/main/src/com/google/refine/expr/functions/strings/SHA1.java b/main/src/com/google/refine/expr/functions/strings/SHA1.java index 204b5457e..97eee6946 100644 --- a/main/src/com/google/refine/expr/functions/strings/SHA1.java +++ b/main/src/com/google/refine/expr/functions/strings/SHA1.java @@ -36,8 +36,6 @@ package com.google.refine.expr.functions.strings; import java.util.Properties; import org.apache.commons.codec.digest.DigestUtils; -import org.json.JSONException; -import org.json.JSONWriter; import com.google.refine.expr.EvalError; import com.google.refine.grel.ControlFunctionRegistry; @@ -56,13 +54,17 @@ public class SHA1 implements Function { } @Override - public void write(JSONWriter writer, Properties options) - throws JSONException { + public String getDescription() { + return "Returns the SHA-1 hash of s"; + } - writer.object(); - writer.key("description"); writer.value("Returns the SHA-1 hash of s"); - writer.key("params"); writer.value("string s"); - writer.key("returns"); writer.value("string"); - writer.endObject(); + @Override + public String getParams() { + return "string s"; + } + + @Override + public String getReturns() { + return "string"; } } diff --git a/main/src/com/google/refine/expr/functions/strings/SmartSplit.java b/main/src/com/google/refine/expr/functions/strings/SmartSplit.java index 937852e1b..6e01ca95b 100644 --- a/main/src/com/google/refine/expr/functions/strings/SmartSplit.java +++ b/main/src/com/google/refine/expr/functions/strings/SmartSplit.java @@ -36,15 +36,12 @@ package com.google.refine.expr.functions.strings; import java.io.IOException; import java.util.Properties; -import org.json.JSONException; -import org.json.JSONWriter; - -import au.com.bytecode.opencsv.CSVParser; - import com.google.refine.expr.EvalError; import com.google.refine.grel.ControlFunctionRegistry; import com.google.refine.grel.Function; +import au.com.bytecode.opencsv.CSVParser; + public class SmartSplit implements Function { static final protected CSVParser s_tabParser = new CSVParser( @@ -104,13 +101,17 @@ public class SmartSplit implements Function { } @Override - public void write(JSONWriter writer, Properties options) - throws JSONException { + public String getDescription() { + return "Returns the array of strings obtained by splitting s with separator sep. Handles quotes properly. Guesses tab or comma separator if \"sep\" is not given."; + } - writer.object(); - writer.key("description"); writer.value("Returns the array of strings obtained by splitting s with separator sep. Handles quotes properly. Guesses tab or comma separator if \"sep\" is not given."); - writer.key("params"); writer.value("string s, optional string sep"); - writer.key("returns"); writer.value("array"); - writer.endObject(); + @Override + public String getParams() { + return "string s, optional string sep"; + } + + @Override + public String getReturns() { + return "array"; } } diff --git a/main/src/com/google/refine/expr/functions/strings/Split.java b/main/src/com/google/refine/expr/functions/strings/Split.java index 2532c9cfc..3a47fd8d8 100644 --- a/main/src/com/google/refine/expr/functions/strings/Split.java +++ b/main/src/com/google/refine/expr/functions/strings/Split.java @@ -37,8 +37,6 @@ import java.util.Properties; import java.util.regex.Pattern; import org.apache.commons.lang3.StringUtils; -import org.json.JSONException; -import org.json.JSONWriter; import com.google.refine.expr.EvalError; import com.google.refine.grel.ControlFunctionRegistry; @@ -76,13 +74,17 @@ public class Split implements Function { } @Override - public void write(JSONWriter writer, Properties options) - throws JSONException { + public String getDescription() { + return "Returns the array of strings obtained by splitting s with separator sep. If preserveAllTokens is true, then empty segments are preserved."; + } - writer.object(); - writer.key("description"); writer.value("Returns the array of strings obtained by splitting s with separator sep. If preserveAllTokens is true, then empty segments are preserved."); - writer.key("params"); writer.value("string s, string or regex sep, optional boolean preserveAllTokens"); - writer.key("returns"); writer.value("array"); - writer.endObject(); + @Override + public String getParams() { + return "string s, string or regex sep, optional boolean preserveAllTokens"; + } + + @Override + public String getReturns() { + return "array"; } } diff --git a/main/src/com/google/refine/expr/functions/strings/SplitByCharType.java b/main/src/com/google/refine/expr/functions/strings/SplitByCharType.java index 85e316974..4f2980cb8 100644 --- a/main/src/com/google/refine/expr/functions/strings/SplitByCharType.java +++ b/main/src/com/google/refine/expr/functions/strings/SplitByCharType.java @@ -36,8 +36,6 @@ package com.google.refine.expr.functions.strings; import java.util.Properties; import org.apache.commons.lang3.StringUtils; -import org.json.JSONException; -import org.json.JSONWriter; import com.google.refine.expr.EvalError; import com.google.refine.grel.ControlFunctionRegistry; @@ -58,13 +56,17 @@ public class SplitByCharType implements Function { } @Override - public void write(JSONWriter writer, Properties options) - throws JSONException { + public String getDescription() { + return "Returns an array of strings obtained by splitting s grouping consecutive chars by their unicode type"; + } - writer.object(); - writer.key("description"); writer.value("Returns an array of strings obtained by splitting s grouping consecutive chars by their unicode type"); - writer.key("params"); writer.value("string s"); - writer.key("returns"); writer.value("array"); - writer.endObject(); + @Override + public String getParams() { + return "string s"; + } + + @Override + public String getReturns() { + return "array"; } } diff --git a/main/src/com/google/refine/expr/functions/strings/SplitByLengths.java b/main/src/com/google/refine/expr/functions/strings/SplitByLengths.java index dd827797e..41c88ce62 100644 --- a/main/src/com/google/refine/expr/functions/strings/SplitByLengths.java +++ b/main/src/com/google/refine/expr/functions/strings/SplitByLengths.java @@ -35,9 +35,6 @@ package com.google.refine.expr.functions.strings; import java.util.Properties; -import org.json.JSONException; -import org.json.JSONWriter; - import com.google.refine.expr.EvalError; import com.google.refine.grel.ControlFunctionRegistry; import com.google.refine.grel.Function; @@ -71,13 +68,17 @@ public class SplitByLengths implements Function { } @Override - public void write(JSONWriter writer, Properties options) - throws JSONException { + public String getDescription() { + return "Returns the array of strings obtained by splitting s into substrings with the given lengths"; + } - writer.object(); - writer.key("description"); writer.value("Returns the array of strings obtained by splitting s into substrings with the given lengths"); - writer.key("params"); writer.value("string s, number n, ..."); - writer.key("returns"); writer.value("array"); - writer.endObject(); + @Override + public String getParams() { + return "string s, number n, ..."; + } + + @Override + public String getReturns() { + return "array"; } } diff --git a/main/src/com/google/refine/expr/functions/strings/StartsWith.java b/main/src/com/google/refine/expr/functions/strings/StartsWith.java index acf9d3d3d..51a803618 100644 --- a/main/src/com/google/refine/expr/functions/strings/StartsWith.java +++ b/main/src/com/google/refine/expr/functions/strings/StartsWith.java @@ -35,9 +35,6 @@ package com.google.refine.expr.functions.strings; import java.util.Properties; -import org.json.JSONException; -import org.json.JSONWriter; - import com.google.refine.expr.EvalError; import com.google.refine.grel.ControlFunctionRegistry; import com.google.refine.grel.Function; @@ -56,13 +53,17 @@ public class StartsWith implements Function { return new EvalError(ControlFunctionRegistry.getFunctionName(this) + " expects 2 strings"); } @Override - public void write(JSONWriter writer, Properties options) - throws JSONException { + public String getDescription() { + return "Returns whether s starts with sub"; + } - writer.object(); - writer.key("description"); writer.value("Returns whether s starts with sub"); - writer.key("params"); writer.value("string s, string sub"); - writer.key("returns"); writer.value("boolean"); - writer.endObject(); + @Override + public String getParams() { + return "string s, string sub"; + } + + @Override + public String getReturns() { + return "boolean"; } } diff --git a/main/src/com/google/refine/expr/functions/strings/ToLowercase.java b/main/src/com/google/refine/expr/functions/strings/ToLowercase.java index f9ec96990..2647b7112 100644 --- a/main/src/com/google/refine/expr/functions/strings/ToLowercase.java +++ b/main/src/com/google/refine/expr/functions/strings/ToLowercase.java @@ -35,9 +35,6 @@ package com.google.refine.expr.functions.strings; import java.util.Properties; -import org.json.JSONException; -import org.json.JSONWriter; - import com.google.refine.expr.EvalError; import com.google.refine.grel.ControlFunctionRegistry; import com.google.refine.grel.Function; @@ -54,13 +51,17 @@ public class ToLowercase implements Function { } @Override - public void write(JSONWriter writer, Properties options) - throws JSONException { + public String getDescription() { + return "Returns s converted to lowercase"; + } - writer.object(); - writer.key("description"); writer.value("Returns s converted to lowercase"); - writer.key("params"); writer.value("string s"); - writer.key("returns"); writer.value("string"); - writer.endObject(); + @Override + public String getParams() { + return "string s"; + } + + @Override + public String getReturns() { + return "string"; } } diff --git a/main/src/com/google/refine/expr/functions/strings/ToTitlecase.java b/main/src/com/google/refine/expr/functions/strings/ToTitlecase.java index e1bb2d7d8..17a1a3e7e 100644 --- a/main/src/com/google/refine/expr/functions/strings/ToTitlecase.java +++ b/main/src/com/google/refine/expr/functions/strings/ToTitlecase.java @@ -36,8 +36,6 @@ package com.google.refine.expr.functions.strings; import java.util.Properties; import org.apache.commons.lang3.text.WordUtils; -import org.json.JSONException; -import org.json.JSONWriter; import com.google.refine.expr.EvalError; import com.google.refine.grel.ControlFunctionRegistry; @@ -64,14 +62,18 @@ public class ToTitlecase implements Function { } @Override - public void write(JSONWriter writer, Properties options) - throws JSONException { + public String getDescription() { + return "Returns s converted to titlecase"; + } - writer.object(); - writer.key("description"); writer.value("Returns s converted to titlecase"); - writer.key("params"); writer.value("string s"); - writer.key("returns"); writer.value("string"); - writer.endObject(); + @Override + public String getParams() { + return "string s"; + } + + @Override + public String getReturns() { + return "string"; } } diff --git a/main/src/com/google/refine/expr/functions/strings/ToUppercase.java b/main/src/com/google/refine/expr/functions/strings/ToUppercase.java index f3b13db41..bfe0e1246 100644 --- a/main/src/com/google/refine/expr/functions/strings/ToUppercase.java +++ b/main/src/com/google/refine/expr/functions/strings/ToUppercase.java @@ -35,9 +35,6 @@ package com.google.refine.expr.functions.strings; import java.util.Properties; -import org.json.JSONException; -import org.json.JSONWriter; - import com.google.refine.expr.EvalError; import com.google.refine.grel.ControlFunctionRegistry; import com.google.refine.grel.Function; @@ -54,13 +51,17 @@ public class ToUppercase implements Function { } @Override - public void write(JSONWriter writer, Properties options) - throws JSONException { + public String getDescription() { + return "Returns s converted to uppercase"; + } - writer.object(); - writer.key("description"); writer.value("Returns s converted to uppercase"); - writer.key("params"); writer.value("string s"); - writer.key("returns"); writer.value("string"); - writer.endObject(); + @Override + public String getParams() { + return "string s"; + } + + @Override + public String getReturns() { + return "string"; } } diff --git a/main/src/com/google/refine/expr/functions/strings/Trim.java b/main/src/com/google/refine/expr/functions/strings/Trim.java index 9f1051a57..6d75a74ca 100644 --- a/main/src/com/google/refine/expr/functions/strings/Trim.java +++ b/main/src/com/google/refine/expr/functions/strings/Trim.java @@ -35,11 +35,7 @@ package com.google.refine.expr.functions.strings; import java.util.Properties; -import org.json.JSONException; -import org.json.JSONWriter; - import com.google.common.base.CharMatcher; - import com.google.refine.expr.EvalError; import com.google.refine.grel.Function; @@ -56,13 +52,17 @@ public class Trim implements Function { return new EvalError("Invalid parameters"); } @Override - public void write(JSONWriter writer, Properties options) - throws JSONException { + public String getDescription() { + return "Returns copy of the string, with leading and trailing whitespace omitted."; + } - writer.object(); - writer.key("description"); writer.value("Returns copy of the string, with leading and trailing whitespace omitted."); - writer.key("params"); writer.value("string s"); - writer.key("returns"); writer.value("string"); - writer.endObject(); + @Override + public String getParams() { + return "string s"; + } + + @Override + public String getReturns() { + return "string"; } } diff --git a/main/src/com/google/refine/expr/functions/strings/Unescape.java b/main/src/com/google/refine/expr/functions/strings/Unescape.java index c3292d351..95a7742ae 100644 --- a/main/src/com/google/refine/expr/functions/strings/Unescape.java +++ b/main/src/com/google/refine/expr/functions/strings/Unescape.java @@ -38,8 +38,6 @@ import java.net.URLDecoder; import java.util.Properties; import org.apache.commons.lang3.StringEscapeUtils; -import org.json.JSONException; -import org.json.JSONWriter; import com.google.refine.expr.EvalError; import com.google.refine.grel.ControlFunctionRegistry; @@ -76,13 +74,17 @@ public class Unescape implements Function { } @Override - public void write(JSONWriter writer, Properties options) - throws JSONException { + public String getDescription() { + return "Unescapes all escaped parts of the string depending on the given escaping mode."; + } - writer.object(); - writer.key("description"); writer.value("Unescapes all escaped parts of the string depending on the given escaping mode."); - writer.key("params"); writer.value("string s, string mode ['html','xml','csv','url','javascript']"); - writer.key("returns"); writer.value("string"); - writer.endObject(); + @Override + public String getParams() { + return "string s, string mode ['html','xml','csv','url','javascript']"; + } + + @Override + public String getReturns() { + return "string"; } } diff --git a/main/src/com/google/refine/expr/functions/strings/Unicode.java b/main/src/com/google/refine/expr/functions/strings/Unicode.java index d1bed5545..69e0f8bee 100644 --- a/main/src/com/google/refine/expr/functions/strings/Unicode.java +++ b/main/src/com/google/refine/expr/functions/strings/Unicode.java @@ -35,9 +35,6 @@ package com.google.refine.expr.functions.strings; import java.util.Properties; -import org.json.JSONException; -import org.json.JSONWriter; - import com.google.refine.grel.Function; public class Unicode implements Function { @@ -57,13 +54,17 @@ public class Unicode implements Function { } @Override - public void write(JSONWriter writer, Properties options) - throws JSONException { + public String getDescription() { + return "Returns an array of strings describing each character of s in their full unicode notation"; + } - writer.object(); - writer.key("description"); writer.value("Returns an array of strings describing each character of s in their full unicode notation"); - writer.key("params"); writer.value("string s"); - writer.key("returns"); writer.value("string"); - writer.endObject(); + @Override + public String getParams() { + return "string s"; + } + + @Override + public String getReturns() { + return "string"; } } diff --git a/main/src/com/google/refine/expr/functions/strings/UnicodeType.java b/main/src/com/google/refine/expr/functions/strings/UnicodeType.java index 3ca1e9aeb..7bf2eb0f9 100644 --- a/main/src/com/google/refine/expr/functions/strings/UnicodeType.java +++ b/main/src/com/google/refine/expr/functions/strings/UnicodeType.java @@ -35,9 +35,6 @@ package com.google.refine.expr.functions.strings; import java.util.Properties; -import org.json.JSONException; -import org.json.JSONWriter; - import com.google.refine.grel.Function; public class UnicodeType implements Function { @@ -94,13 +91,17 @@ public class UnicodeType implements Function { } @Override - public void write(JSONWriter writer, Properties options) - throws JSONException { + public String getDescription() { + return "Returns an array of strings describing each character of s in their full unicode notation"; + } - writer.object(); - writer.key("description"); writer.value("Returns an array of strings describing each character of s in their full unicode notation"); - writer.key("params"); writer.value("string s"); - writer.key("returns"); writer.value("string"); - writer.endObject(); + @Override + public String getParams() { + return "string s"; + } + + @Override + public String getReturns() { + return "string"; } } diff --git a/main/src/com/google/refine/expr/functions/xml/OwnText.java b/main/src/com/google/refine/expr/functions/xml/OwnText.java index 8066b9473..0604f8899 100644 --- a/main/src/com/google/refine/expr/functions/xml/OwnText.java +++ b/main/src/com/google/refine/expr/functions/xml/OwnText.java @@ -35,8 +35,6 @@ package com.google.refine.expr.functions.xml; import java.util.Properties; -import org.json.JSONException; -import org.json.JSONWriter; import org.jsoup.nodes.Element; import com.google.refine.expr.EvalError; @@ -62,14 +60,18 @@ public class OwnText implements Function { @Override - public void write(JSONWriter writer, Properties options) - throws JSONException { - - writer.object(); - writer.key("description"); writer.value("Gets the text owned by this XML/HTML element only; does not get the combined text of all children."); - writer.key("params"); writer.value("Element e"); - writer.key("returns"); writer.value("String ownText"); - writer.endObject(); + public String getDescription() { + return "Gets the text owned by this XML/HTML element only; does not get the combined text of all children."; + } + + @Override + public String getParams() { + return "Element e"; + } + + @Override + public String getReturns() { + return "String ownText"; } } diff --git a/main/src/com/google/refine/expr/functions/xml/SelectXml.java b/main/src/com/google/refine/expr/functions/xml/SelectXml.java index 8bb8d3a84..fff66aac6 100644 --- a/main/src/com/google/refine/expr/functions/xml/SelectXml.java +++ b/main/src/com/google/refine/expr/functions/xml/SelectXml.java @@ -35,8 +35,6 @@ package com.google.refine.expr.functions.xml; import java.util.Properties; -import org.json.JSONException; -import org.json.JSONWriter; import org.jsoup.nodes.Element; import com.google.refine.expr.EvalError; @@ -64,14 +62,18 @@ public class SelectXml implements Function { @Override - public void write(JSONWriter writer, Properties options) - throws JSONException { - - writer.object(); - writer.key("description"); writer.value("Selects an element from an XML or HTML element using selector syntax."); - writer.key("params"); writer.value("Element e, String s"); - writer.key("returns"); writer.value("XML/HTML Elements"); - writer.endObject(); + public String getDescription() { + return "Selects an element from an XML or HTML elementn using selector syntax."; + } + + @Override + public String getParams() { + return "Element e, String s"; + } + + @Override + public String getReturns() { + return "HTML Elements"; } } diff --git a/main/src/com/google/refine/expr/functions/xml/XmlAttr.java b/main/src/com/google/refine/expr/functions/xml/XmlAttr.java index c4746038d..626514efa 100644 --- a/main/src/com/google/refine/expr/functions/xml/XmlAttr.java +++ b/main/src/com/google/refine/expr/functions/xml/XmlAttr.java @@ -35,8 +35,6 @@ package com.google.refine.expr.functions.xml; import java.util.Properties; -import org.json.JSONException; -import org.json.JSONWriter; import org.jsoup.nodes.Element; import com.google.refine.expr.EvalError; @@ -64,14 +62,18 @@ public class XmlAttr implements Function { @Override - public void write(JSONWriter writer, Properties options) - throws JSONException { - - writer.object(); - writer.key("description"); writer.value("Selects a value from an attribute on an xml or html Element."); - writer.key("params"); writer.value("Element e, String s"); - writer.key("returns"); writer.value("String attribute Value"); - writer.endObject(); + public String getDescription() { + return "Selects a value from an attribute on an XML or HTML Element"; + } + + @Override + public String getParams() { + return "Element e, String s"; + } + + @Override + public String getReturns() { + return "String attribute Value"; } } diff --git a/main/src/com/google/refine/expr/functions/xml/XmlText.java b/main/src/com/google/refine/expr/functions/xml/XmlText.java index 014eb8016..8d9167a3b 100644 --- a/main/src/com/google/refine/expr/functions/xml/XmlText.java +++ b/main/src/com/google/refine/expr/functions/xml/XmlText.java @@ -35,8 +35,6 @@ package com.google.refine.expr.functions.xml; import java.util.Properties; -import org.json.JSONException; -import org.json.JSONWriter; import org.jsoup.nodes.Element; import com.google.refine.expr.EvalError; @@ -62,14 +60,18 @@ public class XmlText implements Function { @Override - public void write(JSONWriter writer, Properties options) - throws JSONException { - - writer.object(); - writer.key("description"); writer.value("Selects the text from within an element (including all child elements)"); - writer.key("params"); writer.value("Element e"); - writer.key("returns"); writer.value("String text"); - writer.endObject(); + public String getDescription() { + return "Selects the text from within an element (including all child elements)"; + } + + @Override + public String getParams() { + return "Element e"; + } + + @Override + public String getReturns() { + return "String text"; } } diff --git a/main/src/com/google/refine/grel/Function.java b/main/src/com/google/refine/grel/Function.java index 1153bf6f8..c3c346855 100644 --- a/main/src/com/google/refine/grel/Function.java +++ b/main/src/com/google/refine/grel/Function.java @@ -35,6 +35,11 @@ package com.google.refine.grel; import java.util.Properties; +import org.json.JSONWriter; + +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonInclude.Include; +import com.fasterxml.jackson.annotation.JsonProperty; import com.google.refine.Jsonizable; /** @@ -43,4 +48,27 @@ import com.google.refine.Jsonizable; */ public interface Function extends Jsonizable { public Object call(Properties bindings, Object[] args); + + @JsonProperty("description") + public String getDescription(); + + @JsonProperty("params") + @JsonInclude(Include.NON_EMPTY) + default public String getParams() { + return ""; + } + + @JsonProperty("returns") + public String getReturns(); + + @Override + default public void write(JSONWriter writer, Properties options) { + writer.object(); + writer.key("description"); writer.value(getDescription()); + if (!getParams().isEmpty()) { + writer.key("params"); writer.value(getParams()); + } + writer.key("returns"); writer.value(getReturns()); + writer.endObject(); + } }