Search in sources :

Example 6 with SWRLDArgument

use of org.semanticweb.owlapi.model.SWRLDArgument in project stanbol by apache.

the class LessThanAtom method adapt.

@SuppressWarnings("unchecked")
@Override
public <T> T adapt(RuleAtom ruleAtom) throws RuleAtomCallExeption, UnavailableRuleObjectException, UnsupportedTypeForExportException {
    org.apache.stanbol.rules.manager.atoms.LessThanAtom tmp = (org.apache.stanbol.rules.manager.atoms.LessThanAtom) ruleAtom;
    ExpressionAtom argument1 = tmp.getArgument1();
    ExpressionAtom argument2 = tmp.getArgument2();
    OWLDataFactory factory = OWLManager.getOWLDataFactory();
    SWRLAtom swrlAtom1 = (SWRLAtom) adapter.adaptTo(argument1, SWRLRule.class);
    SWRLAtom swrlAtom2 = (SWRLAtom) adapter.adaptTo(argument2, SWRLRule.class);
    SWRLDArgument swrldArgument1;
    SWRLDArgument swrldArgument2;
    List<SWRLAtom> listOfArguments = new ArrayList<SWRLAtom>();
    if (swrlAtom1 instanceof HigherOrderSWRLAtom) {
        swrldArgument1 = ((HigherOrderSWRLAtom) swrlAtom1).getBindableArgument();
        listOfArguments.addAll(((HigherOrderSWRLAtom) swrlAtom1).getAtoms());
    } else if (swrlAtom1 instanceof ArgumentSWRLAtom) {
        SWRLArgument swrlArgument = ((ArgumentSWRLAtom) swrlAtom1).getSwrlArgument();
        swrldArgument1 = (SWRLDArgument) swrlArgument;
    } else {
        throw new org.apache.stanbol.rules.base.api.RuleAtomCallExeption(getClass());
    }
    if (swrlAtom2 instanceof HigherOrderSWRLAtom) {
        swrldArgument2 = ((HigherOrderSWRLAtom) swrlAtom2).getBindableArgument();
        listOfArguments.addAll(((HigherOrderSWRLAtom) swrlAtom2).getAtoms());
    } else if (swrlAtom2 instanceof ArgumentSWRLAtom) {
        SWRLArgument swrlArgument = ((ArgumentSWRLAtom) swrlAtom2).getSwrlArgument();
        swrldArgument2 = (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);
    SWRLBuiltInAtom swrlBuiltInAtom = factory.getSWRLBuiltInAtom(SWRLBuiltInsVocabulary.LESS_THAN.getIRI(), swrldArguments);
    return (T) swrlBuiltInAtom;
}
Also used : ArrayList(java.util.ArrayList) ArgumentSWRLAtom(org.apache.stanbol.rules.adapters.swrl.ArgumentSWRLAtom) RuleAtomCallExeption(org.apache.stanbol.rules.base.api.RuleAtomCallExeption) ExpressionAtom(org.apache.stanbol.rules.manager.atoms.ExpressionAtom) HigherOrderSWRLAtom(org.apache.stanbol.rules.adapters.swrl.HigherOrderSWRLAtom) SWRLDArgument(org.semanticweb.owlapi.model.SWRLDArgument) SWRLAtom(org.semanticweb.owlapi.model.SWRLAtom) ArgumentSWRLAtom(org.apache.stanbol.rules.adapters.swrl.ArgumentSWRLAtom) HigherOrderSWRLAtom(org.apache.stanbol.rules.adapters.swrl.HigherOrderSWRLAtom) SWRLBuiltInAtom(org.semanticweb.owlapi.model.SWRLBuiltInAtom) SWRLRule(org.semanticweb.owlapi.model.SWRLRule) SWRLArgument(org.semanticweb.owlapi.model.SWRLArgument) OWLDataFactory(org.semanticweb.owlapi.model.OWLDataFactory)

Example 7 with SWRLDArgument

use of org.semanticweb.owlapi.model.SWRLDArgument in project stanbol by apache.

the class LowerCaseAtom method adapt.

@SuppressWarnings("unchecked")
@Override
public <T> T adapt(RuleAtom ruleAtom) throws RuleAtomCallExeption, UnavailableRuleObjectException, UnsupportedTypeForExportException {
    String lowercase_result = "lowercase_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 + lowercase_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.LOWER_CASE.getIRI(), swrldArguments);
}
Also used : ArrayList(java.util.ArrayList) ArgumentSWRLAtom(org.apache.stanbol.rules.adapters.swrl.ArgumentSWRLAtom) RuleAtomCallExeption(org.apache.stanbol.rules.base.api.RuleAtomCallExeption) HigherOrderSWRLAtom(org.apache.stanbol.rules.adapters.swrl.HigherOrderSWRLAtom) StringFunctionAtom(org.apache.stanbol.rules.manager.atoms.StringFunctionAtom) SWRLDArgument(org.semanticweb.owlapi.model.SWRLDArgument) SWRLAtom(org.semanticweb.owlapi.model.SWRLAtom) ArgumentSWRLAtom(org.apache.stanbol.rules.adapters.swrl.ArgumentSWRLAtom) HigherOrderSWRLAtom(org.apache.stanbol.rules.adapters.swrl.HigherOrderSWRLAtom) SWRLRule(org.semanticweb.owlapi.model.SWRLRule) SWRLArgument(org.semanticweb.owlapi.model.SWRLArgument) OWLDataFactory(org.semanticweb.owlapi.model.OWLDataFactory)

Example 8 with SWRLDArgument

use of org.semanticweb.owlapi.model.SWRLDArgument 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);
}
Also used : ArgumentSWRLAtom(org.apache.stanbol.rules.adapters.swrl.ArgumentSWRLAtom) SWRLDArgument(org.semanticweb.owlapi.model.SWRLDArgument) OWLDataFactory(org.semanticweb.owlapi.model.OWLDataFactory)

Example 9 with SWRLDArgument

use of org.semanticweb.owlapi.model.SWRLDArgument in project stanbol by apache.

the class NumericVariableAtom method adapt.

@SuppressWarnings("unchecked")
@Override
public <T> T adapt(RuleAtom ruleAtom) throws RuleAtomCallExeption {
    org.apache.stanbol.rules.manager.atoms.NumericVariableAtom tmp = (org.apache.stanbol.rules.manager.atoms.NumericVariableAtom) ruleAtom;
    URI uri = tmp.getURI();
    return (T) new ArgumentSWRLAtom((SWRLDArgument) OWLManager.getOWLDataFactory().getSWRLVariable(IRI.create(uri.toString())), uri.toString());
}
Also used : SWRLDArgument(org.semanticweb.owlapi.model.SWRLDArgument) ArgumentSWRLAtom(org.apache.stanbol.rules.adapters.swrl.ArgumentSWRLAtom) URI(java.net.URI)

Example 10 with SWRLDArgument

use of org.semanticweb.owlapi.model.SWRLDArgument in project stanbol by apache.

the class SameAtom method adapt.

@SuppressWarnings("unchecked")
@Override
public <T> T adapt(RuleAtom ruleAtom) throws RuleAtomCallExeption, UnavailableRuleObjectException, UnsupportedTypeForExportException {
    org.apache.stanbol.rules.manager.atoms.SameAtom tmp = (org.apache.stanbol.rules.manager.atoms.SameAtom) ruleAtom;
    ExpressionAtom argument1 = tmp.getStringFunctionAtom1();
    ExpressionAtom argument2 = tmp.getStringFunctionAtom2();
    OWLDataFactory factory = OWLManager.getOWLDataFactory();
    SWRLAtom swrlAtom1 = (SWRLAtom) adapter.adaptTo(argument1, SWRLRule.class);
    SWRLAtom swrlAtom2 = (SWRLAtom) adapter.adaptTo(argument2, SWRLRule.class);
    SWRLDArgument swrldArgument1;
    SWRLDArgument swrldArgument2;
    List<SWRLAtom> listOfArguments = new ArrayList<SWRLAtom>();
    if (swrlAtom1 instanceof HigherOrderSWRLAtom) {
        swrldArgument1 = ((HigherOrderSWRLAtom) swrlAtom1).getBindableArgument();
        listOfArguments.addAll(((HigherOrderSWRLAtom) swrlAtom1).getAtoms());
    } else if (swrlAtom1 instanceof ArgumentSWRLAtom) {
        SWRLArgument swrlArgument = ((ArgumentSWRLAtom) swrlAtom1).getSwrlArgument();
        swrldArgument1 = (SWRLDArgument) swrlArgument;
    } else {
        throw new org.apache.stanbol.rules.base.api.RuleAtomCallExeption(getClass());
    }
    if (swrlAtom2 instanceof HigherOrderSWRLAtom) {
        swrldArgument2 = ((HigherOrderSWRLAtom) swrlAtom2).getBindableArgument();
        listOfArguments.addAll(((HigherOrderSWRLAtom) swrlAtom2).getAtoms());
    } else if (swrlAtom2 instanceof ArgumentSWRLAtom) {
        SWRLArgument swrlArgument = ((ArgumentSWRLAtom) swrlAtom2).getSwrlArgument();
        swrldArgument2 = (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);
    SWRLBuiltInAtom swrlBuiltInAtom = factory.getSWRLBuiltInAtom(SWRLBuiltInsVocabulary.EQUAL.getIRI(), swrldArguments);
    return (T) swrlBuiltInAtom;
}
Also used : ArrayList(java.util.ArrayList) ArgumentSWRLAtom(org.apache.stanbol.rules.adapters.swrl.ArgumentSWRLAtom) RuleAtomCallExeption(org.apache.stanbol.rules.base.api.RuleAtomCallExeption) ExpressionAtom(org.apache.stanbol.rules.manager.atoms.ExpressionAtom) HigherOrderSWRLAtom(org.apache.stanbol.rules.adapters.swrl.HigherOrderSWRLAtom) SWRLDArgument(org.semanticweb.owlapi.model.SWRLDArgument) SWRLAtom(org.semanticweb.owlapi.model.SWRLAtom) ArgumentSWRLAtom(org.apache.stanbol.rules.adapters.swrl.ArgumentSWRLAtom) HigherOrderSWRLAtom(org.apache.stanbol.rules.adapters.swrl.HigherOrderSWRLAtom) SWRLBuiltInAtom(org.semanticweb.owlapi.model.SWRLBuiltInAtom) SWRLRule(org.semanticweb.owlapi.model.SWRLRule) SWRLArgument(org.semanticweb.owlapi.model.SWRLArgument) OWLDataFactory(org.semanticweb.owlapi.model.OWLDataFactory)

Aggregations

ArgumentSWRLAtom (org.apache.stanbol.rules.adapters.swrl.ArgumentSWRLAtom)17 SWRLDArgument (org.semanticweb.owlapi.model.SWRLDArgument)17 OWLDataFactory (org.semanticweb.owlapi.model.OWLDataFactory)15 RuleAtomCallExeption (org.apache.stanbol.rules.base.api.RuleAtomCallExeption)13 SWRLAtom (org.semanticweb.owlapi.model.SWRLAtom)13 SWRLRule (org.semanticweb.owlapi.model.SWRLRule)13 ArrayList (java.util.ArrayList)12 HigherOrderSWRLAtom (org.apache.stanbol.rules.adapters.swrl.HigherOrderSWRLAtom)12 SWRLArgument (org.semanticweb.owlapi.model.SWRLArgument)12 ExpressionAtom (org.apache.stanbol.rules.manager.atoms.ExpressionAtom)9 SWRLBuiltInAtom (org.semanticweb.owlapi.model.SWRLBuiltInAtom)8 StringFunctionAtom (org.apache.stanbol.rules.manager.atoms.StringFunctionAtom)3 URI (java.net.URI)2 RuleAtom (org.apache.stanbol.rules.base.api.RuleAtom)1 IObjectAtom (org.apache.stanbol.rules.manager.atoms.IObjectAtom)1 NumericFunctionAtom (org.apache.stanbol.rules.manager.atoms.NumericFunctionAtom)1 OWLDataProperty (org.semanticweb.owlapi.model.OWLDataProperty)1 SWRLIArgument (org.semanticweb.owlapi.model.SWRLIArgument)1