You're Invited: Meet the Socket team at BSidesSF and RSAC - April 27 - May 1.RSVP
Socket
Sign inDemoInstall
Socket

github.com/abdullahdiaa/garabic

Package Overview
Dependencies
Alerts
File Explorer
Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

github.com/abdullahdiaa/garabic

v0.0.0-20230105201152-4c3eb72be29c
Source
Go
Version published
Created
Source

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.

FAQs

Package last updated on 05 Jan 2023

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts