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.
/**
* Copyright (C) 2008, University of Manchester
*
* Modifications to the initial code base are copyright of their
* respective authors, or their employers as appropriate. Authorship
* of the modifications may be determined from the ChangeLog placed at
* the end of this file.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
* This library 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 library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
package org.coode.patterns;
import java.util.Collection;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.regex.Pattern;
import java.util.regex.PatternSyntaxException;
import org.coode.oppl.ConstraintSystem;
import org.coode.oppl.OPPLAbstractFactory;
import org.coode.oppl.Variable;
import org.coode.oppl.VariableScope;
import org.coode.oppl.bindingtree.BindingNode;
import org.coode.oppl.exceptions.OPPLException;
import org.coode.oppl.exceptions.RuntimeExceptionHandler;
import org.coode.oppl.function.Aggregandum;
import org.coode.oppl.function.OPPLFunction;
import org.coode.oppl.generated.GeneratedVariable;
import org.coode.oppl.generated.RegexpGeneratedVariable;
import org.coode.oppl.variabletypes.InputVariable;
import org.coode.oppl.variabletypes.VariableFactory;
import org.coode.oppl.variabletypes.VariableType;
import org.coode.parsers.ErrorListener;
import org.semanticweb.owlapi.model.IRI;
import org.semanticweb.owlapi.model.OWLAxiom;
import org.semanticweb.owlapi.model.OWLClassExpression;
import org.semanticweb.owlapi.model.OWLLiteral;
import org.semanticweb.owlapi.model.OWLObject;
import org.semanticweb.owlapi.model.OWLOntology;
import org.semanticweb.owlapi.model.OWLOntologyManager;
import org.semanticweb.owlapi.model.OWLRuntimeException;
import org.semanticweb.owlapi.reasoner.OWLReasoner;
/** @author Luigi Iannone Jun 19, 2008 */
public class PatternConstraintSystem extends ConstraintSystem {
/** constant symbol for this class */
public static final String THIS_CLASS_VARIABLE_CONSTANT_SYMBOL = "$thisClass";
private final Map> specialVariables = new HashMap>();
private final ConstraintSystem constraintSystem;
private final Map specialVariableRenderings = new HashMap();
private final AbstractPatternModelFactory factory;
/** @param cs
* cs
* @param ontologyManager
* ontologyManager
* @param f
* f */
public PatternConstraintSystem(ConstraintSystem cs,
OWLOntologyManager ontologyManager, AbstractPatternModelFactory f) {
super(cs.getOntology(), ontologyManager, f.getOPPLFactory());
setReasoner(cs.getReasoner());
constraintSystem = cs;
factory = f;
}
/** @param ontology
* ontology
* @param ontologyManager
* ontologyManager
* @param reasoner
* reasoner
* @param f
* f */
public PatternConstraintSystem(OWLOntology ontology,
OWLOntologyManager ontologyManager, OWLReasoner reasoner,
AbstractPatternModelFactory f) {
this(
new ConstraintSystem(ontology, ontologyManager, reasoner,
f.getOPPLFactory()), ontologyManager, f);
}
@Override
public InputVariable createVariable(String name,
VariableType type, VariableScope> variableScope) throws OPPLException {
return constraintSystem.createVariable(name, type, variableScope);
}
/** @return variable for this class */
public Variable> getThisClassVariable() {
Variable toReturn = VariableFactory.getCLASSVariable(
THIS_CLASS_VARIABLE_CONSTANT_SYMBOL, null);
importVariable(toReturn);
return toReturn;
}
@Override
public Variable> getVariable(String name) {
Variable> variable = constraintSystem.getVariable(name);
if (variable == null) {
Iterator it = specialVariables.keySet().iterator();
boolean found = false;
GeneratedVariable> specialVariable = null;
while (!found && it.hasNext()) {
String referenceName = it.next();
specialVariable = specialVariables.get(referenceName);
found = referenceName.equals(name)
|| specialVariableRenderings.get(specialVariable.getName()) != null
&& specialVariableRenderings.get(specialVariable.getName())
.equals(name);
}
if (found) {
variable = specialVariable;
}
}
return variable;
}
@Override
public Variable> getVariable(IRI iri) {
Variable> variable = constraintSystem.getVariable(iri);
if (variable == null) {
variable = getSpecialVariable(iri);
}
return variable;
}
private Variable> getSpecialVariable(IRI iri) {
boolean found = false;
Iterator extends Variable>> it = specialVariables.values().iterator();
Variable> variable = null;
while (!found && it.hasNext()) {
variable = it.next();
found = iri.equals(variable.getIRI());
}
return found ? variable : null;
}
@Override
public boolean isVariableIRI(IRI uri) {
boolean found = constraintSystem.isVariableIRI(uri);
if (!found) {
Iterator extends Variable>> it = specialVariables.values().iterator();
while (!found && it.hasNext()) {
Variable> variable = it.next();
found = uri.equals(variable.getIRI());
}
}
return found;
}
/** @param s
* s
* @return resolved pattern constants */
public String resolvePatternConstants(String s) {
String toReturn = s;
for (String specialVariableName : specialVariables.keySet()) {
GeneratedVariable> variable = specialVariables.get(specialVariableName);
if (variable != null) {
toReturn = toReturn.replaceAll("\\" + specialVariableName,
variable.getName());
}
}
return toReturn;
}
/** @param variable
* variable
* @return true if variable is this class variable */
public boolean isThisClassVariable(Variable> variable) {
return variable.equals(specialVariables
.get(PatternConstraintSystem.THIS_CLASS_VARIABLE_CONSTANT_SYMBOL));
}
@Override
public Set> getVariables() {
Set> toReturn = constraintSystem.getVariables();
toReturn.addAll(specialVariables.values());
return toReturn;
}
/** @param patternName
* patternName
* @param visitedPatterns
* visitedPatterns
* @param dependencies
* dependencies
* @param errorListener
* errorListener
* @param args
* args
* @return resolved pattern
* @throws PatternException
* PatternException */
public String resolvePattern(String patternName, Set visitedPatterns,
List dependencies, ErrorListener errorListener,
List