/*
 * Fact.java 
 * Nadeem Abdul Hamid - Fall 2004 - CSC120 - Berry College
 *
 * Representation of a fact in the manor database program
 *
 * Based on a program developed in "Great Ideas in Computer Science 
 * with Java" by Biermann and Ramm.
 *
 */


import java.io.*;

public class Fact {

    String nounA;
    String relation;
    String nounB;

    public Fact(BufferedReader in) throws IOException {
        nounA = in.readLine();
        if (nounA.equals("")) throw new IOException("Empty fact line");
        relation = in.readLine();
        nounB = in.readLine();
    }

    public String toString() {
        return nounA + " " + relation + " " + nounB;
    }


    public void printToFile(PrintWriter outFile) {
        outFile.println("*");
        outFile.println(nounA);	
        outFile.println(relation);	
        outFile.println(nounB);	
    }

    /*
     * Compare facts, using wild cards (?) 
     */
    public boolean compare(Fact query) {
        if ( (query.nounA.equals("?") ||
              query.nounA.equalsIgnoreCase(nounA))
             && (query.relation.equals("?") ||
                     query.relation.equalsIgnoreCase(relation))
             && (query.nounB.equals("?") ||
             query.nounB.equalsIgnoreCase(nounB)) )
            return true;
        return false;
    }

}
