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



1223
1224
1225
1226
# File 'lib/ruby-spacy.rb', line 1223

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.



1278
1279
1280
# File 'lib/ruby-spacy.rb', line 1278

def method_missing(name, *args)
  Spacy.safe_py_send(@py_lexeme, 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



1215
1216
1217
# File 'lib/ruby-spacy.rb', line 1215

def py_lexeme
  @py_lexeme
end

#textString (readonly)

Returns a string representing the token.

Returns:

  • (String)

    a string representing the token



1218
1219
1220
# File 'lib/ruby-spacy.rb', line 1218

def text
  @text
end

Instance Method Details

#instance_variables_to_inspectObject



1286
1287
1288
# File 'lib/ruby-spacy.rb', line 1286

def instance_variables_to_inspect
  [:@text]
end

#langString

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

Returns:

  • (String)


1248
1249
1250
# File 'lib/ruby-spacy.rb', line 1248

def lang
  @py_lexeme.lang_
end

#lowerString

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

Returns:

  • (String)


1236
1237
1238
# File 'lib/ruby-spacy.rb', line 1236

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)


1266
1267
1268
# File 'lib/ruby-spacy.rb', line 1266

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)


1254
1255
1256
# File 'lib/ruby-spacy.rb', line 1254

def prefix
  @py_lexeme.prefix_
end

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

Returns:

  • (Boolean)


1282
1283
1284
# File 'lib/ruby-spacy.rb', line 1282

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)


1242
1243
1244
# File 'lib/ruby-spacy.rb', line 1242

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)


1273
1274
1275
# File 'lib/ruby-spacy.rb', line 1273

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)


1260
1261
1262
# File 'lib/ruby-spacy.rb', line 1260

def suffix
  @py_lexeme.suffix_
end

#to_sString

String representation of the token.

Returns:

  • (String)


1230
1231
1232
# File 'lib/ruby-spacy.rb', line 1230

def to_s
  @text
end