mirror of
https://github.com/explosion/spaCy.git
synced 2024-12-24 17:06:29 +03:00
Make doc.from_array() consistent with doc.to_array(). Closes #3382
This commit is contained in:
parent
0426689db8
commit
4e80fc41ad
|
@ -737,6 +737,18 @@ cdef class Doc:
|
||||||
|
|
||||||
DOCS: https://spacy.io/api/doc#from_array
|
DOCS: https://spacy.io/api/doc#from_array
|
||||||
"""
|
"""
|
||||||
|
# Handle scalar/list inputs of strings/ints for py_attr_ids
|
||||||
|
# See also #3064
|
||||||
|
if isinstance(attrs, basestring_):
|
||||||
|
# Handle inputs like doc.to_array('ORTH')
|
||||||
|
attrs = [attrs]
|
||||||
|
elif not hasattr(attrs, "__iter__"):
|
||||||
|
# Handle inputs like doc.to_array(ORTH)
|
||||||
|
attrs = [attrs]
|
||||||
|
# Allow strings, e.g. 'lemma' or 'LEMMA'
|
||||||
|
attrs = [(IDS[id_.upper()] if hasattr(id_, "upper") else id_)
|
||||||
|
for id_ in attrs]
|
||||||
|
|
||||||
if SENT_START in attrs and HEAD in attrs:
|
if SENT_START in attrs and HEAD in attrs:
|
||||||
raise ValueError(Errors.E032)
|
raise ValueError(Errors.E032)
|
||||||
cdef int i, col
|
cdef int i, col
|
||||||
|
|
Loading…
Reference in New Issue
Block a user