Class: Pollex::SemanticField
- Inherits:
-
PollexObject
- Object
- PollexObject
- Pollex::SemanticField
- Extended by:
- PollexClass
- Defined in:
- lib/pollex/semantic_field.rb
Overview
A semantic class containing a list of Pollex reconstructed protoforms.
Instance Attribute Summary collapse
-
#code ⇒ Object
Returns the value of attribute code.
-
#count ⇒ Object
Returns the value of attribute count.
-
#name ⇒ Object
Returns the value of attribute name.
-
#path ⇒ Object
Returns the value of attribute path.
Attributes included from PollexClass
Class Method Summary collapse
-
.all ⇒ Array<SemanticField>
Returns all SemanticFields in Pollex.
-
.count ⇒ Integer
Counts the number of SemanticFields within Pollex.
-
.find(id) ⇒ SemanticField
Looks up SemanticField corresponding to a given internal ID.
-
.find_by_name(name) ⇒ Array<SemanticField>
Looks up all SemanticFields matching a given name.
Instance Method Summary collapse
-
#id ⇒ Integer
Pollex’s internal ID for this SemanticField.
-
#reconstructions ⇒ Array<Reconstruction>
Returns all Reconstructions corresponding to this SemanticField.
Methods included from PollexClass
Methods inherited from PollexObject
Constructor Details
This class inherits a constructor from Pollex::PollexObject
Instance Attribute Details
#code ⇒ Object
Returns the value of attribute code.
6 7 8 |
# File 'lib/pollex/semantic_field.rb', line 6 def code @code end |
#count ⇒ Object
Returns the value of attribute count.
6 7 8 |
# File 'lib/pollex/semantic_field.rb', line 6 def count @count end |
#name ⇒ Object
Returns the value of attribute name.
6 7 8 |
# File 'lib/pollex/semantic_field.rb', line 6 def name @name end |
#path ⇒ Object
Returns the value of attribute path.
6 7 8 |
# File 'lib/pollex/semantic_field.rb', line 6 def path @path end |
Class Method Details
.all ⇒ Array<SemanticField>
Returns all SemanticFields in Pollex.
27 28 29 30 31 32 33 34 |
# File 'lib/pollex/semantic_field.rb', line 27 def self.all @semantic_fields ||= Scraper.instance.get_all(SemanticField, "/category/", [ [:code, 'td[1]/a/text()'], [:path, 'td[1]/a/@href'], [:name, 'td[2]/a/text()'], [:count, 'td[3]/text()'] ]) end |
.count ⇒ Integer
Counts the number of SemanticFields within Pollex
38 39 40 |
# File 'lib/pollex/semantic_field.rb', line 38 def self.count self.all.count end |
.find(id) ⇒ SemanticField
Looks up SemanticField corresponding to a given internal ID
45 46 47 |
# File 'lib/pollex/semantic_field.rb', line 45 def self.find(id) self.all.select { |sf| sf.id == id }[0] rescue nil end |
.find_by_name(name) ⇒ Array<SemanticField>
Pollex has no built-in search for SemanticFields, so this method is simply a filter over SemanticField.all.
Looks up all SemanticFields matching a given name.
54 55 56 |
# File 'lib/pollex/semantic_field.rb', line 54 def self.find_by_name(name) self.all.select { |sf| sf.name.downcase.include?(name.downcase) } end |
Instance Method Details
#id ⇒ Integer
Returns Pollex’s internal ID for this SemanticField.
10 11 12 |
# File 'lib/pollex/semantic_field.rb', line 10 def id @path.split('/').last.to_i end |
#reconstructions ⇒ Array<Reconstruction>
Returns all Reconstructions corresponding to this SemanticField
16 17 18 19 20 21 22 23 |
# File 'lib/pollex/semantic_field.rb', line 16 def reconstructions @reconstructions ||= Scraper.instance.get_all(Reconstruction, @path, [ [:path, 'td[1]/a/@href'], [:protoform, 'td[1]/a/text()'], [:description, 'td[2]/text()'], [:semantic_field, nil, lambda {|x| self}] ]) end |