Class: Spacy::Lexeme

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

Overview

See also spaCy Python API document for 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.

Parameters:

  • py_lexeme (Object)

    Python Lexeme object



699
700
701
702
# File 'lib/ruby-spacy.rb', line 699

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.



754
755
756
# File 'lib/ruby-spacy.rb', line 754

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

Instance Attribute Details

#py_lexemeObject (readonly)

Returns a Python Lexeme instance accessible via PyCall.

Returns:

  • (Object)

    a Python Lexeme instance accessible via PyCall



691
692
693
# File 'lib/ruby-spacy.rb', line 691

def py_lexeme
  @py_lexeme
end

#textString (readonly)

Returns a string representing the token.

Returns:

  • (String)

    a string representing the token



694
695
696
# File 'lib/ruby-spacy.rb', line 694

def text
  @text
end

Instance Method Details

#langString

Returns the language by calling lang_' of@py_lexeme` object

Returns:

  • (String)


724
725
726
# File 'lib/ruby-spacy.rb', line 724

def lang 
  @py_lexeme.lang_
end

#lowerString

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

Returns:

  • (String)


712
713
714
# File 'lib/ruby-spacy.rb', line 712

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

Returns:

  • (String)


742
743
744
# File 'lib/ruby-spacy.rb', line 742

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

Returns:

  • (String)


730
731
732
# File 'lib/ruby-spacy.rb', line 730

def prefix 
  @py_lexeme.prefix_
end

#shapeString

Returns the shape (e.g. "Xxxxx") by calling shape_' of@py_lexeme` object

Returns:

  • (String)


718
719
720
# File 'lib/ruby-spacy.rb', line 718

def shape
  @py_lexeme.shape_
end

#similarity(other) ⇒ Float

Returns a semantic similarity estimate.

Parameters:

  • other (Lexeme)

    the other doc to which a similarity estimation is made

Returns:

  • (Float)


749
750
751
# File 'lib/ruby-spacy.rb', line 749

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

Returns:

  • (String)


736
737
738
# File 'lib/ruby-spacy.rb', line 736

def suffix
  @py_lexeme.suffix_
end

#to_sString

String representation of the token.

Returns:

  • (String)


706
707
708
# File 'lib/ruby-spacy.rb', line 706

def to_s
  @text
end