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.

Parameters:

  • py_lexeme (Object)

    Python Lexeme object



1067
1068
1069
1070
# File 'lib/ruby-spacy.rb', line 1067

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.



1122
1123
1124
# File 'lib/ruby-spacy.rb', line 1122

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



1059
1060
1061
# File 'lib/ruby-spacy.rb', line 1059

def py_lexeme
  @py_lexeme
end

#textString (readonly)

Returns a string representing the token.

Returns:

  • (String)

    a string representing the token



1062
1063
1064
# File 'lib/ruby-spacy.rb', line 1062

def text
  @text
end

Instance Method Details

#instance_variables_to_inspectObject



1130
1131
1132
# File 'lib/ruby-spacy.rb', line 1130

def instance_variables_to_inspect
  [:@text]
end

#langString

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

Returns:

  • (String)


1092
1093
1094
# File 'lib/ruby-spacy.rb', line 1092

def lang
  @py_lexeme.lang_
end

#lowerString

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

Returns:

  • (String)


1080
1081
1082
# File 'lib/ruby-spacy.rb', line 1080

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)


1110
1111
1112
# File 'lib/ruby-spacy.rb', line 1110

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)


1098
1099
1100
# File 'lib/ruby-spacy.rb', line 1098

def prefix
  @py_lexeme.prefix_
end

#respond_to_missing?(sym, include_private = false) ⇒ Boolean

Returns:

  • (Boolean)


1126
1127
1128
# File 'lib/ruby-spacy.rb', line 1126

def respond_to_missing?(sym, include_private = false)
  Spacy.py_hasattr?(@py_lexeme, sym) || super
end

#shapeString

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

Returns:

  • (String)


1086
1087
1088
# File 'lib/ruby-spacy.rb', line 1086

def shape
  @py_lexeme.shape_
end

#similarity(other) ⇒ Float

Returns a semantic similarity estimate.

Parameters:

  • other (Lexeme)

    the other lexeme to which a similarity estimation is made

Returns:

  • (Float)


1117
1118
1119
# File 'lib/ruby-spacy.rb', line 1117

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)


1104
1105
1106
# File 'lib/ruby-spacy.rb', line 1104

def suffix
  @py_lexeme.suffix_
end

#to_sString

String representation of the token.

Returns:

  • (String)


1074
1075
1076
# File 'lib/ruby-spacy.rb', line 1074

def to_s
  @text
end