Hi Steven ans Tutors,
Thanks for the code.
Actually I'm not a student at all. I'm an assistant professor of Arabic at
Suez Canal University in Egypt. I would appreciate more contributions from
you and the other list members.

2011/10/8 Steven D'Aprano <st...@pearwood.info>

> Emad Nawfal (عمـ نوفل ـاد) wrote:
>
>> Hello Tutors,
>> It's been quite some time since I last posted something here, and now I'm
>> back with a question:
>>
>> I want to re-structure English so that the adjectives appear after the
>> nouns, instead of before.
>> If I have a sentence like:
>>
>> The tall man plays well
>> I need to change it to
>> The man tall plays well
>> So far, I have thought of the following function, but I'm not sure it's
>> the
>> best solution. It assumes that the sentence has been augmented with part
>> of
>> speech tags
>> (Also plz note that there may be multiple adjectives)
>>
>
> And what do you expect to happen with multiple adjectives?
>
> "the tall fat bald man"
>
> => "the man tall fat bald"
> => "the man fat tall bald"
> => "the man bald fat tall"
> => "the man fat bald tall"
> => something else?
>
> The approach I would take is this:
>
>
> Walk along the sentence, inspecting each word.
> Collect all consecutive adjectives into a list of adjectives
> Other words get copied straight into the buffer.
> When you reach a noun, copy the noun into the buffer, plus the list
>  of adjectives (in whichever order you like!), then clear the list
>  of adjectives ready for the next noun.
>
> Does that help?
>
> Something like this:
>
> def swap(sentence):
>    buffer = []
>    adjectives = []
>    for word in sentence.split():
>        if word.endswith('/ADJ'):
>            adjectives.append(word)
>        elif word.endswith('/N'):
>            buffer.extend(adjectives)
>            buffer.append(word)
>            adjectives = []
>        else:
>            buffer.append(word)
>    return ' '.join(buffer)
>
>
> P.S. Since this looks like homework, I have left a deliberate mistake in my
> code for you to fix. But it should be easy to fix if you study the code and
> think about what it is doing.
>
>
> --
> Steven
> ______________________________**_________________
> Tutor maillist  -  Tutor@python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/**mailman/listinfo/tutor<http://mail.python.org/mailman/listinfo/tutor>
>



-- 
لا أعرف مظلوما تواطأ الناس علي هضمه ولا زهدوا في إنصافه كالحقيقة.....محمد
الغزالي
"No victim has ever been more repressed and alienated than the truth"

Emad Soliman Nawfal
Indiana University, Bloomington
--------------------------------------------------------
_______________________________________________
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor

Reply via email to