Big Data/Analytics Zone is brought to you in partnership with:

Enterprise Architect in HCL Technologies a $7Billion IT services organization. My role is to work as a Technology Partner for large enterprise customers providing them low cost opensource solutions around Java, Spring and vFabric stack. I am also working on various projects involving, Cloud base solution, Mobile application and Business Analytics around Spring and vFabric space. Over 23 yrs, I have build repository of technologies and tools I liked and used extensively in my day to day work. In this blog, I am putting all these best practices and tools so that it will help the people who visit my website. Krishna is a DZone MVB and is not an employee of DZone and has posted 64 posts at DZone. You can read more from them at their website. View Full User Profile

This Sample iPad App Works with a JSON-Based Machine Learning System

  • submit to reddit

GoSmarter is a JSon based Machine Learning System that, if given a Natural Language (NLP) Query, will return a list of recommended products. This Machine Learning also uses social networking capabilities to recommend products based on your friends.

In this sample, I have written a iPad based application, which is a 2 tabbed application, in the first tab, it will return all the popular items among GoSmarter user base. In the tab 2, we can pass any query and it will return list of products that are current from Amazon, eBay and other sources. Some of the iOS Programming capabilities it demonstrate are:

As a starter in Xcode it is easy to create a Tabbed Application with Default Storyboard with 2 Tabs. While creating the project, you just have to tell Xcode this application is better configured for iPad.

Refer this youtube Searchbar samples by iffytheperfect1983, In our sample, we got the query from the Searchbar and passed to GoSmarter JSon RESTful API Code is as below,

-(void)loadData: (NSString *)searchString {
NSString *baseUrlString = @"";
NSString* escapedUrlString = [searchString stringByAddingPercentEscapesUsingEncoding:NSASCIIStringEncoding];
NSString *urlString = [baseUrlString stringByAppendingString:escapedUrlString];
NSURL *url = [NSURL URLWithString:urlString];
NSURLRequest * request = [NSURLRequest requestWithURL:url];
connection = [NSURLConnection connectionWithRequest:request delegate:self];

webData = [[NSMutableData alloc]init];
[self.myTableView resignFirstResponder];

-(void)searchBarSearchButtonClicked:(UISearchBar *)searchBar{
NSString *searchQuery = searchBar.text;
[self loadData:searchQuery];

There is a good youtube demo for sharing data between 2 applications by iffytheperfect1983, there is also a good blog Storyboards Segue Tutorial: Pass Data Between View Controllers. These 2 show how to share data between 2 View Controllers. In our sample, the usecase is, when user selects a popular item, it should pass this query to the 2nd Tab View Controller and it should automatically return all the results in that query. UI is as below,

Storyboard Segue UI for sharing data between View Controller

Storyboard Segue UI for sharing data between View Controller

//First View Controller:
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
SecondViewController *viewController = segue.destinationViewController;
NSIndexPath *indexPath = [self.myTableView indexPathForSelectedRow];
viewController.onLoad = YES;
viewController.searchString = [nameArray objectAtIndex:indexPath.row];

//Second View Controller</pre>
- (void)viewDidLoad
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
[self loadData:searchString];

There is a youtube video on creating Custom Table View Cell. We created a Custom TableView cell and associated with 2 Label one for Name and another for Price as below,

Custom UITableViewCell

Custom UITableViewCell

The code for Custom Cell,

@interface CustomTableViewCell : UITableViewCell
@property (weak, nonatomic) IBOutlet UILabel *label1;
@property (weak, nonatomic) IBOutlet UILabel *label2;

To conclude in this sample, we demonstrated some of the fundamental capabilities of iOS Programming. 

You can also tryout NLP queries in this Machine Learning system as we have defined Product Ontology,

  • iPod below $25
  • Mario < $25
  • Mario > $25
  • Mario less than $25
  • iPad greater than $250
  • Car near 01702
  • Toys for boys, Toys for girls
  • Mobile phones for old people
  • “42″ LED
  • Low cost Smartphones
  • Cheap Phones
  • New LED
  • Samsung: will return Samsung Smartphone, because in Product Ontology, brand identification for Samsung is Smartphone

Published at DZone with permission of Krishna Prasad, author and DZone MVB. (source)

(Note: Opinions expressed in this article and its replies are the opinions of their respective authors and not those of DZone, Inc.)