Search in sources :

Example 56 with RuleAtomCallExeption

use of org.apache.stanbol.rules.base.api.RuleAtomCallExeption in project stanbol by apache.

the class IndividualPropertyAtom method adapt.

@SuppressWarnings("unchecked")
@Override
public <T> T adapt(RuleAtom ruleAtom) throws RuleAtomCallExeption, UnsupportedTypeForExportException, UnavailableRuleObjectException {
    org.apache.stanbol.rules.manager.atoms.IndividualPropertyAtom tmp = (org.apache.stanbol.rules.manager.atoms.IndividualPropertyAtom) ruleAtom;
    IObjectAtom argument1 = tmp.getArgument1();
    IObjectAtom argument2 = tmp.getArgument2();
    IObjectAtom objectProperty = tmp.getObjectProperty();
    SWRLAtom predicateAtom = (SWRLAtom) adapter.adaptTo(objectProperty, SWRLRule.class);
    SWRLAtom subjectAtom = (SWRLAtom) adapter.adaptTo(argument1, SWRLRule.class);
    SWRLAtom objectAtom = (SWRLAtom) adapter.adaptTo(argument2, SWRLRule.class);
    OWLDataFactory factory = OWLManager.getOWLDataFactory();
    OWLObjectProperty owlObjectProperty;
    SWRLIArgument swrliArgument1;
    SWRLIArgument swrliArgument2;
    if (predicateAtom instanceof ArgumentSWRLAtom) {
        owlObjectProperty = factory.getOWLObjectProperty(IRI.create(((ArgumentSWRLAtom) predicateAtom).getId()));
    } else {
        throw new RuleAtomCallExeption(getClass());
    }
    if (subjectAtom instanceof ArgumentSWRLAtom) {
        swrliArgument1 = (SWRLIArgument) ((ArgumentSWRLAtom) subjectAtom).getSwrlArgument();
    } else {
        throw new RuleAtomCallExeption(getClass());
    }
    if (objectAtom instanceof ArgumentSWRLAtom) {
        swrliArgument2 = (SWRLIArgument) ((ArgumentSWRLAtom) objectAtom).getSwrlArgument();
    } else {
        throw new RuleAtomCallExeption(getClass());
    }
    return (T) factory.getSWRLObjectPropertyAtom(owlObjectProperty, swrliArgument1, swrliArgument2);
}
Also used : ArgumentSWRLAtom(org.apache.stanbol.rules.adapters.swrl.ArgumentSWRLAtom) OWLObjectProperty(org.semanticweb.owlapi.model.OWLObjectProperty) IObjectAtom(org.apache.stanbol.rules.manager.atoms.IObjectAtom) SWRLIArgument(org.semanticweb.owlapi.model.SWRLIArgument) SWRLAtom(org.semanticweb.owlapi.model.SWRLAtom) ArgumentSWRLAtom(org.apache.stanbol.rules.adapters.swrl.ArgumentSWRLAtom) SWRLRule(org.semanticweb.owlapi.model.SWRLRule) RuleAtomCallExeption(org.apache.stanbol.rules.base.api.RuleAtomCallExeption) OWLDataFactory(org.semanticweb.owlapi.model.OWLDataFactory)

Example 57 with RuleAtomCallExeption

use of org.apache.stanbol.rules.base.api.RuleAtomCallExeption in project stanbol by apache.

the class MultiplicationAtom method adapt.

@SuppressWarnings("unchecked")
@Override
public <T> T adapt(RuleAtom ruleAtom) throws RuleAtomCallExeption, UnavailableRuleObjectException, UnsupportedTypeForExportException {
    String mul_result = "mul_result" + System.currentTimeMillis();
    org.apache.stanbol.rules.manager.atoms.MultiplicationAtom tmp = (org.apache.stanbol.rules.manager.atoms.MultiplicationAtom) 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.MULTIPLY.getIRI(), swrldArguments);
    listOfArguments.add(swrlBuiltInAtom);
    return (T) new HigherOrderSWRLAtom(swrldArgument1, listOfArguments);
}
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 58 with RuleAtomCallExeption

use of org.apache.stanbol.rules.base.api.RuleAtomCallExeption 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);
}
Also used : ArrayList(java.util.ArrayList) ArgumentSWRLAtom(org.apache.stanbol.rules.adapters.swrl.ArgumentSWRLAtom) NumericFunctionAtom(org.apache.stanbol.rules.manager.atoms.NumericFunctionAtom) 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 59 with RuleAtomCallExeption

use of org.apache.stanbol.rules.base.api.RuleAtomCallExeption in project stanbol by apache.

the class SWRLAdpterTest method test.

@SuppressWarnings("unchecked")
@Test
public void test() {
    try {
        List<SWRLRule> rules = (List<SWRLRule>) ruleAdapter.adaptTo(recipeGood, SWRLRule.class);
        StringBuilder sb = new StringBuilder();
        for (SWRLRule rule : rules) {
            sb.append(rule.toString());
        }
        Assert.assertNotSame(sb.toString(), "");
    } catch (UnavailableRuleObjectException e) {
        Assert.fail(e.getMessage());
    } catch (UnsupportedTypeForExportException e) {
        Assert.fail(e.getMessage());
    } catch (RuleAtomCallExeption e) {
        Assert.fail(e.getMessage());
    }
}
Also used : UnsupportedTypeForExportException(org.apache.stanbol.rules.base.api.UnsupportedTypeForExportException) UnavailableRuleObjectException(org.apache.stanbol.rules.base.api.UnavailableRuleObjectException) SWRLRule(org.semanticweb.owlapi.model.SWRLRule) List(java.util.List) RuleAtomCallExeption(org.apache.stanbol.rules.base.api.RuleAtomCallExeption) Test(org.junit.Test)

Example 60 with RuleAtomCallExeption

use of org.apache.stanbol.rules.base.api.RuleAtomCallExeption 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());
    }
}
Also used : SPARQLObject(org.apache.stanbol.rules.base.api.SPARQLObject) UnavailableRuleObjectException(org.apache.stanbol.rules.base.api.UnavailableRuleObjectException) SPARQLComparison(org.apache.stanbol.rules.adapters.sparql.SPARQLComparison) NumericFunctionAtom(org.apache.stanbol.rules.manager.atoms.NumericFunctionAtom) RuleAtomCallExeption(org.apache.stanbol.rules.base.api.RuleAtomCallExeption) UnsupportedTypeForExportException(org.apache.stanbol.rules.base.api.UnsupportedTypeForExportException)

Aggregations

RuleAtomCallExeption (org.apache.stanbol.rules.base.api.RuleAtomCallExeption)64 ArrayList (java.util.ArrayList)31 UnavailableRuleObjectException (org.apache.stanbol.rules.base.api.UnavailableRuleObjectException)21 UnsupportedTypeForExportException (org.apache.stanbol.rules.base.api.UnsupportedTypeForExportException)21 Node (com.hp.hpl.jena.graph.Node)20 ClauseEntry (com.hp.hpl.jena.reasoner.rulesys.ClauseEntry)20 NodeClauseEntry (org.apache.stanbol.rules.adapters.jena.NodeClauseEntry)20 ExpressionAtom (org.apache.stanbol.rules.manager.atoms.ExpressionAtom)20 SWRLRule (org.semanticweb.owlapi.model.SWRLRule)18 Functor (com.hp.hpl.jena.reasoner.rulesys.Functor)16 ArgumentSWRLAtom (org.apache.stanbol.rules.adapters.swrl.ArgumentSWRLAtom)16 SWRLAtom (org.semanticweb.owlapi.model.SWRLAtom)16 HigherOrderClauseEntry (org.apache.stanbol.rules.adapters.jena.HigherOrderClauseEntry)15 IObjectAtom (org.apache.stanbol.rules.manager.atoms.IObjectAtom)15 OWLDataFactory (org.semanticweb.owlapi.model.OWLDataFactory)15 SWRLDArgument (org.semanticweb.owlapi.model.SWRLDArgument)13 HigherOrderSWRLAtom (org.apache.stanbol.rules.adapters.swrl.HigherOrderSWRLAtom)12 SWRLArgument (org.semanticweb.owlapi.model.SWRLArgument)12 List (java.util.List)10 SPARQLObject (org.apache.stanbol.rules.base.api.SPARQLObject)10