Package org.semanticweb.owlapi.model

Examples of org.semanticweb.owlapi.model.SWRLRule


        if (!DASH.matches(tok)) {
            throw new ExceptionBuilder().withKeyword(DASH, COMMA).build();
        }
        consumeToken(">");
        List<SWRLAtom> head = parseRuleAtoms();
        SWRLRule rule = dataFactory.getSWRLRule(new LinkedHashSet<>(body),
                new LinkedHashSet<>(head));
        List<OntologyAxiomPair> pairs = new ArrayList<>();
        for (OWLOntology ont : ontologies) {
            assert ont != null;
            pairs.add(new OntologyAxiomPair(ont, rule));
View Full Code Here


        SWRLVariable var = df.getSWRLVariable(IRI.create(EXAMPLE_IRI + "#x"));
        Set<SWRLClassAtom> body = Collections.singleton(df.getSWRLClassAtom(
                clsA, var));
        Set<SWRLClassAtom> head = Collections.singleton(df.getSWRLClassAtom(
                clsB, var));
        SWRLRule rule = df.getSWRLRule(body, head);
        m.applyChange(new AddAxiom(o, rule));
        OWLObjectProperty prop = df.getOWLObjectProperty(IRI.create(EXAMPLE_IRI
                + "#propA"));
        OWLObjectProperty propB = df.getOWLObjectProperty(IRI
                .create(EXAMPLE_IRI + "#propB"));
        SWRLObjectPropertyAtom propAtom = df.getSWRLObjectPropertyAtom(prop,
                var, var);
        SWRLObjectPropertyAtom propAtom2 = df.getSWRLObjectPropertyAtom(propB,
                var, var);
        Set<SWRLAtom> antecedent = new HashSet<>();
        antecedent.add(propAtom);
        antecedent.add(propAtom2);
        SWRLRule rule2 = df.getSWRLRule(antecedent,
                Collections.singleton(propAtom));
        m.applyChange(new AddAxiom(o, rule2));
    }
View Full Code Here

                        OWLOntologyDocumentSourceBase
                                .getNextDocumentIRI("string:ontology"),
                        ontologyFormat, null));
        Set<SWRLRule> rules = ont2.getAxioms(AxiomType.SWRL_RULE);
        assertThat(rules.size(), is(1));
        SWRLRule parsedRule = rules.iterator().next();
        assertThat(parsedRule, is(equalTo(rule)));
        List<SWRLAtom> originalBody = new ArrayList<>(body);
        List<SWRLAtom> parsedBody = new ArrayList<>(parsedRule.getBody());
        assertThat(parsedBody, is(equalTo(originalBody)));
        List<SWRLAtom> originalHead = new ArrayList<>(head);
        List<SWRLAtom> parsedHead = new ArrayList<>(parsedRule.getHead());
        assertThat(originalHead, is(equalTo(parsedHead)));
    }
View Full Code Here

    }

    @Test
    public void shouldBuildSWRLRule() {
        // given
        SWRLRule expected = df.getSWRLRule(body, head);
        BuilderSWRLRule builder = new BuilderSWRLRule(expected, df);
        // when
        OWLObject built = builder.buildObject();
        // then
        assertEquals(expected, built);
View Full Code Here

    public boolean equals(Object obj) {
        if (super.equals(obj)) {
            if (!(obj instanceof SWRLRule)) {
                return false;
            }
            SWRLRule other = (SWRLRule) obj;
            return other.getBody().equals(body) && other.getHead().equals(head);
        }
        return false;
    }
View Full Code Here

        return AxiomType.SWRL_RULE;
    }

    @Override
    protected int compareObjectOfSameType(OWLObject object) {
        SWRLRule other = (SWRLRule) object;
        int diff = compareSets(getBody(), other.getBody());
        if (diff == 0) {
            diff = compareSets(getHead(), other.getHead());
        }
        return diff;
    }
View Full Code Here

        // objects from a data factory that represent class A and class B
        OWLClass clsA = factory.getOWLClass(IRI.create(ontologyIRI + "#A"));
        OWLClass clsB = factory.getOWLClass(IRI.create(ontologyIRI + "#B"));
        SWRLVariable var = factory.getSWRLVariable(IRI.create(ontologyIRI
                + "#x"));
        SWRLRule rule = factory.getSWRLRule(
                singleton(factory.getSWRLClassAtom(clsA, var)),
                singleton(factory.getSWRLClassAtom(clsB, var)));
        manager.applyChange(new AddAxiom(ontology, rule));
        OWLObjectProperty prop = factory.getOWLObjectProperty(IRI
                .create(ontologyIRI + "#propA"));
        OWLObjectProperty propB = factory.getOWLObjectProperty(IRI
                .create(ontologyIRI + "#propB"));
        SWRLObjectPropertyAtom propAtom = factory.getSWRLObjectPropertyAtom(
                prop, var, var);
        SWRLObjectPropertyAtom propAtom2 = factory.getSWRLObjectPropertyAtom(
                propB, var, var);
        Set<SWRLAtom> antecedent = new HashSet<SWRLAtom>();
        antecedent.add(propAtom);
        antecedent.add(propAtom2);
        SWRLRule rule2 = factory.getSWRLRule(antecedent,
                Collections.singleton(propAtom));
        manager.applyChange(new AddAxiom(ontology, rule2));
        // Now save the ontology. The ontology will be saved to the location
        // where we loaded it from, in the default ontology format
        manager.saveOntology(ontology);
View Full Code Here

            IRI ruleBodyIRI = consumer.getResourceObject(remappedNode,
                    SWRLVocabulary.BODY.getIRI(), true);
            if (ruleBodyIRI != null) {
                antecedent = listTranslator.translateToSet(ruleBodyIRI);
            }
            SWRLRule rule = null;
            if (!consumer.isAnonymousNode(remappedNode)) {
                rule = consumer.getDataFactory().getSWRLRule(antecedent,
                        consequent, annotations);
            } else {
                rule = consumer.getDataFactory().getSWRLRule(antecedent,
View Full Code Here

        body.add(df.getSWRLDataPropertyAtom(p, x, y));
        body.add(df.getSWRLDataRangeAtom(
                df.getOWLDatatype(XSDVocabulary.STRING.getIRI()), y));
        Set<SWRLAtom> head = new TreeSet<>();
        head.add(df.getSWRLClassAtom(a, x));
        SWRLRule rule = df.getSWRLRule(body, head);
        ontology.getOWLOntologyManager().addAxiom(ontology, rule);
        ontology = roundTrip(ontology, new OWLXMLDocumentFormat());
        OWLOntology onto2 = roundTrip(ontology, new OWLXMLDocumentFormat());
        equal(ontology, onto2);
    }
View Full Code Here

        body.add(df.getSWRLDataPropertyAtom(p, x, y));
        body.add(df.getSWRLDataRangeAtom(
                df.getOWLDatatype(XSDVocabulary.STRING.getIRI()), y));
        Set<SWRLAtom> head = new TreeSet<>();
        head.add(df.getSWRLClassAtom(a, x));
        SWRLRule rule = df.getSWRLRule(body, head);
        ontology.getOWLOntologyManager().addAxiom(ontology, rule);
        ontology = roundTrip(ontology, new ManchesterSyntaxDocumentFormat());
        OWLOntology onto2 = roundTrip(ontology,
                new ManchesterSyntaxDocumentFormat());
        equal(ontology, onto2);
View Full Code Here

TOP

Related Classes of org.semanticweb.owlapi.model.SWRLRule

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.