Skip to content

Commit edf0300

Browse files
feldmuellerkupietz
authored andcommitted
add auth function and bump version to 1.0.0
Change-Id: Ib1f7fa0c5bb3c3aafdc2650ec7bc1bbf53b10e44
1 parent f9be0c5 commit edf0300

File tree

4 files changed

+59
-3
lines changed

4 files changed

+59
-3
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
# Version history
22

3+
## 1.0.0
4+
5+
- Simplified authorization process for accessing restricted data via the new `auth()` function
6+
- Fixed issues with tokenized matches in `corpusQuery` results
7+
- Fixed smoothing constant in `mergeDuplicateCollocates` function
38
- Fixed chainability of fetch methods in `corpusQuery`
49

510
## 0.9.0

KorAPClient/__init__.py

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
from rpy2.rinterface_lib.sexp import StrSexpVector, NULLType
88
from rpy2.robjects import numpy2ri
99
from rpy2.robjects.conversion import localconverter, get_conversion
10+
from rpy2.rinterface import NULL
1011

1112
import rpy2.robjects as robjects
1213
import rpy2.robjects.packages as packages
@@ -15,7 +16,7 @@
1516
from packaging import version
1617
from rpy2.robjects.methods import RS4
1718

18-
CURRENT_R_PACKAGE_VERSION = "0.9.0"
19+
CURRENT_R_PACKAGE_VERSION = "1.0.0"
1920

2021
KorAPClient = packages.importr('RKorAPClient')
2122
if version.parse(KorAPClient.__version__) < version.parse(CURRENT_R_PACKAGE_VERSION):
@@ -24,6 +25,8 @@
2425

2526
korapclient_converter = robjects.conversion.Converter('base empty converter')
2627

28+
# Export NULL
29+
NULL = NULL
2730

2831
@korapclient_converter.py2rpy.register(list)
2932
def _rpy2py_robject(listObject):
@@ -116,6 +119,42 @@ def __init__(self, *args, **kwargs):
116119
kco = KorAPClient.KorAPConnection(*args, **kwargs)
117120
super().__init__(kco)
118121

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+
119158
def corpusStats(self, *args, **kwargs):
120159
"""Query the size of the whole corpus or a virtual corpus specified by the vc argument.
121160

Readme.md

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,18 @@ KorAPConnection(verbose=True) \
7575
| 1 | "Wissenschaftler.*" | 942053 | | https://korap.ids-mannheim.de/?q=%22Wissenschaftler.%2a%22&ql=poliqarp | 1080268 | 0.872055 | 0.871423 | 0.872684 |
7676
| 2 | "Wissenschafter.*" | 138215 | | https://korap.ids-mannheim.de/?q=%22Wissenschafter.%2a%22&ql=poliqarp | 1080268 | 0.127945 | 0.127316 | 0.128577 |
7777

78+
79+
### Authorization
80+
81+
In order to retrieve KWIC data from copyrighted texts, you need to authenticate yourself and authorize the client to act on behalf of you.
82+
There are different ways to do this (see [Authorization Section of RKorAPClient](https://github.com/KorAP/RKorAPClient#-authorizing-rkorapclient-applications-to-access-restricted-kwics-from-copyrighted-texts)).
83+
The easiest way is to use the `auth()` method of the `KorAPConnection` class. This will open a browser window and ask you to log in with your KorAP account.
84+
85+
```python
86+
from KorAPClient import KorAPConnection
87+
kcon = KorAPConnection().auth()
88+
```
89+
7890
## Examples
7991
#### Frequencies of "Hello World" over years and countries
8092
```python
@@ -99,7 +111,7 @@ alt.Chart(df).mark_line(point=True).encode(y="ipm", x="Year:T", color="Country",
99111
```python
100112
from KorAPClient import KorAPConnection
101113

102-
kcon = KorAPConnection(verbose=True)
114+
kcon = KorAPConnection(verbose=True).auth()
103115
results = kcon.collocationAnalysis("focus(in [tt/p=NN] {[tt/l=setzen]})",
104116
leftContextSize=1,
105117
rightContextSize=0,

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[project]
22
name = "KorAPClient"
3-
version = "0.9.0"
3+
version = "1.0.0"
44
description = "Client package to access KorAP's web service API"
55
authors = [
66
{name = "Marc Kupietz",email = "[email protected]"},

0 commit comments

Comments
 (0)