Class: RSemantic::Document

Inherits:
Object
  • Object
show all
Defined in:
lib/rsemantic/document.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(text, attributes = {}) ⇒ Document

Returns a new instance of Document.



6
7
8
9
10
11
12
13
14
15
# File 'lib/rsemantic/document.rb', line 6

def initialize(text, attributes = {})
  if text.respond_to?(:read)
    @text = text.read
  else
    @text = text
  end

  @attributes = attributes
  @corpora    = []
end

Instance Attribute Details

#attributesObject (readonly)

Returns the value of attribute attributes.



4
5
6
# File 'lib/rsemantic/document.rb', line 4

def attributes
  @attributes
end

#corporaObject (readonly)

Returns the value of attribute corpora.



5
6
7
# File 'lib/rsemantic/document.rb', line 5

def corpora
  @corpora
end

#textObject (readonly)

Returns the value of attribute text.



3
4
5
# File 'lib/rsemantic/document.rb', line 3

def text
  @text
end

Instance Method Details

#[](key) ⇒ Object



21
22
23
# File 'lib/rsemantic/document.rb', line 21

def [](key)
  @attributes[key]
end

#keywords(num = 5) ⇒ Object



35
36
37
# File 'lib/rsemantic/document.rb', line 35

def keywords(num = 5)

end
TODO:

document that it has to be part of at least one corpus



26
27
28
29
30
31
32
33
# File 'lib/rsemantic/document.rb', line 26

def related
  results = {}
  @corpora.each do |corpus|
    results[corpus] = corpus.find_related_document(self)
  end

  results
end

#to_sObject



17
18
19
# File 'lib/rsemantic/document.rb', line 17

def to_s
  "#<%s @attributes=%s>" % [self.class.name, @attributes.inspect]
end