Package net.sf.tweety.logics.dl.parser
Class DlParser
- java.lang.Object
-
- net.sf.tweety.commons.Parser<DlBeliefSet,DlAxiom>
-
- net.sf.tweety.logics.dl.parser.DlParser
-
public class DlParser extends Parser<DlBeliefSet,DlAxiom>
This class implements a parser for the description logic ALC (attributive concept language with complements). The input syntax is based on the input syntax of the Racer reasoner.
Note: Racer is built for the description logic SRIQ(D) (= the DL that corresponds to the OWL2 language), which is more expressive than ALC. SRIQ(D)-exclusive elements like inverse roles, role hierarchies and at-least restrictions are not supported by this parser. Furthermore, the syntax of universal and existential restrictions is different for reasons of simplification (see BNF).
The input syntax for an ALC knowledge base is given by the following BNF (starting symbol is KB):
KB ::== SIGNATURE FORMULAS
SIGNATURE ::== "signature(" (CONCEPT_DECLAR)? (ROLE_DECLAR)? (INDIVIDUAL_DECLAR)? ")"
CONCEPT_DECLAR ::== ("\n")* "atomic-concepts(" (CONCEPTNAME)* ")"
ROLE_DECLAR ::== ("\n")* "roles(" (ROLENAME)* ")"
INDIVIDUAL_DECLAR ::== ("\n")* "individuals(" (CONSTANTNAME)* ")"
AXIOMS ::== ("\n" AXIOM)*
AXIOM ::== "instance " " " CONSTANTNAME " " CONCEPT | "related " CONSTANTNAME " " CONSTANTNAME " " ROLENAME |
"implies " " " CONCEPT " " CONCEPT | "equivalent" CONCEPT " " CONCEPT
CONCEPT ::== "(" CONCEPT ")" | CONCEPTNAME | "not " CONCEPT | "*top*" | "*bottom*" | "top" | "bottom" |
"and " CONCEPT " " CONCEPT | "or " CONCEPT " " CONCEPT |
"forall " ROLENAME " " CONCEPT | "exists " ROLENAME " " CONCEPT
where CONCEPTNAME, ROLENAME, CONSTANTNAME are sequences of
symbols from {a,...,z,A,...,Z,0,...,9} with a letter at the beginning
excluding {"top","bottom"}.- Author:
- Anna Gessler, Matthias Thimm
-
-
Field Summary
Fields Modifier and Type Field Description private java.lang.Boolean
addTrueEquivalence
A flag that is used for adding an additional formula to represent a (true) equivalence axiom.private DlSignature
signature
Keeps track of the signature.
-
Constructor Summary
Constructors Constructor Description DlParser()
-
Method Summary
Modifier and Type Method Description DlSignature
getSignature()
Returns the signature of this parser.private DlAxiom
parseAxiom(java.util.List<java.lang.Object> l)
Parses an ALC axiom as a list of String tokens or formulas.DlBeliefSet
parseBeliefBase(java.io.Reader reader)
Parses the given reader into a belief base of the given type.private ComplexConcept
parseConcept(java.lang.Object s)
Parses an atomic concept, top concept or bottom concept from a String token.private ComplexConcept
parseConcept(java.util.List<java.lang.Object> l)
Parses a complex concept as a list of String tokens or formulas.DlAxiom
parseFormula(java.io.Reader reader)
Parses the given reader into a formula of the given type.private Individual
parseIndividual(java.lang.Object s)
Parses an individual from a String token.private AtomicRole
parseRole(java.lang.Object s)
Parses a role from a String token.private void
parseTypeDeclaration(java.lang.String s, DlSignature signature)
Parses an atomic concept declaration of the form "concept" "(" CONCEPTNAME ")" or an atomic role declaration of the form "role" "(" ROLENAME ")" and modifies the given signature accordingly.void
setSignature(DlSignature signature)
Sets the signature for this parser.void
tokenize(java.util.Stack<java.lang.Object> stack, int c)
This method reads one character from the given reader and appropriately tokenizes it.-
Methods inherited from class net.sf.tweety.commons.Parser
isNumeric, parseBeliefBase, parseBeliefBaseFromFile, parseFormula, parseFormulaFromFile
-
-
-
-
Field Detail
-
signature
private DlSignature signature
Keeps track of the signature.
-
addTrueEquivalence
private java.lang.Boolean addTrueEquivalence
A flag that is used for adding an additional formula to represent a (true) equivalence axiom.
-
-
Method Detail
-
parseBeliefBase
public DlBeliefSet parseBeliefBase(java.io.Reader reader) throws java.io.IOException, ParserException
Description copied from class:Parser
Parses the given reader into a belief base of the given type.- Specified by:
parseBeliefBase
in classParser<DlBeliefSet,DlAxiom>
- Parameters:
reader
- a reader- Returns:
- a belief base
- Throws:
java.io.IOException
- if some IO issue occurred.ParserException
- some parsing exceptions may be added here.
-
parseTypeDeclaration
private void parseTypeDeclaration(java.lang.String s, DlSignature signature)
Parses an atomic concept declaration of the form "concept" "(" CONCEPTNAME ")" or an atomic role declaration of the form "role" "(" ROLENAME ")" and modifies the given signature accordingly.- Parameters:
s
- a stringsignature
- a signature
-
parseFormula
public DlAxiom parseFormula(java.io.Reader reader) throws java.io.IOException, ParserException
Description copied from class:Parser
Parses the given reader into a formula of the given type.- Specified by:
parseFormula
in classParser<DlBeliefSet,DlAxiom>
- Parameters:
reader
- a reader- Returns:
- a formula
- Throws:
java.io.IOException
- if some IO issue occurred.ParserException
- some parsing exceptions may be added here.
-
tokenize
public void tokenize(java.util.Stack<java.lang.Object> stack, int c)
This method reads one character from the given reader and appropriately tokenizes it.- Parameters:
stack
- used for monitoring the read itemsc
- token from stream
-
parseAxiom
private DlAxiom parseAxiom(java.util.List<java.lang.Object> l)
Parses an ALC axiom as a list of String tokens or formulas.- Parameters:
l
- list of String tokens or description logic formulas- Returns:
- a DLAxiom
- Throws:
ParserException
- if the list could not be parsed.
-
parseConcept
private ComplexConcept parseConcept(java.util.List<java.lang.Object> l)
Parses a complex concept as a list of String tokens or formulas.- Parameters:
l
- list of String tokens or description logic formulas- Returns:
- a ComplexConcept
- Throws:
ParserException
- if the list could not be parsed.
-
parseIndividual
private Individual parseIndividual(java.lang.Object s)
Parses an individual from a String token.- Parameters:
s
- identifier of the individual- Returns:
- an Individual
- Throws:
ParserException
- if the individual could not be parsed
-
parseConcept
private ComplexConcept parseConcept(java.lang.Object s)
Parses an atomic concept, top concept or bottom concept from a String token.- Parameters:
s
- String identifier of the concept- Returns:
- a ComplexConcept
- Throws:
ParserException
- if the concept could not be parsed
-
parseRole
private AtomicRole parseRole(java.lang.Object s)
Parses a role from a String token.- Parameters:
s
- identifier of the role- Returns:
- an AtomicRole
- Throws:
ParserException
- if the role could not be parsed
-
setSignature
public void setSignature(DlSignature signature)
Sets the signature for this parser.- Parameters:
signature
- a DL signature.
-
getSignature
public DlSignature getSignature()
Returns the signature of this parser.- Returns:
- the signature of this parser.
-
-