Class Translator
java.lang.Object
org.tweetyproject.logics.translators.Translator
- Direct Known Subclasses:
AspFolTranslator
,ClNLPTranslator
,FOLPropTranslator
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 org.tweetyproject.logics.translate.folprop for a short example
implementation.
- Author:
- Tim Janus
-
Field Summary
Modifier and TypeFieldDescriptionstatic final int
Translation type for associative formulastatic final int
Translation type for atomstatic final int
Translation type for predicatestatic final int
Translation type for rule -
Constructor Summary
ConstructorDescriptionCreates a new Translator instance and initializes the translation map. -
Method Summary
Modifier and TypeMethodDescription<A extends AssociativeFormula<? extends SimpleLogicalFormula>>
AssociativeFormula<?> translateAssociative
(A source, Class<?> assocCls) Translates the given source associative formula into an instance of the target associative formula class.translateAtom
(Atom source, Class<?> atomCls) Translates the given source atom into an instance of the target atom class.<C extends Predicate>
CtranslatePredicate
(Predicate source, Class<C> predicateCls) Translates the given source predicate into an instance of the given predicate class.Rule
<?, ?> translateRule
(Rule<? extends SimpleLogicalFormula, ? extends SimpleLogicalFormula> source, Class<?> ruleCls) Translates the given source rule into an instance of the target rule class.Translates the given source formula using the translation map.
-
Field Details
-
TT_PREDICATE
public static final int TT_PREDICATETranslation type for predicate- See Also:
-
TT_ATOM
public static final int TT_ATOMTranslation type for atom- See Also:
-
TT_ASSOC
public static final int TT_ASSOCTranslation type for associative formula- See Also:
-
TT_RULE
public static final int TT_RULETranslation type for rule- See Also:
-
-
Constructor Details
-
Translator
public Translator()Creates a new Translator instance and initializes the translation map.
-
-
Method Details
-
translatePredicate
public <C extends Predicate> C translatePredicate(Predicate source, Class<C> predicateCls) throws LanguageException Translates the given source predicate into an instance of the given predicate class.- Type Parameters:
C
- the type of predicate- Parameters:
source
- the source predicate to be translatedpredicateCls
- the target predicate class- Returns:
- an instance of the target predicate class that is syntactically equivalent to the source predicate
- Throws:
LanguageException
- if there is a language-related issue during translation
-
translateAtom
Translates the given source atom into an instance of the target atom class.- Parameters:
source
- the source atom to be translatedatomCls
- the target atom class- Returns:
- the translated atom
- Throws:
LanguageException
- if there is a language-related issue during translation
-
translateAssociative
public <A extends AssociativeFormula<? extends SimpleLogicalFormula>> AssociativeFormula<?> translateAssociative(A source, Class<?> assocCls) Translates the given source associative formula into an instance of the target associative formula class.- Type Parameters:
A
- the type of associative formulas- Parameters:
source
- the source associative formula to be translatedassocCls
- the target associative formula class- Returns:
- the translated associative formula
-
translateUsingMap
Translates the given source formula using the translation map.- Parameters:
source
- the source formula to be translated- Returns:
- the translated formula, or null if translation could not be performed
-
translateRule
public Rule<?,?> translateRule(Rule<? extends SimpleLogicalFormula, ? extends SimpleLogicalFormula> source, Class<?> ruleCls) Translates the given source rule into an instance of the target rule class.- Parameters:
source
- the source rule to be translatedruleCls
- the target rule class- Returns:
- the translated rule
-