use of org.apache.stanbol.rules.manager.atoms.NumericFunctionAtom in project stanbol by apache.
the class RuleParserImpl method multiplicationAtom.
public final MultiplicationAtom multiplicationAtom() throws ParseException {
NumericFunctionAtom numericFunctionAtom1;
NumericFunctionAtom numericFunctionAtom2;
jj_consume_token(MULTIPLIED);
jj_consume_token(LPAR);
numericFunctionAtom1 = numericFunctionAtom();
jj_consume_token(COMMA);
numericFunctionAtom2 = numericFunctionAtom();
jj_consume_token(RPAR);
{
if (true)
return new MultiplicationAtom(numericFunctionAtom1, numericFunctionAtom2);
}
throw new Error("Missing return statement in function");
}
use of org.apache.stanbol.rules.manager.atoms.NumericFunctionAtom in project stanbol by apache.
the class RuleParserImpl method numericFunctionAtom.
public final NumericFunctionAtom numericFunctionAtom() throws ParseException {
NumericFunctionAtom numericFunctionAtom;
switch((jj_ntk == -1) ? jj_ntk() : jj_ntk) {
case PLUS:
numericFunctionAtom = sumAtom();
break;
case MINUS:
numericFunctionAtom = subtractionAtom();
break;
case LENGTH:
numericFunctionAtom = lengthAtom();
break;
case NUM:
numericFunctionAtom = numberAtom();
break;
case VARIABLE:
numericFunctionAtom = numericVariable();
break;
default:
jj_la1[7] = jj_gen;
jj_consume_token(-1);
throw new ParseException();
}
{
if (true)
return numericFunctionAtom;
}
throw new Error("Missing return statement in function");
}
use of org.apache.stanbol.rules.manager.atoms.NumericFunctionAtom in project stanbol by apache.
the class RuleParserImpl method subtractionAtom.
public final SubtractionAtom subtractionAtom() throws ParseException {
NumericFunctionAtom numericFunctionAtom1;
NumericFunctionAtom numericFunctionAtom2;
jj_consume_token(MINUS);
jj_consume_token(LPAR);
numericFunctionAtom1 = numericFunctionAtom();
jj_consume_token(COMMA);
numericFunctionAtom2 = numericFunctionAtom();
jj_consume_token(RPAR);
{
if (true)
return new SubtractionAtom(numericFunctionAtom1, numericFunctionAtom2);
}
throw new Error("Missing return statement in function");
}
use of org.apache.stanbol.rules.manager.atoms.NumericFunctionAtom in project stanbol by apache.
the class SubstringAtom method adapt.
@SuppressWarnings("unchecked")
@Override
public <T> T adapt(RuleAtom ruleAtom) throws RuleAtomCallExeption, UnavailableRuleObjectException, UnsupportedTypeForExportException {
String substring_result = "substrig_result" + System.currentTimeMillis();
org.apache.stanbol.rules.manager.atoms.SubstringAtom tmp = (org.apache.stanbol.rules.manager.atoms.SubstringAtom) ruleAtom;
StringFunctionAtom stringFunction = tmp.getStringFunctionAtom();
NumericFunctionAtom start = tmp.getStart();
NumericFunctionAtom length = tmp.getLength();
OWLDataFactory factory = OWLManager.getOWLDataFactory();
SWRLAtom stringFunctionAtom = (SWRLAtom) adapter.adaptTo(stringFunction, SWRLRule.class);
SWRLAtom startAtom = (SWRLAtom) adapter.adaptTo(start, SWRLRule.class);
SWRLAtom lengthAtom = (SWRLAtom) adapter.adaptTo(length, SWRLRule.class);
SWRLDArgument retArgument = factory.getSWRLVariable(IRI.create(Symbols.variablesPrefix + substring_result));
;
SWRLDArgument stringArgument;
SWRLDArgument startArgument;
SWRLDArgument lengthArgument;
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());
}
if (startAtom instanceof HigherOrderSWRLAtom) {
startArgument = ((HigherOrderSWRLAtom) startAtom).getBindableArgument();
listOfArguments.addAll(((HigherOrderSWRLAtom) startAtom).getAtoms());
} else if (startAtom instanceof ArgumentSWRLAtom) {
SWRLArgument swrlArgument = ((ArgumentSWRLAtom) startAtom).getSwrlArgument();
startArgument = (SWRLDArgument) swrlArgument;
} else {
throw new org.apache.stanbol.rules.base.api.RuleAtomCallExeption(getClass());
}
if (lengthAtom instanceof HigherOrderSWRLAtom) {
lengthArgument = ((HigherOrderSWRLAtom) lengthAtom).getBindableArgument();
listOfArguments.addAll(((HigherOrderSWRLAtom) lengthAtom).getAtoms());
} else if (lengthAtom instanceof ArgumentSWRLAtom) {
SWRLArgument swrlArgument = ((ArgumentSWRLAtom) lengthAtom).getSwrlArgument();
lengthArgument = (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);
swrldArguments.add(startArgument);
swrldArguments.add(lengthArgument);
return (T) factory.getSWRLBuiltInAtom(SWRLBuiltInsVocabulary.SUBSTRING.getIRI(), swrldArguments);
}
use of org.apache.stanbol.rules.manager.atoms.NumericFunctionAtom in project stanbol by apache.
the class SumAtom method adapt.
@SuppressWarnings("unchecked")
@Override
public <T> T adapt(RuleAtom ruleAtom) throws RuleAtomCallExeption {
org.apache.stanbol.rules.manager.atoms.SumAtom tmp = (org.apache.stanbol.rules.manager.atoms.SumAtom) ruleAtom;
NumericFunctionAtom argument1 = tmp.getNumericFunctionAtom1();
NumericFunctionAtom argument2 = tmp.getNumericFunctionAtom2();
try {
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());
} 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());
}
}
Aggregations