Search in sources :

Example 1 with OWLDataFactory

use of org.semanticweb.owlapi.model.OWLDataFactory in project goci by EBISPOT.

the class KBLoader method getTraitClass.

private Set<IRI> getTraitClass(OWLOntology ontology, OWLNamedIndividual individual) {
    OWLOntologyManager manager = ontology.getOWLOntologyManager();
    OWLDataFactory dataFactory = manager.getOWLDataFactory();
    Set<IRI> results = new HashSet<IRI>();
    // get all individuals related to this one by "is_about"
    OWLObjectProperty has_object = dataFactory.getOWLObjectProperty(IRI.create(OntologyConstants.HAS_OBJECT_IRI));
    Set<OWLIndividual> relatedInds = individual.getObjectPropertyValues(has_object, ontology);
    // for each related individual, get all types
    for (OWLIndividual related : relatedInds) {
        Set<OWLClassExpression> types = related.getTypes(ontology);
        for (OWLClassExpression type : types) {
            results.add(type.asOWLClass().getIRI());
        }
    }
    return results;
}
Also used : IRI(org.semanticweb.owlapi.model.IRI) OWLOntologyManager(org.semanticweb.owlapi.model.OWLOntologyManager) OWLClassExpression(org.semanticweb.owlapi.model.OWLClassExpression) OWLDataFactory(org.semanticweb.owlapi.model.OWLDataFactory) OWLObjectProperty(org.semanticweb.owlapi.model.OWLObjectProperty) HashSet(java.util.HashSet) OWLIndividual(org.semanticweb.owlapi.model.OWLIndividual)

Example 2 with OWLDataFactory

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

the class SubtractionAtom method adapt.

@SuppressWarnings("unchecked")
@Override
public <T> T adapt(RuleAtom ruleAtom) throws RuleAtomCallExeption, UnavailableRuleObjectException, UnsupportedTypeForExportException {
    String mul_result = "subtraction_result" + System.currentTimeMillis();
    org.apache.stanbol.rules.manager.atoms.SubtractionAtom tmp = (org.apache.stanbol.rules.manager.atoms.SubtractionAtom) 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.SUBTRACT.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 3 with OWLDataFactory

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

the class UpperCaseAtom method adapt.

@SuppressWarnings("unchecked")
@Override
public <T> T adapt(RuleAtom ruleAtom) throws RuleAtomCallExeption, UnavailableRuleObjectException, UnsupportedTypeForExportException {
    String uppercase_result = "uppercase_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 + uppercase_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.UPPER_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 4 with OWLDataFactory

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

the class SumAtom method adapt.

@SuppressWarnings("unchecked")
@Override
public <T> T adapt(RuleAtom ruleAtom) throws RuleAtomCallExeption, UnavailableRuleObjectException, UnsupportedTypeForExportException {
    String mul_result = "sum_result" + System.currentTimeMillis();
    org.apache.stanbol.rules.manager.atoms.SumAtom tmp = (org.apache.stanbol.rules.manager.atoms.SumAtom) 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.ADD.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 5 with OWLDataFactory

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

the class ClassAtom method adapt.

@SuppressWarnings("unchecked")
@Override
public <T> T adapt(RuleAtom ruleAtom) throws RuleAtomCallExeption, UnavailableRuleObjectException, UnsupportedTypeForExportException {
    org.apache.stanbol.rules.manager.atoms.ClassAtom tmp = (org.apache.stanbol.rules.manager.atoms.ClassAtom) ruleAtom;
    OWLDataFactory factory = OWLManager.getOWLDataFactory();
    IObjectAtom classResource = tmp.getClassResource();
    IObjectAtom argument = tmp.getArgument1();
    SWRLAtom classResourceAtom = (SWRLAtom) adapter.adaptTo(classResource, SWRLRule.class);
    SWRLAtom argumentAtom = (SWRLAtom) adapter.adaptTo(argument, SWRLRule.class);
    OWLClass classPredicate;
    SWRLIArgument argumentResource;
    if (classResourceAtom instanceof ArgumentSWRLAtom) {
        classPredicate = factory.getOWLClass(IRI.create(((ArgumentSWRLAtom) classResourceAtom).getId()));
    } else {
        throw new RuleAtomCallExeption(getClass());
    }
    if (argumentAtom instanceof ArgumentSWRLAtom) {
        argumentResource = (SWRLIArgument) ((ArgumentSWRLAtom) argumentAtom).getSwrlArgument();
    } else {
        throw new RuleAtomCallExeption(getClass());
    }
    return (T) factory.getSWRLClassAtom(classPredicate, argumentResource);
}
Also used : ArgumentSWRLAtom(org.apache.stanbol.rules.adapters.swrl.ArgumentSWRLAtom) 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) OWLClass(org.semanticweb.owlapi.model.OWLClass) RuleAtomCallExeption(org.apache.stanbol.rules.base.api.RuleAtomCallExeption) OWLDataFactory(org.semanticweb.owlapi.model.OWLDataFactory)

Aggregations

OWLDataFactory (org.semanticweb.owlapi.model.OWLDataFactory)58 OWLOntologyCreationException (org.semanticweb.owlapi.model.OWLOntologyCreationException)24 OWLOntologyManager (org.semanticweb.owlapi.model.OWLOntologyManager)23 OWLOntology (org.semanticweb.owlapi.model.OWLOntology)21 ArgumentSWRLAtom (org.apache.stanbol.rules.adapters.swrl.ArgumentSWRLAtom)18 ArrayList (java.util.ArrayList)16 SWRLAtom (org.semanticweb.owlapi.model.SWRLAtom)16 RuleAtomCallExeption (org.apache.stanbol.rules.base.api.RuleAtomCallExeption)15 SWRLDArgument (org.semanticweb.owlapi.model.SWRLDArgument)15 SWRLRule (org.semanticweb.owlapi.model.SWRLRule)15 HigherOrderSWRLAtom (org.apache.stanbol.rules.adapters.swrl.HigherOrderSWRLAtom)12 OWLClass (org.semanticweb.owlapi.model.OWLClass)12 SWRLArgument (org.semanticweb.owlapi.model.SWRLArgument)12 IRI (org.semanticweb.owlapi.model.IRI)11 OWLLiteral (org.semanticweb.owlapi.model.OWLLiteral)11 OWLIndividual (org.semanticweb.owlapi.model.OWLIndividual)10 OWLObjectProperty (org.semanticweb.owlapi.model.OWLObjectProperty)10 HashSet (java.util.HashSet)9 ExpressionAtom (org.apache.stanbol.rules.manager.atoms.ExpressionAtom)9 OWLDataProperty (org.semanticweb.owlapi.model.OWLDataProperty)9