Garmaine Staff asked 2 years ago
public static int classify(int Newlength, int count7, int count8, int count2, int count6, int count3, int count1,
        int count4, int count5, boolean Backslash, boolean if_https, boolean if_http, boolean ifIP, int count10,
        int count11, int count12)// ,boolean Backslash,boolean if_https, boolean if_http,boolean ifIP
{

    // Create attributes to be used with classifiers
    // Test the model

    int result = 0;
    try {

        ArrayList<Attribute> attributeList = new ArrayList<Attribute>();

        Attribute length = new Attribute("length");
        Attribute hashtag = new Attribute("#");
        Attribute percentage = new Attribute("%");
        Attribute at = new Attribute("@");
        Attribute qustionmark = new Attribute("?");
        Attribute and = new Attribute("&");
        Attribute singdoller = new Attribute("$");
        Attribute dot = new Attribute(".");
        Attribute colon = new Attribute(":");// its mean :
        Attribute doublebackshalsh = new Attribute("//");
        Attribute https = new Attribute("https");
        Attribute http = new Attribute("http");
        Attribute ip = new Attribute("Ip");
        Attribute Greek = new Attribute("Greek");
        Attribute Cyrillic = new Attribute(" Cyrillic");
        Attribute latin = new Attribute("Glatin");

        ArrayList<String> classVal = new ArrayList<String>();
        classVal.add("YES");
        classVal.add("NO");

        attributeList.add(length);
        attributeList.add(hashtag);
        attributeList.add(percentage);
        attributeList.add(at);
        attributeList.add(qustionmark);
        attributeList.add(and);
        attributeList.add(singdoller);
        attributeList.add(dot);
        attributeList.add(colon);
        attributeList.add(doublebackshalsh);
        attributeList.add(https);
        attributeList.add(http);
        attributeList.add(ip);
        attributeList.add(Greek);
        attributeList.add(Cyrillic);
        attributeList.add(latin);

        attributeList.add(new Attribute("@@Target@", classVal));

        Instances data = new Instances("TestInstances", attributeList, 0);
        System.out.println(data);
        Instance inst_co;

        data.setClassIndex(data.numAttributes() - 1);
        inst_co = new DenseInstance(data.numAttributes());
        data.add(inst_co);

        String bs = Boolean.toString(Backslash);// for backslash
        String hs = Boolean.toString(if_https);// for https
        String hp = Boolean.toString(if_http);// for http
        String ips = Boolean.toString(ifIP);// for ip

        inst_co.setValue(length, Newlength);
        inst_co.setValue(hashtag, count7);
        inst_co.setValue(percentage, count8);
        inst_co.setValue(at, count2);
        inst_co.setValue(qustionmark, count6);
        inst_co.setValue(and, count3);
        inst_co.setValue(singdoller, count1);
        inst_co.setValue(dot, count4);
        inst_co.setValue(colon, count5);
        inst_co.setValue(doublebackshalsh, 2);
        inst_co.setValue(https, 3);
        inst_co.setValue(http, 5);
        inst_co.setValue(ip, 3);

        inst_co.setValue(Greek, count10);
        inst_co.setValue(Cyrillic, count11);
        inst_co.setValue(latin, count12);
        inst_co.setDataset(data);
        System.out.println("The instance: " + inst_co);
        // inst_co.setDataset(race);

        // load classifier from file
        Classifier cls_co = (Classifier) weka.core.SerializationHelper
                .read("src/user_withexcel3/NaivBayesmodel.model");

        result = (int) cls_co.classifyInstance(inst_co);

        System.out.println(result);
    } catch (Exception e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    return result;
}