⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mergeutil.java

📁 编辑视频文件
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
/* * File:     MergeUtil.java * Project:  MPI Linguistic Application * Date:     02 May 2007 * * Copyright (C) 2001-2007  Max Planck Institute for Psycholinguistics * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */package mpi.eudico.client.annotator.imports;import mpi.eudico.client.annotator.util.ClientLogger;import mpi.eudico.server.corpora.clom.Transcription;import mpi.eudico.server.corpora.clomimpl.abstr.TierImpl;import mpi.eudico.server.corpora.clomimpl.abstr.TranscriptionImpl;import mpi.eudico.server.corpora.clomimpl.type.LinguisticType;import mpi.util.ControlledVocabulary;import java.util.ArrayList;import java.util.Enumeration;import java.util.HashMap;import java.util.Hashtable;import javax.swing.tree.DefaultMutableTreeNode;/** * DOCUMENT ME! * $Id: jalopy_gnu_src_dist.xml,v 1.3 2007/02/06 13:30:33 hasloe Exp $ * @author $Author: hasloe $ * @version $Revision: 1.3 $ */public class MergeUtil implements ClientLogger {    /**     * Checks whether the tiers can be added: this depends on tier dependencies and     * compatibility of linguistic types.     *     * @return a list of tiers that can be added     */    public ArrayList getAddableTiers(Transcription srcTrans,        Transcription destTrans, ArrayList selTiers) {        if ((srcTrans == null) || (destTrans == null)) {            LOG.warning("A Transcription is null");            return new ArrayList(0);        }        if (selTiers == null) {            int size = srcTrans.getTiers().size();            selTiers = new ArrayList(size);            TierImpl ti;            for (int i = 0; i < size; i++) {                ti = (TierImpl) srcTrans.getTiers().get(i);                selTiers.add(ti.getName());            }        }        ArrayList validTiers = new ArrayList(selTiers.size());        String name;        TierImpl t;        TierImpl t2;        for (int i = 0; i < selTiers.size(); i++) {            name = (String) selTiers.get(i);            t = (TierImpl) srcTrans.getTierWithId(name);            if (t != null) {                t2 = (TierImpl) destTrans.getTierWithId(name);                if (t2 == null) { // not yet in destination                    if (t.getParentTier() == null) {                        // a toplevel tier can always be added                        validTiers.add(t);                    } else {                        // check whether:                        // 1 - the parent/ancestors are also in the list to be added                        // 2 - the parent/ancestors are already in the destination                        TierImpl parent = null;                        String parentName = null;                        TierImpl loopTier = t;                        while (loopTier.getParentTier() != null) {                            parent = (TierImpl) loopTier.getParentTier();                            parentName = parent.getName();                            if (selTiers.contains(parentName)) {                                if (parent.getParentTier() == null) {                                    validTiers.add(t);                                    break;                                } else if (destTrans.getTierWithId(parentName) != null) {                                    if (lingTypeCompatible(parent,                                                (TierImpl) destTrans.getTierWithId(                                                    parentName))) {                                        validTiers.add(t);                                    }                                    break;                                } else {                                    // try next ancestor                                    loopTier = parent;                                    continue;                                }                            } else {                                // the parent is not selected                                if (destTrans.getTierWithId(parentName) != null) {                                    if (lingTypeCompatible(parent,                                                (TierImpl) destTrans.getTierWithId(                                                    parentName))) {                                        validTiers.add(t);                                    }                                    break;                                } else {                                    break;                                }                            }                        }                    }                } else {                    // already in destination, check linguistic type                    if (lingTypeCompatible(t, t2)) {                        validTiers.add(t);                    }                }            } else {                LOG.warning("Tier " + name + " does not exist.");            }            if (!validTiers.contains(t)) {                LOG.warning("Cannot add tier " + name);            }        }        return validTiers;    }    /**     * Check whether the LinguisticTypes of the tiers have the same stereotype.     * This is a loose check, other attributes could also be checked; name, cv etc.     */    public boolean lingTypeCompatible(TierImpl t, TierImpl t2) {        if ((t == null) || (t2 == null)) {            return false;        }        // check linguistic type        LinguisticType lt = t.getLinguisticType();        LinguisticType lt2 = t2.getLinguisticType();        // losely check the linguistic types        if ( /*lt.getLinguisticTypeName().equals(lt2.getLinguisticTypeName()) &&*/            lt.hasConstraints() == lt2.hasConstraints()) {            if (lt.getConstraints() != null) {                if (lt.getConstraints().getStereoType() == lt2.getConstraints()                                                                  .getStereoType()) {                    return true;                } else {                    LOG.warning(                        "Incompatible tier types in source and destination: " +                        t.getName());                    return false;                }            } else {                // both toplevel tiers                return true;            }        }        return false;    }    /**     * Sort the tiers in the list hierarchically.     * @param tiers the tiers     */    public ArrayList sortTiers(ArrayList tiersToSort) {        if ((tiersToSort == null) || (tiersToSort.size() == 0)) {            return null;        }        DefaultMutableTreeNode sortedRootNode = new DefaultMutableTreeNode(                "sortRoot");        HashMap nodes = new HashMap();        TierImpl t = null;        for (int i = 0; i < tiersToSort.size(); i++) {            t = (TierImpl) tiersToSort.get(i);            DefaultMutableTreeNode node = new DefaultMutableTreeNode(t);            nodes.put(t, node);        }        for (int i = 0; i < tiersToSort.size(); i++) {            t = (TierImpl) tiersToSort.get(i);            if ((t.getParentTier() == null) ||                    !tiersToSort.contains(t.getParentTier())) {                sortedRootNode.add((DefaultMutableTreeNode) nodes.get(t));            } else {                ((DefaultMutableTreeNode) nodes.get(t.getParentTier())).add((DefaultMutableTreeNode) nodes.get(                        t));            }        }

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -