Class: Spacy::Lexeme
- Inherits:
-
Object
- Object
- Spacy::Lexeme
- Defined in:
- lib/ruby-spacy.rb
Overview
See also spaCy Python API document for Lexeme.
Instance Attribute Summary collapse
-
#py_lexeme ⇒ Object
readonly
A Python
Lexemeinstance accessible viaPyCall. -
#text ⇒ String
readonly
A string representing the token.
Instance Method Summary collapse
-
#initialize(py_lexeme) ⇒ Lexeme
constructor
It is recommended to use Spacy::Language#vocab or Token#lexeme methods to create tokens.
- #instance_variables_to_inspect ⇒ Object
-
#lang ⇒ String
Returns the language by calling
lang_' of@py_lexeme` object. -
#lower ⇒ String
Returns the lowercase form by calling
lower_' of@py_lexeme` object. -
#method_missing(name, *args) ⇒ Object
Methods defined in Python but not wrapped in ruby-spacy can be called by this dynamic method handling mechanism.
-
#norm ⇒ String
Returns the lexemes's norm, i.e.
-
#prefix ⇒ String
Returns the length-N substring from the start of the word by calling
prefix_' of@py_lexeme` object. - #respond_to_missing?(sym, include_private = false) ⇒ Boolean
-
#shape ⇒ String
Returns the shape (e.g. "Xxxxx") by calling
shape_' of@py_lexeme` object. -
#similarity(other) ⇒ Float
Returns a semantic similarity estimate.
-
#suffix ⇒ String
Returns the length-N substring from the end of the word by calling
suffix_' of@py_lexeme` object. -
#to_s ⇒ String
String representation of the token.
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.
1115 1116 1117 1118 |
# File 'lib/ruby-spacy.rb', line 1115 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.
1170 1171 1172 |
# File 'lib/ruby-spacy.rb', line 1170 def method_missing(name, *args) @py_lexeme.send(name, *args) end |
Instance Attribute Details
#py_lexeme ⇒ Object (readonly)
Returns a Python Lexeme instance accessible via PyCall.
1107 1108 1109 |
# File 'lib/ruby-spacy.rb', line 1107 def py_lexeme @py_lexeme end |
#text ⇒ String (readonly)
Returns a string representing the token.
1110 1111 1112 |
# File 'lib/ruby-spacy.rb', line 1110 def text @text end |
Instance Method Details
#instance_variables_to_inspect ⇒ Object
1178 1179 1180 |
# File 'lib/ruby-spacy.rb', line 1178 def instance_variables_to_inspect [:@text] end |
#lang ⇒ String
Returns the language by calling lang_' of @py_lexeme` object
1140 1141 1142 |
# File 'lib/ruby-spacy.rb', line 1140 def lang @py_lexeme.lang_ end |
#lower ⇒ String
Returns the lowercase form by calling lower_' of @py_lexeme` object
1128 1129 1130 |
# File 'lib/ruby-spacy.rb', line 1128 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
1158 1159 1160 |
# File 'lib/ruby-spacy.rb', line 1158 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
1146 1147 1148 |
# File 'lib/ruby-spacy.rb', line 1146 def prefix @py_lexeme.prefix_ end |
#respond_to_missing?(sym, include_private = false) ⇒ Boolean
1174 1175 1176 |
# File 'lib/ruby-spacy.rb', line 1174 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
1134 1135 1136 |
# File 'lib/ruby-spacy.rb', line 1134 def shape @py_lexeme.shape_ end |
#similarity(other) ⇒ Float
Returns a semantic similarity estimate.
1165 1166 1167 |
# File 'lib/ruby-spacy.rb', line 1165 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
1152 1153 1154 |
# File 'lib/ruby-spacy.rb', line 1152 def suffix @py_lexeme.suffix_ end |
#to_s ⇒ String
String representation of the token.
1122 1123 1124 |
# File 'lib/ruby-spacy.rb', line 1122 def to_s @text end |