|
7 | 7 | from rpy2.rinterface_lib.sexp import StrSexpVector, NULLType
|
8 | 8 | from rpy2.robjects import numpy2ri
|
9 | 9 | from rpy2.robjects.conversion import localconverter, get_conversion
|
| 10 | +from rpy2.rinterface import NULL |
10 | 11 |
|
11 | 12 | import rpy2.robjects as robjects
|
12 | 13 | import rpy2.robjects.packages as packages
|
|
15 | 16 | from packaging import version
|
16 | 17 | from rpy2.robjects.methods import RS4
|
17 | 18 |
|
18 |
| -CURRENT_R_PACKAGE_VERSION = "0.9.0" |
| 19 | +CURRENT_R_PACKAGE_VERSION = "1.0.0" |
19 | 20 |
|
20 | 21 | KorAPClient = packages.importr('RKorAPClient')
|
21 | 22 | if version.parse(KorAPClient.__version__) < version.parse(CURRENT_R_PACKAGE_VERSION):
|
|
24 | 25 |
|
25 | 26 | korapclient_converter = robjects.conversion.Converter('base empty converter')
|
26 | 27 |
|
| 28 | +# Export NULL |
| 29 | +NULL = NULL |
27 | 30 |
|
28 | 31 | @korapclient_converter.py2rpy.register(list)
|
29 | 32 | def _rpy2py_robject(listObject):
|
@@ -116,6 +119,42 @@ def __init__(self, *args, **kwargs):
|
116 | 119 | kco = KorAPClient.KorAPConnection(*args, **kwargs)
|
117 | 120 | super().__init__(kco)
|
118 | 121 |
|
| 122 | + def auth(self, *args, **kwargs): |
| 123 | + """ Authorize PythonKorAPClient to make KorAP queries and download results on behalf of the user. |
| 124 | +
|
| 125 | + - **kco** - `KorAPConnection` object |
| 126 | + - **app_id** - OAuth2 application id. Defaults to the generic KorAP client application id. |
| 127 | + - **app_secret** - OAuth2 application secret. Used with confidential client applications. Defaults to `NULL`. |
| 128 | + - **scope** - OAuth2 scope. Defaults to "search match_info". |
| 129 | +
|
| 130 | + Returns: |
| 131 | +
|
| 132 | + Potentially authorized `KorAPConnection`|`RS4` with access token in `.slots['accessToken']`. |
| 133 | +
|
| 134 | + Example: |
| 135 | +
|
| 136 | + # Create a KorAPConnection object without an existing access token |
| 137 | +
|
| 138 | + kcon = KorAPConnection(accessToken=None, verbose=True).auth() |
| 139 | +
|
| 140 | + # Perform a query using the authenticated connection |
| 141 | +
|
| 142 | + q = kcon.corpusQuery("Ameisenplage", metadataOnly=False) |
| 143 | +
|
| 144 | + # Fetch all results |
| 145 | +
|
| 146 | + q = q.fetchAll() |
| 147 | +
|
| 148 | + # Access the collected matches |
| 149 | +
|
| 150 | + print(q.slots['collectedMatches'].snippet) |
| 151 | +
|
| 152 | + """ |
| 153 | + |
| 154 | + kco = KorAPClient.auth(self, *args, **kwargs) |
| 155 | + super().__init__(kco) |
| 156 | + return self |
| 157 | + |
119 | 158 | def corpusStats(self, *args, **kwargs):
|
120 | 159 | """Query the size of the whole corpus or a virtual corpus specified by the vc argument.
|
121 | 160 |
|
|
0 commit comments