• Stars
    star
    273
  • Rank 150,780 (Top 3 %)
  • Language
    Ruby
  • License
    BSD 3-Clause "New...
  • Created about 14 years ago
  • Updated over 8 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A generic, language-neutral framework for extending Ruby objects with linguistic methods.

Linguistics

docs

deveiate.org/code/linguistics

project

bitbucket.org/ged/linguistics

github

github.com/ged/linguistics

Description

Linguistics is a framework for building linguistic utilities for Ruby objects in any language. It includes a generic language-independant front end, a module for mapping language codes into language names, and a module which contains various English-language utilities.

Usage

The Linguistics module comes with a language-independant mechanism for extending core Ruby classes with linguistic methods.

It consists of three parts: a core linguistics module which contains the class-extension framework for languages, a generic inflector class that serves as an extension point for linguistic methods on Ruby objects, and one or more language-specific modules which contain the actual linguistic functions.

The module works by adding a single instance method for each language named after the language’s two-letter code (or three-letter code, if no two-letter code is defined by ISO639) to various Ruby classes. This allows many language-specific methods to be added to objects without cluttering up the interface or risking collision between them, albeit at the cost of three or four more characters per method invocation. For example:

Linguistics.use( :en )
"goose".en.plural
# => "geese"

If you prefer monkeypatching (around 70) linguistics methods directly onto core classes, you can do that by adding a ‘monkeypatch’ option to ::use:

Linguistics.use( :en, monkeypatch: true )
"goose".plural
# => "geese"

Controlling Which Classes Get Extended

If you should wish to extend classes other than the ones in Linguistics::DEFAULT_EXT_CLASSES, you have a few options.

You can modify the DEFAULT_EXT_CLASSES array directly (before you call ::use, of course):

Linguistics::DEFAULT_EXT_CLASSES << MyClass

You can also pass an Array of classes to .use:

Linguistics.use( :en, classes: [MyClass] )

Or you can add language methods to classes via mixin:

class MyClass
    include Linguistics::EN
end

All Linguistics methods use Ruby’s casting mechanism, so at a minimum, your classes should provide an implementation of #to_s that returns words or phrases.

Adding Language Modules

To add a new language to the framework, define a module that will act as the top-level namespace for all your linguistic functions, and then register it as being available, like so:

module Linguistics::TLH

    # Add Klingon to the list of default languages
    Linguistics.register_language( :tlh, self )

end

The first argument is either the two- or three-letter [ISO 639.2] (www.loc.gov/standards/iso639-2/php/code_list.php) language code for the language you’re registering.

The second is the container module itself.

After you register your language, each class that Linguistics is told to extend will have a method for your language code/s:

irb> Linguistics.use( :tlh, :classes => Object )
# => [Object]
irb> Object.new.tlh
# => #<(Klingon; tlhIngan-Hol-language inflector) for <Object:0x402d9674> >

If you use RSpec 2, you can test out any API requirements of the module by requiring ‘linguistics/languagebehavior’ and adding a shared behavior to your spec:

require 'rspec'
require 'linguistics/languagebehavior'

describe Linguistics::TLH do

  it_should_behave_like "a Linguistics language module"

  # ... any other specs for your module

end

If you wish to use the logging subsystem set up by Linguistics, you can do so one of two ways: by logging to the logger directly:

Linguistics.log.debug "Registering Klingon language extension"

or by mixing the ‘Linguistics::Loggable’ module into your class/module, which will give you a ‘log’ method that prepends the object class on each log message so it’s easy to filter out the ones you want:

require 'linguistics/mixins'
class Linguistics::TLH::Generator
    include Linguistics::Loggable

    def generate_it
        self.log.debug "starting generation..."
    end
end

English Language Module

Linguistics comes with an English-language module; see the API documentation for Linguistics::EN for more information about it.

Authors

Contributors

  • Robert Berry (bdigital on github) - English conjugation ported from MorphAdorner

Requirements

  • Ruby >= 1.9.3

It may work under earlier versions, but I’ll only be testing it on 1.9.3 or later.

Optional

The English-language module for Linguistics has support for a few other optional natural-language libraries:

linkparser

Ruby high-level interface to the CMU Link Grammar library

wordnet

Adds integration for the Ruby binding for the WordNet® lexical refrence system.

Contributing

You can check out the current development source with Mercurial via its project page. Or if you prefer Git, via its Github mirror.

After checking out the source, run:

$ rake newb

This task will install any missing dependencies, run the tests/specs, and generate the API documentation.

License

Copyright © 2003-2012, Michael Granger All rights reserved.

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

  • Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.

  • Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.

  • Neither the name of the author/s, nor the names of the project’s contributors may be used to endorse or promote products derived from this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS “AS IS” AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

More Repositories

1

ruby-pg

A PostgreSQL client library for Ruby
C
786
star
2

ruby-wordnet

A Ruby interface to the WordNet® Lexical Database.
Ruby
136
star
3

bluecloth

A Ruby implementation of Markdown
Ruby
79
star
4

linkparser

A high-level interface to the CMU Link Grammar. (Github mirror)
C
76
star
5

darkfish

A project to make a complete replacement for the default HTML generator for Rdoc, the API documentation-extraction system for Ruby. (github mirror)
Ruby
35
star
6

sysexits

Exit status codes for Ruby system programs.
Ruby
32
star
7

aurelia-semantic-ui

A collection of Semantic UI custom elements for Aurelia applications (Git mirror)
JavaScript
23
star
8

rdoc-generator-fivefish

A(nother) HTML generator for RDoc
Ruby
22
star
9

rspec-formatter-webkit

A webkit-aware pretty formatter for RSpec (github mirror).
Ruby
20
star
10

io-reactor

A multiplexed, single-threaded, event-driven IO reactor
Ruby
18
star
11

treequel

An LDAP toolkit for Ruby, intended to allow quick, easy access to LDAP directories in a manner consistent with LDAP's hierarchical, free-form nature.
Ruby
14
star
12

configurability

A composable configuration system for Ruby (Github mirror)
Ruby
12
star
13

chione

An Entity/Component System for Ruby inspired by Artemis (git mirror)
Ruby
11
star
14

loggability

A composable Ruby logging system built on the standard Logger library.
Ruby
10
star
15

ruby-ode

A Ruby binding for the Open Dynamics Engine™
C
7
star
16

inversion

Inversion is a templating system for Ruby. It uses the "Inversion of Control" principle to decouple the contents and structure of templates from the code that uses them, making it easier to separate concerns, keep your tests simple, and avoid polluting scopes with ephemeral data. (github mirror)
Ruby
7
star
17

ruby-pf

An experimental Ruby interface to `pf`, the OpenBSD Packet Filter (github mirror).
Ruby
7
star
18

ruby-openldap

A simple, but full-featured Ruby binding for libldap (Github mirror)
C
6
star
19

pluginfactory

A Ruby module for adding plugin-like behavior to classes
Ruby
6
star
20

redleaf

A better Ruby binding for the Redland RDF library (librdf)
Ruby
6
star
21

ruby-axis

A Ruby library for accessing Axis Communications network cameras. (git mirror)
Ruby
5
star
22

thingfish

An extensible digital asset manager.
Ruby
4
star
23

RDoc.tmbundle

A TextMate 2 bundle for editing Ruby API documentation
4
star
24

foreman-export-daemontools

An exporter for Foreman that exports supervise service directories
Ruby
4
star
25

arborist

Arborist is a monitoring framework that follows the UNIX philosophy of small parts and loose coupling for stability, reliability, and customizability.
Ruby
4
star
26

gemserver

The Github mirror of an experimental minimalist Rubygems index and gem server written in Sinatra.
JavaScript
4
star
27

mues

An experimental MORPG engine, written in Ruby. It's unfinished, and hasn't been touched in several years, but maybe still has some interesting stuff. I use https://github.com/ged/chione now instead.
Ruby
4
star
28

rake-deveiate

A collection of Rake tasks common to all my projects (Github mirror)
Ruby
3
star
29

arrow

A Ruby web application framework for Apache and mod_ruby
Ruby
3
star
30

rdtool

RD is Ruby's POD. RDtool is a formatter for RD. With this fork, I'm intending to package rdtool as a gem, and update it as necessary for later versions of Ruby.
Ruby
3
star
31

cztop-reactor

An implementation of the Reactor pattern for ZeroMQ sockets (git mirror)
Ruby
3
star
32

ruby-verse

A Ruby binding for Verse, a network protocol that lets multiple applications act together as one large application by sharing data over a network. It's still a work in progress.
C
3
star
33

drbservice

SSL-encrypted, authenticated DRb service library (Github mirror)
Ruby
3
star
34

strelka-metriks

Metriks support for Strelka web apps (github mirror)
Ruby
2
star
35

hglib

A Ruby client library for the Mercurial distributed revision control system (Github mirror)
Ruby
2
star
36

schedulability

A composable scheduling library for Ruby (git mirror)
Ruby
2
star
37

geds-rake-tasklibs

A collection of rake task libraries I use in a number of different projects. It's a git mirror of my main Mercurial repo.
Ruby
2
star
38

hoe-highline

A Hoe plugin for building interactive Rake tasks. (Github mirror)
Ruby
2
star
39

hoe-deveiate

A collection of Rake tasks and utility functions I use to maintain my Open Source projects. It's really only useful if you want to help maintain one of them.
Ruby
2
star
40

homebrew-faeriemud

A Homebrew tap for installing FaerieMUD development dependencies
Ruby
2
star
41

symphony

An asynchronous job system.
Ruby
2
star
42

fluent_fixtures

A toolkit for building a collection of composable testing fixtures with a fluent interface. (git mirror)
Ruby
2
star
43

devEiate.tmbundle

A dark TextMate theme with balanced, subdued colors
2
star
44

hoe-mercurial

A Mercurial plugin for Hoe (Github mirror)
Ruby
2
star
45

strelka-fancyerrors

A Strelka plugin for rendering a bunch of useful information on error responses suitable for developers
Ruby
2
star
46

hoe-manualgen

A Hoe plugin for generating a manual, tutorial, cookbook, or other in-depth documentation.
JavaScript
2
star
47

Mercurial-Manager

A Ruby implementation of mercurial-server (Git mirror)
Ruby
2
star
48

ronin-shell

This is an experimental object-oriented command shell, in the same vein as rush or Windows PowerShell. (Github mirror)
Ruby
2
star
49

ft2-ruby

Freetype2 bindings for Ruby, updated for Ruby 1.9.2.
C
2
star
50

ruby-framenet

Git mirror of a Ruby library for FrameNet
Ruby
2
star
51

LSystem

A Ruby toolkit for constructing and using Lindenmeyer systems
Ruby
2
star
52

strelka-app-profiler

Github mirror of the profiler plugin for Strelka applications
Ruby
1
star
53

ged

It's like a .plan, only different
1
star
54

assemblage

Git mirror of the Assemblage continuous integration toolkit
Ruby
1
star
55

assemblage-web

Web services for the Assemblage continuous integration toolkit (Git mirror)
Ruby
1
star
56

pluggability

Add pluggability to any Ruby base class
Ruby
1
star
57

rdoc-generator-sixfish

Git mirror of https://hg.sr.ht/~ged/Sixfish
SCSS
1
star
58

strelka

A Ruby web framework for Mongrel2 (mirror)
Ruby
1
star
59

strelka-newrelic

New Relic instrumentation middleware for Strelka apps
Ruby
1
star
60

ming-ruby

A resurrected (and updated) copy of the Ruby binding for libming
Ruby
1
star
61

RSpec3.tmbundle

An RSpec 3 bundle. You probably won't like it.
Ruby
1
star
62

git-gist-viewer

An Aurelia app used to search users and view their Github information
JavaScript
1
star
63

thingfish-metastore-pg

PostgreSQL metastore backend for Thingfish (git mirror)
Ruby
1
star
64

state_machines-sequel

A Sequel adapter for the state_machines library
Ruby
1
star
65

blockchain

A playground for learning wtf a blockchain is
Ruby
1
star
66

newznabr

A Ruby port of Newsnab (http://www.newznab.com/), a Usenet indexer.
1
star
67

ruby-mongrel2

Github mirror of Ruby-Mongrel2
Ruby
1
star
68

homebrew-nginx-unit

Homebrew tap for Nginx Unit experimentation
Ruby
1
star
69

thingfish-processor-mp3

Git mirror of a basic mp3-processor plugin for the Thingfish digital asset manager
Ruby
1
star
70

thingfish-datastore-filesystem

Git mirror
Ruby
1
star
71

arborist-webservice

Git mirror of mercurial repo
Ruby
1
star
72

arborist-dns

DNS monitors and node types for Arborist
Ruby
1
star
73

arborist-web

An experimental webservices implementation for Arborist
Ruby
1
star
74

ruby-ant-wireless

Ruby gem for ANT wireless on the Garmin ANT Stick
C
1
star
75

sequel-inlineschema

Github mirror of the inline schema plugin for Sequel
Ruby
1
star
76

strelka-presenters

Github mirror of the Strelka Presenters plugin
Ruby
1
star
77

pushdown

A pushdown automaton toolkit for Ruby.
Ruby
1
star
78

observability

A git mirror of the Observability library
Ruby
1
star
79

saltpack-ruby

A Ruby implementation of Saltpack, a modern crypto messaging format based on Dan Bernstein's NaCl (git mirror)
Ruby
1
star
80

strelka-cors

Cross-Origin Resource Sharing for Strelka applications
Ruby
1
star
81

aurelia-bailiwick

Aurelia adapters for the Bailiwick domain model toolkit (git mirror)
JavaScript
1
star
82

tnetstrings.info

Git mirror for
JavaScript
1
star
83

bailiwick

A more domain-ish Javascript model toolkit (git mirror)
JavaScript
1
star
84

thingfish-processor-image

Github mirror of a basic image-processor plugin for the Thingfish digital asset manager
Ruby
1
star
85

strelka-authprovider-authtoken

An authentication provider plugin for Strelka applications.
Ruby
1
star
86

aurelia-semantic-ui-demo

Demo application/documentation for aurelia-semantic-ui (Github mirror)
HTML
1
star
87

ruby-zyre

A Ruby (MRI) binding for the Zyre library for reliable group messaging over local area networks, an implementation of the ZeroMQ Realtime Exchange protocol.
Ruby
1
star