Permalink
Browse files

Initial commit

  • Loading branch information...
0 parents commit 7d7bc93423ec8a4f221a4f8a4c40cd8560073bbf @brymck committed Apr 12, 2012
Showing with 251 additions and 0 deletions.
  1. +19 −0 .gitignore
  2. +4 −0 Gemfile
  3. +22 −0 LICENSE
  4. +40 −0 README.md
  5. +2 −0 Rakefile
  6. +11 −0 bin/transcribe
  7. +7 −0 lib/transcribe.rb
  8. +26 −0 lib/transcribe/language.rb
  9. +65 −0 lib/transcribe/language/dutch.yml
  10. +34 −0 lib/transcribe/term.rb
  11. +4 −0 lib/transcribe/version.rb
  12. +17 −0 transcribe.gemspec
@@ -0,0 +1,19 @@
+# See http://help.github.com/ignore-files/ for more about ignoring files.
+#
+# If you find yourself ignoring temporary files generated by your text editor
+# or operating system, you probably want to add a global ignore instead:
+# git config --global core.excludesfile ~/.gitignore_global
+
+# Ignore OS X garbage
+.DS_Store
+
+# Ignore bundler config
+/.bundle
+
+# Ignore the default SQLite database.
+/db/*.sqlite3
+
+# Ignore all logfiles and tempfiles.
+/log/*.log
+/tmp
+/pkg
@@ -0,0 +1,4 @@
+source 'https://rubygems.org'
+
+# Specify your gem's dependencies in transcribe.gemspec
+gemspec
@@ -0,0 +1,22 @@
+Copyright (c) 2012 Bryan McKelvey
+
+MIT License
+
+Permission is hereby granted, free of charge, to any person obtaining
+a copy of this software and associated documentation files (the
+"Software"), to deal in the Software without restriction, including
+without limitation the rights to use, copy, modify, merge, publish,
+distribute, sublicense, and/or sell copies of the Software, and to
+permit persons to whom the Software is furnished to do so, subject to
+the following conditions:
+
+The above copyright notice and this permission notice shall be
+included in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,40 @@
+# Transcribe
+
+Transcribes a language into IPA
+
+## Installation
+
+Add this line to your application's Gemfile:
+
+ gem 'transcribe'
+
+And then execute:
+
+ bundle
+
+Or install it yourself as:
+
+ gem install transcribe
+
+## Usage
+
+Transcribe a phrase:
+
+ transcribe dutch "hallo mensen"
+ # => ɦɑlɔ mɛnsɛn
+
+Transcribe a file:
+
+ transcribe dutch hello_world.txt
+
+Write transcription to a file
+
+ transcribe dutch "hallo mensen" > hello_world.txt
+
+## Contributing
+
+1. Fork it
+2. Create your feature branch (`git checkout -b my-new-feature`)
+3. Commit your changes (`git commit -am 'Added some feature'`)
+4. Push to the branch (`git push origin my-new-feature`)
+5. Create new Pull Request
@@ -0,0 +1,2 @@
+#!/usr/bin/env rake
+require "bundler/gem_tasks"
@@ -0,0 +1,11 @@
+#!/usr/bin/env ruby -wKU
+require "transcribe"
+
+language_name, file = ARGV
+
+# Grab text from file if it exists, using text otherwise. We need to duplicate that text if we're
+# using it because it's immutable.
+text = File.exist?(file) ? File.read(file).downcase : file.dup
+
+language = Transcribe::Language.new(language_name)
+puts language.transcribe(text)
@@ -0,0 +1,7 @@
+# coding: utf-8
+require "transcribe/language"
+require "transcribe/term"
+require "transcribe/version"
+
+module Transcribe
+end
@@ -0,0 +1,26 @@
+# coding: utf-8
+require "transcribe/term"
+require "yaml"
+
+module Transcribe
+ class Language
+ def initialize(name)
+ @name = name
+ load_yaml(@name)
+ end
+
+ def transcribe(text)
+ @terms.each { |t| t.apply! text }
+ text
+ end
+
+ private
+
+ def load_yaml(name)
+ @terms = []
+ path = File.join(File.expand_path(File.dirname(__FILE__)), "language", "#{name}.yml")
+ yaml = YAML.load_file(path)
+ yaml.each { |t| @terms << Term.create_from_yaml(t) }
+ end
+ end
+end
@@ -0,0 +1,65 @@
+---
+# VOWELS
+# Diphthongs
+- auw: ʌu
+- aa:
+- ei: ɛi
+- ee:
+- eu: øː
+- ie: i
+- ij: ɛi
+- oe: u
+- oo:
+- ui: œy
+- uu:
+
+# Monophthongs
+- a: ɑ
+- e: ɛ
+- i: ɪ
+- o: ɔ
+- u: ʏ
+
+# CONSONANTS
+# Diphthongs
+- sch: sx
+- ch: x
+- ck: k
+- ng: ŋ
+- nj: nj
+- sj: ʃ
+- tj: tj
+
+# Special
+- b: p
+ word_final: true
+- d: t
+ word_final: true
+- g: x
+ word_initial: true
+
+# Monophthongs
+- b: b
+ repeatable: true
+- d: d
+ repeatable: true
+- f: f
+- g: ɣ
+- h: ɦ
+- j: j
+- k: k
+ repeatable: true
+- l: l
+ repeatable: true
+- m: m
+- n: n
+- p: p
+ repeatable: true
+- r: r
+- s: s
+ repeatable: true
+- t: t
+ repeatable: true
+- v: v
+- w: ʋ
+- z: z
@@ -0,0 +1,34 @@
+# coding: utf-8
+require "transcribe/term"
+
+module Transcribe
+ class Term
+ WORD_BOUNDARY = "\\b"
+ REPETITION = "+"
+
+ class << self
+ def create_from_yaml(yaml)
+ from, to = yaml.shift
+ Term.new from, to, yaml
+ end
+ end
+
+ def initialize(from, to, opts = {})
+ @to = to
+ if opts.empty?
+ @from = from
+ else
+ from = Regexp.escape(from)
+ flags = ""
+ from.concat REPETITION if opts["repeatable"]
+ from.prepend WORD_BOUNDARY if opts["word_initial"]
+ from.concat WORD_BOUNDARY if opts["word_final"]
+ @from = Regexp.new(from, flags)
+ end
+ end
+
+ def apply!(text)
+ text.gsub! @from, @to
+ end
+ end
+end
@@ -0,0 +1,4 @@
+# coding: utf-8
+module Transcribe
+ VERSION = "0.0.1"
+end
@@ -0,0 +1,17 @@
+# -*- encoding: utf-8 -*-
+require File.expand_path('../lib/transcribe/version', __FILE__)
+
+Gem::Specification.new do |gem|
+ gem.authors = ["Bryan McKelvey"]
+ gem.email = ["bryan.mckelvey@gmail.com"]
+ gem.description = %q{Transcribes a language into IPA}
+ gem.summary = %q{Transcribes a language into IPA}
+ gem.homepage = "https://github.com/brymck/transcribe"
+
+ gem.files = `git ls-files`.split($\)
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
+ gem.name = "transcribe"
+ gem.require_paths = ["lib"]
+ gem.version = Transcribe::VERSION
+end

0 comments on commit 7d7bc93

Please sign in to comment.