Search in sources :

Example 6 with Identifiable

use of org.vcell.util.document.Identifiable in project vcell by virtualcell.

the class VCMetaData method cleanupMetadata.

public void cleanupMetadata() {
    Set<Registry.Entry> entries = registry.getAllEntries();
    for (Registry.Entry entry : entries) {
        Identifiable entryIdentifiable = entry.getIdentifiable();
        VCID vcid = identifiableProvider.getVCID(entryIdentifiable);
        Identifiable identifiable = identifiableProvider.getIdentifiableObject(vcid);
        if (identifiable == null) {
            // use miriamManager to remove RDF statements from resource for identifiable
            try {
                Map<MiriamRefGroup, MIRIAMQualifier> miriamRefGps = getMiriamManager().getAllMiriamRefGroups(entryIdentifiable);
                if (miriamRefGps != null) {
                    for (Map.Entry<MiriamRefGroup, MIRIAMQualifier> groupEntry : miriamRefGps.entrySet()) {
                        MiriamRefGroup refGroup = groupEntry.getKey();
                        MIRIAMQualifier qualifier = groupEntry.getValue();
                        getMiriamManager().remove(entryIdentifiable, qualifier, refGroup);
                    }
                }
            } catch (URNParseFailureException e) {
                e.printStackTrace(System.out);
            }
            // set nonRDF annotations to null
            NonRDFAnnotation nonRDFAnnotation = getExistingNonRDFAnnotation(entryIdentifiable);
            if (nonRDFAnnotation != null) {
                nonRDFAnnotation.setFreeTextAnnotation(null);
                nonRDFAnnotation.setXhtmlNotes(null);
                nonRDFAnnotation.setXmlAnnotations(null);
            }
            System.err.println("Deleting resource for identifiable '" + entryIdentifiable.toString() + "' since it is not found in " + identifiableProvider.getClass().getName());
        }
    }
}
Also used : Registry(cbit.vcell.biomodel.meta.registry.Registry) Identifiable(org.vcell.util.document.Identifiable) Entry(cbit.vcell.biomodel.meta.registry.Registry.Entry) Entry(cbit.vcell.biomodel.meta.registry.Registry.Entry) MIRIAMQualifier(org.vcell.sybil.models.miriam.MIRIAMQualifier) Map(java.util.Map) IdentityHashMap(java.util.IdentityHashMap) TreeMap(java.util.TreeMap) URNParseFailureException(org.vcell.sybil.models.miriam.MIRIAMRef.URNParseFailureException) MiriamRefGroup(cbit.vcell.biomodel.meta.MiriamManager.MiriamRefGroup)

Example 7 with Identifiable

use of org.vcell.util.document.Identifiable in project vcell by virtualcell.

the class VCMetaDataMiriamManager method getMiriamTreeMap.

public synchronized TreeMap<Identifiable, Map<MiriamRefGroup, MIRIAMQualifier>> getMiriamTreeMap() {
    if (miriamTreeMap == null) {
        final IdentifiableProvider identifiableProvider = vcMetaData.getIdentifiableProvider();
        miriamTreeMap = new TreeMap<Identifiable, Map<MiriamRefGroup, MIRIAMQualifier>>(new IdentifiableComparator(identifiableProvider));
        Set<Entry> allEntries = vcMetaData.getRegistry().getAllEntries();
        for (Entry entry : allEntries) {
            if (entry.getResource() != null) {
                Map<MiriamRefGroup, MIRIAMQualifier> refGroupMap = queryAllMiriamRefGroups(entry.getIdentifiable());
                if (refGroupMap.size() > 0) {
                    miriamTreeMap.put(entry.getIdentifiable(), refGroupMap);
                }
            }
        }
    }
    return miriamTreeMap;
}
Also used : Entry(cbit.vcell.biomodel.meta.registry.Registry.Entry) HashMap(java.util.HashMap) Map(java.util.Map) TreeMap(java.util.TreeMap) MIRIAMQualifier(org.vcell.sybil.models.miriam.MIRIAMQualifier) Identifiable(org.vcell.util.document.Identifiable)

Example 8 with Identifiable

use of org.vcell.util.document.Identifiable in project vcell by virtualcell.

the class XMLMetaDataReader method readFromElement.

@SuppressWarnings("unchecked")
public static void readFromElement(VCMetaData metaData, IdentifiableProvider identifiableProvider, Element metadataElement) throws XmlParseException {
    Element bindingElement = metadataElement.getChild(XMLMetaData.URI_BINDING_LIST_TAG, VCMetaData.nsVCML);
    if (bindingElement != null) {
        // read binding
        List<Element> entryElements = bindingElement.getChildren(XMLMetaData.URI_BINDING_TAG, VCMetaData.nsVCML);
        for (Iterator<Element> iterator = entryElements.iterator(); iterator.hasNext(); ) {
            Element entryElement = iterator.next();
            try {
                String uri = entryElement.getAttributeValue(XMLMetaData.URI_ATTR_TAG);
                String vcidString = entryElement.getAttributeValue(XMLMetaData.VCID_ATTR_TAG);
                // make new entry based on URI
                // create VCID
                VCID vcid = VCID.fromString(vcidString);
                // lookup Identifiable object using VCID ... add to entry.
                metaData.getRegistry().newEntry(metaData.getRdfData(), identifiableProvider.getIdentifiableObject(vcid), uri);
            } catch (VCID.InvalidVCIDException e) {
                e.printStackTrace();
                throw new XmlParseException(e);
            }
        }
    }
    Element rdfElement = metadataElement.getChild(XMLRDF.tagRDF, XMLRDF.nsRDF);
    if (rdfElement != null) {
        // read RDF
        try {
            metaData.addToModelFromElement(rdfElement);
        } catch (RDFParseException e) {
            e.printStackTrace();
            throw new XmlParseException(e.getMessage());
        } catch (RDFHandlerException e) {
            e.printStackTrace();
            throw new XmlParseException(e.getMessage());
        } catch (IOException e) {
            e.printStackTrace();
            throw new XmlParseException(e.getMessage());
        }
    }
    Element nonRDFAnnotationListElement = metadataElement.getChild(XMLMetaData.NONRDF_ANNOTATION_LIST_TAG, VCMetaData.nsVCML);
    if (nonRDFAnnotationListElement != null) {
        List<Element> nonRDFAnnotationElements = nonRDFAnnotationListElement.getChildren(XMLMetaData.NONRDF_ANNOTATION_TAG, VCMetaData.nsVCML);
        for (Element nonRDFAnnotationElement : nonRDFAnnotationElements) {
            String vcidString = nonRDFAnnotationElement.getAttributeValue(XMLMetaData.VCID_ATTR_TAG);
            VCID vcid = null;
            try {
                vcid = VCID.fromString(vcidString);
            } catch (InvalidVCIDException e) {
                e.printStackTrace();
                throw new XmlParseException(e.getMessage());
            }
            Identifiable identifiable = identifiableProvider.getIdentifiableObject(vcid);
            if (identifiable != null) {
                // populate the annotation
                Element freeTextAnnotationElement = nonRDFAnnotationElement.getChild(XMLMetaData.FREETEXT_TAG, VCMetaData.nsVCML);
                if (freeTextAnnotationElement != null) {
                    String freeText = freeTextAnnotationElement.getText();
                    metaData.setFreeTextAnnotation(identifiable, freeText);
                }
                Element xhtmlNotesElement = nonRDFAnnotationElement.getChild(XMLMetaData.NOTES_TAG, VCMetaData.nsVCML);
                if (xhtmlNotesElement != null) {
                    metaData.setXhtmlNotes(identifiable, xhtmlNotesElement);
                }
                Element annotationListElement = nonRDFAnnotationElement.getChild(XMLMetaData.ANNOTATION_LIST_TAG, VCMetaData.nsVCML);
                if (annotationListElement != null) {
                    List<?> annotationContents = annotationListElement.getContent();
                    List<Element> annotationElements = new ArrayList<Element>();
                    for (int i = 0; i < annotationContents.size(); i++) {
                        if (annotationContents.get(i) instanceof Element) {
                            annotationElements.add((Element) annotationContents.get(i));
                        }
                    }
                    metaData.setXmlAnnotations(identifiable, annotationElements.toArray(new Element[annotationElements.size()]));
                }
            } else {
                System.err.println("Cannot find identifiable for vcid : " + vcidString);
            }
        }
    }
}
Also used : VCID(cbit.vcell.biomodel.meta.VCID) Element(org.jdom.Element) ArrayList(java.util.ArrayList) XmlParseException(cbit.vcell.xml.XmlParseException) IOException(java.io.IOException) InvalidVCIDException(cbit.vcell.biomodel.meta.VCID.InvalidVCIDException) Identifiable(org.vcell.util.document.Identifiable) RDFHandlerException(org.openrdf.rio.RDFHandlerException) InvalidVCIDException(cbit.vcell.biomodel.meta.VCID.InvalidVCIDException) RDFParseException(org.openrdf.rio.RDFParseException)

Example 9 with Identifiable

use of org.vcell.util.document.Identifiable in project vcell by virtualcell.

the class XMLMetaDataWriter method createNonRDFAnnotationElement.

/**
 * creating XMLMetaData element for nonRDFAnnotation element here since nonRDFAnnotation was made package level
 *	this is similar to XMLRDFWriter.createElement(metaData)
 *
 * @return the created NonRDFAnnotationListElement
 */
private static Element createNonRDFAnnotationElement(VCMetaData metaData, IdentifiableProvider identifiableProvider) {
    Set<Map.Entry<Entry, NonRDFAnnotation>> allNonRdfAnnotations = metaData.getAllNonRDFAnnotations();
    Element nonRDFAnnotationListElement = new Element(XMLMetaData.NONRDF_ANNOTATION_LIST_TAG);
    Iterator<Map.Entry<Entry, NonRDFAnnotation>> iter = allNonRdfAnnotations.iterator();
    while (iter.hasNext()) {
        Map.Entry<Entry, NonRDFAnnotation> mapEntry = iter.next();
        Entry openEntry = mapEntry.getKey();
        NonRDFAnnotation nonRDFAnnotation = mapEntry.getValue();
        VCID vcid = identifiableProvider.getVCID(openEntry.getIdentifiable());
        Identifiable identifiable = identifiableProvider.getIdentifiableObject(vcid);
        // only write out nonRDF annotation if identifiable in identifiableProvider is not null
        if (identifiable != null) {
            if (!nonRDFAnnotation.isEmpty()) {
                Element nonRDFAnnotationElement = new Element(XMLMetaData.NONRDF_ANNOTATION_TAG);
                nonRDFAnnotationElement.setAttribute(XMLMetaData.VCID_ATTR_TAG, vcid.toASCIIString());
                nonRDFAnnotationListElement.addContent(nonRDFAnnotationElement);
                String freeTextAnnotation = nonRDFAnnotation.getFreeTextAnnotation();
                if (freeTextAnnotation != null && freeTextAnnotation.length() > 0) {
                    Element freeTextAnnotationElement = new Element(XMLMetaData.FREETEXT_TAG);
                    freeTextAnnotationElement.addContent(new Text(freeTextAnnotation));
                    nonRDFAnnotationElement.addContent(freeTextAnnotationElement);
                }
                Element xhtmlNotes = nonRDFAnnotation.getXhtmlNotes();
                if (xhtmlNotes != null) {
                    // Element notesElement = new Element(XMLMetaData.NOTES_TAG);
                    // notesElement.addContent(xhtmlNotes));
                    nonRDFAnnotationElement.addContent(xhtmlNotes.detach());
                }
                Element[] otherAnnotations = nonRDFAnnotation.getXmlAnnotations();
                if (otherAnnotations != null && otherAnnotations.length > 0) {
                    Element annotationListElement = new Element(XMLMetaData.ANNOTATION_LIST_TAG);
                    nonRDFAnnotationElement.addContent(annotationListElement);
                    for (int i = 0; i < otherAnnotations.length; i++) {
                        annotationListElement.addContent(otherAnnotations[i].detach());
                    }
                }
            }
        }
    }
    return nonRDFAnnotationListElement;
}
Also used : VCID(cbit.vcell.biomodel.meta.VCID) NonRDFAnnotation(cbit.vcell.biomodel.meta.NonRDFAnnotation) Element(org.jdom.Element) Text(org.jdom.Text) Identifiable(org.vcell.util.document.Identifiable) Entry(cbit.vcell.biomodel.meta.registry.Registry.Entry) Map(java.util.Map)

Example 10 with Identifiable

use of org.vcell.util.document.Identifiable in project vcell by virtualcell.

the class XMLMetaDataWriter method getElement.

public static Element getElement(VCMetaData metaData, IdentifiableProvider identifiableProvider) {
    Element element = new Element(XMLMetaData.VCMETADATA_TAG);
    Element elementRDF = metaData.createElement();
    // add RDF data
    if (elementRDF != null) {
        element.addContent(elementRDF);
    }
    Element elementNonRDFList = createNonRDFAnnotationElement(metaData, identifiableProvider);
    element.addContent(elementNonRDFList);
    // add resource binding table
    Element bindingListElement = new Element(XMLMetaData.URI_BINDING_LIST_TAG);
    Set<Registry.Entry> resources = metaData.getRegistry().getAllEntries();
    for (Registry.Entry entry : resources) {
        VCID vcid = identifiableProvider.getVCID(entry.getIdentifiable());
        Identifiable identifiable = identifiableProvider.getIdentifiableObject(vcid);
        if (identifiable != null && entry.getResource() != null) {
            Element entryElement = new Element(XMLMetaData.URI_BINDING_TAG);
            Resource resource = entry.getResource();
            if (resource != null) {
                entryElement.setAttribute(XMLMetaData.URI_ATTR_TAG, resource.stringValue());
            }
            entryElement.setAttribute(XMLMetaData.VCID_ATTR_TAG, vcid.toASCIIString());
            bindingListElement.addContent(entryElement);
        }
    }
    element.addContent(bindingListElement);
    return element;
}
Also used : VCID(cbit.vcell.biomodel.meta.VCID) Entry(cbit.vcell.biomodel.meta.registry.Registry.Entry) Element(org.jdom.Element) Resource(org.openrdf.model.Resource) Entry(cbit.vcell.biomodel.meta.registry.Registry.Entry) Registry(cbit.vcell.biomodel.meta.registry.Registry) Identifiable(org.vcell.util.document.Identifiable)

Aggregations

Identifiable (org.vcell.util.document.Identifiable)14 Map (java.util.Map)7 Entry (cbit.vcell.biomodel.meta.registry.Registry.Entry)6 TreeMap (java.util.TreeMap)6 MIRIAMQualifier (org.vcell.sybil.models.miriam.MIRIAMQualifier)6 MiriamRefGroup (cbit.vcell.biomodel.meta.MiriamManager.MiriamRefGroup)5 VCID (cbit.vcell.biomodel.meta.VCID)4 Registry (cbit.vcell.biomodel.meta.registry.Registry)3 HashMap (java.util.HashMap)3 Element (org.jdom.Element)3 Resource (org.openrdf.model.Resource)3 MiriamManager (cbit.vcell.biomodel.meta.MiriamManager)2 MiriamResource (cbit.vcell.biomodel.meta.MiriamManager.MiriamResource)2 HashSet (java.util.HashSet)2 IdentityHashMap (java.util.IdentityHashMap)2 Set (java.util.Set)2 DublinCoreDate (org.vcell.sybil.models.dublincore.DublinCoreDate)2 DublinCoreQualifier (org.vcell.sybil.models.dublincore.DublinCoreQualifier)2 DateQualifier (org.vcell.sybil.models.dublincore.DublinCoreQualifier.DateQualifier)2 URNParseFailureException (org.vcell.sybil.models.miriam.MIRIAMRef.URNParseFailureException)2