devicemap-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From re...@apache.org
Subject svn commit: r1693757 - in /devicemap/trunk/clients/2.0/reference: src/DeviceMapClient.java src/Pattern.java test.sh
Date Sat, 01 Aug 2015 20:21:46 GMT
Author: rezan
Date: Sat Aug  1 20:21:45 2015
New Revision: 1693757

URL: http://svn.apache.org/r1693757
Log:
ranking based on length and strong fix

Modified:
    devicemap/trunk/clients/2.0/reference/src/DeviceMapClient.java
    devicemap/trunk/clients/2.0/reference/src/Pattern.java
    devicemap/trunk/clients/2.0/reference/test.sh

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=1693757&r1=1693756&r2=1693757&view=diff
==============================================================================
--- devicemap/trunk/clients/2.0/reference/src/DeviceMapClient.java (original)
+++ devicemap/trunk/clients/2.0/reference/src/DeviceMapClient.java Sat Aug  1 20:21:45 2015
@@ -311,11 +311,6 @@ public class DeviceMapClient {
         matchedTokens.add(token);
 
         for(Pattern match : matched) {
-          if(match.isStrong()) {
-            winner = match;
-            break;
-          }
-          
           if(!candidates.contains(match)) {
             candidates.add(match);
           }
@@ -330,8 +325,14 @@ public class DeviceMapClient {
     if(winner == null) {
       for(Pattern candidate : candidates) {
         if(candidate.isValid(matchedTokens)) {
-          Main.log("Candidate: " + candidate.toStringRank(), 3);
-          if(winner == null || candidate.getRank() > winner.getRank()) {
+          Main.log("Candidate: " + candidate.toStringRank(matchedTokens), 3);
+          
+          if(winner == null) {
+            winner = candidate;
+          } else if(candidate.getRank() > winner.getRank()) {
+            winner = candidate;
+          } else if(candidate.getRank() == winner.getRank() &&
+              candidate.getMatchedLength(matchedTokens) > winner.getMatchedLength(matchedTokens))
{
             winner = candidate;
           }
         }

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=1693757&r1=1693756&r2=1693757&view=diff
==============================================================================
--- devicemap/trunk/clients/2.0/reference/src/Pattern.java (original)
+++ devicemap/trunk/clients/2.0/reference/src/Pattern.java Sat Aug  1 20:21:45 2015
@@ -70,6 +70,10 @@ public class Pattern {
       throw new Exception("Invalid rankValue in " + patternId + ": " + rankValue);
     }
 
+    if(rankType.equals(RankType.Strong) && rankValue != 0) {
+      throw new Exception("Strong patterns cannot have a rankValue");
+    }
+
     patternTokens = new ArrayList<>();
 
     for(int i = 0; i < json.get("patternTokens").size(); i++) {
@@ -121,16 +125,25 @@ public class Pattern {
     if(isWeak()) {
       rank += 100000;
     } else if(isStrong()) {
-      rank += 10000000;
+      return 10000000;
     }
 
     return rank;
   }
 
   //LENGTH OF MATCHED TOKENS, FOR RANKING
-  //TODO
-  public long getMatchedLength() {
-    return 0;
+  public long getMatchedLength(List<String> matchedTokens) {
+    int length = 0;
+
+    for(String patternToken : patternTokens) {
+      int found = matchedTokens.indexOf(patternToken);
+
+      if(found >= 0) {
+        length += matchedTokens.get(found).length();
+      }
+    }
+    
+    return length;
   }
 
   @Override
@@ -138,8 +151,8 @@ public class Pattern {
     return patternId;
   }
 
-  public String toStringRank() {
-    return patternId + "(" + getRank() + ")";
+  public String toStringRank(List<String> matchedTokens) {
+    return patternId + "(" + getRank() + "," + getMatchedLength(matchedTokens) + ")";
   }
 
   public String toStringFull() {

Modified: devicemap/trunk/clients/2.0/reference/test.sh
URL: http://svn.apache.org/viewvc/devicemap/trunk/clients/2.0/reference/test.sh?rev=1693757&r1=1693756&r2=1693757&view=diff
==============================================================================
--- devicemap/trunk/clients/2.0/reference/test.sh (original)
+++ devicemap/trunk/clients/2.0/reference/test.sh Sat Aug  1 20:21:45 2015
@@ -36,11 +36,13 @@ do
     A=`find $DROOT -type f | grep attribute | sort | sed "s/^/-a /" | xargs echo`
     T=`find $DROOT -type f | grep test | sort | sed "s/^/-t /" | xargs echo`
 
+    CMD="./run.sh $P $A $T -v"
     ./run.sh $P $A $T -q
 
     if [ "$?" != "0" ]
     then
         FAIL="$FAIL $DOMAIN"
+        echo "Failed command: $CMD"
     else
         PASS="$PASS $DOMAIN"
     fi



Mime
View raw message