Thursday, 8 October 2015

Program to classify data using weka tool


package weka.api;

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.FileReader;
import java.io.FileWriter;
import weka.classifiers.trees.J48;
import weka.core.Instances;

public class Classify{
public static void main(String[] args) throws Exception
{
    BufferedReader breader = null;
   
    breader = new BufferedReader(new FileReader("/home/sonali/11.arff"));

    Instances train = new Instances(breader);
    train.setClassIndex(train.numAttributes() -1);
    breader = new BufferedReader(new FileReader("/home/sonali/22.arff"));
    Instances test = new Instances(breader);
   
    test.setClassIndex(train.numAttributes() -1);
    breader.close();
   
     J48 tree = new J48();
   
    tree.buildClassifier(train);
       
    Instances labeled = new Instances(test);
     
   
    for(int i=0;i< test.numInstances();i++)
    {
        double clsLabel = tree.classifyInstance(test.instance(i));
        labeled.instance(i).setClassValue(clsLabel);
       
     }
    BufferedWriter bwriter =  new BufferedWriter(
            new FileWriter("/home/sonali/labeled1.arff"));
    bwriter.write(labeled.toString());
    bwriter.close();
  }
}


Steps to run the program - 




   
   

Wednesday, 7 October 2015

Program for Recursive Descent Parser

#include<iostream>
#include<string.h>
#include<ctype.h>
#include<stdio.h>

using namespace std;


class recursive
{
public:
char in[20];
int j,error;
void E();
void F();

};

main()
{ recursive obj;
  obj.j=0;
  obj.error=0;
  cout<<"Enter an arithmetic expression   :  ";
                cin>>obj.in;
  obj.E();

if(obj.in[obj.j]=='$' && obj.in[obj.j+1]=='\0')
       cout<<"\n String Accepted. . !!\n";
 else
       cout<<"\n String Rejected. . !!\n";
}

void recursive::E()
{
  if(isalpha(in[j]))
 {  j++;
    F();
 }
}


void recursive::F()
{ if(in[j]=='+' && in[j+1]!='$')
 { j++;
   if(isalpha(in[j]))
   {
     j++;
     F();
   }
 }

}


Explaination :-

Grammar - E -> iF
                  F -> +iF /


 i is any alphabet from a to z.
Accepted Strings - i+i$ , i+i+i$ , . .etc
Rejected Strings - i++, (i), ++i . . etc

In recursive descent parser, for every variable, we are gonna write a function. In function E(), if first symbol is alphabet then increment pointer to next location and call F().
       In function F(), if first symbol is +(plus) then increment pointer to next location and if next symbol is again alphabet then increment pointer and call F().
    



















Embedded Operating System Notes - Unit 1

1. Real Time Tasks : i) It is a task in which performance is judged on the basis of time. It means computation is correct only if it has...