Search in sources :

Example 1 with LiteralExpression

use of org.apache.clerezza.rdf.core.sparql.query.LiteralExpression in project stanbol by apache.

the class DatavaluedPropertyAtom method adapt.

@SuppressWarnings("unchecked")
@Override
public <T> T adapt(RuleAtom ruleAtom) throws RuleAtomCallExeption, UnavailableRuleObjectException, UnsupportedTypeForExportException {
    org.apache.stanbol.rules.manager.atoms.DatavaluedPropertyAtom tmp = (org.apache.stanbol.rules.manager.atoms.DatavaluedPropertyAtom) ruleAtom;
    IObjectAtom argument1 = tmp.getArgument1();
    IObjectAtom datatypeProperty = tmp.getDatatypeProperty();
    RuleAtom argument2 = tmp.getArgument2();
    ClerezzaSparqlObject argument1CSO = (ClerezzaSparqlObject) adapter.adaptTo(argument1, ConstructQuery.class);
    ClerezzaSparqlObject datatypePropertyCSO = (ClerezzaSparqlObject) adapter.adaptTo(datatypeProperty, ConstructQuery.class);
    ClerezzaSparqlObject argument2CSO = (ClerezzaSparqlObject) adapter.adaptTo(argument2, ConstructQuery.class);
    Object arg1 = argument1CSO.getClerezzaObject();
    Object dt = datatypePropertyCSO.getClerezzaObject();
    Object arg2 = argument2CSO.getClerezzaObject();
    UriRefOrVariable subject;
    UriRefOrVariable predicate;
    ResourceOrVariable object;
    if (arg1 instanceof Variable) {
        subject = new UriRefOrVariable((Variable) arg1);
    } else if (arg1 instanceof IRI) {
        subject = new UriRefOrVariable((IRI) arg1);
    } else {
        throw new RuleAtomCallExeption(getClass());
    }
    if (dt instanceof Variable) {
        predicate = new UriRefOrVariable((Variable) dt);
    } else if (dt instanceof IRI) {
        predicate = new UriRefOrVariable((IRI) dt);
    } else {
        throw new RuleAtomCallExeption(getClass());
    }
    if (arg2 instanceof Variable) {
        object = new ResourceOrVariable((Variable) arg2);
    } else if (arg2 instanceof LiteralExpression) {
        object = new ResourceOrVariable(((LiteralExpression) arg2).getLiteral());
    } else {
        throw new RuleAtomCallExeption(getClass());
    }
    return (T) new ClerezzaSparqlObject(new SimpleTriplePattern(subject, predicate, object));
}
Also used : IRI(org.apache.clerezza.commons.rdf.IRI) ResourceOrVariable(org.apache.clerezza.rdf.core.sparql.query.ResourceOrVariable) Variable(org.apache.clerezza.rdf.core.sparql.query.Variable) UriRefOrVariable(org.apache.clerezza.rdf.core.sparql.query.UriRefOrVariable) ResourceOrVariable(org.apache.clerezza.rdf.core.sparql.query.ResourceOrVariable) LiteralExpression(org.apache.clerezza.rdf.core.sparql.query.LiteralExpression) UriRefOrVariable(org.apache.clerezza.rdf.core.sparql.query.UriRefOrVariable) IObjectAtom(org.apache.stanbol.rules.manager.atoms.IObjectAtom) ConstructQuery(org.apache.clerezza.rdf.core.sparql.query.ConstructQuery) ClerezzaSparqlObject(org.apache.stanbol.rules.adapters.clerezza.ClerezzaSparqlObject) SimpleTriplePattern(org.apache.clerezza.rdf.core.sparql.query.impl.SimpleTriplePattern) ClerezzaSparqlObject(org.apache.stanbol.rules.adapters.clerezza.ClerezzaSparqlObject) RuleAtomCallExeption(org.apache.stanbol.rules.base.api.RuleAtomCallExeption) RuleAtom(org.apache.stanbol.rules.base.api.RuleAtom)

Example 2 with LiteralExpression

use of org.apache.clerezza.rdf.core.sparql.query.LiteralExpression 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();
    Expression exp = null;
    if (number.startsWith("\"") && number.endsWith("\"")) {
        number = number.substring(1, number.length() - 1);
    }
    if (number.startsWith(Symbols.variablesPrefix)) {
        exp = new Variable(number.replace(Symbols.variablesPrefix, ""));
    } else {
        exp = new LiteralExpression(LiteralFactory.getInstance().createTypedLiteral(number));
    }
    return (T) new ClerezzaSparqlObject(exp);
}
Also used : Variable(org.apache.clerezza.rdf.core.sparql.query.Variable) LiteralExpression(org.apache.clerezza.rdf.core.sparql.query.LiteralExpression) Expression(org.apache.clerezza.rdf.core.sparql.query.Expression) LiteralExpression(org.apache.clerezza.rdf.core.sparql.query.LiteralExpression) ClerezzaSparqlObject(org.apache.stanbol.rules.adapters.clerezza.ClerezzaSparqlObject)

Example 3 with LiteralExpression

use of org.apache.clerezza.rdf.core.sparql.query.LiteralExpression in project stanbol by apache.

the class StringAtom method adapt.

@SuppressWarnings("unchecked")
@Override
public <T> T adapt(RuleAtom ruleAtom) throws RuleAtomCallExeption {
    org.apache.stanbol.rules.manager.atoms.StringAtom tmp = (org.apache.stanbol.rules.manager.atoms.StringAtom) ruleAtom;
    String string = tmp.getString();
    Expression exp = null;
    if (string.startsWith("\"") && string.endsWith("\"")) {
        string = string.substring(1, string.length() - 1);
    }
    if (string.startsWith(Symbols.variablesPrefix)) {
        exp = new Variable(string.replace(Symbols.variablesPrefix, ""));
    } else {
        exp = new LiteralExpression(new PlainLiteralImpl(string));
    }
    return (T) new ClerezzaSparqlObject(exp);
}
Also used : Variable(org.apache.clerezza.rdf.core.sparql.query.Variable) PlainLiteralImpl(org.apache.clerezza.commons.rdf.impl.utils.PlainLiteralImpl) LiteralExpression(org.apache.clerezza.rdf.core.sparql.query.LiteralExpression) Expression(org.apache.clerezza.rdf.core.sparql.query.Expression) LiteralExpression(org.apache.clerezza.rdf.core.sparql.query.LiteralExpression) ClerezzaSparqlObject(org.apache.stanbol.rules.adapters.clerezza.ClerezzaSparqlObject)

Example 4 with LiteralExpression

use of org.apache.clerezza.rdf.core.sparql.query.LiteralExpression in project stanbol by apache.

the class TypedLiteralAtom method adapt.

@SuppressWarnings("unchecked")
@Override
public <T> T adapt(RuleAtom ruleAtom) throws RuleAtomCallExeption {
    org.apache.stanbol.rules.manager.atoms.TypedLiteralAtom tmp = (org.apache.stanbol.rules.manager.atoms.TypedLiteralAtom) ruleAtom;
    ExpressionAtom expressionAtom = tmp.getValue();
    Literal literal = null;
    if (expressionAtom instanceof StringAtom) {
        String value = expressionAtom.toString();
        literal = LiteralFactory.getInstance().createTypedLiteral(value);
    } else if (expressionAtom instanceof NumberAtom) {
        Number number = ((NumberAtom) expressionAtom).getNumberValue();
        literal = LiteralFactory.getInstance().createTypedLiteral(number);
    } else {
        throw new org.apache.stanbol.rules.base.api.RuleAtomCallExeption(getClass());
    }
    LiteralExpression literalExpression = new LiteralExpression(literal);
    return (T) new ClerezzaSparqlObject(literalExpression);
}
Also used : StringAtom(org.apache.stanbol.rules.manager.atoms.StringAtom) LiteralExpression(org.apache.clerezza.rdf.core.sparql.query.LiteralExpression) RuleAtomCallExeption(org.apache.stanbol.rules.base.api.RuleAtomCallExeption) ExpressionAtom(org.apache.stanbol.rules.manager.atoms.ExpressionAtom) NumberAtom(org.apache.stanbol.rules.manager.atoms.NumberAtom) Literal(org.apache.clerezza.commons.rdf.Literal) ClerezzaSparqlObject(org.apache.stanbol.rules.adapters.clerezza.ClerezzaSparqlObject)

Aggregations

LiteralExpression (org.apache.clerezza.rdf.core.sparql.query.LiteralExpression)4 ClerezzaSparqlObject (org.apache.stanbol.rules.adapters.clerezza.ClerezzaSparqlObject)4 Variable (org.apache.clerezza.rdf.core.sparql.query.Variable)3 Expression (org.apache.clerezza.rdf.core.sparql.query.Expression)2 RuleAtomCallExeption (org.apache.stanbol.rules.base.api.RuleAtomCallExeption)2 IRI (org.apache.clerezza.commons.rdf.IRI)1 Literal (org.apache.clerezza.commons.rdf.Literal)1 PlainLiteralImpl (org.apache.clerezza.commons.rdf.impl.utils.PlainLiteralImpl)1 ConstructQuery (org.apache.clerezza.rdf.core.sparql.query.ConstructQuery)1 ResourceOrVariable (org.apache.clerezza.rdf.core.sparql.query.ResourceOrVariable)1 UriRefOrVariable (org.apache.clerezza.rdf.core.sparql.query.UriRefOrVariable)1 SimpleTriplePattern (org.apache.clerezza.rdf.core.sparql.query.impl.SimpleTriplePattern)1 RuleAtom (org.apache.stanbol.rules.base.api.RuleAtom)1 ExpressionAtom (org.apache.stanbol.rules.manager.atoms.ExpressionAtom)1 IObjectAtom (org.apache.stanbol.rules.manager.atoms.IObjectAtom)1 NumberAtom (org.apache.stanbol.rules.manager.atoms.NumberAtom)1 StringAtom (org.apache.stanbol.rules.manager.atoms.StringAtom)1