From e23d1582a2ee10e5f17f044ce4461d9e13faf385 Mon Sep 17 00:00:00 2001 From: Matthew Honnibal Date: Wed, 1 Jul 2015 18:50:37 +0200 Subject: [PATCH] * Add supersense data to Lexeme objects. Add simple has_sense method to check the flag. --- spacy/lexeme.pyx | 8 +++++++- spacy/structs.pxd | 1 + 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/spacy/lexeme.pyx b/spacy/lexeme.pyx index d66161c83..ebbc6e010 100644 --- a/spacy/lexeme.pyx +++ b/spacy/lexeme.pyx @@ -6,7 +6,7 @@ from murmurhash.mrmr cimport hash64 from libc.string cimport memset from .orth cimport word_shape -from .typedefs cimport attr_t +from .typedefs cimport attr_t, flags_t import numpy @@ -28,6 +28,9 @@ cdef int set_lex_struct_props(LexemeC* lex, dict props, StringStore string_store lex.sentiment = props['sentiment'] lex.flags = props['flags'] + cdef flags_t sense_id + for sense_id in props.get('senses', []): + lex.senses |= 1 << sense_id lex.repvec = empty_vec @@ -46,3 +49,6 @@ cdef class Lexeme: cpdef bint check(self, attr_id_t flag_id) except -1: return self.flags & (1 << flag_id) + + cpdef bint has_sense(self, flags_t flag_id) except -1: + return self.senses & (1 << flag_id) diff --git a/spacy/structs.pxd b/spacy/structs.pxd index a26c87e2f..418d6cc5c 100644 --- a/spacy/structs.pxd +++ b/spacy/structs.pxd @@ -8,6 +8,7 @@ cdef struct LexemeC: const float* repvec flags_t flags + flags_t senses attr_t id attr_t length