Skip to content

Commit

Permalink
Merge pull request #78 from NatLibFi/fix-ntriples-parser
Browse files Browse the repository at this point in the history
Work around N-Triples parser issue by using N3 parser instead
  • Loading branch information
osma committed Nov 4, 2020
2 parents efc249f + 66f3575 commit 48f806c
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions skosify/rdftools/io.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import sys

from rdflib import Graph
from rdflib.util import guess_format


def read_rdf(sources, infmt):
Expand All @@ -30,13 +31,15 @@ def read_rdf(sources, infmt):
fmt = infmt
else:
# determine format based on file extension
fmt = 'xml' # default
if source.endswith('n3'):
fmt = 'n3'
if source.endswith('ttl'):
fmt = 'n3'
if source.endswith('nt'):
fmt = 'nt'
fmt = guess_format(source)
if not fmt:
fmt = 'xml' # default

if fmt == 'nt' and sys.version_info[0] >= 3:
# Avoid using N-Triples parser on Python 3
# due to rdflib issue https://github.com/RDFLib/rdflib/issues/1144
# A workaround is to use N3 parser instead
fmt = 'n3'

logging.debug("Parsing input file %s (format: %s)", source, fmt)
rdf.parse(f, format=fmt)
Expand Down

0 comments on commit 48f806c

Please sign in to comment.