Class: Langue::Japanese::Noun

Inherits:
Word
  • Object
show all
Extended by:
Classifier
Defined in:
lib/langue/japanese/words/noun.rb

Direct Known Subclasses

AdjectiveNoun, Pronoun

Constant Summary collapse

INHIBITED_FIRST_CHARS =
%w(ぁ ァ ぃ ィ ぅ ゥ ぇ ェ ぉ ォ っ ッ ー)
INHIBITED_LAST_CHARS =
%w(

Class Method Summary collapse

Methods included from Classifier

body_adjective?, body_verb?, first_adjective?, first_noun?, first_verb?, following_adjective?, following_noun?, following_symbol?, following_verb?, progressive_verb?, suru_verb?

Class Method Details

.take(morphemes, index) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
# File 'lib/langue/japanese/words/noun.rb', line 14

def take(morphemes, index)
  if first_noun?(morphemes, index)
    take_noun(morphemes, index)
  elsif noun_prefix?(morphemes, index)
    take_noun_with_prefix(morphemes, index)
  elsif adverbable_noun?(morphemes, index)
    take_adverbable_noun(morphemes, index)
  else
    0
  end
end

.take_adverbable_noun(morphemes, index) ⇒ Object



53
54
55
56
57
# File 'lib/langue/japanese/words/noun.rb', line 53

def take_adverbable_noun(morphemes, index)
  size = 0
  size += 1 while adverbable_noun?(morphemes, index + size)
  size
end

.take_noun(morphemes, index) ⇒ Object



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/langue/japanese/words/noun.rb', line 26

def take_noun(morphemes, index)
  return 0 unless first_noun?(morphemes, index)
  all = adjective_stem_noun?(morphemes, index)
  size = 1

  while following_noun?(morphemes, index + size) || following_symbol?(morphemes, index + size)
    all &&= adjective_stem_noun?(morphemes, index + size)
    size += 1
  end

  return 0 if all
  return 0 if noun_conjunct_to_suru?(morphemes, index + size - 1) && suru_verb?(morphemes, index + size)
  first_char = morphemes[index].text[0]
  last_char = morphemes[index + size - 1].text[-1]
  return 0 if INHIBITED_FIRST_CHARS.include?(first_char)
  return 0 if INHIBITED_LAST_CHARS.include?(last_char)
  size
end

.take_noun_with_prefix(morphemes, index) ⇒ Object



45
46
47
48
49
50
51
# File 'lib/langue/japanese/words/noun.rb', line 45

def take_noun_with_prefix(morphemes, index)
  size = 0
  size += 1 while noun_prefix?(morphemes, index + size)
  return 0 unless size > 0
  next_size = take_noun(morphemes, index + size)
  next_size > 0 ? size + next_size : 0
end