From a6f401580d34675141b7b6a279f314f4b1a677bc Mon Sep 17 00:00:00 2001 From: Matthew Honnibal Date: Thu, 16 Jul 2015 17:46:11 +0200 Subject: [PATCH] * Add from_array function to Doc. --- spacy/tokens/doc.pyx | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/spacy/tokens/doc.pyx b/spacy/tokens/doc.pyx index eab321561..6bf37cf36 100644 --- a/spacy/tokens/doc.pyx +++ b/spacy/tokens/doc.pyx @@ -370,3 +370,23 @@ cdef class Doc: # Return the merged Python object return self[start] + def from_array(self, attrs, array): + cdef int i + cdef attr_id_t attr_id + cdef TokenC* tokens = self.data + for attr_id in attrs: + if attr_id == HEAD: + for i in range(length): + tokens[i].head = values[i] + elif attr_id == TAG: + for i in range(length): + tokens[i].tag = values[i] + elif attr_id == DEP: + for i in range(length): + tokens[i].dep = values[i] + elif attr_id == ENT_IOB: + for i in range(length): + tokens[i].ent_iob = values[i] + elif attr_id == ENT_TYPE: + for i in range(length): + tokens[i].ent_type = values[i]