use of org.apache.stanbol.rules.adapters.swrl.ArgumentSWRLAtom in project stanbol by apache.
the class SubtractionAtom method adapt.
@SuppressWarnings("unchecked")
@Override
public <T> T adapt(RuleAtom ruleAtom) throws RuleAtomCallExeption, UnavailableRuleObjectException, UnsupportedTypeForExportException {
String mul_result = "subtraction_result" + System.currentTimeMillis();
org.apache.stanbol.rules.manager.atoms.SubtractionAtom tmp = (org.apache.stanbol.rules.manager.atoms.SubtractionAtom) ruleAtom;
ExpressionAtom argument1 = tmp.getNumericFunctionAtom1();
ExpressionAtom argument2 = tmp.getNumericFunctionAtom2();
OWLDataFactory factory = OWLManager.getOWLDataFactory();
SWRLAtom swrlAtom1 = (SWRLAtom) adapter.adaptTo(argument1, SWRLRule.class);
SWRLAtom swrlAtom2 = (SWRLAtom) adapter.adaptTo(argument2, SWRLRule.class);
SWRLDArgument swrldArgument1 = factory.getSWRLVariable(IRI.create(Symbols.variablesPrefix + mul_result));
SWRLDArgument swrldArgument2;
SWRLDArgument swrldArgument3;
List<SWRLAtom> listOfArguments = new ArrayList<SWRLAtom>();
if (swrlAtom1 instanceof HigherOrderSWRLAtom) {
swrldArgument2 = ((HigherOrderSWRLAtom) swrlAtom1).getBindableArgument();
listOfArguments.addAll(((HigherOrderSWRLAtom) swrlAtom1).getAtoms());
} else if (swrlAtom1 instanceof ArgumentSWRLAtom) {
SWRLArgument swrlArgument = ((ArgumentSWRLAtom) swrlAtom1).getSwrlArgument();
swrldArgument2 = (SWRLDArgument) swrlArgument;
} else {
throw new org.apache.stanbol.rules.base.api.RuleAtomCallExeption(getClass());
}
if (swrlAtom2 instanceof HigherOrderSWRLAtom) {
swrldArgument3 = ((HigherOrderSWRLAtom) swrlAtom2).getBindableArgument();
listOfArguments.addAll(((HigherOrderSWRLAtom) swrlAtom2).getAtoms());
} else if (swrlAtom2 instanceof ArgumentSWRLAtom) {
SWRLArgument swrlArgument = ((ArgumentSWRLAtom) swrlAtom2).getSwrlArgument();
swrldArgument3 = (SWRLDArgument) swrlArgument;
} else {
throw new org.apache.stanbol.rules.base.api.RuleAtomCallExeption(getClass());
}
List<SWRLDArgument> swrldArguments = new ArrayList<SWRLDArgument>();
swrldArguments.add(swrldArgument1);
swrldArguments.add(swrldArgument2);
swrldArguments.add(swrldArgument3);
SWRLBuiltInAtom swrlBuiltInAtom = factory.getSWRLBuiltInAtom(SWRLBuiltInsVocabulary.SUBTRACT.getIRI(), swrldArguments);
listOfArguments.add(swrlBuiltInAtom);
return (T) new HigherOrderSWRLAtom(swrldArgument1, listOfArguments);
}
use of org.apache.stanbol.rules.adapters.swrl.ArgumentSWRLAtom in project stanbol by apache.
the class UpperCaseAtom method adapt.
@SuppressWarnings("unchecked")
@Override
public <T> T adapt(RuleAtom ruleAtom) throws RuleAtomCallExeption, UnavailableRuleObjectException, UnsupportedTypeForExportException {
String uppercase_result = "uppercase_result" + System.currentTimeMillis();
org.apache.stanbol.rules.manager.atoms.UpperCaseAtom tmp = (org.apache.stanbol.rules.manager.atoms.UpperCaseAtom) ruleAtom;
StringFunctionAtom stringFunction = tmp.getStringFunctionAtom();
OWLDataFactory factory = OWLManager.getOWLDataFactory();
SWRLAtom stringFunctionAtom = (SWRLAtom) adapter.adaptTo(stringFunction, SWRLRule.class);
SWRLDArgument retArgument = factory.getSWRLVariable(IRI.create(Symbols.variablesPrefix + uppercase_result));
;
SWRLDArgument stringArgument;
List<SWRLAtom> listOfArguments = new ArrayList<SWRLAtom>();
if (stringFunctionAtom instanceof HigherOrderSWRLAtom) {
stringArgument = ((HigherOrderSWRLAtom) stringFunctionAtom).getBindableArgument();
listOfArguments.addAll(((HigherOrderSWRLAtom) stringFunctionAtom).getAtoms());
} else if (stringFunctionAtom instanceof ArgumentSWRLAtom) {
SWRLArgument swrlArgument = ((ArgumentSWRLAtom) stringFunctionAtom).getSwrlArgument();
stringArgument = (SWRLDArgument) swrlArgument;
} else {
throw new org.apache.stanbol.rules.base.api.RuleAtomCallExeption(getClass());
}
List<SWRLDArgument> swrldArguments = new ArrayList<SWRLDArgument>();
swrldArguments.add(retArgument);
swrldArguments.add(stringArgument);
return (T) factory.getSWRLBuiltInAtom(SWRLBuiltInsVocabulary.UPPER_CASE.getIRI(), swrldArguments);
}
use of org.apache.stanbol.rules.adapters.swrl.ArgumentSWRLAtom 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();
return (T) new ArgumentSWRLAtom((SWRLIArgument) OWLManager.getOWLDataFactory().getSWRLVariable(IRI.create(uri.toString())), uri.toString());
}
use of org.apache.stanbol.rules.adapters.swrl.ArgumentSWRLAtom in project stanbol by apache.
the class SumAtom method adapt.
@SuppressWarnings("unchecked")
@Override
public <T> T adapt(RuleAtom ruleAtom) throws RuleAtomCallExeption, UnavailableRuleObjectException, UnsupportedTypeForExportException {
String mul_result = "sum_result" + System.currentTimeMillis();
org.apache.stanbol.rules.manager.atoms.SumAtom tmp = (org.apache.stanbol.rules.manager.atoms.SumAtom) ruleAtom;
ExpressionAtom argument1 = tmp.getNumericFunctionAtom1();
ExpressionAtom argument2 = tmp.getNumericFunctionAtom2();
OWLDataFactory factory = OWLManager.getOWLDataFactory();
SWRLAtom swrlAtom1 = (SWRLAtom) adapter.adaptTo(argument1, SWRLRule.class);
SWRLAtom swrlAtom2 = (SWRLAtom) adapter.adaptTo(argument2, SWRLRule.class);
SWRLDArgument swrldArgument1 = factory.getSWRLVariable(IRI.create(Symbols.variablesPrefix + mul_result));
SWRLDArgument swrldArgument2;
SWRLDArgument swrldArgument3;
List<SWRLAtom> listOfArguments = new ArrayList<SWRLAtom>();
if (swrlAtom1 instanceof HigherOrderSWRLAtom) {
swrldArgument2 = ((HigherOrderSWRLAtom) swrlAtom1).getBindableArgument();
listOfArguments.addAll(((HigherOrderSWRLAtom) swrlAtom1).getAtoms());
} else if (swrlAtom1 instanceof ArgumentSWRLAtom) {
SWRLArgument swrlArgument = ((ArgumentSWRLAtom) swrlAtom1).getSwrlArgument();
swrldArgument2 = (SWRLDArgument) swrlArgument;
} else {
throw new org.apache.stanbol.rules.base.api.RuleAtomCallExeption(getClass());
}
if (swrlAtom2 instanceof HigherOrderSWRLAtom) {
swrldArgument3 = ((HigherOrderSWRLAtom) swrlAtom2).getBindableArgument();
listOfArguments.addAll(((HigherOrderSWRLAtom) swrlAtom2).getAtoms());
} else if (swrlAtom2 instanceof ArgumentSWRLAtom) {
SWRLArgument swrlArgument = ((ArgumentSWRLAtom) swrlAtom2).getSwrlArgument();
swrldArgument3 = (SWRLDArgument) swrlArgument;
} else {
throw new org.apache.stanbol.rules.base.api.RuleAtomCallExeption(getClass());
}
List<SWRLDArgument> swrldArguments = new ArrayList<SWRLDArgument>();
swrldArguments.add(swrldArgument1);
swrldArguments.add(swrldArgument2);
swrldArguments.add(swrldArgument3);
SWRLBuiltInAtom swrlBuiltInAtom = factory.getSWRLBuiltInAtom(SWRLBuiltInsVocabulary.ADD.getIRI(), swrldArguments);
listOfArguments.add(swrlBuiltInAtom);
return (T) new HigherOrderSWRLAtom(swrldArgument1, listOfArguments);
}
use of org.apache.stanbol.rules.adapters.swrl.ArgumentSWRLAtom 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();
SWRLDArgument swrldArgument = null;
OWLDataFactory factory = OWLManager.getOWLDataFactory();
if (number.startsWith(Symbols.variablesPrefix)) {
swrldArgument = factory.getSWRLVariable(IRI.create(number));
} else {
Number n = null;
if (number.contains("\\.")) {
int indexOfPoint = number.indexOf('.');
if (indexOfPoint == number.length() - 2) {
n = Float.valueOf(number);
} else {
n = Double.valueOf(number);
}
} else {
n = Integer.valueOf(number);
}
swrldArgument = SWRLLiteralBuilder.getSWRLLiteral(n);
}
return (T) new ArgumentSWRLAtom(swrldArgument, number);
}
Aggregations