473,799 Members | 2,822 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

text file parsing

3 New Member
hi,

i have text file of the form

atom_trace('emo tion_response_l evel(a1, 1.56072)', emotion_respons e_level(a1, 1.56072), [range(49, 50, true), range(0, 49, unknown)]).

and

atom_trace('got o(a1, a3)', goto(a1, a3), [range(1, 51, true), range(0, 1, unknown)]).

i heve to parse this file . Basically what i required is , i want to extract, emotion response level, range , true and . please tell, how i can parse it.

awaiting your reply.
thanks.

Ghazanfar

removed
Mar 14 '07 #1
10 1878
bvdet
2,851 Recognized Expert Moderator Specialist
hi,

i have text file of the form

atom_trace('emo tion_response_l evel(a1, 1.56072)', emotion_respons e_level(a1, 1.56072), [range(49, 50, true), range(0, 49, unknown)]).

and

atom_trace('got o(a1, a3)', goto(a1, a3), [range(1, 51, true), range(0, 1, unknown)]).

i heve to parse this file . Basically what i required is , i want to extract, emotion response level, range , true and . please tell, how i can parse it.

awaiting your reply.
thanks.

Ghazanfar

s_ghazanfar@hot mail.com
We can help you with this, but we need some more information. Can you show us exactly how the data should appear after extraction?
e.g.:
Expand|Select|Wrap|Line Numbers
  1. 'emotion_response_level_a1 = 1.56072; range = (49, 50); True'
Should the data be in a dictionary, list or tuple? What about the other ranges?
Mar 14 '07 #2
dshimer
136 Recognized Expert New Member
Guys like GhostDog74 and bvdet really give me a clue as to how elementary my understanding of modules really is, so I'd like to take this opportunity to learn something based on how I first approached it.
In this case my first inclination because the input seems so structured and consistant would be to just grab all the data into a list by replacing all the non data characters with a space then splitting the result, then act on the appropriate index values converting them to numbers or whatever as I go. For example something like
Expand|Select|Wrap|Line Numbers
  1. >>> txt="atom_trace('emotion_response_level(a1, 1.56072)', emotion_response_level(a1, 1.56072), [range(49, 50, true), range(0, 49, unknown)])."
  2. >>> print txt.replace('[',' ').replace(']',' ').replace('(',' ').replace(')',' ').replace(',',' ').replace("'",' ').split()
  3. ['atom_trace', 'emotion_response_level', 'a1', '1.56072', 'emotion_response_level', 'a1', '1.56072', 'range', '49', '50', 'true', 'range', '0', '49', 'unknown', '.']
  4.  
I know there are ways to create multiple replace functions using re, but if that were my only goal (replace stuff with spaces and split, or just split on the non data characters) is there an easier way to do it?
Mar 14 '07 #3
ghazanfar
3 New Member
i have text file like this.

LeadsTo trace
atom_trace('emo tion_response_l evel(a1, 1.56072)', emotion_respons e_level(a1, 1.76072), [range(49, 50, true), range(0, 49, unknown)]).

i can describe above line of text in this way:
a1(agent ) has emotion_respons e_level=1.56072 and that is correspond to range(49,50,tru e), similarly

a1(agent) has emotion_respons e_level=1.76072 and that is correspond to range(0,49,unkn own), now later on, i have to use in my program that,the agent a1 has emotion_ response_level= 1.56072, because it is true in rage (49,50,true)
i.e. i have to select the portion related to true range values.
and then i have also use the vale of range in the program.

atom_trace('got o(a1, a3)', goto(a1, a3), [range(1, 51, true), range(0, 1, unknown)]).

atom_trace('age nts_have_conver sation(a1, a3, ajax)', agents_have_con versation(a1, a3, ajax), [range(3, 11, true), range(0, 3, unknown)]).

ghazanfar
Mar 14 '07 #4
bartonc
6,596 Recognized Expert Expert
i have text file like this.

LeadsTo trace
atom_trace('emo tion_response_l evel(a1, 1.56072)', emotion_respons e_level(a1, 1.76072), [range(49, 50, true), range(0, 49, unknown)]).

i can describe above line of text in this way:
a1(agent ) has emotion_respons e_level=1.56072 and that is correspond to range(49,50,tru e), similarly

a1(agent) has emotion_respons e_level=1.76072 and that is correspond to range(0,49,unkn own), now later on, i have to use in my program that,the agent a1 has emotion_ response_level= 1.56072, because it is true in rage (49,50,true)
i.e. i have to select the portion related to true range values.
and then i have also use the vale of range in the program.

atom_trace('got o(a1, a3)', goto(a1, a3), [range(1, 51, true), range(0, 1, unknown)]).

atom_trace('age nts_have_conver sation(a1, a3, ajax)', agents_have_con versation(a1, a3, ajax), [range(3, 11, true), range(0, 3, unknown)]).

ghazanfar
Please read the "POSTING GUIDELINES" for this site. Double posting and email address in posts are two things that are not allowed.
Mar 14 '07 #5
ghostdog74
511 Recognized Expert Contributor
Can you give an exact sample of the input file , and how you want your output to be like. i can't really understand what you are describing.
Mar 15 '07 #6
ghazanfar
3 New Member
The general format is like

atom_trace(seed , seed, [range(860.0, 1000, false), range(840.0, 860.0, true), range(580.0, 840.0, false), range(560.0, 580.0, true), range(300.0, 560.0, false), range(280, 300.0, true), range(20, 280, false), range(0, 20, true)]).

But I required result as I send u.

Here is the sample.

atom_trace('emo tion_response_l evel(a1, 1.56072)', emotion_respons e_level(a1, 1.56072), [range(49, 50, true), range(0, 49, unknown)]).

atom_trace('emo tion_response_l evel(a2, 1.81894)', emotion_respons e_level(a2, 1.81894), [range(49, 50, true), range(0, 49, unknown)]).

atom_trace('emo tion_response_l evel(a3, 1.51193)', emotion_respons e_level(a3, 1.51193), [range(49, 50, true), range(0, 49, unknown)]).

atom_trace('emo tion_response_l evel(a1, 1.85)', emotion_respons e_level(a1, 1.85), [range(1, 50, unknown), range(0, 1, true)]).

atom_trace('emo tion_response_l evel(a2, 1.2)', emotion_respons e_level(a2, 1.2), [range(1, 50, unknown), range(0, 1, true)]).
atom_trace('emo tion_response_l evel(a3, 0.7)', emotion_respons e_level(a3, 0.7), [range(1, 50, unknown), range(0, 1, true)]).
atom_trace('emo tion_response_l evel(a1, 1.84775)', emotion_respons e_level(a1, 1.84775), [range(2, 50, unknown), range(1, 2, true), range(0, 1, unknown)]).
atom_trace('emo tion_response_l evel(a2, 1.39275)', emotion_respons e_level(a2, 1.39275), [range(2, 50, unknown), range(1, 2, true), range(0, 1, unknown)]).
atom_trace('emo tion_response_l evel(a3, 1.04275)', emotion_respons e_level(a3, 1.04275), [range(2, 50, unknown), range(1, 2, true), range(0, 1, unknown)]).
atom_trace('has _emotional_valu e(a1, aspect, 1.8)', has_emotional_v alue(a1, aspect, 1.8), [range(3, 50, unknown), range(0, 3, true)]).
atom_trace('has _emotional_valu e(a3, aspect, 1.8)', has_emotional_v alue(a3, aspect, 1.8), [range(3, 50, unknown), range(0, 3, true)]).


Ghazanfar
Mar 15 '07 #7
bvdet
2,851 Recognized Expert Moderator Specialist
The general format is like

atom_trace(seed , seed, [range(860.0, 1000, false), range(840.0, 860.0, true), range(580.0, 840.0, false), range(560.0, 580.0, true), range(300.0, 560.0, false), range(280, 300.0, true), range(20, 280, false), range(0, 20, true)]).

But I required result as I send u.

Here is the sample.

atom_trace('emo tion_response_l evel(a1, 1.56072)', emotion_respons e_level(a1, 1.56072), [range(49, 50, true), range(0, 49, unknown)]).

atom_trace('emo tion_response_l evel(a2, 1.81894)', emotion_respons e_level(a2, 1.81894), [range(49, 50, true), range(0, 49, unknown)]).

atom_trace('emo tion_response_l evel(a3, 1.51193)', emotion_respons e_level(a3, 1.51193), [range(49, 50, true), range(0, 49, unknown)]).

atom_trace('emo tion_response_l evel(a1, 1.85)', emotion_respons e_level(a1, 1.85), [range(1, 50, unknown), range(0, 1, true)]).

atom_trace('emo tion_response_l evel(a2, 1.2)', emotion_respons e_level(a2, 1.2), [range(1, 50, unknown), range(0, 1, true)]).
atom_trace('emo tion_response_l evel(a3, 0.7)', emotion_respons e_level(a3, 0.7), [range(1, 50, unknown), range(0, 1, true)]).
atom_trace('emo tion_response_l evel(a1, 1.84775)', emotion_respons e_level(a1, 1.84775), [range(2, 50, unknown), range(1, 2, true), range(0, 1, unknown)]).
atom_trace('emo tion_response_l evel(a2, 1.39275)', emotion_respons e_level(a2, 1.39275), [range(2, 50, unknown), range(1, 2, true), range(0, 1, unknown)]).
atom_trace('emo tion_response_l evel(a3, 1.04275)', emotion_respons e_level(a3, 1.04275), [range(2, 50, unknown), range(1, 2, true), range(0, 1, unknown)]).
atom_trace('has _emotional_valu e(a1, aspect, 1.8)', has_emotional_v alue(a1, aspect, 1.8), [range(3, 50, unknown), range(0, 3, true)]).
atom_trace('has _emotional_valu e(a3, aspect, 1.8)', has_emotional_v alue(a3, aspect, 1.8), [range(3, 50, unknown), range(0, 3, true)]).


Ghazanfar
I would suggest creating a dictionary of dictionaries in this format:
Expand|Select|Wrap|Line Numbers
  1. {record1: {seed: emotion....., agent: ax, value: x.xxxx, rangeTrue: [low, high], rangeFalse: [low,high]}
  2.  record2: {....}
  3.  record3: {....}
  4. }
Mar 15 '07 #8
bvdet
2,851 Recognized Expert Moderator Specialist
Since there may be multiple ranges, maybe this format would be better:
Expand|Select|Wrap|Line Numbers
  1. rec0 = {'ranges': [(49, 50, True), (0, 49, False)], 'seed': 'emotion_response_level', 'value': 1.5607200000000001, 'agent': 'a1'}
Sample dictionary listing:
Expand|Select|Wrap|Line Numbers
  1. rec4: ranges = [(1, 50, False), (0, 1, True)]
  2. rec4: seed = emotion_response_level
  3. rec4: value = 1.2
  4. rec4: agent = a2
  5. rec5: ranges = [(1, 50, False), (0, 1, True)]
  6. rec5: seed = emotion_response_level
  7. rec5: value = 0.7
  8. rec5: agent = a3
  9. rec6: ranges = [(2, 50, False), (1, 2, True), (0, 1, False)]
  10. rec6: seed = emotion_response_level
  11. rec6: value = 1.84775
  12. rec6: agent = a1
Mar 15 '07 #9
bvdet
2,851 Recognized Expert Moderator Specialist
Since there may be multiple ranges, maybe this format would be better:
Expand|Select|Wrap|Line Numbers
  1. rec0 = {'ranges': [(49, 50, True), (0, 49, False)], 'seed': 'emotion_response_level', 'value': 1.5607200000000001, 'agent': 'a1'}
Sample dictionary listing:
Expand|Select|Wrap|Line Numbers
  1. rec4: ranges = [(1, 50, False), (0, 1, True)]
  2. rec4: seed = emotion_response_level
  3. rec4: value = 1.2
  4. rec4: agent = a2
  5. rec5: ranges = [(1, 50, False), (0, 1, True)]
  6. rec5: seed = emotion_response_level
  7. rec5: value = 0.7
  8. rec5: agent = a3
  9. rec6: ranges = [(2, 50, False), (1, 2, True), (0, 1, False)]
  10. rec6: seed = emotion_response_level
  11. rec6: value = 1.84775
  12. rec6: agent = a1
Ghazanfar,

Would the data compiled in this format work for you? Are you going to write the code yourself, or do you need help? We are here if you need help.
Mar 16 '07 #10

Sign in to post your reply or Sign up for a free account.

Similar topics

2
6976
by: Bob | last post by:
Hi, I have a website in a Linux/Apache shared hosting environment and have been given access to the MySQL server running on the same machine. To access this database from PHP, I have to call mysql_connect(host, user, password) where the password is hardcoded into my PHP source file in clear text. I see two security problems with this:
1
17528
by: Scott | last post by:
I am new to perl, and have not found any good examples of parsing to help me out. I have a text file that I am reading into an array that has to be parsed out and put into another file. I have not found any good examples of this. Does anyone know of any? For example the text file looks like this... 900002 "Test,Test" 1/1/2004 F 21 with tabs inbetween each of the colums of the text file.
27
5043
by: Eric | last post by:
Assume that disk space is not an issue (the files will be small < 5k in general for the purpose of storing preferences) Assume that transportation to another OS may never occur. Are there any solid reasons to prefer text files over binary files files?
4
1728
by: Hugh | last post by:
Hello, I am having some problems understanding (most likely), parsing a text file. I would like to parse a file like: block1 { stuff; ... stuffN; };
11
2841
by: .Net Sports | last post by:
In VB.net, I'm trying to do a couple of things in a couple of different blocks of code. I need to take the first 25 characters of a text file, then append at the end some ellipses and a MORE link to a webpage where viewers can read the rest of the article: This is the first few characters of text from my file.......<a href="article-to-read.aspx"> MORE </a> ...I also need to do some in file parsing where I start at one known keyword (START...
13
4970
by: sonald | last post by:
Hi, Can anybody tell me how to change the text delimiter in FastCSV Parser ? By default the text delimiter is double quotes(") I want to change it to anything else... say a pipe (|).. can anyone please tell me how do i go about it?
4
1665
by: thenewuser | last post by:
Hi all, I am working on windows 2000 and using php 5.0 and apache 2.0.59. I am facing a problem while parsing a text file.Actually I am using a pop server for parsing an email.I am downloading new mails from that server using php and parsing the attachments.I want to parse text files as well. BUt when i save the attached .txt file on my machine, "=20" gets appended at the end of every line. If the file is an xml file, sometimes "=90" gets...
3
4387
by: toton | last post by:
Hi, I have some ascii files, which are having some formatted text. I want to read some section only from the total file. For that what I am doing is indexing the sections (denoted by .START in the file) with the location. And for a particular section I parse only that section. The file is something like, .... DATAS
2
2153
by: flyzone | last post by:
Goodmorning people :) I have just started to learn this language and i have a logical problem. I need to write a program to parse various file of text. Here two sample: --------------- trial text bla bla bla bla error bla bla bla bla bla bla bla bla on more lines
2
2593
by: python | last post by:
I'm parsing a text file for a proprietary product that has the following 2 directives: #include <somefile> #define <name<value> Defined constants are referenced via <#name#syntax. I'm looking for a single text stream that results from processing a file containing these directives. Even better would be an iterator(?) type
0
9689
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
10269
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
10248
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
9085
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
7573
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
6811
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5469
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...
2
3764
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2942
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.