use of org.apache.stanbol.rules.base.api.RuleAtomCallExeption in project stanbol by apache.
the class TypedLiteralAtom method adapt.
@SuppressWarnings("unchecked")
@Override
public <T> T adapt(RuleAtom ruleAtom) throws RuleAtomCallExeption {
org.apache.stanbol.rules.manager.atoms.TypedLiteralAtom tmp = (org.apache.stanbol.rules.manager.atoms.TypedLiteralAtom) ruleAtom;
ExpressionAtom expressionAtom = tmp.getValue();
Literal literal = null;
if (expressionAtom instanceof StringAtom) {
String value = expressionAtom.toString();
literal = LiteralFactory.getInstance().createTypedLiteral(value);
} else if (expressionAtom instanceof NumberAtom) {
Number number = ((NumberAtom) expressionAtom).getNumberValue();
literal = LiteralFactory.getInstance().createTypedLiteral(number);
} else {
throw new org.apache.stanbol.rules.base.api.RuleAtomCallExeption(getClass());
}
LiteralExpression literalExpression = new LiteralExpression(literal);
return (T) new ClerezzaSparqlObject(literalExpression);
}
use of org.apache.stanbol.rules.base.api.RuleAtomCallExeption in project stanbol by apache.
the class ClerezzaAdpterTest method wrongAdaptabeClassTest.
@SuppressWarnings("unchecked")
@Test
public void wrongAdaptabeClassTest() {
try {
List<Rule> rules = (List<Rule>) ruleAdapter.adaptTo(recipeGood, Rule.class);
for (Rule rule : rules) {
log.debug(rule.toString());
Assert.fail("The adapter for Clerezza should not accept " + Rule.class.getCanonicalName() + " objects.");
}
} catch (UnavailableRuleObjectException e) {
Assert.fail(e.getMessage());
} catch (UnsupportedTypeForExportException e) {
log.debug(e.getMessage());
} catch (RuleAtomCallExeption e) {
Assert.fail(e.getMessage());
}
}
use of org.apache.stanbol.rules.base.api.RuleAtomCallExeption in project stanbol by apache.
the class ClerezzaAdpterTest method test.
@SuppressWarnings("unchecked")
@Test
public void test() {
try {
List<ConstructQuery> constructQueries = (List<ConstructQuery>) ruleAdapter.adaptTo(recipeGood, ConstructQuery.class);
for (ConstructQuery constructQuery : constructQueries) {
ConstructQuery cq = (ConstructQuery) QueryParser.getInstance().parse(constructQuery.toString());
System.out.println(cq.toString());
}
Assert.assertTrue(true);
} catch (UnavailableRuleObjectException e) {
Assert.fail(e.getMessage());
} catch (UnsupportedTypeForExportException e) {
Assert.fail(e.getMessage());
} catch (RuleAtomCallExeption e) {
Assert.fail(e.getMessage());
} catch (ParseException e) {
Assert.fail(e.getMessage());
}
}
use of org.apache.stanbol.rules.base.api.RuleAtomCallExeption in project stanbol by apache.
the class MultiplicationAtom method adapt.
@SuppressWarnings("unchecked")
@Override
public <T> T adapt(RuleAtom ruleAtom) throws RuleAtomCallExeption, UnavailableRuleObjectException, UnsupportedTypeForExportException {
String div_result = "mul_result" + System.currentTimeMillis();
Node arg1Node = null;
Node arg2Node = null;
Node arg3Node = Node_RuleVariable.createVariable(div_result);
org.apache.stanbol.rules.manager.atoms.MultiplicationAtom tmp = (org.apache.stanbol.rules.manager.atoms.MultiplicationAtom) ruleAtom;
NumericFunctionAtom numericFunctionAtom1 = tmp.getNumericFunctionAtom1();
NumericFunctionAtom numericFunctionAtom2 = tmp.getNumericFunctionAtom2();
ClauseEntry clauseEntry1 = adapter.adaptTo(numericFunctionAtom1, Rule.class);
ClauseEntry clauseEntry2 = adapter.adaptTo(numericFunctionAtom2, Rule.class);
List<ClauseEntry> clauseEntries = new ArrayList<ClauseEntry>();
if (clauseEntry1 instanceof HigherOrderClauseEntry) {
arg1Node = ((HigherOrderClauseEntry) clauseEntry1).getBindableNode();
clauseEntries.addAll(((HigherOrderClauseEntry) clauseEntry1).getClauseEntries());
} else if (clauseEntry1 instanceof NodeClauseEntry) {
arg1Node = ((NodeClauseEntry) clauseEntry1).getNode();
} else {
throw new org.apache.stanbol.rules.base.api.RuleAtomCallExeption(getClass());
}
if (clauseEntry2 instanceof HigherOrderClauseEntry) {
arg2Node = ((HigherOrderClauseEntry) clauseEntry2).getBindableNode();
clauseEntries.addAll(((HigherOrderClauseEntry) clauseEntry2).getClauseEntries());
} else if (clauseEntry2 instanceof NodeClauseEntry) {
arg2Node = ((NodeClauseEntry) clauseEntry2).getNode();
} else {
throw new org.apache.stanbol.rules.base.api.RuleAtomCallExeption(getClass());
}
java.util.List<Node> nodes = new ArrayList<Node>();
nodes.add(arg1Node);
nodes.add(arg2Node);
nodes.add(arg3Node);
ClauseEntry clauseEntry = new Functor("product", nodes, BuiltinRegistry.theRegistry);
clauseEntries.add(clauseEntry);
return (T) new HigherOrderClauseEntry(arg3Node, clauseEntries);
}
use of org.apache.stanbol.rules.base.api.RuleAtomCallExeption in project stanbol by apache.
the class LetAtom method adapt.
@SuppressWarnings("unchecked")
@Override
public <T> T adapt(RuleAtom ruleAtom) throws RuleAtomCallExeption, UnavailableRuleObjectException, UnsupportedTypeForExportException {
org.apache.stanbol.rules.manager.atoms.LetAtom tmp = (org.apache.stanbol.rules.manager.atoms.LetAtom) ruleAtom;
StringFunctionAtom parameterFunctionAtom = tmp.getParameterFunctionAtom();
IObjectAtom variableIObjectAtom = tmp.getVariable();
ClauseEntry parameterClauseEntry = adapter.adaptTo(parameterFunctionAtom, Rule.class);
ClauseEntry variableClauseEntry = adapter.adaptTo(variableIObjectAtom, Rule.class);
List<ClauseEntry> clauseEntries = new ArrayList<ClauseEntry>();
Node parameterNode;
Node variableNode;
if (parameterClauseEntry instanceof HigherOrderClauseEntry) {
parameterNode = ((HigherOrderClauseEntry) parameterClauseEntry).getBindableNode();
clauseEntries.addAll(((HigherOrderClauseEntry) parameterClauseEntry).getClauseEntries());
} else if (parameterClauseEntry instanceof NodeClauseEntry) {
parameterNode = ((NodeClauseEntry) parameterClauseEntry).getNode();
} else {
throw new RuleAtomCallExeption(getClass());
}
if (variableClauseEntry instanceof NodeClauseEntry) {
variableNode = ((NodeClauseEntry) variableClauseEntry).getNode();
} else {
throw new RuleAtomCallExeption(getClass());
}
java.util.List<Node> nodes = new ArrayList<Node>();
nodes.add(variableNode);
nodes.add(parameterNode);
ClauseEntry clauseEntry = new Functor("makeSkolem", nodes, BuiltinRegistry.theRegistry);
clauseEntries.add(clauseEntry);
return (T) new HigherOrderClauseEntry(variableNode, clauseEntries);
}
Aggregations