Git Product home page Git Product logo

garabic's Introduction

Arabic tools for golang - حزمة أدوات للتعامل مع اللغة العربية في لغة go

GArabic

GoDoc codecov Build Status Go Report Card

A set of functions for Arabic text processing in golang

مكتبة برمجية توفر دوالاً للتعامل مع النصوص العربية في لغة برمجة go

⚠️ The library still under active development

⚠️ المكتبة لا تزال تحت التطوير

Features

  • Normalize Arabic text for processing.
  • Remove Harakat from Arabic text.
  • Arabic numbers to words.
  • Arabic Glyphs shaping to render Arabic text properly in images.
  • Convert english digits to Arabic digits, and vice versa
  • Add diacritics to Arabic text [in progress]
  • Hijri date support.
  • English-Arabic Transliteration.
  • Arabic Sentiment Analysis.

المزايا

  • تنميط الحروف
  • اختزال التشكيل
  • تحويل الأعداد إلى كلمات
  • اصلاح تشبيك النص العربي
  • تحويل الأرقام الانجليزية لأرقام عربية و العكس
  • تشكيل النص العربي
  • التاريخ الهجري
  • دعم قراءة و تحويل النص العربي لحروف انجليزية
  • تحليل المشاعر في النص العربي

Usage

Normalization / تنميط الحروف

package main

import (
	"fmt"

	arabic "github.com/abdullahdiaa/garabic"
)

func main() {
     normalized := arabic.RemoveHarakat("سَنواتٌ")
	fmt.Println(normalized)
	// Output:
	// سنوات
}

Arabic Glyphs shaping / اصلاح تشبيك النص العربي

Here's an example for printing Arabic text on an image:

مثال لطباعة نص عربي علي صورة:

without the library/ من غير استخدام المكتبة

using the library/ باستخدام المكتبة

package main

import (
	"image"
	"image/color"
	"image/png"
	"io/ioutil"
	"log"
	"os"

	"github.com/abdullahdiaa/garabic"
	"golang.org/x/image/font"
	"golang.org/x/image/font/opentype"
	"golang.org/x/image/math/fixed"
)

func addLabel(img *image.RGBA, x, y int, label string) {
	//Load font file
	//You can download amiri font from this link: https://fonts.google.com/specimen/Amiri?preview.text=%D8%A8%D9%90%D8%A7%D9%84%D8%B9%D9%8E%D8%B1%D9%8E%D8%A8%D9%90%D9%91%D9%8A&preview.text_type=custom#standard-styles
	b, err := ioutil.ReadFile("Amiri-Regular.ttf")
	if err != nil {
		log.Println(err)
		return
	}

	ttf, err := opentype.Parse(b)
	if err != nil {
		log.Println(err)
		return
	}
	//Create Font.Face from font
	face, err := opentype.NewFace(ttf, &opentype.FaceOptions{
		Size:    26,
		DPI:     72,
		Hinting: font.HintingNone,
	})

	d := &font.Drawer{
		Dst:  img,
		Src:  image.NewUniform(color.RGBA{120, 157, 243, 255}),
		Face: face,
		Dot:  fixed.P(x, y),
	}

	d.DrawString(label)
}

func main() {
	img := image.NewRGBA(image.Rect(0, 0, 700, 70))
	addLabel(img, 40, 40, garabic.Shape("قِفا نَبكِ مِن ذِكرى حَبيبٍ وَمَنزِلِ   ****   بِسِقطِ اللِوى بَينَ الدَخولِ فَحَومَلِ"))

	f, err := os.Create("printed_arabic_text.png")
	if err != nil {
		panic(err)
	}
	defer f.Close()
	if err := png.Encode(f, img); err != nil {
		panic(err)
	}
}

Speed

Here's a benchmark for normalizing ~78K words on MBP i5 takes about ~45ms:

BenchmarkNormalizeBigText-4           25          45546613 ns/op         9275097 B/op         31 allocs/op
~45 ms

Documentation

You can view detailed documentation here: GoDoc.

التوثيق

يمكنك مراجعة توثيق الكود و الاستخدام الخاص بكل دالة من خلال هذا الرابط: GoDoc.

Contributing

There are many ways to contribute:

المشاركة

يمكنك المشاركة في تطوير المكتبة بأحد هذه الطرق:

Changelog

View the changelog for the latest updates and changes by version.

License

Apache License 2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

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.