Package seekfeel.fileparsers

Source Code of seekfeel.fileparsers.Reviews_Parser

package seekfeel.fileparsers;

import seekfeel.dataholders.Product_Feature;
import seekfeel.dataholders.Review;
import seekfeel.fileparsers.FileParser;

/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
//package reviews_parser;
/**
*
* @author Ashraf
*
* This is the class that extracts the Review from the Text
*/
public class Reviews_Parser extends FileParser {

    public static String Title = "";

    public Review Parse_Review_Data(String Sentence) {

        Review Parsed_Review = new Review();


        if (Sentence.contains("[u]") || Sentence.contains("[U]")) {
            Parsed_Review.Without_Feature = true;
            Sentence = Sentence.replace("[u]", "");
            Sentence = Sentence.replace("[U]", "");
        }
        if (Sentence.contains("[p]") || Sentence.contains("[P]")) {
            Parsed_Review.Without_Pronoun_resolution = true;
            Sentence = Sentence.replace("[p]", "");
            Sentence = Sentence.replace("[P]", "");
        }
        if (Sentence.contains("[s]") || Sentence.contains("[S]")) {
            Parsed_Review.Has_Suggetions = true;
            Sentence = Sentence.replace("[s]", "");
            Sentence = Sentence.replace("[S]", "");
        }
        if (Sentence.contains("[CC]") || Sentence.contains("[cc]")) {
            Parsed_Review.Has_Comparison_With_Different_Brand = true;
            Sentence = Sentence.replace("[CC]", "");
            Sentence = Sentence.replace("[cc]", "");
        }
        if (Sentence.contains("[CS]") || Sentence.contains("[cs]")) {
            Parsed_Review.Has_Comparison_With_Same_Brand = true;
            Sentence = Sentence.replace("[cs]", "");
            Sentence = Sentence.replace("[CS]", "");
        }

        String[] Parts = Sentence.split("##");
        if (Parts.length > 0) {
            if (Parts[0].length() < 1) {
                System.out.println(" Features: " + "None");
            } else {
                String[] Features = Parts[0].split(",");
                for (String Feature : Features) {

                    Parsed_Review.Features.add(Get_Feature(Feature));
                }
            }
        }
        if (Parts.length > 1) {
            Parsed_Review.setDataBody(Parts[1]);
        }
        System.out.println(Sentence);

        Parsed_Review.Review_Title = Title;

        return Parsed_Review;
    }

    public void Parse_Review_Title(String Sentence) {
        Sentence = Sentence.replace("[t]", "");
        Title = Sentence;
    }

    Product_Feature Get_Feature(String Feature_Text) {
        Product_Feature Feature = new Product_Feature();
        if (Feature_Text.contains("[+3]")) {
            Feature.Rank = 3;
            Feature_Text = Feature_Text.replace("[+3]", "");
        }
        if (Feature_Text.contains("[+2]")) {
            Feature.Rank = 2;
            Feature_Text = Feature_Text.replace("[+2]", "");
        }
        if (Feature_Text.contains("[+1]")) {
            Feature.Rank = 1;
            Feature_Text = Feature_Text.replace("[+1]", "");
        }
        if (Feature_Text.contains("[-1]")) {
            Feature.Rank = -1;
            Feature_Text = Feature_Text.replace("[-1]", "");
        }
        if (Feature_Text.contains("[-2]")) {
            Feature.Rank = -2;
            Feature_Text = Feature_Text.replace("[-2]", "");
        }
        if (Feature_Text.contains("[-3]")) {
            Feature.Rank = -3;
            Feature_Text = Feature_Text.replace("[-3]", "");
        }

        Feature.Name = Feature_Text;
        return Feature;
    }
}
TOP

Related Classes of seekfeel.fileparsers.Reviews_Parser

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.