Search in sources :

Example 1 with BinaryOWLMetadata

use of org.semanticweb.binaryowl.BinaryOWLMetadata in project webprotege by protegeproject.

the class ImportsCacheManager method toBinaryOWLMetadata.

/**
 * Translates an {@link ImportedOntologyMetadata} object to {@link BinaryOWLMetadata}.
 * @param value The value to be translated.
 * @return The translation.  Not {@code null}.
 */
private BinaryOWLMetadata toBinaryOWLMetadata(ImportedOntologyMetadata value) {
    BinaryOWLMetadata metadata = new BinaryOWLMetadata();
    metadata.setLongAttribute(META_DATA_TIME_STAMP_ATTR, value.getAccessTimestamp());
    metadata.setStringAttribute(METADATA_DOCUMENT_IRI_ATTR, value.getOriginalDocumentLocation().toString());
    return metadata;
}
Also used : BinaryOWLMetadata(org.semanticweb.binaryowl.BinaryOWLMetadata)

Example 2 with BinaryOWLMetadata

use of org.semanticweb.binaryowl.BinaryOWLMetadata in project webprotege by protegeproject.

the class ImportsCacheManager method cacheOntologyIfNotAlreadyCached.

private void cacheOntologyIfNotAlreadyCached(OWLOntology ont) {
    try {
        WRITE_LOCK.lock();
        if (ontologyIDs.contains(ont.getOntologyID())) {
            return;
        }
        final File file = getFreshImportCacheFile();
        try (DataOutputStream os = new DataOutputStream(new BufferedOutputStream(new FileOutputStream(file)))) {
            final long timestamp = System.currentTimeMillis();
            IRI documentIRI = ont.getOWLOntologyManager().getOntologyDocumentIRI(ont);
            final ImportedOntologyMetadata value = new ImportedOntologyMetadata(ont.getOntologyID(), documentIRI, timestamp);
            BinaryOWLMetadata metadata = toBinaryOWLMetadata(value);
            BinaryOWLOntologyDocumentSerializer serializer = new BinaryOWLOntologyDocumentSerializer();
            serializer.write(new OWLOntologyWrapper(ont), os, metadata);
            ontologyIDs.add(ont.getOntologyID());
            metadataMap.put(ont.getOntologyID(), value);
            logger.info("Cached imported ontology: " + ont.getOntologyID() + " in " + file.getName());
        } catch (IOException e) {
            logger.error("An error occurred whilst caching an ontology: {}", e.getMessage(), e);
        }
    } finally {
        WRITE_LOCK.unlock();
    }
}
Also used : OWLOntologyWrapper(org.semanticweb.binaryowl.owlapi.OWLOntologyWrapper) BinaryOWLMetadata(org.semanticweb.binaryowl.BinaryOWLMetadata) ImportedOntologyMetadata(edu.stanford.bmir.protege.web.shared.project.ImportedOntologyMetadata) BinaryOWLOntologyDocumentSerializer(org.semanticweb.binaryowl.BinaryOWLOntologyDocumentSerializer)

Example 3 with BinaryOWLMetadata

use of org.semanticweb.binaryowl.BinaryOWLMetadata in project webprotege by protegeproject.

the class RevisionStoreImpl method load.

public void load() {
    try {
        writeLock.lock();
        if (!changeHistoryFile.exists()) {
            changeHistoryFile.getParentFile().mkdirs();
            return;
        }
        final ImmutableList.Builder<Revision> revisionsBuilder = ImmutableList.builder();
        try {
            logger.info("{} Loading change history", projectId);
            Stopwatch stopwatch = Stopwatch.createStarted();
            BinaryOWLOntologyChangeLog changeLog = new BinaryOWLOntologyChangeLog();
            final BufferedInputStream inputStream = new BufferedInputStream(new FileInputStream(changeHistoryFile));
            final Interner<OWLAxiom> axiomInterner = Interners.newStrongInterner();
            final Interner<String> metadataInterner = Interners.newStrongInterner();
            changeLog.readChanges(inputStream, dataFactory, (list, skipSetting, l) -> {
                BinaryOWLMetadata metadata = list.getMetadata();
                String userName = metadataInterner.intern(metadata.getStringAttribute(RevisionSerializationVocabulary.USERNAME_METADATA_ATTRIBUTE.getVocabularyName(), ""));
                Long revisionNumberValue = metadata.getLongAttribute(RevisionSerializationVocabulary.REVISION_META_DATA_ATTRIBUTE.getVocabularyName(), 0L);
                RevisionNumber revisionNumber = RevisionNumber.getRevisionNumber(revisionNumberValue);
                String description = metadataInterner.intern(metadata.getStringAttribute(RevisionSerializationVocabulary.DESCRIPTION_META_DATA_ATTRIBUTE.getVocabularyName(), ""));
                // RevisionType type = RevisionType.valueOf(metadata.getStringAttribute(RevisionSerializationVocabulary.REVISION_TYPE_META_DATA_ATTRIBUTE.getVocabularyName(), RevisionType.EDIT.name()));
                final UserId userId = UserId.getUserId(userName);
                final List<OWLOntologyChangeRecord> changeRecords = internChangeRecords(list, axiomInterner);
                Revision revision = new Revision(userId, revisionNumber, ImmutableList.copyOf(changeRecords), list.getTimestamp(), description);
                revisionsBuilder.add(revision);
            }, SkipSetting.SKIP_NONE);
            inputStream.close();
            stopwatch.stop();
            revisions = revisionsBuilder.build();
            logger.info("{} Change history loading complete.  Loaded {} revisions in {} ms.", projectId, revisions.size(), stopwatch.elapsed(TimeUnit.MILLISECONDS));
        } catch (Exception e) {
            logger.error("{} Failed to load change history for project.  Cause: {}", projectId, e.getMessage(), e);
        }
    } finally {
        writeLock.unlock();
    }
}
Also used : ImmutableList(com.google.common.collect.ImmutableList) Stopwatch(com.google.common.base.Stopwatch) RevisionNumber(edu.stanford.bmir.protege.web.shared.revision.RevisionNumber) FileInputStream(java.io.FileInputStream) IOException(java.io.IOException) BinaryOWLMetadata(org.semanticweb.binaryowl.BinaryOWLMetadata) BufferedInputStream(java.io.BufferedInputStream) BinaryOWLOntologyChangeLog(org.semanticweb.binaryowl.BinaryOWLOntologyChangeLog) UserId(edu.stanford.bmir.protege.web.shared.user.UserId) AtomicLong(java.util.concurrent.atomic.AtomicLong) OWLAxiom(org.semanticweb.owlapi.model.OWLAxiom)

Example 4 with BinaryOWLMetadata

use of org.semanticweb.binaryowl.BinaryOWLMetadata in project webprotege by protegeproject.

the class RevisionSerializationTask method call.

public Integer call() throws IOException {
    BinaryOWLMetadata metadata = new BinaryOWLMetadata();
    metadata.setStringAttribute(RevisionSerializationVocabulary.USERNAME_METADATA_ATTRIBUTE.getVocabularyName(), revision.getUserId().getUserName());
    metadata.setLongAttribute(RevisionSerializationVocabulary.REVISION_META_DATA_ATTRIBUTE.getVocabularyName(), revision.getRevisionNumber().getValue());
    metadata.setStringAttribute(RevisionSerializationVocabulary.DESCRIPTION_META_DATA_ATTRIBUTE.getVocabularyName(), revision.getHighLevelDescription());
    metadata.setStringAttribute(RevisionSerializationVocabulary.REVISION_TYPE_META_DATA_ATTRIBUTE.getVocabularyName(), RevisionType.EDIT.name());
    BinaryOWLOntologyChangeLog changeLog = new BinaryOWLOntologyChangeLog();
    changeLog.appendChanges(new OntologyChangeRecordList(revision.getTimestamp(), metadata, revision.getChanges()), file);
    return 0;
}
Also used : OntologyChangeRecordList(org.semanticweb.binaryowl.change.OntologyChangeRecordList) BinaryOWLMetadata(org.semanticweb.binaryowl.BinaryOWLMetadata) BinaryOWLOntologyChangeLog(org.semanticweb.binaryowl.BinaryOWLOntologyChangeLog)

Aggregations

BinaryOWLMetadata (org.semanticweb.binaryowl.BinaryOWLMetadata)4 BinaryOWLOntologyChangeLog (org.semanticweb.binaryowl.BinaryOWLOntologyChangeLog)2 Stopwatch (com.google.common.base.Stopwatch)1 ImmutableList (com.google.common.collect.ImmutableList)1 ImportedOntologyMetadata (edu.stanford.bmir.protege.web.shared.project.ImportedOntologyMetadata)1 RevisionNumber (edu.stanford.bmir.protege.web.shared.revision.RevisionNumber)1 UserId (edu.stanford.bmir.protege.web.shared.user.UserId)1 BufferedInputStream (java.io.BufferedInputStream)1 FileInputStream (java.io.FileInputStream)1 IOException (java.io.IOException)1 AtomicLong (java.util.concurrent.atomic.AtomicLong)1 BinaryOWLOntologyDocumentSerializer (org.semanticweb.binaryowl.BinaryOWLOntologyDocumentSerializer)1 OntologyChangeRecordList (org.semanticweb.binaryowl.change.OntologyChangeRecordList)1 OWLOntologyWrapper (org.semanticweb.binaryowl.owlapi.OWLOntologyWrapper)1 OWLAxiom (org.semanticweb.owlapi.model.OWLAxiom)1