Skip to content

Commit

Permalink
refactor: split off uri to subject id conversion
Browse files Browse the repository at this point in the history
  • Loading branch information
osma committed Feb 1, 2019
1 parent b47554b commit a25cac8
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion annif/backend/vw_multi.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,13 +79,17 @@ def _write_train_file(cls, examples, filename):
for ex in examples:
print(ex, file=trainfile)

def _format_examples(self, project, text, uris):
@classmethod
def _uris_to_subject_ids(cls, project, uris):
subject_ids = []
for uri in uris:
subject_id = project.subjects.by_uri(uri)
if subject_id is not None:
subject_ids.append(subject_id)
return subject_ids

def _format_examples(self, project, text, uris):
subject_ids = self._uris_to_subject_ids(project, uris)
if self.algorithm == 'multilabel_oaa':
yield '{} | {}'.format(','.join(map(str, subject_ids)), text)
else:
Expand Down

0 comments on commit a25cac8

Please sign in to comment.