Class: Treat::Workers::Lexicalizers::Categorizers::FromTag

Inherits:
Object
  • Object
show all
Defined in:
lib/treat/workers/lexicalizers/categorizers/from_tag.rb

Overview

4) Xue and Palmer. 2008. Annotating the Propositions in the Penn Chinese Treebank. University of Pennsylvania, Department of Computer Information and Science.

Constant Summary collapse

Pttc =
Treat.tags.aligned.phrase_tags_to_category
Wttc =
Treat.tags.aligned.word_tags_to_category
Ptc =
Treat.linguistics.punctuation.punct_to_category

Class Method Summary collapse

Class Method Details

.category(entity, options = {}) ⇒ Object

Find the category of the entity from its tag.



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# File 'lib/treat/workers/lexicalizers/categorizers/from_tag.rb', line 27

def self.category(entity, options = {})

  tag = entity.check_has(:tag)
  
  return 'unknown' if tag.nil? || tag == ''
  return 'fragment' if tag == 'F'
  return 'sentence' if tag == 'S'
  return 'number' if entity.type == :number
  
  return Ptc[entity.to_s] if entity.type == :punctuation
  
  if entity.is_a?(Treat::Entities::Phrase)
    cat = Pttc[tag]
    cat = Wttc[tag] unless cat
  else
    cat = Wttc[tag]
  end

  return :unknown if cat == nil
  
  ts = nil
  
  if entity.has?(:tag_set)
    ts = entity.get(:tag_set)
  else
    a = entity.ancestor_with_feature(:tag_set)
    if a
      ts = a.get(:tag_set)
    else
      raise Treat::Exception,
      "No information can be found regarding "+
      "which tag set to use."
    end
  end

  if cat[ts]
    return cat[ts]
  else
    raise Treat::Exception,
    "The specified tag set (#{ts})" +
    " does not contain the tag #{tag} " +
    "for token #{entity.to_s}."
  end

  'unknown'

end