<div dir="ltr"><br><br><div class="gmail_quote">On Sat, Oct 8, 2011 at 12:11 PM, Andreas Perstinger <span dir="ltr">&lt;<a href="mailto:andreas.perstinger@gmx.net">andreas.perstinger@gmx.net</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
<div class="im">On 2011-10-08 09:53, Peter Otten wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Emad Nawfal (ÚãÜ äæÝá ÜÇÏ) wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
 Here is the function as I used it, and it works fine:<br>
<br>
 def swap(sentence):<br>
    buffer = []<br>
    adjectives = []<br>
    for word in sentence.split():<br>
        if word.endswith(&#39;/ADJ&#39;):<br>
            adjectives.append(word)<br>
        elif word.endswith(&#39;/N&#39;):<br>
            buffer.append(word)<br>
            buffer.extend(adjectives)<br>
<br>
            adjectives = []<br>
        else:<br>
            buffer.append(word)<br>
    return &#39; &#39;.join(buffer)<br>
</blockquote>
<br>
Does the classification scheme allow for adjectives that are not followed by<br>
a noun? Example: if &quot;good&quot; in the sentence &quot;That looks good&quot; were classified<br>
as an adjective it would be silently dropped.<br>
</blockquote>
<br></div>
As far as I know, adjectives are always in front of a noun in English. Therefore I suggest iterating backwards and everytime you come across a noun check if it is preceded by an adjective and swap the positions. Iterating backwards is necessary for cases where more than one adjective is in front of the noun. So the noun &quot;floats&quot; towards the beginning of the sentence while all adjectives without nouns (or behind nouns - I don&#39;t know if that&#39;s possible in English) will stay where they are:<br>

<br>
def swap(sentence):<br>
    s = sentence.split()<br>
    for i in reversed(range(len(s))):<br>
        if s[i].endswith(&quot;/N&quot;) and s[i-1].endswith(&quot;/ADJ&quot;):<br>
            s[i], s[i-1] = s[i-1], s[i]<br>
    return s<br>
<br>
&gt;&gt;&gt; swap(&quot;the/DET tall/ADJ man/N plays/VBZ well/ADV&quot;)<br>
[&#39;the/DET&#39;, &#39;man/N&#39;, &#39;tall/ADJ&#39;, &#39;plays/VBZ&#39;, &#39;well/ADV&#39;]<br>
<br>
&gt;&gt;&gt; swap(&quot;That/DET looks/VBZ good/ADJ&quot;)<br>
[&#39;That/DET&#39;, &#39;looks/VBZ&#39;, &#39;good/ADJ&#39;]<br>
<br>
&gt;&gt;&gt; swap(&quot;He/P is/VBZ a/ART big/ADJ old/ADJ man/N who/P went/VBZ crazy/ADJ&quot;)<br>
[&#39;He/P&#39;, &#39;is/VBZ&#39;, &#39;a/ART&#39;, &#39;man/N&#39;, &#39;big/ADJ&#39;, &#39;old/ADJ&#39;, &#39;who/P&#39;, &#39;went/VBZ&#39;, &#39;crazy/ADJ&#39;]<br>
<br>
Bye, Andreas<div><div></div><div class="h5"><br>
<br>
______________________________<u></u>_________________<br>
Tutor maillist  -  <a href="mailto:Tutor@python.org" target="_blank">Tutor@python.org</a><br>
To unsubscribe or change subscription options:<br>
<a href="http://mail.python.org/mailman/listinfo/tutor" target="_blank">http://mail.python.org/<u></u>mailman/listinfo/tutor</a><br>
</div></div></blockquote></div><br><br>Thanks Andreas and Peter. Andreas&#39;s solution works perfect for me as it takes care of non-qualitative adjectives. <br>I now have enough information to get started on my little project. Hope you don&#39;t mind my coming back to you if something comes up.<br>
-- <br>áÇ ÃÚÑÝ ãÙáæãÇ ÊæÇØàÇáäÇÓ Úáí åÖãå æáÇ ÒåÏæÇ Ýí ÅäÕÇÝå ßÇáÍÞíÞÉ.....ãÍãÏ ÇáÛÒÇáí<br>&quot;No victim has ever been more repressed and alienated than the truth&quot;<br><br>Emad Soliman Nawfal<br>Indiana University, Bloomington<br>
--------------------------------------------------------<br>
</div>