Coder Social home page Coder Social logo

apertium-python's Introduction

Apertium + Python

Travis Build Status Appveyor Build status ReadTheDocs Docs Status Coverage Status PyPI - Python Version

Introduction

  • The codebase is in development for the GSoC '19 project called Apertium API in Python
  • The Apertium core modules are written in C++.
  • This project makes the Apertium modules available in Python, which because of its simplicity is more appealing to users.

About the Exisiting Code Base

  • The existing codebase has Subprocess and SWIG wrapper implementations of the higher level functions of Apertium and CG modules.

Installation

  • Installation on Debian/Ubuntu and Windows is natively supported:

    pip install apertium
    
  • For developers, pipenv can be used to install the development dependencies and enter a shell with them:

    pip install pipenv
    pipenv install --dev
    pipenv shell
    
  • Apertium packages can be installed from Python interpreter as well.

    • Install apertium-all-dev by calling apertium.installer.install_apertium()
    • Install language packages with apertium.installer.install_module(language_name). For example apertium-eng can be installed by executing apertium.installer.install_module('eng')

Usage

  • For multiple invocations Method 1 is more performant, as the dictionary needs to be loaded only once.

Analysis

Performing Morphological Analysis

Method 1: Create an Analyzer object and call its analyze method.

In [1]: import apertium
In [2]: a = apertium.Analyzer('en')
In [3]: a.analyze('cats')
Out[3]: [cats/cat<n><pl>, ./.<sent>]

Method 2: Calling analyze() directly.

In [1]: import apertium
In [2]: apertium.analyze('en', 'cats')
Out[2]: cats/cat<n><pl>

Generation

Performing Morphological Generation

Method 1: Create a Generator object and call its generate method.

In [1]: import apertium
In [2]: g = apertium.Generator('en')
In [3]: g.generate('^cat<n><pl>$')
Out[3]: 'cats'

Method 2: Calling generate() directly.

In [1]: import apertium
In [2]: apertium.generate('en', '^cat<n><pl>$')
Out[2]: 'cats'

Tagger

Method 1: Create a Tagger object and call its tag method.

In [1]: import apertium
In [2]: tagger = apertium.Tagger('eng')
In [3]: tagger.tag('cats')
Out[3]: [cats/cat<n><pl>]

Method 2: Calling tag() directly.

In [1]: import apertium
In [2]: apertium.tag('en', 'cats')
Out[2]: [cats/cat<n><pl>]

Translation

Method 1: Create a Translator object and call its translate method.

In [1]: import apertium
In [2]: t = apertium.Translator('eng', 'spa')
In [3]: t.translate('cats')
Out[3]: 'Gatos'

Method 2: Calling translate() directly.

In [1]: import apertium
In [2]: apertium.translate('en', 'spa', 'cats')
Out[2]: 'Gatos'

Installing more modes from other language data

One can also install modes by providing the path to the lang-data:

In [1]: import apertium
In [2]: apertium.append_pair_path('..')

apertium-python's People

Contributors

sushain97 avatar singh-lokendra avatar orgh0 avatar dependabot[bot] avatar dolphingarlic avatar tinodidriksen 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.