public class OriginalMarkupMetadataHelper extends Object implements DocumentMetadataHelper, DocumentRenderer
DocumentMetadataHelper
and
DocumentRenderer
that imports relevant markup tags from the indexed
document's original markups annotation set, saves them as document metadata
in the zip collection, and then uses these saved values to render the
document at search time.
The metadata saved by this class is stored in the main document metadata map
using this class's name as a key. The value save is itself a Map, with
multiple metadata fields.Modifier and Type | Class and Description |
---|---|
protected static class |
OriginalMarkupMetadataHelper.DocumentTags
An object storing a list of tags (obtained from the original markup) that
should be saved as document metadata.
|
protected static class |
OriginalMarkupMetadataHelper.StartComparator
Compares annotation by start offset, end offset, and ID.
|
Modifier and Type | Field and Description |
---|---|
static String[] |
DEFAULT_TAG_TYPES
The names of the original tags that should be preserved as
document metadata in the zip collection, and used for rendering documents.
|
static String |
HIT_CLOSING_TAG
The tag used to mark-up query hits (closing tag).
|
static String |
HIT_OPENING_TAG
The tag used to mark-up query hits (opening tag).
|
static String |
TAGS_KEY |
Constructor and Description |
---|
OriginalMarkupMetadataHelper(Set<String> markupAnnTypes)
Creates a new document helper/renderer.
|
Modifier and Type | Method and Description |
---|---|
protected void |
addMetadataField(DocumentData documentData,
String key,
Serializable value)
Adds a new field to the metadata map saved by this class.
|
void |
documentEnd(GATEDocument document,
DocumentData documentData)
Called when the indexing of a document has completed.
|
void |
documentStart(GATEDocument document)
Called when the indexing a new document begins.
|
protected static String |
getClosingTag(String openingTag)
Calculates the closing tag for a given opening tag.
|
protected Serializable |
getMetadataField(DocumentData documentData,
String key)
Gets a metadata field value from the metadata map saved by this class.
|
protected int |
getTagId(gate.Annotation ann,
OriginalMarkupMetadataHelper.DocumentTags documentMetadata)
Gets the ID in the current list of tag descriptors for a given annotation
|
void |
render(DocumentData documentData,
List<Binding> hits,
Appendable output)
Renders a document, using the saved original markup tags, and adding tags
for the provided query hits.
|
protected String |
tagNameForAnnotation(gate.Annotation ann)
Returns the tag name that should be used to represent the given
annotation.
|
public static final String TAGS_KEY
public static final String[] DEFAULT_TAG_TYPES
public static final String HIT_OPENING_TAG
public static final String HIT_CLOSING_TAG
public OriginalMarkupMetadataHelper(Set<String> markupAnnTypes)
markupAnnTypes
- the types of annotations from the original markups
set that should be saved as document metadata (and used for rendering
documents). If the value given for this parameter is null
,
then the default set of tags is used (see DEFAULT_TAG_TYPES
).public void render(DocumentData documentData, List<Binding> hits, Appendable output) throws IOException
render
in interface DocumentRenderer
documentData
- the DocumentData
object for the document to be
rendered.hits
- the list of hits that need to also be rendered.output
- a Appendable
to which the output is written.IOException
DocumentRenderer.render(gate.mimir.index.DocumentData, java.util.List, java.lang.Appendable)
public void documentEnd(GATEDocument document, DocumentData documentData)
DocumentMetadataHelper
documentEnd
in interface DocumentMetadataHelper
document
- the document being indexeddocumentData
- the documentData value that will be stored as part of
the index, and which holds the metadata fields.protected void addMetadataField(DocumentData documentData, String key, Serializable value)
key
- value
- protected Serializable getMetadataField(DocumentData documentData, String key)
key
- value
- protected static String getClosingTag(String openingTag)
openingTag
- protected int getTagId(gate.Annotation ann, OriginalMarkupMetadataHelper.DocumentTags documentMetadata)
ann
- protected String tagNameForAnnotation(gate.Annotation ann)
ann
- an annotationpublic void documentStart(GATEDocument document)
DocumentMetadataHelper
documentStart
in interface DocumentMetadataHelper
document
- the document being indexed.Copyright © 2021 GATE. All rights reserved.