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());
}
}
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);
}
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());
}
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 + ")");
}
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);
}
Aggregations