mirror of
https://github.com/gsi-upm/senpy
synced 2024-11-22 08:12:27 +00:00
Release 0.20
This commit is contained in:
parent
8a516d927e
commit
9758a2977f
@ -6,6 +6,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|||||||
|
|
||||||
## [Unreleased]
|
## [Unreleased]
|
||||||
|
|
||||||
|
## 0.20
|
||||||
|
|
||||||
### Added
|
### Added
|
||||||
* Objects can control the keys that will be used in `serialize`/`jsonld`/`as_dict` by specifying a list of keys in `terse_keys`.
|
* Objects can control the keys that will be used in `serialize`/`jsonld`/`as_dict` by specifying a list of keys in `terse_keys`.
|
||||||
e.g.
|
e.g.
|
||||||
@ -27,6 +29,7 @@ e.g.
|
|||||||
* Plugin and parameter descriptions are now formatted with (showdown)[https://github.com/showdownjs/showdown].
|
* Plugin and parameter descriptions are now formatted with (showdown)[https://github.com/showdownjs/showdown].
|
||||||
* The web UI requests extra_parameters from the server. This is useful for pipelines. See #52
|
* The web UI requests extra_parameters from the server. This is useful for pipelines. See #52
|
||||||
* First batch of semantic tests (using SPARQL)
|
* First batch of semantic tests (using SPARQL)
|
||||||
|
* `Plugin.path()` method to get a file path from a relative path (using the senpy data folder)
|
||||||
|
|
||||||
### Changed
|
### Changed
|
||||||
* `install_deps` now checks what requirements are already met before installing with pip.
|
* `install_deps` now checks what requirements are already met before installing with pip.
|
||||||
|
@ -251,11 +251,15 @@ class Plugin(with_metaclass(PluginMeta, models.Plugin)):
|
|||||||
return alternative
|
return alternative
|
||||||
raise IOError('File does not exist: {}'.format(fname))
|
raise IOError('File does not exist: {}'.format(fname))
|
||||||
|
|
||||||
|
def path(self, fpath):
|
||||||
|
if not os.path.isabs(fpath):
|
||||||
|
fpath = os.path.join(self.data_folder, fpath)
|
||||||
|
return fpath
|
||||||
|
|
||||||
def open(self, fpath, mode='r'):
|
def open(self, fpath, mode='r'):
|
||||||
if 'w' in mode:
|
if 'w' in mode:
|
||||||
# When writing, only use absolute paths or data_folder
|
# When writing, only use absolute paths or data_folder
|
||||||
if not os.path.isabs(fpath):
|
fpath = self.path(fpath)
|
||||||
fpath = os.path.join(self.data_folder, fpath)
|
|
||||||
else:
|
else:
|
||||||
fpath = self.find_file(fpath)
|
fpath = self.find_file(fpath)
|
||||||
|
|
||||||
@ -381,7 +385,9 @@ class SentimentPlugin(Analyser, Evaluable, models.SentimentPlugin):
|
|||||||
activity = self.activity(parameters)
|
activity = self.activity(parameters)
|
||||||
entries = []
|
entries = []
|
||||||
for feat in X:
|
for feat in X:
|
||||||
entries.append(models.Entry(nif__isString=feat[0]))
|
if isinstance(feat, list):
|
||||||
|
feat = ' '.join(feat)
|
||||||
|
entries.append(models.Entry(nif__isString=feat))
|
||||||
labels = []
|
labels = []
|
||||||
for e in self.process_entries(entries, activity):
|
for e in self.process_entries(entries, activity):
|
||||||
sent = e.sentiments[0].polarity
|
sent = e.sentiments[0].polarity
|
||||||
|
@ -320,24 +320,32 @@ class PluginsTest(TestCase):
|
|||||||
for i in range(50):
|
for i in range(50):
|
||||||
testdata.append(["good", 1])
|
testdata.append(["good", 1])
|
||||||
for i in range(50):
|
for i in range(50):
|
||||||
testdata.append(["bad", 0])
|
testdata.append(["bad", -1])
|
||||||
dataset = pd.DataFrame(testdata, columns=['text', 'polarity'])
|
dataset = pd.DataFrame(testdata, columns=['text', 'polarity'])
|
||||||
|
|
||||||
class DummyPlugin(plugins.SentimentBox):
|
class DummyPlugin(plugins.SentimentBox):
|
||||||
description = 'Plugin to test evaluation'
|
description = 'Plugin to test evaluation'
|
||||||
version = 0
|
version = 0
|
||||||
|
|
||||||
|
classes = ['marl:Positive', 'marl:Negative']
|
||||||
|
|
||||||
def predict_one(self, features, **kwargs):
|
def predict_one(self, features, **kwargs):
|
||||||
return 0
|
print(features[0])
|
||||||
|
return [0, 1]
|
||||||
|
|
||||||
class SmartPlugin(plugins.SentimentBox):
|
class SmartPlugin(plugins.SentimentBox):
|
||||||
description = 'Plugin to test evaluation'
|
description = 'Plugin to test evaluation'
|
||||||
version = 0
|
version = 0
|
||||||
|
|
||||||
|
classes = ['marl:Positive', 'marl:Negative']
|
||||||
|
|
||||||
def predict_one(self, features, **kwargs):
|
def predict_one(self, features, **kwargs):
|
||||||
|
print(features[0])
|
||||||
if features[0] == 'good':
|
if features[0] == 'good':
|
||||||
return 1
|
print('positive')
|
||||||
return 0
|
return [1, 0]
|
||||||
|
print('negative')
|
||||||
|
return [0, 1]
|
||||||
|
|
||||||
dpipe = DummyPlugin()
|
dpipe = DummyPlugin()
|
||||||
results = plugins.evaluate(datasets={'testdata': dataset}, plugins=[dpipe], flatten=True)
|
results = plugins.evaluate(datasets={'testdata': dataset}, plugins=[dpipe], flatten=True)
|
||||||
|
Loading…
Reference in New Issue
Block a user