Revision: 17321
          http://sourceforge.net/p/gate/code/17321
Author:   valyt
Date:     2014-02-17 11:11:40 +0000 (Mon, 17 Feb 2014)
Log Message:
-----------
Merged bug-fix from trunk.

Modified Paths:
--------------
    
mimir/branches/5.0/mimir-core/src/gate/mimir/index/OriginalMarkupMetadataHelper.java

Property Changed:
----------------
    
mimir/branches/5.0/mimir-core/src/gate/mimir/index/OriginalMarkupMetadataHelper.java

Modified: 
mimir/branches/5.0/mimir-core/src/gate/mimir/index/OriginalMarkupMetadataHelper.java
===================================================================
--- 
mimir/branches/5.0/mimir-core/src/gate/mimir/index/OriginalMarkupMetadataHelper.java
        2014-02-17 11:01:09 UTC (rev 17320)
+++ 
mimir/branches/5.0/mimir-core/src/gate/mimir/index/OriginalMarkupMetadataHelper.java
        2014-02-17 11:11:40 UTC (rev 17321)
@@ -109,14 +109,18 @@
               //consume the TAG
               String openingTag = docTags.tagDescriptors.get(currentTag[0]);
               output.append(openingTag);
-              
               String closingTag = getClosingTag(openingTag);
-              LinkedList<String> spans = spansToEnd.get(currentTag[2]);
-              if(spans == null){
-                spans = new LinkedList<String>();
-                spansToEnd.put(currentTag[2], spans);
+              if(currentTag[2] == -1) {
+                // zero-length tag
+                output.append(closingTag);
+              } else {
+                LinkedList<String> spans = spansToEnd.get(currentTag[2]);
+                if(spans == null){
+                  spans = new LinkedList<String>();
+                  spansToEnd.put(currentTag[2], spans);
+                }
+                spans.addFirst(closingTag);                
               }
-              spans.addFirst(closingTag);
               //consume the tag
               currentTag = (tagIter != null && tagIter.hasNext()) ? 
                       tagIter.next() : null;
@@ -139,12 +143,17 @@
             String openingTag = docTags.tagDescriptors.get(currentTag[0]);
             output.append(openingTag);
             String closingTag = getClosingTag(openingTag);
-            LinkedList<String> spans = spansToEnd.get(currentTag[2]);
-            if(spans == null){
-              spans = new LinkedList<String>();
-              spansToEnd.put(currentTag[2], spans);
+            if(currentTag[2] == -1) {
+              // zero-length tag
+              output.append(closingTag);
+            } else {
+              LinkedList<String> spans = spansToEnd.get(currentTag[2]);
+              if(spans == null){
+                spans = new LinkedList<String>();
+                spansToEnd.put(currentTag[2], spans);
+              }
+              spans.addFirst(closingTag);                
             }
-            spans.addFirst(closingTag);
             //consume the tag
             currentTag = (tagIter != null && tagIter.hasNext()) ? 
                     tagIter.next() : null;
@@ -205,7 +214,7 @@
     Annotation currentTag = tagsiter.hasNext() ? tagsiter.next() : null;
     long tagStart = currentTag == null ? -1 : 
currentTag.getStartNode().getOffset();
     long tagEnd = currentTag == null ? -1 : 
currentTag.getEndNode().getOffset();
-    for(int tokIdx = 0; tokIdx < tokens.length; tokIdx++){
+    for(int tokIdx = 0; tokIdx < tokens.length; tokIdx++) {
       long tokStart = tokens[tokIdx].getStartNode().getOffset();
       long tokEnd = tokens[tokIdx].getEndNode().getOffset();
       //see if there are any tags to close at this offset
@@ -223,12 +232,20 @@
           //the current tag starts within the current token
           int tagDescId = getTagId(currentTag, documentTags);
           documentTags.tags.add(new int[]{tagDescId, tokIdx, -1});
-          LinkedList<Integer> tagsEnding = tagsToEnd.get(tagEnd);
-          if(tagsEnding == null){
-            tagsEnding = new LinkedList<Integer>();
-            tagsToEnd.put(tagEnd, tagsEnding);
+          if(tagEnd <= tokStart){
+            // the tag starts and ends before the current token starts, so it's
+            // either zero-length, or whitespace-only
+            // leave the end position as -1.
+          } else {
+            // not a zero-length tag, 
+            // so we'll need to find the closing position later
+            LinkedList<Integer> tagsEnding = tagsToEnd.get(tagEnd);
+            if(tagsEnding == null){
+              tagsEnding = new LinkedList<Integer>();
+              tagsToEnd.put(tagEnd, tagsEnding);
+            }
+            tagsEnding.addFirst(documentTags.tags.size() -1);            
           }
-          tagsEnding.addFirst(documentTags.tags.size() -1);
           //update the current tag
           currentTag = tagsiter.hasNext() ? tagsiter.next() : null;
           tagStart = currentTag == null ? -1 : 
currentTag.getStartNode().getOffset();
@@ -405,7 +422,9 @@
    * <ol>
    *   <li>the index in the {@link #tagDescriptors} array for the tag</li>
    *   <li>the start offset for the tag (in terms of token position);</li>
-   *   <li>the end offset for the tag (in terms of token position);</li>
+   *   <li>the end offset for the tag (in terms of token position); That is the
+   *   position of the last token that is part of this tag.  Zero-length tags
+   *   are represented by setting this position to -1.</li>
    * </ol>
    * 
    */
@@ -439,6 +458,20 @@
       }
     }
     
+    
+    @Override
+    public String toString() {
+      StringBuffer str = new StringBuffer();
+      boolean first = true;
+      for(int[] aTag : tags) {
+        if(first) first = false;
+        else str.append(' ');
+        str.append(tagDescriptors.get(aTag[0])).append('(').append(aTag[1])
+            .append(':').append(aTag[2]).append(')');
+      }
+      return str.toString();
+    }
+    
     /**
      * A set used internally to ensure uniqueness of the tag descriptors. 
      */
@@ -464,6 +497,8 @@
      * appear in the correct document order. 
      */
     private List<int[]> tags;
+    
+    
   }
   
   /**


Property changes on: 
mimir/branches/5.0/mimir-core/src/gate/mimir/index/OriginalMarkupMetadataHelper.java
___________________________________________________________________
Added: svn:mergeinfo
## -0,0 +1,4 ##
+/mimir/branches/3.4/mimir-core/src/gate/mimir/index/OriginalMarkupMetadataHelper.java:14623,14634-14643
+/mimir/branches/4.0/mimir-core/src/gate/mimir/index/OriginalMarkupMetadataHelper.java:15380-15383,15385-15386,15388
+/mimir/branches/4.x/mimir-core/src/gate/mimir/index/OriginalMarkupMetadataHelper.java:14299-14316
+/mimir/trunk/mimir-core/src/gate/mimir/index/OriginalMarkupMetadataHelper.java:17030-17320
\ No newline at end of property
This was sent by the SourceForge.net collaborative development platform, the 
world's largest Open Source development site.


------------------------------------------------------------------------------
Android apps run on BlackBerry 10
Introducing the new BlackBerry 10.2.1 Runtime for Android apps.
Now with support for Jelly Bean, Bluetooth, Mapview and more.
Get your Android app in front of a whole new audience.  Start now.
http://pubads.g.doubleclick.net/gampad/clk?id=124407151&iu=/4140/ostg.clktrk
_______________________________________________
GATE-cvs mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/gate-cvs

Reply via email to