Test whether a character string is a CQP query, or turn a character vector into CQP queries.

is.cqp(query)

check_cqp_query(query, warn = TRUE)

as.cqp(query, normalise.case = FALSE, collapse = FALSE)

Arguments

query

A character vector with at least one CQP query.

warn

A (length-one) logical value, whether to issue a warning if a query may be buggy.

normalise.case

A logical value, if TRUE, a flag will be added to the query/queries to omit matching case.

collapse

A logical value, whether to collapse the queries into one.

Value

is.cqp returns a logical value, as.cqp a character vector, check_cqp_query a logical value that is TRUE if all queries are valid, or FALSE if not.

Details

The is.cqp function guesses whether query is a CQP query and returns the respective logical value (TRUE/FALSE).

The as.cqp function takes a character vector as input and converts it to a CQP query by putting the individual strings in quotation marks.

The check_cqp_query-function will check that opening quotation marks are matched by closing quotation marks, to prevent crashes of CQP and the R session.

References

CQP Query Language Tutorial (http://cwb.sourceforge.net/files/CQP_Tutorial.pdf)

Examples

is.cqp("migration") # will return FALSE
#> [1] FALSE
is.cqp('"migration"') # will return TRUE
#> [1] TRUE
is.cqp('[pos = "ADJA"] "migration"') # will return TRUE
#> [1] TRUE
as.cqp("migration")
#> migration #> "\"migration\""
as.cqp(c("migration", "diversity"))
#> migration diversity #> "\"migration\"" "\"diversity\""
as.cqp(c("migration", "diversity"), collapse = TRUE)
#> [1] "(\"migration\"|\"diversity\")"
as.cqp("migration", normalise.case = TRUE)
#> migration #> "\"migration\" %c"
check_cqp_query('"Integration.*"') # TRUE, the query is ok
#> "Integration.*" #> TRUE
check_cqp_query('"Integration.*') # FALSE, closing quotation mark is missing
#> Warning: An issue occurred when checking query: "Integration.* #> Number of quotation marks is not divisable by 2: Opening quotation marks are not matched by closing quotation marks, or vice versa. Aborting to avoid a potential crash of CQP and the entire R session. Please check query.
#> "Integration.* #> FALSE
check_cqp_query("'Integration.*") # FALSE, closing quotation mark is missing
#> Warning: An issue occurred when checking query: 'Integration.* #> Number of quotation marks is not divisable by 2: Opening quotation marks are not matched by closing quotation marks, or vice versa. Aborting to avoid a potential crash of CQP and the entire R session. Please check query.
#> 'Integration.* #> FALSE
check_cqp_query(c("'Integration.*", '"Integration.*')) # FALSE too
#> Warning: An issue occurred when checking query: 'Integration.* #> Number of quotation marks is not divisable by 2: Opening quotation marks are not matched by closing quotation marks, or vice versa. Aborting to avoid a potential crash of CQP and the entire R session. Please check query.
#> Warning: An issue occurred when checking query: "Integration.* #> Number of quotation marks is not divisable by 2: Opening quotation marks are not matched by closing quotation marks, or vice versa. Aborting to avoid a potential crash of CQP and the entire R session. Please check query.
#> 'Integration.* "Integration.* #> FALSE FALSE