Skip to content

Commit

Permalink
refactor _inputs_to_exampletext: split off _get_input
Browse files Browse the repository at this point in the history
  • Loading branch information
osma committed Feb 5, 2019
1 parent 899e887 commit 7edf0f6
Showing 1 changed file with 18 additions and 12 deletions.
30 changes: 18 additions & 12 deletions annif/backend/vw_multi.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,21 +107,27 @@ def _format_examples(self, project, text, uris):
for subject_id in subject_ids:
yield '{} {}'.format(subject_id + 1, text)

def _get_input(self, input, project, text):
if input == '_text_':
normalized = self._normalize_text(project, text)
if normalized != '':
return normalized
else:
proj = annif.project.get_project(input)
result = proj.analyze(text)
features = [
'{}:{}'.format(self._cleanup_text(hit.uri), hit.score)
for hit in result.hits]
if features:
return ' '.join(features)
return None

def _inputs_to_exampletext(self, project, text):
namespaces = {}
for input in self.inputs:
if input == '_text_':
normalized = self._normalize_text(project, text)
if normalized != '':
namespaces['_text_'] = normalized
else:
proj = annif.project.get_project(input)
result = proj.analyze(text)
features = [
'{}:{}'.format(self._cleanup_text(hit.uri), hit.score)
for hit in result.hits]
if features:
namespaces[input] = ' '.join(features)
inputtext = self._get_input(input, project, text)
if inputtext:
namespaces[input] = inputtext
if not namespaces:
return None
return ' '.join(['|{} {}'.format(namespace, featurestr)
Expand Down

0 comments on commit 7edf0f6

Please sign in to comment.