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

📄 annotationblockcreator.java

📁 编辑视频文件
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
/* * File:     AnnotationBlockCreator.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.interlinear;import mpi.eudico.server.corpora.clom.Transcription;import mpi.eudico.server.corpora.clomimpl.abstr.AbstractAnnotation;import mpi.eudico.server.corpora.clomimpl.abstr.TierImpl;import mpi.eudico.server.corpora.clomimpl.type.Constraint;import java.util.ArrayList;import java.util.Enumeration;import java.util.HashMap;import java.util.Vector;import javax.swing.tree.DefaultMutableTreeNode;/** * A class that creates an AnnotationBlock for a given root annotation. The * created <code>InterlinearAnnotation</code> objects are stored and returned * in a tree structure. Annotations on invisible tiers are omitted, their * child annotations on visible tiers are added to first ancestor encountered. * * @author Han Sloetjes */public class AnnotationBlockCreator {    /**     * Creates a new AnnotationBlockCreator instance.     */    public AnnotationBlockCreator() {    }    /**     * Creates a tree with the specified annotation as the root, only including     * block information for visible annotations. Annotations the parent of     * which is on a invisble tier will be added to the first visible     * ancestor.  When the tier the annotation 'aa' is on is not included in     * the visible tiers array  it is checked for separately in the loops to     * guarantee proper annotation ordering.     *     * @param aa the annotation to create a tree for     * @param visibleTiers a list of the visible tiers (TierImpl objects)     *     * @return a DefaultMutableTreeNode; the root node containing the root     *         annotation print record     */    public DefaultMutableTreeNode createBlockForAnnotation(        AbstractAnnotation aa, ArrayList visibleTiers) {        if (aa == null) {            return null;        }        DefaultMutableTreeNode root = new DefaultMutableTreeNode(new InterlinearAnnotation(                    aa));        ArrayList children = null;        AbstractAnnotation next = null;        AbstractAnnotation parent = null;        DefaultMutableTreeNode nextNode = null;        DefaultMutableTreeNode parentNode = root;        TierImpl tier = null;        String tierName = null;        DefaultMutableTreeNode tempNode = null;        InterlinearAnnotation dataRecord = null;        children = aa.getParentListeners();        if (children.size() > 0) {downloop:             for (int i = 0; i < children.size(); i++) {                next = (AbstractAnnotation) children.get(i);                // children can come in any order                tier = (TierImpl) next.getTier();                if ((visibleTiers == null) || visibleTiers.contains(tier) ||                        (tier == aa.getTier())) {                    nextNode = new DefaultMutableTreeNode(new InterlinearAnnotation(                                next));                    if (parentNode.getChildCount() == 0) {                        parentNode.add(nextNode);                    } else {                        long bt = next.getBeginTimeBoundary();                        tierName = next.getTier().getName();                        boolean inTierGroup = false;                        int numChildren = parentNode.getChildCount();                        for (int k = 0; k < numChildren; k++) {                            tempNode = (DefaultMutableTreeNode) parentNode.getChildAt(k);                            dataRecord = (InterlinearAnnotation) tempNode.getUserObject();                            if (dataRecord.getTierName().equals(tierName)) {                                inTierGroup = true;                            }                            if ((dataRecord.bt > bt) && inTierGroup) {                                parentNode.insert(nextNode, k);                                break;                            } else if (inTierGroup &&                                    !dataRecord.getTierName().equals(tierName)) {                                // we passed the last ann of the right tier in the group of children                                parentNode.insert(nextNode, k);                                break;                            } else if (k == (parentNode.getChildCount() - 1)) {                                parentNode.add(nextNode);                            }                        }                    }                    if (next.getParentListeners().size() > 0) {                        children = next.getParentListeners();                        parentNode = nextNode;                        i = -1;                        continue downloop;                    }                } else {                    if (next.getParentListeners().size() > 0) {                        children = next.getParentListeners();                        //parentNode = nextNode;                        i = -1;                        continue downloop;                    }                }                if (i == (children.size() - 1)) {uploop:                     while (true) {                        parent = (AbstractAnnotation) next.getParentAnnotation();                        if (parent != null) {                            if ((visibleTiers == null) ||                                    visibleTiers.contains(next.getTier()) ||                                    (next.getTier() == aa.getTier())) {                                if ((nextNode != null) &&                                        (nextNode.getParent() != null)) {                                    parentNode = (DefaultMutableTreeNode) nextNode.getParent();                                } else {                                    parentNode = root;                                }                            }                            children = parent.getParentListeners();                            int j = children.indexOf(next);                            if (j == (children.size() - 1)) {                                if (parent == aa) {                                    break downloop;                                }                                next = parent;                                nextNode = parentNode;                                continue uploop;                            } else {                                i = j;                                continue downloop;                            }                        } else {                            break downloop;                        }                    }                }            }        }        /*           Enumeration en = root.depthFirstEnumeration();           //           System.out.println("Depth First:\n");           while (en.hasMoreElements()){               DefaultMutableTreeNode nextnode = (DefaultMutableTreeNode)en.nextElement();               InterlinearAnnotation rec = (InterlinearAnnotation) nextnode.getUserObject();               System.out.println("Level: " + nextnode.getLevel() + " -- Tier: " + rec.getTierName() + " anndata: " + rec.getValue());           }           System.out.println("\n");           System.out.println("Breadth First:\n");           en = root.breadthFirstEnumeration();           while (en.hasMoreElements()){               DefaultMutableTreeNode nextnode = (DefaultMutableTreeNode)en.nextElement();               InterlinearAnnotation rec = (InterlinearAnnotation) nextnode.getUserObject();               System.out.println("Level: " + nextnode.getLevel() + " -- Tier: " + rec.getTierName() + " anndata: " + rec.getValue());           }           System.out.println("\n");           System.out.println("Post Order:\n");           en = root.postorderEnumeration();           while (en.hasMoreElements()){               DefaultMutableTreeNode nextnode = (DefaultMutableTreeNode)en.nextElement();               InterlinearAnnotation rec = (InterlinearAnnotation) nextnode.getUserObject();               System.out.println("Level: " + nextnode.getLevel() + " -- Tier: " + rec.getTierName() + " anndata: " + rec.getValue());           }           System.out.println("\n");           //           System.out.println("Pre Order:\n");           en = root.preorderEnumeration();           while (en.hasMoreElements()){               DefaultMutableTreeNode nextnode = (DefaultMutableTreeNode)en.nextElement();               InterlinearAnnotation rec = (InterlinearAnnotation) nextnode.getUserObject();                   System.out.println("Level: " + nextnode.getLevel() + " -- Tier: " + rec.getTierName() + " anndata: " + rec.getValue());           }           System.out.println("\n");         */        return root;    }    /**     * Creates a tree with the specified annotation as the root, only including     * block information for visible annotations. Annotations the parent of     * which is on a invisble tier will be added to the first visible     * ancestor.  When the tier the annotation 'aa' is on is not included in     * the visible tiers array  it is checked for separately in the loops to     * guarantee proper annotation ordering. Empty InterlinearAnnotations are added     * to dependent tiers where there is no child annotation at a position where there     * could be an annotation according to the parent-child tier relationship.     *     * @param aa the annotation to create a tree for     * @param visibleTiers a list of the visible tiers (TierImpl objects)     *     * @return a DefaultMutableTreeNode; the root node containing the root     *         annotation print record     */    public DefaultMutableTreeNode createBlockFillEmptyPositions(        AbstractAnnotation aa, ArrayList visibleTiers) {        if (aa == null) {            return null;        }        DefaultMutableTreeNode root = new DefaultMutableTreeNode(new InterlinearAnnotation(                    aa));        ArrayList children = null;        AbstractAnnotation next = null;        AbstractAnnotation parent = null;        DefaultMutableTreeNode nextNode = null;        DefaultMutableTreeNode parentNode = root;        TierImpl tier = null;        String tierName = null;        DefaultMutableTreeNode tempNode = null;        InterlinearAnnotation dataRecord = null;        fillEmptyPositions(root, aa, visibleTiers);        children = aa.getParentListeners();        if (children.size() > 0) {downloop:             for (int i = 0; i < children.size(); i++) {                next = (AbstractAnnotation) children.get(i);                // children can come in any order                tier = (TierImpl) next.getTier();                if ((visibleTiers == null) || visibleTiers.contains(tier) ||                        (tier == aa.getTier())) {                    nextNode = new DefaultMutableTreeNode(new InterlinearAnnotation(                                next));                    fillEmptyPositions(nextNode, next, visibleTiers);                    if (parentNode.getChildCount() == 0) {                        parentNode.add(nextNode);                    } else {                        long bt = next.getBeginTimeBoundary();                        tierName = next.getTier().getName();                        boolean inTierGroup = false;                        int numChildren = parentNode.getChildCount();                        for (int k = 0; k < numChildren; k++) {                            tempNode = (DefaultMutableTreeNode) parentNode.getChildAt(k);                            dataRecord = (InterlinearAnnotation) tempNode.getUserObject();                            if (dataRecord.getTierName().equals(tierName)) {

⌨️ 快捷键说明

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