Class: SiSU_Sem::Tags

Inherits:
Object
  • Object
show all
Defined in:
lib/sisu/shared_sem.rb

Instance Method Summary collapse

Constructor Details

#initialize(para, md) ⇒ Tags

Returns a new instance of Tags.



60
61
62
# File 'lib/sisu/shared_sem.rb', line 60

def initialize(para,md)
  @para,@md=para,md
end

Instance Method Details

#allObject



145
146
147
148
149
150
151
# File 'lib/sisu/shared_sem.rb', line 145

def all
  if @md.sem_tag
    sem_marker_parts
    sem_marker_added_extra_parts
  end
  @para
end

#each_cObject



70
71
72
# File 'lib/sisu/shared_sem.rb', line 70

def each_c
  /(?:[a-z]+(?:[_:.][a-z]+)+|[a-z]*):\{|\}:[a-z]+(?:[_:.][a-z]+)*/m
end

#each_cscObject



67
68
69
# File 'lib/sisu/shared_sem.rb', line 67

def each_csc
  /(?:;|(?:[a-z]+(?:[_:.][a-z]+)+|[a-z]*):)\{|\}[:;][a-z]+(?:[_:.][a-z]+)*/m
end

#each_csc_aeObject



88
89
90
# File 'lib/sisu/shared_sem.rb', line 88

def each_csc_ae
  /(?:;|(?:[a-z]+(?:[_:.][a-z]+)+)*:|[a-z]*:)\[|\][:;](?:[a-z]+(?:[_:.][a-z]+)+|[a-z]+)/m
end

#each_scObject



73
74
75
# File 'lib/sisu/shared_sem.rb', line 73

def each_sc
  /(?:[a-z]+(?:[_:.][a-z]+)+|[a-z]*);\{|\};[a-z]+(?:[_:.][a-z]+)*/m
end

#excludeObject



64
65
66
# File 'lib/sisu/shared_sem.rb', line 64

def exclude
  /^(?:<:code>|%+ )/
end

#if_pair_cObject



104
105
106
107
108
# File 'lib/sisu/shared_sem.rb', line 104

def if_pair_c
  if @para=~/([a-z](?:[a-z_:.]+?[a-z])?)+(?::\{(.+?)\}:\1)/m
    puts "#{$1}:{ #{$2} }:#{$1}"
  end
end

#if_pair_scObject



109
110
111
112
113
# File 'lib/sisu/shared_sem.rb', line 109

def if_pair_sc
  if @para=~/;\{\s*(.+?)\s*\};([a-z]+(?:[_:.][a-z]+)*)/
    puts ";{ #{$1} };#{$2}"
  end
end

#match_pair_cObject



114
115
116
117
118
# File 'lib/sisu/shared_sem.rb', line 114

def match_pair_c
  matched=[]
  matched=rgx.pair_c.match(@para)[1] if @para =~ rgx.pair_c
  puts matched unless matched.nil?
end

#match_pair_scObject



119
120
121
122
123
# File 'lib/sisu/shared_sem.rb', line 119

def match_pair_sc
  matched=[]
  matched=rgx.pair_sc.match(@para)[1] if @para =~ rgx.pair_sc
  puts matched unless matched.nil?
end

#matchingObject



124
125
126
# File 'lib/sisu/shared_sem.rb', line 124

def matching
  scan_pair_c
end

#pair_cObject



79
80
81
# File 'lib/sisu/shared_sem.rb', line 79

def pair_c
  /(([a-z]+(?:[_:.][a-z]+)*)(?::\{(.+?)\}:\2)|:\{(.+?)\}:[a-z]+(?:[_:.][a-z]+)*)/m
end

#pair_cscObject



76
77
78
# File 'lib/sisu/shared_sem.rb', line 76

def pair_csc
  /(([a-z]+(?:[_:.][a-z]+)+|[a-z]+)(?::\{(.+?)\}:\2)|([:;])\{(.+?)\}\4[a-z]+(?:[_:.][a-z]+)*)/m
end

#pair_scObject



82
83
84
# File 'lib/sisu/shared_sem.rb', line 82

def pair_sc
  /(;\{.+?\};[a-z]+(?:[_:.][a-z]+)*)/m
end


93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
# File 'lib/sisu/shared_sem.rb', line 93

def print
  def scan_pair_c
    if @para =~ rgx.pair_c
      matched=@para.scan(rgx.pair_c).flatten
      puts matched[0] unless matched[0].nil?
    end
  end
  def scan_pair_sc
    matched=@para.scan(rgx.pair_sc).flatten
    puts matched[0] unless matched[0].nil?
  end
  def if_pair_c
    if @para=~/([a-z](?:[a-z_:.]+?[a-z])?)+(?::\{(.+?)\}:\1)/m
      puts "#{$1}:{ #{$2} }:#{$1}"
    end
  end
  def if_pair_sc
    if @para=~/;\{\s*(.+?)\s*\};([a-z]+(?:[_:.][a-z]+)*)/
      puts ";{ #{$1} };#{$2}"
    end
  end
  def match_pair_c
    matched=[]
    matched=rgx.pair_c.match(@para)[1] if @para =~ rgx.pair_c
    puts matched unless matched.nil?
  end
  def match_pair_sc
    matched=[]
    matched=rgx.pair_sc.match(@para)[1] if @para =~ rgx.pair_sc
    puts matched unless matched.nil?
  end
  def matching
    scan_pair_c
  end
  self
end

#rgxObject



63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
# File 'lib/sisu/shared_sem.rb', line 63

def rgx
  def exclude
    /^(?:<:code>|%+ )/
  end
  def each_csc
    /(?:;|(?:[a-z]+(?:[_:.][a-z]+)+|[a-z]*):)\{|\}[:;][a-z]+(?:[_:.][a-z]+)*/m
  end
  def each_c
    /(?:[a-z]+(?:[_:.][a-z]+)+|[a-z]*):\{|\}:[a-z]+(?:[_:.][a-z]+)*/m
  end
  def each_sc
    /(?:[a-z]+(?:[_:.][a-z]+)+|[a-z]*);\{|\};[a-z]+(?:[_:.][a-z]+)*/m
  end
  def pair_csc
    /(([a-z]+(?:[_:.][a-z]+)+|[a-z]+)(?::\{(.+?)\}:\2)|([:;])\{(.+?)\}\4[a-z]+(?:[_:.][a-z]+)*)/m
  end
  def pair_c
    /(([a-z]+(?:[_:.][a-z]+)*)(?::\{(.+?)\}:\2)|:\{(.+?)\}:[a-z]+(?:[_:.][a-z]+)*)/m
  end
  def pair_sc
    /(;\{.+?\};[a-z]+(?:[_:.][a-z]+)*)/m
  end
  def whole_csc_ae
    /(([a-z]+(?:[_.][a-z]+)+|[a-z]*)(?::\[(.+?)\]:\2)|;\{(.+?)\};(?:[a-z]+(?:[_:.][a-z]+)+|[a-z]+)\b)/m
  end
  def each_csc_ae
    /(?:;|(?:[a-z]+(?:[_:.][a-z]+)+)*:|[a-z]*:)\[|\][:;](?:[a-z]+(?:[_:.][a-z]+)+|[a-z]+)/m
  end
  self
end

#rmObject



129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
# File 'lib/sisu/shared_sem.rb', line 129

def rm
  def sem_marker_parts
    unless @para =~ rgx.exclude
      @para.gsub!(rgx.each_csc,'')
    end
    @para
  end
  def sem_marker_added_extra_parts
    unless @para =~ rgx.exclude
      @para.gsub!(rgx.whole_csc_ae,'')
      if @para =~rgx.each_csc_ae
        STDERR.puts "WARNING semantic tagging error: #{@para}"
      end
    end
    @para
  end
  def all
    if @md.sem_tag
      sem_marker_parts
      sem_marker_added_extra_parts
    end
    @para
  end
  self
end

#scan_pair_cObject



94
95
96
97
98
99
# File 'lib/sisu/shared_sem.rb', line 94

def scan_pair_c
  if @para =~ rgx.pair_c
    matched=@para.scan(rgx.pair_c).flatten
    puts matched[0] unless matched[0].nil?
  end
end

#scan_pair_scObject



100
101
102
103
# File 'lib/sisu/shared_sem.rb', line 100

def scan_pair_sc
  matched=@para.scan(rgx.pair_sc).flatten
  puts matched[0] unless matched[0].nil?
end

#sem_marker_added_extra_partsObject



136
137
138
139
140
141
142
143
144
# File 'lib/sisu/shared_sem.rb', line 136

def sem_marker_added_extra_parts
  unless @para =~ rgx.exclude
    @para.gsub!(rgx.whole_csc_ae,'')
    if @para =~rgx.each_csc_ae
      STDERR.puts "WARNING semantic tagging error: #{@para}"
    end
  end
  @para
end

#sem_marker_partsObject



130
131
132
133
134
135
# File 'lib/sisu/shared_sem.rb', line 130

def sem_marker_parts
  unless @para =~ rgx.exclude
    @para.gsub!(rgx.each_csc,'')
  end
  @para
end

#whole_csc_aeObject



85
86
87
# File 'lib/sisu/shared_sem.rb', line 85

def whole_csc_ae
  /(([a-z]+(?:[_.][a-z]+)+|[a-z]*)(?::\[(.+?)\]:\2)|;\{(.+?)\};(?:[a-z]+(?:[_:.][a-z]+)+|[a-z]+)\b)/m
end