• Stars
    star
    685
  • Rank 65,982 (Top 2 %)
  • Language
    Ruby
  • License
    MIT License
  • Created over 16 years ago
  • Updated over 2 years ago

Reviews

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

Repository Details

A language detection library for Ruby that uses bloom filters for speed.

whatlanguage

by Peter Cooper

Text language detection. Quick, fast, memory efficient, and all in pure Ruby. Uses Bloom filters for aforementioned speed and memory benefits. It works well on texts of over 10 words in length (e.g. blog posts or comments) and very poorly on short or Twitter-esque text, so be aware.

Works with Dutch, English, Farsi, French, German, Italian, Pinyin, Swedish, Portuguese, Russian, Arabic, Finnish, Greek, Hebrew, Hungarian, Korean, Norwegian, Polish and Spanish out of the box.

Important note

This library was first built in 2007 and has received only a few minor updates over the years. There are now more efficient and effective algorithms for doing language detection which I am investigating for a future WhatLanguage.

This library has been updated to be distributed and to work on modern Ruby implementations but other than that, has had no significant improvements.

Synopsis

Full Example

require 'whatlanguage'

texts = []
texts << %q{Deux autres personnes ont été arrêtées durant la nuit}
texts << %q{The links between the attempted car bombings in Glasgow and London are becoming clearer}
texts << %q{En estado de máxima alertaen su nivel de crítico}
texts << %q{Returns the object in enum with the maximum value.}
texts << %q{Propose des données au sujet de la langue espagnole.}
texts << %q{La palabra "mezquita" se usa en español para referirse a todo tipo de edificios dedicados.}
texts << %q{اللغة التي هي هذه؟}
texts << %q{Mitä kieltä tämä on?}
texts << %q{Ποια γλώσσα είναι αυτή;}
texts << %q{באיזו שפה זה?}
texts << %q{Milyen nyelv ez?}
texts << %q{이 어떤 언어인가?}
texts << %q{Hvilket språk er dette?}
texts << %q{W jakim języku to jest?}

texts.each { |text| puts "#{text[0..18]}... is in #{text.language.to_s.capitalize}" }

Initialize WhatLanguage with all filters

wl = WhatLanguage.new(:all)

Return language with best score

wl.language(text)

Return hash with scores for all relevant languages

wl.process_text(text)

Convenience methods on String

"This is a test".language   # => :english
"This is a test".language_iso   # => :en

Initialize WhatLanguage with certain languages

wl = WhatLanguage.new(:english, :german, :french)

Requirements

None, minor libraries (BloominSimple and BitField) included with this release.

Installation

gem install whatlanguage

To test, go into irb, then:

require 'whatlanguage'
"Je suis un homme".language

## Credits

Contributions from Konrad Reiche, Salimane Adjao Moustapha, and others appreciated.

License

MIT License

Copyright (c) 2007-2016 Peter Cooper

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.

More Repositories

1

pismo

Extracts machine-readable metadata and content from Web pages
Ruby
747
star
2

testrocket

Super simple Ruby testing library
Ruby
237
star
3

engblogs

Engineering Blogs
Ruby
119
star
4

bitarray

Pure Ruby bit array/bitfield implementation
Ruby
105
star
5

hackerslide

A sliding view of the Hacker News front page over time
JavaScript
76
star
6

trtl

Tk-powered Ruby turtle graphics
Ruby
65
star
7

chrome2gif

Dynamically create an animated GIF of a page running in Chrome
JavaScript
63
star
8

rsmaz

Ruby port of Smaz - a short string compression library
Ruby
44
star
9

multirb

Run Ruby code over multiple implementations/versions using RVM from a IRB-esque prompt
Ruby
43
star
10

potc-jruby

JRuby port of Prelude of the Chambered, a Java game
Ruby
41
star
11

videocr

Perform OCR upon entire videos to look for credentials or similar.
Python
39
star
12

webloc

Read and write .webloc (web link) files on macOS / OS X
Ruby
24
star
13

switchpipe

SwitchPipe is a backend process manager and HTTP proxy that makes (especially Ruby) web app deployment simple. NOW OBSOLETE. DO NOT USE.
Ruby
14
star
14

webassembly-simplest-demo

A simple example of compiling C to WebAssembly and running it
HTML
13
star
15

simredis

Redis simulator that allows you to use redis-rb without a Redis daemon running
Ruby
10
star
16

monos

My Ludum Dare 22 entry
Ruby
8
star
17

coffeebots

A programmable robot war game in CoffeeScript / JavaScript
CoffeeScript
4
star
18

illustrator-cc-scripting

Help and resources on scripting Illustrator CC on macOS
JavaScript
4
star
19

igsubscriber

Streams live market data from IG.com's Lightstreamer into a Redis data store
JavaScript
4
star
20

massiveattract

A game developed in a few hours for Ludum Dare 23
JavaScript
2
star
21

bits

Random bits of code I want to keep track of
Ruby
1
star
22

hntitles

Hacker News title edit tracker
Ruby
1
star
23

cardnut

Simple backend for pushing Twilio text messages over WebSocket to a client (not useful for many)
JavaScript
1
star
24

toto

MIDI proxying for great fun with keyboards
Ruby
1
star
25

superhighway

superhighway.dev
HTML
1
star
26

ruranopupore

An Ubuntu 12.04 LTS Ruby, Rails, Nginx, Node.js, Puma, Postgres, and Redis Ansible Playbook Collection
1
star
27

aoc2019solutions

My Advent of Code 2019 Solutions
Ruby
1
star
28

herokuexperiment

Running two processes (web and worker) on a single Heroku dyno
Ruby
1
star