Package edu.upf.taln.dri.common.util
Class GateUtil
- java.lang.Object
-
- edu.upf.taln.dri.common.util.GateUtil
-
public class GateUtil extends Object
Collection of utility methods to interact with GATE documents.
-
-
Constructor Summary
Constructors Constructor Description GateUtil()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static boolean
containedIn(gate.Annotation container, gate.Annotation contained)
Check if an annotation is contained in another one.static gate.Document
formListStrToGateDoc(List<String> sentList)
Creates a GATE document from a list of Strings.static List<Integer>
fromAnnListToAnnIDlist(List<gate.Annotation> annList)
Given a list of annotations return the list of annotation IDsstatic List<gate.Annotation>
getAnnInDocOrder(gate.Document doc, String annSet, String annType)
Get the ordered annotations from an annotation set and typestatic List<gate.Annotation>
getAnnInDocOrderContainedAnn(gate.Document doc, String annSet, String annType, gate.Annotation includedInAnn)
Get the ordered annotations from an annotation set and type, included in an annotation NB: all annotations with start position >= startOffset and whose end position <= endOffsetstatic List<gate.Annotation>
getAnnInDocOrderContainedOffset(gate.Document doc, String annSet, String annType, Long startOffset, Long endOffset)
Get the ordered annotations from an annotation set and type, included in a couple of offsets NB: all annotations with start position >= startOffset and whose end position <= endOffsetstatic List<gate.Annotation>
getAnnInDocOrderIntersectAnn(gate.Document doc, String annSet, String annType, gate.Annotation intersectingAnn)
Get the ordered annotations from an annotation set and type, intersecting an annotationstatic List<gate.Annotation>
getAnnInDocOrderIntersectOffset(gate.Document doc, String annSet, String annType, Long startOffset, Long intersectingAnn)
Get the ordered annotations from an annotation set and type, intersecting a couple of offsets NB: all annotations with start position >= startOffset and whose end position <= endOffsetstatic Optional<String>
getAnnotationText(gate.Annotation ann, gate.Document doc)
Return the text spotted by the annotationstatic Optional<Boolean>
getBooleanFeature(gate.Annotation ann, String featName)
Return the value of the annotation featurestatic Optional<Boolean>
getBooleanFeature(gate.Document doc, String featName)
Return the value of the document featurestatic Optional<String>
getDocumentText(gate.Document doc, Long startOffset, Long endOffset)
Return the text spotted by the annotationstatic Optional<Double>
getDoubleFeature(gate.Annotation ann, String featName)
Return the value of the annotation featurestatic Optional<gate.Annotation>
getFirstAnnotationInDocOrder(gate.Document doc, String annSet, String annType)
Get the first annotation in doc order of a specific set and typestatic Optional<Integer>
getIntegerFeature(gate.Annotation ann, String featName)
Return the value of the annotation featurestatic Optional<gate.Annotation>
getLastAnnotationInDocOrder(gate.Document doc, String annSet, String annType)
Get the last annotation in doc order of a specific set and typestatic Optional<List<Integer>>
getListIntegerFeature(gate.Annotation ann, String featName)
Return the value of the annotation featurestatic Optional<String>
getStringFeature(gate.Annotation ann, String featName)
Return the value of the annotation featurestatic Optional<String>
getStringFeature(gate.Document doc, String featName)
Return the value of the document featurestatic void
transferAnnotations(gate.Document doc, String annType, String newAnnType, String sourceAS, String destinationAS, Predicate<gate.Annotation> filterPred)
Transfer from the source Annotation Set all the annotations of type equal to annType to the destination Annotation Set, renaming each annotation with the new annotation type.
-
-
-
Method Detail
-
getStringFeature
public static Optional<String> getStringFeature(gate.Annotation ann, String featName)
Return the value of the annotation feature- Parameters:
ann
-featName
-- Returns:
-
getBooleanFeature
public static Optional<Boolean> getBooleanFeature(gate.Annotation ann, String featName)
Return the value of the annotation feature- Parameters:
ann
-featName
-- Returns:
-
getIntegerFeature
public static Optional<Integer> getIntegerFeature(gate.Annotation ann, String featName)
Return the value of the annotation feature- Parameters:
ann
-featName
-- Returns:
-
getDoubleFeature
public static Optional<Double> getDoubleFeature(gate.Annotation ann, String featName)
Return the value of the annotation feature- Parameters:
ann
-featName
-- Returns:
-
getListIntegerFeature
public static Optional<List<Integer>> getListIntegerFeature(gate.Annotation ann, String featName)
Return the value of the annotation feature- Parameters:
ann
-featName
-- Returns:
-
getStringFeature
public static Optional<String> getStringFeature(gate.Document doc, String featName)
Return the value of the document feature- Parameters:
ann
-featName
-- Returns:
-
getBooleanFeature
public static Optional<Boolean> getBooleanFeature(gate.Document doc, String featName)
Return the value of the document feature- Parameters:
ann
-featName
-- Returns:
-
containedIn
public static boolean containedIn(gate.Annotation container, gate.Annotation contained)
Check if an annotation is contained in another one. The contained annotation needs to have: - a start offset >= than the start offset of the container - a end offset <= than the end offset of the container- Parameters:
container
-contained
-- Returns:
-
getAnnotationText
public static Optional<String> getAnnotationText(gate.Annotation ann, gate.Document doc)
Return the text spotted by the annotation- Parameters:
ann
-doc
-- Returns:
-
getDocumentText
public static Optional<String> getDocumentText(gate.Document doc, Long startOffset, Long endOffset)
Return the text spotted by the annotation- Parameters:
ann
-doc
-- Returns:
-
transferAnnotations
public static void transferAnnotations(gate.Document doc, String annType, String newAnnType, String sourceAS, String destinationAS, Predicate<gate.Annotation> filterPred)
Transfer from the source Annotation Set all the annotations of type equal to annType to the destination Annotation Set, renaming each annotation with the new annotation type.- Parameters:
annType
-newAnnType
-sourceAS
-destinationAS
-filterPred
- If not null, useful to filter the annotations to transfer
-
getAnnInDocOrder
public static List<gate.Annotation> getAnnInDocOrder(gate.Document doc, String annSet, String annType)
Get the ordered annotations from an annotation set and type- Parameters:
doc
-annSet
-annType
-- Returns:
-
getAnnInDocOrderContainedOffset
public static List<gate.Annotation> getAnnInDocOrderContainedOffset(gate.Document doc, String annSet, String annType, Long startOffset, Long endOffset)
Get the ordered annotations from an annotation set and type, included in a couple of offsets NB: all annotations with start position >= startOffset and whose end position <= endOffset- Parameters:
doc
-annSet
-annType
-startOffset
-endOffset
-- Returns:
-
getAnnInDocOrderContainedAnn
public static List<gate.Annotation> getAnnInDocOrderContainedAnn(gate.Document doc, String annSet, String annType, gate.Annotation includedInAnn)
Get the ordered annotations from an annotation set and type, included in an annotation NB: all annotations with start position >= startOffset and whose end position <= endOffset- Parameters:
doc
-annSet
-annType
-startOffset
-endOffset
-- Returns:
-
getAnnInDocOrderIntersectOffset
public static List<gate.Annotation> getAnnInDocOrderIntersectOffset(gate.Document doc, String annSet, String annType, Long startOffset, Long intersectingAnn)
Get the ordered annotations from an annotation set and type, intersecting a couple of offsets NB: all annotations with start position >= startOffset and whose end position <= endOffset- Parameters:
doc
-annSet
-annType
-startOffset
-intersectingAnn
-- Returns:
-
getAnnInDocOrderIntersectAnn
public static List<gate.Annotation> getAnnInDocOrderIntersectAnn(gate.Document doc, String annSet, String annType, gate.Annotation intersectingAnn)
Get the ordered annotations from an annotation set and type, intersecting an annotation- Parameters:
doc
-annSet
-annType
-startOffset
-endOffset
-- Returns:
-
formListStrToGateDoc
public static gate.Document formListStrToGateDoc(List<String> sentList)
Creates a GATE document from a list of Strings. Each element of the list is annotated by the ImportBase.headerDOC_Sentence in the ImportBase.headerDOC_AnnSet annotation set- Parameters:
sentList
-- Returns:
-
getFirstAnnotationInDocOrder
public static Optional<gate.Annotation> getFirstAnnotationInDocOrder(gate.Document doc, String annSet, String annType)
Get the first annotation in doc order of a specific set and type- Parameters:
doc
-annSet
-annType
-- Returns:
-
getLastAnnotationInDocOrder
public static Optional<gate.Annotation> getLastAnnotationInDocOrder(gate.Document doc, String annSet, String annType)
Get the last annotation in doc order of a specific set and type- Parameters:
doc
-annSet
-annType
-- Returns:
-
-