473,699 Members | 3,212 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

splitting strings with python

im trying to split a string with this form (the string is from a
japanese dictionary file with mulitple definitions in english for each
japanese word)
str1 [str2] / (def1, ...) (1) def2 / def3 / .... (2) def4/ def5 ... /
the varibles i need are str*, def*.

sometimes the (1) and (2) are not included - they are included only if
the word has two different meanings
"..." means that there are sometimes more then two definitions per
meaning.
im trying to use the re.split() function but with no luck.

Is this possible with python, or am i dreamin!?

All the best,

..

Jul 19 '05 #1
4 1835

<sb******@gmail .com> wrote in message
news:11******** **************@ g47g2000cwa.goo glegroups.com.. .
im trying to split a string with this form (the string is from a
japanese dictionary file with mulitple definitions in english for each
japanese word)
str1 [str2] / (def1, ...) (1) def2 / def3 / .... (2) def4/ def5 ... /
the varibles i need are str*, def*.

sometimes the (1) and (2) are not included - they are included only if
the word has two different meanings
"..." means that there are sometimes more then two definitions per
meaning.
im trying to use the re.split() function but with no luck.

Is this possible with python, or am i dreamin!?

All the best,

.


i don't think you can do it with string.split, although i guess you could do
it with re.split, although i think it's easier to use re.findall.

import re
re.findall("[a-zA-Z][ a-zA-Z0-9]*", inputstring)

should work.


Jul 19 '05 #2
one problem is that str1 is unicode (japanese kanji), and str2 is
japanese kana

can i still use re.findall(~)?

thanks for your help!

Jul 19 '05 #3
sorry, i should be more specific about the encoding

it's euc-jp

i googled alittle, and you can still use re.findall with the japanese
kana, but i didnt find anything about kanji.

Jul 19 '05 #4
sb******@gmail. com wrote:
im trying to split a string with this form (the string is from a
japanese dictionary file with mulitple definitions in english for each
japanese word)
str1 [str2] / (def1, ...) (1) def2 / def3 / .... (2) def4/ def5 ... /
the varibles i need are str*, def*.
Could you post a few examples of real data and what you want to extract from it? The above raises a few questions:
- are str* and def* single words or can they include whitespace, comma, slash, paren...
- not clear what replaces the ... (or if they are literal)

This might be a good job for PyParsing.

Kent
sometimes the (1) and (2) are not included - they are included only if
the word has two different meanings
"..." means that there are sometimes more then two definitions per
meaning.
im trying to use the re.split() function but with no luck.

Is this possible with python, or am i dreamin!?

All the best,

.

Jul 19 '05 #5

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

Similar topics

18
2063
by: robsom | last post by:
Hi, I have a problem with a small python program I'm trying to write and I hope somebody may help me. I'm working on tables of this kind: CGA 1988 06 21 13 48 G500-050 D 509.62 J.. R1 1993 01 28 00 00 880006 CGA 1988 06 21 14 04 G500-051 D 550.62 J.. R1 1993 01 28 00 00 880007 I have to read each line of the table and put it into comma-separated lists like these for later manipulation: ...
5
5353
by: Steven Bethard | last post by:
Here's what I'm doing: >>> lst = >>> splits = >>> for s in lst: .... pair = s.split(':') .... if len(pair) != 2: .... pair.append(None) .... splits.append(pair) ....
7
3202
by: Jeremy Sanders | last post by:
I have a large string containing lines of text separated by '\n'. I'm currently using text.splitlines(True) to break the text into lines, and I'm iterating over the resulting list. This is very slow (when using 400000 lines!). Other than dumping the string to a file, and reading it back using the file iterator, is there a way to quickly iterate over the lines? I tried using newpos=text.find('\n', pos), and returning the chopped text...
9
14724
by: Dr. StrangeLove | last post by:
Greetings, Let say we want to split column 'list' in table lists into separate rows using the comma as the delimiter. Table lists id list 1 aa,bbb,c 2 e,f,gggg,hh 3 ii,kk 4 m
2
2520
by: Trint Smith | last post by:
Ok, My program has been formating .txt files for input into sql server and ran into a problem...the .txt is an export from an accounting package and is only supposed to contain comas (,) between fields in a table...well, someone has been entering description fields with comas (,) in the description and now it is splitting between one field...example: "santa clause mushrooms, pens, cups and dolls" I somehow need to NOT split anything...
20
3704
by: Opettaja | last post by:
I am new to c# and I am currently trying to make a program to retrieve Battlefield 2 game stats from the gamespy servers. I have got it so I can retrieve the data but I do not know how to cut up the data to assign each value to its own variable. So right now I am just saving the data to a txt file and when I look in the text file all the data is there. Not sure if this matters but when I open the text file in Word pad (Rich Text) It...
4
5347
by: Michael Yanowitz | last post by:
Hello: For some reason I can't figure out how to split a 4-byte (for instance) float number (such as 3.14159265359) into its 4-bytes so I can send it via a socket to another computer. For integers, it is easy, I can get the 4 bytes by anding like: byte1 = int_val & 0x000000FF byte2 = int_val & 0x0000FF00 byte3 = int_val & 0x00FF0000
17
8203
by: Qiangning Hong | last post by:
I've got some strings to split. They are main words, but some words are inside a pair of brackets and should be considered as one unit. I prefer to use re.split, but haven't written a working one after hours of work. Example: "a (b c) d h i" should be splitted to ", "h", "i"]
2
3268
by: shadow_ | last post by:
Hi i m new at C and trying to write a parser and a string class. Basicly program will read data from file and splits it into lines then lines to words. i used strtok function for splitting data to lines it worked quite well but srttok isnot working for multiple blank or commas. Can strtok do this kind of splitting if it cant what should i use . Unal
4
3818
by: Steven D'Aprano | last post by:
I'm trying to split a URL into components. For example: URL = 'http://steve:secret@www.domain.com.au:82/dir" + \ 'ectory/file.html;params?query#fragment' (joining the strings above with plus has no significance, it's just to avoid word-wrapping) If I split the URL, I would like to get the following components:
0
8706
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9055
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8947
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
7787
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6552
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4392
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4642
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3076
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2366
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.