Class: Pollex::SemanticField

Inherits:
PollexObject show all
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

Attributes included from PollexClass

#inspectables

Class Method Summary collapse

Instance Method Summary collapse

Methods included from PollexClass

attr_inspector

Methods inherited from PollexObject

#initialize, #inspect

Constructor Details

This class inherits a constructor from Pollex::PollexObject

Instance Attribute Details

#codeObject

Returns the value of attribute code.



6
7
8
# File 'lib/pollex/semantic_field.rb', line 6

def code
  @code
end

#countObject

Returns the value of attribute count.



6
7
8
# File 'lib/pollex/semantic_field.rb', line 6

def count
  @count
end

#nameObject

Returns the value of attribute name.



6
7
8
# File 'lib/pollex/semantic_field.rb', line 6

def name
  @name
end

#pathObject

Returns the value of attribute path.



6
7
8
# File 'lib/pollex/semantic_field.rb', line 6

def path
  @path
end

Class Method Details

.allArray<SemanticField>

Returns all SemanticFields in Pollex.

Returns:



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

.countInteger

Counts the number of SemanticFields within Pollex

Returns:

  • (Integer)

    number of SemanticFields in 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

Parameters:

  • id (Integer)

    ID of SemanticField to find

Returns:



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>

Note:

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.

Parameters:

  • name (String)

    term to search for

Returns:

  • (Array<SemanticField>)

    array of SemanticFields matching the search term



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

#idInteger

Returns Pollex’s internal ID for this SemanticField.

Returns:

  • (Integer)

    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

#reconstructionsArray<Reconstruction>

Returns all Reconstructions corresponding to this SemanticField

Returns:

  • (Array<Reconstruction>)

    array of 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