Skip to content

Commit

Permalink
FIX: correctly handle plus signs in dbpedia URIs
Browse files Browse the repository at this point in the history
  • Loading branch information
Nicolas Heist committed Jan 4, 2021
1 parent 16cfbee commit 1a2311c
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
6 changes: 3 additions & 3 deletions impl/util/rdf.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,15 +57,15 @@ def parse_triples_from_file(filepath: str) -> Iterator[Triple]:
object_triple = object_pattern.match(line)
if object_triple:
[sub, pred, obj] = object_triple.groups()
sub = urllib.parse.unquote_plus(sub.decode('utf-8'))
sub = urllib.parse.unquote(sub.decode('utf-8'))
pred = pred.decode('utf-8')
obj = urllib.parse.unquote_plus(obj.decode('utf-8'))
obj = urllib.parse.unquote(obj.decode('utf-8'))
yield Triple(sub=sub, pred=pred, obj=obj)
else:
literal_triple = literal_pattern.match(line)
if literal_triple:
[sub, pred, obj] = literal_triple.groups()
sub = urllib.parse.unquote_plus(sub.decode('utf-8'))
sub = urllib.parse.unquote(sub.decode('utf-8'))
yield Triple(sub=sub, pred=pred.decode('utf-8'), obj=obj.decode('utf-8'))


Expand Down
6 changes: 3 additions & 3 deletions impl/util/serialize.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
int: 'http://www.w3.org/2001/XMLSchema#integer',
datetime.datetime: 'http://www.w3.org/2001/XMLSchema#date'
}
RESOURCE_ENCODING_EXCEPTIONS = ['#', ':', ',', ';', '(', ')', '\'', '&', '!', '*', '+', '=', '$']
RESOURCE_ENCODING_EXCEPTIONS = ['#', ':', ',', ';', '(', ')', '\'', '&', '!', '*', '=', '$']
LITERAL_ENCODED_CHARS = ['\\', '\'', '"']


Expand Down Expand Up @@ -52,9 +52,9 @@ def _resource_to_string(resource: str) -> str:


def _encode_resource(resource: str) -> str:
res_name = urllib.parse.quote_plus(resource)
res_name = urllib.parse.quote(resource)
for char in RESOURCE_ENCODING_EXCEPTIONS:
res_name = res_name.replace(urllib.parse.quote_plus(char), char)
res_name = res_name.replace(urllib.parse.quote(char), char)
return res_name


Expand Down

0 comments on commit 1a2311c

Please sign in to comment.