use of org.apache.stanbol.rules.base.api.SPARQLObject in project stanbol by apache.
the class SPARQLAdapter method adaptRecipeTo.
@SuppressWarnings("unchecked")
protected <T> T adaptRecipeTo(Recipe recipe, Class<T> type) throws UnsupportedTypeForExportException, UnavailableRuleObjectException {
List<SPARQLObject> sparqlObjects = null;
if (type == SPARQLObject.class) {
RuleList ruleList = recipe.getRuleList();
Iterator<Rule> ruleIterator = ruleList.iterator();
sparqlObjects = new ArrayList<SPARQLObject>();
for (int i = 0; ruleIterator.hasNext(); i++) {
sparqlObjects.add((SPARQLObject) adaptRuleTo(ruleIterator.next(), type));
}
} else {
throw new UnsupportedTypeForExportException("The SPARQL Export Provider does not support the selected serialization : " + type.getCanonicalName());
}
return (T) sparqlObjects;
}
use of org.apache.stanbol.rules.base.api.SPARQLObject 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());
}
}
use of org.apache.stanbol.rules.base.api.SPARQLObject in project stanbol by apache.
the class SPARQLAdpterTest method test.
@SuppressWarnings("unchecked")
@Test
public void test() {
try {
List<SPARQLObject> sparqlObjects = (List<SPARQLObject>) ruleAdapter.adaptTo(recipeGood, SPARQLObject.class);
for (SPARQLObject sparqlObject : sparqlObjects) {
log.debug(sparqlObject.getObject());
}
Assert.assertTrue(true);
} catch (UnavailableRuleObjectException e) {
Assert.fail(e.getMessage());
} catch (UnsupportedTypeForExportException e) {
Assert.fail(e.getMessage());
} catch (RuleAtomCallExeption e) {
Assert.fail(e.getMessage());
}
}
use of org.apache.stanbol.rules.base.api.SPARQLObject in project stanbol by apache.
the class MultiplicationAtom method adapt.
@SuppressWarnings("unchecked")
@Override
public <T> T adapt(RuleAtom ruleAtom) throws RuleAtomCallExeption, UnavailableRuleObjectException, UnsupportedTypeForExportException {
org.apache.stanbol.rules.manager.atoms.MultiplicationAtom tmp = (org.apache.stanbol.rules.manager.atoms.MultiplicationAtom) ruleAtom;
NumericFunctionAtom argument1 = tmp.getNumericFunctionAtom1();
NumericFunctionAtom argument2 = tmp.getNumericFunctionAtom2();
SPARQLObject sparqlArgument1 = adapter.adaptTo(argument1, SPARQLObject.class);
SPARQLObject sparqlArgument2 = adapter.adaptTo(argument2, SPARQLObject.class);
String sparqlFunction1 = sparqlArgument1.getObject();
String sparqlFunction2 = sparqlArgument2.getObject();
StringBuilder sb = new StringBuilder();
sb.append("(");
sb.append(sparqlFunction1);
sb.append(" * ");
sb.append(sparqlFunction2);
sb.append(")");
return (T) new SPARQLComparison(sb.toString());
}
use of org.apache.stanbol.rules.base.api.SPARQLObject in project stanbol by apache.
the class NamespaceAtom method adapt.
@SuppressWarnings("unchecked")
@Override
public <T> T adapt(RuleAtom ruleAtom) throws RuleAtomCallExeption, UnavailableRuleObjectException, UnsupportedTypeForExportException {
org.apache.stanbol.rules.manager.atoms.NamespaceAtom tmp = (org.apache.stanbol.rules.manager.atoms.NamespaceAtom) ruleAtom;
IObjectAtom argument = tmp.getUriResource();
SPARQLObject sparqlObject = adapter.adaptTo(argument, SPARQLObject.class);
String sparql = "<http://jena.hpl.hp.com/ARQ/function#namespace>(" + sparqlObject.getObject() + ")";
return (T) new SPARQLFunction(sparql);
}
Aggregations