Skip to content

Commit

Permalink
Include notes by default, deprecate --notes option
Browse files Browse the repository at this point in the history
As mentioned in #33
  • Loading branch information
danmichaelo committed Aug 11, 2017
1 parent 97bdadb commit 5caa2ba
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 5 deletions.
19 changes: 16 additions & 3 deletions mc2skos/mc2skos.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import sys
import re
import time
import warnings
from datetime import datetime
from lxml import etree
from iso639 import languages
Expand All @@ -27,14 +28,19 @@
from .element import Element
from .record import InvalidRecordError, UnknownSchemeError, ClassificationRecord, AuthorityRecord, CONFIG, ConceptScheme

logging.captureWarnings(True)
warnings.simplefilter('always', DeprecationWarning)

logger = logging.getLogger()
logger.setLevel(logging.DEBUG)
formatter = logging.Formatter('[%(asctime)s %(levelname)s] %(message)s')

console_handler = logging.StreamHandler()
console_handler.setLevel(logging.DEBUG)
console_handler.setFormatter(formatter)
logger.addHandler(console_handler)


WD = Namespace('http://data.ub.uio.no/webdewey-terms#')
MADS = Namespace('http://www.loc.gov/mads/rdf/v1#')

Expand Down Expand Up @@ -90,7 +96,7 @@ def add_record_to_graph(graph, record, options):
graph.add((record_uri, relation.get('relation'), URIRef(relation['uri'])))

# Add notes
if options.get('include_notes'):
if not options.get('exclude_notes'):
for note in record.definition:
graph.add((record_uri, SKOS.definition, Literal(note, lang=record.lang)))

Expand Down Expand Up @@ -214,7 +220,9 @@ def main():
parser.add_argument('--altlabels', '--indexterms', dest='altlabels', action='store_true',
help='Include altlabels (from 7XX or 4XX).')
parser.add_argument('--notes', dest='notes', action='store_true',
help='Include note fields.')
help='Include note fields (DEPRECATED as including notes is now the default).')
parser.add_argument('--exclude_notes', dest='exclude_notes', action='store_true',
help='Exclude note fields.')
parser.add_argument('--components', dest='components', action='store_true',
help='Include component information from 765.')
parser.add_argument('--webdewey', dest='webdewey', action='store_true',
Expand All @@ -229,6 +237,11 @@ def main():

args = parser.parse_args()

if args.notes:
warnings.warn('--notes is deprecated as including notes is now the default. '
'The inverse option --exclude_notes has been added to exclude notes.',
DeprecationWarning)

if args.list_schemes:
print('Classification schemes:')
for k in CONFIG['classification_schemes'].keys():
Expand Down Expand Up @@ -278,7 +291,7 @@ def main():
'base_uri': args.base_uri,
'scheme_uri': args.scheme_uri,
'include_altlabels': args.altlabels,
'include_notes': args.notes,
'exclude_notes': args.exclude_notes,
'include_components': args.components,
'include_webdewey': args.webdewey,
'skip_classification': args.skip_classification,
Expand Down
4 changes: 2 additions & 2 deletions tests/test_process_examples.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ def test_bk_example(marc_file):
uri = URIRef(u'http://uri.gbv.de/terminology/bk/' + notation)
expect.add((uri, RDF.type, SKOS.Concept))

graph = marc.processed_records(include_altlabels=True, include_notes=True)
graph = marc.processed_records(include_altlabels=True)
check_rdf(graph, expect, rdf_file)

vocabularies = {
Expand All @@ -110,7 +110,7 @@ def test_authority_example(marc_file):
uri = URIRef(uri_base + control_number)
expect.add((uri, RDF.type, SKOS.Concept))

graph = marc.processed_records(include_altlabels=True, include_notes=True)
graph = marc.processed_records(include_altlabels=True)
check_rdf(graph, expect, rdf_file)

if __name__ == '__main__':
Expand Down

0 comments on commit 5caa2ba

Please sign in to comment.