lojix/logic/src/main/com/thesett/aima/logic/fol/TermUtils.java
public static Clause convertToClause(Term term, VariableAndFunctorInterner interner) throws SourceCodeException
    {
        // Check if the top level term is a query, an implication or neither and reduce the term into a clause
        // accordingly.
        if (term instanceof OpSymbol)
        {
            OpSymbol symbol = (OpSymbol) term;

            if (":-".equals(symbol.getTextName()))
            {
                List<Functor> flattenedArgs = flattenTerm(symbol.getArgument(1), Functor.class, ",", interner);

                return new Clause<Functor>((Functor) symbol.getArgument(0),
                    flattenedArgs.toArray(new Functor[flattenedArgs.size()]));
            }
            else if ("?-".equals(symbol.getTextName()))
            {
                List<Functor> flattenedArgs = flattenTerm(symbol.getArgument(0), Functor.class, ",", interner);

                return new Clause<Functor>(null, flattenedArgs.toArray(new Functor[flattenedArgs.size()]));
            }
        }

        if (term instanceof Functor)
        {
            return new Clause<Functor>((Functor) term, null);
        }
        else
        {
            throw new SourceCodeException("Only functors can for a clause body, not " + term + ".", null, null, null,
                term.getSourceCodePosition());
        }
    }
public static Clause convertToClause(Term term, VariableAndFunctorInterner interner) throws SourceCodeException
    {
        // Check if the top level term is a query, an implication or neither and reduce the term into a clause
        // accordingly.
        if (term instanceof OpSymbol)
        {
            OpSymbol symbol = (OpSymbol) term;

            if (":-".equals(symbol.getTextName()))
            {
                List<Functor> flattenedArgs = flattenTerm(symbol.getArgument(1), Functor.class, ",", interner);

                return new Clause<Functor>((Functor) symbol.getArgument(0),
                    flattenedArgs.toArray(new Functor[flattenedArgs.size()]));
            }
            else if ("?-".equals(symbol.getTextName()))
            {
                List<Functor> flattenedArgs = flattenTerm(symbol.getArgument(0), Functor.class, ",", interner);

                return new Clause<Functor>(null, flattenedArgs.toArray(new Functor[flattenedArgs.size()]));
            }
        }

        if (term instanceof Functor)
        {
            return new Clause<Functor>((Functor) term, null);
        }
        else
        {
            throw new SourceCodeException("Only functors can for a clause body, not " + term + ".", null, null, null,
                term.getSourceCodePosition());
        }
    }
public static Clause convertToClause ( Term term , VariableAndFunctorInterner interner ) throws SourceCodeException { // Check if the top level term is a query, an implication or neither and reduce the term into a clause // accordingly. if ( term instanceof OpSymbol ) { OpSymbol symbol = ( OpSymbol ) term ; if ( ":-" . equals ( symbol . getTextName ( ) ) ) { List < Functor > flattenedArgs = flattenTerm ( symbol . getArgument ( 1 ) , Functor . class , "," , interner ) ; return new Clause < Functor > ( ( Functor ) symbol . getArgument ( 0 ) , flattenedArgs . toArray ( new Functor [ flattenedArgs . size ( ) ] ) ) ; } else if ( "?-" . equals ( symbol . getTextName ( ) ) ) { List < Functor > flattenedArgs = flattenTerm ( symbol . getArgument ( 0 ) , Functor . class , "," , interner ) ; return new Clause < Functor > ( null , flattenedArgs . toArray ( new Functor [ flattenedArgs . size ( ) ] ) ) ; } } if ( term instanceof Functor ) { return new Clause < Functor > ( ( Functor ) term , null ) ; } else { throw new SourceCodeException ( "Only functors can for a clause body, not " + term + "." , null , null , null , term . getSourceCodePosition ( ) ) ; } }
Converts a term into a clause. The term must be a functor. If it is a functor corresponding to the ':-' symbol it
is a clause with a head and a body. If it is a functor corresponding to the '?-' symbol it is a query clause with
no head but must have a body. If it is neither but is a functor it is interpreted as a program clause ':-' with
no body, that is, a fact.

@param  term     The term to convert to a top-level clause.
@param  interner The functor and variable name interner for the namespace the term to convert is in.

@return A clause for the term, or <tt>null</tt> if it cannot be converted.

@throws SourceCodeException If the term to convert to a clause does not form a valid clause.
Converts a term into a clause . The term must be a functor . If it is a functor corresponding to the : - symbol it is a clause with a head and a body . If it is a functor corresponding to the ? - symbol it is a query clause with no head but must have a body . If it is neither but is a functor it is interpreted as a program clause : - with no body that is a fact .