mirror of
https://github.com/gsi-upm/senpy
synced 2024-11-21 15:52:28 +00:00
Change Box plugin to mimic a sklearn classifier
This commit is contained in:
parent
fbb418c365
commit
92189822d8
@ -18,7 +18,7 @@ class BasicBox(SentimentBox):
|
||||
'default': 'marl:Neutral'
|
||||
}
|
||||
|
||||
def box(self, input, **kwargs):
|
||||
def predict(self, input):
|
||||
output = basic.get_polarity(input)
|
||||
return self.mappings.get(output, self.mappings['default'])
|
||||
|
||||
|
@ -18,7 +18,7 @@ class Basic(MappingMixin, SentimentBox):
|
||||
'default': 'marl:Neutral'
|
||||
}
|
||||
|
||||
def box(self, input, **kwargs):
|
||||
def predict(self, input):
|
||||
return basic.get_polarity(input)
|
||||
|
||||
test_cases = [{
|
||||
|
@ -18,7 +18,7 @@ class PipelineSentiment(MappingMixin, SentimentBox):
|
||||
-1: 'marl:Negative'
|
||||
}
|
||||
|
||||
def box(self, input, *args, **kwargs):
|
||||
def predict(self, input):
|
||||
return pipeline.predict([input, ])[0]
|
||||
|
||||
test_cases = [
|
||||
|
@ -251,7 +251,7 @@ class Box(AnalysisPlugin):
|
||||
|
||||
.. 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
|
||||
@ -267,13 +267,13 @@ class Box(AnalysisPlugin):
|
||||
'''Transforms the results of the black box into an entry'''
|
||||
return output
|
||||
|
||||
def box(self):
|
||||
def predict(self, input):
|
||||
raise NotImplementedError('You should define the behavior of this plugin')
|
||||
|
||||
def analyse_entries(self, entries, params):
|
||||
for entry in entries:
|
||||
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)
|
||||
|
||||
|
||||
@ -453,7 +453,8 @@ def install_deps(*plugins):
|
||||
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):
|
||||
|
@ -212,7 +212,7 @@ class PluginsTest(TestCase):
|
||||
def input(self, entry, **kwargs):
|
||||
return entry.text
|
||||
|
||||
def box(self, input, **kwargs):
|
||||
def predict(self, input):
|
||||
return 'SIGN' in input
|
||||
|
||||
def output(self, output, entry, **kwargs):
|
||||
@ -242,7 +242,7 @@ class PluginsTest(TestCase):
|
||||
|
||||
mappings = {'happy': 'marl:Positive', 'sad': 'marl:Negative'}
|
||||
|
||||
def box(self, input, **kwargs):
|
||||
def predict(self, input, **kwargs):
|
||||
return 'happy' if ':)' in input else 'sad'
|
||||
|
||||
test_cases = [
|
||||
|
Loading…
Reference in New Issue
Block a user