hi,
i have text file of the form
atom_trace('emotion_response_level(a1, 1.56072)', emotion_response_level(a1, 1.56072), [range(49, 50, true), range(0, 49, unknown)]).
and
atom_trace('goto(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
10 1856 bvdet 2,851
Expert Mod 2GB
hi,
i have text file of the form
atom_trace('emotion_response_level(a1, 1.56072)', emotion_response_level(a1, 1.56072), [range(49, 50, true), range(0, 49, unknown)]).
and
atom_trace('goto(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@hotmail.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.: - '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?
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 - >>> txt="atom_trace('emotion_response_level(a1, 1.56072)', emotion_response_level(a1, 1.56072), [range(49, 50, true), range(0, 49, unknown)])."
-
>>> print txt.replace('[',' ').replace(']',' ').replace('(',' ').replace(')',' ').replace(',',' ').replace("'",' ').split()
-
['atom_trace', 'emotion_response_level', 'a1', '1.56072', 'emotion_response_level', 'a1', '1.56072', 'range', '49', '50', 'true', 'range', '0', '49', 'unknown', '.']
-
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?
i have text file like this.
LeadsTo trace
atom_trace('emotion_response_level(a1, 1.56072)', emotion_response_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_response_level=1.56072 and that is correspond to range(49,50,true), similarly
a1(agent) has emotion_response_level=1.76072 and that is correspond to range(0,49,unknown), 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('goto(a1, a3)', goto(a1, a3), [range(1, 51, true), range(0, 1, unknown)]).
atom_trace('agents_have_conversation(a1, a3, ajax)', agents_have_conversation(a1, a3, ajax), [range(3, 11, true), range(0, 3, unknown)]).
ghazanfar
i have text file like this.
LeadsTo trace
atom_trace('emotion_response_level(a1, 1.56072)', emotion_response_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_response_level=1.56072 and that is correspond to range(49,50,true), similarly
a1(agent) has emotion_response_level=1.76072 and that is correspond to range(0,49,unknown), 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('goto(a1, a3)', goto(a1, a3), [range(1, 51, true), range(0, 1, unknown)]).
atom_trace('agents_have_conversation(a1, a3, ajax)', agents_have_conversation(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.
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.
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('emotion_response_level(a1, 1.56072)', emotion_response_level(a1, 1.56072), [range(49, 50, true), range(0, 49, unknown)]).
atom_trace('emotion_response_level(a2, 1.81894)', emotion_response_level(a2, 1.81894), [range(49, 50, true), range(0, 49, unknown)]).
atom_trace('emotion_response_level(a3, 1.51193)', emotion_response_level(a3, 1.51193), [range(49, 50, true), range(0, 49, unknown)]).
atom_trace('emotion_response_level(a1, 1.85)', emotion_response_level(a1, 1.85), [range(1, 50, unknown), range(0, 1, true)]).
atom_trace('emotion_response_level(a2, 1.2)', emotion_response_level(a2, 1.2), [range(1, 50, unknown), range(0, 1, true)]).
atom_trace('emotion_response_level(a3, 0.7)', emotion_response_level(a3, 0.7), [range(1, 50, unknown), range(0, 1, true)]).
atom_trace('emotion_response_level(a1, 1.84775)', emotion_response_level(a1, 1.84775), [range(2, 50, unknown), range(1, 2, true), range(0, 1, unknown)]).
atom_trace('emotion_response_level(a2, 1.39275)', emotion_response_level(a2, 1.39275), [range(2, 50, unknown), range(1, 2, true), range(0, 1, unknown)]).
atom_trace('emotion_response_level(a3, 1.04275)', emotion_response_level(a3, 1.04275), [range(2, 50, unknown), range(1, 2, true), range(0, 1, unknown)]).
atom_trace('has_emotional_value(a1, aspect, 1.8)', has_emotional_value(a1, aspect, 1.8), [range(3, 50, unknown), range(0, 3, true)]).
atom_trace('has_emotional_value(a3, aspect, 1.8)', has_emotional_value(a3, aspect, 1.8), [range(3, 50, unknown), range(0, 3, true)]).
Ghazanfar
bvdet 2,851
Expert Mod 2GB
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('emotion_response_level(a1, 1.56072)', emotion_response_level(a1, 1.56072), [range(49, 50, true), range(0, 49, unknown)]).
atom_trace('emotion_response_level(a2, 1.81894)', emotion_response_level(a2, 1.81894), [range(49, 50, true), range(0, 49, unknown)]).
atom_trace('emotion_response_level(a3, 1.51193)', emotion_response_level(a3, 1.51193), [range(49, 50, true), range(0, 49, unknown)]).
atom_trace('emotion_response_level(a1, 1.85)', emotion_response_level(a1, 1.85), [range(1, 50, unknown), range(0, 1, true)]).
atom_trace('emotion_response_level(a2, 1.2)', emotion_response_level(a2, 1.2), [range(1, 50, unknown), range(0, 1, true)]).
atom_trace('emotion_response_level(a3, 0.7)', emotion_response_level(a3, 0.7), [range(1, 50, unknown), range(0, 1, true)]).
atom_trace('emotion_response_level(a1, 1.84775)', emotion_response_level(a1, 1.84775), [range(2, 50, unknown), range(1, 2, true), range(0, 1, unknown)]).
atom_trace('emotion_response_level(a2, 1.39275)', emotion_response_level(a2, 1.39275), [range(2, 50, unknown), range(1, 2, true), range(0, 1, unknown)]).
atom_trace('emotion_response_level(a3, 1.04275)', emotion_response_level(a3, 1.04275), [range(2, 50, unknown), range(1, 2, true), range(0, 1, unknown)]).
atom_trace('has_emotional_value(a1, aspect, 1.8)', has_emotional_value(a1, aspect, 1.8), [range(3, 50, unknown), range(0, 3, true)]).
atom_trace('has_emotional_value(a3, aspect, 1.8)', has_emotional_value(a3, aspect, 1.8), [range(3, 50, unknown), range(0, 3, true)]).
Ghazanfar
I would suggest creating a dictionary of dictionaries in this format: -
{record1: {seed: emotion....., agent: ax, value: x.xxxx, rangeTrue: [low, high], rangeFalse: [low,high]}
-
record2: {....}
-
record3: {....}
-
}
bvdet 2,851
Expert Mod 2GB
Since there may be multiple ranges, maybe this format would be better: - rec0 = {'ranges': [(49, 50, True), (0, 49, False)], 'seed': 'emotion_response_level', 'value': 1.5607200000000001, 'agent': 'a1'}
Sample dictionary listing: - rec4: ranges = [(1, 50, False), (0, 1, True)]
-
rec4: seed = emotion_response_level
-
rec4: value = 1.2
-
rec4: agent = a2
-
rec5: ranges = [(1, 50, False), (0, 1, True)]
-
rec5: seed = emotion_response_level
-
rec5: value = 0.7
-
rec5: agent = a3
-
rec6: ranges = [(2, 50, False), (1, 2, True), (0, 1, False)]
-
rec6: seed = emotion_response_level
-
rec6: value = 1.84775
-
rec6: agent = a1
bvdet 2,851
Expert Mod 2GB
Since there may be multiple ranges, maybe this format would be better: - rec0 = {'ranges': [(49, 50, True), (0, 49, False)], 'seed': 'emotion_response_level', 'value': 1.5607200000000001, 'agent': 'a1'}
Sample dictionary listing: - rec4: ranges = [(1, 50, False), (0, 1, True)]
-
rec4: seed = emotion_response_level
-
rec4: value = 1.2
-
rec4: agent = a2
-
rec5: ranges = [(1, 50, False), (0, 1, True)]
-
rec5: seed = emotion_response_level
-
rec5: value = 0.7
-
rec5: agent = a3
-
rec6: ranges = [(2, 50, False), (1, 2, True), (0, 1, False)]
-
rec6: seed = emotion_response_level
-
rec6: value = 1.84775
-
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.
bvdet 2,851
Expert Mod 2GB
I guess ghazanfar solved his problem since he has not been back. For those of you interested, here is the code I came up with: -
fname = r'your_file'
-
-
def atomtraceParse(fn):
-
fileList = [x[x.find(")', ")+4:].replace(', aspect', '').strip() for x in open(fn).readlines()]
-
dd = {}
-
cnt = 0
-
for item in fileList:
-
itemList = item.split('), ')
-
a = itemList[0].split('(')
-
a1 = a[1].split(', ')
-
rangeList = [eval(x.strip('[]()').split('(')[1].replace('unknown', 'False').replace('true', 'True')) for x in itemList[1:]]
-
dd['rec'+str(cnt)]=dict(seed=a[0], agent=a1[0], value=float(a1[1]), ranges=[x for x in rangeList])
-
cnt += 1
-
return dd
-
-
dataDict = atomtraceParse(fname)
-
-
keys = dataDict.keys()
-
keys.sort()
-
for key in keys:
-
for item in dataDict[key]:
-
print '%s: %s = %s' % (key, item, dataDict[key][item])
Sign in to post your reply or Sign up for a free account.
Similar topics
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...
|
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...
|
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...
|
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;
};
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
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...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
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...
|
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,...
|
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...
| |