Jump to content

Recommended Posts

Posted

except Perl and Tcl, for the love of everything beautiful in computing, leave the old languages alone.

 

I won't argue with that. Perl is a handy thing for an experienced programmer to have in their toolkit. But I shouldn't recommend it to a learner (it has very sharp edges and is dangerously flammable :))

Posted

The perceived need for Perl goes away with Python, and/or Ruby, and/or PHP on your belt. As far as on unix command line, Bash and Sed or Awk also do the job, and you can always pipe things into grep multiple times...

Posted

Shell scripting is a far cry from the OP. My advice is to get familiar with Eclipse first because it has lots of plug ins and a bigger user base so there will be more support should you come into any issues compiling and running your project.

 

Also, as far as your program goes you can get the required result with only a few functions tailored for your needs, one that checks the abbreviation against the list as i demonstrated earlier and returns the new string. One that breaks the sentence down into words and injects the new word/'s while deleting the old one. If your going to expand the program further it might be useful to break these functions down further so that other functions can benefit from smaller functions. So for example in the function to replace the words you might want to have another function that break the sentence into an array of words, a function to find the location in the array to switch and finally a switch function. This will allow your code to be easily maintained and add a higher level of functionality, it also adheres to certain programming principles such as DRY (dont repeat yourself) which basically means your not using the same code twice.

 

Hope this helps.

Posted

The comment was purely a reply on the usefulness of Perl, shell scripting is not the solution to the original question at hand. Also Eclipse is not a language, the perhaps incorrectly stated question at hand was what language to use. I personally find Eclipse too intrusive for everything outside of Java (for either PC or Android), and prefer lighter IDEs like Geany or just good editors with good syntax highlighting and folding like Emacs, Vim and more and more recently, Sublime.

 

As far as functions, if i were doing this in Ruby or Python, I would just extend the String class and write the to_s or toString methods for simplicity of use later on (like automagically applying your method when you output the data in the structure). I would probably split the string, map over the array and use a hash for the lookup purpose. And this isn't much of a parser, would be more like a light version of a lexical analyzer.

 

A very quick-hand, dirty, 2-line version in ruby would look something like:

sub={'btw'=>'by the way', 'b4u'=>'before you', 'cyl'=>'catch you later'}

"Bingo! btw, cyl. b4u go that is".split(' ').map{|word| term=word.downcase.gsub(/[^0-9a-z]/i, ''); (sub[term].nil?) ? word : word.downcase.gsub(term,sub[term])}.join(' ').gsub(/[.!?]\s*./, &:upcase)
Posted

It doesnt matter for the IDE, whatever you are most comfortable with, if none, i suggest you check out sublime (for mostly everything) or eclipse (for java).

 

As far as languages go, any language works, pick one, and go with it, except Perl and Tcl, for the love of everything beautiful in computing, leave the old languages alone. Python, PHP, Ruby, JavaScript (biggest advantage here is that you can run your code entirely in your browser), C++, C#, Java, they all work for the purpose. You can also go to places like Udacity and Coursera, sign up for a course on programming (language-dependent or independent), and start there with learning the basics and applying them to your project...

okey...now i can learn new things..thanks for sharing your knowledge...

 

 

Shell scripting is a far cry from the OP. My advice is to get familiar with Eclipse first because it has lots of plug ins and a bigger user base so there will be more support should you come into any issues compiling and running your project.

 

Also, as far as your program goes you can get the required result with only a few functions tailored for your needs, one that checks the abbreviation against the list as i demonstrated earlier and returns the new string. One that breaks the sentence down into words and injects the new word/'s while deleting the old one. If your going to expand the program further it might be useful to break these functions down further so that other functions can benefit from smaller functions. So for example in the function to replace the words you might want to have another function that break the sentence into an array of words, a function to find the location in the array to switch and finally a switch function. This will allow your code to be easily maintained and add a higher level of functionality, it also adheres to certain programming principles such as DRY (dont repeat yourself) which basically means your not using the same code twice.

 

Hope this helps.

thanks for your reply... its help me a lot...^^

 

 

 

The comment was purely a reply on the usefulness of Perl, shell scripting is not the solution to the original question at hand. Also Eclipse is not a language, the perhaps incorrectly stated question at hand was what language to use. I personally find Eclipse too intrusive for everything outside of Java (for either PC or Android), and prefer lighter IDEs like Geany or just good editors with good syntax highlighting and folding like Emacs, Vim and more and more recently, Sublime.

 

As far as functions, if i were doing this in Ruby or Python, I would just extend the String class and write the to_s or toString methods for simplicity of use later on (like automagically applying your method when you output the data in the structure). I would probably split the string, map over the array and use a hash for the lookup purpose. And this isn't much of a parser, would be more like a light version of a lexical analyzer.

 

A very quick-hand, dirty, 2-line version in ruby would look something like:

sub={'btw'=>'by the way', 'b4u'=>'before you', 'cyl'=>'catch you later'}

"Bingo! btw, cyl. b4u go that is".split(' ').map{|word| term=word.downcase.gsub(/[^0-9a-z]/i, ''); (sub[term].nil?) ? word : word.downcase.gsub(term,sub[term])}.join(' ').gsub(/[.!?]\s*./, &:upcase)

yeah i know about this lexical analyzer...thanks a lot..^^

Posted

That is not an LA, its a simple string replacer, that is a dirty, horrible (in terms of quality of code) way to do what you wanted to do very quickly, as a quick PoC. Took about 3 minutes to write, maybe 5 or so to test.

Posted

That is not an LA, its a simple string replacer, that is a dirty, horrible (in terms of quality of code) way to do what you wanted to do very quickly, as a quick PoC. Took about 3 minutes to write, maybe 5 or so to test.

so LA is a shortcut way to do that re-placer?? hurm...i understand it now...but honestly now i just test it use javahashmap...one word refer to one meaning...

Posted

Lexical analyzer is not a shortcut, it is a part of a typical parser/compiler and it has a different purpose from replacing strings. It's purpose is to read a raw stream (typically code) and split it into identifiable lexemes. The combination of lexeme and its' identity (i.e. class) are combined into a structure typically identified as a token. Tokens are then passed to the parser to to build the parse tree.

 

What i wrote is a simple string replacer. It is not an LA, it is simpler than an LA, and it is quick and dirty. You can do what you want to do with a combination of an LA and a much better context-aware string replacer. But it seemed like too complex of a solution for the fairly simple task at hand.

Posted

sure, why not?

so if i'm combine this java hashmap with the decision tree...whether it will reduce the time to compile this system?? i have an hundred word in the hashmap..so it is proper to combine this code or just only using hashmap??

Posted

if there is only 100 words, you can just build a quick hashmap and let it go at it... Substitution is not the hard part, its the correcting the beggining of the sentence that will be a little bit challenging.

Posted

if there is only 100 words, you can just build a quick hashmap and let it go at it... Substitution is not the hard part, its the correcting the beggining of the sentence that will be a little bit challenging.

ouh okey...now i understand... if the word need to be check the grammar so that part need the right algorithm..

btw, for the database design, if i just use java hashmap.. it is the data become one to one?? because java hashmap only have a key and value in same table.

Posted

ouh okey...now i understand... if the word need to be check the grammar so that part need the right algorithm..

btw, for the database design, if i just use java hashmap.. it is the data become one to one?? because java hashmap only have a key and value in same table.

 

In an sql you could store all the data in a single table and then query the data as required, the hashmap is the database. If it was larger and you required extra functionality from the databse you could query all the data from that table and store it in a hashmap.

Posted

 

In an sql you could store all the data in a single table and then query the data as required, the hashmap is the database. If it was larger and you required extra functionality from the databse you could query all the data from that table and store it in a hashmap.

Could you explain in detail? it vague for me to understand this. or would u just give the link that can i refer to learn it??

Posted

Could you explain in detail? it vague for me to understand this. or would u just give the link that can i refer to learn it??

 

It'd be like:

 

SELECT FullWord FROM AbrreviationTable WHERE Abbreviation = 'OMG';

 

FullWord column correlates to Abbreviation column.

 

ID Abbreviation FullWord

 

1 OMG oh my god

2 CBA can't be arsed

3 CEEBS .....etc

Posted

 

It'd be like:

 

SELECT FullWord FROM AbrreviationTable WHERE Abbreviation = 'OMG';

 

FullWord column correlates to Abbreviation column.

 

ID Abbreviation FullWord

 

1 OMG oh my god

2 CBA can't be arsed

3 CEEBS .....etc

ok..ok....now i got it...many thank's...so that would only need one table for the data...their entity just abbreviation and fullword..

thanks a lot for help..^^

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.