NISUS Archives

April 2017

NISUS@LISTSERV.DARTMOUTH.EDU

Options: Use Monospaced Font
Show Text Part by Default
Show All Mail Headers

Message: [<< First] [< Prev] [Next >] [Last >>]
Topic: [<< First] [< Prev] [Next >] [Last >>]
Author: [<< First] [< Prev] [Next >] [Last >>]

Print Reply
Subject:
From:
Reply To:
Date:
Sun, 16 Apr 2017 02:31:58 +0900
Content-Type:
text/plain
Parts/Attachments:
text/plain (154 lines)
Dear Abdassamad,

Sorry for being very late in reply.

> On 2016/05/28, at 02:46, Abdassamad Clarke <[log in to unmask]> wrote:
> 
> I remember in the previous iteration of Nisus, that there was a macro that purported to generate transliterated text when fed Arabic. Does anyone else remember that or know of a version of that macro for NWP pro? I have a very substantial Diwan of Arabic poetry which we would like to publish with transliteration but my heart quails at the thought of doing it manually.

Not having a transliteration macro for NWP, I wrote it. As a computer program does not understand natural languages like Arabic, this macro produces more or less useable transliteration only when the target text is fully vocalized.

Even with fully vocalized text, the resulting transliteration is far from perfect. You have to insert hyphens manually, for example, between "fa" and "kataba" of "fakataba". And, in most cases, there are several *typos* you have to fix manually.

However, perhaps this macro may be better than nothing.

I uploaded the macro files as
<http://www2.odn.ne.jp/alt-quinon/files/NWPro/arabic/ArabictoTransliteration_20170416_nwm.zip>

This macro should contain numerous bugs and shortcomings. As the spring vacations are over now, I will not be able to fix them soon. Sorry in advance.


Kino
--

### Arabic to Transliteration ###

# This macro adds just after the selected Arabic text its transliteration enclosed between $prefix and $suffix.
# Non-contiguous selections are supported.

Require Pro Version '2.1'

$LC = @false # @true: th, j, kh, etc. @false: ṯ, ǧ, ḫ, etc.
$alAsPronounced = @true # @true: aš-šaǧara; @false: al-šaǧara
$hamzaAtWordStart = @true # @true: ʾinnna-ka; @false: innna-ka

$prefix = Cast to String "\n(" # preceding transliterated text
$suffix = Cast to String ")" # following transliterated text

$fontname = 'Palatino'
$fontsize = '10'


$doc = Document.active
if $doc == @undefined
	exit 'No open document, exiting...'
end

$sels = $doc.textSelections
if ! $sels.firstValue.length
	exit 'No selection, exiting...'
end

$tr = Hash.new
$tr{0x0640} = $tr{0x0652} = @S|| # remove taṭwīl and sukūn
$tr{0x0621} = $tr{0x0623} = $tr{0x0624} = $tr{0x0625} = $tr{0x0626} = @S|ʾ| # hamza
$tr{0x0627} = @S|ā| # alif
$tr{0x0622} = @S|ʾā| # alif with madda
$tr{0x0628} = @S|b| # bāʾ
$tr{0x062A} = @S|t| # tāʾ
$tr{0x0629} = @S|t| # tāʾ marbūṭa
$tr{0x062B} = @S|ṯ| # ṯāʾ
$tr{0x062C} = @S|ǧ| # ǧīm
$tr{0x062D} = @S|ḥ| # ḥāʾ
$tr{0x062E} = @S|ḫ| # ḫāʾ
$tr{0x062F} = @S|d| # dāl
$tr{0x0630} = @S|ḏ| # ḏāl
$tr{0x0631} = @S|r| # rāʾ
$tr{0x0632} = @S|z| # zāy
$tr{0x0633} = @S|s| # sīn
$tr{0x0634} = @S|š| # šīn
$tr{0x0635} = @S|ṣ| # ṣād
$tr{0x0636} = @S|ḍ| # ḍād
$tr{0x0637} = @S|ṭ| # ṭāʾ
$tr{0x0638} = @S|ẓ| # ẓāʾ
$tr{0x0639} = @S|ʿ| # ʿayn (the glyph of Courier font is wrong)
$tr{0x063A} = @S|ġ| # ġayn
$tr{0x0641} = @S|f| # fāʾ
$tr{0x0642} = @S|q| # qāf
$tr{0x0643} = @S|k| # kāf
$tr{0x0644} = @S|l| # lām
$tr{0x0645} = @S|m| # mīm
$tr{0x0646} = @S|n| # nūn
$tr{0x0647} = @S|h| # hāʾ
$tr{0x0648} = @S|w| # wāʾ
$tr{0x064A} = $tr{0x06CC} = @S|y| # yāʾ
$tr{0x0649} = @S|ā| # ? alif maqṣūra
$tr{0x0670} = @S|ā| # superscript alif
$tr{0x064E} = @S|a|
$tr{0x0650} = @S|i|
$tr{0x064F} = @S|u|
$tr{0x064B} = @S|an|
$tr{0x064D} = @S|in|
$tr{0x064C} = @S|un|
$tr{0x0660} = $tr{0x06F0} = @S|0|
$tr{0x0661} = $tr{0x06F1} = @S|1|
$tr{0x0662} = $tr{0x06F2} = @S|2|
$tr{0x0663} = $tr{0x06F3} = @S|3|
$tr{0x0664} = $tr{0x06F4} = @S|4|
$tr{0x0665} = $tr{0x06F5} = @S|5|
$tr{0x0666} = $tr{0x06F6} = @S|6|
$tr{0x0667} = $tr{0x06F7} = @S|7|
$tr{0x0668} = $tr{0x06F8} = @S|8|
$tr{0x0669} = $tr{0x06F9} = @S|9|
$tr{0x060C} = @S|,|
$tr{0x061B} = @S|;|
$tr{0x061F} = @S|?|

$lctr = Hash.new
$lctr{@S|ʾ|} = @S|’| # hamza
$lctr{@S|ʿ|} = @S|‘| # ʿayn
$lctr{@S|ṯ|} = @S|th|
$lctr{@S|ǧ|} = @S|j|
$lctr{@S|ḫ|} = @S|kh|
$lctr{@S|ḏ|} = @S|dh|
$lctr{@S|š|} = @S|sh|
$lctr{@S|ġ|} = @S|gh|

foreach $sel in reversed $sels
	$copiedText = $sel.subtext.copy
	$copiedText = $copiedText.textByNormalizing('compose')
	$copiedText.replaceAll '\b(?:[\x{0627}\x{0623}]\x{064E}?|\x{0671})\x{0644}\x{0652}?', 'al-', 'E-i'
	$copiedText.replaceAll '(?<=\x{0648}|\x{0648}\x{064E}|\x{0641}|\x{0641}\x{064E})(?:[\x{0627}\x{0623}]\x{064E}?|\x{0671})\x{0644}\x{0652}?', '-al-', 'E-i'
	$copiedText.replaceAll '(?<=al-\S|al-\S[\x{064B}-\x{0650}])\x{0651}', '', 'E-i' # remove šadda from a succeeding letter
	$copiedText.replaceAll '([\x{064B}-\x{0650}\x{0670}])(\x{0651})', '\2\1', 'E-i' # change "vowel shadda" to "šadda vowel"
	$copiedText.replaceAll '(\S)\x{0651}', '\1\1', 'E-i' # change "letter šadda" to "letter letter"
	$copiedText.replaceAll '(?:\x{064B}\x{0627}|\x{0627}\x{064B})\b', 'an', 'E-i'
	$range = Range.new(0, $copiedText.length)
	$copiedText.transliterateInRange $range, $tr
	if $alAsPronounced == @true
		$copiedText.replaceAll '\bal-([tṯdḏrzsšṣḍṭẓln])', 'a\1-\1', 'E-i'
	end
	$copiedText.replaceAll 'aā|āa', 'ā', 'E-i'
	$copiedText.replaceAll 'i(?=ī)', '', 'E-i'
	$copiedText.replaceAll 'u(?=ū)', '', 'E-i'
	$copiedText.replaceAll 'iy', 'ī', 'E-i'
	$copiedText.replaceAll 'uw', 'ū', 'E-i'
	$copiedText.replaceAll '\b([fw]a-)a(l-)', '\1\2', 'E-i'
	$copiedText.replaceAll '\b(ʾ?inna(?!mā)|ʾ?anna|ʾ?ilay|ʿalay)(?=\S)', '\1-', 'E-i'
	if $hamzaAtWordStart == @false
		$copiedText.replaceAll '\bʾ', '', 'E-i'
	end
	if $LC == @true
		$range = Range.new(0, $copiedText.length)
		$copiedText.transliterateInRange $range, $lctr
	end
	$copiedText = $prefix & $copiedText & $suffix
	Push Target Text $copiedText
		Set Font Name $fontname
		Set Font Size $fontsize
	Pop Target Text
	$sel.text.insertAtIndex $sel.bound, $copiedText
end

### end of macro

ATOM RSS1 RSS2