Analyze the flat file data in a nested structure.
This has been driving me crazy all day long.
I have a flat data file I want to analyze in a nested data structure.
Small sample data:
0 HEAD 1 SOUR FTW 2 VERS Family Tree Maker (16.0.350) 2 NAME Family Tree Maker for Windows 2 CORP MyFamily.com, Inc. 3 ADDR 360 W 4800 N 4 CONT Provo, UT 84604 3 PHON (801) 705-7000 0 TRLR
If anyone recognizes this, yes it's a small piece of a GEDCOM file. That's what I'm trying to analyze. For someone who is not familiar with this data format. The first number is the level of a data element. Level 0 are elements of the root of a data segment. Level 1 lines relate to the data of level 0 line previous closest. Level 2 lines relate to the level 1 data line that precedes the closest. And so on.
Here is an example of the desired output, the different elements to the related parent of nesting.
<cfset foobar = { HEAD = {lvl=0, SOUR = {lvl=1,data="FTW", VERS = {lvl=2,data="Family Tree Maker (16.0.350)"}, NAME = {lvl=2,data="Family Tree Maker for Windows"}, CORP = {lvl=2,data="MyFamily.com, Inc.", ADDR = {lvl=3,data="360 W 4800 N", CONT = {lvl=4,data="Provo, UT 84604"}}, PHON = {lvl=3,data="(801) 705-7000"}}}}, TRLR = {lvl=0} }> <cfdump var="#foobar#">
I think I'm looking at a kind of recursive function to embed these data correctly, but I just can't figure out how to do.
I have this basic function that will display each line of data in a separate structure key
<cffunction name="parseFile"> <cfargument name="file" required="yes"> <cfargument name="line" required="no" type="string" default=""> <cfscript> var returnStruct = structNew(); var subStruct = structNew(); var cur_line = ""; var next_line = ""; var line_lvl = ""; var line_key = ""; var loop = true; if (len(trim(arguments.line)) EQ 0) { cur_line = fileReadLine(arguments.file); } else { cur_line = arguments.line; } do { if (not FileISEOF(arguments.file)) { next_line = fileReadLine(arguments.file); } else { next_line = "-1"; loop = false; } line_lvl = listFirst(cur_line, ' '); cur_line = listRest(cur_line, ' '); line_key = listFirst(cur_line, ' '); cur_line = listRest(cur_line, ' '); returnStruct[line_key] = structNew(); returnStruct[line_key]["level"] = line_lvl; cur_line = next_line; } while (loop); return returnStruct; </cfscript> </cffunction> <cfscript> gedcom_file = FileOpen(getDirectoryFromPath(getCurrentTemplatePath()) & "Ian Skinner.GED","read"); /*gedcom_data = {individuals = structNew(), families = structNew(), sources = structNew(), notes = structNew()};*/ gedcom_data = parseFile(gedcom_file); </cfscript> <cfdump var="#gedcom_data#" label="Final Output">
I tried many ways to recursively call this function in order to nest the elements. None of them have produced await in the above example of hand coded output. Which made me the closest is recursive call, the function parseFile() towards the end of the while loop if the following line is greater than the current level of line:
if (listFirst(next_line,' ') GT line_lvl) { parseFile(arguments.file,next_line); }
It works pretty well, as long as the next level of line is the same as or higher than its previous level of the line. But once the next line level is lower, the recursive call will not return to the appropriate parent level. The current function call ends just on a loop on the data file. Everything that I tried to provide a correct output for recursive function calls when the next data line belongs to a line parent just a horribly distorted data.
Yes, that's exactly it. I think that the node must always be added to the stack.
I just had a period gave me. But that's what I thought.
That is to say...
While (not FileISEOF (gedcom_file)) {}
line = fileReadLine (gedcom_file);
extract data from the node
node = {};
node.LVL = listFirst (line, "");
line = listRest (line, "");
key = listFirst (line, "");
If (listLen (line, "") gt 1) {}
node. Data = listRest (line, "");
}
Download the most recent ancestor of the battery
lastNode = stack [1];
If it is a brother/ancestor, look for its parent
While (arrayLen (stack) & node.lvl lte lastNode.lvl) {}
arrayDeleteAt (battery, 1);
lastNode = stack [1];
}
Add to the stack
arrayPrepend (stack, node);
Add this node from its parent
lastNode [key] = node;
}
Tags: ColdFusion
Similar Questions
-
Create the flat file data from the oracle table
d_adp_num char (10)
d_schd_date tank (8)
d_sched_code tank (25)
d_pay_code char (50)
d_mil_start char (4)
d_mil_end char (4)
d_duration char (5)
d_site_code char (4)
d_dept_id tank (6)
Select payroll_id,
schedule_date,
reason_code, (sched_code)
reason_code, (pay_code)
start_time,
end_time,
total_hours,
site_code,
department_id
of dept_staff
where schedule_date between (sysdate + 1) and (sysdate + 90)
loading data for the date range instead.
sched_code - if 'Unavailable' reason_code = 'OD' and 'THE '.
pay_code - "Berevevement BD" If reason_code = "BD".
"UP PTO without reasonable excuse" If reason_code = 'UP '.
"RG" If reason_code = "SH".
"PTO" If reason_code = "GO".
Here are some...
start_time and end_time - convert military time
based on start_ampm and end_ampm
On this basis, I need help to create a flat file. Sewing of the flat and data file in dept_staff sample
If site_code is there so no need to get department_id (see the sample flat file)
------------------------------------
examples of data to flat file
ZZW002324006072012 PTO
0800160008.00
ZZW002428106072012 RG
1015174507.50HM34
ZZW002391606072012 RG
1100193008.50
ZZW002430406072012 RG
1100193008.50 130000
----------------------------
dept_staff table data
REASON_CODE_1 PAYROLL_ID SCHEDULE_DATE REASON_CODE START_TIME, END_TIME START_AMPM END_AMPM TOTAL_HOURS SITE_CODE DEPARTMENT_ID
ZZW0024468 08/06/2012 HS HS 730 HAS 400 850 12 P
ZZW0000199 08/06/2012 HS HS 730 HAS 400 850 14 P
ZZW0023551 08/06/2012 SH SH 1145 A 930 975 GH08 95 P
ZZW0024460 08/06/2012 SH SH 515 HAS 330 P 1025 GH08 95
ZZW0023787 08/06/2012 SH SH 630 HAS 300 850 24 P
ZZW0024595 08/06/2012 TR TR 730 HAS 400 850 90 P
ZZW0023516 08/06/2012 OD OD 800 HAS 400 800 95 P
ZZW0023784 08/06/2012 OD OD 800 HAS 400 800 5 P
ZZW0024445 08/06/2012 SH SH 1145 A GH08 930 975 5 P
ZZW0024525 08/06/2012 OD OD 800 HAS 400 800 23 P
ZZW0024592 08/06/2012 TR TR 730 HAS 400 850 5 P
ZZW0024509 08/06/2012 SH SH 95 MK21 830 HAS 330 P 700
ZZW0023916 06/14/2012 SH SH 1100 A 850 27 730 PHow to ask questions
SQL and PL/SQL FAQUTL_FILE allows to write the OS file
-
Where to download the flat file for POC adapter
Hi all
We are currently looking at GoldenGate as a mechanism to capture changes to tables specified in an Oracle database and produce text files containing these changes in near real-time. Everything I read pointing adapter flat file for GoldenGate as a way to get there.
I am now at the point where I want to start a little POC see prove if it will work for our needs. I downloaded GG for databases Oracle 12.1.2.1.0 RTO, as well as customer GG monitor and Director of GG. My question is now - where can I download the flat file adapter? It includes the GG for the download of Oracle?
If I missed something in the documentation somewhere - I'm happy to be told where to read them.
Kind regards
John
I'll answer my own question here...
(1) delivery seems to be the only place to get it
(2) 12 GoldenGate can capture a trail and send it to a configuration of GoldenGate 11 running FF adapter.
-
Export a table for the flat file and must insert sysdate in flat file column
Hi, I created an interface allowing to export an oracle table to a csv file. All the columns in the table work well. Then I need to insert the sysdate in a column in the csv file.
I made the map as working in the transit area, implementation is to_char(sysdate,'dd/mm/yyyy'). But the result is insert in column 14.
I tried to create a variable refreshing that choose double to_char(sysdate,'dd/mm/yyyy'), maps then as the csv file column, but he only insert 1 row and the format is YYYYMMDD.
I tried to use SELECT '< % = odiRef.getSysDate ("YYYYMMDD") % >' double to the variable and it also only insert a line in the flat file.
I used the same methodology in ODI10g, it works fine.
So, I wonder how it can be implemented in 11g.
Thank you
It turns out that I used the snapshot_date as a field name, it may be a reserved word. After that I changed the name of the field, it works fine. Thank you.
-
KM for the flat file to flat file
Hello
Including KM to use for the flat file to flat file extraction.
Thank you.Hello
Use LKM FILE SQL and SQL IKM FILE APPENDIX
Make sure that the file exists and your waiting area is facing a pattern of RDBMS
Thank you
Fati -
Remove users from UDF attribute of unique values present in the flat file
Hello
I'm trying to remove users from the IOM by using a single value of one of the present of the UDF in the flat file for example say SSN. I preferred the approach to go through a scheduled task to remove users from IOM. I know that the permanent deletion of IOM through the database is not possible. To have written a custom code to do the same thing and I have used the tcuseroperationintf.deleteuser(long...) method. But I had a straight and simple query for the same thing. Should what value I contact in the long appropriate field in the list of the attributes of this method?
Any guidance on this task would be appreciate.
Thanks in advance,
-oidm.You want to the Users.Key or the USR_KEY and give it in the format of variable length.
-Kevin
-
How to view the flat file to ADF Flow task data
Hello
I have some data in a flat file.
Now, I want to show the data in a table in the workflow of adf.
Please help me to know how to achieve this functionality.Hello
Have a look here: http://dstas.blogspot.de/2012/11/csv-files-with-adf-csvparser-example.html?m=1
Once the file is loaded in a query of the VO, the workflow can construct the table by dragging the VO
Frank
-
Could not load the flat file (csv) through FDMEE
Hi Experts,
I am trying to load data from flat file to HFM via FDMEE, it throws the below error
2014-06-06 16:35:13, 465 INFO [AIF]: beginning of the process FDMEE, process ID: 1 341
2014-06-06 16:35:13, 465 [AIF] INFO: recording of the FDMEE level: 4
2014-06-06 16:35:13, 465 [AIF] INFO: FDMEE log file: d:\orcl\FDMEE\outbox\logs\CONSOL_1341.log
2014-06-06 16:35:13, 465 [AIF] INFO: User: hyp_admin
2014-06-06 16:35:13, 465 [AIF] INFO: location: HFM UXC (Partitionkey:59)
2014-06-06 16:35:13, 465 [AIF] INFO: period name: Apr-14 (period key: 1/04/14 12:00 AM)
2014-06-06 16:35:13, 465 INFO [AIF]: name of the category: real (main category: 4)
2014-06-06 16:35:13, 465 [AIF] INFO: name rule: HFM UXC D300 (rule ID:69)
2014-06-06 16:35:15, 785 [AIF] INFO: Jython Version: 2.5.1 (Release_2_5_1:6813, September 26 2009, 13:47:54)
[JRockit (R) Oracle (Oracle Corporation)]
2014-06-06 16:35:15, 785 [AIF] INFO: Java platform: java1.6.0_37
2014-06-06 16:35:15, 785 [AIF] INFO: log the file encoding: UTF-8
2014-06-06 16:35:19, 132 [AIF] INFO: - START IMPORT STEP -
2014-06-06 16:35:25, 188 [AIF] INFO: file name: UXC_D300_Apr - 14.csv
2014-06-06 16:35:25, 360 FATAL [AIF]: error in Comm.doScriptInit
Traceback (most recent call changed):
File '< string >", line 347 in doScriptInit
Exception: java.lang.Exception: NO details found for Loadid:13412014-06-06 16:35:25, 655 FATAL [AIF]: load balances data launch GL error
2014-06-06 16:35:25, 671 INFO [AIF]: end process FDMEE, process ID: 1341The pointers will be greatly appreciated.
Thank you very much
Jeff
This error is usually related to if you do not properly apply patch ODI.
Can you take a look at the opatch inventory, rollback FDMEE and ODI patch and then apply again.
Make sure that these patches are applied successfully without any errors.
Thank you
~ KKT ~. -
Ignoring the fields in the flat file
I have a table with column empid and dat_of_birth. I get a flat file with fields location | empname | EmpID. salary | dat_of_birth
How can I load only empid and dat_of_birth?
In addition, how can even be done using external table?Hoek wrote:
Load the entire file and select only the columns you need?No need. Simply use FILL even as in SQL * Loader. For example:
Data file:
New York|King|123|10000|04.21.1967 Boston|Smith|456|5000|07.11.1976
External table:
CREATE TABLE test_tbl( empid number, dat_of_birth date ) ORGANIZATION EXTERNAL( TYPE ORACLE_LOADER DEFAULT DIRECTORY tmp ACCESS PARAMETERS ( FIELDS TERMINATED BY '|' ( filler, filler, empid, filler, dat_of_birth date 'mm.dd.yyyy' ) ) LOCATION ('test_tbl.txt') ) / Table created. SQL> select * from test_tbl 2 / EMPID DAT_OF_BI ---------- --------- 123 21-APR-67 456 11-JUL-76 SQL>
SY.
-
How to determine the size of the binary file data set
Hi all
I write specific sets of data in table in a binary file, by adding each time so the file grows a set of data for each write operation. I use the set file position function to make sure that I'm at the end of the file each time.
When I read the file, I want to read only the last 25 data sets (or numbers). To do this, I thought using the position set file to set the file position where it was 25 sets of data from the end. Math easy, right? Apparently not.
Well, as I was collecting data file size as I began the initial tet run, I find the size of the file (using file order size and get number of bytes so) as the size increases the same amount every time. My size and the format of my data being written is the same every time, a series of four numbers double precision.
I get increments are as follows, after the first write - 44 bytes, after 2nd - 52 bytes, 3 - 52 bytes, bytes 44 4th, 5th - 52 bytes, 6 - 52 bytes, 7th - 44 bytes and it seems to continue this trend in the future.
Why each write operation would be identical in size of bytes. This means that my basic math for the determination of the poistion of correct file to read only the last 25 sets of data won't be easy, and if somewhere along the line after I've accumulated hundreds or thousands of data sets, what happens if the model changes.
Any help on why this occurs or on a working method, all about the problem would be much appreciated.
Thank you
Doug
-
So, like many others, I was punished by Bill Gates and co.. With a BSOD.
Just need help analyzing dump files to determine which driver I should change, updated or what not.
The dump files are located in...
https://onedrive.live.com/redir?RESID=3D2BA1E313ACF8DA! 2592 & authkey =! AH4PFrNFacnAfvw & ithint = the file % 2crar
BTW, still stuck in windows 7 hehe
Thank you
Had to go to the dentist - ZigZag3143 is reliable using BSOD.
Your Atheros is an AR5007G Wireless Network Adapter.
Visit this link:
https://www.Atheros-drivers.com/
Find AR5007G, click:
Scroll down until you find AR5007G for Windows 7 64 bit and you want to:
-
The MTS file date display information on screen time in CC PP
I need to display the timestamp from date of the MTS files so I can see them in PP CC15. Is it possible to get rid of it within the program? Now, I have to do it in another program and then import the file. Takes too much time this way.
Premiere Pro does not have this feature. The closest you can get is display the timecode for clips that have it. If these clips were recorded using Free Run, that would give you a time, but there is no way to see the date displayed in an overlay.
-
Of size zero image blob in the flat file DB
Hello friends,
I am just new on ODI 11 G.
Try to load images of flat filesystem from unix to Table DB using ODI 11 G.
The image loaded by '0' File size - IE empty. I don't understand.
Here the log files, control files and exit the generated file.
CTL file:
" )
Appreciate your quick response.
Thank you/kumar
Published by: kumar73 on July 3, 2012 07:13Check the code you have. Your chemin_image is a FILLER. Thus, the LOBFILE charge NULL in the DB.
-
How to extract the flat file schema
Hello
I want to extract the contour of the ASO cube. cube is in version 7 essbase.
What can be the methods to extract the schema with data.
Thank you
ruser8738287 wrote:
Should I run the installer of contour with the oracle Installer?No, you must install the Essbase client installs it with the Oracle... Outline Extractor has the Essbase Client on the machine to run.
I get this error runtime error 53 file not found: esbapin. DLL
Esbapin.dll is the VB API installed as part of the Essbase Client dll.
Tim Tow
Applied OLAP, Inc. -
Hello
My Source is access DB and target is flat file.
The IKM I use is IKM SQL to add files.
When I try to run the Interface, I get this error: -.
3100: 37000: java.sql.SQLException: error [Microsoft] [ODBC Microsoft Access driver] syntax (missing operator) in query expression ' CUSTOMER. [CustomerID] CUSTOMERID "."
java.sql.SQLException: error [Microsoft] [ODBC Microsoft Access driver] syntax (missing operator) in query expression ' CUSTOMER. [CustomerID] CUSTOMERID "."
at sun.jdbc.odbc.JdbcOdbc.createSQLException (unknown Source)
at sun.jdbc.odbc.JdbcOdbc.standardError (unknown Source)
at sun.jdbc.odbc.JdbcOdbc.SQLPrepare (unknown Source)
at sun.jdbc.odbc.JdbcOdbcConnection.prepareStatement (unknown Source)
at sun.jdbc.odbc.JdbcOdbcConnection.prepareStatement (unknown Source)
at com.sunopsis.sql.SnpsQuery.a (SnpsQuery.java)
at com.sunopsis.sql.SnpsQuery.a (SnpsQuery.java)
at com.sunopsis.sql.SnpsQuery.updateExecStatement (SnpsQuery.java)
at com.sunopsis.sql.SnpsQuery.executeQuery (SnpsQuery.java)
at com.sunopsis.dwg.dbobj.SnpSessTaskSql.execCollOrders (SnpSessTaskSql.java)
at com.sunopsis.dwg.dbobj.SnpSessTaskSql.treatTaskTrt (SnpSessTaskSql.java)
at com.sunopsis.dwg.dbobj.SnpSessTaskSqlI.treatTaskTrt (SnpSessTaskSqlI.java)
at com.sunopsis.dwg.dbobj.SnpSessTaskSql.treatTask (SnpSessTaskSql.java)
at com.sunopsis.dwg.dbobj.SnpSessStep.treatSessStep (SnpSessStep.java)
at com.sunopsis.dwg.dbobj.SnpSession.treatSession (SnpSession.java)
at com.sunopsis.dwg.cmd.DwgCommandSession.treatCommand (DwgCommandSession.java)
at com.sunopsis.dwg.cmd.DwgCommandBase.execute (DwgCommandBase.java)
at com.sunopsis.dwg.cmd.e.i (e.java)
at com.sunopsis.dwg.cmd.g.y (g.java)
at com.sunopsis.dwg.cmd.e.run (e.java)
at java.lang.Thread.run (unknown Source)
Would appreciate the help.
ChanduwarHi Chandwar,
As we discussed in Gtalk,
the problem is the quotes in the select query.Select
CUSTOMER. "" ' Town.
CUSTOMER. "' Region '.
'Customer' as a CUSTOMER
where (1 = 1)Please customize step KM
<%=snpRef.getColList("", "[EXPRESSION] [ALIAS_SEP] [CX_COL_NAME]", ",\n\t", "", "INS and !TRG") %>
to remove the quotes and the expression of the Alias
Please reffer to the PDF API user to customize the same.An additional point->
Please try to use the appropriate kms which is dedicated for each technology,
This will improve the performance and this kind of questions.Kind regards
Its
Maybe you are looking for
-
I get error C00D10D1 in Media Player 11 to play a .wav file.
original title: I am getting error C00D10D1 in Media Player 11, running XP Home. try to play a .wav file. Suggestions? Thank you! I get this error message, "an audio codec is needed to play this file. To determine if this codec is available to downlo
-
HP Deskjet 2050 J510a series, when I open my HP printer software (click on the desktop icon) I no longer get the options to align the cartridges, etc. All I get is a page of configuration with 3 options for: see Whats Printing, use preferences and Cu
-
How to find the position of errors about?
When an exception occurs apper Android can find their mistakes about searching in the journal. What could we do?
-
Can't change the wallpaper on windows 7 ultimate x 64
The problem is that I can't change my wallpaper (I have in the past). I can't change it via the Customize menu (I choose other wallpapers, but the new wallpaper is not displayed). I also tried to change my custom theme default theme and still does n
-
Restarting the management agents
I need to restart the management agents on ESXi infrastructure vSphere 5.5 5.5 Server member.The procedure I am considering is described on page restart on an ESXi or ESX host management agents (1003490) | VMware KB .I can safely send suggested order