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



1297
1298
1299
1300
# File 'lib/ruby-spacy.rb', line 1297

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.



1352
1353
1354
# File 'lib/ruby-spacy.rb', line 1352

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

Instance Attribute Details

#py_lexeme ⇒ Object (readonly)

Returns a Python Lexeme instance accessible via PyCall.

Returns:

  • (Object) —

    a Python Lexeme instance accessible via PyCall



1289
1290
1291
# File 'lib/ruby-spacy.rb', line 1289

def py_lexeme
  @py_lexeme
end

#text ⇒ String (readonly)

Returns a string representing the token.

Returns:

  • (String) —

    a string representing the token



1292
1293
1294
# File 'lib/ruby-spacy.rb', line 1292

def text
  @text
end

Instance Method Details

#instance_variables_to_inspect ⇒ Object



1360
1361
1362
# File 'lib/ruby-spacy.rb', line 1360

def instance_variables_to_inspect
  [:@text]
end

#lang ⇒ String

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

Returns:

  • (String)


1322
1323
1324
# File 'lib/ruby-spacy.rb', line 1322

def lang
  @py_lexeme.lang_
end

#lower ⇒ String

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

Returns:

  • (String)


1310
1311
1312
# File 'lib/ruby-spacy.rb', line 1310

def lower
  @py_lexeme.lower_
end

#norm ⇒ String

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

Returns:

  • (String)


1340
1341
1342
# File 'lib/ruby-spacy.rb', line 1340

def norm
  @py_lexeme.norm_
end

#prefix ⇒ String

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

Returns:

  • (String)


1328
1329
1330
# File 'lib/ruby-spacy.rb', line 1328

def prefix
  @py_lexeme.prefix_
end

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

Returns:

  • (Boolean)


1356
1357
1358
# File 'lib/ruby-spacy.rb', line 1356

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

#shape ⇒ String

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

Returns:

  • (String)


1316
1317
1318
# File 'lib/ruby-spacy.rb', line 1316

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)


1347
1348
1349
# File 'lib/ruby-spacy.rb', line 1347

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

#suffix ⇒ String

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

Returns:

  • (String)


1334
1335
1336
# File 'lib/ruby-spacy.rb', line 1334

def suffix
  @py_lexeme.suffix_
end

#to_s ⇒ String

String representation of the token.

Returns:

  • (String)


1304
1305
1306
# File 'lib/ruby-spacy.rb', line 1304

def to_s
  @text
end