Delete all items in the list

2009-02-26 Thread Clarendon
Hi. This must be a simple command but I just can't find it in the
Phthon manual. How do I delete all items with a certain condition from
a list? For instance:

L=['a', 'b', 'c', 'a']

I want to delete all 'a's from the list.
But if L.remove('a') only deletes the first 'a'.

How do you delete all 'a's?
I would really appreciate your help.

Thanks.

--
http://mail.python.org/mailman/listinfo/python-list


Re: Delete all items in the list

2009-02-28 Thread Clarendon
Thank you very much for all your replies. I actually used the while
loop as the data is not large. But I was looking for a simpler, built
in command, something like L.remove('a', all) or L.removeall('a').
Python has re.findall function, but why not removeall, so users have
to make up long lines of expression?
--
http://mail.python.org/mailman/listinfo/python-list


Python parser

2009-03-02 Thread Clarendon
Can somebody recommend a good parser that can be used in Python
programs? I need a parser with large grammar that can cover a large
amount of random texts.

Thank you very much.
--
http://mail.python.org/mailman/listinfo/python-list


Re: Python parser

2009-03-02 Thread Clarendon
Thank you, Lie and Andrew for your help.

I have studied NLTK quite closely but its parsers seem to be only for
demo. It has a very limited grammar set, and even a parser that is
supposed to be "large" does not have enough grammar to cover common
words like "I".

I need to parse a large amount of texts collected from the web (around
a couple hundred sentences at a time) very quickly, so I need a parser
with a broad scope of grammar, enough to cover all these texts. This
is what I mean by 'random'.

An advanced programmer has advised me that Python is rather slow in
processing large data, and so there are not many parsers written in
Python. He recommends that I use Jython to use parsers written in
Java. What are your views about this?

Thank you very much.



--
http://mail.python.org/mailman/listinfo/python-list


Accessing a parse tree

2009-04-16 Thread Clarendon
Hello!

I need a program that accesses a parse tree based on the designated
words (terminals) within the tree. For instance, in:

I came a long way in changing my habit.

(ROOT
  (S
(NP (PRP I))
(VP (VBD came)
  (NP (DT a) (JJ long) (NN way))
  (PP (IN in)
(S
  (VP (VBG changing)
(NP (PRP$ my) (NN habit))


the designated words are "a long way". I need the program to recognize
how many parentheses there are after them. Currently two: NN way)).
Then I need it to see how many parentheses there are before it.
Currently there are two as well: (NP (DT. Then the program should that
the designated wordssee are followed by (PP (IN in) and then by  (S
(VP (VBG.

I looked at the NLTK Tree class but it does not seem to have a method
that works with designated words. Is there some kind of tree navigator
that does something like this? If I need to write one myself, I would
appreciate any tips about where to start.

Thanks.
--
http://mail.python.org/mailman/listinfo/python-list


Re: Accessing a parse tree

2009-04-17 Thread Clarendon
Thank you very much for this information. It seems to point me to the
right direction. However, I do not fully understand the flatten
function and its output. Some indices seem to be inaccurate. I tried
to find this function at nltk.tree.Tree.flatten, but it returns a
flattened tree, not a tuple.

So your flatten function must be a different one, and it's not one of
the builtins, either. Could you tell me where I can find the
documentation about this flatten function?
--
http://mail.python.org/mailman/listinfo/python-list


Re: Accessing a parse tree

2009-04-18 Thread Clarendon
Dear John Machin

So sorry about the typo. It should be: "the program should *see* that
the designated *words* are..."

"a long way" has two parentheses to the left -- (VP (DT -- before it
hits a separate group -- VBD came). If there are three parenthesis,
for instance (NP, this will means that what follows "a long way" is a
modifier of "a long way", as illustrated below:

(VP (VBD came)
   (NP
 (NP (DT a) (JJ long) (NN way))
 (PP (IN in)

So I am trying to capture the grammatical relations following the
designated words.




--
http://mail.python.org/mailman/listinfo/python-list


string Index for the last position

2009-04-28 Thread Clarendon
I am trying to get the index for the last occurrance of a sub string.

S = 'dab dab dab'
print S.find('ab')
1

This gives me the index for the first position of 'ab'.
But I need to index the last position of 'ab' here.
Is there a quick option for find that will do this, or do I have to
write a long code to get what I want?

Thank you very much.


--
http://mail.python.org/mailman/listinfo/python-list


Re: string Index for the last position

2009-04-28 Thread Clarendon
Dear Christian

Thank you so much! It works!

--
http://mail.python.org/mailman/listinfo/python-list