|
From: Sue on 8 Feb 2005 17:42 I have a text file in the following format -- I need to read and parse this file and extract values for minDoseBinIndex and minimumDose. Any pointers on how to do this will be of much help. I spend hours trying to do this and all I have is code below which for some reason does not work, I am not able to capture the values that I need. Can someone PLEASE help? Thank you SO very much! ----------sample data file----------------- voxelVolume: 0.004395 binSize: 0.163389 structureSetUID: doseVolumeUID: œ(A¼t @ëÿ@>*A¼t @ normalizationPointDose= 0.000000; normalizationPoint={ 0.000000 0.000000 0.000000 }; numOfdvhCurves= 16; dvhCurveList={ structure name: motion envelope associatedROIUID: 0 minDoseBinIndex= 61203; minimumDose= 10000.000000; precedence= 10; isTarget= 0; numOfBins= 1; voxelCounts={ 0 } } ----------code extract------------------------ FileReader rd = new FileReader(strFileName); StreamTokenizer st = new StreamTokenizer(rd); // Prepare the tokenizer for Java-style tokenizing rules st.parseNumbers(); //st.wordChars('_', '_'); st.eolIsSignificant(true); // If whitespace is not to be discarded, make this call st.ordinaryChars(0, ' '); // These calls caused comments to be discarded st.slashSlashComments(true); st.slashStarComments(true); // Parse the file int token = st.nextToken(); while (token != StreamTokenizer.TT_EOF) { token = st.nextToken(); switch (token) { case StreamTokenizer.TT_NUMBER: // A number was found; the value is in nval double num = st.nval; System.out.println("num=" + num); // break; case StreamTokenizer.TT_WORD: // A word was found; the value is in sval //if (st.sval.equals("minDoseBinIndex")) { String word = st.sval; System.out.println("word=" + word); // } break; case '"': // A double-quoted string was found; sval contains the contents String dquoteVal = st.sval; // System.out.println("dquoteVal" + dquoteVal); break; case '\'': // A single-quoted string was found; sval contains the contents String squoteVal = st.sval; // System.out.println("squoteVal=" + squoteVal); break; case StreamTokenizer.TT_EOL: // End of line character found break; case StreamTokenizer.TT_EOF: // End of file has been reached break; default: // A regular character was found; the value is the token itself char ch = (char)st.ttype; System.out.println("ch" + ch); break; } } rd.close(); } catch (IOException et) { }
From: dar7yl on 8 Feb 2005 19:34 "Sue" <sea_099(a)hotmail.com> wrote in message news:1107902545.183720.258940(a)g14g2000cwa.googlegroups.com... >> I have a text file in the following format -- I need to read and parse >> this file and extract values for minDoseBinIndex and minimumDose. Any >> pointers on how to do this will be of much help. I spend hours trying >> to do this and all I have is code below which for some reason does not >> work, I am not able to capture the values that I need. Can someone >> PLEASE help? Thank you SO very much! What is the expected output of your program, and what are you actually getting? What is the program doing when it fails. ie, what input line is it reading? Is this your complete program? You might want to create a mini-language, concentrating first on the simplest form of the data you want to extract vis: <data> ::= <property> | <value> <property> ::= <label> ':' <number>|<string> // for instance 'structure name: motion envelope' <value> ::= <label> '=' <number>|<array> ';' // for instance 'minimumDose= 10000.000000;' or 'normalizationPoint={ 0.000000 0.000000 0.000000 };' Then design your parser to extract the appropriate elements, and place them somewhere to be dealt with after the parsing is completed, either on a line-by-line basis, or the complete file. I suspect that your next assignment is to parse the dvhCurveList which would involve a wee bit of recursion. You should structure your solution to anticipate this. regards, Dar7yl
From: gimme_this_gimme_that on 8 Feb 2005 20:25 You can get it in a few lines if you use a regular expression. I'm used to using the jakarta oro package. If you agree to use oro I'll write up a solution.
|
Pages: 1 Prev: Bad class file, wrong version Next: Struts Newbie going crazy! |