You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@devicemap.apache.org by re...@apache.org on 2015/07/29 20:54:18 UTC
svn commit: r1693332 - in /devicemap/trunk/clients/2.0/reference/src:
DeviceMapClient.java Main.java
Author: rezan
Date: Wed Jul 29 18:54:17 2015
New Revision: 1693332
URL: http://svn.apache.org/r1693332
Log:
better verbose logging
Modified:
devicemap/trunk/clients/2.0/reference/src/DeviceMapClient.java
devicemap/trunk/clients/2.0/reference/src/Main.java
Modified: devicemap/trunk/clients/2.0/reference/src/DeviceMapClient.java
URL: http://svn.apache.org/viewvc/devicemap/trunk/clients/2.0/reference/src/DeviceMapClient.java?rev=1693332&r1=1693331&r2=1693332&view=diff
==============================================================================
--- devicemap/trunk/clients/2.0/reference/src/DeviceMapClient.java (original)
+++ devicemap/trunk/clients/2.0/reference/src/DeviceMapClient.java Wed Jul 29 18:54:17 2015
@@ -71,7 +71,7 @@ public class DeviceMapClient {
}
Main.log(" Loading pattern domain: " + patterns.getDomain() + ", version: " +
- patterns.getDomainVersion() + (patch ? ", patch" : ""));
+ patterns.getDomainVersion() + (patch ? ", patch" : ""), 1);
if(get(patterns.getJsonNode(), "inputParser").isObject()) {
JsonNode inputParser = patterns.getJsonNode().get("inputParser");
@@ -86,10 +86,12 @@ public class DeviceMapClient {
transformers.add(getTransformer(transformer));
- Main.log(" Found transformer: " + transformer.get("type"));
+ Main.log(" Found transformer: " + transformer.get("type"), 2);
}
}
+ Main.log(" Found " + transformers.size() + " transformer(s)", 1);
+
if(get(inputParser, "tokenSeperators").isArray()) {
if(patch) {
tokenSeperators = new ArrayList<byte[]>();
@@ -104,14 +106,16 @@ public class DeviceMapClient {
tokenSeperators.add(tokenSeperator.asText().getBytes());
- Main.log(" Found tokenSeperator: '" + tokenSeperator.asText() + "'");
+ Main.log(" Found tokenSeperator: '" + tokenSeperator.asText() + "'", 2);
}
}
+ Main.log(" Found " + tokenSeperators.size() + " tokenSeperator(s)", 1);
+
if(get(inputParser, "ngramConcatSize").asInt(0) > 0) {
ngramConcatSize = inputParser.get("ngramConcatSize").asInt(0);
- Main.log(" Found ngramConcatSize: " + ngramConcatSize);
+ Main.log(" Found ngramConcatSize: " + ngramConcatSize, 2);
}
}
@@ -121,20 +125,28 @@ public class DeviceMapClient {
if(get(patternSet, "defaultId").isTextual()) {
defaultId = patternSet.get("defaultId").asText();
- Main.log(" Found defaultId: " + defaultId);
+ Main.log(" Found defaultId: " + defaultId, 2);
}
int patternCount = 0;
if(get(patternSet, "patterns").isArray()) {
for(Iterator<JsonNode> i = patternSet.get("patterns").iterator(); i.hasNext();) {
- JsonNode tokenSeperator = i.next();
+ JsonNode pattern = i.next();
+
+ if(get(pattern, "patternId").asText().isEmpty()) {
+ throw new Exception("Bad patternId found, position: " + patternCount);
+ }
+
+ String patternId = pattern.get("patternId").asText();
+
+ Main.log(" patternId: " + patternId, 3);
patternCount++;
}
-
- Main.log(" Found " + patternCount + " pattern(s)");
}
+
+ Main.log(" Found " + patternCount + " pattern(s)", 1);
}
}
@@ -151,7 +163,7 @@ public class DeviceMapClient {
throw new Exception("DomainVersions do not match: " + domainVersion + " != " + attributes.getDomainVersion());
}
- Main.log(" Loading attributes: " + attributes.getDomain() + ", version: " + attributes.getDomainVersion());
+ Main.log(" Loading attributes: " + attributes.getDomain() + ", version: " + attributes.getDomainVersion(), 1);
int attributeCount = 0;
@@ -160,11 +172,13 @@ public class DeviceMapClient {
JsonNode attribute = i.next();
if(get(attribute, "patternId").asText().isEmpty()) {
- throw new Exception("Bad patternId found, position: " + attributeCount);
+ throw new Exception("Bad attribute patternId found, position: " + attributeCount);
}
String patternId = attribute.get("patternId").asText();
+ Main.log(" Attribute patternId: " + patternId, 3);
+
if(get(attribute, "attributes").isObject()) {
for(Iterator<String> j = attribute.get("attributes").getFieldNames(); j.hasNext();) {
String key = j.next();
@@ -192,9 +206,9 @@ public class DeviceMapClient {
attributeCount++;
}
-
- Main.log(" Found " + attributeCount + " attributes(s)");
}
+
+ Main.log(" Found " + attributeCount + " attributes(s)", 1);
}
public static JsonNode get(JsonNode node, String name) throws Exception {
@@ -232,7 +246,7 @@ public class DeviceMapClient {
text = "";
}
- Main.log(" Classify: '" + text + "'");
+ Main.log(" Classify: '" + text + "'", 2);
String transformed = text;
@@ -240,7 +254,7 @@ public class DeviceMapClient {
transformed = transformer.transform(transformed);
}
- Main.log(" Transformed: '" + transformed + "'");
+ Main.log(" Transformed: '" + transformed + "'", 2);
//tokenization using bytes
List<String> tokens = new ArrayList<String>();
@@ -280,7 +294,7 @@ public class DeviceMapClient {
tokens.add(new String(dest, 0, destPos));
}
- Main.log(" Tokens: " + tokens);
+ Main.log(" Tokens: " + tokens, 2);
List<String> ngrams = new ArrayList<String>();
@@ -299,7 +313,7 @@ public class DeviceMapClient {
ngramParts.clear();
}
- Main.log(" Ngrams: " + ngrams);
+ Main.log(" Ngrams: " + ngrams, 2);
return "";
}
Modified: devicemap/trunk/clients/2.0/reference/src/Main.java
URL: http://svn.apache.org/viewvc/devicemap/trunk/clients/2.0/reference/src/Main.java?rev=1693332&r1=1693331&r2=1693332&view=diff
==============================================================================
--- devicemap/trunk/clients/2.0/reference/src/Main.java (original)
+++ devicemap/trunk/clients/2.0/reference/src/Main.java Wed Jul 29 18:54:17 2015
@@ -24,10 +24,10 @@ import org.codehaus.jackson.JsonNode;
public class Main {
- private static boolean verbose = true;
+ private static int verbose = 1;
public static void main(String args[]) throws Exception {
- System.out.println("DeviceMap Reference Client " + DeviceMapClient.VERSION);
+ log("DeviceMap Reference Client " + DeviceMapClient.VERSION, 0);
DeviceMapClient client = new DeviceMapClient();
@@ -54,7 +54,11 @@ public class Main {
} else if(!option.startsWith("-") && testString == null) {
testString = option;
} else if(option.equals("-q")) {
- verbose = false;
+ verbose = 0;
+ } else if(option.equals("-v")) {
+ verbose = 2;
+ } else if(option.equals("-vv")) {
+ verbose = 3;
} else {
printHelp();
throw new Exception("unknown option: " + option);
@@ -67,22 +71,22 @@ public class Main {
}
for(String pattern : patterns) {
- Main.log("Pattern file: '" + pattern + "'");
+ log("Pattern file: '" + pattern + "'", 1);
client.loadPatterns(new JsonFile(pattern));
}
for(String attribute : attributes) {
- Main.log("Attribute file: '" + attribute + "'");
+ log("Attribute file: '" + attribute + "'", 1);
client.loadAttributes(new JsonFile(attribute));
}
for(String test : tests) {
- Main.log("Test file: '" + test + "'");
+ log("Test file: '" + test + "'", 1);
failure |= test(client, new JsonFile(test));
}
if(testString != null) {
- Main.log("Test string: '" + testString + "'");
+ log("Test string: '" + testString + "'", 1);
String result = client.classify(testString);
}
@@ -92,14 +96,15 @@ public class Main {
}
private static void printHelp() {
- System.out.println("Usage: " + Main.class.getName() + " [OPTIONS] [STRING]\n");
- System.out.println(" -p <file> load DeviceMap 2.0 pattern file (REQUIRED)");
- System.out.println(" -a <file> load DeviceMap 2.0 attribute file");
- System.out.println(" -t <file> load DeviceMap 2.0 test file");
- System.out.println(" -h print help");
- System.out.println(" -q quiet");
- System.out.println(" STRING test string");
- System.out.println("");
+ log("Usage: " + Main.class.getName() + " [OPTIONS] [STRING]\n", 0);
+ log(" -p <file> load DeviceMap 2.0 pattern file (REQUIRED)", 0);
+ log(" -a <file> load DeviceMap 2.0 attribute file", 0);
+ log(" -t <file> load DeviceMap 2.0 test file", 0);
+ log(" -h print help", 0);
+ log(" -q quiet", 0);
+ log(" -v[v] verbose", 0);
+ log(" STRING test string", 0);
+ log("", 0);
}
private static String getParam(String args[], int pos, String error) throws Exception {
@@ -112,8 +117,8 @@ public class Main {
}
}
- public static void log(String s) {
- if(verbose) {
+ public static void log(String s, int level) {
+ if(level <= verbose) {
System.out.println(s);
}
}
@@ -131,7 +136,7 @@ public class Main {
throw new Exception("DomainVersions do not match: " + client.getDomainVersion() + " != " + tests.getDomainVersion());
}
- Main.log(" Loading test: " + tests.getDomain() + ", version: " + tests.getDomainVersion());
+ log(" Loading test: " + tests.getDomain() + ", version: " + tests.getDomainVersion(), 1);
int testCount = 0;
int passCount = 0;
@@ -168,7 +173,7 @@ public class Main {
}
}
- System.out.println("Test passed " + passCount + " out of " + testCount + ". " + (testCount == passCount ? "PASS" : "FAIL"));
+ log("Test passed " + passCount + " out of " + testCount + ". " + (testCount == passCount ? "PASS" : "FAIL"), 0);
return testCount != passCount;
}