Class: Semr::Language
Class Method Summary
collapse
Instance Method Summary
collapse
#as_class, #as_fixnum, #as_list, #as_list_of_classes, #by_removing_outer_quotes, #each_item, #lookup_synonyms
#all_models, #any_number, #any_word, #multiple_occurrences_of, #word, #words_in_quotes
Class Method Details
.create(grammer_file = nil, &block) ⇒ Object
8
9
10
11
12
13
|
# File 'lib/semr/language.rb', line 8
def create(grammer_file = nil, &block)
language = Language.new
language.instance_eval(&block) if block_given?
language.instance_eval(IO.readlines(grammer_file).join("\n")) unless grammer_file.nil?
language
end
|
Instance Method Details
#concept(keyword, definition, options = {}) ⇒ Object
24
25
26
|
# File 'lib/semr/language.rb', line 24
def concept(keyword, definition, options = {})
concepts[keyword] = Concept.new(keyword, definition, options)
end
|
#concepts ⇒ Object
16
17
18
|
# File 'lib/semr/language.rb', line 16
def concepts
@concepts ||= {}
end
|
#parse(statement) ⇒ Object
32
33
34
35
36
37
38
39
40
41
42
43
44
45
|
# File 'lib/semr/language.rb', line 32
def parse(statement)
translation = Translation.new
statements = statement.split('.').map{|stmt| stmt.strip } statements.each do |statement|
phrases.each do |phrase|
if phrase.handles?(statement)
translation.phrases_translated << phrase
phrase.interpret(statement, translation)
break end
end
end
translation
end
|
#phrase(phrase, &block) ⇒ Object
28
29
30
|
# File 'lib/semr/language.rb', line 28
def phrase(phrase, &block)
phrases << Phrase.new(concepts, phrase, &block)
end
|
#phrases ⇒ Object
20
21
22
|
# File 'lib/semr/language.rb', line 20
def phrases
@phrases ||= []
end
|