module DomainVariationsWordnet
WordNet-driven creative domain relabels (vowel drag, synonym swap).
Constants
- MAX_CREATIVE
- MAX_LENGTH_EXTRA
- SYNONYM_LINE
- VOWELS
Public Instance Methods
Source
# File lib/domain_variations_wordnet.rb, line 68 def creative_domains(domain, lookup: default_lookup) host = domain.to_s.downcase labels = host.split(".") return [] if labels.length < 2 results = [] labels.each_with_index do |label, index| next if label.match?(/\A\d+\z/) alternatives = synonym_labels(label, lookup: lookup) + elongated_labels(label) alternatives.each do |alt| next if alt == label rebuilt = labels.dup rebuilt[index] = alt candidate = rebuilt.join(".") next if DomainParse.parse(candidate)[:error] results << candidate end end results.uniq.take(MAX_CREATIVE) rescue StandardError [] end
Source
# File lib/domain_variations_wordnet.rb, line 15 def default_lookup DictionaryLookup.method(:default_run) end
Source
# File lib/domain_variations_wordnet.rb, line 19 def elongated_labels(label) text = label.to_s.downcase return [] if text.empty? || text.match?(/\A\d+\z/) results = [] text.chars.each_with_index do |char, index| next unless VOWELS.include?(char) elongated = text.dup.insert(index + 1, char) next unless elongated.length <= text.length + 1 results << elongated end results.uniq end
Source
# File lib/domain_variations_wordnet.rb, line 64 def normalize_label(text) text.to_s.downcase.gsub(/[^a-z0-9-]/, "").gsub(/\A-+|-+\z/, "") end
Source
# File lib/domain_variations_wordnet.rb, line 47 def parse_synonym_tokens(output, max_length:) tokens = [] output.to_s.each_line do |line| match = line.strip.match(SYNONYM_LINE) next unless match match[1].split(",").each do |piece| token = normalize_label(piece) next if token.empty? next if token.length > max_length tokens << token end end tokens.uniq end
Source
# File lib/domain_variations_wordnet.rb, line 35 def synonym_labels(label, lookup: default_lookup) text = label.to_s.downcase return [] if text.empty? || text.match?(/\A\d+\z/) output, status = DictionaryLookup.run_lookup(text, ["-synsn"], run: lookup) return [] if DictionaryLookup.wn_miss?(output, status) parse_synonym_tokens(output, max_length: text.length + MAX_LENGTH_EXTRA) rescue StandardError [] end