quranize

package module
v1.5.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 21, 2019 License: MIT Imports: 6 Imported by: 1

README

GoDoc Build Status codecov

Quranize

Quranize provides Alquran in Go representation. Original source of Alquran is taken from http://tanzil.net in XML format.

Quranize can transform alphabet into arabic using fast and efficient algorithm: suffix-tree for indexing and dynamic programming for parsing.

Documentation

https://godoc.org/github.com/alpancs/quranize

Example

Here is a minimal example.

package main

import (
  "fmt"

  "github.com/alpancs/quranize"
)

func main() {
  q := quranize.NewDefaultQuranize()
  quran := quranize.NewQuranSimpleEnhanced()

  encodeds := q.Encode("alhamdulillah hirobbil 'alamin")
  fmt.Println(encodeds)
  // Output: [الحمد لله رب العالمين]

  locations := q.Locate(encodeds[0])
  fmt.Println(locations)
  // Output: [{1 2 0} {10 10 10} {39 75 13} {40 65 10}]

  suraName, _ := quran.GetSuraName(locations[0].GetSura())
  fmt.Println(suraName)
  // Output: الفاتحة

  aya, _ := quran.GetAya(locations[0].GetSura(), locations[0].GetAya())
  fmt.Println(aya)
  // Output: الْحَمْدُ لِلَّهِ رَبِّ الْعَالَمِينَ
}

https://github.com/alpancs/quranize-service

Documentation

Overview

Package quranize provides Go representation of Alquran. Original source of Alquran is taken from http://tanzil.net in XML format.

This package can transform alphabet into arabic using fast and efficient algorithm: suffix-tree for indexing and dynamic programming for parsing.

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Location

type Location struct {
	// contains filtered or unexported fields
}

Location represents a location in Quran.

func NewLocation added in v1.2.0

func NewLocation(sura, aya, wordIndex int) Location

NewLocation returns new Location given sura number, aya number, and "word index" (assuming aya is splitted word by word using separator " ").

func (Location) GetAya added in v1.2.0

func (l Location) GetAya() int

GetAya returns aya number of this location.

func (Location) GetSura added in v1.2.0

func (l Location) GetSura() int

GetSura returns sura number of this location.

func (Location) GetWordIndex added in v1.2.0

func (l Location) GetWordIndex() int

GetWordIndex returns word index of this location.

func (Location) String added in v1.2.0

func (l Location) String() string

type Quran

type Quran struct {
	Suras []struct {
		Name string `xml:"name,attr"`
		Ayas []struct {
			Text string `xml:"text,attr"`
		} `xml:"aya"`
	} `xml:"sura"`
}

Quran stores information of every sura and aya. It has suffix-tree index.

func NewIDIndonesian

func NewIDIndonesian() Quran

NewIDIndonesian returns new Quran instance using corpus:

corpus.IDIndonesianXML

See https://github.com/alpancs/quranize/blob/master/corpus/id_indonesian.go#L4.

func NewIDMuntakhab

func NewIDMuntakhab() Quran

NewIDMuntakhab returns new Quran instance using corpus:

corpus.IDMuntakhabXML

See https://github.com/alpancs/quranize/blob/master/corpus/id_muntakhab.go#L4.

func NewQuranSimpleClean

func NewQuranSimpleClean() Quran

NewQuranSimpleClean returns new Quran instance using corpus:

corpus.QuranSimpleCleanXML

See https://github.com/alpancs/quranize/blob/master/corpus/quran_simple_clean.go#L4.

func NewQuranSimpleEnhanced

func NewQuranSimpleEnhanced() Quran

NewQuranSimpleEnhanced returns new Quran instance using corpus:

corpus.QuranSimpleEnhancedXML

See https://github.com/alpancs/quranize/blob/master/corpus/quran_simple_enhanced.go#L4.

func ParseQuran

func ParseQuran(raw string) (q Quran, err error)

ParseQuran returns Quran from given raw.

func (Quran) GetAya

func (q Quran) GetAya(sura int, aya int) (string, error)

GetAya returns aya text from sura number and aya number in Quran q (number starting from 1).

func (Quran) GetSuraName

func (q Quran) GetSuraName(sura int) (string, error)

GetSuraName returns sura name from sura number in Quran q (number starting from 1).

type Quranize

type Quranize struct {
	// contains filtered or unexported fields
}

Quranize encodes arabic into alphabet.

func NewDefaultQuranize

func NewDefaultQuranize() Quranize

NewDefaultQuranize returns new Quranize using default mapping and quran "quran-simple-clean.xml".

Mapping: https://github.com/alpancs/quranize/blob/master/corpus/arabic_to_alphabet_clean.go#L3

Quran: https://github.com/alpancs/quranize/blob/master/corpus/quran_simple_clean.go#L4

func NewQuranize

func NewQuranize(t Transliteration, q Quran) Quranize

NewQuranize return new Quranize using Transliteration t and Quran q.

func (Quranize) Encode

func (q Quranize) Encode(s string) []string

Encode returns arabic encodings of given string using Transliteration t.

Example
quranize := NewDefaultQuranize()
fmt.Println(quranize.Encode("alhamdulillah hirobbil 'alamin"))
Output:

[الحمد لله رب العالمين]

func (Quranize) Locate

func (q Quranize) Locate(s string) []Location

Locate returns locations of s (quran kalima), matching the whole word.

Example
quranize := NewDefaultQuranize()
fmt.Println(quranize.Locate("الحمد لله رب العالمين"))
Output:

[{1 2 0} {10 10 10} {39 75 13} {40 65 10}]

type Transliteration

type Transliteration struct {
	// contains filtered or unexported fields
}

Transliteration helps Quranize to encode arabic into alphabet.

func NewDefaultTransliteration

func NewDefaultTransliteration() Transliteration

NewDefaultTransliteration returns new Transliteration using default mapping.

Mapping: https://github.com/alpancs/quranize/blob/master/corpus/arabic_to_alphabet_clean.go#L3

func NewTransliteration

func NewTransliteration(raw string) Transliteration

NewTransliteration returns new Transliteration.

Directories

Path Synopsis
Package corpus provides corpus in go string.
Package corpus provides corpus in go string.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL