protected void expandAssertions(OWLOntology o, OWLAnnotationProperty p) { OWLAnnotationProperty ap425 = df.getOWLAnnotationProperty(IRI_IAO_0000425.getIRI()); getAnnotationObjects(p, o.importsClosure(), ap425).map(a -> a.getValue().asLiteral()) .filter(v -> v.isPresent()) .forEach(v -> { String str = v.get().getLiteral(); LOG.info("assertion mapping {} to {}", p, str); expandAssertionToMap.put(p.getIRI(), str); }); }
@Override public OWLAnnotation visit(OWLAnnotation node) { return df.getOWLAnnotation(t(node.getProperty()), t(node.getValue()), node.annotations().map(this::t)); }
@Override public void visit(OWLAnnotation node) { sb.append("Annotation("); node.annotations().forEach(a -> { a.accept(this); sb.append(' '); }); node.getProperty().accept(this); sb.append(' '); node.getValue().accept(this); sb.append(')'); }
@Override public void visit(OWLAnnotation annotation) { annotation.getProperty().accept(this); annotation.getValue().accept(this); for (OWLAnnotation anno : annotation.getAnnotations()) { anno.accept(this); } }
@Override public void visit(OWLAnnotation a) { a.getValue().asAnonymousIndividual().ifPresent(this::checkAppearanceAsObject); a.annotations().forEach(a1 -> a1.accept(this)); }
.getOWLAnnotationProperty(Obo2OWLVocabulary.IRI_OIO_LogicalDefinitionViewRelation); Optional<String> findAny = ontology.annotations().filter(a -> a.getProperty().equals(p)) .map(a -> a.getValue() .asLiteral()).filter(Optional::isPresent).map(x -> x.get().getLiteral()).findAny(); if (!findAny.isPresent()) { return; OWLObjectProperty vp = fac.getOWLObjectProperty(pIRI); Set<OWLAxiom> rmAxioms = new HashSet<>(); Set<OWLAxiom> newAxioms = new HashSet<>(); ontology.axioms(AxiomType.EQUIVALENT_CLASSES).forEach(eca -> { AtomicInteger numNamed = new AtomicInteger(); Set<OWLClassExpression> xs = new HashSet<>(); xs.add(fac.getOWLObjectSomeValuesFrom(vp, x)); ontology.remove(rmAxioms); ontology.add(newAxioms);
@Nonnull public List<OBOXRef> getXRefs(@Nonnull OWLAnnotationAssertionAxiom annotationAssertion) { return annotationAssertion.getAnnotations().stream() .filter(anno -> isXRefProperty(anno.getProperty())) .map(anno -> converter.toXRef(anno, anno.getAnnotations())) .filter(xref -> xref != null) .collect(toList()); }
/** * @param patternName patternName * @param ontology ontology * @param factory factory * @return found pattern */ public static PatternModel find(String patternName, OWLOntology ontology, AbstractPatternModelFactory factory) { PatternExtractor patternExtractor = factory.getPatternExtractor(PatternManager.getDefaultErrorListener()); return ontology.annotations().filter(Utils::annotationInPatternNamespace) .map(a -> (PatternModel) a.accept(patternExtractor)).filter(Objects::nonNull) .filter(e -> e.getPatternLocalName().equals(patternName)).findFirst().orElse(null); }
/** * @param ontology ontology * @return set of existing pattern names */ public static Set<String> getExistingPatternNames(OWLOntology ontology) { return asSet(ontology.annotations().filter(Utils::annotationInPatternNamespace) .map(a -> a.getProperty().getIRI().getFragment())); }
@Nonnull @Override public GetOntologyAnnotationsResult execute(@Nonnull GetOntologyAnnotationsAction action, @Nonnull ExecutionContext executionContext) { List<OWLAnnotation> result = new ArrayList<>(rootOntology.getAnnotations()); ImmutableList.Builder<PropertyAnnotationValue> annotationValues = ImmutableList.builder(); result.stream() .map(annotation -> PropertyAnnotationValue.get( renderingManager.getAnnotationPropertyData(annotation.getProperty()), renderingManager.getRendering(annotation.getValue()), State.ASSERTED )) .sorted(propertyValueComparator) .forEach(annotationValues::add); return new GetOntologyAnnotationsResult(annotationValues.build()); }
/** * @return originating ontology */ public OWLOntology getOriginatingOntology() { return ontologyManager.ontologies() .filter(o -> o.annotations().anyMatch(a -> a.getProperty().getIRI().equals(iri))) .findFirst().orElse(null); }
/** * Retrieve annotations from an axiom. For regular axioms, their annotations are retrieved; for * annotation assertion axioms, their asserted annotation is retrieved as well. * * @param axiom axiom * @param p optional annotation property to filter. Null means all. * @return annotations */ public static Stream<OWLAnnotation> annotations(OWLAxiom axiom, @Nullable OWLAnnotationProperty p) { Stream<OWLAnnotation> stream = empty(); if (axiom instanceof OWLAnnotationAssertionAxiom) { stream = Stream.of(((OWLAnnotationAssertionAxiom) axiom).getAnnotation()); } stream = Stream.concat(stream, axiom.annotations()).distinct().sorted(); if (p != null) { stream = stream.filter(a -> a.getProperty().equals(p)); } return stream.distinct(); }
private static TestRunner<?> getRunner(OWLNamedIndividual i, OWLOntology o) { final IRI iri = i.getIRI(); TestRunner<?> runner = _runners.get(iri); if (runner == null) { String name; final Collection<OWLAnnotation> s = EntitySearcher.getAnnotations(i.getIRI(), o, o.getOWLOntologyManager().getOWLDataFactory().getRDFSLabel()).collect(Collectors.toList()); if (s == null || s.isEmpty()) { name = i.getIRI().toURI().toASCIIString(); } else { name = s.iterator().next().getValue().toString(); } runner = new ReadOnlyTestRunner<>(iri, name); _runners.put(iri, runner); } return runner; }
/** * @param ontology ontology * @param factory factory * @return set of existing patterns */ public static Set<PatternModel> getExistingPatterns(OWLOntology ontology, AbstractPatternModelFactory factory) { PatternExtractor patternExtractor = factory.getPatternExtractor(PatternManager.getDefaultErrorListener()); return asSet(ontology.annotations().map(a -> (PatternModel) a.accept(patternExtractor))); }
/** * Pre process. */ protected void preProcess() { // converse of postProcess in obo2owl String viewRel = null; OWLAnnotationProperty logicalDef = manager.getOWLDataFactory().getOWLAnnotationProperty( Obo2OWLVocabulary.IRI_OIO_LogicalDefinitionViewRelation.getIRI()); List<OWLAnnotation> collect = asList(getOWLOntology().annotations(logicalDef)); for (OWLAnnotation ann : collect) { OWLAnnotationValue v = ann.getValue(); if (v instanceof OWLLiteral) { viewRel = ((OWLLiteral) v).getLiteral(); } else if (v.isIRI()) { viewRel = getIdentifier((IRI) v); } break; } if (viewRel == null) { return; } String view = viewRel; Set<OWLAxiom> rmAxioms = new HashSet<>(); Set<OWLAxiom> newAxioms = new HashSet<>(); getOWLOntology().axioms(AxiomType.EQUIVALENT_CLASSES) .forEach(eca -> preprocessEquivalents(view, rmAxioms, newAxioms, eca)); getOWLOntology().remove(rmAxioms); getOWLOntology().add(newAxioms); }
@Override public void visit(OWLAnnotation node) { write(ANNOTATION); writeOpenBracket(); node.annotations().forEach(this::acceptAndSpace); acceptAndSpace(node.getProperty()); node.getValue().accept(this); writeCloseBracket(); }
@Override public <T extends OWLObject> void walk(StructureWalker<T> walker, OWLObject o) { if (o instanceof OWLOntology) { ((OWLOntology) o).annotations().forEach(a -> a.accept(walker)); } } },
/** * @param axiom the axiom whose annotations should be written */ public void writeAnnotations(OWLAxiom axiom) { axiom.annotations().forEach(a -> { a.accept(this); insertSpace(); }); }
protected RDFRendererBase(OWLOntology ontology, @Nullable OWLDocumentFormat format, OWLOntologyWriterConfiguration config) { this.ontology = ontology; this.config = config; OWLOntologyManager m = this.ontology.getOWLOntologyManager(); df = m.getOWLDataFactory(); this.format = format; if (m.getOntologyWriterConfiguration().shouldSaveIdsForAllAnonymousIndividuals()) { occurrences = x -> true; axiomOccurrences = x -> true; } else { OWLAnonymousIndividualsWithMultipleOccurrences visitor = new OWLAnonymousIndividualsWithMultipleOccurrences(); occurrences = visitor; ontology.accept(visitor); axiomOccurrences = x -> x.annotations().anyMatch(a -> a.annotations().count() > 0); } punned = ontology.getPunnedIRIs(EXCLUDED); }