All Downloads are FREE. Search and download functionalities are using the official Maven repository.

tptp_parser.TptpParserOutput Maven / Gradle / Ivy

Go to download

Sigma knowledge engineering system is an system for developing, viewing and debugging theories in first order logic. It works with Knowledge Interchange Format (KIF) and is optimized for the Suggested Upper Merged Ontology (SUMO) www.ontologyportal.org.

There is a newer version: 2.10
Show newest version

package tptp_parser;


/**
 *  Abstract syntax for TPTP. Most of the features declared here
 *  are used by the TPTP parser to communicate the results of parsing. 
 *  The user of the parser is supposed to provide implementations 
 *  of the interfaces declared here (for many users the default implementation
 *  in SimpleTptpParserOutput.java may be good enough).
 *
 *  Such approach is taken to nicely isolate the grammar sources from 
 *  the environment. It makes the parser highly alienable. A new user 
 *  only has to provide an implementation of these interfaces in order to link
 *  the parser to his/her code. No matter how the data returned from 
 *  the parser is processed, no modification of the parser code is 
 *  required. The requirements imposed by the interface are quite
 *  liberal, so that writing modules glueing the parser with practically
 *  any application is easy.
 *
 *  @author Alexandre Riazanov
 *  @since Feb 02, 2006
 *  @since Nov 13, 2007 ("package tptp_parser;" added by AR)
 */

public interface TptpParserOutput {

    /** Must be implemented by a class representing instances of 
     *  <TPTP input> in the BNF grammar (except comments), ie top level input 
     *  items, such as annotated formulas and include directives.
     */
    public static interface TptpInput {
      
      enum Kind {
          ThfFormula, 
          Formula, 
          Clause,
          Include
      };

    } // interface TptpInput
    
    /** Must be implemented by a class representing formula structures
     *  corresponding to instances of <thf formula> in the BNF grammar.
     */
    public static interface ThfFormula {
      // nothing here
    }; // static interface ThfFormula

    /** Must be implemented by a class representing formula structures
     *  corresponding to instances of <fof formula> in the BNF grammar.
     */
    public static interface FofFormula {
      // nothing here
    }; // static interface FofFormula

    /** Must be implemented by a class representing clause structures
     *  corresponding to instances of <cnf formula> in the BNF grammar.
     */
    public static interface CnfFormula {
      // nothing here
    }; // static interface CnfFormula

    /** Must be implemented by a class representing structures
     *  corresponding to instances of <thf atom> in the BNF grammar.
     */
    public static interface ThfAtomicFormula {
      // nothing here
    }; // static interface ThfAtomicFormula

    /** Must be implemented by a class representing structures
     *  corresponding to instances of <atomic formula> in the BNF grammar.
     */
    public static interface AtomicFormula {
      // nothing here
    }; // static interface AtomicFormula

    /** Must be implemented by a class representing structures
     *  corresponding to instances of <literal> in the BNF grammar.
     */
    public static interface Literal {
      // nothing here
    }; // static interface Literal

    
    /** Must be implemented by a class representing
     *      <term> in the BNF grammar.
     */
    public static interface Term {
      // nothing here
    }; // static interface Term
    


    /** Reprsents all unary connectives, both associative (&,|) and nonassociative
     *  (admissible instances of <binary connective>).
     */
    public static enum UnaryConnective {

      Negation,  // ~
      UnaryPi,   // !!
      UnarySigma;  // ??
      
      public String toString() {
          switch (this) 
          {
            case Negation: return new String("~");
            case UnaryPi: return new String("!!");
            case UnarySigma: return new String("??");
          };
          assert false;
          return null;
      } // toString()

    }; // enum UnaryConnective

    /** Reprsents all binary connectives, both associative (&,|) and nonassociative
     *  (admissible instances of <binary connective>).
     */
    public static enum BinaryConnective {

      And,
      Or,
      
      Equivalence, /* <=> */
      Implication, /* => */
      ReverseImplication, /* <= */
      Disequivalence, /* <~> */
      NotOr, /* ~| */
      NotAnd, /* ~& */

//----For THF
      Apply, // @
      Map,   // >
      Assign,   // :=
      TupleComma,   // ,
      Equal, // =
      NotEqual,  // !=
      Type,  // :
      XProd, // *
      Union, // +
      Subtype, // <<
      Sequent, // -->
      None;  // For controlling printing

      public String toString() {
          switch (this) 
          {
            case And: return new String("&");
            case Or: return new String("|");
            case Equivalence: return new String("<=>");
            case Implication: return new String("=>");
            case ReverseImplication: return new String("<=");
            case Disequivalence: return new String("<~>");
            case NotOr: return new String("~|");
            case NotAnd: return new String("~&");      
            case Apply: return new String("@");
            case Map: return new String(">");
            case Assign: return new String(":=");
            case TupleComma: return new String(",");
            case Equal: return new String("=");
            case NotEqual: return new String("!=");
            case Type: return new String(":");
            case XProd: return new String("*");
            case Union: return new String("+");
            case Subtype: return new String("<<");
            case Sequent: return new String("-->");
            case None: return new String(" SHOULD NEVER SEE THIS");
          };
          assert false;
          return null;
      } // toString()

    }; // enum BinaryConnective


    /** Reprsents all quantifiers. */
    public static enum Quantifier {
      
      ForAll, /* ! */
      Exists,  /* ? */
      Lambda,  // ^
      QuantifierPi,  // ^
      QuantifierSigma,  // ^
      Assign,   // :=
      Choice,   // @+
      Description; // @-
      
      public String toString() {
          switch (this) {
            case ForAll: return new String("!");
            case Exists: return new String("?");
            case Lambda: return new String("^");
            case QuantifierPi: return new String("!>");
            case QuantifierSigma: return new String("?*");
            case Assign: return new String(":=");
            case Choice: return new String("@+");
            case Description: return new String("@-");
          }
          assert false;
          return null;
      }

    }; // enum Quantifier

    
    

    /** Reprsents all admissible instances of <formula role>
     *  (see the BNF grammar).
     */
    public static enum FormulaRole {
      
      Axiom, 
      Hypothesis,
      Definition, 
      Type,
      Assumption, 
      Lemma,
      Theorem,
      Conjecture,
      NegatedConjecture,
      Question,
      Plain,
      Answer,
      FiDomain,
      FiFunctors,
      FiPredicates,
      Unknown;

      public String toString() {
          switch (this) {
            case Axiom: return "axiom";
            case Hypothesis: return "hypothesis";
            case Definition: return "definition"; 
            case Type: return "type"; 
            case Assumption: return "assumption"; 
            case Lemma: return "lemma";
            case Theorem: return "theorem";
            case Conjecture: return "conjecture";
            case NegatedConjecture: return "negated_conjecture";
            case Question: return "question";
            case Plain: return "plain";
            case Answer: return "answer";
            case FiDomain: return "fi_domain";
            case FiFunctors: return "fi_functors";
            case FiPredicates: return "fi_predicates";
            case Unknown: return "unknown";
          };
          assert false;
          return null;
      }

    }; // enum FormulaRole

    /** Must be implemented by a class representing annotations,
     *      ie instances of <annotations> in the BNF grammar.
     */
    public static interface Annotations {
      // nothing here
    }; // static interface Annotations


    /** Must be implemented by a class representing instances of <source> 
     *  in the BNF grammar.
     */
    public static interface Source {
      // nothing here
    }; // static interface Source

    /** Must be implemented by a class representing instances of <info item> 
     *  in the BNF grammar.
     */
    public static interface InfoItem {
      // nothing here
    }; // static interface InfoItem



    /** Reprsents all admissible instances of <intro type>
     *  (see the BNF grammar).
     */
    public static enum IntroType {
      
      Definition,
      AxiomOfChoice,
      Tautology,
      Assumption;
      
      public String toString() {
          switch (this) 
          {
            case Definition:    return new String("definition");
            case AxiomOfChoice: return new String("axiom_of_choice");
            case Tautology:     return new String("tautology");
            case Assumption:    return new String("assumption");
          };
          assert false;
          return null;
      } // toString()
    }; // enum IntroType

    /** Reprsents all admissible instances of <status value>
     *  (see the BNF grammar).
     */
    public static enum StatusValue {
      
      Thm, Sat, Csa, Uns, Cth, Esa, Unknown;
      
      public String toString() {
          switch (this) 
          {
            case Thm: return new String("thm");
            case Sat: return new String("sat");
            case Csa: return new String("csa");
            case Uns: return new String("uns");
            case Cth: return new String("cth");
            case Esa: return new String("esa");
            case Unknown: return new String("unknown");
          };
          assert false;
          return null;
      } // toString()

    }; // enum StatusValue



    /** Must be implemented by a class representing
     *      <general term> in the BNF grammar.
     */
    public static interface GeneralTerm {
      // nothing here
    }; // static interface GeneralTerm
      
    
    /** Must be implemented by a class representing
     *      <parent info> in the BNF grammar.
     */
    public static interface ParentInfo {
      // nothing here
    }; // static interface ParentInfo

    

    /*==================================================================
     *                      Top level items.                           *
     *=================================================================*/


    /** A correct implementation must return a TptpInput object representing
     *   formula  wrapped in the corresponding annotation.
     *  @param name != null
     *  @param role != null 
     *  @param formula != null
     *  @param annotations can be null
     *  @param lineNumber location in the input
     */
    public 
    TptpInput
    createThfAnnotated(String name,
                   FormulaRole role,
                   ThfFormula formula,
                   Annotations annotations,
                   int lineNumber);

    
    /** A correct implementation must return a TptpInput object representing
     *   formula  wrapped in the corresponding annotation.
     *  @param name != null
     *  @param role != null 
     *  @param formula != null
     *  @param annotations can be null
     *  @param lineNumber location in the input
     */
    public 
    TptpInput
    createFofAnnotated(String name,
                   FormulaRole role,
                   FofFormula formula,
                   Annotations annotations,
                   int lineNumber);

    
    /** A correct implementation must return a TptpInput object representing
     *   clause  wrapped in the corresponding annotation.
     *  @param name != null
     *  @param role != null 
     *  @param clause != null
     *  @param annotations can be null
     *  @param lineNumber location in the input
     */
    public 
    TptpInput
    createCnfAnnotated(String name,
                   FormulaRole role,
                   CnfFormula clause,
                   Annotations annotations,
                   int lineNumber);


    /** A correct implementation must return a TptpInput object representing
     *  the instance of <include> with the specified parameters.
     *  @param fileName != null
     *  @param formulaSelection satisfies
     *         (formulaSelection == null || formulaSelection.iterator().hasNext())
     *  @param lineNumber location in the input
     */
    public 
    TptpInput
    createIncludeDirective(String fileName,
                     Iterable formulaSelection,
                     int lineNumber);




    /*==================================================================
     *          Formulas, clauses, literals and terms.                 *
     *=================================================================*/

    /** A correct implementation must return an object representing
     *  the binary formula obtained by applying  connective 
     *  to  lhs  and  rhs .
     *  Note that the method must work with conjunction and disjunction,
     *  as well as with nonassociative connectives.
     *  @param lhs != null
     *  @param connective != null 
     *  @param rhs != null
     */
    public 
    ThfFormula 
    createThfBinaryFormula(ThfFormula lhs,
                  BinaryConnective connective,
                  ThfFormula rhs);

    /** A correct implementation must return an object representing
     *  the formula obtained by applying the negation connective
     *  to  formula .
     *  @param formula != null
     */
    public 
    ThfFormula
    createThfUnaryOf(TptpParserOutput.UnaryConnective unary,
TptpParserOutput.ThfFormula formula);
    /** A correct implementation must return an object representing
     *  the formula obtained by applying the quantifier
     *   quantifier  to  formula .
     *  @param quantifier != null
     *  @param variableList != null && variableList.iterator().hasNext()
     *  @param formula != null
     */
    public 
    ThfFormula
    createThfQuantifiedFormula(Quantifier quantifier,
                      Iterable variableList,
                      ThfFormula formula);


    /** A correct implementation must return an object of the class implementing ThfFormula,
     *  representing the atomic formula represented by the object
     *   atom . 
     *  @param atom != null
     */
    public ThfFormula atomAsThfFormula(ThfAtomicFormula atom);

    public ThfFormula createThfPlainAtom(String predicate,
                  Iterable arguments);
    public ThfFormula createThfSystemAtom(String predicate,
                   Iterable arguments);
    public ThfFormula builtInThfTrue();
    public ThfFormula builtInThfFalse();
    public ThfFormula createThfVariableAtom(String variable);


    /** A correct implementation must return an object representing
     *  the binary formula obtained by applying  connective 
     *  to  lhs  and  rhs .
     *  Note that the method must work with conjunction and disjunction,
     *  as well as with nonassociative connectives.
     *  @param lhs != null
     *  @param connective != null 
     *  @param rhs != null
     */
    public 
    FofFormula 
    createBinaryFormula(FofFormula lhs,
                  BinaryConnective connective,
                  FofFormula rhs);

    /** A correct implementation must return an object representing
     *  the formula obtained by applying the negation connective
     *  to  formula .
     *  @param formula != null
     */
    public 
    FofFormula
    createNegationOf(FofFormula formula);


    /** A correct implementation must return an object representing
     *  the formula obtained by applying the quantifier
     *   quantifier  to  formula .
     *  @param quantifier != null
     *  @param variableList != null && variableList.iterator().hasNext()
     *  @param formula != null
     */
    public 
    FofFormula
    createQuantifiedFormula(Quantifier quantifier,
                      Iterable variableList,
                      FofFormula formula);


    /** A correct implementation must return an object representing
     *  the clause made of  literals .
     *   literals  will always be null if an empty
     *  clause has to be created.
     *  @param literals satisfies 
     *                   (literals == null || literals.iterator().hasNext())
     */
    public CnfFormula createClause(Iterable literals);
    

    /** A correct implementation must return an object of the class implementing FofFormula,
     *  representing the atomic formula represented by the object
     *   atom . 
     *  @param atom != null
     */
    public FofFormula atomAsFormula(AtomicFormula atom);
    
    /** A correct implementation must return an object representing the literal
     *  with  atom  and the polarity determined by 
     *   positive .
     *  @param positive == true iff the literal has to be positive
     *  @param atom != null
     */
    public Literal createLiteral(boolean positive,AtomicFormula atom);
    
    
    /** A correct implementation must return an object representing
     *  the atomic formula obtained by applying 
     *   predicate  to
     *   arguments .  arguments  
     *  will always be null if there are no arguments.
     *  @param predicate != null
     *  @param arguments satisfies 
     *                   (arguments == null || arguments.iterator().hasNext())
     */
    public 
    AtomicFormula
    createPlainAtom(String predicate,Iterable arguments);
    
    /** A correct implementation must return an object representing
     *  the atomic formula obtained by applying 
     *   predicate  to
     *   arguments .  arguments  
     *  will always be null if there are no arguments.
     *  @param predicate != null
     *  @param arguments satisfies 
     *                   (arguments == null || arguments.iterator().hasNext())
     */
    public 
    AtomicFormula
    createSystemAtom(String predicate,Iterable arguments);
    
    /** A correct implementation must return an object representing
     *  the atomic formula obtained by applying 
     *  the equality predicate to the terms.
     */
    public
    AtomicFormula
    createEqualityAtom(Term lhs,Term rhs);
    
    /* 
       Nothing for disequality here: lhs != lhs is handled with
       createNegationOf(createEqualityAtom(lhs,rhs)) 
    */

    /** A correct implementation must return a representation for $true. */
    public AtomicFormula builtInTrue();

    /** A correct implementation must return a representation for $false. */
    public AtomicFormula builtInFalse();

    
    /** A correct implementation must return an object representing 
     *   variable  as a term.
     *  @param variable != null
     */
    public Term createVariableTerm(String variable);
    
    
    /** A correct implementation must return an object representing
     *  the non-variable term obtained by applying 
     *   function  to
     *   arguments .  arguments  
     *  will always be null if there are no arguments, ie 
     *  when the term is an individual constant.
     *  @param function != null
     *  @param arguments satisfies 
     *                   (arguments == null || arguments.iterator().hasNext())
     */
    public Term createPlainTerm(String function,Iterable arguments);
                           
    
    /** A correct implementation must return an object representing
     *  the atomic formula obtained by applying 
     *   function  to
     *   arguments .  arguments  
     *  will always be null if there are no arguments, ie 
     *  when the term is an individual constant.
     *  @param function != null
     *  @param arguments satisfies 
     *                   (arguments == null || arguments.iterator().hasNext())
     */
    public Term createSystemTerm(String function,Iterable arguments);



    

    /*==================================================================
     *                     Annotations for top level items.            *
     *=================================================================*/



    /** A correct implementation must return an object representing
     *  an instance of <annotations> composed of 
     *   source  and  usefulInfo .
     *  @param source != null
     *  @param usefulInfo satisfies 
     *                    (usefulInfo == null || usefulInfo.iterator().hasNext())
     */
    public Annotations createAnnotations(Source source,
                               Iterable usefulInfo);



    /*==================================================================
     *  Various kinds of source descriptors (see  in the BNF). *
     *=================================================================*/

    
    /** A correct implementation must return an object representing
     *  an instance of <source> corresponding to 
     *   name .
     *  @param name != null
     */
    public Source createSourceFromName(String name);

    
    
    /** A correct implementation must return an object representing
     *  an instance of <source> corresponding to 
     *  a list of <sources> with the specified constituents.
     *  @param listOfSources nonempty
     */
    public 
    Source 
    createSourceFromListOfSources(Iterable listOfSources);


    /** A correct implementation must return an object representing
     *  an instance of <source> corresponding to 
     *  an instance of <inference record> with the specified constituents.
     *  @param inferenceRule != null
     *  @param usefulInfo satisfies 
     *                    (usefulInfo == null || usefulInfo.iterator().hasNext())
     *  @param parentInfoList nonempty
     */
    public 
    Source 
    createSourceFromInferenceRecord(String inferenceRule,
                            Iterable usefulInfo,
                            Iterable parentInfoList);


    /** A correct implementation must return an object representing
     *  an instance of <source> corresponding to 
     *  an instance of <internal source> with the specified constituents.
     *  @param introType != null
     *  @param introInfo satisfies 
     *                    (usefulInfo == null || usefulInfo.iterator().hasNext())
     */
    public Source createInternalSource(String introType,
                               Iterable introInfo);

    /** A correct implementation must return an object representing
     *  an instance of <source> corresponding to the specified
     *  location in a file.
     *  @param fileName != null
     *  @param fileInfo (may be null)
     */
    public Source createSourceFromFile(String fileName,
                                       String fileInfo);


    /** A correct implementation must return an object representing
     *  an instance of <source> corresponding to the specified
     *  creator.
     *  @param creatorName != null
     *  @param usefulInfo satisfies 
     *         (usefulInfo == null || usefulInfo.iterator().hasNext())
     */
    public Source createSourceFromCreator(String creatorName,
                                          Iterable usefulInfo);
    
    /** A correct implementation must return an object representing
     *  an instance of <source> corresponding to the specified
     *  theory.
     *  @param theoryName != null
     *  @param usefulInfo satisfies 
     *         (usefulInfo == null || usefulInfo.iterator().hasNext())
     */
    public Source createSourceFromTheory(String theoryName,
                                         Iterable usefulInfo);


    /*==================================================================
     *  Various kinds of info items (see  in the BNF).           *
     *=================================================================*/


    /** A correct implementation must return an object representing
     *  an instance of <info item> corresponding to an instance
     *  of <description item> with the specified parameter.
     *  @param singleQuoted != null
     */
    public InfoItem createDescriptionInfoItem(String singleQuoted);


    /** A correct implementation must return an object representing
     *  an instance of <info item> corresponding to an instance
     *  of <iquote item> with the specified parameter.
     *  @param singleQuoted != null
     */
    public InfoItem createIQuoteInfoItem(String singleQuoted);


    /** A correct implementation must return an object representing
     *  an instance of <info item> corresponding to an instance
     *  of  status(<status value>) with the specified parameter.
     *  @param statusValue != null
     */
    public InfoItem createInferenceStatusInfoItem(StatusValue statusValue);


    /** A correct implementation must return an object representing
     *  an instance of <info item> corresponding to an instance
     *  of <assumption record> with a list <name list> as the parameter.
     *  @param nameList != null
     */
    public InfoItem createAssumptionRecordInfoItem(Iterable nameList);


    /** A correct implementation must return an object representing
     *  an instance of <info item> corresponding to an instance
     *  of  <inference info> with the specified constituents.
     *  @param inferenceRule != null
     *  @param inferenceId != null
     *  @param attributes satisfies (attributes == null || attributes.iterator().hasNext())
     */
    public InfoItem createInferenceRuleInfoItem(String inferenceRule,
                                    String inferenceId,
                                    Iterable attributes);



    /** A correct implementation must return an object representing
     *  an instance of <info item> corresponding to an instance
     *  of <refutation> with the specified parameter.
     *  @param fileSource returned by a call to createSourceFromFile(..)
     */
    public InfoItem createRefutationInfoItem(Source fileSource);

    

    /** A correct implementation must return an object representing
     *  an instance of <info item> corresponding to the specified 
     *  instance of <general function>.
     *  @param generalFunction returned by a call to 
     *         createGeneralFunction(..)
     */
    public InfoItem createGeneralFunctionInfoItem(GeneralTerm generalFunction);


    /*==================================================================
     *        General terms (see  in the BNF).           *
     *=================================================================*/

    
    
    /** A correct implementation must return an object representing
     *  the non-list term obtained by applying 
     *   function  to
     *   arguments .  arguments  
     *  will always be null if there are no arguments, ie 
     *  when the term is an individual constant.
     *  @param function != null
     *  @param arguments satisfies 
     *                   (arguments == null || arguments.iterator().hasNext())
     */
    public GeneralTerm createGeneralFunction(String function,
                                   Iterable arguments);


    /** A correct implementation must return an object representing
     *  the general term constructed as a list.
     *  @param list satisfies 
     *              (list == null || list.iterator().hasNext())
     */
    public GeneralTerm createGeneralList(Iterable list);


    /** A correct implementation must return an object representing
     *  a general term obtained by applying ':' (colon) binary operator 
     *  to two general terms. Left operand should be not a list.
     *  @param left should not be a general term presenting a list 
     *  @param righ
     */
    public GeneralTerm createGeneralColon(GeneralTerm left, GeneralTerm right);


    /** A correct implementation must return an object representing
     *  a general term constructed as a number or a double-quoted string
     *  (both represented as a string)
     *  @param str
     */
    public GeneralTerm createGeneralDistinctObject(String str);


    /** A correct implementation must return an object representing
     *  a general term constructed as a variable
     *  (represented as a string)
     *  @param str
     */
    public GeneralTerm createGeneralVariable(String var);


    /** A correct implementation must return an object representing
     *  a formula
     *  @param formula
     */
    public GeneralTerm createGeneralThfFormula(ThfFormula formula);

    /** A correct implementation must return an object representing
     *  a formula
     *  @param formula
     */
    public GeneralTerm createGeneralFofFormula(FofFormula formula);

    /** A correct implementation must return an object representing
     *  a formula
     *  @param formula
     */
    public GeneralTerm createGeneralCnfFormula(CnfFormula formula);

    /** A correct implementation must return an object representing
     *  a formula
     *  @param formula
     */
    public GeneralTerm createGeneralTerm(Term term);


    /*==================================================================
     *          Parent info items (see  in the BNF).      *
     *=================================================================*/

    /** A correct implementation must return an object representing
     *  the parent info item with the specified parameters.
     *  @param source != null
     *  @param parentDetails if nonnull, corresponds to <single quoted> 
     *         in the -<single quoted> option in the BNF rule for <parent details>
     *         when parentDetails = null, it corresponds to the <null> option
     *         in that rule
     */
    public ParentInfo createParentInfo(Source source,GeneralTerm parentDetails);



} // interface TptpParserOutput




© 2015 - 2024 Weber Informatics LLC | Privacy Policy