devicemap-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From re...@apache.org
Subject svn commit: r1693381 - in /devicemap/trunk/clients/2.0/reference/src: DeviceMapClient.java JsonFile.java Main.java Pattern.java TransformerReplaceAll.java
Date Thu, 30 Jul 2015 01:37:43 GMT
Author: rezan
Date: Thu Jul 30 01:37:42 2015
New Revision: 1693381

URL: http://svn.apache.org/r1693381
Log:
comments and minor cleanup

Modified:
    devicemap/trunk/clients/2.0/reference/src/DeviceMapClient.java
    devicemap/trunk/clients/2.0/reference/src/JsonFile.java
    devicemap/trunk/clients/2.0/reference/src/Main.java
    devicemap/trunk/clients/2.0/reference/src/Pattern.java
    devicemap/trunk/clients/2.0/reference/src/TransformerReplaceAll.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=1693381&r1=1693380&r2=1693381&view=diff
==============================================================================
--- devicemap/trunk/clients/2.0/reference/src/DeviceMapClient.java (original)
+++ devicemap/trunk/clients/2.0/reference/src/DeviceMapClient.java Thu Jul 30 01:37:42 2015
@@ -76,9 +76,13 @@ public class DeviceMapClient {
     Main.log("Loading pattern domain: " + patternFile.getDomain() + ", version: " +
         patternFile.getDomainVersion() + (patch ? ", patch" : ""), 1);
 
+    //INPUT PARSER
+
     if(JsonFile.get(patternFile.getJsonNode(), "inputParser").isObject()) {
       JsonNode inputParser = patternFile.getJsonNode().get("inputParser");
 
+      //TRANSFORMERS
+
       if(JsonFile.get(inputParser, "transformers").isArray()) {
         if(patch) {
           transformers = new ArrayList<>();
@@ -97,6 +101,8 @@ public class DeviceMapClient {
 
       Main.log("Found " + transformers.size() + " transformer(s)", 1);
 
+      //TOKEN SEPERATORS
+
       if(JsonFile.get(inputParser, "tokenSeperators").isArray()) {
         if(patch) {
           tokenSeperators = new ArrayList<>();
@@ -119,6 +125,8 @@ public class DeviceMapClient {
 
       Main.log("Found " + tokenSeperators.size() + " tokenSeperator(s)", 1);
 
+      //NGRAM SIZE
+
       if(inputParser.get("ngramConcatSize") != null) {
         String ngramConcatSizeStr = inputParser.get("ngramConcatSize").asText();
         ngramConcatSize = Integer.parseInt(ngramConcatSizeStr);
@@ -131,6 +139,8 @@ public class DeviceMapClient {
       }
     }
 
+    //PATTERN SET
+
     if(JsonFile.get(patternFile.getJsonNode(), "patternSet").isObject()) {
       JsonNode patternSet = patternFile.getJsonNode().get("patternSet");
 
@@ -151,6 +161,8 @@ public class DeviceMapClient {
         patterns = new HashMap<>(simpleHashCount);
       }
 
+      //PATTERNS
+
       if(JsonFile.get(patternSet, "patterns").isArray()) {
         for(Iterator<JsonNode> i = patternSet.get("patterns").iterator(); i.hasNext();)
{
           JsonNode patternNode = i.next();
@@ -192,6 +204,8 @@ public class DeviceMapClient {
 
     Main.log("Loading attributes: " + attributes.getDomain() + ", version: " + attributes.getDomainVersion(),
1);
 
+    //ATTRIBUTES
+
     int attributeCount = 0;
 
     if(JsonFile.get(attributes.getJsonNode(), "attributes").isArray()) {
@@ -213,6 +227,8 @@ public class DeviceMapClient {
             }
           }
 
+          //ATTRIBUTE TRANFORMERS
+
           if(JsonFile.get(attribute, "attributeTransformers").isArray()) {
             for(Iterator<JsonNode> j = attribute.get("attributeTransformers").iterator();
j.hasNext();) {
               JsonNode attributeTransformer = j.next();
@@ -260,6 +276,8 @@ public class DeviceMapClient {
 
     Main.log("Classify: '" + text + "'", 2);
 
+    //TRANFORM THE INPUT
+
     String transformed = text;
 
     for(Transformer transformer : transformers) {
@@ -268,7 +286,8 @@ public class DeviceMapClient {
 
     Main.log("Transformed: '" + transformed + "'", 3);
 
-    //tokenization
+    //TOKENIZE THE INPUT
+
     List<String> tokens = new ArrayList<>();
 
     String source = transformed;
@@ -308,6 +327,8 @@ public class DeviceMapClient {
 
     Main.log("Tokens: " + tokens, 3);
 
+    //NGRAM THE INPUT
+
     List<String> ngramTokenStream = new ArrayList<>();
 
     for(int i = 0; i < tokens.size(); i++) {
@@ -327,6 +348,8 @@ public class DeviceMapClient {
 
     Main.log("Ngrams: " + ngramTokenStream, 3);
 
+    //MATCH THE TOKEN STREAM AGAINST THE PATTERNS
+
     List<String> matchedTokens = new ArrayList<>();
     List<Pattern> candidates = new ArrayList<>();
     Pattern winner = null;
@@ -352,6 +375,8 @@ public class DeviceMapClient {
       }
     }
 
+    //FIND THE WINNER
+
     if(winner == null) {
       for(Pattern candidate : candidates) {
         if(candidate.isValid(matchedTokens)) {
@@ -365,6 +390,8 @@ public class DeviceMapClient {
     
     Main.log("Winner: " + (winner == null ? "null" : winner.toStringFull()), 3);
 
+    //RETURN THE RESULT
+
     if(winner == null) {
       if(defaultId != null) {
         return defaultId;

Modified: devicemap/trunk/clients/2.0/reference/src/JsonFile.java
URL: http://svn.apache.org/viewvc/devicemap/trunk/clients/2.0/reference/src/JsonFile.java?rev=1693381&r1=1693380&r2=1693381&view=diff
==============================================================================
--- devicemap/trunk/clients/2.0/reference/src/JsonFile.java (original)
+++ devicemap/trunk/clients/2.0/reference/src/JsonFile.java Thu Jul 30 01:37:42 2015
@@ -43,15 +43,15 @@ public class JsonFile {
       throw new Exception("Bad specVersion found: " + json.get("specVersion").asDouble(0d));
     }
 
-    if(json.get("type") == null || json.get("type").asText().isEmpty()) {
+    if(empty(json, "type")) {
       throw new Exception("type not defined");
     }
 
-    if(json.get("domain") == null || json.get("domain").asText().isEmpty()) {
+    if(empty(json, "domain")) {
       throw new Exception("domain not defined");
     }
 
-    if(json.get("domainVersion") == null || json.get("domainVersion").asText().isEmpty())
{
+    if(empty(json, "domainVersion")) {
       throw new Exception("domainVersion not defined");
     }
 
@@ -75,6 +75,10 @@ public class JsonFile {
     return nullNode;
   }
 
+  public static boolean empty(JsonNode node, String name) {
+    return (node.get(name) == null || node.get(name).asText().isEmpty());
+  }
+
   public String getType() {
     return type;
   }

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=1693381&r1=1693380&r2=1693381&view=diff
==============================================================================
--- devicemap/trunk/clients/2.0/reference/src/Main.java (original)
+++ devicemap/trunk/clients/2.0/reference/src/Main.java Thu Jul 30 01:37:42 2015
@@ -39,6 +39,8 @@ public class Main {
 
     boolean failure = false;
 
+    //PARSE THE COMMAND LINE
+
     for(int i = 0; i < args.length; i++) {
       String option = args[i];
 
@@ -70,6 +72,8 @@ public class Main {
       throw new Exception("Pattern file required");
     }
 
+    //BUILD THE DEVICEMAP CLIENT
+
     for(String pattern : patterns) {
       log("Pattern file: '" + pattern + "'", 0);
       client.loadPatterns(new JsonFile(pattern));
@@ -80,6 +84,8 @@ public class Main {
       client.loadAttributes(new JsonFile(attribute));
     }
 
+    //DO THE TESTS
+
     for(String test : tests) {
       log("Test file: '" + test + "'", 0);
       failure |= test(client, new JsonFile(test));
@@ -146,6 +152,8 @@ public class Main {
     int testCount = 0;
     int passCount = 0;
 
+    //ITERATE THRU THE TESTS
+    
     if(JsonFile.get(tests.getJsonNode(), "tests").isArray()) {
         for(Iterator<JsonNode> i = tests.getJsonNode().get("tests").iterator(); i.hasNext();)
{
           JsonNode test = i.next();

Modified: devicemap/trunk/clients/2.0/reference/src/Pattern.java
URL: http://svn.apache.org/viewvc/devicemap/trunk/clients/2.0/reference/src/Pattern.java?rev=1693381&r1=1693380&r2=1693381&view=diff
==============================================================================
--- devicemap/trunk/clients/2.0/reference/src/Pattern.java (original)
+++ devicemap/trunk/clients/2.0/reference/src/Pattern.java Thu Jul 30 01:37:42 2015
@@ -45,7 +45,7 @@ public class Pattern {
 
     patternId = json.get("patternId").asText();
 
-    if(json.get("patternType") == null || json.get("patternType").asText().isEmpty()) {
+    if(JsonFile.empty(json, "patternType")) {
       throw new Exception("patternType not found in " + patternId);
     }
 
@@ -53,7 +53,7 @@ public class Pattern {
       throw new Exception("patternTokens array not found in " + patternId);
     }
 
-    if(json.get("rankType") == null || json.get("rankType").asText().isEmpty()) {
+    if(JsonFile.empty(json, "rankType")) {
       throw new Exception("rankType not found in " + patternId);
     }
 

Modified: devicemap/trunk/clients/2.0/reference/src/TransformerReplaceAll.java
URL: http://svn.apache.org/viewvc/devicemap/trunk/clients/2.0/reference/src/TransformerReplaceAll.java?rev=1693381&r1=1693380&r2=1693381&view=diff
==============================================================================
--- devicemap/trunk/clients/2.0/reference/src/TransformerReplaceAll.java (original)
+++ devicemap/trunk/clients/2.0/reference/src/TransformerReplaceAll.java Thu Jul 30 01:37:42
2015
@@ -24,7 +24,7 @@ public class TransformerReplaceAll imple
   private final String replaceWith;
 
   public TransformerReplaceAll(JsonNode json) throws Exception {
-    if(json.get("find") == null || json.get("find").asText().isEmpty()) {
+    if(JsonFile.empty(json, "find")) {
       throw new Exception("ReplaceAll find not defined");
     }
 



Mime
View raw message