use of org.apache.stanbol.rules.base.api.RuleAtomCallExeption in project stanbol by apache.
the class IsBlankAtom method adapt.
@SuppressWarnings("unchecked")
@Override
public <T> T adapt(RuleAtom ruleAtom) throws RuleAtomCallExeption, UnavailableRuleObjectException, UnsupportedTypeForExportException {
org.apache.stanbol.rules.manager.atoms.IsBlankAtom tmp = (org.apache.stanbol.rules.manager.atoms.IsBlankAtom) ruleAtom;
IObjectAtom uriResource = tmp.getUriResource();
ClerezzaSparqlObject argumentCSO = (ClerezzaSparqlObject) adapter.adaptTo(uriResource, ConstructQuery.class);
;
Object arg = argumentCSO.getClerezzaObject();
Expression argumentExpression;
if (arg instanceof Variable) {
argumentExpression = (Variable) arg;
} else if (arg instanceof IRI) {
argumentExpression = new UriRefExpression((IRI) arg);
} else {
throw new RuleAtomCallExeption(getClass());
}
List<Expression> expressions = new ArrayList<Expression>();
expressions.add(argumentExpression);
return (T) new ClerezzaSparqlObject(new BuiltInCall("isBLANK", expressions));
}
use of org.apache.stanbol.rules.base.api.RuleAtomCallExeption in project stanbol by apache.
the class LetAtom method adapt.
@SuppressWarnings("unchecked")
@Override
public <T> T adapt(RuleAtom ruleAtom) throws RuleAtomCallExeption, UnavailableRuleObjectException, UnsupportedTypeForExportException {
org.apache.stanbol.rules.manager.atoms.LetAtom tmp = (org.apache.stanbol.rules.manager.atoms.LetAtom) ruleAtom;
StringFunctionAtom parameterFunctionAtom = tmp.getParameterFunctionAtom();
URIResource variableUriResource = tmp.getVariable();
ClerezzaSparqlObject iriArgument;
iriArgument = (ClerezzaSparqlObject) adapter.adaptTo(parameterFunctionAtom, ConstructQuery.class);
List<Expression> iriArgumentExpressions = new ArrayList<Expression>();
iriArgumentExpressions.add((Expression) iriArgument.getClerezzaObject());
BuiltInCall iriBuiltInCall = new BuiltInCall("IRI", iriArgumentExpressions);
if (variableUriResource instanceof VariableAtom) {
String variableName = ((VariableAtom) variableUriResource).getVariableName();
Variable variable = new Variable(variableName);
List<Expression> bindArgumentExpressions = new ArrayList<Expression>();
bindArgumentExpressions.add(iriBuiltInCall);
bindArgumentExpressions.add(variable);
BuiltInCall bindBuiltInCall = new BuiltInCall("BIND", iriArgumentExpressions);
return (T) new ClerezzaSparqlObject(bindBuiltInCall);
} else {
throw new org.apache.stanbol.rules.base.api.RuleAtomCallExeption(getClass());
}
}
use of org.apache.stanbol.rules.base.api.RuleAtomCallExeption in project stanbol by apache.
the class ClassAtom method adapt.
@SuppressWarnings("unchecked")
@Override
public <T> T adapt(RuleAtom ruleAtom) throws RuleAtomCallExeption, UnavailableRuleObjectException, UnsupportedTypeForExportException {
org.apache.stanbol.rules.manager.atoms.ClassAtom tmp = (org.apache.stanbol.rules.manager.atoms.ClassAtom) ruleAtom;
IObjectAtom argument1 = tmp.getArgument1();
IObjectAtom classResource = tmp.getClassResource();
ClerezzaSparqlObject argumentCSO = (ClerezzaSparqlObject) adapter.adaptTo(argument1, ConstructQuery.class);
ClerezzaSparqlObject classCSO = (ClerezzaSparqlObject) adapter.adaptTo(classResource, ConstructQuery.class);
UriRefOrVariable subject;
UriRefOrVariable predicate = new UriRefOrVariable(RDF.type);
ResourceOrVariable object;
Object arg = argumentCSO.getClerezzaObject();
Object cl = classCSO.getClerezzaObject();
if (arg instanceof Variable) {
subject = new UriRefOrVariable((Variable) arg);
} else if (arg instanceof IRI) {
subject = new UriRefOrVariable((IRI) arg);
} else {
throw new RuleAtomCallExeption(getClass());
}
if (cl instanceof Variable) {
object = new ResourceOrVariable((Variable) cl);
} else if (cl instanceof IRI) {
object = new ResourceOrVariable((IRI) cl);
} else {
throw new RuleAtomCallExeption(getClass());
}
return (T) new ClerezzaSparqlObject(new SimpleTriplePattern(subject, predicate, object));
}
use of org.apache.stanbol.rules.base.api.RuleAtomCallExeption in project stanbol by apache.
the class DatavaluedPropertyAtom method adapt.
@SuppressWarnings("unchecked")
@Override
public <T> T adapt(RuleAtom ruleAtom) throws RuleAtomCallExeption, UnavailableRuleObjectException, UnsupportedTypeForExportException {
org.apache.stanbol.rules.manager.atoms.DatavaluedPropertyAtom tmp = (org.apache.stanbol.rules.manager.atoms.DatavaluedPropertyAtom) ruleAtom;
IObjectAtom argument1 = tmp.getArgument1();
IObjectAtom datatypeProperty = tmp.getDatatypeProperty();
RuleAtom argument2 = tmp.getArgument2();
ClerezzaSparqlObject argument1CSO = (ClerezzaSparqlObject) adapter.adaptTo(argument1, ConstructQuery.class);
ClerezzaSparqlObject datatypePropertyCSO = (ClerezzaSparqlObject) adapter.adaptTo(datatypeProperty, ConstructQuery.class);
ClerezzaSparqlObject argument2CSO = (ClerezzaSparqlObject) adapter.adaptTo(argument2, ConstructQuery.class);
Object arg1 = argument1CSO.getClerezzaObject();
Object dt = datatypePropertyCSO.getClerezzaObject();
Object arg2 = argument2CSO.getClerezzaObject();
UriRefOrVariable subject;
UriRefOrVariable predicate;
ResourceOrVariable object;
if (arg1 instanceof Variable) {
subject = new UriRefOrVariable((Variable) arg1);
} else if (arg1 instanceof IRI) {
subject = new UriRefOrVariable((IRI) arg1);
} else {
throw new RuleAtomCallExeption(getClass());
}
if (dt instanceof Variable) {
predicate = new UriRefOrVariable((Variable) dt);
} else if (dt instanceof IRI) {
predicate = new UriRefOrVariable((IRI) dt);
} else {
throw new RuleAtomCallExeption(getClass());
}
if (arg2 instanceof Variable) {
object = new ResourceOrVariable((Variable) arg2);
} else if (arg2 instanceof LiteralExpression) {
object = new ResourceOrVariable(((LiteralExpression) arg2).getLiteral());
} else {
throw new RuleAtomCallExeption(getClass());
}
return (T) new ClerezzaSparqlObject(new SimpleTriplePattern(subject, predicate, object));
}
use of org.apache.stanbol.rules.base.api.RuleAtomCallExeption in project stanbol by apache.
the class RefactorerImpl method graphRefactoring.
@SuppressWarnings("unchecked")
@Override
public Graph graphRefactoring(Graph inputGraph, Recipe recipe) throws RefactoringException {
RuleAdapter ruleAdapter;
try {
ruleAdapter = ruleAdapterManager.getAdapter(recipe, ConstructQuery.class);
List<ConstructQuery> constructQueries = (List<ConstructQuery>) ruleAdapter.adaptTo(recipe, ConstructQuery.class);
for (ConstructQuery constructQuery : constructQueries) {
System.out.println(constructQuery.toString());
}
Graph unionGraph = new SimpleGraph();
for (ConstructQuery constructQuery : constructQueries) {
unionGraph.addAll(sparqlConstruct(constructQuery, inputGraph));
}
return unionGraph;
} catch (UnavailableRuleObjectException e) {
throw new RefactoringException("The cause of the refactoring excpetion is: " + e.getMessage(), e);
} catch (UnsupportedTypeForExportException e) {
throw new RefactoringException("The cause of the refactoring excpetion is: " + e.getMessage(), e);
} catch (RuleAtomCallExeption e) {
throw new RefactoringException("The cause of the refactoring excpetion is: " + e.getMessage(), e);
}
}
Aggregations