use of com.hp.hpl.jena.reasoner.rulesys.Functor in project stanbol by apache.
the class EndsWithAtom 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.EndsWithAtom tmp = (org.apache.stanbol.rules.manager.atoms.EndsWithAtom) ruleAtom;
ExpressionAtom argument = tmp.getArgument();
ExpressionAtom term = tmp.getTerm();
ClauseEntry clauseEntry1 = adapter.adaptTo(argument, Rule.class);
ClauseEntry clauseEntry2 = adapter.adaptTo(term, 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) {
Node tmpNode = ((NodeClauseEntry) clauseEntry2).getNode();
LiteralLabel literalLabel = tmpNode.getLiteral();
String lexicalForm = literalLabel.getLexicalForm();
StringBuilder sb = new StringBuilder();
sb.append(lexicalForm);
sb.append("$");
String regex = sb.toString();
arg2Node = Node_RuleVariable.createLiteral(regex);
} 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);
return (T) new Functor("regex", nodes, BuiltinRegistry.theRegistry);
}
use of com.hp.hpl.jena.reasoner.rulesys.Functor in project stanbol by apache.
the class GreaterThanAtom 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.GreaterThanAtom tmp = (org.apache.stanbol.rules.manager.atoms.GreaterThanAtom) 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);
Builtin f = BuiltinRegistry.theRegistry.getImplementation("greaterThan");
System.out.println("Class: " + f.getClass().getCanonicalName());
System.out.println("Arg1: " + arg1Node.getClass().getCanonicalName());
System.out.println("Arg2: " + arg2Node.getClass().getCanonicalName());
Functor functor = new Functor("greaterThan", nodes, BuiltinRegistry.theRegistry);
clauseEntries.add(functor);
return (T) new HigherOrderClauseEntry(arg1Node, clauseEntries);
}
use of com.hp.hpl.jena.reasoner.rulesys.Functor 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 uriResource = tmp.getUriResource();
ClauseEntry argumentClauseEntry = adapter.adaptTo(uriResource, Rule.class);
Node argNode;
if (argumentClauseEntry instanceof NodeClauseEntry) {
argNode = ((NodeClauseEntry) argumentClauseEntry).getNode();
} else {
throw new RuleAtomCallExeption(getClass());
}
java.util.List<Node> nodes = new ArrayList<Node>();
nodes.add(argNode);
return (T) new Functor("isBlankNode", nodes, BuiltinRegistry.theRegistry);
}
use of com.hp.hpl.jena.reasoner.rulesys.Functor 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);
}
use of com.hp.hpl.jena.reasoner.rulesys.Functor in project stanbol by apache.
the class SameAtom 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.SameAtom tmp = (org.apache.stanbol.rules.manager.atoms.SameAtom) ruleAtom;
ExpressionAtom argument1 = tmp.getStringFunctionAtom1();
ExpressionAtom argument2 = tmp.getStringFunctionAtom2();
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);
return (T) new Functor("equal", nodes, new BuiltinRegistry());
}
Aggregations