1
0
mirror of https://github.com/gsi-upm/senpy synced 2024-12-22 13:08:13 +00:00

Minor updates

This commit is contained in:
J. Fernando Sánchez 2024-11-28 13:51:21 +01:00
parent 297e9e8106
commit 9414b0e3e6
13 changed files with 43 additions and 31 deletions

View File

@ -5,10 +5,12 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
## [Unreleased]
### Fixed
* Tests now use strict mode to detect errors on optional plugins
### Added
* The code of many senpy community plugins have been included by default. However, additional files (e.g., licensed data) and/or installing additional dependencies may be necessary for some plugins. Read each plugin's documentation for more information.
* `--strict` flag, to fail and not start when a
* `optional` attribute in plugins. Optional plugins may fail to load or activate but the server will be started regardless, unless running in strict mode
* `--strict` flag to set strict mode. In this mode, the server will not start when optional plugins fail to load
* Option in shelf plugins to ignore pickling errors
### Removed
* `--only-install`, `--only-test` and `--only-list` flags were removed in favor of `--no-run` + `--install`/`--test`/`--dependencies`

View File

@ -1,6 +1,6 @@
gsitk>0.1.9.1
flask_cors==3.0.10
Pattern==3.6
lxml==4.9.3
pandas==2.1.1
textblob==0.17.1
git+https://github.com/uob-vil/pattern.git#pattern

View File

@ -77,6 +77,8 @@ class Senpy(object):
if app is not None:
self.init_app(app)
self._conversion_candidates = {}
if self.install:
self.install_deps()
def init_app(self, app):
""" Initialise a flask app to add plugins to its context """

View File

@ -777,7 +777,8 @@ def install_deps(*plugins):
if exitcode != 0:
raise models.Error(
"Dependencies not properly installed: {}".format(pip_args))
return installed or download(list(nltk_resources))
installed_nltk = download(list(nltk_resources))
return installed or installed_nltk
is_plugin_file = re.compile(r'.*\.senpy$|senpy_[a-zA-Z0-9_]+\.py$|'
@ -826,10 +827,10 @@ def from_info(info, root=None, strict=False, **kwargs):
fun = partial(one_from_module, module, root=root, info=info, **kwargs)
try:
return fun()
except (ImportError, LookupError):
if strict or not str(info.get("optional", "false")).lower() in ["True", "true", "t"]:
except (ImportError, LookupError) as ex:
if strict or str(info.get("optional", "false")).lower() not in ["true", "t"]:
raise
print(f"Could not import plugin: { info }")
print(f"Could not import plugin: { info }: {ex}", file=sys.stderr)
return FailedPlugin(info, fun)

View File

@ -1,5 +1,5 @@
---
module: emotion-anew
module: emotion_anew_plugin
optional: true
requirements:
- numpy
@ -8,5 +8,5 @@ requirements:
- scipy
- scikit-learn
- textblob
- pattern
- lxml
- 'git+https://github.com/uob-vil/pattern.git'
- lxml

View File

@ -10,6 +10,8 @@ import sys
import string
import numpy as np
from six.moves import urllib
import nltk
from nltk.corpus import stopwords
from senpy import EmotionBox, models

View File

@ -1,7 +0,0 @@
---
module: emotion-wnaffect
optional: true
requirements:
- nltk>=3.0.5
- lxml>=3.4.2
async: false

View File

@ -31,11 +31,16 @@ class WNAffect(EmotionPlugin, ShelfMixin):
'options': ['en',]
}
}
optional = True
requirements = [
"nltk>=3.0.5",
"lxml>=3.4.2"
]
synsets_path = "a-synsets.xml"
hierarchy_path = "a-hierarchy.xml"
wn16_path = "wordnet1.6/dict"
onyx__usesEmotionModel = "emoml:big6"
nltk_resources = ['stopwords', 'averaged_perceptron_tagger', 'wordnet']
nltk_resources = ['stopwords', 'averaged_perceptron_tagger_eng', 'wordnet']
def _load_synsets(self, synsets_path):
"""Returns a dictionary POS tag -> synset offset -> emotion (str -> int -> str)."""

View File

@ -1,8 +0,0 @@
---
module: sentiment-basic
optional: true
requirements:
- nltk>=3.0.5
- scipy>=0.14.0
- textblob

View File

@ -39,8 +39,9 @@ class SentimentBasic(SentimentBox):
pos_path = "unigram_spanish.pickle"
maxPolarityValue = 1
minPolarityValue = -1
nltk_resources = ['punkt','wordnet', 'omw', 'omw-1.4']
nltk_resources = ['punkt_tab','wordnet', 'omw', 'omw-1.4']
optional = True
requirements = ['nltk>=3.0.5', 'scipy>=0.14.0', 'textblob==0.17']
with_polarity = False
def _load_swn(self):

View File

@ -3,3 +3,4 @@ pytest-cov
pytest
pandas
noop
gsitk

View File

@ -31,6 +31,7 @@ from senpy import config
import pandas as pd
ROOT = os.path.join(os.path.dirname(__file__), '..')
class ShelfDummyPlugin(plugins.SentimentPlugin, plugins.ShelfMixin):
'''Dummy plugin for tests.'''
@ -332,6 +333,18 @@ class PluginsTest(TestCase):
res = c._backwards_conversion(e)
assert res["onyx:hasEmotionCategory"] == "c2"
def test_installation(self):
sentiment = next(plugins.from_path('senpy/plugins/sentiment/basic/sentiment_basic_plugin.py'))
assert sentiment
inst, missing, nltk_deps = plugins.list_dependencies(sentiment)
assert 'punkt_tab' in nltk_deps
emotion = next(plugins.from_path('senpy/plugins/emotion/wnaffect/emotion_wnaffect_plugin.py'))
assert emotion
inst, missing, nltk_deps = plugins.list_dependencies(emotion)
assert 'averaged_perceptron_tagger_eng' in nltk_deps
def _test_evaluation(self):
testdata = []
for i in range(50):
@ -387,15 +400,15 @@ class PluginsTest(TestCase):
def make_mini_test(fpath):
def mini_test(self):
for plugin in plugins.from_path(fpath, install=True, strict=config.strict):
for plugin in plugins.from_path(fpath, strict=True):
plugins.install_deps(plugin)
plugin.test()
return mini_test
def _add_tests():
root = os.path.join(os.path.dirname(__file__), '..')
print(root)
for fpath in plugins.find_plugins([root, ]):
print(ROOT)
for fpath in plugins.find_plugins([ROOT, ]):
pass
t_method = make_mini_test(fpath)
t_method.__name__ = 'test_plugin_{}'.format(fpath)