hits: Get hits for query

Description Usage Arguments Details Examples

Description

Get hits for queries, optionally with s-attribute values.

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
hits(.Object, ...)

## S4 method for signature 'corpus'
hits(
  .Object,
  query,
  cqp = FALSE,
  check = TRUE,
  s_attribute = NULL,
  p_attribute = "word",
  size = FALSE,
  freq = FALSE,
  mc = 1L,
  verbose = TRUE,
  progress = FALSE,
  ...
)

## S4 method for signature 'character'
hits(
  .Object,
  query,
  cqp = FALSE,
  check = TRUE,
  s_attribute = NULL,
  p_attribute = "word",
  size = FALSE,
  freq = FALSE,
  mc = FALSE,
  verbose = TRUE,
  progress = TRUE,
  ...
)

## S4 method for signature 'slice'
hits(
  .Object,
  query,
  cqp = FALSE,
  s_attribute = NULL,
  p_attribute = "word",
  size = FALSE,
  freq = FALSE,
  mc = FALSE,
  progress = FALSE,
  verbose = TRUE,
  ...
)

## S4 method for signature 'subcorpus'
hits(
  .Object,
  query,
  cqp = FALSE,
  s_attribute = NULL,
  p_attribute = "word",
  size = FALSE,
  freq = FALSE,
  mc = FALSE,
  progress = FALSE,
  verbose = TRUE,
  ...
)

## S4 method for signature 'partition'
hits(
  .Object,
  query,
  cqp = FALSE,
  s_attribute = NULL,
  p_attribute = "word",
  size = FALSE,
  freq = FALSE,
  mc = FALSE,
  progress = FALSE,
  verbose = TRUE,
  ...
)

## S4 method for signature 'partition_bundle'
hits(
  .Object,
  query,
  cqp = FALSE,
  check = TRUE,
  p_attribute = getOption("polmineR.p_attribute"),
  s_attribute = NULL,
  size = TRUE,
  freq = FALSE,
  mc = getOption("polmineR.mc"),
  progress = FALSE,
  verbose = TRUE,
  ...
)

## S4 method for signature 'context'
hits(.Object, s_attribute = NULL, verbose = TRUE, ...)

Arguments

.Object

A length-one character vector with a corpus ID, a partition or partition_bundle object

...

Further arguments (used for backwards compatibility).

query

A character vector (optionally named, see details) with one or more queries.

cqp

Either a logical value (TRUE if query is a CQP query), or a function to check whether query is a CQP query or not.

check

A logical value, whether to check validity of CQP query using check_cqp_query.

s_attribute

A character vector of s-attributes that will be reported as metadata.

p_attribute

A character vector stating a p-attribute.

size

A logical value, whether to report the size of subcorpus.

freq

A logcial value, whether to report relative frequencies.

mc

A logical value, whether to use multicore.

verbose

A logical value, whether to output messages.

progress

A logical value, whether to show progress bar.

Details

If the character vector provided by query is named, these names will be reported in the data.table that is returned rather than the queries.

If freq is TRUE, the data.table returned in the DT-slot will deliberately include the subsets of the partition/corpus with no hits (query is NA, count is 0).

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
use("polmineR")

# get hits for corpus object
y <- corpus("REUTERS") %>% hits(query = "oil")
y <- corpus("REUTERS") %>% hits(query = c("oil", "barrel"))
y <- corpus("REUTERS") %>% hits(query = "oil", s_attribute = "places", freq = TRUE)

# specify corpus by corpus ID
y <- hits("REUTERS", query = "oil")
y <- hits("REUTERS", query = "oil", s_attribute = "places", freq = TRUE)

# get hits for partition
p <- partition("REUTERS", places = "saudi-arabia", regex = TRUE)
y <- hits(p, query = "oil")
y <- hits(p, query = "oil", s_attribute = "id")

# get hits for subcorpus
y <- corpus("REUTERS") %>%
  subset(grep("saudi-arabia", places)) %>%
  hits(query = "oil")

polmineR documentation built on Oct. 23, 2020, 8:31 p.m.