Turn on global conversion between rpy and py objects
In our case, simplicity outweighs performance, and concerning the
performance the KorAP server is the bottleneck, anyway.
Resolves #8
Change-Id: I03a4c23b5f3224491b2974c98a2080cfc6fc4614
diff --git a/KorAPClient/__init__.py b/KorAPClient/__init__.py
index 40db1a0..de41622 100644
--- a/KorAPClient/__init__.py
+++ b/KorAPClient/__init__.py
@@ -16,8 +16,7 @@
warnings.warn("R-package RKorAPClient version " + KorAPClient.__version__ + " is outdated, please update.",
DeprecationWarning)
-pandas2ri.activate()
-
+robjects.conversion.set_conversion(robjects.default_converter + pandas2ri.converter)
# noinspection PyPep8Naming
class KorAPConnection(RS4):
@@ -59,8 +58,7 @@
"""
default_kwargs = {"as.df": True}
default_kwargs.update(kwargs)
- with localconverter(robjects.default_converter + pandas2ri.converter):
- return KorAPClient.corpusStats(self, *args, **default_kwargs)
+ return KorAPClient.corpusStats(self, *args, **default_kwargs)
def frequencyQuery(self, *args, **kwargs):
"""Query relative frequency of search term(s).
@@ -92,8 +90,7 @@
5 Ameisenplage 3 ... 8.629463e-10 1.064780e-08
```
"""
- with localconverter(robjects.default_converter + pandas2ri.converter):
- return robjects.conversion.rpy2py(KorAPClient.frequencyQuery(self, *args, **kwargs))
+ return KorAPClient.frequencyQuery(self, *args, **kwargs)
def collocationScoreQuery(self, node, collocate, vc="", **kwargs):
"""Get collocation scores for given node(s) and collocate(s).
@@ -126,7 +123,7 @@
if type(vc) is list:
vc = robjects.StrVector(vc)
- return robjects.conversion.rpy2py(KorAPClient.collocationScoreQuery(self, node, collocate, vc, **kwargs))
+ return KorAPClient.collocationScoreQuery(self, node, collocate, vc, **kwargs)
def collocationAnalysis(self, node, vc="", **kwargs):
""" **EXPERIMENTAL**: Performs a collocation analysis for the given node (or query) in the given virtual corpus.
@@ -167,7 +164,7 @@
if type(vc) is list:
vc = robjects.StrVector(vc)
- return robjects.conversion.rpy2py(KorAPClient.collocationAnalysis(self, node, vc, **kwargs))
+ return KorAPClient.collocationAnalysis(self, node, vc, **kwargs)
def corpusQuery(self, *args, **kwargs):
"""Query search term(s).