spec/matching_spec.rb
# takes a pattern and list of prefixes/suffixes
# returns a bunch of variants of that pattern embedded
# with each possible prefix/suffix combination, including no prefix/suffix
# returns a list of triplets [variant, i, j] where [i,j] is the start/end of the pattern, inclusive
takes a pattern and list of prefixes/suffixes
returns a bunch of variants of that pattern embedded
with each possible prefix/suffix combination, including no prefix/suffix
returns a list of triplets [variant, i, j] where [i,j] is the start/end of the pattern, inclusive
takes a pattern and list of prefixes / suffixes returns a bunch of variants of that pattern embedded with each possible prefix / suffix combination including no prefix / suffix returns a list of triplets [ variant i j ] where [ i j ] is the start / end of the pattern inclusive
def genpws(pattern, prefixes, suffixes)
  prefixes = prefixes.dup
  suffixes = suffixes.dup
  [prefixes, suffixes].each do |lst|
    lst.unshift "" if !lst.include?("")
  end
  result = []
  prefixes.each do |prefix|
    suffixes.each do |suffix|
      i = prefix.length
      j = prefix.length + pattern.length - 1
      result.push [prefix + pattern + suffix, i, j]
    end
  end
  result
end
def genpws ( pattern , prefixes , suffixes ) prefixes = prefixes . dup suffixes = suffixes . dup [ prefixes , suffixes ] . each do | lst | lst . unshift "" if ! lst . include? ( "" ) end result = [ ] prefixes . each do | prefix | suffixes . each do | suffix | i = prefix . length j = prefix . length + pattern . length - 1 result . push [ prefix + pattern + suffix , i , j ] end end result end
takes a pattern and list of prefixes/suffixes
returns a bunch of variants of that pattern embedded
with each possible prefix/suffix combination, including no prefix/suffix
returns a list of triplets [variant, i, j] where [i,j] is the start/end of the pattern, inclusive
takes a pattern and list of prefixes / suffixes returns a bunch of variants of that pattern embedded with each possible prefix / suffix combination including no prefix / suffix returns a list of triplets [ variant i j ] where [ i j ] is the start / end of the pattern inclusive
pattern
prefixes
suffixes