tmf: update calculation of confidence level of text trace validation
authorBernd Hufmann <Bernd.Hufmann@ericsson.com>
Mon, 21 Jul 2014 16:36:45 +0000 (12:36 -0400)
committerBernd Hufmann <bernd.hufmann@ericsson.com>
Thu, 24 Jul 2014 12:16:08 +0000 (08:16 -0400)
With this patch text traces with patterns that have higher number
of groups to match have higher confidence level.

Change-Id: I631c2ad15630a79e989c95ced93e9ff0c8cc3ed0
Signed-off-by: Bernd Hufmann <Bernd.Hufmann@ericsson.com>
Reviewed-on: https://git.eclipse.org/r/30281
Reviewed-by: Matthew Khouzam <matthew.khouzam@ericsson.com>
Tested-by: Hudson CI
org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/trace/text/TextTraceTest.java
org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/parsers/custom/CustomTxtTrace.java
org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/trace/text/TextTrace.java

index 269562173f757999f8d7df9ae5b9fb21e4709bd4..ebaca0bb73fd0e690ccce58c294a3807ba064760 100644 (file)
@@ -134,7 +134,7 @@ public class TextTraceTest {
         IStatus status = trace.validate(null, validTracePath);
         assertTrue(status.isOK());
         assertTrue(status instanceof TraceValidationStatus);
-        assertEquals(100, ((TraceValidationStatus) status).getConfidence());
+        assertEquals(180, ((TraceValidationStatus) status).getConfidence());
 
         URL location = FileLocator.find(TmfCoreTestPlugin.getDefault().getBundle(), new Path(OTHER_PATH), null);
         URI uri = FileLocator.toFileURL(location).toURI();
index c7d462b1c32dbc0ddbd070dcb7e52eb9b2cd2362..5d45ce359be3d9c6300d91406678070178a18f8a 100644 (file)
@@ -416,17 +416,18 @@ public class CustomTxtTrace extends TmfTrace implements ITmfEventParser, ITmfPer
         int confidence = 0;
         try (BufferedRandomAccessFile rafile = new BufferedRandomAccessFile(path, "r")) { //$NON-NLS-1$
             int lineCount = 0;
-            int matches = 0;
+            double matches = 0.0;
             String line = rafile.getNextLine();
             while ((line != null) && (lineCount++ < MAX_LINES)) {
                 for (InputLine inputLine : fDefinition.inputs) {
                     Matcher matcher = inputLine.getPattern().matcher(line);
                     if (matcher.matches()) {
-                        matches++;
+                        int groupCount = matcher.groupCount();
+                        matches += (1.0 + groupCount / ((double) groupCount + 1));
                         break;
                     }
                 }
-                confidence = MAX_CONFIDENCE * matches / lineCount;
+                confidence = (int) (MAX_CONFIDENCE * matches / lineCount);
                 line = rafile.getNextLine();
             }
         } catch (IOException e) {
index aa810e2bac16b57559f2a3ebff6c3dfefee5946c..5c48b14cee937ed0eba364d720dff34f9c1fbfe9 100644 (file)
@@ -88,14 +88,15 @@ public abstract class TextTrace<T extends TextTraceEvent> extends TmfTrace imple
         int confidence = 0;
         try (BufferedRandomAccessFile rafile = new BufferedRandomAccessFile(path, "r")) { //$NON-NLS-1$
             int lineCount = 0;
-            int matches = 0;
+            double matches = 0.0;
             String line = rafile.getNextLine();
             while ((line != null) && (lineCount++ < MAX_LINES)) {
                 Matcher matcher = getFirstLinePattern().matcher(line);
                 if (matcher.matches()) {
-                    matches++;
+                    int groupCount = matcher.groupCount();
+                    matches += (1.0 + groupCount / ((double) groupCount + 1));
                 }
-                confidence = MAX_CONFIDENCE * matches / lineCount;
+                confidence = (int) (MAX_CONFIDENCE * matches / lineCount);
                 line = rafile.getNextLine();
             }
         } catch (IOException e) {
@@ -106,7 +107,6 @@ public abstract class TextTrace<T extends TextTraceEvent> extends TmfTrace imple
         return new TraceValidationStatus(confidence, Activator.PLUGIN_ID);
 
     }
-
     @Override
     public void initTrace(IResource resource, String path, Class<? extends ITmfEvent> type) throws TmfTraceException {
         super.initTrace(resource, path, type);
This page took 0.028305 seconds and 5 git commands to generate.