Text Message Analysis program

Ask questions about projects relating to: computer science or pure mathematics (such as probability, statistics, geometry, etc...).

Moderators: MelissaB, kgudger, Ray Trent, Moderators

Text Message Analysis program

Postby PerpetuallyConfused » Sat Nov 24, 2012 8:19 pm

My goal is to write a java program that can tell me who sent a text message based on the words/abbreviations that are unique to them. I am almost completely new to programming, so I have no clue on how to do this. I thought about using an If-statement, but I've realized that only works for numerical input. Does anyone know which direction I should go in? All suggestions are welcome :)
PerpetuallyConfused
 
Posts: 2
Joined: Sat Nov 24, 2012 6:04 pm
Occupation: Student:10th grde
Project Question: Java Programming: Text Message Analysis
Project Due Date: 1/15/13
Project Status: I am conducting my research

Re: Text Message Analysis program

Postby dcnick96 » Sun Nov 25, 2012 11:41 pm

Hello, and welcome to Science Buddies!

I assume you have a list of words/abbreviations that define each person and you will be using your program to search for these pre-defined strings? If so, you can use a switch statement in java. This replaces multiple if...then statements. While most examples of the switch statement uses integers, it is possible to use strings. There are multiple examples on the web of the correct syntax.

I hope this helps. Be sure to write back if you have any other questions. Good luck!
Deana
dcnick96
Moderator
 
Posts: 249
Joined: Wed Jul 25, 2007 7:59 pm

Re: Text Message Analysis program

Postby vysarge » Mon Nov 26, 2012 4:31 pm

Hello PerpetuallyConfused!

Dcnick96 gives good advice; a switch statement in Java can definitely help to cut down on code length and complexity. If you separate a String, or text message, into words, that should be much quicker and easier.

I wanted to clear up a bit of a misunderstanding that you seem to have, though- in Java (as well as a few other programming languages such as C++, I believe), it is in fact possible to use string input in an if-statement. If-then statements always contain a boolean value- simply put, a true or false. This allows a bit more flexibility than a switch-case statement, as you can actually ask a String, such as the text message, a few valuable things, such as if it contains another String.

For finding out what functions you can use with each class, like a String, [[the Javadoc]] is probably the most useful resource that I've come across. To the left, you can see a bar containing every class in Java 7, including String; clicking on this link will give you a list of all of the functions. If you're using Java 6 or an earlier version, just Google 'javadoc 6' (or javadoc 5 or similar) and it should be the first link.

[[This function]] in particular should be useful for the function you described.

Hope this helped, and good luck!
-Vysarge

~~~~~~~~~~~~~
Nature uses only the longest threads to weave her patterns, so that each small piece of her fabric reveals the organization of the entire tapestry.
-Richard Feynman
vysarge
Expert
 
Posts: 64
Joined: Tue Sep 27, 2011 4:56 pm
Occupation: Student: 12th grade
Project Question: Student volunteer.
Project Due Date: N/a: see above.
Project Status: Not applicable

Re: Text Message Analysis program

Postby hhemken » Tue Nov 27, 2012 5:39 pm

PerpetuallyConfused,

Most programming languages have a bit of magic called Regular Expressions. Google this:

Code: Select all
java regular expressions


This will allow you to define generic text patterns and quickly see if they are in a string or not. You can even use them to delicately extract substrings with great accuracy and sensitivity. Don't worry if at first you feel clueless. Write a few simple programs on some contrived input data and you'll soon see what's going on.

Trust me, it is pure magic!

Heinz Hemken
Heinz Hemken
Mentor
Science Buddies Expert Forum
hhemken
Expert
 
Posts: 260
Joined: Mon Oct 03, 2005 3:16 pm

Re: Text Message Analysis program

Postby PerpetuallyConfused » Wed Nov 28, 2012 5:15 pm

Thank you all so much! I think I'll play with all three methods before I decide which one to use.
PerpetuallyConfused
 
Posts: 2
Joined: Sat Nov 24, 2012 6:04 pm
Occupation: Student:10th grde
Project Question: Java Programming: Text Message Analysis
Project Due Date: 1/15/13
Project Status: I am conducting my research

Re: Text Message Analysis program

Postby Ray Trent » Mon Dec 03, 2012 11:12 pm

If you want an extra strong challenge, you might look into the idea of creating a Bayesian classifier. This is the kind of algorithm often used to create spam filters for email programs, and they work by training the algorithm on a set of data and applying Bayes' theorem to determine the conditional probability of the text being spam based on things that the user has marked as spam previously.

There's a good starting place here, though it does get a bit technical... there are other sources on the web that you could search for if you find this technique interesting: http://en.wikipedia.org/wiki/Naive_Bayes_classifier
../ray\..
Ray Trent
Expert
 
Posts: 208
Joined: Wed Aug 24, 2005 3:07 pm


Return to Grades 9-12: Math and Computer Science

Who is online

Users browsing this forum: No registered users and 2 guests