Package nl2sql.matcher

Source Code of nl2sql.matcher.PairWithDB

/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package nl2sql.matcher;

import nl2sql.parserQuestion.LinguisticComponent;
import java.io.File;
import java.util.*;
import nl2sql.lexicon.Database;
import nl2sql.lexicon.GetElement;
import nl2sql.lexicon.Synonym;

/**
*
* @author TAMHD
*/
public class PairWithDB {
   
    ArrayList<String[]> pairs = new ArrayList<String[]>();
    ArrayList<String> right;
   
    public PairWithDB(ArrayList<String> Right){
        this.right = Right;
    };
    // Get all pair of elements, including the missing attribute
    public void matchingElementPair(String parser, Database db, ArrayList<String> Left, ArrayList<String> Right, ArrayList<String> Tag) throws Exception{
        TagProcess tag = new TagProcess();
        for(int i = 0; i < right.size(); i ++){
            String current = right.get(i);
            System.out.println("Trying to match " + current + "...");
           
            // Kiểm tra giá trị đó là value
            if(!db.attribute.contains(current)){
                String attr;
                String valu = current;
                // Xử lý ngữ nghĩa trước
                int tagPos = tag.getTag(Tag.get(i));
                if(tagPos!= -1){
                    attr = tag.getCol(db, tagPos);
                    Synonym sy = new Synonym();
                    ArrayList<String> syn = sy.getSynonym(current);
                    if(!syn.isEmpty()){
                        valu = syn.get(0);
                    } else{
                        valu = current;
                    }
                    System.out.println("Getting attribute " + attr + " through tag processing OF " + current);
                }else{
                    GetAttribute getA = new GetAttribute(parser, db, current, Left, Right);
                    attr = getA.getAttr();
                    System.out.println("Getting attribute " + attr + " through parser OF " + current);
                    valu = current;
                }
                // If it is unable to find the attribute
                if(attr == null) continue;
               
                String[] tmp = {attr, valu};
               
                pairs.add(tmp);
                int Vindex = right.indexOf(current);
               
                // Remove vi tri cua current
                right.remove(Vindex);
                Left.remove(Vindex);
                Tag.remove(Vindex);
                System.out.println("right" + right);
                System.out.println("Right" + Right);       
               
                int Aindex = right.indexOf(attr);
                if(Aindex != -1){
                    Left.remove(Aindex);
                    Tag.remove(Aindex);
                    //Right.remove(Aindex);
                    right.remove(Aindex);
                }           
                i = -1;// Xoa di 2 phần tử rồi mà
            } else{
                System.out.println("Matcher " + current + " fail");
            }
        }
    }
   
    public ArrayList<String[]> getPairs(){
        return this.pairs;
    }
    public ArrayList<String> getRemainers(){
        return this.right;
    }
   

   
   
    public static void main(String[] args) throws Exception {
        Database db = new Database("đại học công nghệ");
        //System.out.println(attach("19", "điểm", db));
        //System.out.println(TokenVn_ann);
    }
   
   
}
TOP

Related Classes of nl2sql.matcher.PairWithDB

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.