ssmd 0.4.0 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 7bf70e02b121cec8728e59ae56a22e8a96024336
4
- data.tar.gz: '00582115495e3b0ccc088f5c268cd367e0602630'
3
+ metadata.gz: 03caaaca94965b74c05fc30c4eeb711f78b533b0
4
+ data.tar.gz: 4f046adf9b9f249dca0a0314c1145a6f3511ef87
5
5
  SHA512:
6
- metadata.gz: f8cfcf7f8f4c809a980970b2e5c9380d7ec798263352896fa27203be998eb4d1cd4a3c57891d7c5e8e257ae76251d29bce00658896cf6df274aa261d03786f33
7
- data.tar.gz: 65aadce5e10d597d1d1c14eca36bd843ad6092f3342910915d5bcf10faca47d751c0f9c0da5763f2e105d4a5c8e0a10ca3c0451f91a6c47d9162d95e89efaf25
6
+ metadata.gz: 2066578aac73b3ac021aa060eeb8d06befdf9fcbcdb70c8782b275d86cb95d1632fcca4bb727bd54def7ae009e8e8ed3bf1930709f78d1291a441b13602b1f5a
7
+ data.tar.gz: 7ab57f41be445fb91b5c1c412b4824710bb81a5bb4fed30be8e251841438ea0e9e5ac41982e5fd0702991e60050404943a9d2307dc9d82b7e73f57fff6234adf
@@ -0,0 +1,25 @@
1
+ require_relative 'annotation'
2
+
3
+ require 'pathname'
4
+
5
+ module SSMD::Annotations
6
+ class SubstitutionAnnotation < Annotation
7
+ attr_reader :text_alias
8
+
9
+ def self.regex
10
+ /sub: ?(.+)/
11
+ end
12
+
13
+ def initialize(text_alias)
14
+ @text_alias = text_alias
15
+ end
16
+
17
+ def wrap(text)
18
+ "<sub alias=\"#{text_alias}\">#{text}</sub>"
19
+ end
20
+
21
+ def combine(annotation)
22
+ self # discard further substitution annotations
23
+ end
24
+ end
25
+ end
@@ -6,3 +6,4 @@ require 'ssmd/annotations/annotation'
6
6
  require 'ssmd/annotations/language_annotation'
7
7
  require 'ssmd/annotations/phoneme_annotation'
8
8
  require 'ssmd/annotations/prosody_annotation'
9
+ require 'ssmd/annotations/substitution_annotation'
@@ -2,19 +2,20 @@ require 'ssmd/processors'
2
2
 
3
3
  module SSMD
4
4
  class Converter
5
- attr_reader :input
5
+ attr_reader :input, :skip
6
6
 
7
7
  def initialize(input, skip: [])
8
8
  @input = input
9
+ @skip = Array(skip)
9
10
 
10
11
  processors.delete_if do |processor|
11
- Array(skip).any? { |name| processor.name =~ /\ASSMD::Processors::#{name}Processor\Z/i }
12
+ self.skip.any? { |name| processor.name =~ /\ASSMD::Processors::#{name}Processor\Z/i }
12
13
  end
13
14
  end
14
15
 
15
16
  def convert
16
17
  result = processors.inject(input.encode(xml: :text)) do |text, processor|
17
- process processor.new, text
18
+ process processor.new(processor_options), text
18
19
  end
19
20
 
20
21
  "<speak>#{result.strip}</speak>"
@@ -22,7 +23,7 @@ module SSMD
22
23
 
23
24
  def strip
24
25
  processors.inject(input) do |text, processor|
25
- process processor.new, text, strip: true
26
+ process processor.new(processor_options), text, strip: true
26
27
  end
27
28
  end
28
29
 
@@ -45,5 +46,9 @@ module SSMD
45
46
  input
46
47
  end
47
48
  end
49
+
50
+ def processor_options
51
+ { skip: skip }
52
+ end
48
53
  end
49
54
  end
@@ -6,6 +6,16 @@ module SSMD::Processors
6
6
  class AnnotationProcessor < Processor
7
7
  attr_reader :annotations
8
8
 
9
+ def initialize(options = {})
10
+ super
11
+
12
+ @annotations = self.class.annotations.dup
13
+
14
+ annotations.delete_if do |annotation|
15
+ Array(options[:skip]).any? { |name| annotation.name =~ /\ASSMD::Annotations::#{name}Annotation\Z/i }
16
+ end
17
+ end
18
+
9
19
  def result
10
20
  _, annotations_text = match.captures
11
21
 
@@ -21,7 +31,11 @@ module SSMD::Processors
21
31
  def self.annotations
22
32
  a = SSMD::Annotations
23
33
 
24
- [a::LanguageAnnotation, a::PhonemeAnnotation, a::ProsodyAnnotation]
34
+ [
35
+ a::LanguageAnnotation, a::PhonemeAnnotation, a::ProsodyAnnotation,
36
+ a::SubstitutionAnnotation
37
+ ]
38
+ .freeze
25
39
  end
26
40
 
27
41
  def ok?
@@ -65,7 +79,7 @@ module SSMD::Processors
65
79
  #
66
80
  # [Guardians of the Galaxy](en-GB, v: +4dB, p: -3%)
67
81
  def regex
68
- %r{
82
+ @regex ||= %r{
69
83
  \[ # opening text
70
84
  ([^\]]+) # annotated text
71
85
  \] # closing text
@@ -80,7 +94,7 @@ module SSMD::Processors
80
94
  end
81
95
 
82
96
  def annotations_regex
83
- self.class.annotations.map(&:regex).join("|")
97
+ annotations.map(&:regex).join("|")
84
98
  end
85
99
 
86
100
  def warnings
@@ -1,6 +1,10 @@
1
1
  module SSMD::Processors
2
2
  class Processor
3
- attr_reader :match
3
+ attr_reader :match, :options
4
+
5
+ def initialize(options = {})
6
+ @options = options
7
+ end
4
8
 
5
9
  def matches?(input)
6
10
  @match = regex.match input
data/lib/ssmd/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module SSMD
2
- VERSION = "0.4.0"
2
+ VERSION = "0.5.0"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ssmd
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Markus Kahl
@@ -110,6 +110,7 @@ files:
110
110
  - lib/ssmd/annotations/language_annotation.rb
111
111
  - lib/ssmd/annotations/phoneme_annotation.rb
112
112
  - lib/ssmd/annotations/prosody_annotation.rb
113
+ - lib/ssmd/annotations/substitution_annotation.rb
113
114
  - lib/ssmd/annotations/xsampa_to_ipa_table.txt
114
115
  - lib/ssmd/converter.rb
115
116
  - lib/ssmd/processors.rb