From 5fe5e6e66b3d3770214264671bf2c46315abd1c1 Mon Sep 17 00:00:00 2001 From: Matthew Honnibal Date: Sun, 7 Dec 2014 21:59:04 +1100 Subject: [PATCH] * Move context functions to header, inlining them. --- spacy/context.pxd | 17 ++++++++++++++++- spacy/context.pyx | 15 --------------- 2 files changed, 16 insertions(+), 16 deletions(-) diff --git a/spacy/context.pxd b/spacy/context.pxd index 3dd842b6e..3c7764846 100644 --- a/spacy/context.pxd +++ b/spacy/context.pxd @@ -46,4 +46,19 @@ cpdef enum: N_FIELDS -cdef int fill_context(atom_t[N_FIELDS] context, const int i, TokenC* tokens) except -1 +cdef inline void fill_context(atom_t* context, const int i, const TokenC* tokens) nogil: + _fill_from_token(&context[P2_sic], &tokens[i-2]) + _fill_from_token(&context[P1_sic], &tokens[i-1]) + _fill_from_token(&context[W_sic], &tokens[i]) + _fill_from_token(&context[N1_sic], &tokens[i+1]) + _fill_from_token(&context[N2_sic], &tokens[i+2]) + + +cdef inline void _fill_from_token(atom_t* context, const TokenC* t) nogil: + context[0] = t.lex.sic + context[1] = t.lex.cluster + context[2] = t.lex.shape + context[3] = t.lex.prefix + context[4] = t.lex.suffix + context[5] = t.pos + context[6] = t.sense diff --git a/spacy/context.pyx b/spacy/context.pyx index c81daef2c..8b1378917 100644 --- a/spacy/context.pyx +++ b/spacy/context.pyx @@ -1,16 +1 @@ -cdef int fill_context(atom_t[N_FIELDS] context, const int i, TokenC* tokens) except -1: - _fill_from_token(&context[P2_sic], &tokens[i-2]) - _fill_from_token(&context[P1_sic], &tokens[i-1]) - _fill_from_token(&context[W_sic], &tokens[i]) - _fill_from_token(&context[N1_sic], &tokens[i+1]) - _fill_from_token(&context[N2_sic], &tokens[i+2]) - -cdef inline void _fill_from_token(atom_t[N_FIELDS] context, const TokenC* t) nogil: - context[0] = t.lex.sic - context[1] = t.lex.cluster - context[2] = t.lex.shape - context[3] = t.lex.prefix - context[4] = t.lex.suffix - context[5] = t.pos - context[6] = t.sense