Search in sources :

Example 1 with OWLObject

use of org.semanticweb.owlapi.model.OWLObject in project protege-client by protegeproject.

the class OwlCellRenderer method getIcon.

@Override
protected Icon getIcon(Object object) {
    if (object instanceof IRI) {
        setHighlightKeywords(false);
        IRI ontIri = editorKit.getOWLModelManager().getActiveOntology().getOntologyID().getOntologyIRI().get();
        if (!object.equals(ontIri)) {
            // IRI of OWLAnnotationSubject
            return new OWLAnnotationPropertyIcon();
        } else {
            // IRI of ontology
            return OWLIcons.getIcon(GuiUtils.ONTOLOGY_ICON_FILENAME);
        }
    } else if (object instanceof String) {
        setHighlightKeywords(false);
        return GuiUtils.getIcon(GuiUtils.STRING_ICON_FILENAME, 13, 13);
    } else {
        return editorKit.getWorkspace().getOWLIconProvider().getIcon((OWLObject) object);
    }
}
Also used : OWLObject(org.semanticweb.owlapi.model.OWLObject) IRI(org.semanticweb.owlapi.model.IRI) OWLAnnotationPropertyIcon(org.protege.editor.owl.ui.renderer.OWLAnnotationPropertyIcon)

Example 2 with OWLObject

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

the class RegistryManagerImpl method createModel.

@Override
public Set<Registry> createModel(Set<OWLOntology> registryOntologies) {
    Set<Registry> results = new HashSet<Registry>();
    // Reset population
    population.clear();
    // Build the transitive imports closure of the union.
    Set<OWLOntology> closure = new HashSet<OWLOntology>();
    for (OWLOntology rego : registryOntologies) closure.addAll(rego.getOWLOntologyManager().getImportsClosure(rego));
    /*
         * For each value in this map, index 0 is the score of the library class, while 1 is the score of the
         * ontology class.
         */
    final Map<IRI, int[]> candidateTypes = new HashMap<IRI, int[]>();
    /*
         * Scans class assertions and object property values and tries to determine the type of each
         * individual it finds.
         */
    OWLAxiomVisitor scanner = new OWLAxiomVisitorAdapter() {

        /*
             * For a given identifier, returns the array of integers whose value determine the likelihood if
             * the corresponding entity being a library or an ontology. If no such array exists, it is
             * created.
             */
        private int[] checkScores(IRI key) {
            int[] scores;
            if (candidateTypes.containsKey(key))
                scores = candidateTypes.get(key);
            else {
                scores = new int[] { 0, 0 };
                candidateTypes.put(key, scores);
            }
            return scores;
        }

        @Override
        public void visit(OWLAnnotationAssertionAxiom axiom) {
            /*
                 * Works like object property assertions, in case hasOntology and isOntologyOf are not
                 * detected to be object properties (e.g. due to a failure to load codolight or the registry
                 * metamodel).
                 */
            OWLAnnotationProperty prop = axiom.getProperty();
            if (hasOntologyAnn.equals(prop)) {
                IRI iri;
                // The axiom subject gets a +1 in its library score.
                OWLObject ind = axiom.getSubject();
                if (ind instanceof IRI) {
                    iri = (IRI) ind;
                    checkScores(iri)[0]++;
                }
                // The axiom object gets a +1 in its ontology score.
                ind = axiom.getValue();
                if (ind instanceof IRI) {
                    iri = (IRI) ind;
                    checkScores(iri)[1]++;
                }
            } else if (isOntologyOfAnn.equals(prop)) {
                IRI iri;
                // The axiom subject gets a +1 in its ontology score.
                OWLObject ind = axiom.getSubject();
                if (ind instanceof IRI) {
                    iri = (IRI) ind;
                    checkScores(iri)[1]++;
                }
                // The axiom object gets a +1 in its library score.
                ind = axiom.getValue();
                if (ind instanceof IRI) {
                    iri = (IRI) ind;
                    checkScores(iri)[0]++;
                }
            }
        }

        @Override
        public void visit(OWLClassAssertionAxiom axiom) {
            OWLIndividual ind = axiom.getIndividual();
            // Do not accept anonymous registry items.
            if (ind.isAnonymous())
                return;
            IRI iri = ind.asOWLNamedIndividual().getIRI();
            int[] scores = checkScores(iri);
            OWLClassExpression type = axiom.getClassExpression();
            // If the type is stated to be a library, increase its library score.
            if (cRegistryLibrary.equals(type)) {
                scores[0]++;
            } else // If the type is stated to be an ontology, increase its ontology score.
            if (cOntology.equals(type)) {
                scores[1]++;
            }
        }

        @Override
        public void visit(OWLObjectPropertyAssertionAxiom axiom) {
            OWLObjectPropertyExpression prop = axiom.getProperty();
            if (hasOntology.equals(prop)) {
                IRI iri;
                // The axiom subject gets a +1 in its library score.
                OWLIndividual ind = axiom.getSubject();
                if (!ind.isAnonymous()) {
                    iri = ind.asOWLNamedIndividual().getIRI();
                    checkScores(iri)[0]++;
                }
                // The axiom object gets a +1 in its ontology score.
                ind = axiom.getObject();
                if (!ind.isAnonymous()) {
                    iri = ind.asOWLNamedIndividual().getIRI();
                    checkScores(iri)[1]++;
                }
            } else if (isOntologyOf.equals(prop)) {
                IRI iri;
                // The axiom subject gets a +1 in its ontology score.
                OWLIndividual ind = axiom.getSubject();
                if (!ind.isAnonymous()) {
                    iri = ind.asOWLNamedIndividual().getIRI();
                    checkScores(iri)[1]++;
                }
                // The axiom object gets a +1 in its library score.
                ind = axiom.getObject();
                if (!ind.isAnonymous()) {
                    iri = ind.asOWLNamedIndividual().getIRI();
                    checkScores(iri)[0]++;
                }
            }
        }
    };
    // First pass to determine the types.
    for (OWLOntology o : closure) for (OWLAxiom ax : o.getAxioms()) ax.accept(scanner);
    // Then populate on the registry
    OWLDataFactory df = OWLManager.getOWLDataFactory();
    for (IRI iri : candidateTypes.keySet()) {
        int[] scores = candidateTypes.get(iri);
        if (scores != null && (scores[0] > 0 || scores[1] > 0)) {
            if (scores[0] > 0 && scores[1] == 0)
                population.put(iri, riFactory.createLibrary(df.getOWLNamedIndividual(iri)));
            else if (scores[0] == 0 && scores[1] > 0)
                population.put(iri, riFactory.createRegistryOntology(df.getOWLNamedIndividual(iri)));
        }
    // else log.warn("Unable to determine type for registry item {}", iri);
    }
    for (OWLOntology oReg : registryOntologies) {
        try {
            results.add(populateRegistry(oReg));
        } catch (RegistryContentException e) {
            log.error("An error occurred while populating an ontology registry.", e);
        }
    }
    return results;
}
Also used : OWLObject(org.semanticweb.owlapi.model.OWLObject) IRI(org.semanticweb.owlapi.model.IRI) OWLAnnotationAssertionAxiom(org.semanticweb.owlapi.model.OWLAnnotationAssertionAxiom) OWLAxiomVisitor(org.semanticweb.owlapi.model.OWLAxiomVisitor) HashMap(java.util.HashMap) Registry(org.apache.stanbol.ontologymanager.registry.api.model.Registry) OWLClassExpression(org.semanticweb.owlapi.model.OWLClassExpression) OWLAxiomVisitorAdapter(org.semanticweb.owlapi.util.OWLAxiomVisitorAdapter) OWLAnnotationProperty(org.semanticweb.owlapi.model.OWLAnnotationProperty) OWLOntology(org.semanticweb.owlapi.model.OWLOntology) OWLObjectPropertyExpression(org.semanticweb.owlapi.model.OWLObjectPropertyExpression) RegistryContentException(org.apache.stanbol.ontologymanager.registry.api.RegistryContentException) OWLObjectPropertyAssertionAxiom(org.semanticweb.owlapi.model.OWLObjectPropertyAssertionAxiom) OWLAxiom(org.semanticweb.owlapi.model.OWLAxiom) OWLClassAssertionAxiom(org.semanticweb.owlapi.model.OWLClassAssertionAxiom) OWLDataFactory(org.semanticweb.owlapi.model.OWLDataFactory) HashSet(java.util.HashSet) OWLIndividual(org.semanticweb.owlapi.model.OWLIndividual)

Example 3 with OWLObject

use of org.semanticweb.owlapi.model.OWLObject in project webprotege by protegeproject.

the class AxiomBySubjectComparator method compare.

/**
 * Compares the two axioms using their subject.
 * @param ax1 The first axiom.
 * @param ax2 The second axiom.
 * @return If both axioms have subjects: An integer representing the comparison of the subjects of the two axioms.
 * If the first axiom has a subject, but the second axiom does not, then -1 (first before second).  If the second axiom has a subject
 * but the first axiom does not, then 1 (first after second).  If neither the first axiom has a subject or the second
 * axiom has a subject then 0.
 */
@Override
public int compare(OWLAxiom ax1, OWLAxiom ax2) {
    Optional<? extends OWLObject> optionalSubject1 = axiomSubjectProvider.getSubject(ax1);
    Optional<? extends OWLObject> optionalSubject2 = axiomSubjectProvider.getSubject(ax2);
    if (optionalSubject1.isPresent()) {
        if (optionalSubject2.isPresent()) {
            OWLObject subject1 = optionalSubject1.get();
            OWLObject subject2 = optionalSubject2.get();
            return subjectComparator.compare(subject1, subject2);
        } else {
            return BEFORE;
        }
    } else {
        if (optionalSubject2.isPresent()) {
            return AFTER;
        } else {
            return SAME;
        }
    }
}
Also used : OWLObject(org.semanticweb.owlapi.model.OWLObject)

Example 4 with OWLObject

use of org.semanticweb.owlapi.model.OWLObject in project webprotege by protegeproject.

the class OWLObjectStringFormatter method renderObject.

private String renderObject(Object object) {
    if (!(object instanceof OWLObject)) {
        return object.toString();
    }
    if (object instanceof OWLEntity) {
        return shortFormProvider.getShortForm((OWLEntity) object);
    } else if (object instanceof IRI) {
        return iriShortFormProvider.getShortForm((IRI) object);
    } else if (object instanceof OWLLiteral) {
        OWLLiteral literal = (OWLLiteral) object;
        String rendering;
        if (literal.isRDFPlainLiteral() || literal.getDatatype().isString()) {
            rendering = "\"" + literal.getLiteral() + "\"";
        } else {
            rendering = this.render.render((OWLLiteral) object);
        }
        int startIndex = rendering.indexOf("\"");
        int endIndex = rendering.lastIndexOf("\"");
        if (startIndex == -1 || endIndex == -1) {
            return rendering;
        }
        if (endIndex - startIndex < 10) {
            return rendering;
        }
        if (rendering.length() < MAX_LITERAL_LENGTH) {
            return rendering;
        }
        String withoutQuotes = rendering.substring(startIndex + 1, endIndex);
        String abbreviatedLexicalValue = StringUtils.abbreviate(withoutQuotes, MAX_LITERAL_LENGTH);
        String prefix = rendering.substring(0, startIndex + 1);
        String suffix = rendering.substring(endIndex);
        return prefix + abbreviatedLexicalValue + suffix;
    } else {
        String rendering = this.render.render((OWLObject) object);
        return escape(rendering);
    }
}
Also used : OWLObject(org.semanticweb.owlapi.model.OWLObject) IRI(org.semanticweb.owlapi.model.IRI) OWLLiteral(org.semanticweb.owlapi.model.OWLLiteral) OWLEntity(org.semanticweb.owlapi.model.OWLEntity)

Example 5 with OWLObject

use of org.semanticweb.owlapi.model.OWLObject in project protege-client by protegeproject.

the class ChangesTableCellRenderer method getTableCellRendererComponent.

@Override
public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
    // coordinates passed to the renderer are in view coordinate system after sorting, so they need converting to model coordinates before accessing the model
    int modelRow = table.convertRowIndexToModel(row);
    ChangeMode mode = (ChangeMode) table.getModel().getValueAt(modelRow, ChangesTableModel.Column.MODE.ordinal());
    ChangeType type = (ChangeType) table.getModel().getValueAt(modelRow, ChangesTableModel.Column.CHANGE_TYPE.ordinal());
    if (value instanceof OWLObject) {
        Component c = owlCellRenderer.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
        setBackground(table, type, mode, c, isSelected);
        return c;
    }
    if (value instanceof Boolean) {
        if ((Boolean) value) {
            return getIconLabel(table, type, mode, GuiUtils.WARNING_ICON_FILENAME, isSelected, true);
        } else {
            value = null;
        }
    }
    if (value != null && value instanceof Review) {
        Review review = (Review) value;
        switch(review.getStatus()) {
            case ACCEPTED:
                return getIconLabel(table, type, mode, GuiUtils.REVIEW_ACCEPTED_ICON_FILENAME, isSelected, review.isCommitted());
            case REJECTED:
                return getIconLabel(table, type, mode, GuiUtils.REVIEW_REJECTED_ICON_FILENAME, isSelected, review.isCommitted());
            case PENDING:
            default:
                value = "";
        }
    }
    if (value instanceof Date) {
        setText(GuiUtils.getFormattedDate((Date) value));
    } else {
        setText(value != null ? value.toString() : "");
    }
    setBackground(table, type, mode, this, isSelected);
    setFont(table.getFont());
    return this;
}
Also used : OWLObject(org.semanticweb.owlapi.model.OWLObject) ChangeType(org.protege.editor.owl.client.diff.model.ChangeType) Review(org.protege.editor.owl.client.diff.model.Review) Date(java.util.Date) ChangeMode(org.protege.editor.owl.client.diff.model.ChangeMode)

Aggregations

OWLObject (org.semanticweb.owlapi.model.OWLObject)5 IRI (org.semanticweb.owlapi.model.IRI)3 Date (java.util.Date)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 RegistryContentException (org.apache.stanbol.ontologymanager.registry.api.RegistryContentException)1 Registry (org.apache.stanbol.ontologymanager.registry.api.model.Registry)1 ChangeMode (org.protege.editor.owl.client.diff.model.ChangeMode)1 ChangeType (org.protege.editor.owl.client.diff.model.ChangeType)1 Review (org.protege.editor.owl.client.diff.model.Review)1 OWLAnnotationPropertyIcon (org.protege.editor.owl.ui.renderer.OWLAnnotationPropertyIcon)1 OWLAnnotationAssertionAxiom (org.semanticweb.owlapi.model.OWLAnnotationAssertionAxiom)1 OWLAnnotationProperty (org.semanticweb.owlapi.model.OWLAnnotationProperty)1 OWLAxiom (org.semanticweb.owlapi.model.OWLAxiom)1 OWLAxiomVisitor (org.semanticweb.owlapi.model.OWLAxiomVisitor)1 OWLClassAssertionAxiom (org.semanticweb.owlapi.model.OWLClassAssertionAxiom)1 OWLClassExpression (org.semanticweb.owlapi.model.OWLClassExpression)1 OWLDataFactory (org.semanticweb.owlapi.model.OWLDataFactory)1 OWLEntity (org.semanticweb.owlapi.model.OWLEntity)1 OWLIndividual (org.semanticweb.owlapi.model.OWLIndividual)1