Search in sources :

Example 1 with AlignmentBean

use of eu.esdihumboldt.hale.common.align.io.impl.internal.AlignmentBean 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 AlignmentBean

use of eu.esdihumboldt.hale.common.align.io.impl.internal.AlignmentBean in project hale by halestudio.

the class CastorAlignmentIO method save.

/**
 * Save a default alignment to an output stream.
 *
 * @param alignment the alignment to save
 * @param out the output stream
 * @param pathUpdate to update relative paths in case of a path change
 * @throws MappingException if the mapping could not be loaded
 * @throws ValidationException if the mapping is no valid XML
 * @throws MarshalException if the alignment could not be marshaled
 * @throws IOException if the output could not be written
 */
public static void save(Alignment alignment, OutputStream out, PathUpdate pathUpdate) throws MappingException, MarshalException, ValidationException, IOException {
    AlignmentBean bean = new AlignmentBean(alignment, pathUpdate);
    Mapping mapping = new Mapping(AlignmentBean.class.getClassLoader());
    mapping.loadMapping(new InputSource(AlignmentBean.class.getResourceAsStream("AlignmentBean.xml")));
    XMLContext context = new XMLContext();
    // enable
    context.setProperty("org.exolab.castor.indent", true);
    // indentation
    // for
    // marshaling as
    // project files
    // should be
    // very small
    context.addMapping(mapping);
    Marshaller marshaller = context.createMarshaller();
    // marshaller.setEncoding("UTF-8"); XXX not possible using the XMLContext but UTF-8 seems to be default, see http://jira.codehaus.org/browse/CASTOR-2846
    Writer writer = new BufferedWriter(new OutputStreamWriter(out, "UTF-8"));
    try {
        marshaller.setWriter(writer);
        marshaller.marshal(bean);
    } finally {
        try {
            writer.close();
        } catch (IOException e) {
        // ignore
        }
    }
}
Also used : InputSource(org.xml.sax.InputSource) Marshaller(org.exolab.castor.xml.Marshaller) XMLContext(org.exolab.castor.xml.XMLContext) AlignmentBean(eu.esdihumboldt.hale.common.align.io.impl.internal.AlignmentBean) Mapping(org.exolab.castor.mapping.Mapping) OutputStreamWriter(java.io.OutputStreamWriter) IOException(java.io.IOException) BufferedWriter(java.io.BufferedWriter) Writer(java.io.Writer) OutputStreamWriter(java.io.OutputStreamWriter) BufferedWriter(java.io.BufferedWriter)

Aggregations

AlignmentBean (eu.esdihumboldt.hale.common.align.io.impl.internal.AlignmentBean)2 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 Alignment (eu.esdihumboldt.hale.io.oml.internal.goml.align.Alignment)1 OmlRdfReader (eu.esdihumboldt.hale.io.oml.internal.goml.oml.io.OmlRdfReader)1 ICell (eu.esdihumboldt.hale.io.oml.internal.model.align.ICell)1 IEntity (eu.esdihumboldt.hale.io.oml.internal.model.align.IEntity)1 BufferedWriter (java.io.BufferedWriter)1 IOException (java.io.IOException)1 OutputStreamWriter (java.io.OutputStreamWriter)1 Writer (java.io.Writer)1 ArrayList (java.util.ArrayList)1 Mapping (org.exolab.castor.mapping.Mapping)1 Marshaller (org.exolab.castor.xml.Marshaller)1 XMLContext (org.exolab.castor.xml.XMLContext)1 InputSource (org.xml.sax.InputSource)1