Class: EstraierPure::Document

Inherits:
Object
  • Object
show all
Defined in:
lib/vendor/estraierpure.rb

Overview


++ Abstraction of document.


Instance Method Summary collapse

Instance Method Details

#add_attr(name, value) ⇒ Object

Add an attribute. ‘name’ specifies the name of an attribute. ‘value’ specifies the value of the attribute. If it is ‘nil’, the attribute is removed. The return value is always ‘nil’.



53
54
55
56
57
58
59
60
61
# File 'lib/vendor/estraierpure.rb', line 53

def add_attr(name, value)
  Utility::check_types({ name=>String, value=>String }) if $DEBUG
  name = name.gsub(/[ \t\r\n\v\f]+/, " ")
  name = name.strip.squeeze(" ")
  value = value.gsub(/[ \t\r\n\v\f]+/, " ")
  value = value.strip.squeeze(" ")
  @attrs[name] = value
  nil
end

#add_hidden_text(text) ⇒ Object

Add a hidden sentence. ‘text’ specifies a hidden sentence. The return value is always ‘nil’.



75
76
77
78
79
80
81
# File 'lib/vendor/estraierpure.rb', line 75

def add_hidden_text(text)
  Utility::check_types({ text=>String }) if $DEBUG
  text = text.gsub(/[ \t\r\n\v\f]+/, " ")
  text = text.strip.squeeze(" ")
  @htexts.push(text) if text.length
  nil
end

#add_text(text) ⇒ Object

Add a sentence of text. ‘text’ specifies a sentence of text. The return value is always ‘nil’.



65
66
67
68
69
70
71
# File 'lib/vendor/estraierpure.rb', line 65

def add_text(text)
  Utility::check_types({ text=>String }) if $DEBUG
  text = text.gsub(/[ \t\r\n\v\f]+/, " ")
  text = text.strip.squeeze(" ")
  @dtexts.push(text) if text.length
  nil
end

#attr(name) ⇒ Object

Get the value of an attribute. ‘name’ specifies the name of an attribute. The return value is the value of the attribute or ‘nil’ if it does not exist.



104
105
106
107
# File 'lib/vendor/estraierpure.rb', line 104

def attr(name)
  Utility::check_types({ name=>String }) if $DEBUG
  @attrs[name]
end

#attr_namesObject

Get a list of attribute names of a document object. The return value is a list object of attribute names.



98
99
100
# File 'lib/vendor/estraierpure.rb', line 98

def attr_names()
  @attrs.keys.sort
end

#cat_textsObject

Concatenate sentences of the text of a document object. The return value is concatenated sentences.



115
116
117
118
119
120
121
122
# File 'lib/vendor/estraierpure.rb', line 115

def cat_texts()
  buf = StringIO::new
  for i in 0...@dtexts.length
    buf.write(" ") if i > 0
    buf.write(@dtexts[i])
  end
  buf.string
end

#dump_draftObject

Dump draft data of a document object. The return value is draft data.



125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
# File 'lib/vendor/estraierpure.rb', line 125

def dump_draft()
  buf = StringIO::new
  keys = @attrs.keys.sort
  for i in 0...keys.length
    buf.printf("%s=%s\n", keys[i], @attrs[keys[i]])
  end
  if @kwords
    buf.printf("%%VECTOR");
    @kwords.each() do |key, value|
      buf.printf("\t%s\t%s", key, value);
    end
    buf.printf("\n");
  end
  buf.printf("\n")
  for i in 0...@dtexts.length
    buf.printf("%s\n", @dtexts[i])
  end
  for i in 0...@htexts.length
    buf.printf("\t%s\n", @htexts[i])
  end
  buf.string
end

#idObject

Get the ID number. The return value is the ID number of the document object. If the object has never been registered, -1 is returned.



93
94
95
# File 'lib/vendor/estraierpure.rb', line 93

def id()
  @id
end

#keywordsObject

Get attached keywords. The return value is a map object of keywords and their scores in decimal string. If no keyword is attached, ‘nil’ is returned.



150
151
152
# File 'lib/vendor/estraierpure.rb', line 150

def keywords()
  @kwords
end

#set_keywords(kwords) ⇒ Object

Attache keywords. ‘kwords’ specifies a map object of keywords. Keys of the map should be keywords of the document and values should be their scores in decimal string. The return value is always ‘nil’.



86
87
88
89
# File 'lib/vendor/estraierpure.rb', line 86

def set_keywords(kwords)
  Utility::check_types({ kwords=>Hash }) if $DEBUG
  @kwords = kwords
end

#textsObject

Get a list of sentences of the text. The return value is a list object of sentences of the text.



110
111
112
# File 'lib/vendor/estraierpure.rb', line 110

def texts()
  @dtexts
end