Class: StyleScanner::TaggedWord

Inherits:
Object
  • Object
show all
Defined in:
lib/style_scanner/tagged_word.rb

Constant Summary collapse

STRUCTURAL_TAGS =

TODO add tests for all the new methods added here.

%{
  WRB WPS WP WDT UH TO SYM PRPS CC DET EX IN LS PDT POS PRP PRPS
}

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(tag, word) ⇒ TaggedWord

Returns a new instance of TaggedWord.



11
12
13
14
# File 'lib/style_scanner/tagged_word.rb', line 11

def initialize(tag, word)
  @tag = tag.upcase
  @word = word 
end

Instance Attribute Details

#tagObject (readonly)

Returns the value of attribute tag.



9
10
11
# File 'lib/style_scanner/tagged_word.rb', line 9

def tag
  @tag
end

#wordObject (readonly)

Returns the value of attribute word.



9
10
11
# File 'lib/style_scanner/tagged_word.rb', line 9

def word
  @word
end

Instance Method Details

#==(string) ⇒ Object



16
17
18
# File 'lib/style_scanner/tagged_word.rb', line 16

def ==(string)
  word == string
end

#adverb?Boolean

Returns:

  • (Boolean)


24
25
26
# File 'lib/style_scanner/tagged_word.rb', line 24

def adverb?
  tag.start_with?("RB")
end

#be_verb?Boolean

Returns:

  • (Boolean)


48
49
50
# File 'lib/style_scanner/tagged_word.rb', line 48

def be_verb?
  verb? && ["is", "was", "been", "be"].include?(tokenized) 
end

#determiner?Boolean

Returns:

  • (Boolean)


32
33
34
# File 'lib/style_scanner/tagged_word.rb', line 32

def determiner?
  tag.start_with?("DET")
end

#gerund_verb?Boolean

Gerund verb = ING verb

Returns:

  • (Boolean)


58
59
60
# File 'lib/style_scanner/tagged_word.rb', line 58

def gerund_verb?
  tag == "VBG" && tokenized != "being"
end

#non_structural?Boolean

Returns:

  • (Boolean)


36
37
38
# File 'lib/style_scanner/tagged_word.rb', line 36

def non_structural?
  ! STRUCTURAL_TAGS.include?(tag)
end

#noun?Boolean

Returns:

  • (Boolean)


44
45
46
# File 'lib/style_scanner/tagged_word.rb', line 44

def noun?
  tag.start_with?("NN")
end

#possessive?Boolean

Returns:

  • (Boolean)


40
41
42
# File 'lib/style_scanner/tagged_word.rb', line 40

def possessive?
  ["POS", "PRP", "PRPS"].include?(tag)
end

#preposition?Boolean

Returns:

  • (Boolean)


28
29
30
# File 'lib/style_scanner/tagged_word.rb', line 28

def preposition?
  tag.start_with?("IN")
end

#tokenizedObject



20
21
22
# File 'lib/style_scanner/tagged_word.rb', line 20

def tokenized
  word.downcase.gsub(/\W/, "")
end

#verb?Boolean

Returns:

  • (Boolean)


52
53
54
55
# File 'lib/style_scanner/tagged_word.rb', line 52

def verb?
  # account for modal verbs like may
  tag.start_with?("V") || tag == "MD"
end