Search in sources :

Example 1 with SPARQLNot

use of org.apache.stanbol.rules.adapters.sparql.SPARQLNot in project stanbol by apache.

the class ClassAtom method adapt.

@SuppressWarnings("unchecked")
@Override
public <T> T adapt(RuleAtom ruleAtom) throws RuleAtomCallExeption, UnavailableRuleObjectException, UnsupportedTypeForExportException {
    String argument1SPARQL = null;
    String argument2SPARQL = null;
    boolean negativeArg = false;
    boolean negativeClass = false;
    org.apache.stanbol.rules.manager.atoms.ClassAtom tmp = (org.apache.stanbol.rules.manager.atoms.ClassAtom) ruleAtom;
    SPARQLObject sparqlArgument1 = adapter.adaptTo(tmp.getArgument1(), SPARQLObject.class);
    SPARQLObject sparqlArgument2 = adapter.adaptTo(tmp.getClassResource(), SPARQLObject.class);
    if (negativeArg || negativeClass) {
        String optional = sparqlArgument1.getObject() + " <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> " + sparqlArgument2.getObject();
        ArrayList<String> filters = new ArrayList<String>();
        if (negativeArg) {
            filters.add("!bound(" + argument1SPARQL + ")");
        }
        if (negativeClass) {
            filters.add("!bound(" + argument2SPARQL + ")");
        }
        String[] filterArray = new String[filters.size()];
        filterArray = filters.toArray(filterArray);
        return (T) new SPARQLNot(optional, filterArray);
    } else {
        return (T) new SPARQLTriple(sparqlArgument1.getObject() + " <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> " + sparqlArgument2.getObject());
    }
}
Also used : SPARQLNot(org.apache.stanbol.rules.adapters.sparql.SPARQLNot) SPARQLObject(org.apache.stanbol.rules.base.api.SPARQLObject) ArrayList(java.util.ArrayList) SPARQLTriple(org.apache.stanbol.rules.adapters.sparql.SPARQLTriple)

Aggregations

ArrayList (java.util.ArrayList)1 SPARQLNot (org.apache.stanbol.rules.adapters.sparql.SPARQLNot)1 SPARQLTriple (org.apache.stanbol.rules.adapters.sparql.SPARQLTriple)1 SPARQLObject (org.apache.stanbol.rules.base.api.SPARQLObject)1