473,396 Members | 1,886 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

How to parse a list using pyparsing

Hi Guys

I am using pyparsing to parse transformation rules for my natural
language processing application. The rules also have structure to
them, i.e., a rule might look like:

[ A [ B ] ] <--> [ C [ D ] ]

where A, B, C, D are nodes in the rule (although they are usually much
more complex than this)

I have figured out how to parse the nodes out of the rules and return
them like this:

[ [ A, B ], [ C, D ] ]

but I would like to return them in a list with the same hierarchical
structure as in the original rule, i.e., I would like to return:

[ [ A, [ B ] ] , [ C, [ D ] ] ]

I hope that makes sense. Any advice is much appreciated.
Thanks !
Nitin
Jul 18 '05 #1
0 1105

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: serpent17 | last post by:
Hello all, I have this line of numbers: 04242005 18:20:42-0.000002, 271.1748608, , , repeated several times in a text file and I would like each element to be part of a vector. how do...
11
by: vdavidster | last post by:
Hello everyone, I want to convert a tuple to a list, and I expected this behavior: list(('abc','def')) -> list(('abc')) -> But Python gave me this behavior: list(('abc','def')) ->
1
by: Petr Jakes | last post by:
I have a file which contains data in the format shown in the sample bellow. How can I parse it to get following: (14,trigger,guard,do_action,15) Thanks a lot for your postings Petr Jakes ...
10
by: Ernesto | last post by:
I'm still fairly new to python, so I need some guidance here... I have a text file with lots of data. I only need some of the data. I want to put the useful data into an struct-like...
14
by: Rob Cowie | last post by:
I'm having a bit of trouble with this so any help would be gratefully recieved... After splitting up a url I have a string of the form 'tag1+tag2+tag3-tag4', or '-tag1-tag2' etc. The first tag...
8
by: jerry.levan | last post by:
Hi, I have a file that contains a "tcl" list stored as a string. The list members are sql commands ex: { begin { select * from foo where baz='whatever'} {select * from gooble } end { insert...
10
by: Michael B. Trausch | last post by:
Alright... I am attempting to find a way to parse ANSI text from a telnet application. However, I am experiencing a bit of trouble. What I want to do is have all ANSI sequences _removed_ from...
9
by: martinskou | last post by:
Hi, I'm looking for something like: multi_split( 'a:=b+c' , ) returning: whats the python way to achieve this, preferably without regexp? Thanks.
2
by: dpw.asdf | last post by:
I have been searching all over for a solution to this. I am new to Python, so I'm a little lost. Any pointers would be a great help. I have a couple hundred emails that contain data I would like to...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.