Package net.sf.tweety.logics.translators
Class Translator
- java.lang.Object
-
- net.sf.tweety.logics.translators.Translator
-
- Direct Known Subclasses:
AspFolTranslator
,ClNLPTranslator
,FOLPropTranslator
public abstract class Translator extends java.lang.Object
Allows translation between different logic languages, sub classes have to implement the translation between complex formulas but this base class provides methods to translate, predicates, Atoms, Associative formulas and Rules. To translate more complex formulas subclasses shall override the translateUsingMap() method. It is recommended to call the super method when overriding to have the correct translate behavior for basic constructs like Atoms, Predicate etc. The sub class also have to implement the createTranslateMap() method. The map maps a source class to a pair of a target class and an implementation which shall be used for translation. Although sub classes shall provide an easy user-interface with different overloads of methods like: toLang1() and toLang2() the translate map is necessary to support nested formulas like a disjunction of conjunction of several disjunction etc. Remark: The implementations used unchecked generic casts. It is important that the subclasses create consistent translation maps, otherwise there might be a ClassCastException which is not thrown by this code although it is caused by the inconsistent translation map. Also see net.sf.tweety.logics.translate.folprop for a short example implementation.- Author:
- Tim Janus
-
-
Field Summary
Fields Modifier and Type Field Description static int
TT_ASSOC
static int
TT_ATOM
static int
TT_PREDICATE
static int
TT_RULE
-
Constructor Summary
Constructors Constructor Description Translator()
-
Method Summary
Modifier and Type Method Description <A extends AssociativeFormula<? extends SimpleLogicalFormula>>
AssociativeFormula<?>translateAssociative(A source, java.lang.Class<?> assocCls)
Translates the given AssociativeFormula into another AssociativeFormula thats type is given by the parameter assocClsAtom
translateAtom(Atom source, java.lang.Class<?> atomCls)
Translates the given source atom into an instance of atomCls and returns the translation.<C extends Predicate>
CtranslatePredicate(Predicate source, java.lang.Class<C> predicateCls)
Translates the given source predicate into an instance of the given predicate class and returns the translation.Rule<?,?>
translateRule(Rule<? extends SimpleLogicalFormula,? extends SimpleLogicalFormula> source, java.lang.Class<?> ruleCls)
SimpleLogicalFormula
translateUsingMap(SimpleLogicalFormula source)
-
-
-
Field Detail
-
TT_PREDICATE
public static final int TT_PREDICATE
- See Also:
- Constant Field Values
-
TT_ATOM
public static final int TT_ATOM
- See Also:
- Constant Field Values
-
TT_ASSOC
public static final int TT_ASSOC
- See Also:
- Constant Field Values
-
TT_RULE
public static final int TT_RULE
- See Also:
- Constant Field Values
-
-
Method Detail
-
translatePredicate
public <C extends Predicate> C translatePredicate(Predicate source, java.lang.Class<C> predicateCls) throws LanguageException
Translates the given source predicate into an instance of the given predicate class and returns the translation.- Type Parameters:
C
- the type of predicate- Parameters:
source
- The predicate acting as source for the operationpredicateCls
- The description of the destination Predicate class- Returns:
- An instance of predicateCls which is syntactically equal to source.
- Throws:
LanguageException
- if an issue with the language occurs.
-
translateAtom
public Atom translateAtom(Atom source, java.lang.Class<?> atomCls) throws LanguageException
Translates the given source atom into an instance of atomCls and returns the translation.- Parameters:
source
- The atom acting as sourceatomCls
- The description of the destination Atom class- Returns:
- The translated atom
- Throws:
LanguageException
- if an issue with the language occurs.
-
translateAssociative
public <A extends AssociativeFormula<? extends SimpleLogicalFormula>> AssociativeFormula<?> translateAssociative(A source, java.lang.Class<?> assocCls)
Translates the given AssociativeFormula into another AssociativeFormula thats type is given by the parameter assocCls- Type Parameters:
A
- the type of associative formulas- Parameters:
source
- The source formulaassocCls
- the class of the expected associative formula- Returns:
- an associative formula
-
translateUsingMap
public SimpleLogicalFormula translateUsingMap(SimpleLogicalFormula source)
-
translateRule
public Rule<?,?> translateRule(Rule<? extends SimpleLogicalFormula,? extends SimpleLogicalFormula> source, java.lang.Class<?> ruleCls)
-
-