Search in sources :

Example 11 with IObjectAtom

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));
}
Also used : IRI(org.apache.clerezza.commons.rdf.IRI) ResourceOrVariable(org.apache.clerezza.rdf.core.sparql.query.ResourceOrVariable) BlankNode(org.apache.clerezza.commons.rdf.BlankNode) UriRefOrVariable(org.apache.clerezza.rdf.core.sparql.query.UriRefOrVariable) IObjectAtom(org.apache.stanbol.rules.manager.atoms.IObjectAtom) ConstructQuery(org.apache.clerezza.rdf.core.sparql.query.ConstructQuery) ClerezzaSparqlObject(org.apache.stanbol.rules.adapters.clerezza.ClerezzaSparqlObject) SimpleTriplePattern(org.apache.clerezza.rdf.core.sparql.query.impl.SimpleTriplePattern)

Example 12 with IObjectAtom

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));
}
Also used : IRI(org.apache.clerezza.commons.rdf.IRI) ResourceOrVariable(org.apache.clerezza.rdf.core.sparql.query.ResourceOrVariable) Variable(org.apache.clerezza.rdf.core.sparql.query.Variable) UriRefOrVariable(org.apache.clerezza.rdf.core.sparql.query.UriRefOrVariable) ResourceOrVariable(org.apache.clerezza.rdf.core.sparql.query.ResourceOrVariable) LiteralExpression(org.apache.clerezza.rdf.core.sparql.query.LiteralExpression) UriRefOrVariable(org.apache.clerezza.rdf.core.sparql.query.UriRefOrVariable) IObjectAtom(org.apache.stanbol.rules.manager.atoms.IObjectAtom) ConstructQuery(org.apache.clerezza.rdf.core.sparql.query.ConstructQuery) ClerezzaSparqlObject(org.apache.stanbol.rules.adapters.clerezza.ClerezzaSparqlObject) SimpleTriplePattern(org.apache.clerezza.rdf.core.sparql.query.impl.SimpleTriplePattern) ClerezzaSparqlObject(org.apache.stanbol.rules.adapters.clerezza.ClerezzaSparqlObject) RuleAtomCallExeption(org.apache.stanbol.rules.base.api.RuleAtomCallExeption) RuleAtom(org.apache.stanbol.rules.base.api.RuleAtom)

Example 13 with IObjectAtom

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);
}
Also used : ArrayList(java.util.ArrayList) BuiltInCall(org.apache.clerezza.rdf.core.sparql.query.BuiltInCall) IObjectAtom(org.apache.stanbol.rules.manager.atoms.IObjectAtom) ConstructQuery(org.apache.clerezza.rdf.core.sparql.query.ConstructQuery) StringFunctionAtom(org.apache.stanbol.rules.manager.atoms.StringFunctionAtom) Expression(org.apache.clerezza.rdf.core.sparql.query.Expression) ClerezzaSparqlObject(org.apache.stanbol.rules.adapters.clerezza.ClerezzaSparqlObject)

Example 14 with IObjectAtom

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);
}
Also used : ArgumentSWRLAtom(org.apache.stanbol.rules.adapters.swrl.ArgumentSWRLAtom) IObjectAtom(org.apache.stanbol.rules.manager.atoms.IObjectAtom) SWRLIArgument(org.semanticweb.owlapi.model.SWRLIArgument) SWRLAtom(org.semanticweb.owlapi.model.SWRLAtom) ArgumentSWRLAtom(org.apache.stanbol.rules.adapters.swrl.ArgumentSWRLAtom) SWRLRule(org.semanticweb.owlapi.model.SWRLRule) OWLClass(org.semanticweb.owlapi.model.OWLClass) RuleAtomCallExeption(org.apache.stanbol.rules.base.api.RuleAtomCallExeption) OWLDataFactory(org.semanticweb.owlapi.model.OWLDataFactory)

Example 15 with IObjectAtom

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());
    }
}
Also used : ArgumentSWRLAtom(org.apache.stanbol.rules.adapters.swrl.ArgumentSWRLAtom) IObjectAtom(org.apache.stanbol.rules.manager.atoms.IObjectAtom) SWRLAtom(org.semanticweb.owlapi.model.SWRLAtom) ArgumentSWRLAtom(org.apache.stanbol.rules.adapters.swrl.ArgumentSWRLAtom) SWRLRule(org.semanticweb.owlapi.model.SWRLRule) RuleAtomCallExeption(org.apache.stanbol.rules.base.api.RuleAtomCallExeption)

Aggregations

IObjectAtom (org.apache.stanbol.rules.manager.atoms.IObjectAtom)36 RuleAtomCallExeption (org.apache.stanbol.rules.base.api.RuleAtomCallExeption)15 ConstructQuery (org.apache.clerezza.rdf.core.sparql.query.ConstructQuery)8 ClerezzaSparqlObject (org.apache.stanbol.rules.adapters.clerezza.ClerezzaSparqlObject)8 Node (com.hp.hpl.jena.graph.Node)7 ClauseEntry (com.hp.hpl.jena.reasoner.rulesys.ClauseEntry)7 ArrayList (java.util.ArrayList)7 NodeClauseEntry (org.apache.stanbol.rules.adapters.jena.NodeClauseEntry)7 StringFunctionAtom (org.apache.stanbol.rules.manager.atoms.StringFunctionAtom)6 IRI (org.apache.clerezza.commons.rdf.IRI)5 TriplePattern (com.hp.hpl.jena.reasoner.TriplePattern)4 BuiltInCall (org.apache.clerezza.rdf.core.sparql.query.BuiltInCall)4 Expression (org.apache.clerezza.rdf.core.sparql.query.Expression)4 ResourceOrVariable (org.apache.clerezza.rdf.core.sparql.query.ResourceOrVariable)4 UriRefOrVariable (org.apache.clerezza.rdf.core.sparql.query.UriRefOrVariable)4 Variable (org.apache.clerezza.rdf.core.sparql.query.Variable)4 SimpleTriplePattern (org.apache.clerezza.rdf.core.sparql.query.impl.SimpleTriplePattern)4 ArgumentSWRLAtom (org.apache.stanbol.rules.adapters.swrl.ArgumentSWRLAtom)4 RuleAtom (org.apache.stanbol.rules.base.api.RuleAtom)4 SPARQLObject (org.apache.stanbol.rules.base.api.SPARQLObject)4