annotations_in_spans: Annotations contained in character spans

Description Usage Arguments Value Examples

View source: R/annotation.R

Description

Extract annotations contained in character spans.

Usage

1

Arguments

x

an Annotation object.

y

a Span object, or something coercible to this (such as an Annotation object).

Value

A list with elements the annotations in x with character spans contained in the respective elements of y.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
## A simple text.
s <- String("  First sentence.  Second sentence.  ")
##           ****5****0****5****0****5****0****5**

## Basic sentence and word token annotation for the text.
a <- c(Annotation(1 : 2,
                  rep.int("sentence", 2L),
                  c( 3L, 20L),
                  c(17L, 35L)),
       Annotation(3 : 6,
                  rep.int("word", 4L),
                  c( 3L,  9L, 20L, 27L),
                  c( 7L, 16L, 25L, 34L)))

## Annotation for word tokens according to sentence:
annotations_in_spans(a[a$type == "word"], a[a$type == "sentence"])

Example output

[[1]]
 id type start end features
  3 word     3   7 
  4 word     9  16 

[[2]]
 id type start end features
  5 word    20  25 
  6 word    27  34 

NLP documentation built on Oct. 23, 2020, 6:18 p.m.