Search in sources :

Example 11 with SPARQLObject

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

the class SubstringAtom method adapt.

@SuppressWarnings("unchecked")
@Override
public <T> T adapt(RuleAtom ruleAtom) throws RuleAtomCallExeption {
    org.apache.stanbol.rules.manager.atoms.SubstringAtom tmp = (org.apache.stanbol.rules.manager.atoms.SubstringAtom) ruleAtom;
    StringFunctionAtom stringFunctionAtom = tmp.getStringFunctionAtom();
    NumericFunctionAtom startAtom = tmp.getStart();
    NumericFunctionAtom lengthAtom = tmp.getLength();
    try {
        SPARQLObject stringSparqlAtom = adapter.adaptTo(stringFunctionAtom, SPARQLObject.class);
        SPARQLObject startSparqlAtom = adapter.adaptTo(startAtom, SPARQLObject.class);
        SPARQLObject lengthSparqlAtom = adapter.adaptTo(lengthAtom, SPARQLObject.class);
        String uriResourceString = stringSparqlAtom.getObject();
        String start = startSparqlAtom.getObject();
        String length = lengthSparqlAtom.getObject();
        String sparql = "<http://www.w3.org/2005/xpath-functions#substring> (" + uriResourceString + ", " + start + ", " + length + ")";
        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) NumericFunctionAtom(org.apache.stanbol.rules.manager.atoms.NumericFunctionAtom) 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 12 with SPARQLObject

use of org.apache.stanbol.rules.base.api.SPARQLObject 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 13 with SPARQLObject

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

the class DifferentAtom method adapt.

@SuppressWarnings("unchecked")
@Override
public <T> T adapt(RuleAtom ruleAtom) throws RuleAtomCallExeption, UnavailableRuleObjectException, UnsupportedTypeForExportException {
    org.apache.stanbol.rules.manager.atoms.DifferentAtom tmp = (org.apache.stanbol.rules.manager.atoms.DifferentAtom) ruleAtom;
    ExpressionAtom expressionAtom1 = tmp.getStringFunctionAtom1();
    ExpressionAtom expressionAtom2 = tmp.getStringFunctionAtom2();
    SPARQLObject sparqlArgument1 = adapter.adaptTo(expressionAtom1, SPARQLObject.class);
    SPARQLObject sparqlArgument2 = adapter.adaptTo(expressionAtom2, SPARQLObject.class);
    String argument1 = sparqlArgument1.getObject();
    String argument2 = sparqlArgument2.getObject();
    argument1 = argument1.replace(Symbols.variablesPrefix, "");
    argument2 = argument2.replace(Symbols.variablesPrefix, "");
    StringBuilder sb = new StringBuilder();
    sb.append("(");
    sb.append(argument1);
    sb.append("!=");
    sb.append(argument2);
    sb.append(")");
    return (T) new SPARQLComparison(sb.toString());
}
Also used : SPARQLObject(org.apache.stanbol.rules.base.api.SPARQLObject) SPARQLComparison(org.apache.stanbol.rules.adapters.sparql.SPARQLComparison) ExpressionAtom(org.apache.stanbol.rules.manager.atoms.ExpressionAtom)

Example 14 with SPARQLObject

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

the class EndsWithAtom method adapt.

@SuppressWarnings("unchecked")
@Override
public <T> T adapt(RuleAtom ruleAtom) throws RuleAtomCallExeption, UnsupportedTypeForExportException, UnavailableRuleObjectException {
    org.apache.stanbol.rules.manager.atoms.EndsWithAtom tmp = (org.apache.stanbol.rules.manager.atoms.EndsWithAtom) ruleAtom;
    StringFunctionAtom argument = tmp.getArgument();
    StringFunctionAtom term = tmp.getTerm();
    SPARQLObject sparqlArgument = adapter.adaptTo(argument, SPARQLObject.class);
    SPARQLObject sparqlTerm = adapter.adaptTo(term, SPARQLObject.class);
    String argumentSparql = sparqlArgument.getObject();
    String termSparql = sparqlTerm.getObject();
    return (T) new SPARQLComparison("<http://www.w3.org/2005/xpath-functions#ends-with> (" + argumentSparql + ", " + termSparql + ")");
}
Also used : SPARQLObject(org.apache.stanbol.rules.base.api.SPARQLObject) SPARQLComparison(org.apache.stanbol.rules.adapters.sparql.SPARQLComparison) StringFunctionAtom(org.apache.stanbol.rules.manager.atoms.StringFunctionAtom)

Example 15 with SPARQLObject

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

the class IsBlankAtom method adapt.

@SuppressWarnings("unchecked")
@Override
public <T> T adapt(RuleAtom ruleAtom) throws RuleAtomCallExeption, UnavailableRuleObjectException, UnsupportedTypeForExportException {
    org.apache.stanbol.rules.manager.atoms.IsBlankAtom tmp = (org.apache.stanbol.rules.manager.atoms.IsBlankAtom) ruleAtom;
    IObjectAtom argument = tmp.getUriResource();
    SPARQLObject sparqlObject = adapter.adaptTo(argument, SPARQLObject.class);
    String sparql = "isBlank(" + sparqlObject.getObject() + ")";
    return (T) new SPARQLComparison(sparql);
}
Also used : SPARQLObject(org.apache.stanbol.rules.base.api.SPARQLObject) SPARQLComparison(org.apache.stanbol.rules.adapters.sparql.SPARQLComparison) IObjectAtom(org.apache.stanbol.rules.manager.atoms.IObjectAtom)

Aggregations

SPARQLObject (org.apache.stanbol.rules.base.api.SPARQLObject)35 SPARQLFunction (org.apache.stanbol.rules.adapters.sparql.SPARQLFunction)16 SPARQLComparison (org.apache.stanbol.rules.adapters.sparql.SPARQLComparison)13 UnsupportedTypeForExportException (org.apache.stanbol.rules.base.api.UnsupportedTypeForExportException)11 RuleAtomCallExeption (org.apache.stanbol.rules.base.api.RuleAtomCallExeption)10 UnavailableRuleObjectException (org.apache.stanbol.rules.base.api.UnavailableRuleObjectException)10 StringFunctionAtom (org.apache.stanbol.rules.manager.atoms.StringFunctionAtom)10 ExpressionAtom (org.apache.stanbol.rules.manager.atoms.ExpressionAtom)7 NumericFunctionAtom (org.apache.stanbol.rules.manager.atoms.NumericFunctionAtom)5 IObjectAtom (org.apache.stanbol.rules.manager.atoms.IObjectAtom)4 SPARQLTriple (org.apache.stanbol.rules.adapters.sparql.SPARQLTriple)3 ArrayList (java.util.ArrayList)2 RuleAtom (org.apache.stanbol.rules.base.api.RuleAtom)2 List (java.util.List)1 SPARQLNot (org.apache.stanbol.rules.adapters.sparql.SPARQLNot)1 Rule (org.apache.stanbol.rules.base.api.Rule)1 URIResource (org.apache.stanbol.rules.base.api.URIResource)1 AtomList (org.apache.stanbol.rules.base.api.util.AtomList)1 RuleList (org.apache.stanbol.rules.base.api.util.RuleList)1 Test (org.junit.Test)1