Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit b6cb619

Browse files
committed
Fix perceptron.py
1 parent b448a78 commit b6cb619

1 file changed

Lines changed: 8 additions & 2 deletions

File tree

nltk/tag/perceptron.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
import json
1212
import logging
13+
import os
1314
import random
1415
from collections import defaultdict
1516
from os.path import join as path_join
@@ -279,8 +280,13 @@ def load_from_json(self, lang="eng", loc=None):
279280
if loc is None:
280281
loc = find(f"taggers/averaged_perceptron_tagger_{lang}/")
281282
elif isinstance(loc, str):
282-
# Backward compatible: strings are treated as resource names and resolved via find()
283-
loc = find(loc)
283+
# Backward compatible:
284+
# - absolute paths are explicit filesystem locations
285+
# - relative strings are treated as NLTK resource names and resolved via find()
286+
if os.path.isabs(loc):
287+
loc = FileSystemPathPointer(loc)
288+
else:
289+
loc = find(loc)
284290
elif isinstance(loc, Path):
285291
# Explicit filesystem path
286292
loc = FileSystemPathPointer(str(loc))

0 commit comments

Comments
 (0)