[Logo]
Forums Register Login
Implementing an algorithm using counters
 

the last column isn't necessarily followed by a space.


That is backwards from what I was asking.  Does the last column follow the last space?
 

Liutauras Vilda wrote:If you got data parsed correctly by regex - that is fine! Let’s move on.

Do you understand what guys mentioned (including myself) about creating objects with a given data? That is kind of similar step what you do now, just instead of adding these three (number, action, number) to three separate data structures, you’d create object and would add once in a list or other data structure as WhateverItRepresents objects, by one for each parsed line.



Yes, I understand that.
What I tried is creating getter methods for all the variables in the Subtitle class and then in the class where I parse the file, in the try statement, I initialised them like this: double startTime=subtitle.getStartTime();... and then I have a while loop that saves my needed lines so I initialised the Subtitle object like this subtitle = new Subtitle(0, i, 0); and then:

And so on for all the other variables...
Now the problem is that I get a NullPointerException at line startTime=subtitle.getStartTime();. I know what a NPE is but how I don't know how to fix it in this case? And is that what you meant I should do?
Don’t know, all got confusing.

Please post all the code (use code tags) you have without any comments in the code and without any explanations here. Let the code speak.
 

Liutauras Vilda wrote:Don’t know, all got confusing.

Please post all the code (use code tags) you have without any comments in the code and without any explanations here. Let the code speak.



Sorry, I want to post the code but I just can't post it all publicly. Is it alright if I send it to you by message?
 

Trent Green wrote:. . . . Is it alright if I send it to you by message?

No. Post what you can or change what is secret so the code cannot be recognised.
Trent,

one of the problems and I think the main reason why we are in the third long topic about your problem, is that you seem to be reluctant to supply sufficient information. In this topic questions are being raised that were already raised in the foregoing topics and still are unanswered. For instance, if I ask for some real examples of the lines-to-be-split I don't get them, so that question came up in this topic as well, still unanswered.

We have given examples of how to create instances of the Subtitle class, filled with the corrct values from the input file, yet you seem to hang on to whatever code you had. That is okay, but don't then expect us to be able to correct your unknown code. Also, offering one of the repliers insight in your code is at least a little impolite towards all the others that have been trying to help.

Well, I hope we're close to solving the problem, although I have no idea how far we are.


 

Piet Souris wrote:Trent,

one of the problems and I think the main reason why we are in the third long topic about your problem, is that you seem to be reluctant to supply sufficient information. In this topic questions are being raised that were already raised in the foregoing topics and still are unanswered. For instance, if I ask for some real examples of the lines-to-be-split I don't get them, so that question came up in this topic as well, still unanswered.

We have given examples of how to create instances of the Subtitle class, filled with the corrct values from the input file, yet you seem to hang on to whatever code you had. That is okay, but don't then expect us to be able to correct your unknown code. Also, offering one of the repliers insight in your code is at least a little impolite towards all the others that have been trying to help.

Well, I hope we're close to solving the problem, although I have no idea how far we are.



Yes, I know that is part of the problem, but it's just not possible. And I'm sorry, you're right that it was a bit impolite, but I didn't mean to direct an 'offer' to show my code towards anyone specific, it just happened to be the last person that asked to see my code.

I'm posting some snippets. Hopefully that helps a bit.



 

Trent Green wrote:



Sorry, it should read subtitle rather than plan.
That code should not compile.  subtitle is defined 2 times: line 2 and line 4

Please fix compiler errors before posting your code.
 

Norm Radder wrote:That code should not compile.  subtitle is defined 2 times: line 2 and line 4


I fixed this. Line 4 is now String subtitleName... But my question is why do I have a NullPointerEx at line 3? And also is my way of filling the variables with the values correct?
Trent, I'm certain that we (=you) won't solve this exercise that way. As you see everything goes in chaotic manner.

We need to change approach. One of which is being honest with each other.

If that is final year project and you don't want to share, fine, just let us know that. If that is final mark assignment, that is fine too - just let us know, so we'll know how to act and we won't ask unnecessary questions because we all been there.

It is clear to me that you copy/paste code from various websites, assembling code from different sources - that way projects are almost all meant to fail. But that is not most important part. What would you learn from that? Very likely nothing.

If that is for commercial project you are working on, best such cases would be to discuss with your team leader, so you could inform her/him, that things get uncontrolled and you need help from more experienced people.

Put the cards face up and then we can see how we best can help you and how you can help us best to help you.
 

why do I have a NullPointerEx at line 3?


Because some variable has a null value.  If you can not tell which one, add a print statement to print the values of the variables on line 3 so you can see.
When you have found the variable, back track in the code to see why it does not have a valid value.
 

Liutauras Vilda wrote:Trent, I'm certain that we (=you) won't solve this exercise that way. As you see everything goes in chaotic manner.

We need to change approach. One of which is being honest with each other.

If that is final year project and you don't want to share, fine, just let us know that. If that is final mark assignment, that is fine too - just let us know, so we'll know how to act and we won't ask unnecessary questions because we all been there.

It is clear to me that you copy/paste code from various websites, assembling code from different sources - that way projects are almost all meant to fail. But that is not most important part. What would you learn from that? Very likely nothing.

If that is for commercial project you are working on, best such cases would be to discuss with your team leader, so you could inform her/him, that things get uncontrolled and you need help from more experienced people.

Put the cards face up and then we can see how we best can help you and how you can help us best to help you.


Yes, it is for an assignment and I guess now you understand why I was reluctant to share any code and that's why the code I posted was chaotic, because I was trying to change parts so it doesn't get flagged.
Alright. If that is not some kind of final year project which you need to come up with yourself, you probably have definite requirements/instructions you need to follow.

For example, if to use regex was/is part of the instructions, please do tell us in such cases, so nobody would question anymore the approach you chose. Other than that, you need to be prepared to hear other suggestions/offers over and over what people think would be better to use in this situation.

Now, what Piet mentioned about the data lines you need to parse, instead of showing exact lines if you think you can't show them, you can specify the requirement in the form similar to:

data line can follow one of these forms:
a) floating point number followed by [1] colon, then [2] space, then [3] the content within the parentheses of any length, [4] followed by space, [5] followed by floating point number
b) floating point number followed by [1] semi-colon, [2], [3], [4], and [5] same as in above example
c) ...

So, that is considered as being able to express the requirements in clear manner without showing actual given data which might be let's say confidential or similar...

Get an idea.

So what we are missing here, is exactly that. We don't have clear picture of what you need to do. But again, Piet said there are another 2 or 3 threads of the same kind, maybe you could collect them and post URL's here so people could have a look and we could might even merge them if they re-assemble whole picture.

What's regarding direct help why NPE is thrown and questions how to fix this I don't think would lead you any further towards completing this project. Maybe is better to start over? So you could describe some little part of requirements and you could do with some hints from us in case you get stuck. After all, assignments are meant to be done by the assignee. I used to do all of my assignments on my own without asking absolutely any help of anybody else, but some students not learning across the semester and then when the assignment comes happens what happens, desperately looking for help, trying to research internet and assemble code from various sources. I'm not saying it happened to you, but if you recognise some of the parts which holds, try to change such approach and you'll get better over time with your studies.

I don't know how to proceed further. Another thread? Maybe not. Don't know, what others think?
Trent, how you'd assess yourself the current state of your project, how much you think you accomplished in percentages?

I'm leaning towards that, that maybe it is really not a bad idea to start over for you, so you could create completely fresh project in your environment, also you could create fresh thread so you could start tackling parts in less chaotic way so that we know now it is an assignment.

Hm, what do you think?
 

Liutauras Vilda wrote:Trent, how you'd assess yourself the current state of your project, how much you think you accomplished in percentages?

I'm leaning towards that, that maybe it is really not a bad idea to start over for you, so you could create completely fresh project in your environment, also you could create fresh thread so you could start tackling parts in less chaotic way so that we know now it is an assignment.

Hm, what do you think?


I don't think it's worth it to start a new thread and for me to start over, because I feel like if I write the requirements one more time, I'll go crazy. But maybe I can start from the point where it doesn't make sense for you guys, because finally for me I think it kind of makes sense - the part with creating an object that stores each parsed line etc. Although I'm still unsure if my way of filling the variables with the parsed date is correct or whether I'm in the right direction.
Also, I want to note that I don't really have clear requirements for this project so that definitely makes it harder.
 

Trent Green wrote:But maybe I can start from the point where it doesn't make sense for you guys, because finally for me I think it kind of makes sense - the part with creating an object that stores each parsed line etc.


We have been speaking about this for quite a while, but I didn't see you achieved that. Seems you say you understand/understood and then again showed your old way of doing this. So I'm unsure you understand actually.

Please show the where you:
1. Parse the line
2. Create an instance of object with parsed line's separate parts

Nothing else.
 

Trent Green wrote:Although I'm still unsure if my way of filling the variables with the parsed date is correct or whether I'm in the right direction.


If you parse data line and you can extract its individual pieces (3 of them as far as I understood) from all given variations of lines - then you in the right direction. In order to be sure, you need to have either automated test to verify that or to have simple print statements so you could go manually through those an verify.

Trent Green wrote:Also, I want to note that I don't really have clear requirements for this project so that definitely makes it harder.


Yes, that can be hard to get somewhere, when you don't know where you need to.
 

Liutauras Vilda wrote:

Trent Green wrote:But maybe I can start from the point where it doesn't make sense for you guys, because finally for me I think it kind of makes sense - the part with creating an object that stores each parsed line etc.


We have been speaking about this for quite a while, but I didn't see you achieved that. Seems you say you understand/understood and then again showed your old way of doing this. So I'm unsure you understand actually.

Please show the where you:
1. Parse the line
2. Create an instance of object with parsed line's separate parts

Nothing else.



Well, I parse a line like this:

  while ((string = stdout.readLine()) != null) {
     savedSubs.add(string);
  }
And then follows my for loop I showed a few posts ago.
But as I said, I understood how I would parse the line if I have to use split, but since I am using regex, the only way I can think of is to just assign my variable that holds the captured part of the regex inside the variable from the Subtitle class like this: startTime = time;
  
 

  I parse a line like this:


The posted code does not parse the String read from the file.  It looks like it saves the String in a list.
When I use the term parse, I mean the process where an input record (often a String) is scanned and its separate parts extracted so they can be used for something.
Saving the input record is not parsing it.

After the parts have been extracted from the input record, they can be used to create an instance of a class to save them.  Perhaps in a constructor:
Then savedP can be saved in a list for later processing.
(1 like)
"To parse" means something like "to assign meaning to symbols". A string is just a bunch of symbols without meaning. When you parse a string, you interpret parts of the string and create an object that encapsulates the interpreted meaning.

In the previous topic you posted, I posted a Subtitle class that encapsulates the meaning of a line of your input. you should add a static Subtitle parse(String) method to it that converts a line of input to an instance of Subtitle. Show us your implementation of that method, nothing more, nothing less. Then we can continue with the next step.
 

Stephan van Hulst wrote:"To parse" means something like "to assign meaning to symbols". A string is just a bunch of symbols without meaning. When you parse a string, you interpret parts of the string and create an object that encapsulates the interpreted meaning.

In the previous topic you posted, I posted a Subtitle class that encapsulates the meaning of a line of your input. You should add a static Subtitle parse(String) method to it that converts a line of input to an instance of Subtitle. Show us your implementation of that method, nothing more, nothing less. Then we can continue with the next step.


My bad. I am still struggling writing that and I know I've said that many times in this topic, but I just feel like I'm struggling so much because of the regexes. Basically, if my file was a csv or the delimiter between columns was the same, I could just easily use split or indexOf. But since it is not, how would I split the string consistently into an array, where using indexes I would extract the first column, second column, third column? That has been my question all along.
And also I don't think in my case it'll be suitable to have that method in the Subtitle class because I'm not reading and processing my file there, but in a different class and that is where I was thinking of doing the parsing
Well, the format of the line-to-split is still unknown to us, so if your regex is working, stick to the regexes! The only important thing is that the three constituing fields are retrieved in a way that you understand and feel comfortable with.

Now, having these three constituents, you can either create a Subtitle instance, several examples have been given. Or what Stephan means: let the Subtitle class itself split such a line (parsing) and have it send back an instance of itself. Both ways are equivalent, maybe one may considered to be a bit more  'OO'. For instance:
 

Trent Green wrote:And also I don't think in my case it'll be suitable to have that method in the Subtitle class because I'm not reading and processing my file there, but in a different class


While you don’t think, still put some trust on more experienced colleagues who told it is the approach you should try (at least). I think it is invaluable to listen to these advices and try to absorb them.

Indeed, file reading is done outside Subtitle class. What you do is you pass already read line from the file to the method of Subtitle class which just have been showed.

For the last time, please show at least 3 different data line examples.

Okay, I think I'm pretty close to the goal, but now I included some print statements and apparently I am getting the initial values so 0.0s and nulls. Could that be because I initialised the variables inside the try statement before reading the file to 0.0, null, 0.0 so they never change, but I did that because it doesn't let me just declare them when I create a new subtitle instance inside the try statement like this And then in the for loop I showed before I do this:
Again, I'm really sorry that I'm not able to post all the code, as this is not the best way of explaining what I've done.
 

how would I split the string consistently into an array,


You need to describe what Strings delimit each of the three fields.
Can there be spaces before the first field?
Can there be spaces after the last field?

 

Norm Radder wrote:
You need to describe what Strings delimit each of the three fields.
Can there be spaces before the first field?
Can there be spaces after the last field?


No spaces before the first column; : after the first column, space after : ; text inside brackets; space; number in third column might be inside []

But as I've already said that is not the problem, I'm still not sure why all of you guys are so against using my regexes if I've tested them and they work!
Also, please can somebody give their opinion on my previous post?
The last test  regex code you posted did not work for me.  Have you updated the code?
Could you post some code that defines a sample record and the regexs to parse it.
The test code could print out the values of the three fields that are parsed from the record.

If the regex work for you, work on creating a class to hold the parsed data.
 

Trent Green wrote:(...)
But as I've already said that is not the problem, I'm still not sure why all of you guys are so against using my regexes if I've tested them and they work!
Also, please can somebody give their opinion on my previous post?


Now I feel offended!          In my direct reply I advised to stick to these regexes!
All Liutauras and I did was telling how and where to apply the three parts of the input lines, either directly create a Subtitle instance, there where you process the input lines, or via the parse-method of the Subtitle class. What more should we tell?
 

Norm Radder wrote:If the regex work for you, work on creating a class to hold the parsed data.



Yes, i am working on that. I already created my Subtitle class, but as I said in my previous post - I am having troubles with getting any data inside an object instance. I declare my local variables inside try{ like this

And then use the parse method:


But when I print a subtitle I get this:
Subtitle start time 0.0, text null, duration 0.0
 

Piet Souris wrote:[
Now I feel offended!          In my direct reply I advised to stick to these regexes!
All Liutauras and I did was telling how and where to apply the three parts of the input lines, either directly create a Subtitle instance, there where you process the input lines, or via the parse-method of the Subtitle class. What more should we tell?


Haha no, don't be! I was just speaking generally. And I do appreciate your help, really, and I know it's frustrating for both myself and you guys but I just keep encountering more problems - refer to my last post.
 

having troubles with getting any data inside an object instance


Can't say why without seeing the code.
Many code examples have already been posted.

The steps would be:
Parse data into 3 variables
use those 3 variables to create an instance of the class
add that instance to a list
Allright.

Well, this part is oke:

But what you next must do:

1) split the line you just read into the three parts, say start2, text2, duration2, using your regexes
2) then put these values into your just created subtitle instance: subtitle.setStart(start2); subtitle.setText(text2) et cetera
3) add subtitle to your list
 

Piet Souris wrote:.
But what you next must do:

1) split the line you just read into the three parts, say start2, text2, duration2, using your regexes
2) then put these values into your just created subtitle instance: subtitle.setStart(start2); subtitle.setText(text2) et cetera
3) add subtitle to your list


Hmm, but since I'm now I chose to implement the parse method, I'm using the regexes in my Subtitle class
And so on for the other 2.
And then using the parse method as in the code I provided. Wouldn't that work?
Alright, it seems we have another barrier.

Regexes are for pattern matching. But let's put away this fancy terms. In simple words it let's you extract individual pieces from the text line.
Using indexOf and substring methods would be just another way to achieve the same.

Now you decided to go with regexes - absolutely fine!

Parsing is just a terminology of process when you give a meaning to an extracted text. So you parse either using regexes or let's say indexOf and substring methods routine.

You don't say: I do regexes, now I'll parse text... It doesn't make sense. If you used regexes and extracted needed parts from the data line - you already parsed it.

Now what you need to do is to create an instance of the Subtitle class.

I'll use strings for example:
String start = regex.giveMeFirstThing();
String middle = regex.giveMeWhatIsInBetweenParentheses();
String end = regex.giveMeLastThing();

So you done with your regexes, you extracted 3 things you were interested in from the line within the file.

What's next? You create an instance of Subtitle with these 3 things.

Subtitle subtitle = new Subtitle(start, middle, end);
bunchOfSubtitles.add(subtitle);

And you repeat your regex magic, creating subtitle and adding it to the collection of bunch of subtitles per every line you have in a file. Loop probably needed here.
Of course that will work, but what troubles me is that from the code you supplied I'm afraid there is something wrong with the order in which you let things happen.

Trent Green wrote:

Norm Radder wrote:If the regex work for you, work on creating a class to hold the parsed data.



Yes, i am working on that. I already created my Subtitle class, but as I said in my previous post - I am having troubles with getting any data inside an object instance. I declare my local variables inside try{ like this

And then use the parse method:


But when I print a subtitle I get this:
Subtitle start time 0.0, text null, duration 0.0


Look at hte first part:

You are creating subtitle as an instance of Subtitle, as I said in my previous reply, that is oke. But on the next line, you create an ArrayList that is supposed to hold all these Subtitle instances! Normally, this list should be there before creating any sublist at all.
Next:

What is 'saveSubs'? I assume it is the list of inputlines-to-be-split, but the code we supplied was meant to send each inputline directly to the parse-method of the Subtitle class. And next: the parse method is a static method of the Subtitle class. What you are now doing is invoke the parse method via the subtitle instance. Although that should also work, it requires that you have this instance in the first place.

You see, your code should work in principle, but it is presented in snippets and so it is hard for us to judge if the order of things are correct. Now, we know you don't want to publish your full code, for good reasons, but it means that you yourself must look very carefull if your code indeed does what it should do. So, to sum up:

1) read an inputline
2) if that line is after the line containing 'Duration'(see topic 1) send that line to the parse method of the Subtitle class, using your working regexes there to get the reuired fields
3) save the returned Subtitle instance to you Subtitle-list
4) and, what has not yet come up, use your list to get the subtitles to show up in time!
 

Liutauras Vilda wrote:
Now what you need to do is to create an instance of the Subtitle class.

I'll use strings for example:
String start = regex.giveMeFirstThing();
String middle = regex.giveMeWhatIsInBetweenParentheses();
String end = regex.giveMeLastThing();


I find this bit a little confusing. How would those 3 methods look like? Because I have the parsing in one method, as I said, in parse(String) in the Subtitle class. Is that not okay? And do you mean this code would go where I read and process the file? Also what is regex in this case?
Why does the code you've posted for parsing have a while loop to get the first field?

Could you post some code that defines a sample record and the regexes to parse it.
The test code should print out the values of the three fields that are parsed from the record.
For the record:

the other topics were
https://coderanch.com/t/690835/java/String-split#3242850
and
https://coderanch.com/t/691001/java/Java-Timer-counters#3243865
These were just dummy ideas to visualise concept.

It can be confusing, and probably it is, but that is because we talk about the things we don't see. I'm talking about the things what's in my head only, you are talking about the things which are in your head only, and we don't share any indirectly tangible asset (code).

So yeah, you are talking about the shoes, I'm about the barrels That's the joke, to give visual imagination how difficult sometimes can be to discuss about the things on forums.


Trent, buddy, we are not going to get anywhere with this. Your concern is Turnitin, that's understandable, but then you need to work out yourself somehow.

If I were you, and would know that I need to catch up with my course material, I'd just share my code, I'd do my best to take advices in order to finish project, UNDERSTAND IT, and wouldn't worry about the submission - that's because you have a backlog of understanding (reasons are known for you probably).

Point is to LEARN and UNDERSTAND. Not to get the MARK. Mark is the result of the mentioned first two. If you look for a job, much more important is UNDERSTAND. So is your call what you want to achieve here.
Wink, wink, nudge, nudge, say no more ... https://richsoil.com/cards


This thread has been viewed 1378 times.

All times above are in ranch (not your local) time.
The current ranch time is
Jun 24, 2018 03:06:50.