Commit 92189822 authored by J. Fernando Sánchez's avatar J. Fernando Sánchez

Change Box plugin to mimic a sklearn classifier

parent fbb418c3
...@@ -18,7 +18,7 @@ class BasicBox(SentimentBox): ...@@ -18,7 +18,7 @@ class BasicBox(SentimentBox):
'default': 'marl:Neutral' 'default': 'marl:Neutral'
} }
def box(self, input, **kwargs): def predict(self, input):
output = basic.get_polarity(input) output = basic.get_polarity(input)
return self.mappings.get(output, self.mappings['default']) return self.mappings.get(output, self.mappings['default'])
......
...@@ -18,7 +18,7 @@ class Basic(MappingMixin, SentimentBox): ...@@ -18,7 +18,7 @@ class Basic(MappingMixin, SentimentBox):
'default': 'marl:Neutral' 'default': 'marl:Neutral'
} }
def box(self, input, **kwargs): def predict(self, input):
return basic.get_polarity(input) return basic.get_polarity(input)
test_cases = [{ test_cases = [{
......
...@@ -18,7 +18,7 @@ class PipelineSentiment(MappingMixin, SentimentBox): ...@@ -18,7 +18,7 @@ class PipelineSentiment(MappingMixin, SentimentBox):
-1: 'marl:Negative' -1: 'marl:Negative'
} }
def box(self, input, *args, **kwargs): def predict(self, input):
return pipeline.predict([input, ])[0] return pipeline.predict([input, ])[0]
test_cases = [ test_cases = [
......
...@@ -251,7 +251,7 @@ class Box(AnalysisPlugin): ...@@ -251,7 +251,7 @@ class Box(AnalysisPlugin):
.. code-block:: .. code-block::
entry --> input() --> box() --> output() --> entry' entry --> input() --> predict() --> output() --> entry'
In other words: their ``input`` method convers a query (entry and a set of parameters) into In other words: their ``input`` method convers a query (entry and a set of parameters) into
...@@ -267,13 +267,13 @@ class Box(AnalysisPlugin): ...@@ -267,13 +267,13 @@ class Box(AnalysisPlugin):
'''Transforms the results of the black box into an entry''' '''Transforms the results of the black box into an entry'''
return output return output
def box(self): def predict(self, input):
raise NotImplementedError('You should define the behavior of this plugin') raise NotImplementedError('You should define the behavior of this plugin')
def analyse_entries(self, entries, params): def analyse_entries(self, entries, params):
for entry in entries: for entry in entries:
input = self.input(entry=entry, params=params) input = self.input(entry=entry, params=params)
results = self.box(input=input, params=params) results = self.predict(input=input)
yield self.output(output=results, entry=entry, params=params) yield self.output(output=results, entry=entry, params=params)
...@@ -453,7 +453,8 @@ def install_deps(*plugins): ...@@ -453,7 +453,8 @@ def install_deps(*plugins):
return installed return installed
is_plugin_file = re.compile(r'.*\.senpy$|senpy_[a-zA-Z0-9_]+\.py$|[a-zA-Z0-9_]+_plugin.py$') is_plugin_file = re.compile(r'.*\.senpy$|senpy_[a-zA-Z0-9_]+\.py$|'
'^(?!test_)[a-zA-Z0-9_]+_plugin.py$')
def find_plugins(folders): def find_plugins(folders):
......
...@@ -212,7 +212,7 @@ class PluginsTest(TestCase): ...@@ -212,7 +212,7 @@ class PluginsTest(TestCase):
def input(self, entry, **kwargs): def input(self, entry, **kwargs):
return entry.text return entry.text
def box(self, input, **kwargs): def predict(self, input):
return 'SIGN' in input return 'SIGN' in input
def output(self, output, entry, **kwargs): def output(self, output, entry, **kwargs):
...@@ -242,7 +242,7 @@ class PluginsTest(TestCase): ...@@ -242,7 +242,7 @@ class PluginsTest(TestCase):
mappings = {'happy': 'marl:Positive', 'sad': 'marl:Negative'} mappings = {'happy': 'marl:Positive', 'sad': 'marl:Negative'}
def box(self, input, **kwargs): def predict(self, input, **kwargs):
return 'happy' if ':)' in input else 'sad' return 'happy' if ':)' in input else 'sad'
test_cases = [ test_cases = [
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment