Class: Spacy::Lexeme

Inherits:
Object
  • Object
show all
Defined in:
lib/ruby-spacy.rb

Overview

See also spaCy Python API document for [‘Lexeme`](spacy.io/api/lexeme).

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(py_lexeme) ⇒ Lexeme

It is recommended to use Spacy::Language#vocab or Token#lexeme methods to create tokens. There is no way to generate a lexeme from scratch but relying on a pre-exising Python Spacy::Lexeme object.



864
865
866
867
# File 'lib/ruby-spacy.rb', line 864

def initialize(py_lexeme)
  @py_lexeme = py_lexeme
  @text = @py_lexeme.text
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(name, *args) ⇒ Object

Methods defined in Python but not wrapped in ruby-spacy can be called by this dynamic method handling mechanism.



919
920
921
# File 'lib/ruby-spacy.rb', line 919

def method_missing(name, *args)
  @py_lexeme.send(name, *args)
end

Instance Attribute Details

#py_lexemeObject (readonly)



856
857
858
# File 'lib/ruby-spacy.rb', line 856

def py_lexeme
  @py_lexeme
end

#textString (readonly)



859
860
861
# File 'lib/ruby-spacy.rb', line 859

def text
  @text
end

Instance Method Details

#langString

Returns the language by calling ‘lang_’ of ‘@py_lexeme` object



889
890
891
# File 'lib/ruby-spacy.rb', line 889

def lang
  @py_lexeme.lang_
end

#lowerString

Returns the lowercase form by calling ‘lower_’ of ‘@py_lexeme` object



877
878
879
# File 'lib/ruby-spacy.rb', line 877

def lower
  @py_lexeme.lower_
end

#normString

Returns the lexemes’s norm, i.e. a normalized form of the lexeme calling ‘norm_’ of ‘@py_lexeme` object



907
908
909
# File 'lib/ruby-spacy.rb', line 907

def norm
  @py_lexeme.norm_
end

#prefixString

Returns the length-N substring from the start of the word by calling ‘prefix_’ of ‘@py_lexeme` object



895
896
897
# File 'lib/ruby-spacy.rb', line 895

def prefix
  @py_lexeme.prefix_
end

#respond_to_missing?(sym) ⇒ Boolean



923
924
925
# File 'lib/ruby-spacy.rb', line 923

def respond_to_missing?(sym)
  sym ? true : super
end

#shapeString

Returns the shape (e.g. “Xxxxx”) by calling ‘shape_’ of ‘@py_lexeme` object



883
884
885
# File 'lib/ruby-spacy.rb', line 883

def shape
  @py_lexeme.shape_
end

#similarity(other) ⇒ Float

Returns a semantic similarity estimate.



914
915
916
# File 'lib/ruby-spacy.rb', line 914

def similarity(other)
  @py_lexeme.similarity(other.py_lexeme)
end

#suffixString

Returns the length-N substring from the end of the word by calling ‘suffix_’ of ‘@py_lexeme` object



901
902
903
# File 'lib/ruby-spacy.rb', line 901

def suffix
  @py_lexeme.suffix_
end

#to_sString

String representation of the token.



871
872
873
# File 'lib/ruby-spacy.rb', line 871

def to_s
  @text
end