mirror of https://github.com/explosion/spaCy.git
* Allow json to be used as a fallback if ujson is not available
This commit is contained in:
parent
9da06671cf
commit
f4809e562f
|
@ -1,7 +1,5 @@
|
||||||
import numpy
|
import numpy
|
||||||
import codecs
|
import codecs
|
||||||
import json
|
|
||||||
import ujson
|
|
||||||
import random
|
import random
|
||||||
import re
|
import re
|
||||||
import os
|
import os
|
||||||
|
@ -9,6 +7,11 @@ from os import path
|
||||||
|
|
||||||
from libc.string cimport memset
|
from libc.string cimport memset
|
||||||
|
|
||||||
|
try:
|
||||||
|
import ujson as json
|
||||||
|
except ImportError:
|
||||||
|
import json
|
||||||
|
|
||||||
|
|
||||||
def tags_to_entities(tags):
|
def tags_to_entities(tags):
|
||||||
entities = []
|
entities = []
|
||||||
|
@ -128,7 +131,7 @@ def read_json_file(loc, docs_filter=None):
|
||||||
yield from read_json_file(path.join(loc, filename))
|
yield from read_json_file(path.join(loc, filename))
|
||||||
else:
|
else:
|
||||||
with open(loc) as file_:
|
with open(loc) as file_:
|
||||||
docs = ujson.load(file_)
|
docs = json.load(file_)
|
||||||
for doc in docs:
|
for doc in docs:
|
||||||
if docs_filter is not None and not docs_filter(doc):
|
if docs_filter is not None and not docs_filter(doc):
|
||||||
continue
|
continue
|
||||||
|
|
Loading…
Reference in New Issue