Search in sources :

Example 6 with IObjectAtom

use of org.apache.stanbol.rules.manager.atoms.IObjectAtom in project stanbol by apache.

the class NamespaceAtom method adapt.

@SuppressWarnings("unchecked")
@Override
public <T> T adapt(RuleAtom ruleAtom) throws RuleAtomCallExeption, UnavailableRuleObjectException, UnsupportedTypeForExportException {
    org.apache.stanbol.rules.manager.atoms.NamespaceAtom tmp = (org.apache.stanbol.rules.manager.atoms.NamespaceAtom) ruleAtom;
    IObjectAtom argument = tmp.getUriResource();
    SPARQLObject sparqlObject = adapter.adaptTo(argument, SPARQLObject.class);
    String sparql = "<http://jena.hpl.hp.com/ARQ/function#namespace>(" + sparqlObject.getObject() + ")";
    return (T) new SPARQLFunction(sparql);
}
Also used : SPARQLObject(org.apache.stanbol.rules.base.api.SPARQLObject) IObjectAtom(org.apache.stanbol.rules.manager.atoms.IObjectAtom) SPARQLFunction(org.apache.stanbol.rules.adapters.sparql.SPARQLFunction)

Example 7 with IObjectAtom

use of org.apache.stanbol.rules.manager.atoms.IObjectAtom 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 argument = tmp.getUriResource();
    SPARQLObject sparqlObject = adapter.adaptTo(argument, SPARQLObject.class);
    String sparql = "isBlank(" + sparqlObject.getObject() + ")";
    return (T) new SPARQLComparison(sparql);
}
Also used : SPARQLObject(org.apache.stanbol.rules.base.api.SPARQLObject) SPARQLComparison(org.apache.stanbol.rules.adapters.sparql.SPARQLComparison) IObjectAtom(org.apache.stanbol.rules.manager.atoms.IObjectAtom)

Example 8 with IObjectAtom

use of org.apache.stanbol.rules.manager.atoms.IObjectAtom in project stanbol by apache.

the class IndividualPropertyAtom method adapt.

@SuppressWarnings("unchecked")
@Override
public <T> T adapt(RuleAtom ruleAtom) throws RuleAtomCallExeption, UnavailableRuleObjectException, UnsupportedTypeForExportException {
    org.apache.stanbol.rules.manager.atoms.IndividualPropertyAtom tmp = (org.apache.stanbol.rules.manager.atoms.IndividualPropertyAtom) ruleAtom;
    IObjectAtom argument1 = tmp.getArgument1();
    IObjectAtom objectProperty = tmp.getObjectProperty();
    IObjectAtom argument2 = tmp.getArgument2();
    ClerezzaSparqlObject argument1CSO = (ClerezzaSparqlObject) adapter.adaptTo(argument1, ConstructQuery.class);
    ClerezzaSparqlObject datatypePropertyCSO = (ClerezzaSparqlObject) adapter.adaptTo(objectProperty, 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 UriRefOrVariable((Variable) arg2);
    } else if (dt instanceof IRI) {
        object = new UriRefOrVariable((IRI) arg2);
    } 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) 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)

Example 9 with IObjectAtom

use of org.apache.stanbol.rules.manager.atoms.IObjectAtom 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));
}
Also used : IRI(org.apache.clerezza.commons.rdf.IRI) Variable(org.apache.clerezza.rdf.core.sparql.query.Variable) ArrayList(java.util.ArrayList) BuiltInCall(org.apache.clerezza.rdf.core.sparql.query.BuiltInCall) UriRefExpression(org.apache.clerezza.rdf.core.sparql.query.UriRefExpression) IObjectAtom(org.apache.stanbol.rules.manager.atoms.IObjectAtom) ConstructQuery(org.apache.clerezza.rdf.core.sparql.query.ConstructQuery) UriRefExpression(org.apache.clerezza.rdf.core.sparql.query.UriRefExpression) Expression(org.apache.clerezza.rdf.core.sparql.query.Expression) ClerezzaSparqlObject(org.apache.stanbol.rules.adapters.clerezza.ClerezzaSparqlObject) ClerezzaSparqlObject(org.apache.stanbol.rules.adapters.clerezza.ClerezzaSparqlObject) RuleAtomCallExeption(org.apache.stanbol.rules.base.api.RuleAtomCallExeption)

Example 10 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;
    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));
}
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) 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)

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