

import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.UnsupportedEncodingException;

import jp.ac.osaka_u.sanken.sparql.PlainSparqlAccessor;
import jp.ac.osaka_u.sanken.sparql.SparqlAccessor;

public class Compare {


	public static void main(String[] args){
		String epFile = null;
		String inFile = null;
		String outFile = null;
		int targetType = SparqlAccessor.FIND_TARGET_ALL;
		boolean fullMatch = true;
		
		try {
			for (int i=0; i<args.length; i++){
				if (args[i].startsWith("-") && i < (args.length-1)){
					
					if (args[i].equals("-o")){
						outFile = args[i+1];
					}
					if (args[i].equals("-i")){
						inFile = args[i+1];
					}
					if (args[i].equals("-e")){
						epFile = args[i+1];
					}
					if (args[i].equals("-p")){
						fullMatch = false;
						i--;
					}
					if (args[i].equals("-t")){
						if (args[i+1].equals("a")){
							targetType = PlainSparqlAccessor.FIND_TARGET_ALL;
						}
						if (args[i+1].equals("s")){
							targetType = PlainSparqlAccessor.FIND_TARGET_SUBJECT;
						}
						if (args[i+1].equals("l")){
							targetType = PlainSparqlAccessor.FIND_TARGET_SPECIFIC_OBJECT;
						}
						if (args[i+1].equals("o")){
							targetType = PlainSparqlAccessor.FIND_TARGET_OBJECT;
						}
					}
					i++;
				}
				
			}
			if (epFile == null || inFile == null || outFile == null || targetType == -1){
				System.out.println("usage:java -jar SparqlTestTool.jar Compare -e endpointFile -i inputFile -o outputFile [-t type] [-p]");
				System.out.println();
				System.out.println("\t-e\tendpoint file path");
				System.out.println("\t-i\tword list file path");
				System.out.println("\t-o\tresult output file path");
				System.out.println("\t-t\tsearch type");
				System.out.println("\t\t\ts:subject");
				System.out.println("\t\t\tl:object(label only)");
				System.out.println("\t\t\to:object");
				System.out.println("\t-p\tpart match");
			} else {
				jp.ac.osaka_u.sanken.sparql.plugin.compare.Compare ct = new jp.ac.osaka_u.sanken.sparql.plugin.compare.Compare(new File(inFile), new File(epFile));
				ct.outputResult(targetType, fullMatch, new File(outFile));
			}
		} catch (UnsupportedEncodingException e) {
			e.printStackTrace();
		} catch (FileNotFoundException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}
		
	}
}
