Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
/*
* This file is part of "TweetyProject", a collection of Java libraries for
* logical aspects of artificial intelligence and knowledge representation.
*
* TweetyProject is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License version 3 as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see .
*
* Copyright 2016 The TweetyProject Team
*/
package net.sf.tweety.action.query.parser;
import java.io.IOException;
import java.io.Reader;
import java.io.StringReader;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import java.util.Set;
import java.util.Stack;
import net.sf.tweety.action.grounding.GroundingRequirement;
import net.sf.tweety.action.grounding.parser.GroundingRequirementsParser;
import net.sf.tweety.action.query.syntax.AlwaysQuery;
import net.sf.tweety.action.query.syntax.HoldsQuery;
import net.sf.tweety.action.query.syntax.NecessarilyQuery;
import net.sf.tweety.action.query.syntax.QueryProposition;
import net.sf.tweety.action.query.syntax.SActionQuery;
import net.sf.tweety.action.query.syntax.SActionQuerySet;
import net.sf.tweety.action.signature.ActionSignature;
import net.sf.tweety.action.signature.FolAction;
import net.sf.tweety.action.signature.FolActionName;
import net.sf.tweety.commons.Parser;
import net.sf.tweety.commons.ParserException;
import net.sf.tweety.logics.commons.LogicalSymbols;
import net.sf.tweety.logics.commons.syntax.Variable;
import net.sf.tweety.logics.fol.parser.FolParser;
import net.sf.tweety.logics.fol.syntax.FolAtom;
import net.sf.tweety.logics.fol.syntax.FolFormula;
import net.sf.tweety.logics.pl.syntax.Conjunction;
import net.sf.tweety.logics.pl.syntax.Contradiction;
import net.sf.tweety.logics.pl.syntax.Disjunction;
import net.sf.tweety.logics.pl.syntax.Negation;
import net.sf.tweety.logics.pl.syntax.Proposition;
import net.sf.tweety.logics.pl.syntax.PlFormula;
import net.sf.tweety.logics.pl.syntax.Tautology;
/**
* This class implements a parser for action queries in S. The BNF of such queries is given by: (starting symbol is KB)
* KB ::== QUERY1 ("\n" QUERY1)*
* QUERY1 ::== QUERY ( "requires" REQUIREMENTS )?
* QUERY ::== PROPOSITION | QUERY "&&" QUERY | QUERY "||" QUERY | "!" QUERY | "(" QUERY ")" | "+" | "-"
* PROPOSITION ::== HOLDSQUERY | ALWAYSQUERY | NECESSARILYQUERY
* HOLDSQUERY ::== "holds" "[" STATEFORMULA "]"
* ALWAYSQUERY ::== "always" "[" STATEFORMULA "]"
* NECESSARILYQUERY ::== "necessarily" "[" STATEFORMULA "]" "after" ACTIONS
* ACTIONS ::== ACTION ( ";" ACTION )*
* ACTION ::== "{" ACTIONNAME ("," ACTIONNAME)* "}"
* REQUIREMENTS ::== REQUIREMENT ("," REQUIREMENT)*
* REQUIREMENT ::== (VARIABLENAME "<>" VARIABLENAME | VARIABLENAME "<>" CONSTANTNAME)*
*
* where STATEFORMULA is an unquantified first-order formula without functors,
* and VARIABLENAME, CONSTANTNAME are sequences of symbols
* from {a,...,z,A,...,Z,0,...,9} with a letter at the beginning.
*
* @author Sebastian Homann
* @author Tim Janus (change constant LogicalSymbols to dynamic)
*/
public class ActionQueryParser
extends Parser {
private ActionSignature signature;
public ActionQueryParser(ActionSignature signature) {
this.signature = signature;
}
/*
* (non-Javadoc)
* @see net.sf.tweety.Parser#parseBeliefBase(java.io.Reader)
*/
@Override
public SActionQuerySet parseBeliefBase( Reader reader ) {
SActionQuerySet beliefSet = new SActionQuerySet();
String s = "";
// read from the reader and separate formulas by "\n"
try{
for(int c = reader.read(); c != -1; c = reader.read()){
if(c == 10){
if(!s.equals("") && !s.trim().startsWith( "%" ))
beliefSet.add(this.parseFormula(new StringReader(s)));
s = "";
}else{
s += (char) c;
}
}
if(!s.equals("") && !s.trim().startsWith("%"))
beliefSet.add(this.parseFormula(new StringReader(s)));
}catch(Exception e){
throw new ParserException(e);
}
return beliefSet;
}
/*
* (non-Javadoc)
* @see net.sf.tweety.Parser#parseFormula(java.io.Reader)
*/
@Override
public SActionQuery parseFormula( Reader reader )
throws IOException, ParserException {
Stack