コード例 #1
0
 def _convert_param(self, param, val):
     pspec, _ = self.VW_PARAMS[param]
     if isinstance(pspec, list):
         if val in pspec:
             return val
         raise ConfigurationException(
             "{} is not a valid value for {} (allowed: {})".format(
                 val, param, ', '.join(pspec)), backend_id=self.backend_id)
     try:
         return pspec(val)
     except ValueError:
         raise ConfigurationException(
             "The {} value {} cannot be converted to {}".format(
                 param, val, pspec), backend_id=self.backend_id)
コード例 #2
0
ファイル: backend.py プロジェクト: mo-fu/Annif
 def _validate_input_limit(self, input_limit):
     input_limit = int(input_limit)
     if input_limit >= 0:
         return input_limit
     else:
         raise ConfigurationException('input_limit can not be negative',
                                      backend_id=self.backend_id)
コード例 #3
0
ファイル: cli.py プロジェクト: mo-fu/Annif
def validate_backend_params(backend, beparam, project):
    if 'algorithm' in beparam:
        raise NotSupportedException('Algorithm overriding not supported.')
    if backend != project.config['backend']:
        raise ConfigurationException(
            'The backend {} in CLI option "-b {}" not matching the project'
            ' backend {}.'.format(backend, beparam, project.config['backend']))
コード例 #4
0
 def tagger(self):
     try:
         return self.params['tagger']
     except KeyError:
         raise ConfigurationException(
             "tagger must be set in project configuration",
             backend_id=self.backend_id)
コード例 #5
0
 def endpoint(self):
     try:
         return self.params['endpoint']
     except KeyError:
         raise ConfigurationException(
             "endpoint must be set in project configuration",
             backend_id=self.backend_id)
コード例 #6
0
ファイル: project.py プロジェクト: archaeocharlie/Annif
def _create_projects(projects_file, datadir, init_projects):
    if not os.path.exists(projects_file):
        logger.warning(
            'Project configuration file "%s" is missing. Please provide one.' +
            ' You can set the path to the project configuration file using ' +
            'the ANNIF_PROJECTS environment variable or the command-line ' +
            'option "--projects".', projects_file)
        return {}

    config = configparser.ConfigParser()
    config.optionxform = lambda option: option
    with open(projects_file, encoding='utf-8-sig') as projf:
        try:
            config.read_file(projf)
        except (configparser.DuplicateOptionError,
                configparser.DuplicateSectionError) as err:
            raise ConfigurationException(err)

    # create AnnifProject objects from the configuration file
    projects = collections.OrderedDict()
    for project_id in config.sections():
        projects[project_id] = AnnifProject(project_id,
                                            config[project_id],
                                            datadir)
        if init_projects:
            projects[project_id].initialize()
    return projects
コード例 #7
0
 def algorithm(self):
     algorithm = self.params.get('algorithm', self.DEFAULT_ALGORITHM)
     if algorithm not in self.SUPPORTED_ALGORITHMS:
         raise ConfigurationException(
             "{} is not a valid algorithm (allowed: {})".format(
                 algorithm, ', '.join(self.SUPPORTED_ALGORITHMS)),
             backend_id=self.backend_id)
     return algorithm
コード例 #8
0
 def _init_access(self):
     access = self.config.get('access', self.DEFAULT_ACCESS)
     try:
         self.access = getattr(Access, access)
     except AttributeError:
         raise ConfigurationException(
             "'{}' is not a valid access setting".format(access),
             project_id=self.project_id)
コード例 #9
0
 def vocab(self):
     if self._vocab is None:
         if self.vocab_id is None:
             raise ConfigurationException("vocab setting is missing",
                                          project_id=self.project_id)
         self._vocab = annif.vocab.AnnifVocabulary(self.vocab_id,
                                                   self._base_datadir)
     return self._vocab
コード例 #10
0
 def analyzer(self):
     if self._analyzer is None:
         if self.analyzer_spec:
             self._analyzer = annif.analyzer.get_analyzer(
                 self.analyzer_spec)
         else:
             raise ConfigurationException("analyzer setting is missing",
                                          project_id=self.project_id)
     return self._analyzer
コード例 #11
0
ファイル: __init__.py プロジェクト: juhoinkinen/Annif
def get_transform(transform_specs, project):
    transform_defs = parse_specs(transform_specs)
    transform_classes = []
    args = []
    for trans, posargs, kwargs in transform_defs:
        if trans not in _transforms:
            raise ConfigurationException(f"No such transform {trans}")
        transform_classes.append(_transforms[trans])
        args.append((posargs, kwargs))
    return transform.TransformChain(transform_classes, args, project)
コード例 #12
0
ファイル: transform.py プロジェクト: juhoinkinen/Annif
 def _init_transforms(self, transform_classes, args):
     transforms = []
     for trans, (posargs, kwargs) in zip(transform_classes, args):
         try:
             transforms.append(trans(self.project, *posargs, **kwargs))
         except (ValueError, TypeError):
             raise ConfigurationException(
                 f"Invalid arguments to {trans.name} transform: "
                 f"{posargs}, {kwargs})",
                 project_id=self.project.project_id)
     return transforms
コード例 #13
0
ファイル: project.py プロジェクト: Dans-labs/Annif
 def backend(self):
     if self._backend is None:
         if 'backend' not in self.config:
             raise ConfigurationException("backend setting is missing",
                                          project_id=self.project_id)
         backend_id = self.config['backend']
         try:
             backend_class = annif.backend.get_backend(backend_id)
             self._backend = backend_class(backend_id,
                                           config_params=self.config,
                                           project=self)
         except ValueError:
             logger.warning(
                 "Could not create backend %s, "
                 "make sure you've installed optional dependencies",
                 backend_id)
     return self._backend
コード例 #14
0
ファイル: cli.py プロジェクト: juhoinkinen/Annif
def validate_backend_params(backend, beparam, project):
    if backend != project.config['backend']:
        raise ConfigurationException(
            'The backend {} in CLI option "-b {}" not matching the project'
            ' backend {}.'.format(backend, beparam, project.config['backend']))
コード例 #15
0
ファイル: inputlimiter.py プロジェクト: juhoinkinen/Annif
 def _validate_value(self, input_limit):
     if input_limit < 0:
         raise ConfigurationException(
             'input_limit in limit_input transform cannot be negative',
             project_id=self.project.project_id)
コード例 #16
0
 def _validate_label_types(self, label_types):
     for lt in label_types:
         if lt not in ('prefLabel', 'altLabel', 'hiddenLabel'):
             raise ConfigurationException(
                 f'invalid label type {lt}', backend_id=self.backend_id)