blob: b57aae71e58085d71fb295d0fe4c9a7ceefa2edb [file] [log] [blame]
Marc Kupietz0bb21522020-02-04 11:27:25 +01001library(RKorAPClient)
2
3displayKwics <- function(q, htmlFile = file.path(tempfile(fileext = ".html"))) {
4 cat(
5 '<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
6 <!DOCTYPE html>
7 <html>
8 <header>
9 <style>
10 body {
11 font-family: "Lato", sans-serif;
12 font-size: 10pt;
13 }
14 div.kwic {
15 display: table-row;
16 line-height: 180%;
17 }
18 div.kwic:nth-child(even) {background: #EEE}
19 div.kwic:nth-child(odd) {background: #FFF}
20 .sigle {
21 font-size: 90%;
22 font-family: "Courier New", monospace;
23 display: table-cell;
24 text-align: right;
25 padding-right: 1ex;
26 }
27 .context-left {
28 display: table-cell;
29 text-align: right;
30 overflow: hidden;
31 white-space: nowrap;
32 }
33 .context-right {
34 display: table-cell;
35 text-align: left;
36 white-space: nowrap;
37 overflow: hidden;
38 }
39 .match {
40 display: table-cell;
41 padding-left: 1ex;
42 padding-right: 1ex;
43 text-align: center;
44 }
45 </style>
46 </header>
47 <body>
48 <table>',
49 paste0(
50 "<div class='kwic'><span class='sigle'>",
51 q@collectedMatches$textSigle,
52 "</span> ",
53 as.character(q@collectedMatches$snippet),
54 "</div>"
55 ),
56 ' </table>
57 </body>
58</html>',
59 file = htmlFile,
60 sep = "\n"
61 )
62 viewer <- getOption("viewer")
63 viewer(htmlFile)
64}
65
66kco <- new("KorAPConnection", verbose = TRUE)
67if (is.null(kco@accessToken)) {
68 message(
69 paste0(
70 "In order to receive KWICSs also from corpora with restricted licenses, you need an access token.\n",
71 "To generate an access token, login to KorAP and navigite to KorAP's OAuth settings <",
72 kco@KorAPUrl,
73 "settings/oauth#page-top>"
74 )
75 )
76}
77q <- corpusQuery(kco, "Ameisenplage", metadataOnly = F) %>%
78 fetchAll() %>%
79 displayKwics()