refactoring!
diff --git a/pom.xml b/pom.xml
index e033deb..e4b88f2 100644
--- a/pom.xml
+++ b/pom.xml
@@ -1,88 +1,84 @@
<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>
- <parent>
- <groupId>KorAP-modules</groupId>
- <artifactId>KorAP-core-modules</artifactId>
- <version>1.0</version>
- </parent>
-
- <groupId>KorAP-modules</groupId>
- <artifactId>KorAP-querySerialization</artifactId>
- <version>0.0.2</version>
- <packaging>jar</packaging>
+ 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>
+ <parent>
+ <groupId>KorAP-modules</groupId>
+ <artifactId>KorAP-core-modules</artifactId>
+ <version>1.1</version>
+ </parent>
+
+ <groupId>KorAP-modules</groupId>
+ <artifactId>KorAP-querySerialization</artifactId>
+ <version>0.0.2</version>
+ <packaging>jar</packaging>
- <name>KorAP-querySerialization</name>
- <url>http://maven.apache.org</url>
+ <name>KorAP-querySerialization</name>
+ <url>http://maven.apache.org</url>
- <properties>
- <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
- </properties>
-
- <dependencies>
- <dependency>
- <groupId>org.antlr</groupId>
- <artifactId>antlr4-runtime</artifactId>
- <version>4.0</version>
- </dependency>
- <dependency>
- <groupId>com.google.guava</groupId>
- <artifactId>guava</artifactId>
- <version>15.0</version>
- </dependency>
- <dependency>
- <groupId>com.fasterxml.jackson.core</groupId>
- <artifactId>jackson-databind</artifactId>
- <version>2.2.2</version>
- </dependency>
- <dependency>
- <groupId>KorAP-modules</groupId>
- <artifactId>KorAP-PoliqarpParser</artifactId>
- <version>0.05</version>
- </dependency>
- <dependency>
- <groupId>KorAP-modules</groupId>
- <artifactId>KorAP-Cosmas2Parser</artifactId>
- <version>LATEST</version>
- </dependency>
- <dependency>
- <groupId>KorAP-modules</groupId>
- <artifactId>KorAP-lucene-index</artifactId>
- <version>LATEST</version>
- </dependency>
- <dependency>
- <groupId>junit</groupId>
- <artifactId>junit</artifactId>
- <version>4.11</version>
- <scope>test</scope>
- </dependency>
- <dependency>
- <groupId>joda-time</groupId>
- <artifactId>joda-time</artifactId>
- <version>2.2</version>
- </dependency>
- <dependency>
- <groupId>commons-lang</groupId>
- <artifactId>commons-lang</artifactId>
- <version>2.6</version>
- </dependency>
- </dependencies>
- <build>
- <sourceDirectory>${basedir}/src/main/java</sourceDirectory>
- <outputDirectory>${basedir}/bin</outputDirectory>
- <plugins>
- <plugin>
- <artifactId>maven-compiler-plugin</artifactId>
- <version>2.3.2</version>
- <configuration>
- <source>1.7</source>
- <target>1.7</target>
- <!-- excludes>
- <exclude>**/CosmasTree.java</exclude>
- </excludes -->
- </configuration>
- </plugin>
- </plugins>
- </build>
+ <dependencies>
+ <dependency>
+ <groupId>org.antlr</groupId>
+ <artifactId>antlr4-runtime</artifactId>
+ <version>4.0</version>
+ </dependency>
+ <dependency>
+ <groupId>com.google.guava</groupId>
+ <artifactId>guava</artifactId>
+ <version>15.0</version>
+ </dependency>
+ <dependency>
+ <groupId>com.fasterxml.jackson.core</groupId>
+ <artifactId>jackson-databind</artifactId>
+ <version>2.2.2</version>
+ </dependency>
+ <dependency>
+ <groupId>KorAP-modules</groupId>
+ <artifactId>KorAP-PoliqarpParser</artifactId>
+ <version>0.05</version>
+ </dependency>
+ <dependency>
+ <groupId>KorAP-modules</groupId>
+ <artifactId>KorAP-Cosmas2Parser</artifactId>
+ <version>LATEST</version>
+ </dependency>
+ <dependency>
+ <groupId>KorAP-modules</groupId>
+ <artifactId>KorAP-lucene-index</artifactId>
+ <version>LATEST</version>
+ </dependency>
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <version>4.11</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>joda-time</groupId>
+ <artifactId>joda-time</artifactId>
+ <version>2.2</version>
+ </dependency>
+ <dependency>
+ <groupId>commons-lang</groupId>
+ <artifactId>commons-lang</artifactId>
+ <version>2.6</version>
+ </dependency>
+ </dependencies>
+ <build>
+ <sourceDirectory>${basedir}/src/main/java</sourceDirectory>
+ <outputDirectory>${basedir}/bin</outputDirectory>
+ <plugins>
+ <plugin>
+ <artifactId>maven-compiler-plugin</artifactId>
+ <version>2.3.2</version>
+ <configuration>
+ <source>1.7</source>
+ <target>1.7</target>
+ <!-- excludes>
+ <exclude>**/CosmasTree.java</exclude>
+ </excludes -->
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
</project>
diff --git a/src/main/java/LayerTranslator.java b/src/main/java/LayerTranslator.java
new file mode 100644
index 0000000..5ab9783
--- /dev/null
+++ b/src/main/java/LayerTranslator.java
@@ -0,0 +1,33 @@
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * @author hanl
+ * @date 24/01/2014
+ */
+public class LayerTranslator {
+
+ //fixme: standardize
+ private String[] bases = new String[]{"morph", "lemma", "mds", "dep"};
+ private Map<String, String> mapper;
+
+
+ public LayerTranslator() {
+ mapper = new HashMap<>();
+ }
+
+ public void set(String m, String l, String mds, String dep) {
+ mapper.clear();
+ mapper.put(bases[0], m);
+ mapper.put(bases[1], l);
+ mapper.put(bases[2], mds);
+ mapper.put(bases[3], dep);
+ }
+
+ public String translate(String base) {
+ String r = mapper.get(base);
+ if (r != null)
+ return r;
+ return "";
+ }
+}
diff --git a/src/main/java/de/ids_mannheim/korap/query/serialize/MetaQuery.java b/src/main/java/de/ids_mannheim/korap/query/serialize/CollectionQuery.java
similarity index 88%
rename from src/main/java/de/ids_mannheim/korap/query/serialize/MetaQuery.java
rename to src/main/java/de/ids_mannheim/korap/query/serialize/CollectionQuery.java
index 2d81800..ed1d5ef 100644
--- a/src/main/java/de/ids_mannheim/korap/query/serialize/MetaQuery.java
+++ b/src/main/java/de/ids_mannheim/korap/query/serialize/CollectionQuery.java
@@ -15,7 +15,7 @@
* @author hanl
* @date 06/12/2013
*/
-public class MetaQuery {
+public class CollectionQuery {
private JsonFactory factory;
private MetaTypes types;
@@ -24,7 +24,7 @@
private List<Map> mfil;
private List<Map> mext;
- public MetaQuery() {
+ public CollectionQuery() {
this.serialzer = new ObjectMapper();
this.rq = new ArrayList<>();
this.mfil = new ArrayList<>();
@@ -33,7 +33,7 @@
this.types = new MetaTypes();
}
- public MetaQuery addResource(String query) {
+ public CollectionQuery addResource(String query) {
try {
JsonParser jp = factory.createParser(query);
JsonNode m = jp.readValueAsTree();
@@ -46,7 +46,7 @@
return this;
}
- public MetaQuery addResources(List<String> queries) {
+ public CollectionQuery addResources(List<String> queries) {
for (String query : queries)
addResource(query);
return this;
@@ -90,7 +90,6 @@
value.add(group);
}
-
for (int i = idx; i < dates.length; i++) {
if (dates[i] != null) {
Map term1 = types.createTerm(dates[i], "korap:date");
@@ -101,8 +100,9 @@
return value;
}
- // map can only have one key, value pair. thus, text class can only be added once. Multiple types are not possible!
- public MetaQuery addMetaFilter(String queries) {
+ // fixme: map can only have one key/value pair. thus,
+ // text class can only be added once. Multiple types are not possible!
+ public CollectionQuery addMetaFilter(String queries) {
Multimap<String, String> m = resEq(queries);
boolean multypes = m.keys().size() > 1;
String def_key = null;
@@ -125,7 +125,7 @@
return this;
}
- public MetaQuery addMetaExtend(String queries) {
+ public CollectionQuery addMetaExtend(String queries) {
Multimap<String, String> m = resEq(queries);
boolean multypes = m.keys().size() > 1;
String def_key = null;
@@ -148,18 +148,17 @@
return this;
}
- public MetaQuery addMetaFilter(String attr, String val) {
+ public CollectionQuery addMetaFilter(String attr, String val) {
return addMetaFilter(attr + ":" + val);
}
- public MetaQuery addMetaExtend(String attr, String val) {
+ public CollectionQuery addMetaExtend(String attr, String val) {
return addMetaExtend(attr + ":" + val);
}
private String[] processDates(List<String> dates) {
if (dates.isEmpty())
return new String[3];
- boolean range = false;
String[] el = new String[dates.size() + 3];
int idx = 3;
for (String value : dates) {
@@ -192,7 +191,7 @@
return cursor;
}
- private List<Map> getMetaOnly() {
+ private List<Map> getCollectionsOnly() {
List<Map> cursor = new ArrayList<>(this.mfil);
cursor.addAll(this.mext);
return cursor;
@@ -204,7 +203,7 @@
* @return
*/
public String stringify() {
- List meta = getMetaOnly();
+ List meta = getCollectionsOnly();
if (meta.isEmpty())
return "";
@@ -236,9 +235,9 @@
*
* @return
*/
- public String toMeta() {
+ public String toCollections() {
Map meta = new LinkedHashMap();
- meta.put("meta", join());
+ meta.put("collections", join());
try {
return serialzer.writeValueAsString(meta);
@@ -250,11 +249,12 @@
/**
* resolves all queries as equal (hierarchy) AND relations
+ *
* @param queries
* @return
*/
private Multimap<String, String> resEq(String queries) {
- Multimap<String, String> qmap = ArrayListMultimap.create();
+ Multimap<String, String> qmap = ArrayListMultimap.create();
String[] spl = queries.split(" AND ");
for (String query : spl) {
String[] q = query.split(":");
@@ -263,7 +263,17 @@
qmap.put(attr, val);
}
return qmap;
+ }
+
+ /**
+ * resolves query string with AND and OR relations alike!
+ *
+ * @param queries
+ * @return
+ */
+ private Multimap<String, String> resDep(String queries) {
+ return null;
}
diff --git a/src/main/java/de/ids_mannheim/korap/query/serialize/CosmasTree.java b/src/main/java/de/ids_mannheim/korap/query/serialize/CosmasTree.java
index a02450f..a772a5c 100644
--- a/src/main/java/de/ids_mannheim/korap/query/serialize/CosmasTree.java
+++ b/src/main/java/de/ids_mannheim/korap/query/serialize/CosmasTree.java
@@ -27,7 +27,7 @@
*/
public class CosmasTree extends AbstractSyntaxTree {
- Logger log = LoggerFactory.getLogger(CosmasTree.class);
+ private static Logger log = LoggerFactory.getLogger(CosmasTree.class);
private static c2psParser cosmasParser;
/*
diff --git a/src/main/java/de/ids_mannheim/korap/query/serialize/MetaTypes.java b/src/main/java/de/ids_mannheim/korap/query/serialize/MetaTypes.java
index 628c777..1a3b07b 100644
--- a/src/main/java/de/ids_mannheim/korap/query/serialize/MetaTypes.java
+++ b/src/main/java/de/ids_mannheim/korap/query/serialize/MetaTypes.java
@@ -94,12 +94,4 @@
return mapper.readValue(s, Map.class);
}
- public List listify(String s) throws IOException {
- return mapper.readValue(s, LinkedList.class);
- }
-
- public String stringify(Map m) throws JsonProcessingException {
- return mapper.writeValueAsString(m);
- }
-
}
diff --git a/src/main/java/de/ids_mannheim/korap/query/serialize/QuerySerializer.java b/src/main/java/de/ids_mannheim/korap/query/serialize/QuerySerializer.java
index 71ca9ad..3252c0f 100644
--- a/src/main/java/de/ids_mannheim/korap/query/serialize/QuerySerializer.java
+++ b/src/main/java/de/ids_mannheim/korap/query/serialize/QuerySerializer.java
@@ -130,11 +130,11 @@
throw new QueryException(ql + " is not a supported query language!");
}
Map<String, Object> requestMap = ast.getRequestMap();
- MetaQuery metaQuery = new MetaQuery();
- metaQuery.addResources(parents);
+ CollectionQuery collectionQuery = new CollectionQuery();
+ collectionQuery.addResources(parents);
try {
- requestMap.put("meta", metaQuery.raw());
+ requestMap.put("meta", collectionQuery.raw());
requestMap = QueryUtils.addParameters(requestMap, page, num,
cli, cri, cls, crs, cutoff);
String res = mapper.writeValueAsString(requestMap);