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