Over a million developers have joined DZone.

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

DZone 's Guide to

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

· Big Data Zone ·
Free Resource

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 = @"http://gosmarter.net/gosmarter/searchwall.do?query=";
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

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}