अगर मैं आपके सवाल का सही ढंग से समझ, आप कोड पॉइंट्स युक्त एक यूनिकोड स्ट्रिंग मिल गया है, और आप graphames की एक सरणी में इस परिवर्तित करना चाहते हैं?
मैं Tamil Language website के लिए इस तरह के कार्यों को करने के लिए एक ओपन सोर्स पायथन पुस्तकालय विकसित करने पर काम कर रहा हूं।
मैंने थोड़ी देर में PHP का उपयोग नहीं किया है, इसलिए मैं तर्क पोस्ट करूंगा। आप amuthaa/TamilWord.py file's split_letters() function में कोड को देख सकते हैं।
जैसा कि खंड का उल्लेख किया गया है, तमिल ग्रैफेम्स को कोडपॉइंट्स के रूप में बनाया गया है।
स्वर (உயிர் எழுத்து), aytham (ஆய்த எழுத்து - ஃ) और सभी संयोजनों ((உயிர்-மெய் 'एक' कॉलम में எழுத்து) (அ வரி - यानी க, ச, ட, த , ப, ற, ம, ஞ, σ, ந, ம, வ, 繁, ர, ள, வ, ழ, ல) प्रत्येक एक एकल कोडपॉइंट का उपयोग करते हैं।
प्रत्येक व्यंजन दो कोडपॉइंट्स से बना होता है: एक संयोजन पत्र + पुली। जैसे ப் = ப + ்
ए-संयोजन के अलावा प्रत्येक संयोजन als हैं ओ दो कोड पॉइंट्स से बना: एक-संयोजन पत्र + एक अंकन: जैसे பி = ப் + ி, தை = த் + ை
इसलिए यदि आपके तर्क कुछ इस तरह होने जा रहा है:
initialize an empty array
for each codepoint in word:
if the codepoint is a vowel, a-combination or aytham, it is also its grapheme, so add it to the array
otherwise, the codepoint is a marking such as the pulli (i.e. ்) or one of the combination extensions (e.g. ி or ை), so append it to the end of the last element of the array
यह निश्चित रूप से मानता है कि आपकी स्ट्रिंग अच्छी तरह से बनाई गई है और आपके पास पंक्ति में दो चिह्नों जैसी चीजें नहीं हैं।
यहां पाइथन कोड है, यदि आपको यह उपयोगी लगता है। आप PHP करने के लिए हमें बंदरगाह इस मदद करना चाहते हैं, तो मुझे रूप में अच्छी तरह से अवगत कराएं:
@staticmethod
def split_letters(word=u''):
""" Returns the graphemes (i.e. the Tamil characters) in a given word as a list """
# ensure that the word is a valid word
TamilWord.validate(word)
# list (which will be returned to user)
letters = []
# a tuple of all combination endings and of all அ combinations
combination_endings = TamilLetter.get_combination_endings()
a_combinations = TamilLetter.get_combination_column(u'அ').values()
# loop through each codepoint in the input string
for codepoint in word:
# if codepoint is an அ combination, a vowel, aytham or a space,
# add it to the list
if codepoint in a_combinations or \
TamilLetter.is_whitespace(codepoint) or \
TamilLetter.is_vowel(codepoint) or \
TamilLetter.is_aytham(codepoint):
letters.append(codepoint)
# if codepoint is a combination ending or a pulli ('்'), add it
# to the end of the previously-added codepoint
elif codepoint in combination_endings or \
codepoint == TamilLetter.get_pulli():
# ensure that at least one character already exists
if len(letters) > 0:
letters[-1] = letters[-1] + codepoint
# otherwise raise an Error. However, validate_word()
# should catch this
else:
raise ValueError("""%s cannot be first character of a word""" % (codepoint))
return letters
स्रोत
2013-01-25 16:48:10
मुझे लगता है कि परीक्षण किया है और इसे सही ढंग से वर्णों से मेल नहीं करता है। – Danack
@ डेनैक 57: कूल, बहुत बहुत धन्यवाद। :-) – ruakh
धन्यवाद। यह अच्छा काम करता है। – priyacst