Search in sources :

Example 1 with SPARQLFunction

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

the class UpperCaseAtom method adapt.

@SuppressWarnings("unchecked")
@Override
public <T> T adapt(RuleAtom ruleAtom) throws RuleAtomCallExeption {
    StringFunctionAtom argument = ((org.apache.stanbol.rules.manager.atoms.UpperCaseAtom) ruleAtom).getStringFunctionAtom();
    try {
        SPARQLObject sparqlArgument = adapter.adaptTo(argument, SPARQLObject.class);
        String sparql = "<http://www.w3.org/2005/xpath-functions#upper-case> (" + sparqlArgument.getObject() + ")";
        return (T) new SPARQLFunction(sparql);
    } 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());
    }
}
Also used : 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) StringFunctionAtom(org.apache.stanbol.rules.manager.atoms.StringFunctionAtom) UnsupportedTypeForExportException(org.apache.stanbol.rules.base.api.UnsupportedTypeForExportException)

Example 2 with SPARQLFunction

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

the class CreateLabelAtom method adapt.

@SuppressWarnings("unchecked")
@Override
public <T> T adapt(RuleAtom ruleAtom) throws RuleAtomCallExeption, UnsupportedTypeForExportException, UnavailableRuleObjectException {
    org.apache.stanbol.rules.manager.atoms.CreateLabelAtom tmp = (org.apache.stanbol.rules.manager.atoms.CreateLabelAtom) ruleAtom;
    StringFunctionAtom stringFunctionAtom = tmp.getStringFunctionAtom();
    System.out.println("Argument instance of " + stringFunctionAtom.getClass().getCanonicalName());
    SPARQLObject sparqlArgument1 = adapter.adaptTo(stringFunctionAtom, SPARQLObject.class);
    String argument = sparqlArgument1.getObject();
    if (argument.startsWith(Symbols.variablesPrefix)) {
        argument = "?" + argument.replace(Symbols.variablesPrefix, "");
    }
    String sparql = "<http://www.stlab.istc.cnr.it/semion/function#createLabel>(" + argument + ")";
    return (T) new SPARQLFunction(sparql);
}
Also used : SPARQLObject(org.apache.stanbol.rules.base.api.SPARQLObject) SPARQLFunction(org.apache.stanbol.rules.adapters.sparql.SPARQLFunction) StringFunctionAtom(org.apache.stanbol.rules.manager.atoms.StringFunctionAtom)

Example 3 with SPARQLFunction

use of org.apache.stanbol.rules.adapters.sparql.SPARQLFunction 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;
    String variableArgument = tmp.getVariable().toString().replace(Symbols.variablesPrefix, "");
    StringFunctionAtom argument = tmp.getParameterFunctionAtom();
    SPARQLObject sparqlArgument = adapter.adaptTo(argument, SPARQLObject.class);
    String arg = sparqlArgument.getObject();
    String let = "LET (?" + variableArgument + " := " + arg + ")";
    SPARQLObject sparqlObject = new SPARQLFunction(let);
    return (T) sparqlObject;
}
Also used : SPARQLObject(org.apache.stanbol.rules.base.api.SPARQLObject) SPARQLFunction(org.apache.stanbol.rules.adapters.sparql.SPARQLFunction) StringFunctionAtom(org.apache.stanbol.rules.manager.atoms.StringFunctionAtom)

Example 4 with SPARQLFunction

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

the class LowerCaseAtom method adapt.

@SuppressWarnings("unchecked")
@Override
public <T> T adapt(RuleAtom ruleAtom) throws RuleAtomCallExeption, UnavailableRuleObjectException, UnsupportedTypeForExportException {
    StringFunctionAtom argument = ((org.apache.stanbol.rules.manager.atoms.LowerCaseAtom) ruleAtom).getStringFunctionAtom();
    SPARQLObject sparqlArgument = adapter.adaptTo(argument, SPARQLObject.class);
    String sparql = "<http://www.w3.org/2005/xpath-functions#lower-case> (" + sparqlArgument.getObject() + ")";
    return (T) new SPARQLFunction(sparql);
}
Also used : StringFunctionAtom(org.apache.stanbol.rules.manager.atoms.StringFunctionAtom) SPARQLObject(org.apache.stanbol.rules.base.api.SPARQLObject) SPARQLFunction(org.apache.stanbol.rules.adapters.sparql.SPARQLFunction)

Example 5 with SPARQLFunction

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

the class NewIRIAtom method adapt.

@SuppressWarnings("unchecked")
@Override
public <T> T adapt(RuleAtom ruleAtom) throws RuleAtomCallExeption, UnavailableRuleObjectException, UnsupportedTypeForExportException {
    org.apache.stanbol.rules.manager.atoms.NewIRIAtom tmp = (org.apache.stanbol.rules.manager.atoms.NewIRIAtom) ruleAtom;
    SPARQLObject binding = adapter.adaptTo(tmp.getBinding(), SPARQLObject.class);
    SPARQLObject variable = adapter.adaptTo(tmp.getNewNodeVariable(), SPARQLObject.class);
    SPARQLObject sparqlObject = new SPARQLFunction("BIND(" + "IRI(" + binding.getObject() + ") AS " + variable.getObject() + ")");
    return (T) sparqlObject;
}
Also used : SPARQLObject(org.apache.stanbol.rules.base.api.SPARQLObject) SPARQLFunction(org.apache.stanbol.rules.adapters.sparql.SPARQLFunction)

Aggregations

SPARQLFunction (org.apache.stanbol.rules.adapters.sparql.SPARQLFunction)23 SPARQLObject (org.apache.stanbol.rules.base.api.SPARQLObject)16 StringFunctionAtom (org.apache.stanbol.rules.manager.atoms.StringFunctionAtom)8 RuleAtomCallExeption (org.apache.stanbol.rules.base.api.RuleAtomCallExeption)4 UnavailableRuleObjectException (org.apache.stanbol.rules.base.api.UnavailableRuleObjectException)4 UnsupportedTypeForExportException (org.apache.stanbol.rules.base.api.UnsupportedTypeForExportException)4 IObjectAtom (org.apache.stanbol.rules.manager.atoms.IObjectAtom)3 NumericFunctionAtom (org.apache.stanbol.rules.manager.atoms.NumericFunctionAtom)2 RuleAtom (org.apache.stanbol.rules.base.api.RuleAtom)1 URIResource (org.apache.stanbol.rules.base.api.URIResource)1 AtomList (org.apache.stanbol.rules.base.api.util.AtomList)1 ExpressionAtom (org.apache.stanbol.rules.manager.atoms.ExpressionAtom)1