use of org.apache.stanbol.rules.manager.atoms.IObjectAtom in project stanbol by apache.
the class BlankNodeAtom method adapt.
@SuppressWarnings("unchecked")
@Override
public <T> T adapt(RuleAtom ruleAtom) throws RuleAtomCallExeption, UnavailableRuleObjectException, UnsupportedTypeForExportException {
org.apache.stanbol.rules.manager.atoms.BlankNodeAtom tmp = (org.apache.stanbol.rules.manager.atoms.BlankNodeAtom) ruleAtom;
UriRefOrVariable subject;
UriRefOrVariable predicate;
ResourceOrVariable object;
IObjectAtom argument2UriResource = tmp.getArgument2();
IObjectAtom argument1UriResource = tmp.getArgument1();
ClerezzaSparqlObject subjectCSO = (ClerezzaSparqlObject) adapter.adaptTo(argument2UriResource, ConstructQuery.class);
ClerezzaSparqlObject predicateCSO = (ClerezzaSparqlObject) adapter.adaptTo(argument1UriResource, ConstructQuery.class);
subject = new UriRefOrVariable((IRI) subjectCSO.getClerezzaObject());
predicate = new UriRefOrVariable((IRI) predicateCSO.getClerezzaObject());
object = new ResourceOrVariable(new BlankNode());
return (T) new ClerezzaSparqlObject(new SimpleTriplePattern(subject, predicate, object));
}
use of org.apache.stanbol.rules.manager.atoms.IObjectAtom 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.manager.atoms.IObjectAtom in project stanbol by apache.
the class NewLiteralAtom method adapt.
@SuppressWarnings("unchecked")
@Override
public <T> T adapt(RuleAtom ruleAtom) throws RuleAtomCallExeption, UnavailableRuleObjectException, UnsupportedTypeForExportException {
org.apache.stanbol.rules.manager.atoms.NewLiteralAtom tmp = (org.apache.stanbol.rules.manager.atoms.NewLiteralAtom) ruleAtom;
StringFunctionAtom bindingAtom = tmp.getBinding();
IObjectAtom variableAtom = tmp.getNewNodeVariable();
ClerezzaSparqlObject binding = (ClerezzaSparqlObject) adapter.adaptTo(bindingAtom, ConstructQuery.class);
ClerezzaSparqlObject variable = (ClerezzaSparqlObject) adapter.adaptTo(variableAtom, ConstructQuery.class);
List<Expression> bindArgumentExpressions = new ArrayList<Expression>();
bindArgumentExpressions.add((Expression) binding.getClerezzaObject());
bindArgumentExpressions.add((Expression) variable.getClerezzaObject());
BuiltInCall bindBuiltInCall = new BuiltInCall("BIND", bindArgumentExpressions);
return (T) new ClerezzaSparqlObject(bindBuiltInCall);
}
use of org.apache.stanbol.rules.manager.atoms.IObjectAtom 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;
OWLDataFactory factory = OWLManager.getOWLDataFactory();
IObjectAtom classResource = tmp.getClassResource();
IObjectAtom argument = tmp.getArgument1();
SWRLAtom classResourceAtom = (SWRLAtom) adapter.adaptTo(classResource, SWRLRule.class);
SWRLAtom argumentAtom = (SWRLAtom) adapter.adaptTo(argument, SWRLRule.class);
OWLClass classPredicate;
SWRLIArgument argumentResource;
if (classResourceAtom instanceof ArgumentSWRLAtom) {
classPredicate = factory.getOWLClass(IRI.create(((ArgumentSWRLAtom) classResourceAtom).getId()));
} else {
throw new RuleAtomCallExeption(getClass());
}
if (argumentAtom instanceof ArgumentSWRLAtom) {
argumentResource = (SWRLIArgument) ((ArgumentSWRLAtom) argumentAtom).getSwrlArgument();
} else {
throw new RuleAtomCallExeption(getClass());
}
return (T) factory.getSWRLClassAtom(classPredicate, argumentResource);
}
use of org.apache.stanbol.rules.manager.atoms.IObjectAtom in project stanbol by apache.
the class StrAtom method adapt.
@SuppressWarnings("unchecked")
@Override
public <T> T adapt(RuleAtom ruleAtom) throws RuleAtomCallExeption, UnavailableRuleObjectException, UnsupportedTypeForExportException {
org.apache.stanbol.rules.manager.atoms.StrAtom tmp = (org.apache.stanbol.rules.manager.atoms.StrAtom) ruleAtom;
IObjectAtom uriResource = tmp.getUriResource();
SWRLAtom swrlAtom = (SWRLAtom) adapter.adaptTo(uriResource, SWRLRule.class);
if (swrlAtom instanceof ArgumentSWRLAtom) {
return (T) swrlAtom;
} else {
throw new RuleAtomCallExeption(getClass());
}
}
Aggregations