Skip to content

Commit

Permalink
add explanatory output to load-vocab command
Browse files Browse the repository at this point in the history
  • Loading branch information
osma committed Sep 2, 2022
1 parent ecd067b commit bd21582
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
3 changes: 3 additions & 0 deletions annif/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -279,15 +279,18 @@ def run_load_vocab(vocab_id, language, force, subjectfile):
if annif.corpus.SubjectFileSKOS.is_rdf_file(subjectfile):
# SKOS/RDF file supported by rdflib
subjects = annif.corpus.SubjectFileSKOS(subjectfile)
click.echo(f"Loading vocabulary from SKOS file {subjectfile}...")
elif annif.corpus.SubjectFileCSV.is_csv_file(subjectfile):
# CSV file
subjects = annif.corpus.SubjectFileCSV(subjectfile)
click.echo(f"Loading vocabulary from CSV file {subjectfile}...")
else:
# probably a TSV file - we need to know its language
if not language:
click.echo("Please use --language option to set the language of " +
"a TSV vocabulary.", err=True)
sys.exit(1)
click.echo(f"Loading vocabulary from TSV file {subjectfile}...")
subjects = annif.corpus.SubjectFileTSV(subjectfile, language)
vocab.load_vocabulary(subjects, force=force)

Expand Down
8 changes: 5 additions & 3 deletions annif/vocab.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,13 +111,15 @@ def load_vocabulary(self, subject_corpus, force=False):

if not force and os.path.exists(
os.path.join(self.datadir, self.INDEX_FILENAME_CSV)):
logger.info('updating existing vocabulary')
logger.info('updating existing subject index')
self._subjects = self._update_subject_index(subject_corpus)
else:
logger.info('creating subject index')
self._subjects = self._create_subject_index(subject_corpus)

subject_corpus.save_skos(
os.path.join(self.datadir, self.INDEX_FILENAME_TTL))
skosfile = os.path.join(self.datadir, self.INDEX_FILENAME_TTL)
logger.info(f'saving vocabulary into SKOS file {skosfile}')
subject_corpus.save_skos(skosfile)

def as_graph(self):
"""return the vocabulary as an rdflib graph"""
Expand Down

0 comments on commit bd21582

Please sign in to comment.