Learn R Programming

RKorAPClient (version 0.5.9)

corpusQuery,KorAPConnection-method: Method corpusQuery

Description

Perform a corpus query via a connection to a KorAP-API-server.

Usage

# S4 method for KorAPConnection
corpusQuery(
  kco,
  query = if (missing(KorAPUrl))
    stop("At least one of the parameters query and KorAPUrl must be specified.", call. =
    FALSE) else httr::parse_url(KorAPUrl)$query$q,
  vc = if (missing(KorAPUrl)) "" else httr::parse_url(KorAPUrl)$query$cq,
  KorAPUrl,
  metadataOnly = TRUE,
  ql = if (missing(KorAPUrl)) "poliqarp" else httr::parse_url(KorAPUrl)$query$ql,
  fields = c("corpusSigle", "textSigle", "pubDate", "pubPlace", "availability",
    "textClass", "snippet"),
  accessRewriteFatal = TRUE,
  verbose = kco@verbose,
  expand = length(vc) != length(query),
  as.df = FALSE
)

Arguments

kco

KorAPConnection object (obtained e.g. from new("KorAPConnection")

query

string that contains the corpus query. The query language depends on the ql parameter. Either query must be provided or KorAPUrl.

vc

string describing the virtual corpus in which the query should be performed. An empty string (default) means the whole corpus, as far as it is license-wise accessible.

KorAPUrl

instead of providing the query and vc string parameters, you can also simply copy a KorAP query URL from your browser and use it here (and in KorAPConnection) to provide all necessary information for the query.

metadataOnly

logical that determines whether queries should return only metadata without any snippets. This can also be useful to prevent access rewrites. Note that the default value is TRUE, unless the connection is authorized (currently not possible).

ql

string to choose the query language (see section on Query Parameters in the Kustvakt-Wiki for possible values.

fields

(meta)data fields that will be fetched for every match.

accessRewriteFatal

abort if query or given vc had to be rewritten due to insufficient rights (not yet implemented).

verbose

print some info

expand

logical that decides if query and vc parameters are expanded to all of their combinations

as.df

return result as data frame instead of as S4 object?

Value

Depending on the as.df parameter, a table or a KorAPQuery object that, among other information, contains the total number of results in @totalResults. The resulting object can be used to fetch all query results (with fetchAll) or the next page of results (with fetchNext). A corresponding URL to be used within a web browser is contained in @webUIRequestUrl Please make sure to check $collection$rewrites to see if any unforeseen access rewrites of the query's virtual corpus had to be performed.

References

https://ids-pub.bsz-bw.de/frontdoor/index/index/docId/9026

See Also

KorAPConnection, fetchNext, fetchRest, fetchAll, corpusStats

Examples

Run this code
# NOT RUN {
# Fetch metadata of every query hit for "Ameisenplage" and show a summary
# }
# NOT RUN {
new("KorAPConnection") %>% corpusQuery("Ameisenplage") %>% fetchAll()
# }
# NOT RUN {
# Use the copy of a KorAP-web-frontend URL for an API query of "Ameise" in a virtual corpus
# and show the number of query hits (but don't fetch them).

new("KorAPConnection", verbose = TRUE) %>%
 corpusQuery(KorAPUrl =
   "https://korap.ids-mannheim.de/?q=Ameise&cq=pubDate+since+2017&ql=poliqarp")

# Plot the time/frequency curve of "Ameisenplage"
# }
# NOT RUN {
new("KorAPConnection", verbose=TRUE) %>%
  { . ->> kco } %>%
  corpusQuery("Ameisenplage") %>%
  fetchAll() %>%
  slot("collectedMatches") %>%
  mutate(year = lubridate::year(pubDate)) %>%
  dplyr::select(year) %>%
  group_by(year) %>%
  summarise(Count = dplyr::n()) %>%
  mutate(Freq = mapply(function(f, y)
    f / corpusStats(kco, paste("pubDate in", y))@tokens, Count, year)) %>%
  dplyr::select(-Count) %>%
  complete(year = min(year):max(year), fill = list(Freq = 0)) %>%
  plot(type = "l")
# }

Run the code above in your browser using DataLab