use of org.apache.stanbol.rules.adapters.sparql.SPARQLComparison in project stanbol by apache.
the class MultiplicationAtom method adapt.
@SuppressWarnings("unchecked")
@Override
public <T> T adapt(RuleAtom ruleAtom) throws RuleAtomCallExeption, UnavailableRuleObjectException, UnsupportedTypeForExportException {
org.apache.stanbol.rules.manager.atoms.MultiplicationAtom tmp = (org.apache.stanbol.rules.manager.atoms.MultiplicationAtom) ruleAtom;
NumericFunctionAtom argument1 = tmp.getNumericFunctionAtom1();
NumericFunctionAtom argument2 = tmp.getNumericFunctionAtom2();
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());
}
use of org.apache.stanbol.rules.adapters.sparql.SPARQLComparison in project stanbol by apache.
the class SameAtom method adapt.
@SuppressWarnings("unchecked")
@Override
public <T> T adapt(RuleAtom ruleAtom) throws RuleAtomCallExeption {
org.apache.stanbol.rules.manager.atoms.SameAtom tmp = (org.apache.stanbol.rules.manager.atoms.SameAtom) ruleAtom;
ExpressionAtom argument1 = tmp.getStringFunctionAtom1();
ExpressionAtom argument2 = tmp.getStringFunctionAtom2();
try {
SPARQLObject sparqlArgument1 = adapter.adaptTo(argument1, SPARQLObject.class);
SPARQLObject sparqlArgument2 = adapter.adaptTo(argument2, SPARQLObject.class);
;
String arg1 = sparqlArgument1.getObject();
String arg2 = sparqlArgument2.getObject();
StringBuilder sb = new StringBuilder();
sb.append("(");
sb.append(arg1);
sb.append(" = ");
sb.append(arg2);
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());
}
}
use of org.apache.stanbol.rules.adapters.sparql.SPARQLComparison in project stanbol by apache.
the class SubtractionAtom method adapt.
@SuppressWarnings("unchecked")
@Override
public <T> T adapt(RuleAtom ruleAtom) throws RuleAtomCallExeption {
org.apache.stanbol.rules.manager.atoms.SubtractionAtom tmp = (org.apache.stanbol.rules.manager.atoms.SubtractionAtom) 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());
}
}
use of org.apache.stanbol.rules.adapters.sparql.SPARQLComparison in project stanbol by apache.
the class NotAtom method adapt.
@SuppressWarnings("unchecked")
@Override
public <T> T adapt(RuleAtom ruleAtom) throws RuleAtomCallExeption {
org.apache.stanbol.rules.manager.atoms.NotAtom tmp = (org.apache.stanbol.rules.manager.atoms.NotAtom) ruleAtom;
SPARQLObject sparqlObject;
try {
sparqlObject = adapter.adaptTo(tmp.getComparisonAtom(), SPARQLObject.class);
String sparqlAtom = "!" + sparqlObject.getObject();
return (T) new SPARQLComparison(sparqlAtom);
} 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());
}
}
use of org.apache.stanbol.rules.adapters.sparql.SPARQLComparison in project stanbol by apache.
the class DifferentAtom method adapt.
@SuppressWarnings("unchecked")
@Override
public <T> T adapt(RuleAtom ruleAtom) throws RuleAtomCallExeption, UnavailableRuleObjectException, UnsupportedTypeForExportException {
org.apache.stanbol.rules.manager.atoms.DifferentAtom tmp = (org.apache.stanbol.rules.manager.atoms.DifferentAtom) ruleAtom;
ExpressionAtom expressionAtom1 = tmp.getStringFunctionAtom1();
ExpressionAtom expressionAtom2 = tmp.getStringFunctionAtom2();
SPARQLObject sparqlArgument1 = adapter.adaptTo(expressionAtom1, SPARQLObject.class);
SPARQLObject sparqlArgument2 = adapter.adaptTo(expressionAtom2, SPARQLObject.class);
String argument1 = sparqlArgument1.getObject();
String argument2 = sparqlArgument2.getObject();
argument1 = argument1.replace(Symbols.variablesPrefix, "");
argument2 = argument2.replace(Symbols.variablesPrefix, "");
StringBuilder sb = new StringBuilder();
sb.append("(");
sb.append(argument1);
sb.append("!=");
sb.append(argument2);
sb.append(")");
return (T) new SPARQLComparison(sb.toString());
}
Aggregations