devicemap-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From re...@apache.org
Subject svn commit: r1693591 - in /devicemap/trunk/clients/2.0/reference/src: DeviceMapClient.java Pattern.java TransformerReplaceFirst.java TransformerSubstring.java
Date Fri, 31 Jul 2015 13:14:18 GMT
Author: rezan
Date: Fri Jul 31 13:14:18 2015
New Revision: 1693591

URL: http://svn.apache.org/r1693591
Log:
final 2 transformers

Added:
    devicemap/trunk/clients/2.0/reference/src/TransformerReplaceFirst.java
    devicemap/trunk/clients/2.0/reference/src/TransformerSubstring.java
Modified:
    devicemap/trunk/clients/2.0/reference/src/DeviceMapClient.java
    devicemap/trunk/clients/2.0/reference/src/Pattern.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=1693591&r1=1693590&r2=1693591&view=diff
==============================================================================
--- devicemap/trunk/clients/2.0/reference/src/DeviceMapClient.java (original)
+++ devicemap/trunk/clients/2.0/reference/src/DeviceMapClient.java Fri Jul 31 13:14:18 2015
@@ -20,7 +20,6 @@
 import java.util.ArrayList;
 import java.util.Collections;
 import java.util.HashMap;
-import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
 
@@ -33,10 +32,12 @@ public class DeviceMapClient {
   private String domain;
   private String domainVersion;
 
+  //INPUT PARSING
   private List<Transformer> transformers;
   private List<String> tokenSeperators;
   private int ngramConcatSize;
 
+  //PATTERN MATCHING
   private Map<String, List<Pattern>> patterns;
   private Map<String, Attributes> attributes;
 

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=1693591&r1=1693590&r2=1693591&view=diff
==============================================================================
--- devicemap/trunk/clients/2.0/reference/src/Pattern.java (original)
+++ devicemap/trunk/clients/2.0/reference/src/Pattern.java Fri Jul 31 13:14:18 2015
@@ -127,6 +127,12 @@ public class Pattern {
     return rank;
   }
 
+  //LENGTH OF MATCHED TOKENS, FOR RANKING
+  //TODO
+  public long getMatchedLength() {
+    return 0;
+  }
+
   @Override
   public String toString() {
     return patternId;

Added: devicemap/trunk/clients/2.0/reference/src/TransformerReplaceFirst.java
URL: http://svn.apache.org/viewvc/devicemap/trunk/clients/2.0/reference/src/TransformerReplaceFirst.java?rev=1693591&view=auto
==============================================================================
--- devicemap/trunk/clients/2.0/reference/src/TransformerReplaceFirst.java (added)
+++ devicemap/trunk/clients/2.0/reference/src/TransformerReplaceFirst.java Fri Jul 31 13:14:18
2015
@@ -0,0 +1,54 @@
+/*
+ Licensed to the Apache Software Foundation (ASF) under one
+ or more contributor license agreements.  See the NOTICE file
+ distributed with this work for additional information
+ regarding copyright ownership.  The ASF licenses this file
+ to you under the Apache License, Version 2.0 (the
+ "License"); you may not use this file except in compliance
+ with the License.  You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing,
+ software distributed under the License is distributed on an
+ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ KIND, either express or implied.  See the License for the
+ specific language governing permissions and limitations
+ under the License.
+ */
+
+import org.codehaus.jackson.JsonNode;
+
+public class TransformerReplaceFirst implements Transformer {
+  private final String find;
+  private final String replaceWith;
+
+  public TransformerReplaceFirst(JsonNode json) throws Exception {
+    if(JsonFile.empty(json, "find")) {
+      throw new Exception("TransformerReplaceFirst find not defined");
+    }
+
+    if(json.get("replaceWith") == null) {
+      throw new Exception("TransformerReplaceFirst replaceWith not defined");
+    }
+
+    find = json.get("find").asText();
+    replaceWith = json.get("replaceWith").asText();
+  }
+
+  @Override
+  public String transform(String input) {
+    int pos = input.indexOf(find);
+
+    if(pos > 0) {
+      return input.substring(0, pos) + replaceWith + input.substring(pos + find.length());
+    }
+
+    return input;
+  }
+
+  @Override
+  public String toString() {
+    return "TransformerReplaceFirst, find: '" + find + "', replaceWith: '" + replaceWith
+ "'";
+  }
+}

Added: devicemap/trunk/clients/2.0/reference/src/TransformerSubstring.java
URL: http://svn.apache.org/viewvc/devicemap/trunk/clients/2.0/reference/src/TransformerSubstring.java?rev=1693591&view=auto
==============================================================================
--- devicemap/trunk/clients/2.0/reference/src/TransformerSubstring.java (added)
+++ devicemap/trunk/clients/2.0/reference/src/TransformerSubstring.java Fri Jul 31 13:14:18
2015
@@ -0,0 +1,67 @@
+/*
+ Licensed to the Apache Software Foundation (ASF) under one
+ or more contributor license agreements.  See the NOTICE file
+ distributed with this work for additional information
+ regarding copyright ownership.  The ASF licenses this file
+ to you under the Apache License, Version 2.0 (the
+ "License"); you may not use this file except in compliance
+ with the License.  You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing,
+ software distributed under the License is distributed on an
+ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ KIND, either express or implied.  See the License for the
+ specific language governing permissions and limitations
+ under the License.
+ */
+
+import org.codehaus.jackson.JsonNode;
+
+public class TransformerSubstring implements Transformer {
+  private final int start;
+  private final int maxLength;
+
+  public TransformerSubstring(JsonNode json) throws Exception {
+    if(JsonFile.empty(json, "start")) {
+      throw new Exception("TransformerSubstring start not defined");
+    }
+
+    start = Integer.parseInt(json.get("start").asText());
+
+    if(start < 0) {
+      throw new Exception("Invalid value of start for TransformerSubstring: " + start);
+    }
+
+    String maxLengthStr = "-1";
+
+    if(!JsonFile.empty(json, "maxLength")) {
+      maxLengthStr = json.get("maxLength").asText();
+
+      if(Integer.parseInt(maxLengthStr) < 0) {
+        throw new Exception("Invalid value of maxLength for TransformerSubstring: " + maxLengthStr);
+      }
+    }
+
+    maxLength = Integer.parseInt(maxLengthStr);
+  }
+
+  @Override
+  public String transform(String input) throws Exception {
+    if(start >= input.length()) {
+      throw new Exception("start position out of range: " + start);
+    }
+
+    if(maxLength >= 0 && (maxLength + start) <= input.length()) {
+      return input.substring(start, maxLength + start);
+    }
+
+    return input.substring(start);
+  }
+
+  @Override
+  public String toString() {
+    return "TransformerSubstring, start: '" + start + (maxLength >= 0 ? "', maxLength:
" + maxLength : "");
+  }
+}



Mime
View raw message