Search in sources :

Example 1 with VariableAtom

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

the class LetAtom method adapt.

@SuppressWarnings("unchecked")
@Override
public <T> T adapt(RuleAtom ruleAtom) throws RuleAtomCallExeption, UnavailableRuleObjectException, UnsupportedTypeForExportException {
    org.apache.stanbol.rules.manager.atoms.LetAtom tmp = (org.apache.stanbol.rules.manager.atoms.LetAtom) ruleAtom;
    StringFunctionAtom parameterFunctionAtom = tmp.getParameterFunctionAtom();
    URIResource variableUriResource = tmp.getVariable();
    ClerezzaSparqlObject iriArgument;
    iriArgument = (ClerezzaSparqlObject) adapter.adaptTo(parameterFunctionAtom, ConstructQuery.class);
    List<Expression> iriArgumentExpressions = new ArrayList<Expression>();
    iriArgumentExpressions.add((Expression) iriArgument.getClerezzaObject());
    BuiltInCall iriBuiltInCall = new BuiltInCall("IRI", iriArgumentExpressions);
    if (variableUriResource instanceof VariableAtom) {
        String variableName = ((VariableAtom) variableUriResource).getVariableName();
        Variable variable = new Variable(variableName);
        List<Expression> bindArgumentExpressions = new ArrayList<Expression>();
        bindArgumentExpressions.add(iriBuiltInCall);
        bindArgumentExpressions.add(variable);
        BuiltInCall bindBuiltInCall = new BuiltInCall("BIND", iriArgumentExpressions);
        return (T) new ClerezzaSparqlObject(bindBuiltInCall);
    } else {
        throw new org.apache.stanbol.rules.base.api.RuleAtomCallExeption(getClass());
    }
}
Also used : Variable(org.apache.clerezza.rdf.core.sparql.query.Variable) VariableAtom(org.apache.stanbol.rules.manager.atoms.VariableAtom) URIResource(org.apache.stanbol.rules.base.api.URIResource) ArrayList(java.util.ArrayList) BuiltInCall(org.apache.clerezza.rdf.core.sparql.query.BuiltInCall) 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) RuleAtomCallExeption(org.apache.stanbol.rules.base.api.RuleAtomCallExeption)

Example 2 with VariableAtom

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

the class RuleParserImpl method variable.

public final IObjectAtom variable() throws ParseException {
    Token t;
    String var;
    switch((jj_ntk == -1) ? jj_ntk() : jj_ntk) {
        case NOTEX:
            jj_consume_token(NOTEX);
            jj_consume_token(LPAR);
            t = jj_consume_token(VARIABLE);
            jj_consume_token(RPAR);
            var = t.image;
            var = kb.getPrefixURI("var") + var.substring(1);
            try {
                {
                    if (true)
                        return new VariableAtom(new URI(var), true);
                }
            } catch (URISyntaxException e) {
                e.printStackTrace();
                {
                    if (true)
                        return null;
                }
            }
            break;
        case VARIABLE:
            t = jj_consume_token(VARIABLE);
            var = t.image;
            var = kb.getPrefixURI("var") + var.substring(1);
            try {
                {
                    if (true)
                        return new VariableAtom(new URI(var), false);
                }
            } catch (URISyntaxException e) {
                e.printStackTrace();
                {
                    if (true)
                        return null;
                }
            }
            break;
        case BNODE:
            t = jj_consume_token(BNODE);
            var = t.image;
            {
                if (true)
                    return new RuleBlankNode(var);
            }
            break;
        default:
            jj_la1[15] = jj_gen;
            jj_consume_token(-1);
            throw new ParseException();
    }
    throw new Error("Missing return statement in function");
}
Also used : RuleBlankNode(org.apache.stanbol.rules.manager.atoms.RuleBlankNode) NumericVariableAtom(org.apache.stanbol.rules.manager.atoms.NumericVariableAtom) StringVariableAtom(org.apache.stanbol.rules.manager.atoms.StringVariableAtom) VariableAtom(org.apache.stanbol.rules.manager.atoms.VariableAtom) URISyntaxException(java.net.URISyntaxException) URI(java.net.URI)

Aggregations

VariableAtom (org.apache.stanbol.rules.manager.atoms.VariableAtom)2 URI (java.net.URI)1 URISyntaxException (java.net.URISyntaxException)1 ArrayList (java.util.ArrayList)1 BuiltInCall (org.apache.clerezza.rdf.core.sparql.query.BuiltInCall)1 Expression (org.apache.clerezza.rdf.core.sparql.query.Expression)1 Variable (org.apache.clerezza.rdf.core.sparql.query.Variable)1 ClerezzaSparqlObject (org.apache.stanbol.rules.adapters.clerezza.ClerezzaSparqlObject)1 RuleAtomCallExeption (org.apache.stanbol.rules.base.api.RuleAtomCallExeption)1 URIResource (org.apache.stanbol.rules.base.api.URIResource)1 NumericVariableAtom (org.apache.stanbol.rules.manager.atoms.NumericVariableAtom)1 RuleBlankNode (org.apache.stanbol.rules.manager.atoms.RuleBlankNode)1 StringFunctionAtom (org.apache.stanbol.rules.manager.atoms.StringFunctionAtom)1 StringVariableAtom (org.apache.stanbol.rules.manager.atoms.StringVariableAtom)1