Search in sources :

Example 16 with SPARQLFunction

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

the class PropStringAtom method adapt.

@SuppressWarnings("unchecked")
@Override
public <T> T adapt(RuleAtom ruleAtom) throws RuleAtomCallExeption {
    org.apache.stanbol.rules.manager.atoms.PropStringAtom tmp = (org.apache.stanbol.rules.manager.atoms.PropStringAtom) ruleAtom;
    StringFunctionAtom namespaceArg = tmp.getNamespaceArg();
    StringFunctionAtom labelArg = tmp.getLabelArg();
    try {
        SPARQLObject namespaceSparqlAtom = adapter.adaptTo(namespaceArg, SPARQLObject.class);
        SPARQLObject labelSparqlAtom = adapter.adaptTo(labelArg, SPARQLObject.class);
        String ns = namespaceSparqlAtom.getObject();
        String label = labelSparqlAtom.getObject();
        String sparql = "<http://www.stlab.istc.cnr.it/semion/function#propString>(" + ns + ", " + label + ")";
        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 17 with SPARQLFunction

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

the class StrAtom method adapt.

@SuppressWarnings("unchecked")
@Override
public <T> T adapt(RuleAtom ruleAtom) throws RuleAtomCallExeption, UnavailableRuleObjectException, UnsupportedTypeForExportException {
    org.apache.stanbol.rules.manager.atoms.StrAtom tmp = (org.apache.stanbol.rules.manager.atoms.StrAtom) ruleAtom;
    IObjectAtom argumentAtom = tmp.getUriResource();
    SPARQLObject sparqlObject = adapter.adaptTo(argumentAtom, SPARQLObject.class);
    String sparql = "str(" + 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 18 with SPARQLFunction

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

the class TypedLiteralAtom method adapt.

@SuppressWarnings("unchecked")
@Override
public <T> T adapt(RuleAtom ruleAtom) throws RuleAtomCallExeption, UnavailableRuleObjectException, UnsupportedTypeForExportException {
    org.apache.stanbol.rules.manager.atoms.TypedLiteralAtom tmp = (org.apache.stanbol.rules.manager.atoms.TypedLiteralAtom) ruleAtom;
    ExpressionAtom valueExpression = tmp.getValue();
    URIResource xsdTypeResource = tmp.getXsdType();
    SPARQLObject sparqlObject = null;
    sparqlObject = adapter.adaptTo(valueExpression, SPARQLObject.class);
    String value = sparqlObject.getObject();
    if (!value.startsWith("\"")) {
        value = "\"" + value;
    }
    if (!value.endsWith("\"")) {
        value += "\"";
    }
    String xsdType = "<" + xsdTypeResource.getURI().toString() + ">";
    return (T) new SPARQLFunction(value + "^^" + xsdType);
}
Also used : URIResource(org.apache.stanbol.rules.base.api.URIResource) SPARQLObject(org.apache.stanbol.rules.base.api.SPARQLObject) ExpressionAtom(org.apache.stanbol.rules.manager.atoms.ExpressionAtom) SPARQLFunction(org.apache.stanbol.rules.adapters.sparql.SPARQLFunction)

Example 19 with SPARQLFunction

use of org.apache.stanbol.rules.adapters.sparql.SPARQLFunction 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)

Example 20 with SPARQLFunction

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

the class ConcatAtom method adapt.

@SuppressWarnings("unchecked")
@Override
public <T> T adapt(RuleAtom ruleAtom) throws RuleAtomCallExeption, UnavailableRuleObjectException, UnsupportedTypeForExportException {
    org.apache.stanbol.rules.manager.atoms.ConcatAtom tmp = (org.apache.stanbol.rules.manager.atoms.ConcatAtom) ruleAtom;
    String sparqlConcat = "<http://www.w3.org/2005/xpath-functions#concat>";
    StringFunctionAtom argument1 = tmp.getArgument1();
    StringFunctionAtom argument2 = tmp.getArgument2();
    SPARQLObject sparqlArgument1;
    sparqlArgument1 = adapter.adaptTo(argument1, SPARQLObject.class);
    SPARQLObject sparqlArgument2 = adapter.adaptTo(argument2, SPARQLObject.class);
    String function = sparqlConcat + " (" + sparqlArgument1.getObject() + ", " + sparqlArgument2.getObject() + ")";
    return (T) new SPARQLFunction(function);
}
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)

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