Added FCSQL Quantifier serialization.

Change-Id: Ie3a1e49afdb7afa35cf5d35a389dcd1f31582e7c
diff --git a/pom.xml b/pom.xml
index e59fd5c..453f107 100644
--- a/pom.xml
+++ b/pom.xml
@@ -1,271 +1,274 @@
 <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
-	 xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
-  <modelVersion>4.0.0</modelVersion>
+	xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+	<modelVersion>4.0.0</modelVersion>
 
-  <groupId>de.ids_mannheim.korap</groupId>
-  <artifactId>Koral</artifactId>
-  <version>0.22</version>
-  <packaging>jar</packaging>
-  <name>Koral</name>
-  <url>http://maven.apache.org</url>
+	<groupId>de.ids_mannheim.korap</groupId>
+	<artifactId>Koral</artifactId>
+	<version>0.22</version>
+	<packaging>jar</packaging>
+	<name>Koral</name>
+	<url>http://maven.apache.org</url>
 
-  <organization>
-    <name>IDS Mannheim</name>
-    <url>http://www.ids-mannheim.de/</url>
-  </organization>
+	<organization>
+		<name>IDS Mannheim</name>
+		<url>http://www.ids-mannheim.de/</url>
+	</organization>
 
-  <developers>
-    <developer>
-      <name>Joachim Bingel</name>
-      <email>bingel@ids-mannheim.de</email>
-    </developer>
-    <developer>
-      <name>Nils Diewald</name>
-      <email>diewald@ids-mannheim.de</email>
-      <url>http://nils-diewald.de</url>
-    </developer>
-    <developer>
-      <name>Michael Hanl</name>
-      <email>hanl@ids-mannheim.de</email>
-    </developer>
-    <developer>
-      <name>Eliza Margaretha</name>
-      <email>margaretha@ids-mannheim.de</email>
-    </developer>
-  </developers>
+	<developers>
+		<developer>
+			<name>Joachim Bingel</name>
+			<email>bingel@ids-mannheim.de</email>
+		</developer>
+		<developer>
+			<name>Nils Diewald</name>
+			<email>diewald@ids-mannheim.de</email>
+			<url>http://nils-diewald.de</url>
+		</developer>
+		<developer>
+			<name>Michael Hanl</name>
+			<email>hanl@ids-mannheim.de</email>
+		</developer>
+		<developer>
+			<name>Eliza Margaretha</name>
+			<email>margaretha@ids-mannheim.de</email>
+		</developer>
+	</developers>
 
-  <properties>
-    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
-  </properties>
+	<properties>
+		<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+	</properties>
 
-  <repositories>
-    <repository>
-      <id>id-maven-repo</id>
-      <url>http://maven.indexdata.com</url>
-    </repository>
-  </repositories>
-  <dependencies>
-    <dependency>
-      <groupId>org.antlr</groupId>
-      <artifactId>antlr4-runtime</artifactId>
-      <version>4.2</version>
-    </dependency>
-    <dependency>
-      <groupId>org.antlr</groupId>
-      <artifactId>antlr4-runtime</artifactId>
-      <version>4.5.1</version>
-    </dependency>
-    <dependency>
-      <groupId>org.antlr</groupId>
-      <artifactId>antlr4-maven-plugin</artifactId>
-      <version>4.2</version>
-    </dependency>
-    <dependency>
-      <groupId>org.antlr</groupId>
-      <artifactId>antlr-runtime</artifactId>
-      <version>3.5</version>
-      <scope>compile</scope>
-    </dependency>
-    <dependency>
-      <groupId>com.google.guava</groupId>
-      <artifactId>guava</artifactId>
-      <version>15.0</version>
-    </dependency>
-    <dependency>
-      <groupId>com.fasterxml.jackson.core</groupId>
-      <artifactId>jackson-core</artifactId>
-      <version>2.3.3</version>
-    </dependency>
-    <dependency>
-      <groupId>com.fasterxml.jackson.core</groupId>
-      <artifactId>jackson-annotations</artifactId>
-      <version>2.3.3</version>
-    </dependency>
-    <dependency>
-      <groupId>com.fasterxml.jackson.core</groupId>
-      <artifactId>jackson-databind</artifactId>
-      <version>2.3.3</version>
-    </dependency>
-    <dependency>
-      <groupId>junit</groupId>
-      <artifactId>junit</artifactId>
-      <version>4.11</version>
-      <scope>test</scope>
-    </dependency>
-    <dependency>
-      <groupId>commons-lang</groupId>
-      <artifactId>commons-lang</artifactId>
-      <version>2.6</version>
-    </dependency>
-    <dependency>
-      <groupId>org.z3950.zing</groupId>
-      <artifactId>cql-java</artifactId>
-      <version>1.12</version>
-    </dependency>
-    <dependency>
-      <groupId>log4j</groupId>
-      <artifactId>log4j</artifactId>
-      <version>1.2.17</version>
-    </dependency>
-    <dependency>
-      <groupId>log4j</groupId>
-      <artifactId>apache-log4j-extras</artifactId>
-      <version>1.2.17</version>
-    </dependency>
-    <dependency>
-      <groupId>org.slf4j</groupId>
-      <artifactId>slf4j-api</artifactId>
-      <version>1.7.5</version>
-    </dependency>
-    <dependency>
-      <groupId>org.slf4j</groupId>
-      <artifactId>slf4j-log4j12</artifactId>
-      <version>1.7.5</version>
-    </dependency>
-    <dependency>
-      <groupId>eu.clarin.sru.fcs</groupId>
-      <artifactId>fcs-simple-endpoint</artifactId>
-      <version>1.3.0</version>
-    </dependency>
-    <dependency>
-      <groupId>org.apache.lucene</groupId>
-      <artifactId>lucene-core</artifactId>
-      <version>5.2.1</version>
-    </dependency>
-    <dependency>
-      <groupId>org.apache.lucene</groupId>
-      <artifactId>lucene-analyzers-common</artifactId>
-      <version>5.2.1</version>
-    </dependency>
-    <dependency>
-      <groupId>org.apache.lucene</groupId>
-      <artifactId>lucene-queryparser</artifactId>
-      <version>5.2.1</version>
-    </dependency>
-  </dependencies>
-  <build>
-    <sourceDirectory>${basedir}/src/main/java</sourceDirectory>
-    <outputDirectory>${basedir}/target/classes</outputDirectory>
-    <plugins>
-      <plugin>
-        <groupId>org.apache.maven.plugins</groupId>
-        <artifactId>maven-compiler-plugin</artifactId>
-        <version>3.3</version>
-        <configuration>
-          <compilerVersion>1.7</compilerVersion>
-          <source>1.7</source>
-          <target>1.7</target>
-        </configuration>
-      </plugin>
-      <!--
-	  Formatter plugin for Eclipse based coding conventions
-	  http://maven-java-formatter-plugin.googlecode.com/svn/site/0.4/usage.html
-      -->      
-      <plugin>
-	<groupId>com.googlecode.maven-java-formatter-plugin</groupId>
-	<artifactId>maven-java-formatter-plugin</artifactId>
-	<version>0.4</version>
-	<configuration>
-	  <configFile>${project.basedir}/Format.xml</configFile>
-	  <overrideConfigCompilerVersion>true</overrideConfigCompilerVersion>
-	  <compilerSource>1.7</compilerSource>
-	  <compilerCompliance>1.7</compilerCompliance>
-	  <compilerTargetPlatform>1.7</compilerTargetPlatform>
-	</configuration>
-      </plugin>
-      <plugin>
-	<artifactId>maven-dependency-plugin</artifactId>
-	<executions>
-	  <execution>
-	    <phase>install</phase>
-	    <goals>
-	      <goal>copy-dependencies</goal>
-	    </goals>
-	    <configuration>
-	      <outputDirectory>${project.build.directory}/../lib</outputDirectory>
-	    </configuration>
-	  </execution>
-	</executions>
-      </plugin>
-      <plugin>
-	<groupId>org.apache.maven.plugins</groupId>
-	<artifactId>maven-jar-plugin</artifactId>
-	<version>2.5</version>
-	<configuration>
-	  <archive>
-	    <manifest>
-	      <addClasspath>true</addClasspath>
-	      <classpathPrefix>../lib/</classpathPrefix>
-	      <mainClass>de.ids_mannheim.korap.query.serialize.QuerySerializer</mainClass>
-	    </manifest>
-	  </archive>
-	</configuration>
-      </plugin>
-      <plugin>
-	<!-- This plugin will help to build the ANTLR4 grammar on the fly. The 
-	     recipe is based on http://stackoverflow.com/questions/15310628/ customize-maven-to-automatically-create-antlr4-grammar-java-files-on-build -->
-	<groupId>org.antlr</groupId>
-	<artifactId>antlr4-maven-plugin</artifactId>
-	<version>4.2</version>
-	<executions>
-	  <execution>
-	    <id>poliqarpplus</id>
-	    <goals>
-	      <goal>antlr4</goal>
-	    </goals>
-	    <configuration>
-	      <sourceDirectory>${basedir}/src/main/antlr/poliqarpplus</sourceDirectory>
-	      <outputDirectory>${basedir}/src/main/java/de/ids_mannheim/korap/query/parse/poliqarpplus</outputDirectory>
-	      <libDirectory>${basedir}/src/main/antlr/poliqarpplus</libDirectory>
-	    </configuration>
-	    <phase>generate-sources</phase>
-	  </execution>
-	  <execution>
-	    <id>annis</id>
-	    <goals>
-	      <goal>antlr4</goal>
-	    </goals>
-	    <configuration>
-	      <sourceDirectory>${basedir}/src/main/antlr/annis</sourceDirectory>
-	      <outputDirectory>${basedir}/src/main/java/de/ids_mannheim/korap/query/parse/annis</outputDirectory>
-	      <libDirectory>${basedir}/src/main/antlr/annis</libDirectory>
-	    </configuration>
-	    <phase>generate-sources</phase>
-	  </execution>
-	  <execution>
-	    <id>collection</id>
-	    <goals>
-	      <goal>antlr4</goal>
-	    </goals>
-	    <configuration>
-	      <sourceDirectory>${basedir}/src/main/antlr/collection</sourceDirectory>
-	      <outputDirectory>${basedir}/src/main/java/de/ids_mannheim/korap/query/parse/collection</outputDirectory>
-	      <libDirectory>${basedir}/src/main/antlr/collection</libDirectory>
-	    </configuration>
-	    <phase>generate-sources</phase>
-	  </execution>
-	</executions>
-      </plugin>
-      <plugin>
-	<!-- This plugin will help to build the ANTLR3 grammar on the fly. The 
-	     recipe is based on http://stackoverflow.com/questions/15310628/ customize-maven-to-automatically-create-antlr4-grammar-java-files-on-build -->
-	<groupId>org.antlr</groupId>
-	<artifactId>antlr3-maven-plugin</artifactId>
-	<version>3.5.1</version>
-	<configuration>
-	  <sourceDirectory>${basedir}/src/main/antlr/cosmas</sourceDirectory>
-	  <outputDirectory>${basedir}/src/main/java/de/ids_mannheim/korap/query/parse/cosmas</outputDirectory>
-	  <libDirectory>${basedir}/src/main/antlr</libDirectory>
-	</configuration>
-	<executions>
-	  <execution>
-	    <goals>
-	      <goal>antlr</goal>
-	    </goals>
-	    <phase>generate-sources</phase>
-	  </execution>
-	</executions>
-      </plugin>
-    </plugins>
-  </build>
+	<repositories>
+		<repository>
+			<id>id-maven-repo</id>
+			<url>http://maven.indexdata.com</url>
+		</repository>
+		<repository>
+			<id>CLARIN</id>
+			<name>CLARIN Repository</name>
+			<url>https://nexus.clarin.eu/content/repositories/Clarin</url>
+			<snapshots>
+				<enabled>false</enabled>
+			</snapshots>
+		</repository>
+	</repositories>
+	<dependencies>
+		<!-- <dependency> <groupId>org.antlr</groupId> <artifactId>antlr4-runtime</artifactId> 
+			<version>4.2</version> </dependency> -->
+		<dependency>
+			<groupId>org.antlr</groupId>
+			<artifactId>antlr4-runtime</artifactId>
+			<version>4.5.1</version>
+		</dependency>
+		<dependency>
+			<groupId>org.antlr</groupId>
+			<artifactId>antlr4-maven-plugin</artifactId>
+			<version>4.2</version>
+		</dependency>
+		<dependency>
+			<groupId>org.antlr</groupId>
+			<artifactId>antlr-runtime</artifactId>
+			<version>3.5</version>
+			<scope>compile</scope>
+		</dependency>
+		<dependency>
+			<groupId>com.google.guava</groupId>
+			<artifactId>guava</artifactId>
+			<version>15.0</version>
+		</dependency>
+		<dependency>
+			<groupId>com.fasterxml.jackson.core</groupId>
+			<artifactId>jackson-core</artifactId>
+			<version>2.3.3</version>
+		</dependency>
+		<dependency>
+			<groupId>com.fasterxml.jackson.core</groupId>
+			<artifactId>jackson-annotations</artifactId>
+			<version>2.3.3</version>
+		</dependency>
+		<dependency>
+			<groupId>com.fasterxml.jackson.core</groupId>
+			<artifactId>jackson-databind</artifactId>
+			<version>2.3.3</version>
+		</dependency>
+		<dependency>
+			<groupId>junit</groupId>
+			<artifactId>junit</artifactId>
+			<version>4.11</version>
+			<scope>test</scope>
+		</dependency>
+		<dependency>
+			<groupId>commons-lang</groupId>
+			<artifactId>commons-lang</artifactId>
+			<version>2.6</version>
+		</dependency>
+		<dependency>
+			<groupId>org.z3950.zing</groupId>
+			<artifactId>cql-java</artifactId>
+			<version>1.12</version>
+		</dependency>
+		<dependency>
+			<groupId>log4j</groupId>
+			<artifactId>log4j</artifactId>
+			<version>1.2.17</version>
+		</dependency>
+		<dependency>
+			<groupId>log4j</groupId>
+			<artifactId>apache-log4j-extras</artifactId>
+			<version>1.2.17</version>
+		</dependency>
+		<dependency>
+			<groupId>org.slf4j</groupId>
+			<artifactId>slf4j-api</artifactId>
+			<version>1.7.5</version>
+		</dependency>
+		<dependency>
+			<groupId>org.slf4j</groupId>
+			<artifactId>slf4j-log4j12</artifactId>
+			<version>1.7.5</version>
+		</dependency>
+		<dependency>
+			<groupId>eu.clarin.sru.fcs</groupId>
+			<artifactId>fcs-simple-endpoint</artifactId>
+			<version>1.3.0</version>
+		</dependency>
+		<dependency>
+			<groupId>org.apache.lucene</groupId>
+			<artifactId>lucene-core</artifactId>
+			<version>5.2.1</version>
+		</dependency>
+		<dependency>
+			<groupId>org.apache.lucene</groupId>
+			<artifactId>lucene-analyzers-common</artifactId>
+			<version>5.2.1</version>
+		</dependency>
+		<dependency>
+			<groupId>org.apache.lucene</groupId>
+			<artifactId>lucene-queryparser</artifactId>
+			<version>5.2.1</version>
+		</dependency>
+	</dependencies>
+	<build>
+		<sourceDirectory>${basedir}/src/main/java</sourceDirectory>
+		<outputDirectory>${basedir}/target/classes</outputDirectory>
+		<plugins>
+			<plugin>
+				<groupId>org.apache.maven.plugins</groupId>
+				<artifactId>maven-compiler-plugin</artifactId>
+				<version>3.3</version>
+				<configuration>
+					<compilerVersion>1.7</compilerVersion>
+					<source>1.7</source>
+					<target>1.7</target>
+				</configuration>
+			</plugin>
+			<!-- Formatter plugin for Eclipse based coding conventions http://maven-java-formatter-plugin.googlecode.com/svn/site/0.4/usage.html -->
+			<plugin>
+				<groupId>com.googlecode.maven-java-formatter-plugin</groupId>
+				<artifactId>maven-java-formatter-plugin</artifactId>
+				<version>0.4</version>
+				<configuration>
+					<configFile>${project.basedir}/Format.xml</configFile>
+					<overrideConfigCompilerVersion>true</overrideConfigCompilerVersion>
+					<compilerSource>1.7</compilerSource>
+					<compilerCompliance>1.7</compilerCompliance>
+					<compilerTargetPlatform>1.7</compilerTargetPlatform>
+				</configuration>
+			</plugin>
+			<plugin>
+				<groupId>org.apache.maven.plugins</groupId>
+				<artifactId>maven-dependency-plugin</artifactId>
+				<executions>
+					<execution>
+						<phase>install</phase>
+						<goals>
+							<goal>copy-dependencies</goal>
+						</goals>
+						<configuration>
+							<outputDirectory>${project.build.directory}/../lib</outputDirectory>
+						</configuration>
+					</execution>
+				</executions>
+			</plugin>
+			<plugin>
+				<groupId>org.apache.maven.plugins</groupId>
+				<artifactId>maven-jar-plugin</artifactId>
+				<version>2.5</version>
+				<configuration>
+					<archive>
+						<manifest>
+							<addClasspath>true</addClasspath>
+							<classpathPrefix>../lib/</classpathPrefix>
+							<mainClass>de.ids_mannheim.korap.query.serialize.QuerySerializer</mainClass>
+						</manifest>
+					</archive>
+				</configuration>
+			</plugin>
+			<plugin>
+				<!-- This plugin will help to build the ANTLR4 grammar on the fly. The 
+					recipe is based on http://stackoverflow.com/questions/15310628/ customize-maven-to-automatically-create-antlr4-grammar-java-files-on-build -->
+				<groupId>org.antlr</groupId>
+				<artifactId>antlr4-maven-plugin</artifactId>
+				<version>4.2</version>
+				<executions>
+					<execution>
+						<id>poliqarpplus</id>
+						<goals>
+							<goal>antlr4</goal>
+						</goals>
+						<configuration>
+							<sourceDirectory>${basedir}/src/main/antlr/poliqarpplus</sourceDirectory>
+							<outputDirectory>${basedir}/src/main/java/de/ids_mannheim/korap/query/parse/poliqarpplus</outputDirectory>
+							<libDirectory>${basedir}/src/main/antlr/poliqarpplus</libDirectory>
+						</configuration>
+						<phase>generate-sources</phase>
+					</execution>
+					<execution>
+						<id>annis</id>
+						<goals>
+							<goal>antlr4</goal>
+						</goals>
+						<configuration>
+							<sourceDirectory>${basedir}/src/main/antlr/annis</sourceDirectory>
+							<outputDirectory>${basedir}/src/main/java/de/ids_mannheim/korap/query/parse/annis</outputDirectory>
+							<libDirectory>${basedir}/src/main/antlr/annis</libDirectory>
+						</configuration>
+						<phase>generate-sources</phase>
+					</execution>
+					<execution>
+						<id>collection</id>
+						<goals>
+							<goal>antlr4</goal>
+						</goals>
+						<configuration>
+							<sourceDirectory>${basedir}/src/main/antlr/collection</sourceDirectory>
+							<outputDirectory>${basedir}/src/main/java/de/ids_mannheim/korap/query/parse/collection</outputDirectory>
+							<libDirectory>${basedir}/src/main/antlr/collection</libDirectory>
+						</configuration>
+						<phase>generate-sources</phase>
+					</execution>
+				</executions>
+			</plugin>
+			<plugin>
+				<!-- This plugin will help to build the ANTLR3 grammar on the fly. The 
+					recipe is based on http://stackoverflow.com/questions/15310628/ customize-maven-to-automatically-create-antlr4-grammar-java-files-on-build -->
+				<groupId>org.antlr</groupId>
+				<artifactId>antlr3-maven-plugin</artifactId>
+				<version>3.5.1</version>
+				<configuration>
+					<sourceDirectory>${basedir}/src/main/antlr/cosmas</sourceDirectory>
+					<outputDirectory>${basedir}/src/main/java/de/ids_mannheim/korap/query/parse/cosmas</outputDirectory>
+					<libDirectory>${basedir}/src/main/antlr</libDirectory>
+				</configuration>
+				<executions>
+					<execution>
+						<goals>
+							<goal>antlr</goal>
+						</goals>
+						<phase>generate-sources</phase>
+					</execution>
+				</executions>
+			</plugin>
+		</plugins>
+	</build>
 </project>
diff --git a/src/main/java/de/ids_mannheim/korap/query/object/KoralBoundary.java b/src/main/java/de/ids_mannheim/korap/query/object/KoralBoundary.java
new file mode 100644
index 0000000..0faee0e
--- /dev/null
+++ b/src/main/java/de/ids_mannheim/korap/query/object/KoralBoundary.java
@@ -0,0 +1,46 @@
+package de.ids_mannheim.korap.query.object;
+
+import java.util.LinkedHashMap;
+import java.util.Map;
+
+public class KoralBoundary implements KoralObject {
+
+    private static final KoralType type = KoralType.BOUNDARY;
+
+    private int min;
+    private int max;
+
+    public KoralBoundary (int min, int max) {
+        this.min = min;
+        this.max = max;
+    }
+
+    public int getMin() {
+        return min;
+    }
+
+    public void setMin(int min) {
+        this.min = min;
+    }
+
+    public int getMax() {
+        return max;
+    }
+
+    public void setMax(int max) {
+        this.max = max;
+    }
+
+    @Override
+    public Map<String, Object> buildMap() {
+        Map<String, Object> map = new LinkedHashMap<String, Object>();
+        map.put("@type", type.toString());
+        if (min > -1) {
+            map.put("min", getMin());
+        }
+        if (max > -1) {
+            map.put("max", getMax());
+        }
+        return map;
+    }
+}
diff --git a/src/main/java/de/ids_mannheim/korap/query/object/KoralGroup.java b/src/main/java/de/ids_mannheim/korap/query/object/KoralGroup.java
index 090ecbc..70d05fc 100644
--- a/src/main/java/de/ids_mannheim/korap/query/object/KoralGroup.java
+++ b/src/main/java/de/ids_mannheim/korap/query/object/KoralGroup.java
@@ -24,6 +24,7 @@
     private List<KoralObject> operands;
     private List<Distance> distances;
     private List<Frame> frames;
+    private KoralBoundary boundary;
 
     public KoralGroup (KoralOperation operation) {
         this.operation = operation;
@@ -61,6 +62,14 @@
 		this.frames = frames;
 	}
 
+    public KoralBoundary getBoundary() {
+        return boundary;
+    }
+
+    public void setBoundary(KoralBoundary boundary) {
+        this.boundary = boundary;
+    }
+
     @Override
     public Map<String, Object> buildMap() {
         Map<String, Object> map = new LinkedHashMap<String, Object>();
@@ -81,6 +90,10 @@
             operandList.add(MapBuilder.buildQueryMap(o));
         }
         map.put("operands", operandList);
+
+        if (boundary != null) {
+            map.put("boundary", boundary.buildMap());
+        }
         return map;
     }
 
@@ -146,8 +159,6 @@
             distanceMap.put("min", getMin());
             distanceMap.put("max", getMax());
             return distanceMap;
-
         }
-
     }
 }
diff --git a/src/main/java/de/ids_mannheim/korap/query/parse/fcsql/FCSSRUQueryParser.java b/src/main/java/de/ids_mannheim/korap/query/parse/fcsql/FCSSRUQueryParser.java
index 85be144..fa440e1 100644
--- a/src/main/java/de/ids_mannheim/korap/query/parse/fcsql/FCSSRUQueryParser.java
+++ b/src/main/java/de/ids_mannheim/korap/query/parse/fcsql/FCSSRUQueryParser.java
@@ -7,6 +7,7 @@
 import de.ids_mannheim.korap.query.object.KoralContext;
 import de.ids_mannheim.korap.query.serialize.util.KoralException;
 import de.ids_mannheim.korap.query.serialize.util.StatusCodes;
+import de.ids_mannheim.korap.query.object.KoralBoundary;
 import de.ids_mannheim.korap.query.object.KoralGroup;
 import de.ids_mannheim.korap.query.object.KoralObject;
 import de.ids_mannheim.korap.query.object.KoralOperation;
@@ -111,12 +112,22 @@
     }
 
     private KoralObject parseQuerySegment(QuerySegment segment) throws KoralException {
-        if ((segment.getMinOccurs() == 1) && (segment.getMaxOccurs() == 1)) {
+        int minOccurs = segment.getMinOccurs();
+        int maxOccurs = segment.getMaxOccurs();
+        
+        if ((minOccurs == 1) && (maxOccurs == 1)) {
             return expressionParser.parseExpression(segment.getExpression());
         }
         else {
-            throw new KoralException(StatusCodes.QUERY_TOO_COMPLEX,
-                    "FCS diagnostic 11: Query is too complex.");
+            KoralBoundary boundary = new KoralBoundary(minOccurs, maxOccurs);
+            List<KoralObject> operand = new ArrayList<KoralObject>(1);
+            operand.add(expressionParser.parseExpression(segment
+                    .getExpression()));
+
+            KoralGroup koralGroup = new KoralGroup(KoralOperation.REPETITION);
+            koralGroup.setBoundary(boundary);
+            koralGroup.setOperands(operand);
+            return koralGroup;
         }
     }
 }
diff --git a/src/test/java/de/ids_mannheim/korap/query/serialize/FCSQLComplexTest.java b/src/test/java/de/ids_mannheim/korap/query/serialize/FCSQLComplexTest.java
index 3973aea..6aedc12 100644
--- a/src/test/java/de/ids_mannheim/korap/query/serialize/FCSQLComplexTest.java
+++ b/src/test/java/de/ids_mannheim/korap/query/serialize/FCSQLComplexTest.java
@@ -38,20 +38,6 @@
         FCSQLQueryProcessorTest
                 .validateNode(query, "/query/operands/1", jsonLd);
 
-        // sequence and disjunction
-        query = "([pos=\"NN\"]|[cnx:pos=\"N\"])[text=\"Mann\"]";
-        jsonLd = "{@type:koral:group,"
-                + "operation:operation:sequence,"
-                + "operands:["
-                + "{@type:koral:group,"
-                + "operation:operation:disjunction,"
-                + "operands:[{@type:koral:token,wrap:{@type:koral:term,key:NN,foundry:tt,layer:p,type:type:regex,match:match:eq}},"
-                + "{@type:koral:token,wrap:{@type:koral:term,key:N,foundry:cnx,layer:p,type:type:regex,match:match:eq}}"
-                + "]},"
-                + "{@type:koral:token,wrap:{@type:koral:term,key:Mann,foundry:opennlp,layer:orth,type:type:regex,match:match:eq}}"
-                + "]}";
-        FCSQLQueryProcessorTest.runAndValidate(query, jsonLd);
-
         // group and sequence
         query = "([text=\"blaue\"][pos=\"NN\"])";
         jsonLd = "{@type:koral:group,"
@@ -94,13 +80,6 @@
                 + "{@type:koral:token, wrap:{@type:koral:term,key:NN,foundry:tt,layer:p,type:type:regex,match:match:eq}},"
                 + "{@type:koral:token, wrap:{@type:koral:term,key:Mann,foundry:opennlp,layer:orth,type:type:regex,match:match:eq}}]}";
         FCSQLQueryProcessorTest.runAndValidate(query, jsonLd);
-
-        query = "[pos=\"NN\"]&[text=\"Mann\"]";
-        List<Object> error = FCSQLQueryProcessorTest
-                .getError(new FCSQLQueryProcessor(query, "2.0"));
-        assertEquals(399, error.get(0));
-        String msg = (String) error.get(1);
-        assertEquals(true, msg.startsWith("FCS diagnostic 10"));
     }
 
     // | simple-query main-query /* sequence */
@@ -123,12 +102,67 @@
         FCSQLQueryProcessorTest
                 .validateNode(query, "/query/operands/1", jsonLd);
 
+        // sequence and disjunction
+        query = "([pos=\"NN\"]|[cnx:pos=\"N\"])[text=\"Mann\"]";
+        jsonLd = "{@type:koral:group,"
+                + "operation:operation:sequence,"
+                + "operands:["
+                + "{@type:koral:group,"
+                + "operation:operation:disjunction,"
+                + "operands:[{@type:koral:token,wrap:{@type:koral:term,key:NN,foundry:tt,layer:p,type:type:regex,match:match:eq}},"
+                + "{@type:koral:token,wrap:{@type:koral:term,key:N,foundry:cnx,layer:p,type:type:regex,match:match:eq}}"
+                + "]},"
+                + "{@type:koral:token,wrap:{@type:koral:term,key:Mann,foundry:opennlp,layer:orth,type:type:regex,match:match:eq}}"
+                + "]}";
+        FCSQLQueryProcessorTest.runAndValidate(query, jsonLd);
+
     }
 
     // | simple-query quantifier /* quatification */
     @Test
     public void testQueryWithQuantifier() throws IOException {
+        // repetition
+        String query = "\"die\"{2}";
+        String jsonLd = "{@type:koral:group,"
+                + "operation:operation:repetition,"
+                + "operands:["
+                + "{@type:koral:token,wrap:{@type:koral:term,key:die,foundry:opennlp,layer:orth,type:type:regex,match:match:eq}}],"
+                + "boundary:{@type:koral:boundary,min:2,max:2}}";
+        FCSQLQueryProcessorTest.runAndValidate(query, jsonLd);
 
+        query = "\"die\"{1,2}";
+        jsonLd = "{@type:koral:boundary,min:1,max:2}";
+        FCSQLQueryProcessorTest.validateNode(query, "/query/boundary", jsonLd);
+
+        query = "\"die\"{,2}";
+        jsonLd = "{@type:koral:boundary,min:0,max:2}";
+        FCSQLQueryProcessorTest.validateNode(query, "/query/boundary", jsonLd);
+
+        query = "\"die\"{2,}";
+        jsonLd = "{@type:koral:boundary,min:2}";
+        FCSQLQueryProcessorTest.validateNode(query, "/query/boundary", jsonLd);
+
+        query = "\"die\"+";
+        jsonLd = "{@type:koral:boundary,min:1}";
+        FCSQLQueryProcessorTest.validateNode(query, "/query/boundary", jsonLd);
+
+        query = "\"die\"?";
+        jsonLd = "{@type:koral:boundary,min:0, max:1}";
+        FCSQLQueryProcessorTest.validateNode(query, "/query/boundary", jsonLd);
+        
+        query = "\"die\"*";
+        jsonLd = "{@type:koral:boundary,min:0}";
+        FCSQLQueryProcessorTest.validateNode(query, "/query/boundary", jsonLd);
+
+        query = "\"die\"{0}";
+        jsonLd = "{@type:koral:boundary,min:0, max:0}";
+        FCSQLQueryProcessorTest.validateNode(query, "/query/boundary", jsonLd);
+    }
+
+    @Test
+    public void testEmptyToken() {
+        // distance query
+        // query = "\"Hund\" []{3} \"Katze\"";
     }
 
     // -------------------------------------------------------------------------
@@ -170,4 +204,32 @@
                 (String) error.get(1));
     }
     
+    @Test
+    public void testWrongQuery() throws IOException {
+        String query = "!(mate:lemma=\"sein\" | mate:pos=\"PPOSS\")";
+        List<Object> error = FCSQLQueryProcessorTest
+                .getError(new FCSQLQueryProcessor(query, "2.0"));
+        assertEquals(399, error.get(0));
+        assertEquals(true,
+                error.get(1).toString().startsWith("FCS diagnostic 10"));
+
+        query = "![mate:lemma=\"sein\" | mate:pos=\"PPOSS\"]";
+        error = FCSQLQueryProcessorTest.getError(new FCSQLQueryProcessor(query,
+                "2.0"));
+        assertEquals(true,
+                error.get(1).toString().startsWith("FCS diagnostic 10"));
+
+        query = "(\"blaue\"&\"grüne\")";
+        error = FCSQLQueryProcessorTest.getError(new FCSQLQueryProcessor(query,
+                "2.0"));
+        assertEquals(true,
+                error.get(1).toString().startsWith("FCS diagnostic 10"));
+
+        query = "[pos=\"NN\"]&[text=\"Mann\"]";
+        error = FCSQLQueryProcessorTest
+                .getError(new FCSQLQueryProcessor(query, "2.0"));
+        assertEquals(399, error.get(0));
+        String msg = (String) error.get(1);
+        assertEquals(true, msg.startsWith("FCS diagnostic 10"));
+    }
 }
diff --git a/src/test/java/de/ids_mannheim/korap/query/serialize/FCSQLQueryProcessorTest.java b/src/test/java/de/ids_mannheim/korap/query/serialize/FCSQLQueryProcessorTest.java
index 7fa90d0..93a130c 100644
--- a/src/test/java/de/ids_mannheim/korap/query/serialize/FCSQLQueryProcessorTest.java
+++ b/src/test/java/de/ids_mannheim/korap/query/serialize/FCSQLQueryProcessorTest.java
@@ -280,24 +280,4 @@
         FCSQLQueryProcessorTest.runAndValidate(query, jsonLd);
     }
 
-
-    @Test
-    public void testWrongQuery() throws IOException {
-        String query = "!(mate:lemma=\"sein\" | mate:pos=\"PPOSS\")";
-        List<Object> error = getError(new FCSQLQueryProcessor(query, "2.0"));
-        assertEquals(399, error.get(0));
-        assertEquals(true,
-                error.get(1).toString().startsWith("FCS diagnostic 10"));
-
-        query = "![mate:lemma=\"sein\" | mate:pos=\"PPOSS\"]";
-        error = getError(new FCSQLQueryProcessor(query, "2.0"));
-        assertEquals(true,
-                error.get(1).toString().startsWith("FCS diagnostic 10"));
-
-        query = "(\"blaue\"&\"grüne\")";
-        error = getError(new FCSQLQueryProcessor(query, "2.0"));
-        assertEquals(true,
-                error.get(1).toString().startsWith("FCS diagnostic 10"));
-    }
-
 }