ua.gradsoft.termware
Class TermSystem

java.lang.Object
  extended by ua.gradsoft.termware.TermSystem

public class TermSystem
extends Object

TermSystem is set < rules,facts,strategy,env > where

The main sence of term system - reduce terms with help of given rules and in given environment by some strategy.

See Also:
IFacts, ITermRewritingStrategy, IEnv

Constructor Summary
TermSystem(ITermRewritingStrategy strategy, IFacts facts)
          create new instance of ITermSystem in default TermWare environment.
TermSystem(ITermRewritingStrategy strategy, IFacts facts, TermWareInstance instance)
          create new instance of ITermSystem
 
Method Summary
 void addNormalizer(String termName, ITermTransformer transformer)
          add normalizer transformer for terms with name termName
 void addRule(String s)
          add rule s to system.
 void addRule(Term t)
          add rule t to system with default priority.
 Term apply(String x)
          synonim of appply(ITermFactory.createParsedTerm(x))
 Term apply(String x, SourceCodeLocation scl)
          synonim of appply(ITermFactory.createParsedTerm(x,scl))
 Term apply(Term x)
          apply system to term x.
 boolean checkFact(String s)
          synonim of checkFact(ITermFactory.createParsedTerm(x))
 boolean checkFact(Term t, TransformationContext ctx)
          check fact t in associated facts database.
 boolean checkLoggedEntity(String s)
           
 void clearLoggedEntities()
           
 IEnv getEnv()
          get environment for input/output operations.
 IFacts getFacts()
          get facts base.
 TermWareInstance getInstance()
          get instance of runtime environment.
 Set<String> getLoggedEntities()
           
 SortedSet<String> getPatternNames()
          get patterns for all rules, added to system.
 ITermRewritingStrategy getStrategy()
          get strategy
 boolean isLoggingMode()
           
 boolean isReduceFacts()
          true, if facts are reduced by system before passing to facts database in checkFact and setFact methods.
 boolean isStop()
           
 void printHelp(PrintStream out)
          print to output stream name and descriptions of all rules in system.
 Term reduce(Term x)
          reduce term x
 Term reduce(Term x, TransformationContext ctx)
          reduce term in given transformation context.
 void setEnv(IEnv env)
          set environment for input/output operations.
 void setFact(String s)
          set fact s .
 void setFact(Term t, TransformationContext ctx)
          set fact t
 void setFacts(IFacts facts)
          set facts base
 void setLoggedEntities(Collection<String> loggedEntities)
           
 void setLoggedEntity(String s)
           
 void setLoggingMode(boolean mode)
           
 void setReduceFacts(boolean reduceFacts)
          if set to true, then facts are reduced by system before passing to facts database in checkFact and setFact methods.
 void setStop(boolean stop)
           
 void unsetLoggedEntity(String s)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

TermSystem

public TermSystem(ITermRewritingStrategy strategy,
                  IFacts facts,
                  TermWareInstance instance)
create new instance of ITermSystem

Parameters:
strategy - - strategy
facts - - database of facts
instance - - instance of TermWare environment.

TermSystem

public TermSystem(ITermRewritingStrategy strategy,
                  IFacts facts)
create new instance of ITermSystem in default TermWare environment.

Parameters:
strategy - - strategy
facts - - database of facts
Method Detail

apply

public Term apply(Term x)
apply system to term x. (try to reduce, on error return NIL)

Parameters:
x - term to reduce
Returns:
reduced term, or nil if reduce was failed.

apply

public final Term apply(String x)
synonim of appply(ITermFactory.createParsedTerm(x))

Parameters:
x - string, with term to reduce.
Returns:
reduced Term, or NIL if parsing was failed.

apply

public final Term apply(String x,
                        SourceCodeLocation scl)
synonim of appply(ITermFactory.createParsedTerm(x,scl))

Parameters:
x - string, with term to reduce.
scl - source code location of x.
Returns:
reduced Term, or NIL if parsing was failed.

checkFact

public boolean checkFact(Term t,
                         TransformationContext ctx)
                  throws TermWareException
check fact t in associated facts database. (after reducing of t, if ReduceFacts property set to true).

Parameters:
t - fact to check.
ctx - transformation context of system.
Returns:
true if fact t is checked, false otherwise.
Throws:
TermWareException
See Also:
isReduceFacts(), setReduceFacts(boolean), setFact(ua.gradsoft.termware.Term, ua.gradsoft.termware.TransformationContext)

checkFact

public boolean checkFact(String s)
                  throws TermWareException
synonim of checkFact(ITermFactory.createParsedTerm(x))

Parameters:
s - - sring with facts to reduce.
Returns:
true if fact is checked.
Throws:
TermWareException

setFact

public void setFact(Term t,
                    TransformationContext ctx)
             throws TermWareException
set fact t

Throws:
TermWareException

setFact

public final void setFact(String s)
                   throws TermWareException
set fact s .

Throws:
TermWareException

isReduceFacts

public boolean isReduceFacts()
true, if facts are reduced by system before passing to facts database in checkFact and setFact methods.

See Also:
setReduceFacts(boolean)

setReduceFacts

public void setReduceFacts(boolean reduceFacts)
if set to true, then facts are reduced by system before passing to facts database in checkFact and setFact methods. otherwise, facts terms are passed to facts database directly.

See Also:
isReduceFacts(), checkFact(ua.gradsoft.termware.Term, ua.gradsoft.termware.TransformationContext), setFact(ua.gradsoft.termware.Term, ua.gradsoft.termware.TransformationContext)

addRule

public void addRule(Term t)
             throws TermWareException
add rule t to system with default priority.

Throws:
TermWareException

addRule

public final void addRule(String s)
                   throws TermWareException
add rule s to system. alias for addRule(ITermFactory.createParsedTerm(s));

Throws:
TermWareException

addNormalizer

public void addNormalizer(String termName,
                          ITermTransformer transformer)
                   throws TermWareException
add normalizer transformer for terms with name termName

Throws:
TermWareException

reduce

public Term reduce(Term x)
            throws TermWareException
reduce term x

Throws:
TermWareException

reduce

public Term reduce(Term x,
                   TransformationContext ctx)
            throws TermWareException
reduce term in given transformation context. (This method used for shared transformation context between many systems, as implementation of apply)

Throws:
TermWareException

getEnv

public final IEnv getEnv()
get environment for input/output operations. If one was not set, than environment from TermWare instance is returned.

Returns:
i/o environment.
See Also:
IEnv, TermWareInstance.getEnv(), setEnv(ua.gradsoft.termware.IEnv)

setEnv

public final void setEnv(IEnv env)
set environment for input/output operations.

See Also:
IEnv, TermWareInstance.getEnv(), getEnv()

isStop

public final boolean isStop()

setStop

public final void setStop(boolean stop)

isLoggingMode

public final boolean isLoggingMode()

setLoggingMode

public final void setLoggingMode(boolean mode)

checkLoggedEntity

public final boolean checkLoggedEntity(String s)

setLoggedEntity

public final void setLoggedEntity(String s)

unsetLoggedEntity

public final void unsetLoggedEntity(String s)

getLoggedEntities

public final Set<String> getLoggedEntities()

setLoggedEntities

public final void setLoggedEntities(Collection<String> loggedEntities)

clearLoggedEntities

public final void clearLoggedEntities()

getStrategy

public final ITermRewritingStrategy getStrategy()
get strategy

Returns:
strategy of the system

getFacts

public final IFacts getFacts()
get facts base.

Returns:
facts of the system.

setFacts

public void setFacts(IFacts facts)
set facts base

Parameters:
facts - - new facts to set.

getInstance

public final TermWareInstance getInstance()
get instance of runtime environment.

Returns:
instance of TermWare runtime.

printHelp

public void printHelp(PrintStream out)
print to output stream name and descriptions of all rules in system.

Parameters:
out - - where we print help messages.

getPatternNames

public SortedSet<String> getPatternNames()
get patterns for all rules, added to system.

Returns:
sorted set of all patterns in system