Author: rezan
Date: Thu Jul 30 20:46:53 2015
New Revision: 1693496
URL: http://svn.apache.org/r1693496
Log:
comments
Modified:
devicemap/trunk/clients/2.0/reference/src/AttributeTransformer.java
devicemap/trunk/clients/2.0/reference/src/Attributes.java
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
Modified: devicemap/trunk/clients/2.0/reference/src/AttributeTransformer.java
URL:
http://svn.apache.org/viewvc/devicemap/trunk/clients/2.0/reference/src/AttributeTransformer.java?rev=1693496&r1=1693495&r2=1693496&view=diff
==============================================================================
--- devicemap/trunk/clients/2.0/reference/src/AttributeTransformer.java
(original)
+++ devicemap/trunk/clients/2.0/reference/src/AttributeTransformer.java Thu Jul
30 20:46:53 2015
@@ -27,6 +27,9 @@ public class AttributeTransformer {
private final List<Transformer> transformers;
public AttributeTransformer(JsonNode json) throws Exception {
+
+ //PARSE ATTRIBUTE TRANSFORMER JSON
+
String defaultValueStr = "";
if(!JsonFile.empty(json, "defaultValue")) {
@@ -36,6 +39,8 @@ public class AttributeTransformer {
defaultValue = defaultValueStr;
transformers = new ArrayList<>();
+ //PARSE TRANSFORMER LIST
+
if(JsonFile.get(json, "transformers").isArray()) {
for(int k = 0; k < json.get("transformers").size(); k++) {
JsonNode transformerNode = json.get("transformers").get(k);
@@ -52,6 +57,9 @@ public class AttributeTransformer {
}
public String getValue(String input) throws Exception {
+
+ //TRANSFORM INPUT
+
for(Transformer transformer : transformers) {
input = transformer.transform(input);
}
Modified: devicemap/trunk/clients/2.0/reference/src/Attributes.java
URL:
http://svn.apache.org/viewvc/devicemap/trunk/clients/2.0/reference/src/Attributes.java?rev=1693496&r1=1693495&r2=1693496&view=diff
==============================================================================
--- devicemap/trunk/clients/2.0/reference/src/Attributes.java (original)
+++ devicemap/trunk/clients/2.0/reference/src/Attributes.java Thu Jul 30
20:46:53 2015
@@ -31,6 +31,9 @@ public class Attributes {
private final Map<String, AttributeTransformer> attributeTransformers;
public Attributes(JsonNode json) throws Exception {
+
+ //PARSE ATTRIBUTE JSON
+
if(JsonFile.empty(json, "patternId")) {
throw new Exception("Bad attribute patternId found");
}
@@ -39,7 +42,7 @@ public class Attributes {
parentId = (JsonFile.empty(json, "parentId") ? null :
json.get("parentId").asText());
attributeTransformers = new HashMap<>();
- //ATTRIBUTES
+ //ATTRIBUTE MAP
Map<String, String> attributeMap = new HashMap<>();
@@ -75,6 +78,9 @@ public class Attributes {
}
public Map<String, String> getAttributes(String input) {
+
+ //RETURN MAP
+
if(attributeTransformers.isEmpty()) {
return attributes;
}
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=1693496&r1=1693495&r2=1693496&view=diff
==============================================================================
--- devicemap/trunk/clients/2.0/reference/src/DeviceMapClient.java (original)
+++ devicemap/trunk/clients/2.0/reference/src/DeviceMapClient.java Thu Jul 30
20:46:53 2015
@@ -57,6 +57,9 @@ public class DeviceMapClient {
}
public void loadPatterns(JsonFile patternFile) throws Exception {
+
+ //PARSE PATTERN FILE JSON
+
if(!patternFile.getType().equals("pattern")) {
throw new Exception("Unknown pattern file type: " +
patternFile.getType());
}
@@ -202,6 +205,9 @@ public class DeviceMapClient {
}
public void loadAttributes(JsonFile attributeFile) throws Exception {
+
+ //PARSE ATTRIBUTE FILE JSON
+
if(!attributeFile.getType().equals("pattern") &&
!attributeFile.getType().equals("attribute")) {
throw new Exception("Unknown pattern file type: " +
attributeFile.getType());
}
@@ -382,6 +388,7 @@ public class DeviceMapClient {
return Collections.unmodifiableMap(custom);
}
+ //SPLIT A STRING
public static List<String> split(String source, List<String>
tokenSeperators) {
List<String> tokens = new ArrayList<>();
int sourcePos = 0;
@@ -421,6 +428,7 @@ public class DeviceMapClient {
return tokens;
}
+ //GET A TRANSFORMER
public static Transformer getTransformer(JsonNode transformer) throws
Exception {
String type = JsonFile.get(transformer, "type").asText();
JsonNode parameters = JsonFile.get(transformer, "parameters");
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=1693496&r1=1693495&r2=1693496&view=diff
==============================================================================
--- devicemap/trunk/clients/2.0/reference/src/JsonFile.java (original)
+++ devicemap/trunk/clients/2.0/reference/src/JsonFile.java Thu Jul 30 20:46:53
2015
@@ -33,6 +33,9 @@ public class JsonFile {
private final String domainVersion;
public JsonFile(String path) throws Exception {
+
+ //LOAD A JSON FILE AND VALIDATE IT
+
ObjectMapper mapper = new ObjectMapper();
json = mapper.readTree(new File(path));
@@ -61,6 +64,7 @@ public class JsonFile {
domainVersion = json.get("domainVersion").asText();
}
+ //GET HELPER, RETURN A NULL NODE IF NOT FOUND
public static JsonNode get(JsonNode node, String name) throws Exception {
JsonNode ret = null;
@@ -80,6 +84,7 @@ public class JsonFile {
return nullNode;
}
+ //EMPTY HELPER
public static boolean empty(JsonNode node, String name) {
return (node == null || node.get(name) == null ||
node.get(name).asText().isEmpty());
}
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=1693496&r1=1693495&r2=1693496&view=diff
==============================================================================
--- devicemap/trunk/clients/2.0/reference/src/Main.java (original)
+++ devicemap/trunk/clients/2.0/reference/src/Main.java Thu Jul 30 20:46:53 2015
@@ -138,6 +138,9 @@ public class Main {
}
private static boolean test(DeviceMapClient client, JsonFile tests) throws
Exception {
+
+ //PARSE TEST FILE JSON
+
if(!tests.getType().equals("test")) {
throw new Exception("Unknown test type: " + tests.getType());
}
@@ -172,6 +175,8 @@ public class Main {
resultPatternId = JsonFile.get(test, "resultPatternId").asText();
}
+ //PERFORM CLASSIFICATION
+
Map<String, String> result = client.classify(input);
String patternId = null;
@@ -179,6 +184,8 @@ public class Main {
patternId = result.get("patternId");
}
+ //CHECK IF IT PASSES
+
boolean pass = false;
int failedAttributes = 0;
@@ -207,6 +214,8 @@ public class Main {
}
}
+ //PRINT RESULTS
+
if(pass && failedAttributes == 0) {
passCount++;
log("Passed, expected patternId: " + resultPatternId, 2);
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=1693496&r1=1693495&r2=1693496&view=diff
==============================================================================
--- devicemap/trunk/clients/2.0/reference/src/Pattern.java (original)
+++ devicemap/trunk/clients/2.0/reference/src/Pattern.java Thu Jul 30 20:46:53
2015
@@ -39,6 +39,9 @@ public class Pattern {
};
public Pattern(JsonNode json) throws Exception {
+
+ //PARSE PATTERN JSON
+
if(json.get("patternId") == null ||
json.get("patternId").asText().isEmpty()) {
throw new Exception("patternId not found");
}
@@ -80,6 +83,7 @@ public class Pattern {
}
}
+ //IS PATTERN VALID FOR MATCHED TOKENS
public boolean isValid(List<String> matchedTokens) {
int lastFound = -1;
@@ -110,6 +114,7 @@ public class Pattern {
}
}
+ //RANK COMPARED TO OTHER PATTERNS
public long getRank() {
long rank = rankValue;