| 1 | |
|---|
| 2 | = Linguistics |
|---|
| 3 | |
|---|
| 4 | == Authors |
|---|
| 5 | |
|---|
| 6 | * Michael Granger <ged@FaerieMUD.org> |
|---|
| 7 | * Martin Chase <stillflame@FaerieMUD.org> |
|---|
| 8 | |
|---|
| 9 | |
|---|
| 10 | == Requirements |
|---|
| 11 | |
|---|
| 12 | * Ruby >= 1.8.6 |
|---|
| 13 | |
|---|
| 14 | |
|---|
| 15 | == Optional |
|---|
| 16 | |
|---|
| 17 | * Ruby-WordNet (>= 0.0.5) - adds integration for the Ruby binding for the |
|---|
| 18 | WordNet® lexical refrence system. |
|---|
| 19 | |
|---|
| 20 | URL: http://deveiate.org/projects/Ruby-WordNet |
|---|
| 21 | |
|---|
| 22 | * LinkParser (>= 1.0.2) - adds integration for the Ruby Link Grammar Parser by |
|---|
| 23 | Martin Chase. |
|---|
| 24 | |
|---|
| 25 | URL: http://dev.faeriemud.org/~stillflame/linkparse.html |
|---|
| 26 | Download: http://www.faeriemud.org/code/Ruby-LinkParser-0.0.4.tgz |
|---|
| 27 | |
|---|
| 28 | |
|---|
| 29 | == General Information |
|---|
| 30 | |
|---|
| 31 | Linguistics is a framework for building linguistic utilities for Ruby objects |
|---|
| 32 | in any language. It includes a generic language-independant front end, a |
|---|
| 33 | module for mapping language codes into language names, and a module which |
|---|
| 34 | contains various English-language utilities. |
|---|
| 35 | |
|---|
| 36 | |
|---|
| 37 | === Method Interface |
|---|
| 38 | |
|---|
| 39 | The Linguistics module comes with a language-independant mechanism for |
|---|
| 40 | extending core Ruby classes with linguistic methods. |
|---|
| 41 | |
|---|
| 42 | It consists of three parts: a core linguistics module which contains the |
|---|
| 43 | class-extension framework for languages, a generic inflector class that serves |
|---|
| 44 | as a delegator for linguistic methods on Ruby objects, and one or more |
|---|
| 45 | language-specific modules which contain the actual linguistic functions. |
|---|
| 46 | |
|---|
| 47 | The module works by adding a single instance method for each language named |
|---|
| 48 | after the language's two-letter code (or three-letter code, if no two-letter |
|---|
| 49 | code is defined by ISO639) to various Ruby classes. This allows many |
|---|
| 50 | language-specific methods to be added to objects without cluttering up the |
|---|
| 51 | interface or risking collision between them, albeit at the cost of three or four |
|---|
| 52 | more characters per method invocation. |
|---|
| 53 | |
|---|
| 54 | If you don't like extending core Ruby classes, the language modules should |
|---|
| 55 | also allow you to use them as a function library as well. |
|---|
| 56 | |
|---|
| 57 | For example, the English-language module contains a #plural function which can |
|---|
| 58 | be accessed via a method on a core class: |
|---|
| 59 | |
|---|
| 60 | Linguistics::use( :en ) |
|---|
| 61 | "goose".en.plural |
|---|
| 62 | # => "geese" |
|---|
| 63 | |
|---|
| 64 | or via the Linguistics::EN::plural function directly: |
|---|
| 65 | |
|---|
| 66 | include Linguistics::EN |
|---|
| 67 | plural( "goose" ) |
|---|
| 68 | # => "geese" |
|---|
| 69 | |
|---|
| 70 | The class-extension mechanism actually uses the functional interface behind |
|---|
| 71 | the scenes. |
|---|
| 72 | |
|---|
| 73 | A new feature with the 0.02 release: You can now omit the language-code method |
|---|
| 74 | for unambiguous methods by calling Linguistics::use with the +:installProxy+ |
|---|
| 75 | configuration key, with the language code of the language module whose methods |
|---|
| 76 | you wish to be available. For example, instead of having to call: |
|---|
| 77 | |
|---|
| 78 | "goose".en.plural |
|---|
| 79 | |
|---|
| 80 | from the example above, you can now do this: |
|---|
| 81 | |
|---|
| 82 | Lingusitics::use( :en, :installProxy => :en ) |
|---|
| 83 | "goose".plural |
|---|
| 84 | # => "geese" |
|---|
| 85 | |
|---|
| 86 | More about how this works in the documentation for Linguistics::use. |
|---|
| 87 | |
|---|
| 88 | |
|---|
| 89 | ==== Adding Language Modules |
|---|
| 90 | |
|---|
| 91 | To add a new language to the framework, create a file named the same as the |
|---|
| 92 | ISO639 2- or 3-letter language code for the language you're adding. It must be |
|---|
| 93 | placed under lib/linguistics/ to be recognized by the linguistics module, but |
|---|
| 94 | you can also just require it yourself prior to calling Linguistics::use(). |
|---|
| 95 | This file should define a module under Linguistics that is an all-caps version |
|---|
| 96 | of the code used in the filename. Any methods you wish to be exposed to users |
|---|
| 97 | should be declared as module functions (ie., using Module#module_function). |
|---|
| 98 | |
|---|
| 99 | You may also wish to add your module to the list of default languages by |
|---|
| 100 | adding the appropriate symbol to the Linguistics::DefaultLanguages array. |
|---|
| 101 | |
|---|
| 102 | For example, to create a Portuguese-language module, create a file called |
|---|
| 103 | 'lib/linguistics/pt.rb' which contains the following: |
|---|
| 104 | |
|---|
| 105 | module Linguistics |
|---|
| 106 | module PT |
|---|
| 107 | Linguistics::DefaultLanguages << :pt |
|---|
| 108 | |
|---|
| 109 | module_function |
|---|
| 110 | <language methods here> |
|---|
| 111 | end |
|---|
| 112 | end |
|---|
| 113 | |
|---|
| 114 | See the English language module (lib/linguistics/en.rb) for an example. |
|---|
| 115 | |
|---|
| 116 | |
|---|
| 117 | === English Language Module |
|---|
| 118 | |
|---|
| 119 | See the README.english file for a synopsis. |
|---|
| 120 | |
|---|
| 121 | The English-language module currently contains linguistic functions ported |
|---|
| 122 | from a few excellent Perl modules: |
|---|
| 123 | |
|---|
| 124 | Lingua::EN::Inflect |
|---|
| 125 | Lingua::Conjunction |
|---|
| 126 | Lingua::EN::Infinitive |
|---|
| 127 | |
|---|
| 128 | See the lib/linguistics/en.rb file for specific attributions. |
|---|
| 129 | |
|---|
| 130 | New with version 0.02: integration with the Ruby WordNet® and LinkParser |
|---|
| 131 | modules (which must be installed separately). |
|---|
| 132 | |
|---|
| 133 | |
|---|
| 134 | == To Do |
|---|
| 135 | |
|---|
| 136 | * I am planning on improving the results from the infinitive functions, which |
|---|
| 137 | currently return useful results only part of the time. Investigations into |
|---|
| 138 | additional stemming functions and some other strategies are ongoing. |
|---|
| 139 | |
|---|
| 140 | * Martin Chase <stillflame at FaerieMUD dot org> is working on an integration |
|---|
| 141 | module for his excellent work on a Ruby interface to the CMU Link Grammar |
|---|
| 142 | (an english-sentence parser). This will make writing fairly accurate natural |
|---|
| 143 | language parsers in Ruby much easier. |
|---|
| 144 | |
|---|
| 145 | * Suggestions (and patches) for any of these items or additional features are |
|---|
| 146 | welcomed. |
|---|
| 147 | |
|---|
| 148 | |
|---|
| 149 | |
|---|
| 150 | == Legal |
|---|
| 151 | |
|---|
| 152 | This module is Open Source Software which is Copyright (c) 2003 by The |
|---|
| 153 | FaerieMUD Consortium. All rights reserved. |
|---|
| 154 | |
|---|
| 155 | You may use, modify, and/or redistribute this software under the terms of the |
|---|
| 156 | Perl Artistic License, a copy of which should have been included in this |
|---|
| 157 | distribution (See the file Artistic). If it was not, a copy of it may be |
|---|
| 158 | obtained from http://language.perl.com/misc/Artistic.html or |
|---|
| 159 | http://www.faeriemud.org/artistic.html). |
|---|
| 160 | |
|---|
| 161 | THIS PACKAGE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED |
|---|
| 162 | WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF |
|---|
| 163 | MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. |
|---|
| 164 | |
|---|
| 165 | |
|---|
| 166 | $Id$ |
|---|
| 167 | |
|---|