thdiaman / ASTExtractor

Abstract Syntax Tree Extractor for Java Source Code
Other
42 stars 17 forks source link

Some lines of source code aren't parsed properly #1

Open hangpm opened 6 years ago

hangpm commented 6 years ago

I try to parse a file written in java below. But in the output xml file, all the statements inside findOpinion() and methods defined after findOpinion() are nowhere to be found. Is this issue due to some kinds of constraint or do I miss any configurtions?

package vnu.uet.vietsentiwordnet.apis;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.ServerSocket;

import jvntextpro.JVnTextPro;
import vnu.uet.vietsentiwordnet.objects.ResultObject;
import vnu.uet.vietsentiwordnet.objects.SentenceLevel;
import vnu.uet.vietsentiwordnet.utils.Ultils;

public class OpinionFinder {
    private static OpinionFinder myInst;

    public static OpinionFinder getInstance() {
        if (myInst == null)
            myInst = new OpinionFinder();
        return myInst;
    }

    public SentenceLevel loadModels() {
        SentenceLevel sl = new SentenceLevel();
        Ultils ul = new Ultils();
        JVnTextPro jvn = new JVnTextPro();
        jvn = ul.loadModels();
        try {
            sl.loadSenLevel(jvn);
        } catch (IOException e1) {
            e1.printStackTrace();
        }
        return sl;
    }

    public ResultObject findOpinion(String sentence) {
        SentenceLevel sl = loadModels();

        // do opinion mining at sentenceLevel
        ResultObject res = new ResultObject();
        try {
            res = sl.doSenLevel(sentence);
        } catch (IOException e) {
            e.printStackTrace();
        }

        return res;
    }

    private static void test() {
        SentenceLevel sl = OpinionFinder.getInstance().loadModels();
        // do opinion mining at sentenceLevel
        ResultObject res = new ResultObject();
        while (true) {
            System.out.print("Enter a sentence:");
            BufferedReader br = new BufferedReader(new InputStreamReader(
                    System.in));
            try {
                String body = br.readLine();
                if (body == null)
                    body = "Tôi yêu Hà Nội nhiều lắm";
                System.out.println(body);
                res = sl.doSenLevel(body);
                // get score
                double Score = res.getScore();
                // get sentiment string
                String Sentiment = res.getResultString();
                System.out.println("Score: " + Score + ", Sentiment: "
                        + Sentiment);
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }

    public static void main(String[] args) {
        test();
    }

}
thdiaman commented 6 years ago

Hi, you may have to change the ASTExtractor.properties file, so that the BLOCK is not in the list of elements that are omitted. By doing so, I was able to get a complete AST for the code you posted

hangpm commented 6 years ago

Hi, sorry for my broken English. I might not give enough information in the last comment that I didn't customize any properties at all and I used parseFile(). Also the findOpinion method in the output file is below.

<MethodDeclaration>
         <Modifier>public</Modifier>
         <SimpleType>
            <SimpleName>ResultObject</SimpleName>
         </SimpleType>
         <SimpleName>findOpinion</SimpleName>
         <SingleVariableDeclaration>
            <SimpleType>
               <SimpleName>String</SimpleName>
            </SimpleType>
            <SimpleName>sentence</SimpleName>
         </SingleVariableDeclaration>
         <Block>{
}
</Block>
      </MethodDeclaration>

On the other hand, I switched to parseString() instead of parseFile() right after I open this issue, and it turned out OK. Now I see your comment, but unfortunately changing omitted list is not work for me.