Search in sources :

Example 6 with AtomList

use of org.apache.stanbol.rules.base.api.util.AtomList in project stanbol by apache.

the class RuleParserImpl method ruleDefinition.

public final AtomList[] ruleDefinition() throws ParseException {
    AtomList body;
    AtomList head;
    Token t;
    body = atomList();
    jj_consume_token(LARROW);
    head = atomList();
    {
        if (true)
            return new AtomList[] { body, head };
    }
    throw new Error("Missing return statement in function");
}
Also used : AtomList(org.apache.stanbol.rules.base.api.util.AtomList)

Example 7 with AtomList

use of org.apache.stanbol.rules.base.api.util.AtomList in project stanbol by apache.

the class UnionAtom method adapt.

@SuppressWarnings("unchecked")
@Override
public <T> T adapt(RuleAtom ruleAtom) throws RuleAtomCallExeption {
    org.apache.stanbol.rules.manager.atoms.UnionAtom tmp = (org.apache.stanbol.rules.manager.atoms.UnionAtom) ruleAtom;
    AtomList atomList1 = tmp.getAtomList1();
    AtomList atomList2 = tmp.getAtomList2();
    String scope1 = "";
    for (RuleAtom inGroupRuleAtom : atomList1) {
        if (!scope1.isEmpty()) {
            scope1 += " . ";
        }
        try {
            SPARQLObject inGroupSparqlAtom = adapter.adaptTo(inGroupRuleAtom, SPARQLObject.class);
            scope1 += inGroupSparqlAtom.getObject();
        } catch (UnsupportedTypeForExportException e) {
            throw new org.apache.stanbol.rules.base.api.RuleAtomCallExeption(getClass());
        } catch (UnavailableRuleObjectException e) {
            throw new org.apache.stanbol.rules.base.api.RuleAtomCallExeption(getClass());
        }
    }
    String scope2 = "";
    for (RuleAtom inGroupRuleAtom : atomList2) {
        if (!scope2.isEmpty()) {
            scope2 += " . ";
        }
        try {
            SPARQLObject inGroupSparqlAtom = adapter.adaptTo(inGroupRuleAtom, SPARQLObject.class);
            scope2 += inGroupSparqlAtom.getObject();
        } catch (UnsupportedTypeForExportException e) {
            throw new org.apache.stanbol.rules.base.api.RuleAtomCallExeption(getClass());
        } catch (UnavailableRuleObjectException e) {
            throw new org.apache.stanbol.rules.base.api.RuleAtomCallExeption(getClass());
        }
    }
    String sparqlUnion = " { " + scope1 + " } UNION { " + scope2 + " } ";
    return (T) new SPARQLFunction(sparqlUnion);
}
Also used : AtomList(org.apache.stanbol.rules.base.api.util.AtomList) SPARQLObject(org.apache.stanbol.rules.base.api.SPARQLObject) UnavailableRuleObjectException(org.apache.stanbol.rules.base.api.UnavailableRuleObjectException) RuleAtomCallExeption(org.apache.stanbol.rules.base.api.RuleAtomCallExeption) SPARQLFunction(org.apache.stanbol.rules.adapters.sparql.SPARQLFunction) UnsupportedTypeForExportException(org.apache.stanbol.rules.base.api.UnsupportedTypeForExportException) RuleAtom(org.apache.stanbol.rules.base.api.RuleAtom)

Aggregations

AtomList (org.apache.stanbol.rules.base.api.util.AtomList)7 RuleAtom (org.apache.stanbol.rules.base.api.RuleAtom)4 UnsupportedTypeForExportException (org.apache.stanbol.rules.base.api.UnsupportedTypeForExportException)2 ClauseEntry (com.hp.hpl.jena.reasoner.rulesys.ClauseEntry)1 ArrayList (java.util.ArrayList)1 IRI (org.apache.clerezza.commons.rdf.IRI)1 SPARQLFunction (org.apache.stanbol.rules.adapters.sparql.SPARQLFunction)1 Rule (org.apache.stanbol.rules.base.api.Rule)1 RuleAtomCallExeption (org.apache.stanbol.rules.base.api.RuleAtomCallExeption)1 SPARQLObject (org.apache.stanbol.rules.base.api.SPARQLObject)1 UnavailableRuleObjectException (org.apache.stanbol.rules.base.api.UnavailableRuleObjectException)1 RuleImpl (org.apache.stanbol.rules.manager.RuleImpl)1 UnionAtom (org.apache.stanbol.rules.manager.atoms.UnionAtom)1