Changeset 4033


Ignore:
Timestamp:
2003-03-28T13:50:51+12:00 (21 years ago)
Author:
mdewsnip
Message:

Modified to returned a section with annotations as a proper XML document (with structure), rather than just a block of text. This allows much easier access to the annotations, and the code no longer needs to know anything about its usage (span tags are now added in the XSLT).

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/gsdl3/src/java/org/greenstone/gsdl3/service/GATEServices.java

    r4024 r4033  
    240240
    241241        // Remove the surrounding HTML tags
    242         annotated_text = annotated_text.substring(25, annotated_text.length() - 7);
     242        annotated_text = annotated_text.substring(49, annotated_text.length() - 13);
    243243        // System.out.println("GATE result:\n" + annotated_text);
    244         content_text.setNodeValue(annotated_text);
     244
     245        annotated_text = "<nodeContent>" + annotated_text + "</nodeContent>";
     246        Element annotated_content = converter_.getDOM(annotated_text).getDocumentElement();
     247        doc_node.replaceChild(doc_node.getOwnerDocument().importNode(annotated_content, true), content);
    245248    }
    246249
     
    271274
    272275        // Extract all the annotations
    273         // AnnotationSet annSet = outputAnnotationSetName == null ||
    274         // outputAnnotationSetName.length() == 0 ?
    275         // doc.getAnnotations() :
    276         // doc.getAnnotations(outputAnnotationSetName);
    277276        AnnotationSet annSet = doc.getAnnotations();
    278         // String result = doc.toXml(annSet, false);
    279277
    280278        // Return the desired annotations
     
    283281        Factory.deleteResource(doc);
    284282
    285         // Replace all the annotations with div tags
     283        // 1. Escape the GATE result
     284        result = GSXML.xmlSafe(result);
     285
     286        // 2. Unescape the annotation tags
    286287        Iterator setIterator = annotationTypesToExport.iterator();
    287288        while (setIterator.hasNext()) {
    288289        String annotationType = (String) setIterator.next();
    289         result = result.replaceAll("<" + annotationType + ">",
    290                        "<span class=\"" + annotationType + "\">");
    291         result = result.replaceAll("</" + annotationType + ">",
    292                        "</span>");
     290        result = result.replaceAll("&lt;" + annotationType + "&gt;",
     291                       "<annotation type=\"" + annotationType + "\">");
     292        result = result.replaceAll("&lt;/" + annotationType + "&gt;",
     293                       "</annotation>");
    293294        }
    294295
    295         // System.out.println("Result:\n" + result);
    296296        return result;
    297297    }
Note: See TracChangeset for help on using the changeset viewer.