GithubHelp home page GithubHelp logo

ged / linguistics Goto Github PK

View Code? Open in Web Editor NEW
275.0 18.0 28.0 646 KB

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

Home Page: http://deveiate.org/projects/Linguistics

License: BSD 3-Clause "New" or "Revised" License

Ruby 99.83% Shell 0.17%

linguistics's Introduction

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.

linguistics's People

Contributors

ged avatar ippeiukai avatar

Stargazers

Gerald Bauer avatar Nels Nelson avatar Machine391 avatar Rosalynn avatar  avatar ciscoLegrand avatar Pierce Brooks avatar hmltn-2 avatar Will Lewis avatar Kuo Ting-Kai avatar Paul F avatar Dr Stefanie Hills avatar OSINTAI avatar Salvador Guzman avatar Andrea Leone avatar Hamidreza Safari avatar gang han avatar Yasin ATEŞ avatar Vassiliki Doropoulou avatar Jack Corley avatar Justin Bishop avatar Noah Hendlish avatar Paul Philippov avatar Naoya Ueda avatar Martin avatar Ajay Jaiman avatar PLUSOR avatar jdgc avatar Zhisong Ge avatar Mark Allen avatar Jochen Seeber avatar Viacheslav Ptsarev avatar UsabilityHub avatar Sophie Duan avatar  avatar Joel Van Horn avatar Walter Lee Davis avatar Elvack Riansyah avatar Mikołaj Fejzer avatar Hooopo avatar  avatar Athitya Kumar avatar HughP avatar Gergely Brautigam avatar William Clifford avatar Carlos Rocha avatar  avatar chenmi avatar nghiach avatar Oleksandr Shchyhol avatar Den Patin avatar Wenderson Fernandes avatar Kyle Duck avatar Enrique Esquinas avatar Matt Scilipoti avatar Evin Weissenberg avatar  avatar Alan avatar Hazel avatar Filipe Chagas avatar Johan Hernandez avatar  avatar Chris Olstrom avatar Steve Hansell avatar //de avatar mr.The avatar Loïc KARTONO avatar Dzmitry Chyrta avatar Jerry Wu avatar Andrew Prentice avatar Serge Bedzhyk avatar KAK avatar Yoichiro Hasebe avatar Alex Baldwin avatar Ryan Scott Lewis avatar Matt Beedle avatar Diego Figueroa avatar David Wabnitz avatar Yonatan Bergman avatar Alexey Elizarov avatar Angus H. avatar Robin Berlin avatar Tyler Breton avatar Javier L. Velasquez avatar Quentin Rousseau avatar Lukas Elmer avatar Johnson Qu avatar Paul Mackay avatar Rupak Ganguly avatar Ragav Satish avatar Sergio Diaz avatar himkt avatar dongyuwei avatar Matusalem Marques avatar Kevin Dias avatar Pascal Weiland avatar Anatoli Makarevich avatar Matt Morris avatar NDuma avatar Cody Estes avatar

Watchers

Kirk Haines avatar  avatar İbrahim YILDIZ avatar  avatar Takeshi Watanabe avatar  avatar James Cloos avatar Anatoly Chernov avatar Yuri Oliveira avatar Shmin Zhang avatar Simeon Mugisha avatar Cem Ozturk avatar Rahul Garg avatar Victor Maslov avatar  avatar Tyler Breton avatar Robin Berlin avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.