Shrads
Shrads

Reputation: 61

Gate- setting text for annotation

I am trying to set content for a particular annotation in Gate. There are methods to extract content/text for the given annotation in the document. I want to change the text shown by the given annotation that means ultimately it should change the actual text of the document. Is it possible in Gate to change the content of annotations?

gate.Utils.stringFor(document, annotation) or contentFor methods gives the text highlighted by the given annotation. COuld not find any method which will set content as well.

DocumentContent documentContent = new DocumentContentImpl(value);
        Long start = getAnnotation(annotation).getStartNode().getOffset();
        Long end = getAnnotation(annotation).getEndNode().getOffset();
        doc.edit(start, end, documentContent);

I want to edit content of the document. I have tried above method I have also added documentListener to the document. Control goes into contentEdited method but the actual content of the document does not get replaced with new content. Rather document does not get affected at all. Can someone suggest me what to do for this or am I doing anything wrong here?

Upvotes: 2

Views: 439

Answers (2)

Shrads
Shrads

Reputation: 61

Finally found a solution for this. I need to use following method for writing xml

File f = new File("/path/to/output.xml");
DocumentStaxUtils.writeDocument(doc, f)

And this gives a proper xml output after editing the document

Upvotes: 0

Yasen
Yasen

Reputation: 1683

The Document interface has a method for this, the mechanics are described in DocumentImpl.

However, are you sure that you really need to update the document content? That's the point of having annotations - put whatever you need as annotations on top of the text itself. Then just use the annotation features instead of document content. For instance if you get the Token strings you can reconstruct the text, if you use Token stems you get a stemmed version. Just use Token.newstring instead of changing the content.

Also, it is a cumbersome operation because it has to shift all the annotation offsets.

Upvotes: 1

Related Questions