use of org.apache.stanbol.rules.adapters.jena.NodeClauseEntry in project stanbol by apache.
the class LessThanAtom method adapt.
@SuppressWarnings("unchecked")
@Override
public <T> T adapt(RuleAtom ruleAtom) throws RuleAtomCallExeption, UnavailableRuleObjectException, UnsupportedTypeForExportException {
Node arg1Node = null;
Node arg2Node = null;
org.apache.stanbol.rules.manager.atoms.LessThanAtom tmp = (org.apache.stanbol.rules.manager.atoms.LessThanAtom) ruleAtom;
ExpressionAtom argument1 = tmp.getArgument1();
ExpressionAtom argument2 = tmp.getArgument2();
ClauseEntry clauseEntry1 = adapter.adaptTo(argument1, Rule.class);
ClauseEntry clauseEntry2 = adapter.adaptTo(argument2, 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);
Functor functor = new Functor("lessThan", nodes, BuiltinRegistry.theRegistry);
clauseEntries.add(functor);
return (T) new HigherOrderClauseEntry(arg1Node, clauseEntries);
}
use of org.apache.stanbol.rules.adapters.jena.NodeClauseEntry in project stanbol by apache.
the class NumberAtom method adapt.
@SuppressWarnings("unchecked")
@Override
public <T> T adapt(RuleAtom ruleAtom) throws RuleAtomCallExeption {
org.apache.stanbol.rules.manager.atoms.NumberAtom tmp = (org.apache.stanbol.rules.manager.atoms.NumberAtom) ruleAtom;
String number = tmp.getNumber();
Node node = null;
System.out.println("Number atom " + number);
if (number.startsWith("?")) {
number = number.substring(1);
node = Node_RuleVariable.createVariable(number);
} else {
Number n = null;
if (number.contains("\\.")) {
int indexOfPoint = number.indexOf('.');
if (indexOfPoint == number.length() - 2) {
n = Float.parseFloat(number);
} else {
n = Double.parseDouble(number);
}
} else {
n = Integer.parseInt(number);
}
node = NodeFactory.getTypedLiteral(n);
}
return (T) new NodeClauseEntry(node);
}
use of org.apache.stanbol.rules.adapters.jena.NodeClauseEntry in project stanbol by apache.
the class ResourceAtom method adapt.
@SuppressWarnings("unchecked")
@Override
public <T> T adapt(RuleAtom ruleAtom) throws RuleAtomCallExeption {
org.apache.stanbol.rules.manager.atoms.ResourceAtom tmp = (org.apache.stanbol.rules.manager.atoms.ResourceAtom) ruleAtom;
String unquotedURI = tmp.toUnquotedString();
Node node = Node_RuleVariable.createURI(unquotedURI);
return (T) new NodeClauseEntry(node);
}
use of org.apache.stanbol.rules.adapters.jena.NodeClauseEntry in project stanbol by apache.
the class NumericVariableAtom method adapt.
@SuppressWarnings("unchecked")
@Override
public <T> T adapt(RuleAtom ruleAtom) throws RuleAtomCallExeption {
org.apache.stanbol.rules.manager.atoms.NumericVariableAtom tmp = (org.apache.stanbol.rules.manager.atoms.NumericVariableAtom) ruleAtom;
URI uri = tmp.getURI();
String variable = uri.toString();
variable = variable.replace(Symbols.variablesPrefix, "");
if (variable.startsWith("?")) {
variable = variable.substring(1);
}
Integer index = ((JenaAdapter) adapter).variableMap.get(variable);
if (index == null) {
index = ((JenaAdapter) adapter).variableMap.size();
((JenaAdapter) adapter).variableMap.put(variable, index);
}
Node_RuleVariable ruleVariable = new Node_RuleVariable("?" + variable, index.intValue());
return (T) new NodeClauseEntry(ruleVariable);
}
use of org.apache.stanbol.rules.adapters.jena.NodeClauseEntry in project stanbol by apache.
the class VariableAtom method adapt.
@SuppressWarnings("unchecked")
@Override
public <T> T adapt(RuleAtom ruleAtom) throws RuleAtomCallExeption {
org.apache.stanbol.rules.manager.atoms.VariableAtom tmp = (org.apache.stanbol.rules.manager.atoms.VariableAtom) ruleAtom;
URI uri = tmp.getURI();
String variable = uri.toString();
variable = variable.replace(Symbols.variablesPrefix, "");
if (variable.startsWith("?")) {
variable = variable.substring(1);
}
Integer index = ((JenaAdapter) adapter).variableMap.get(variable);
if (index == null) {
index = ((JenaAdapter) adapter).variableMap.size();
((JenaAdapter) adapter).variableMap.put(variable, index);
}
Node_RuleVariable ruleVariable = new Node_RuleVariable("?" + variable, index.intValue());
return (T) new NodeClauseEntry(ruleVariable);
}
Aggregations