Class: GrammarCop::Sentence

Inherits:
Object
  • Object
show all
Extended by:
LinkGrammar
Defined in:
lib/grammar_cop/sentence.rb

Class Method Summary collapse

Methods included from LinkGrammar

create_dictionary, create_linkage, create_parse_options, create_sentence, delete_dictionary, delete_linkage, delete_parse_options, delete_sentence, dictionary_path_set, disjunct_cost_get, disjunct_cost_set, islands_ok_get, islands_ok_set, linkage_count_num_links, linkage_count_num_words, linkage_count_sublinkages, linkage_limit_get, linkage_limit_set, max_null_count_get, max_null_count_set, min_null_count_get, min_null_count_set, options_null_block_get, options_null_block_set, parse_sentence, print_linkage_diagram, short_length_get, short_length_set

Class Method Details

.count_linkages(text, dictionary, options) ⇒ Object



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/grammar_cop/sentence.rb', line 18

def self.count_linkages(text, dictionary, options)
  count = 0
  #split sentence up by punctuation to reduce processing time
  text.split(/[\!?,;:']+/).each do |clause|
    c = create_sentence(clause, dictionary)
    count += parse_sentence(c, options)
    delete_sentence(c)
  end
  
  #however, sometimes the split results in all incomplete clause so check one more time in those cases
  #but make sure it's not a really long sentence which will cause link-grammar to choke with combinatorial explosion
  if text.size < 250 and count == 0
    s = create_sentence(text, dictionary)
    count = parse_sentence(s, options)
    delete_sentence(s)
  end
  count
end

.create(text, dictionary) ⇒ Object



6
7
8
# File 'lib/grammar_cop/sentence.rb', line 6

def self.create(text, dictionary)
  create_sentence(text, dictionary)
end

.destroy(sentence) ⇒ Object



14
15
16
# File 'lib/grammar_cop/sentence.rb', line 14

def self.destroy(sentence)
  delete_sentence(sentence)
end

.parse(sentence, options) ⇒ Object



10
11
12
# File 'lib/grammar_cop/sentence.rb', line 10

def self.parse(sentence, options)
  parse_sentence(sentence, options)
end