Search in sources :

Example 1 with Alignment

use of eu.esdihumboldt.hale.io.oml.internal.goml.align.Alignment in project hale by halestudio.

the class OmlReader method loadAlignment.

@Override
protected MutableAlignment loadAlignment(ProgressIndicator progress, IOReporter reporter) throws IOProviderConfigurationException, IOException {
    try {
        progress.begin("Load ontology mapping file", ProgressIndicator.UNKNOWN);
        OmlRdfReader reader = new OmlRdfReader();
        Alignment alignment = reader.read(getSource().getLocation().toURL());
        AlignmentBean align = new AlignmentBean();
        List<CellBean> cells = new ArrayList<CellBean>();
        List<ICell> map = alignment.getMap();
        for (ICell cell : map) {
            // create a new CellBean for each ICell
            CellBean cellBean = new CellBean();
            IEntity entity = cell.getEntity1();
            IEntity entity2 = cell.getEntity2();
            // temporary list to be copied into the CellBean
            List<NamedEntityBean> temp_source = new ArrayList<NamedEntityBean>();
            List<NamedEntityBean> temp_target = new ArrayList<NamedEntityBean>();
            setBeanLists(entity, temp_source, getSourceSchema());
            setBeanLists(entity2, temp_target, getTargetSchema());
            // set source/target lists of the CellBean
            cellBean.setSource(temp_source);
            cellBean.setTarget(temp_target);
            // check if one of the entities has a transformation
            if (entity.getTransformation() != null || entity2.getTransformation() != null) {
                // entity 1 if it has the transformation
                if (entity.getTransformation() != null) {
                    setParameters(cellBean, entity, reporter, cell);
                    setTransformationId(cellBean, entity);
                } else {
                    // else set parameters and transformation id from entity
                    // 2
                    setParameters(cellBean, entity2, reporter, cell);
                    setTransformationId(cellBean, entity2);
                }
            }
            // add the CellBean to a list of CellBeans
            cells.add(cellBean);
        }
        // set the cells for the alignment after the all iterations
        align.setCells(cells);
        MutableAlignment mutableAlignment = align.createAlignment(reporter, getSourceSchema(), getTargetSchema(), new PathUpdate(null, null));
        reporter.setSuccess(true);
        return mutableAlignment;
    } finally {
        progress.end();
    }
}
Also used : IEntity(eu.esdihumboldt.hale.io.oml.internal.model.align.IEntity) ArrayList(java.util.ArrayList) MutableAlignment(eu.esdihumboldt.hale.common.align.model.MutableAlignment) ICell(eu.esdihumboldt.hale.io.oml.internal.model.align.ICell) MutableAlignment(eu.esdihumboldt.hale.common.align.model.MutableAlignment) Alignment(eu.esdihumboldt.hale.io.oml.internal.goml.align.Alignment) CellBean(eu.esdihumboldt.hale.common.align.io.impl.internal.CellBean) NamedEntityBean(eu.esdihumboldt.hale.common.align.io.impl.internal.NamedEntityBean) AlignmentBean(eu.esdihumboldt.hale.common.align.io.impl.internal.AlignmentBean) PathUpdate(eu.esdihumboldt.hale.common.core.io.PathUpdate) OmlRdfReader(eu.esdihumboldt.hale.io.oml.internal.goml.oml.io.OmlRdfReader)

Example 2 with Alignment

use of eu.esdihumboldt.hale.io.oml.internal.goml.align.Alignment in project hale by halestudio.

the class OmlRdfReader method read.

/**
 * Unmarshalls oml-mapping to the HUMBOLDT Alignment.
 *
 * @param rdfFile path to the oml-mapping file
 * @return Alignment object
 */
public Alignment read(URL rdfFile) {
    // 1. unmarshal rdf
    JAXBContext jc;
    JAXBElement<AlignmentType> root = null;
    try {
        jc = JAXBContext.newInstance(ALIGNMENT_CONTEXT, ObjectFactory.class.getClassLoader());
        Unmarshaller u = jc.createUnmarshaller();
        // it will debug problems while unmarshalling
        u.setEventHandler(new javax.xml.bind.helpers.DefaultValidationEventHandler());
        root = u.unmarshal(new StreamSource(rdfFile.openStream()), AlignmentType.class);
    /*
			 * root = u.unmarshal(new StreamSource(new File(rdfFile)),
			 * AlignmentType.class);
			 */
    } catch (Exception e) {
        throw new IllegalStateException("Failed to read alignment", e);
    }
    AlignmentType genAlignment = root.getValue();
    // 2. create humboldt alignment object and fulfill the required fields
    Alignment al = new Alignment();
    // set about
    al.setAbout(new About(UUID.randomUUID()));
    // set level
    if (genAlignment.getLevel() != null) {
        al.setLevel(genAlignment.getLevel());
    }
    // set map with cells
    if (genAlignment.getMap() != null) {
        al.setMap(getMap(genAlignment.getMap()));
    }
    // set schema1,2 containing information about ontologies1,2
    if (genAlignment.getOnto1() != null && genAlignment.getOnto1().getOntology() != null) {
        al.setSchema1(getSchema(genAlignment.getOnto1().getOntology()));
    }
    if (genAlignment.getOnto2() != null && genAlignment.getOnto2().getOntology() != null) {
        al.setSchema2(getSchema(genAlignment.getOnto2().getOntology()));
    }
    // set Value Class
    if (genAlignment.getValueClass() != null) {
        al.setValueClass(getValueClass(genAlignment.getValueClass()));
    }
    return al;
}
Also used : AlignmentType(eu.esdihumboldt.hale.io.oml.internal.model.generated.oml.AlignmentType) Alignment(eu.esdihumboldt.hale.io.oml.internal.goml.align.Alignment) StreamSource(javax.xml.transform.stream.StreamSource) JAXBContext(javax.xml.bind.JAXBContext) Unmarshaller(javax.xml.bind.Unmarshaller) URISyntaxException(java.net.URISyntaxException) MalformedURLException(java.net.MalformedURLException) IOException(java.io.IOException) About(eu.esdihumboldt.hale.io.oml.internal.goml.rdf.About) IAbout(eu.esdihumboldt.hale.io.oml.internal.model.rdf.IAbout)

Aggregations

Alignment (eu.esdihumboldt.hale.io.oml.internal.goml.align.Alignment)2 AlignmentBean (eu.esdihumboldt.hale.common.align.io.impl.internal.AlignmentBean)1 CellBean (eu.esdihumboldt.hale.common.align.io.impl.internal.CellBean)1 NamedEntityBean (eu.esdihumboldt.hale.common.align.io.impl.internal.NamedEntityBean)1 MutableAlignment (eu.esdihumboldt.hale.common.align.model.MutableAlignment)1 PathUpdate (eu.esdihumboldt.hale.common.core.io.PathUpdate)1 OmlRdfReader (eu.esdihumboldt.hale.io.oml.internal.goml.oml.io.OmlRdfReader)1 About (eu.esdihumboldt.hale.io.oml.internal.goml.rdf.About)1 ICell (eu.esdihumboldt.hale.io.oml.internal.model.align.ICell)1 IEntity (eu.esdihumboldt.hale.io.oml.internal.model.align.IEntity)1 AlignmentType (eu.esdihumboldt.hale.io.oml.internal.model.generated.oml.AlignmentType)1 IAbout (eu.esdihumboldt.hale.io.oml.internal.model.rdf.IAbout)1 IOException (java.io.IOException)1 MalformedURLException (java.net.MalformedURLException)1 URISyntaxException (java.net.URISyntaxException)1 ArrayList (java.util.ArrayList)1 JAXBContext (javax.xml.bind.JAXBContext)1 Unmarshaller (javax.xml.bind.Unmarshaller)1 StreamSource (javax.xml.transform.stream.StreamSource)1