Refactor: Renamed fromJson() to fromKoral()

Change-Id: Idba70a6cec6e9e1c17291888bdd98a24157b1250
diff --git a/Changes b/Changes
index ef06563..83ccfa9 100644
--- a/Changes
+++ b/Changes
@@ -1,5 +1,6 @@
-0.55.6 2016-06-03
+0.55.6 2016-06-08
         - [bugfix] distance with key "t" uses default foundry (diewald)
+	- [cleanup] Renamed fromJson() to fromKoral() (diewald)
 
 0.55.5 2016-05-02
 	- [performance] Changed to a dynamic window for sorting in FocusSpans (margaretha)
diff --git a/src/main/java/de/ids_mannheim/korap/Krill.java b/src/main/java/de/ids_mannheim/korap/Krill.java
index ad72f7a..964c10c 100644
--- a/src/main/java/de/ids_mannheim/korap/Krill.java
+++ b/src/main/java/de/ids_mannheim/korap/Krill.java
@@ -83,7 +83,7 @@
      *            The KoralQuery json string.
      */
     public Krill (String query) {
-        this.fromJson(query);
+        this.fromKoral(query);
     };
 
 
@@ -95,7 +95,7 @@
      *            The KoralQuery {@link JsonNode} object.
      */
     public Krill (JsonNode query) {
-        this.fromJson(query);
+        this.fromKoral(query);
     };
 
 
@@ -138,11 +138,11 @@
      * @return The {@link Krill} object for chaining.
      * @throws QueryException
      */
-    public Krill fromJson (final String query) {
+    public Krill fromKoral (final String query) {
         // Parse query string
         try {
             this.request = mapper.readTree(query);
-            this.fromJson(this.request);
+            this.fromKoral(this.request);
         }
 
         // Unable to parse JSON
@@ -162,7 +162,7 @@
      * @return The {@link Krill} object for chaining.
      * @throws QueryException
      */
-    public Krill fromJson (JsonNode json) {
+    public Krill fromKoral (JsonNode json) {
 
         // Parse "query" attribute
         if (json.has("query")) {
@@ -170,7 +170,7 @@
                 final KrillQuery kq = new KrillQuery("tokens");
                 this.setQuery(kq);
 
-                final SpanQueryWrapper qw = kq.fromJson(json.get("query"));
+                final SpanQueryWrapper qw = kq.fromKoral(json.get("query"));
 
                 // Throw an error, in case the query matches everywhere
                 if (qw.isEmpty())
@@ -215,7 +215,7 @@
 
                 // TODO: Temporary
                 if (collNode.fieldNames().hasNext()) {
-                    this.setCollection(new KrillCollection().fromJson(collNode));
+                    this.setCollection(new KrillCollection().fromKoral(collNode));
                 };
             }
 
diff --git a/src/main/java/de/ids_mannheim/korap/KrillCollection.java b/src/main/java/de/ids_mannheim/korap/KrillCollection.java
index ae09adc..36e9d5a 100644
--- a/src/main/java/de/ids_mannheim/korap/KrillCollection.java
+++ b/src/main/java/de/ids_mannheim/korap/KrillCollection.java
@@ -89,7 +89,7 @@
             JsonNode json = mapper.readTree(jsonString);
 
             if (json.has("collection"))
-                this.fromJson(json.get("collection"));
+                this.fromKoral(json.get("collection"));
 
             else if (json.has("collections"))
                 this.addError(899,
@@ -128,10 +128,10 @@
      *            The "collection" part of a KoralQuery.
      * @throws QueryException
      */
-    public KrillCollection fromJson (String jsonString) throws QueryException {
+    public KrillCollection fromKoral (String jsonString) throws QueryException {
         ObjectMapper mapper = new ObjectMapper();
         try {
-            this.fromJson((JsonNode) mapper.readTree(jsonString));
+            this.fromKoral((JsonNode) mapper.readTree(jsonString));
         }
         catch (Exception e) {
             this.addError(621, "Unable to parse JSON", "KrillCollection");
@@ -149,13 +149,13 @@
      *            as a {@link JsonNode} object.
      * @throws QueryException
      */
-    public KrillCollection fromJson (JsonNode json) throws QueryException {
+    public KrillCollection fromKoral (JsonNode json) throws QueryException {
         this.json = json;
-        return this.fromBuilder(this._fromJson(json));
+        return this.fromBuilder(this._fromKoral(json));
     };
 
 
-    private CollectionBuilder.Interface _fromJson (JsonNode json)
+    private CollectionBuilder.Interface _fromKoral (JsonNode json)
             throws QueryException {
 
         if (!json.has("@type")) {
@@ -282,7 +282,7 @@
                         "Unknown document group operation");
 
             for (JsonNode operand : json.get("operands")) {
-                group.with(this._fromJson(operand));
+                group.with(this._fromKoral(operand));
             };
             return group;
         }
diff --git a/src/main/java/de/ids_mannheim/korap/KrillQuery.java b/src/main/java/de/ids_mannheim/korap/KrillQuery.java
index b5ea08d..d12e473 100644
--- a/src/main/java/de/ids_mannheim/korap/KrillQuery.java
+++ b/src/main/java/de/ids_mannheim/korap/KrillQuery.java
@@ -44,7 +44,7 @@
  * String koral = "{\"@type\":"koral:group", ... }";
  * 
  * SpanQueryWrapper sqw = new
- * KrillQuery("tokens").fromJson("{... JsonString ...}");
+ * KrillQuery("tokens").fromKoral("{... JsonString ...}");
  * </pre></blockquote>
  * 
  * @author diewald
@@ -142,7 +142,7 @@
      * 
      * <blockquote><pre>
      * KrillQuery kq = new KrillQuery("tokens");
-     * SpanQueryWrapper sqw = kq.fromJson(
+     * SpanQueryWrapper sqw = kq.fromKoral(
      * "{\"@type\" : \"koral:token\","+
      * "\"wrap\" : {" +
      * "\"@type\" :   \"koral:term\"," +
@@ -159,7 +159,7 @@
      * @return {@link SpanQueryWrapper} object.
      * @throws QueryException
      */
-    public SpanQueryWrapper fromJson (String json) throws QueryException {
+    public SpanQueryWrapper fromKoral (String json) throws QueryException {
         JsonNode jsonN;
         try {
             // Read Json string
@@ -178,7 +178,7 @@
             jsonN = jsonN.get("query");
 
         // Deserialize from node
-        return this.fromJson(jsonN);
+        return this.fromKoral(jsonN);
     };
 
 
@@ -195,15 +195,15 @@
     // TODO: Use the shortcuts implemented in the builder
     //       instead of the wrapper constructors
     // TODO: Rename this span context!
-    public SpanQueryWrapper fromJson (JsonNode json) throws QueryException {
+    public SpanQueryWrapper fromKoral (JsonNode json) throws QueryException {
 
         // Set this for reserialization - may be changed later on
         this.json = json;
-        return this._fromJson(json);
+        return this._fromKoral(json);
     };
 
 
-    private SpanQueryWrapper _fromJson (JsonNode json) throws QueryException {
+    private SpanQueryWrapper _fromKoral (JsonNode json) throws QueryException {
         int number = 0;
 
         // Only accept @typed objects for the moment
@@ -278,7 +278,7 @@
                         log.trace("Wrap span reference {},{}", startOffset,
                                 length);
 
-                    SpanQueryWrapper sqw = this._fromJson(operands.get(0));
+                    SpanQueryWrapper sqw = this._fromKoral(operands.get(0));
                     SpanSubspanQueryWrapper ssqw = new SpanSubspanQueryWrapper(
                             sqw, startOffset, length);
                     return ssqw;
@@ -289,7 +289,7 @@
                     log.trace("Wrap class reference {}", number);
 
                 return new SpanFocusQueryWrapper(
-                        this._fromJson(operands.get(0)), number);
+                        this._fromKoral(operands.get(0)), number);
 
             case "koral:token":
 
@@ -476,7 +476,7 @@
         if (isReference) {
             JsonNode resolvedNode = _resolveReference(node, operands,
                     refOperandNum, classNum);
-            return new SpanReferenceQueryWrapper(this._fromJson(resolvedNode),
+            return new SpanReferenceQueryWrapper(this._fromKoral(resolvedNode),
                     (byte) classNum);
         }
 
@@ -539,8 +539,8 @@
                     "Number of operands is not acceptable");
         }
 
-        SpanQueryWrapper operand1 = this._fromJson(operands.get(0));
-        SpanQueryWrapper operand2 = this._fromJson(operands.get(1));
+        SpanQueryWrapper operand1 = this._fromKoral(operands.get(0));
+        SpanQueryWrapper operand2 = this._fromKoral(operands.get(1));
 
         String direction = ">:";
         if (operand1.isEmpty() && !operand2.isEmpty()) {
@@ -570,7 +570,7 @@
             throws QueryException {
         SpanAlterQueryWrapper ssaq = new SpanAlterQueryWrapper(this.field);
         for (JsonNode operand : operands) {
-            ssaq.or(this._fromJson(operand));
+            ssaq.or(this._fromKoral(operand));
         };
         return ssaq;
     };
@@ -662,8 +662,8 @@
         // </legacyCode>
 
         // Create SpanWithin Query
-        return new SpanWithinQueryWrapper(this._fromJson(operands.get(0)),
-                this._fromJson(operands.get(1)), flag);
+        return new SpanWithinQueryWrapper(this._fromKoral(operands.get(0)),
+                this._fromKoral(operands.get(1)), flag);
     };
 
 
@@ -712,7 +712,7 @@
         if (min > max)
             max = max;
 
-        SpanQueryWrapper sqw = this._fromJson(operands.get(0));
+        SpanQueryWrapper sqw = this._fromKoral(operands.get(0));
 
         if (sqw.maybeExtension())
             return sqw.setMin(min).setMax(max);
@@ -750,7 +750,7 @@
                     "Span references are currently not supported");
         };
 
-        return new SpanFocusQueryWrapper(this._fromJson(operands.get(0)),
+        return new SpanFocusQueryWrapper(this._fromKoral(operands.get(0)),
                 number);
     };
 
@@ -804,7 +804,7 @@
             };
 
             // Serialize operand
-            SpanQueryWrapper sqw = this._fromJson(operands.get(0));
+            SpanQueryWrapper sqw = this._fromKoral(operands.get(0));
 
             // Problematic
             if (sqw.maybeExtension())
@@ -823,7 +823,7 @@
 
         // Sequence with only one operand
         if (operands.size() == 1)
-            return this._fromJson(operands.get(0));
+            return this._fromKoral(operands.get(0));
 
         SpanSequenceQueryWrapper sseqqw = this.builder().seq();
 
@@ -945,7 +945,7 @@
 
         // Add segments to sequence
         for (JsonNode operand : operands) {
-            sseqqw.append(this._fromJson(operand));
+            sseqqw.append(this._fromKoral(operand));
         };
 
         // inOrder was set to false without a distance constraint
diff --git a/src/test/java/de/ids_mannheim/korap/TestSimple.java b/src/test/java/de/ids_mannheim/korap/TestSimple.java
index 9a42ab8..17179aa 100644
--- a/src/test/java/de/ids_mannheim/korap/TestSimple.java
+++ b/src/test/java/de/ids_mannheim/korap/TestSimple.java
@@ -96,7 +96,7 @@
 
         try {
             String json = getString(jsonFile);
-            sqwi = new KrillQuery("tokens").fromJson(json);
+            sqwi = new KrillQuery("tokens").fromKoral(json);
         }
         catch (QueryException e) {
             fail(e.getMessage());
diff --git a/src/test/java/de/ids_mannheim/korap/benchmark/TestBenchmarkSpans.java b/src/test/java/de/ids_mannheim/korap/benchmark/TestBenchmarkSpans.java
index e29c2b4..26874c4 100644
--- a/src/test/java/de/ids_mannheim/korap/benchmark/TestBenchmarkSpans.java
+++ b/src/test/java/de/ids_mannheim/korap/benchmark/TestBenchmarkSpans.java
@@ -383,7 +383,7 @@
 
         try {
             String json = getString(jsonFile);
-            sqwi = new KrillQuery("tokens").fromJson(json);
+            sqwi = new KrillQuery("tokens").fromKoral(json);
         }
         catch (QueryException e) {
             fail(e.getMessage());
diff --git a/src/test/java/de/ids_mannheim/korap/highlight/TestClass.java b/src/test/java/de/ids_mannheim/korap/highlight/TestClass.java
index c307e80..7b2bd7c 100644
--- a/src/test/java/de/ids_mannheim/korap/highlight/TestClass.java
+++ b/src/test/java/de/ids_mannheim/korap/highlight/TestClass.java
@@ -32,7 +32,7 @@
         String jsonPath = getClass().getResource("/queries/poly1.json")
                 .getFile();
         String jsonQuery = readFile(jsonPath);
-        SpanQueryWrapper sqwi = new KrillQuery("tokens").fromJson(jsonQuery);
+        SpanQueryWrapper sqwi = new KrillQuery("tokens").fromKoral(jsonQuery);
 
         SpanNextQuery sq = (SpanNextQuery) sqwi.toQuery();
         //System.out.println(sq.toString());
@@ -67,7 +67,7 @@
         String jsonPath = getClass().getResource("/queries/poly4.json")
                 .getFile();
         String jsonQuery = readFile(jsonPath);
-        SpanQueryWrapper sqwi = new KrillQuery("tokens").fromJson(jsonQuery);
+        SpanQueryWrapper sqwi = new KrillQuery("tokens").fromKoral(jsonQuery);
         SpanQuery sq = sqwi.toQuery();
 
         // System.out.println(sq.toString());
diff --git a/src/test/java/de/ids_mannheim/korap/index/TestElementDistanceIndex.java b/src/test/java/de/ids_mannheim/korap/index/TestElementDistanceIndex.java
index 17d9bf3..f63f299 100644
--- a/src/test/java/de/ids_mannheim/korap/index/TestElementDistanceIndex.java
+++ b/src/test/java/de/ids_mannheim/korap/index/TestElementDistanceIndex.java
@@ -245,7 +245,6 @@
         assertEquals("[ec]ebdc", kr.getMatch(0).getSnippetBrackets());
     };
 
-
     public static String getString (String path) {
         StringBuilder contentBuilder = new StringBuilder();
         try {
@@ -268,7 +267,7 @@
 
         try {
             String json = getString(jsonFile);
-            sqwi = new KrillQuery("tokens").fromJson(json);
+            sqwi = new KrillQuery("tokens").fromKoral(json);
         }
         catch (QueryException e) {
             fail(e.getMessage());
diff --git a/src/test/java/de/ids_mannheim/korap/index/TestFieldDocument.java b/src/test/java/de/ids_mannheim/korap/index/TestFieldDocument.java
index 73acd2a..91eab68 100644
--- a/src/test/java/de/ids_mannheim/korap/index/TestFieldDocument.java
+++ b/src/test/java/de/ids_mannheim/korap/index/TestFieldDocument.java
@@ -231,7 +231,7 @@
 
         try {
             String json = getString(jsonFile);
-            sqwi = new KrillQuery("tokens").fromJson(json);
+            sqwi = new KrillQuery("tokens").fromKoral(json);
         }
         catch (QueryException e) {
             fail(e.getMessage());
diff --git a/src/test/java/de/ids_mannheim/korap/index/TestSpanExpansionIndex.java b/src/test/java/de/ids_mannheim/korap/index/TestSpanExpansionIndex.java
index 5c2bc24..2a81f68 100644
--- a/src/test/java/de/ids_mannheim/korap/index/TestSpanExpansionIndex.java
+++ b/src/test/java/de/ids_mannheim/korap/index/TestSpanExpansionIndex.java
@@ -299,7 +299,7 @@
         String jsonPath = getClass().getResource("/queries/poly3.json")
                 .getFile();
         String jsonQuery = readFile(jsonPath);
-        SpanQueryWrapper sqwi = new KrillQuery("tokens").fromJson(jsonQuery);
+        SpanQueryWrapper sqwi = new KrillQuery("tokens").fromKoral(jsonQuery);
 
         SpanQuery sq = sqwi.toQuery();
         //System.out.println(sq.toString());
@@ -409,7 +409,7 @@
         String json = readFile(getClass().getResource(
                 "/queries/bugs/expansion_bug_3.jsonld").getFile());
         KrillQuery kq = new KrillQuery("base");
-        SpanQuery sq = kq.fromJson(json).toQuery();
+        SpanQuery sq = kq.fromKoral(json).toQuery();
         assertEquals(
                 sq.toString(),
                 "focus(254: spanContain(<base:base/s:t />, {254: spanExpansion(base:s:c, []{0, 4}, right)}))");
diff --git a/src/test/java/de/ids_mannheim/korap/index/TestWithinIndex.java b/src/test/java/de/ids_mannheim/korap/index/TestWithinIndex.java
index 8ac224f..b0bd6cc 100644
--- a/src/test/java/de/ids_mannheim/korap/index/TestWithinIndex.java
+++ b/src/test/java/de/ids_mannheim/korap/index/TestWithinIndex.java
@@ -1110,7 +1110,7 @@
         String jsonPath = getClass().getResource("/queries/poly2.json")
                 .getFile();
         String jsonPQuery = readFile(jsonPath);
-        SpanQueryWrapper sqwi = new KrillQuery("tokens").fromJson(jsonPQuery);
+        SpanQueryWrapper sqwi = new KrillQuery("tokens").fromKoral(jsonPQuery);
 
         SpanWithinQuery sq = (SpanWithinQuery) sqwi.toQuery();
 
@@ -1147,7 +1147,7 @@
         String jsonPath = getClass().getResource(
                 "/queries/bugs/span_or_bug.jsonld").getFile();
         String jsonPQuery = readFile(jsonPath);
-        SpanQueryWrapper sqwi = new KrillQuery("tokens").fromJson(jsonPQuery);
+        SpanQueryWrapper sqwi = new KrillQuery("tokens").fromKoral(jsonPQuery);
 
         SpanWithinQuery sq = (SpanWithinQuery) sqwi.toQuery();
 
diff --git a/src/test/java/de/ids_mannheim/korap/query/TestKrillQueryJSON.java b/src/test/java/de/ids_mannheim/korap/query/TestKrillQueryJSON.java
index cf8f67d..5e865d1 100644
--- a/src/test/java/de/ids_mannheim/korap/query/TestKrillQueryJSON.java
+++ b/src/test/java/de/ids_mannheim/korap/query/TestKrillQueryJSON.java
@@ -254,7 +254,7 @@
     @Test
     public void queryJSONDemo () throws QueryException {
         SpanQueryWrapper sqwi = new KrillQuery("tokens")
-                .fromJson("{ \"query\" : { \"@type\" : \"koral:token\", \"wrap\" : { \"@type\" : \"koral:term\", \"foundry\" : \"base\", \"layer\" : \"p\", \"key\" : \"foo\", \"match\" : \"match:eq\" }}}");
+                .fromKoral("{ \"query\" : { \"@type\" : \"koral:token\", \"wrap\" : { \"@type\" : \"koral:term\", \"foundry\" : \"base\", \"layer\" : \"p\", \"key\" : \"foo\", \"match\" : \"match:eq\" }}}");
 
         assertEquals(sqwi.toQuery().toString(), "tokens:base/p:foo");
     };
@@ -424,7 +424,7 @@
         try {
             String json = getString(getClass().getResource(
                     "/queries/bugs/underspecified_token.jsonld").getFile());
-            new KrillQuery("tokens").fromJson(json);
+            new KrillQuery("tokens").fromKoral(json);
         }
         catch (QueryException e) {
             assertEquals(701, e.getErrorCode());
@@ -495,21 +495,21 @@
             String json = getString(getClass().getResource(
                     "/queries/flags/unknown1.jsonld").getFile());
             KrillQuery kq = new KrillQuery("tokens");
-            assertEquals(kq.fromJson(json).toQuery().toString(),
+            assertEquals(kq.fromKoral(json).toQuery().toString(),
                     "tokens:s:buchstabe");
             assertEquals(kq.getWarning(0).getCode(), 748);
 
             json = getString(getClass().getResource(
                     "/queries/flags/unknown2.jsonld").getFile());
             kq = new KrillQuery("tokens");
-            assertEquals(kq.fromJson(json).toQuery().toString(),
+            assertEquals(kq.fromKoral(json).toQuery().toString(),
                     "tokens:i:buchstabe");
             assertEquals(kq.getWarning(0).getCode(), 748);
 
             json = getString(getClass().getResource(
                     "/queries/flags/unknown3.jsonld").getFile());
             kq = new KrillQuery("tokens");
-            assertEquals(kq.fromJson(json).toQuery().toString(),
+            assertEquals(kq.fromKoral(json).toQuery().toString(),
                     "tokens:i:buchstabe");
             assertEquals(kq.getWarning(0).getCode(), 748);
 
@@ -528,7 +528,7 @@
                     "/queries/element/simple-element.jsonld").getFile());
             KrillQuery kq = new KrillQuery("tokens");
 
-            assertEquals(kq.fromJson(json).toQuery().toString(),
+            assertEquals(kq.fromKoral(json).toQuery().toString(),
                     "<tokens:base/s:s />");
         }
         catch (QueryException e) {
@@ -546,7 +546,7 @@
             KrillQuery kq = new KrillQuery("tokens");
 
             assertEquals(
-                    kq.fromJson(json).toQuery().toString(),
+                    kq.fromKoral(json).toQuery().toString(),
                     "focus(254: spanContain(<tokens:base/s:t />, {254: spanExpansion(tokens:s:c, []{0, 4}, right)}))");
         }
         catch (QueryException e) {
@@ -563,7 +563,7 @@
                     "/queries/bugs/span_or_bug.jsonld").getFile());
             KrillQuery kq = new KrillQuery("tokens");
 
-            assertEquals(kq.fromJson(json).toQuery().toString(),
+            assertEquals(kq.fromKoral(json).toQuery().toString(),
                     "spanStartsWith(<tokens:base/s:s />, spanOr([tokens:s:Er, tokens:s:Sie]))");
         }
         catch (QueryException e) {
@@ -594,7 +594,7 @@
 
         try {
             String json = getString(jsonFile);
-            sqwi = new KrillQuery("tokens").fromJson(json);
+            sqwi = new KrillQuery("tokens").fromKoral(json);
         }
         catch (QueryException e) {
             fail(e.getMessage());