Giter Club home page Giter Club logo

ude's Introduction

NuGet

Build status

Ude is a C# port of Mozilla Universal Charset Detector.

The article "A composite approach to language/encoding detection" describes the charsets detection algorithms implemented by the library.

Ude can recognize the following charsets:

  • UTF-8
  • UTF-16 (BE and LE)
  • UTF-32 (BE and LE)
  • windows-1252 (mostly equivalent to iso8859-1)
  • windows-1251 and ISO-8859-5 (cyrillic)
  • windows-1253 and ISO-8859-7 (greek)
  • windows-1255 (logical hebrew. Includes ISO-8859-8-I and most of x-mac-hebrew)
  • ISO-8859-8 (visual hebrew)
  • Big5
  • gb18030 (superset of gb2312)
  • HZ-GB-2312
  • Shift-JIS
  • EUC-KR, EUC-JP, EUC-TW
  • ISO-2022-JP, ISO-2022-KR, ISO-2022-CN
  • KOI8-R
  • x-mac-cyrillic
  • IBM855 and IBM866
  • X-ISO-10646-UCS-4-3412 and X-ISO-10646-UCS-4-2413 (unusual BOM)
  • ASCII

Platform

  • Windows and Linux (Mono)
  • .NET Core
  • Universal Windows Platform
  • Windows Phone
  • Xamarin

Install

The release consists in the main library (Ude.dll),(Ude.NetStandard.dll) and a command-line client (udetect.exe) that can be used for one-shot tests.

On Windows, compile the Visual Studio 2017 solution ude.sln. On Linux you can build the library, the example and the nunit tests with monodelop and its solution ude.mds, or using make. To compile the sources tarball:

$ ./configure.sh --prefix=/usr/local --enable-tests=yes
$ make

To compile from svn:

$ ./autogen.sh --prefix=/usr/local --enable-tests=yes
$ make

You can pick the library (Ude.dll) from the toplevel build directory (./bin) or you can install it to $prefix/lib/ude by typing:

$ make install

This will installs a command-line example program ($prefix/bin/udetect) to test the library on a given file as:

$ udetect filename 

To run the nunit tests type:

$ make test

Usage

Example

public static void Main(String[] args)
{
    string filename = args[0];
    using (var fs = File.OpenRead(filename)) {
        Ude.CharsetDetector cdet = new Ude.CharsetDetector();
        cdet.Feed(fs);
        cdet.DataEnd();
        if (cdet.Charset != null) {
            Console.WriteLine("Charset: {0}, confidence: {1}", 
                 cdet.Charset, cdet.Confidence);
        } else {
            Console.WriteLine("Detection failed.");
        }
    }
}    

Other portings

The original Mozilla Universal Charset Detector has been ported to a variety of languages. Among these, a Java port:

from which I copied a few data structures, and a Python port:

License

The library is subject to the Mozilla Public License Version 1.1 (the "License"). Alternatively, it may be used under the terms of either the GNU General Public License Version 2 or later (the "GPL"), or the GNU Lesser General Public License Version 2.1 or later (the "LGPL").

Test data has been extracted from Wikipedia and The Project Gutenberg books and is subject to their licenses.

ude's People

Contributors

yinyue200 avatar lorenzck avatar reyhn3 avatar cmpute avatar errepi avatar

Watchers

James Cloos 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.